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 : : /* Similar as Clang's preserve_none function parameter passing.
339 : : NB: Use DI_REG and SI_REG, see ix86_function_value_regno_p. */
340 : :
341 : : static int const x86_64_preserve_none_int_parameter_registers[6] =
342 : : {
343 : : R12_REG, R13_REG, R14_REG, R15_REG, DI_REG, SI_REG
344 : : };
345 : :
346 : : static int const x86_64_int_return_registers[4] =
347 : : {
348 : : AX_REG, DX_REG, DI_REG, SI_REG
349 : : };
350 : :
351 : : /* Define the structure for the machine field in struct function. */
352 : :
353 : : struct GTY(()) stack_local_entry {
354 : : unsigned short mode;
355 : : unsigned short n;
356 : : rtx rtl;
357 : : struct stack_local_entry *next;
358 : : };
359 : :
360 : : /* Which cpu are we scheduling for. */
361 : : enum attr_cpu ix86_schedule;
362 : :
363 : : /* Which cpu are we optimizing for. */
364 : : enum processor_type ix86_tune;
365 : :
366 : : /* Which instruction set architecture to use. */
367 : : enum processor_type ix86_arch;
368 : :
369 : : /* True if processor has SSE prefetch instruction. */
370 : : unsigned char ix86_prefetch_sse;
371 : :
372 : : /* Preferred alignment for stack boundary in bits. */
373 : : unsigned int ix86_preferred_stack_boundary;
374 : :
375 : : /* Alignment for incoming stack boundary in bits specified at
376 : : command line. */
377 : : unsigned int ix86_user_incoming_stack_boundary;
378 : :
379 : : /* Default alignment for incoming stack boundary in bits. */
380 : : unsigned int ix86_default_incoming_stack_boundary;
381 : :
382 : : /* Alignment for incoming stack boundary in bits. */
383 : : unsigned int ix86_incoming_stack_boundary;
384 : :
385 : : /* True if there is no direct access to extern symbols. */
386 : : bool ix86_has_no_direct_extern_access;
387 : :
388 : : /* Calling abi specific va_list type nodes. */
389 : : tree sysv_va_list_type_node;
390 : : tree ms_va_list_type_node;
391 : :
392 : : /* Prefix built by ASM_GENERATE_INTERNAL_LABEL. */
393 : : char internal_label_prefix[16];
394 : : int internal_label_prefix_len;
395 : :
396 : : /* Fence to use after loop using movnt. */
397 : : tree x86_mfence;
398 : :
399 : : /* Register class used for passing given 64bit part of the argument.
400 : : These represent classes as documented by the PS ABI, with the exception
401 : : of SSESF, SSEDF classes, that are basically SSE class, just gcc will
402 : : use SF or DFmode move instead of DImode to avoid reformatting penalties.
403 : :
404 : : Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
405 : : whenever possible (upper half does contain padding). */
406 : : enum x86_64_reg_class
407 : : {
408 : : X86_64_NO_CLASS,
409 : : X86_64_INTEGER_CLASS,
410 : : X86_64_INTEGERSI_CLASS,
411 : : X86_64_SSE_CLASS,
412 : : X86_64_SSEHF_CLASS,
413 : : X86_64_SSESF_CLASS,
414 : : X86_64_SSEDF_CLASS,
415 : : X86_64_SSEUP_CLASS,
416 : : X86_64_X87_CLASS,
417 : : X86_64_X87UP_CLASS,
418 : : X86_64_COMPLEX_X87_CLASS,
419 : : X86_64_MEMORY_CLASS
420 : : };
421 : :
422 : : #define MAX_CLASSES 8
423 : :
424 : : /* Table of constants used by fldpi, fldln2, etc.... */
425 : : static REAL_VALUE_TYPE ext_80387_constants_table [5];
426 : : static bool ext_80387_constants_init;
427 : :
428 : :
429 : : static rtx ix86_function_value (const_tree, const_tree, bool);
430 : : static bool ix86_function_value_regno_p (const unsigned int);
431 : : static unsigned int ix86_function_arg_boundary (machine_mode,
432 : : const_tree);
433 : : static rtx ix86_static_chain (const_tree, bool);
434 : : static int ix86_function_regparm (const_tree, const_tree);
435 : : static void ix86_compute_frame_layout (void);
436 : : static tree ix86_canonical_va_list_type (tree);
437 : : static unsigned int split_stack_prologue_scratch_regno (void);
438 : : static bool i386_asm_output_addr_const_extra (FILE *, rtx);
439 : :
440 : : static bool ix86_can_inline_p (tree, tree);
441 : : static unsigned int ix86_minimum_incoming_stack_boundary (bool);
442 : :
443 : : typedef enum ix86_flags_cc
444 : : {
445 : : X86_CCO = 0, X86_CCNO, X86_CCB, X86_CCNB,
446 : : X86_CCE, X86_CCNE, X86_CCBE, X86_CCNBE,
447 : : X86_CCS, X86_CCNS, X86_CCP, X86_CCNP,
448 : : X86_CCL, X86_CCNL, X86_CCLE, X86_CCNLE
449 : : } ix86_cc;
450 : :
451 : : static const char *ix86_ccmp_dfv_mapping[] =
452 : : {
453 : : "{dfv=of}", "{dfv=}", "{dfv=cf}", "{dfv=}",
454 : : "{dfv=zf}", "{dfv=}", "{dfv=cf, zf}", "{dfv=}",
455 : : "{dfv=sf}", "{dfv=}", "{dfv=cf}", "{dfv=}",
456 : : "{dfv=sf}", "{dfv=sf, of}", "{dfv=sf, of, zf}", "{dfv=sf, of}"
457 : : };
458 : :
459 : :
460 : : /* Whether -mtune= or -march= were specified */
461 : : int ix86_tune_defaulted;
462 : : int ix86_arch_specified;
463 : :
464 : : /* Return true if a red-zone is in use. We can't use red-zone when
465 : : there are local indirect jumps, like "indirect_jump" or "tablejump",
466 : : which jumps to another place in the function, since "call" in the
467 : : indirect thunk pushes the return address onto stack, destroying
468 : : red-zone.
469 : :
470 : : NB: Don't use red-zone for functions with no_caller_saved_registers
471 : : and 32 GPRs or 16 XMM registers since 128-byte red-zone is too small
472 : : for 31 GPRs or 15 GPRs + 16 XMM registers.
473 : :
474 : : TODO: If we can reserve the first 2 WORDs, for PUSH and, another
475 : : for CALL, in red-zone, we can allow local indirect jumps with
476 : : indirect thunk. */
477 : :
478 : : bool
479 : 9741295 : ix86_using_red_zone (void)
480 : : {
481 : 9741295 : return (TARGET_RED_ZONE
482 : 8805158 : && !TARGET_64BIT_MS_ABI
483 : 8502710 : && ((!TARGET_APX_EGPR && !TARGET_SSE)
484 : 8479805 : || (cfun->machine->call_saved_registers
485 : 8479805 : != TYPE_NO_CALLER_SAVED_REGISTERS))
486 : 18243952 : && (!cfun->machine->has_local_indirect_jump
487 : 71873 : || cfun->machine->indirect_branch_type == indirect_branch_keep));
488 : : }
489 : :
490 : : /* Return true, if profiling code should be emitted before
491 : : prologue. Otherwise it returns false.
492 : : Note: For x86 with "hotfix" it is sorried. */
493 : : static bool
494 : 4420104 : ix86_profile_before_prologue (void)
495 : : {
496 : 4420104 : return flag_fentry != 0;
497 : : }
498 : :
499 : : /* Update register usage after having seen the compiler flags. */
500 : :
501 : : static void
502 : 831412 : ix86_conditional_register_usage (void)
503 : : {
504 : 831412 : int i, c_mask;
505 : :
506 : : /* If there are no caller-saved registers, preserve all registers.
507 : : except fixed_regs and registers used for function return value
508 : : since aggregate_value_p checks call_used_regs[regno] on return
509 : : value. */
510 : 831412 : if (cfun
511 : 63204 : && (cfun->machine->call_saved_registers
512 : 63204 : == TYPE_NO_CALLER_SAVED_REGISTERS))
513 : 397017 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
514 : 392748 : if (!fixed_regs[i] && !ix86_function_value_regno_p (i))
515 : 353533 : call_used_regs[i] = 0;
516 : :
517 : : /* For 32-bit targets, disable the REX registers. */
518 : 831412 : if (! TARGET_64BIT)
519 : : {
520 : 133263 : for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
521 : 118456 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
522 : 133263 : for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
523 : 118456 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
524 : 251719 : for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
525 : 236912 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
526 : : }
527 : :
528 : : /* See the definition of CALL_USED_REGISTERS in i386.h. */
529 : 831412 : c_mask = CALL_USED_REGISTERS_MASK (TARGET_64BIT_MS_ABI);
530 : :
531 : 831412 : CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
532 : :
533 : 77321316 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
534 : : {
535 : : /* Set/reset conditionally defined registers from
536 : : CALL_USED_REGISTERS initializer. */
537 : 76489904 : if (call_used_regs[i] > 1)
538 : 13242771 : call_used_regs[i] = !!(call_used_regs[i] & c_mask);
539 : :
540 : : /* Calculate registers of CLOBBERED_REGS register set
541 : : as call used registers from GENERAL_REGS register set. */
542 : 76489904 : if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
543 : 76489904 : && call_used_regs[i])
544 : 23182059 : SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
545 : : }
546 : :
547 : : /* If MMX is disabled, disable the registers. */
548 : 831412 : if (! TARGET_MMX)
549 : 387028 : accessible_reg_set &= ~reg_class_contents[MMX_REGS];
550 : :
551 : : /* If SSE is disabled, disable the registers. */
552 : 831412 : if (! TARGET_SSE)
553 : 381834 : accessible_reg_set &= ~reg_class_contents[ALL_SSE_REGS];
554 : :
555 : : /* If the FPU is disabled, disable the registers. */
556 : 831412 : if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
557 : 382238 : accessible_reg_set &= ~reg_class_contents[FLOAT_REGS];
558 : :
559 : : /* If AVX512F is disabled, disable the registers. */
560 : 831412 : if (! TARGET_AVX512F)
561 : : {
562 : 9986208 : for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
563 : 9398784 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
564 : :
565 : 1174848 : accessible_reg_set &= ~reg_class_contents[ALL_MASK_REGS];
566 : : }
567 : :
568 : : /* If APX is disabled, disable the registers. */
569 : 831412 : if (! (TARGET_APX_EGPR && TARGET_64BIT))
570 : : {
571 : 14124076 : for (i = FIRST_REX2_INT_REG; i <= LAST_REX2_INT_REG; i++)
572 : 13293248 : CLEAR_HARD_REG_BIT (accessible_reg_set, i);
573 : : }
574 : 831412 : }
575 : :
576 : : /* Canonicalize a comparison from one we don't have to one we do have. */
577 : :
578 : : static void
579 : 22335680 : ix86_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
580 : : bool op0_preserve_value)
581 : : {
582 : : /* The order of operands in x87 ficom compare is forced by combine in
583 : : simplify_comparison () function. Float operator is treated as RTX_OBJ
584 : : with a precedence over other operators and is always put in the first
585 : : place. Swap condition and operands to match ficom instruction. */
586 : 22335680 : if (!op0_preserve_value
587 : 21530978 : && GET_CODE (*op0) == FLOAT && MEM_P (XEXP (*op0, 0)) && REG_P (*op1))
588 : : {
589 : 6 : enum rtx_code scode = swap_condition ((enum rtx_code) *code);
590 : :
591 : : /* We are called only for compares that are split to SAHF instruction.
592 : : Ensure that we have setcc/jcc insn for the swapped condition. */
593 : 6 : if (ix86_fp_compare_code_to_integer (scode) != UNKNOWN)
594 : : {
595 : 6 : std::swap (*op0, *op1);
596 : 6 : *code = (int) scode;
597 : 6 : return;
598 : : }
599 : : }
600 : :
601 : : /* Swap operands of GTU comparison to canonicalize
602 : : addcarry/subborrow comparison. */
603 : 21530972 : if (!op0_preserve_value
604 : 21530972 : && *code == GTU
605 : 752443 : && GET_CODE (*op0) == PLUS
606 : 316969 : && ix86_carry_flag_operator (XEXP (*op0, 0), VOIDmode)
607 : 48587 : && GET_CODE (XEXP (*op0, 1)) == ZERO_EXTEND
608 : 44386 : && GET_CODE (*op1) == ZERO_EXTEND)
609 : : {
610 : 41351 : std::swap (*op0, *op1);
611 : 41351 : *code = (int) swap_condition ((enum rtx_code) *code);
612 : 41351 : return;
613 : : }
614 : : }
615 : :
616 : : /* Hook to determine if one function can safely inline another. */
617 : :
618 : : static bool
619 : 9542581 : ix86_can_inline_p (tree caller, tree callee)
620 : : {
621 : 9542581 : tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
622 : 9542581 : tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
623 : :
624 : : /* Changes of those flags can be tolerated for always inlines. Lets hope
625 : : user knows what he is doing. */
626 : 9542581 : unsigned HOST_WIDE_INT always_inline_safe_mask
627 : : = (MASK_USE_8BIT_IDIV | MASK_ACCUMULATE_OUTGOING_ARGS
628 : : | MASK_NO_ALIGN_STRINGOPS | MASK_AVX256_SPLIT_UNALIGNED_LOAD
629 : : | MASK_AVX256_SPLIT_UNALIGNED_STORE | MASK_CLD
630 : : | MASK_NO_FANCY_MATH_387 | MASK_IEEE_FP | MASK_INLINE_ALL_STRINGOPS
631 : : | MASK_INLINE_STRINGOPS_DYNAMICALLY | MASK_RECIP | MASK_STACK_PROBE
632 : : | MASK_STV | MASK_TLS_DIRECT_SEG_REFS | MASK_VZEROUPPER
633 : : | MASK_NO_PUSH_ARGS | MASK_OMIT_LEAF_FRAME_POINTER);
634 : :
635 : :
636 : 9542581 : if (!callee_tree)
637 : 8906430 : callee_tree = target_option_default_node;
638 : 9542581 : if (!caller_tree)
639 : 8906512 : caller_tree = target_option_default_node;
640 : 9542581 : if (callee_tree == caller_tree)
641 : : return true;
642 : :
643 : 5191 : struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
644 : 5191 : struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
645 : 5191 : bool ret = false;
646 : 5191 : bool always_inline
647 : 5191 : = (DECL_DISREGARD_INLINE_LIMITS (callee)
648 : 9771 : && lookup_attribute ("always_inline",
649 : 4580 : DECL_ATTRIBUTES (callee)));
650 : :
651 : : /* If callee only uses GPRs, ignore MASK_80387. */
652 : 5191 : if (TARGET_GENERAL_REGS_ONLY_P (callee_opts->x_ix86_target_flags))
653 : 1023 : always_inline_safe_mask |= MASK_80387;
654 : :
655 : 5191 : cgraph_node *callee_node = cgraph_node::get (callee);
656 : : /* Callee's isa options should be a subset of the caller's, i.e. a SSE4
657 : : function can inline a SSE2 function but a SSE2 function can't inline
658 : : a SSE4 function. */
659 : 5191 : if (((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags)
660 : : != callee_opts->x_ix86_isa_flags)
661 : 4961 : || ((caller_opts->x_ix86_isa_flags2 & callee_opts->x_ix86_isa_flags2)
662 : : != callee_opts->x_ix86_isa_flags2))
663 : : ret = false;
664 : :
665 : : /* See if we have the same non-isa options. */
666 : 4940 : else if ((!always_inline
667 : 376 : && caller_opts->x_target_flags != callee_opts->x_target_flags)
668 : 4896 : || (caller_opts->x_target_flags & ~always_inline_safe_mask)
669 : 4896 : != (callee_opts->x_target_flags & ~always_inline_safe_mask))
670 : : ret = false;
671 : :
672 : 4896 : else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath
673 : : /* If the calle doesn't use FP expressions differences in
674 : : ix86_fpmath can be ignored. We are called from FEs
675 : : for multi-versioning call optimization, so beware of
676 : : ipa_fn_summaries not available. */
677 : 1240 : && (! ipa_fn_summaries
678 : 1240 : || ipa_fn_summaries->get (callee_node) == NULL
679 : 1240 : || ipa_fn_summaries->get (callee_node)->fp_expressions))
680 : : ret = false;
681 : :
682 : : /* At this point we cannot identify whether arch or tune setting
683 : : comes from target attribute or not. So the most conservative way
684 : : is to allow the callee that uses default arch and tune string to
685 : : be inlined. */
686 : 4622 : else if (!strcmp (callee_opts->x_ix86_arch_string, "x86-64")
687 : 1423 : && !strcmp (callee_opts->x_ix86_tune_string, "generic"))
688 : : ret = true;
689 : :
690 : : /* See if arch, tune, etc. are the same. As previous ISA flags already
691 : : checks if callee's ISA is subset of caller's, do not block
692 : : always_inline attribute for callee even it has different arch. */
693 : 3207 : else if (!always_inline && caller_opts->arch != callee_opts->arch)
694 : : ret = false;
695 : :
696 : 3 : else if (!always_inline && caller_opts->tune != callee_opts->tune)
697 : : ret = false;
698 : :
699 : 3207 : else if (!always_inline
700 : 3 : && caller_opts->branch_cost != callee_opts->branch_cost)
701 : : ret = false;
702 : :
703 : : else
704 : 9542012 : ret = true;
705 : :
706 : : return ret;
707 : : }
708 : :
709 : : /* Return true if this goes in large data/bss. */
710 : :
711 : : static bool
712 : 80014254 : ix86_in_large_data_p (tree exp)
713 : : {
714 : 80014254 : if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC
715 : 80014016 : && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC)
716 : : return false;
717 : :
718 : 1040 : if (exp == NULL_TREE)
719 : : return false;
720 : :
721 : : /* Functions are never large data. */
722 : 1040 : if (TREE_CODE (exp) == FUNCTION_DECL)
723 : : return false;
724 : :
725 : : /* Automatic variables are never large data. */
726 : 256 : if (VAR_P (exp) && !is_global_var (exp))
727 : : return false;
728 : :
729 : 256 : if (VAR_P (exp) && DECL_SECTION_NAME (exp))
730 : : {
731 : 51 : const char *section = DECL_SECTION_NAME (exp);
732 : 51 : if (strcmp (section, ".ldata") == 0
733 : 51 : || strcmp (section, ".lbss") == 0)
734 : : return true;
735 : : return false;
736 : : }
737 : : else
738 : : {
739 : 205 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
740 : :
741 : : /* If this is an incomplete type with size 0, then we can't put it
742 : : in data because it might be too big when completed. Also,
743 : : int_size_in_bytes returns -1 if size can vary or is larger than
744 : : an integer in which case also it is safer to assume that it goes in
745 : : large data. */
746 : 205 : if (size <= 0 || size > ix86_section_threshold)
747 : : return true;
748 : : }
749 : :
750 : : return false;
751 : : }
752 : :
753 : : /* i386-specific section flag to mark large sections. */
754 : : #define SECTION_LARGE SECTION_MACH_DEP
755 : :
756 : : /* Switch to the appropriate section for output of DECL.
757 : : DECL is either a `VAR_DECL' node or a constant of some sort.
758 : : RELOC indicates whether forming the initial value of DECL requires
759 : : link-time relocations. */
760 : :
761 : : ATTRIBUTE_UNUSED static section *
762 : 1644940 : x86_64_elf_select_section (tree decl, int reloc,
763 : : unsigned HOST_WIDE_INT align)
764 : : {
765 : 1644940 : if (ix86_in_large_data_p (decl))
766 : : {
767 : 6 : const char *sname = NULL;
768 : 6 : unsigned int flags = SECTION_WRITE | SECTION_LARGE;
769 : 6 : switch (categorize_decl_for_section (decl, reloc))
770 : : {
771 : 1 : case SECCAT_DATA:
772 : 1 : sname = ".ldata";
773 : 1 : break;
774 : 0 : case SECCAT_DATA_REL:
775 : 0 : sname = ".ldata.rel";
776 : 0 : break;
777 : 0 : case SECCAT_DATA_REL_LOCAL:
778 : 0 : sname = ".ldata.rel.local";
779 : 0 : break;
780 : 0 : case SECCAT_DATA_REL_RO:
781 : 0 : sname = ".ldata.rel.ro";
782 : 0 : break;
783 : 0 : case SECCAT_DATA_REL_RO_LOCAL:
784 : 0 : sname = ".ldata.rel.ro.local";
785 : 0 : break;
786 : 0 : case SECCAT_BSS:
787 : 0 : sname = ".lbss";
788 : 0 : flags |= SECTION_BSS;
789 : 0 : break;
790 : : case SECCAT_RODATA:
791 : : case SECCAT_RODATA_MERGE_STR:
792 : : case SECCAT_RODATA_MERGE_STR_INIT:
793 : : case SECCAT_RODATA_MERGE_CONST:
794 : : sname = ".lrodata";
795 : : flags &= ~SECTION_WRITE;
796 : : break;
797 : 0 : case SECCAT_SRODATA:
798 : 0 : case SECCAT_SDATA:
799 : 0 : case SECCAT_SBSS:
800 : 0 : gcc_unreachable ();
801 : : case SECCAT_TEXT:
802 : : case SECCAT_TDATA:
803 : : case SECCAT_TBSS:
804 : : /* We don't split these for medium model. Place them into
805 : : default sections and hope for best. */
806 : : break;
807 : : }
808 : 1 : if (sname)
809 : : {
810 : : /* We might get called with string constants, but get_named_section
811 : : doesn't like them as they are not DECLs. Also, we need to set
812 : : flags in that case. */
813 : 6 : if (!DECL_P (decl))
814 : 3 : return get_section (sname, flags, NULL);
815 : 3 : return get_named_section (decl, sname, reloc);
816 : : }
817 : : }
818 : 1644934 : return default_elf_select_section (decl, reloc, align);
819 : : }
820 : :
821 : : /* Select a set of attributes for section NAME based on the properties
822 : : of DECL and whether or not RELOC indicates that DECL's initializer
823 : : might contain runtime relocations. */
824 : :
825 : : static unsigned int ATTRIBUTE_UNUSED
826 : 66745910 : x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
827 : : {
828 : 66745910 : unsigned int flags = default_section_type_flags (decl, name, reloc);
829 : :
830 : 66745910 : if (ix86_in_large_data_p (decl))
831 : 7 : flags |= SECTION_LARGE;
832 : :
833 : 66745910 : if (decl == NULL_TREE
834 : 367 : && (strcmp (name, ".ldata.rel.ro") == 0
835 : 367 : || strcmp (name, ".ldata.rel.ro.local") == 0))
836 : 0 : flags |= SECTION_RELRO;
837 : :
838 : 66745910 : if (strcmp (name, ".lbss") == 0
839 : 66745906 : || startswith (name, ".lbss.")
840 : 133491813 : || startswith (name, ".gnu.linkonce.lb."))
841 : 7 : flags |= SECTION_BSS;
842 : :
843 : 66745910 : return flags;
844 : : }
845 : :
846 : : /* Build up a unique section name, expressed as a
847 : : STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
848 : : RELOC indicates whether the initial value of EXP requires
849 : : link-time relocations. */
850 : :
851 : : static void ATTRIBUTE_UNUSED
852 : 1796339 : x86_64_elf_unique_section (tree decl, int reloc)
853 : : {
854 : 1796339 : if (ix86_in_large_data_p (decl))
855 : : {
856 : 3 : const char *prefix = NULL;
857 : : /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
858 : 3 : bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP;
859 : :
860 : 3 : switch (categorize_decl_for_section (decl, reloc))
861 : : {
862 : 0 : case SECCAT_DATA:
863 : 0 : case SECCAT_DATA_REL:
864 : 0 : case SECCAT_DATA_REL_LOCAL:
865 : 0 : case SECCAT_DATA_REL_RO:
866 : 0 : case SECCAT_DATA_REL_RO_LOCAL:
867 : 0 : prefix = one_only ? ".ld" : ".ldata";
868 : : break;
869 : 3 : case SECCAT_BSS:
870 : 3 : prefix = one_only ? ".lb" : ".lbss";
871 : : break;
872 : : case SECCAT_RODATA:
873 : : case SECCAT_RODATA_MERGE_STR:
874 : : case SECCAT_RODATA_MERGE_STR_INIT:
875 : : case SECCAT_RODATA_MERGE_CONST:
876 : : prefix = one_only ? ".lr" : ".lrodata";
877 : : break;
878 : 0 : case SECCAT_SRODATA:
879 : 0 : case SECCAT_SDATA:
880 : 0 : case SECCAT_SBSS:
881 : 0 : gcc_unreachable ();
882 : : case SECCAT_TEXT:
883 : : case SECCAT_TDATA:
884 : : case SECCAT_TBSS:
885 : : /* We don't split these for medium model. Place them into
886 : : default sections and hope for best. */
887 : : break;
888 : : }
889 : 3 : if (prefix)
890 : : {
891 : 3 : const char *name, *linkonce;
892 : 3 : char *string;
893 : :
894 : 3 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
895 : 3 : name = targetm.strip_name_encoding (name);
896 : :
897 : : /* If we're using one_only, then there needs to be a .gnu.linkonce
898 : : prefix to the section name. */
899 : 3 : linkonce = one_only ? ".gnu.linkonce" : "";
900 : :
901 : 3 : string = ACONCAT ((linkonce, prefix, ".", name, NULL));
902 : :
903 : 3 : set_decl_section_name (decl, string);
904 : 3 : return;
905 : : }
906 : : }
907 : 1796336 : default_unique_section (decl, reloc);
908 : : }
909 : :
910 : : /* Return true if TYPE has no_callee_saved_registers or preserve_none
911 : : attribute. */
912 : :
913 : : bool
914 : 7457808 : ix86_type_no_callee_saved_registers_p (const_tree type)
915 : : {
916 : 14915616 : return (lookup_attribute ("no_callee_saved_registers",
917 : 7457808 : TYPE_ATTRIBUTES (type)) != NULL
918 : 14915497 : || lookup_attribute ("preserve_none",
919 : 7457689 : TYPE_ATTRIBUTES (type)) != NULL);
920 : : }
921 : :
922 : : #ifdef COMMON_ASM_OP
923 : :
924 : : #ifndef LARGECOMM_SECTION_ASM_OP
925 : : #define LARGECOMM_SECTION_ASM_OP "\t.largecomm\t"
926 : : #endif
927 : :
928 : : /* This says how to output assembler code to declare an
929 : : uninitialized external linkage data object.
930 : :
931 : : For medium model x86-64 we need to use LARGECOMM_SECTION_ASM_OP opcode for
932 : : large objects. */
933 : : void
934 : 168788 : x86_elf_aligned_decl_common (FILE *file, tree decl,
935 : : const char *name, unsigned HOST_WIDE_INT size,
936 : : unsigned align)
937 : : {
938 : 168788 : if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC
939 : 168782 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
940 : 6 : && size > (unsigned int)ix86_section_threshold)
941 : : {
942 : 1 : switch_to_section (get_named_section (decl, ".lbss", 0));
943 : 1 : fputs (LARGECOMM_SECTION_ASM_OP, file);
944 : : }
945 : : else
946 : 168787 : fputs (COMMON_ASM_OP, file);
947 : 168788 : assemble_name (file, name);
948 : 168788 : fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
949 : : size, align / BITS_PER_UNIT);
950 : 168788 : }
951 : : #endif
952 : :
953 : : /* Utility function for targets to use in implementing
954 : : ASM_OUTPUT_ALIGNED_BSS. */
955 : :
956 : : void
957 : 764248 : x86_output_aligned_bss (FILE *file, tree decl, const char *name,
958 : : unsigned HOST_WIDE_INT size, unsigned align)
959 : : {
960 : 764248 : if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC
961 : 764238 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
962 : 37 : && size > (unsigned int)ix86_section_threshold)
963 : 3 : switch_to_section (get_named_section (decl, ".lbss", 0));
964 : : else
965 : 764245 : switch_to_section (bss_section);
966 : 915257 : ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
967 : : #ifdef ASM_DECLARE_OBJECT_NAME
968 : 764248 : last_assemble_variable_decl = decl;
969 : 764248 : ASM_DECLARE_OBJECT_NAME (file, name, decl);
970 : : #else
971 : : /* Standard thing is just output label for the object. */
972 : : ASM_OUTPUT_LABEL (file, name);
973 : : #endif /* ASM_DECLARE_OBJECT_NAME */
974 : 764248 : ASM_OUTPUT_SKIP (file, size ? size : 1);
975 : 764248 : }
976 : :
977 : : /* Decide whether we must probe the stack before any space allocation
978 : : on this target. It's essentially TARGET_STACK_PROBE except when
979 : : -fstack-check causes the stack to be already probed differently. */
980 : :
981 : : bool
982 : 860338 : ix86_target_stack_probe (void)
983 : : {
984 : : /* Do not probe the stack twice if static stack checking is enabled. */
985 : 860338 : if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
986 : : return false;
987 : :
988 : 860338 : return TARGET_STACK_PROBE;
989 : : }
990 : :
991 : : /* Decide whether we can make a sibling call to a function. DECL is the
992 : : declaration of the function being targeted by the call and EXP is the
993 : : CALL_EXPR representing the call. */
994 : :
995 : : static bool
996 : 133950 : ix86_function_ok_for_sibcall (tree decl, tree exp)
997 : : {
998 : 133950 : tree type, decl_or_type;
999 : 133950 : rtx a, b;
1000 : 133950 : bool bind_global = decl && !targetm.binds_local_p (decl);
1001 : :
1002 : 133950 : if (ix86_function_naked (current_function_decl))
1003 : : return false;
1004 : :
1005 : : /* Sibling call isn't OK if there are no caller-saved registers
1006 : : since all registers must be preserved before return. */
1007 : 133948 : if (cfun->machine->call_saved_registers
1008 : 133948 : == TYPE_NO_CALLER_SAVED_REGISTERS)
1009 : : return false;
1010 : :
1011 : : /* If we are generating position-independent code, we cannot sibcall
1012 : : optimize direct calls to global functions, as the PLT requires
1013 : : %ebx be live. (Darwin does not have a PLT.) */
1014 : 133919 : if (!TARGET_MACHO
1015 : 133919 : && !TARGET_64BIT
1016 : 10967 : && flag_pic
1017 : 8113 : && flag_plt
1018 : 8113 : && bind_global)
1019 : : return false;
1020 : :
1021 : : /* If we need to align the outgoing stack, then sibcalling would
1022 : : unalign the stack, which may break the called function. */
1023 : 129418 : if (ix86_minimum_incoming_stack_boundary (true)
1024 : 129418 : < PREFERRED_STACK_BOUNDARY)
1025 : : return false;
1026 : :
1027 : 128837 : if (decl)
1028 : : {
1029 : 118817 : decl_or_type = decl;
1030 : 118817 : type = TREE_TYPE (decl);
1031 : : }
1032 : : else
1033 : : {
1034 : : /* We're looking at the CALL_EXPR, we need the type of the function. */
1035 : 10020 : type = CALL_EXPR_FN (exp); /* pointer expression */
1036 : 10020 : type = TREE_TYPE (type); /* pointer type */
1037 : 10020 : type = TREE_TYPE (type); /* function type */
1038 : 10020 : decl_or_type = type;
1039 : : }
1040 : :
1041 : : /* Sibling call isn't OK if callee has no callee-saved registers
1042 : : and the calling function has callee-saved registers. */
1043 : 128837 : if ((cfun->machine->call_saved_registers
1044 : 128837 : != TYPE_NO_CALLEE_SAVED_REGISTERS)
1045 : 128818 : && cfun->machine->call_saved_registers != TYPE_PRESERVE_NONE
1046 : 128811 : && (cfun->machine->call_saved_registers
1047 : : != TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP)
1048 : 257648 : && ix86_type_no_callee_saved_registers_p (type))
1049 : : return false;
1050 : :
1051 : : /* If outgoing reg parm stack space changes, we cannot do sibcall. */
1052 : 128825 : if ((OUTGOING_REG_PARM_STACK_SPACE (type)
1053 : 128825 : != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
1054 : 256903 : || (REG_PARM_STACK_SPACE (decl_or_type)
1055 : 128078 : != REG_PARM_STACK_SPACE (current_function_decl)))
1056 : : {
1057 : 747 : maybe_complain_about_tail_call (exp,
1058 : : "inconsistent size of stack space"
1059 : : " allocated for arguments which are"
1060 : : " passed in registers");
1061 : 747 : return false;
1062 : : }
1063 : :
1064 : : /* Check that the return value locations are the same. Like
1065 : : if we are returning floats on the 80387 register stack, we cannot
1066 : : make a sibcall from a function that doesn't return a float to a
1067 : : function that does or, conversely, from a function that does return
1068 : : a float to a function that doesn't; the necessary stack adjustment
1069 : : would not be executed. This is also the place we notice
1070 : : differences in the return value ABI. Note that it is ok for one
1071 : : of the functions to have void return type as long as the return
1072 : : value of the other is passed in a register. */
1073 : 128078 : a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
1074 : 128078 : b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
1075 : 128078 : cfun->decl, false);
1076 : 128078 : if (STACK_REG_P (a) || STACK_REG_P (b))
1077 : : {
1078 : 693 : if (!rtx_equal_p (a, b))
1079 : : return false;
1080 : : }
1081 : 127385 : else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
1082 : : ;
1083 : 25348 : else if (!rtx_equal_p (a, b))
1084 : : return false;
1085 : :
1086 : 127689 : if (TARGET_64BIT)
1087 : : {
1088 : : /* The SYSV ABI has more call-clobbered registers;
1089 : : disallow sibcalls from MS to SYSV. */
1090 : 121223 : if (cfun->machine->call_abi == MS_ABI
1091 : 121223 : && ix86_function_type_abi (type) == SYSV_ABI)
1092 : : return false;
1093 : : }
1094 : : else
1095 : : {
1096 : : /* If this call is indirect, we'll need to be able to use a
1097 : : call-clobbered register for the address of the target function.
1098 : : Make sure that all such registers are not used for passing
1099 : : parameters. Note that DLLIMPORT functions and call to global
1100 : : function via GOT slot are indirect. */
1101 : 6466 : if (!decl
1102 : 4672 : || (bind_global && flag_pic && !flag_plt)
1103 : : || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl))
1104 : 4672 : || flag_force_indirect_call)
1105 : : {
1106 : : /* Check if regparm >= 3 since arg_reg_available is set to
1107 : : false if regparm == 0. If regparm is 1 or 2, there is
1108 : : always a call-clobbered register available.
1109 : :
1110 : : ??? The symbol indirect call doesn't need a call-clobbered
1111 : : register. But we don't know if this is a symbol indirect
1112 : : call or not here. */
1113 : 1794 : if (ix86_function_regparm (type, decl) >= 3
1114 : 1794 : && !cfun->machine->arg_reg_available)
1115 : : return false;
1116 : : }
1117 : : }
1118 : :
1119 : 127689 : if (decl && ix86_use_pseudo_pic_reg ())
1120 : : {
1121 : : /* When PIC register is used, it must be restored after ifunc
1122 : : function returns. */
1123 : 2019 : cgraph_node *node = cgraph_node::get (decl);
1124 : 2019 : if (node && node->ifunc_resolver)
1125 : : return false;
1126 : : }
1127 : :
1128 : : /* Disable sibcall if callee has indirect_return attribute and
1129 : : caller doesn't since callee will return to the caller's caller
1130 : : via an indirect jump. */
1131 : 127689 : if (((flag_cf_protection & (CF_RETURN | CF_BRANCH))
1132 : : == (CF_RETURN | CF_BRANCH))
1133 : 52376 : && lookup_attribute ("indirect_return", TYPE_ATTRIBUTES (type))
1134 : 127693 : && !lookup_attribute ("indirect_return",
1135 : 4 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))))
1136 : : return false;
1137 : :
1138 : : /* Otherwise okay. That also includes certain types of indirect calls. */
1139 : : return true;
1140 : : }
1141 : :
1142 : : /* This function determines from TYPE the calling-convention. */
1143 : :
1144 : : unsigned int
1145 : 6125425 : ix86_get_callcvt (const_tree type)
1146 : : {
1147 : 6125425 : unsigned int ret = 0;
1148 : 6125425 : bool is_stdarg;
1149 : 6125425 : tree attrs;
1150 : :
1151 : 6125425 : if (TARGET_64BIT)
1152 : : return IX86_CALLCVT_CDECL;
1153 : :
1154 : 3241707 : attrs = TYPE_ATTRIBUTES (type);
1155 : 3241707 : if (attrs != NULL_TREE)
1156 : : {
1157 : 63458 : if (lookup_attribute ("cdecl", attrs))
1158 : : ret |= IX86_CALLCVT_CDECL;
1159 : 63458 : else if (lookup_attribute ("stdcall", attrs))
1160 : : ret |= IX86_CALLCVT_STDCALL;
1161 : 63458 : else if (lookup_attribute ("fastcall", attrs))
1162 : : ret |= IX86_CALLCVT_FASTCALL;
1163 : 63449 : else if (lookup_attribute ("thiscall", attrs))
1164 : : ret |= IX86_CALLCVT_THISCALL;
1165 : :
1166 : : /* Regparam isn't allowed for thiscall and fastcall. */
1167 : : if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
1168 : : {
1169 : 63449 : if (lookup_attribute ("regparm", attrs))
1170 : 15683 : ret |= IX86_CALLCVT_REGPARM;
1171 : 63449 : if (lookup_attribute ("sseregparm", attrs))
1172 : 0 : ret |= IX86_CALLCVT_SSEREGPARM;
1173 : : }
1174 : :
1175 : 63458 : if (IX86_BASE_CALLCVT(ret) != 0)
1176 : 9 : return ret;
1177 : : }
1178 : :
1179 : 3241698 : is_stdarg = stdarg_p (type);
1180 : 3241698 : if (TARGET_RTD && !is_stdarg)
1181 : 0 : return IX86_CALLCVT_STDCALL | ret;
1182 : :
1183 : 3241698 : if (ret != 0
1184 : 3241698 : || is_stdarg
1185 : 3217191 : || TREE_CODE (type) != METHOD_TYPE
1186 : 3371491 : || ix86_function_type_abi (type) != MS_ABI)
1187 : 3241698 : return IX86_CALLCVT_CDECL | ret;
1188 : :
1189 : : return IX86_CALLCVT_THISCALL;
1190 : : }
1191 : :
1192 : : /* Return 0 if the attributes for two types are incompatible, 1 if they
1193 : : are compatible, and 2 if they are nearly compatible (which causes a
1194 : : warning to be generated). */
1195 : :
1196 : : static int
1197 : 1459469 : ix86_comp_type_attributes (const_tree type1, const_tree type2)
1198 : : {
1199 : 1459469 : unsigned int ccvt1, ccvt2;
1200 : :
1201 : 1459469 : if (TREE_CODE (type1) != FUNCTION_TYPE
1202 : 1459469 : && TREE_CODE (type1) != METHOD_TYPE)
1203 : : return 1;
1204 : :
1205 : 1452847 : ccvt1 = ix86_get_callcvt (type1);
1206 : 1452847 : ccvt2 = ix86_get_callcvt (type2);
1207 : 1452847 : if (ccvt1 != ccvt2)
1208 : : return 0;
1209 : 2883838 : if (ix86_function_regparm (type1, NULL)
1210 : 1441919 : != ix86_function_regparm (type2, NULL))
1211 : : return 0;
1212 : :
1213 : 1404174 : if (ix86_type_no_callee_saved_registers_p (type1)
1214 : 702087 : != ix86_type_no_callee_saved_registers_p (type2))
1215 : : return 0;
1216 : :
1217 : : /* preserve_none attribute uses a different calling convention is
1218 : : only for 64-bit. */
1219 : 701973 : if (TARGET_64BIT
1220 : 1403886 : && (lookup_attribute ("preserve_none", TYPE_ATTRIBUTES (type1))
1221 : 701913 : != lookup_attribute ("preserve_none",
1222 : 701913 : TYPE_ATTRIBUTES (type2))))
1223 : : return 0;
1224 : :
1225 : : return 1;
1226 : : }
1227 : :
1228 : : /* Return the regparm value for a function with the indicated TYPE and DECL.
1229 : : DECL may be NULL when calling function indirectly
1230 : : or considering a libcall. */
1231 : :
1232 : : static int
1233 : 4144738 : ix86_function_regparm (const_tree type, const_tree decl)
1234 : : {
1235 : 4144738 : tree attr;
1236 : 4144738 : int regparm;
1237 : 4144738 : unsigned int ccvt;
1238 : :
1239 : 4144738 : if (TARGET_64BIT)
1240 : 2883718 : return (ix86_function_type_abi (type) == SYSV_ABI
1241 : 2883718 : ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
1242 : 1261020 : ccvt = ix86_get_callcvt (type);
1243 : 1261020 : regparm = ix86_regparm;
1244 : :
1245 : 1261020 : if ((ccvt & IX86_CALLCVT_REGPARM) != 0)
1246 : : {
1247 : 2017 : attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
1248 : 2017 : if (attr)
1249 : : {
1250 : 2017 : regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
1251 : 2017 : return regparm;
1252 : : }
1253 : : }
1254 : 1259003 : else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
1255 : : return 2;
1256 : 1259003 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
1257 : : return 1;
1258 : :
1259 : : /* Use register calling convention for local functions when possible. */
1260 : 1259003 : if (decl
1261 : 1195737 : && TREE_CODE (decl) == FUNCTION_DECL)
1262 : : {
1263 : 1185642 : cgraph_node *target = cgraph_node::get (decl);
1264 : 1185642 : if (target)
1265 : 1178159 : target = target->function_symbol ();
1266 : :
1267 : : /* Caller and callee must agree on the calling convention, so
1268 : : checking here just optimize means that with
1269 : : __attribute__((optimize (...))) caller could use regparm convention
1270 : : and callee not, or vice versa. Instead look at whether the callee
1271 : : is optimized or not. */
1272 : 1178159 : if (target && opt_for_fn (target->decl, optimize)
1273 : 2355467 : && !(profile_flag && !flag_fentry))
1274 : : {
1275 : 1177308 : if (target->local && target->can_change_signature)
1276 : : {
1277 : 137868 : int local_regparm, globals = 0, regno;
1278 : :
1279 : : /* Make sure no regparm register is taken by a
1280 : : fixed register variable. */
1281 : 137868 : for (local_regparm = 0; local_regparm < REGPARM_MAX;
1282 : : local_regparm++)
1283 : 103401 : if (fixed_regs[local_regparm])
1284 : : break;
1285 : :
1286 : : /* We don't want to use regparm(3) for nested functions as
1287 : : these use a static chain pointer in the third argument. */
1288 : 34467 : if (local_regparm == 3 && DECL_STATIC_CHAIN (target->decl))
1289 : : local_regparm = 2;
1290 : :
1291 : : /* Save a register for the split stack. */
1292 : 34467 : if (flag_split_stack)
1293 : : {
1294 : 20896 : if (local_regparm == 3)
1295 : : local_regparm = 2;
1296 : 707 : else if (local_regparm == 2
1297 : 707 : && DECL_STATIC_CHAIN (target->decl))
1298 : : local_regparm = 1;
1299 : : }
1300 : :
1301 : : /* Each fixed register usage increases register pressure,
1302 : : so less registers should be used for argument passing.
1303 : : This functionality can be overriden by an explicit
1304 : : regparm value. */
1305 : 241269 : for (regno = AX_REG; regno <= DI_REG; regno++)
1306 : 206802 : if (fixed_regs[regno])
1307 : 0 : globals++;
1308 : :
1309 : 34467 : local_regparm
1310 : 34467 : = globals < local_regparm ? local_regparm - globals : 0;
1311 : :
1312 : 34467 : if (local_regparm > regparm)
1313 : 4144738 : regparm = local_regparm;
1314 : : }
1315 : : }
1316 : : }
1317 : :
1318 : : return regparm;
1319 : : }
1320 : :
1321 : : /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
1322 : : DFmode (2) arguments in SSE registers for a function with the
1323 : : indicated TYPE and DECL. DECL may be NULL when calling function
1324 : : indirectly or considering a libcall. Return -1 if any FP parameter
1325 : : should be rejected by error. This is used in siutation we imply SSE
1326 : : calling convetion but the function is called from another function with
1327 : : SSE disabled. Otherwise return 0. */
1328 : :
1329 : : static int
1330 : 1065480 : ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
1331 : : {
1332 : 1065480 : gcc_assert (!TARGET_64BIT);
1333 : :
1334 : : /* Use SSE registers to pass SFmode and DFmode arguments if requested
1335 : : by the sseregparm attribute. */
1336 : 1065480 : if (TARGET_SSEREGPARM
1337 : 1065480 : || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
1338 : : {
1339 : 0 : if (!TARGET_SSE)
1340 : : {
1341 : 0 : if (warn)
1342 : : {
1343 : 0 : if (decl)
1344 : 0 : error ("calling %qD with attribute sseregparm without "
1345 : : "SSE/SSE2 enabled", decl);
1346 : : else
1347 : 0 : error ("calling %qT with attribute sseregparm without "
1348 : : "SSE/SSE2 enabled", type);
1349 : : }
1350 : 0 : return 0;
1351 : : }
1352 : :
1353 : : return 2;
1354 : : }
1355 : :
1356 : 1065480 : if (!decl)
1357 : : return 0;
1358 : :
1359 : 969546 : cgraph_node *target = cgraph_node::get (decl);
1360 : 969546 : if (target)
1361 : 962070 : target = target->function_symbol ();
1362 : :
1363 : : /* For local functions, pass up to SSE_REGPARM_MAX SFmode
1364 : : (and DFmode for SSE2) arguments in SSE registers. */
1365 : 962070 : if (target
1366 : : /* TARGET_SSE_MATH */
1367 : 962070 : && (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE)
1368 : 1296 : && opt_for_fn (target->decl, optimize)
1369 : 963366 : && !(profile_flag && !flag_fentry))
1370 : : {
1371 : 1296 : if (target->local && target->can_change_signature)
1372 : : {
1373 : : /* Refuse to produce wrong code when local function with SSE enabled
1374 : : is called from SSE disabled function.
1375 : : FIXME: We need a way to detect these cases cross-ltrans partition
1376 : : and avoid using SSE calling conventions on local functions called
1377 : : from function with SSE disabled. For now at least delay the
1378 : : warning until we know we are going to produce wrong code.
1379 : : See PR66047 */
1380 : 0 : if (!TARGET_SSE && warn)
1381 : : return -1;
1382 : 0 : return TARGET_SSE2_P (target_opts_for_fn (target->decl)
1383 : 0 : ->x_ix86_isa_flags) ? 2 : 1;
1384 : : }
1385 : : }
1386 : :
1387 : : return 0;
1388 : : }
1389 : :
1390 : : /* Return true if EAX is live at the start of the function. Used by
1391 : : ix86_expand_prologue to determine if we need special help before
1392 : : calling allocate_stack_worker. */
1393 : :
1394 : : static bool
1395 : 7090 : ix86_eax_live_at_start_p (void)
1396 : : {
1397 : : /* Cheat. Don't bother working forward from ix86_function_regparm
1398 : : to the function type to whether an actual argument is located in
1399 : : eax. Instead just look at cfg info, which is still close enough
1400 : : to correct at this point. This gives false positives for broken
1401 : : functions that might use uninitialized data that happens to be
1402 : : allocated in eax, but who cares? */
1403 : 7090 : return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0);
1404 : : }
1405 : :
1406 : : static bool
1407 : 159260 : ix86_keep_aggregate_return_pointer (tree fntype)
1408 : : {
1409 : 159260 : tree attr;
1410 : :
1411 : 159260 : if (!TARGET_64BIT)
1412 : : {
1413 : 159260 : attr = lookup_attribute ("callee_pop_aggregate_return",
1414 : 159260 : TYPE_ATTRIBUTES (fntype));
1415 : 159260 : if (attr)
1416 : 0 : return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0);
1417 : :
1418 : : /* For 32-bit MS-ABI the default is to keep aggregate
1419 : : return pointer. */
1420 : 159260 : if (ix86_function_type_abi (fntype) == MS_ABI)
1421 : : return true;
1422 : : }
1423 : : return KEEP_AGGREGATE_RETURN_POINTER != 0;
1424 : : }
1425 : :
1426 : : /* Value is the number of bytes of arguments automatically
1427 : : popped when returning from a subroutine call.
1428 : : FUNDECL is the declaration node of the function (as a tree),
1429 : : FUNTYPE is the data type of the function (as a tree),
1430 : : or for a library call it is an identifier node for the subroutine name.
1431 : : SIZE is the number of bytes of arguments passed on the stack.
1432 : :
1433 : : On the 80386, the RTD insn may be used to pop them if the number
1434 : : of args is fixed, but if the number is variable then the caller
1435 : : must pop them all. RTD can't be used for library calls now
1436 : : because the library is compiled with the Unix compiler.
1437 : : Use of RTD is a selectable option, since it is incompatible with
1438 : : standard Unix calling sequences. If the option is not selected,
1439 : : the caller must always pop the args.
1440 : :
1441 : : The attribute stdcall is equivalent to RTD on a per module basis. */
1442 : :
1443 : : static poly_int64
1444 : 7505130 : ix86_return_pops_args (tree fundecl, tree funtype, poly_int64 size)
1445 : : {
1446 : 7505130 : unsigned int ccvt;
1447 : :
1448 : : /* None of the 64-bit ABIs pop arguments. */
1449 : 7505130 : if (TARGET_64BIT)
1450 : 6639071 : return 0;
1451 : :
1452 : 866059 : ccvt = ix86_get_callcvt (funtype);
1453 : :
1454 : 866059 : if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL
1455 : : | IX86_CALLCVT_THISCALL)) != 0
1456 : 866059 : && ! stdarg_p (funtype))
1457 : 3 : return size;
1458 : :
1459 : : /* Lose any fake structure return argument if it is passed on the stack. */
1460 : 866056 : if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
1461 : 866056 : && !ix86_keep_aggregate_return_pointer (funtype))
1462 : : {
1463 : 159260 : int nregs = ix86_function_regparm (funtype, fundecl);
1464 : 159260 : if (nregs == 0)
1465 : 456720 : return GET_MODE_SIZE (Pmode);
1466 : : }
1467 : :
1468 : 713816 : return 0;
1469 : : }
1470 : :
1471 : : /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook. */
1472 : :
1473 : : static bool
1474 : 9591013 : ix86_legitimate_combined_insn (rtx_insn *insn)
1475 : : {
1476 : 9591013 : int i;
1477 : :
1478 : : /* Check operand constraints in case hard registers were propagated
1479 : : into insn pattern. This check prevents combine pass from
1480 : : generating insn patterns with invalid hard register operands.
1481 : : These invalid insns can eventually confuse reload to error out
1482 : : with a spill failure. See also PRs 46829 and 46843. */
1483 : :
1484 : 9591013 : gcc_assert (INSN_CODE (insn) >= 0);
1485 : :
1486 : 9591013 : extract_insn (insn);
1487 : 9591013 : preprocess_constraints (insn);
1488 : :
1489 : 9591013 : int n_operands = recog_data.n_operands;
1490 : 9591013 : int n_alternatives = recog_data.n_alternatives;
1491 : 32856596 : for (i = 0; i < n_operands; i++)
1492 : : {
1493 : 23269054 : rtx op = recog_data.operand[i];
1494 : 23269054 : machine_mode mode = GET_MODE (op);
1495 : 23269054 : const operand_alternative *op_alt;
1496 : 23269054 : int offset = 0;
1497 : 23269054 : bool win;
1498 : 23269054 : int j;
1499 : :
1500 : : /* A unary operator may be accepted by the predicate, but it
1501 : : is irrelevant for matching constraints. */
1502 : 23269054 : if (UNARY_P (op))
1503 : 54095 : op = XEXP (op, 0);
1504 : :
1505 : 23269054 : if (SUBREG_P (op))
1506 : : {
1507 : 781921 : if (REG_P (SUBREG_REG (op))
1508 : 781921 : && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
1509 : 57 : offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
1510 : 57 : GET_MODE (SUBREG_REG (op)),
1511 : 57 : SUBREG_BYTE (op),
1512 : 57 : GET_MODE (op));
1513 : 781921 : op = SUBREG_REG (op);
1514 : : }
1515 : :
1516 : 23269054 : if (!(REG_P (op) && HARD_REGISTER_P (op)))
1517 : 22986889 : continue;
1518 : :
1519 : 282165 : op_alt = recog_op_alt;
1520 : :
1521 : : /* Operand has no constraints, anything is OK. */
1522 : 282165 : win = !n_alternatives;
1523 : :
1524 : 282165 : alternative_mask preferred = get_preferred_alternatives (insn);
1525 : 773424 : for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
1526 : : {
1527 : 487542 : if (!TEST_BIT (preferred, j))
1528 : 133326 : continue;
1529 : 354216 : if (op_alt[i].anything_ok
1530 : 189759 : || (op_alt[i].matches != -1
1531 : 33995 : && operands_match_p
1532 : 33995 : (recog_data.operand[i],
1533 : 33995 : recog_data.operand[op_alt[i].matches]))
1534 : 539739 : || reg_fits_class_p (op, op_alt[i].cl, offset, mode))
1535 : : {
1536 : : win = true;
1537 : : break;
1538 : : }
1539 : : }
1540 : :
1541 : 282165 : if (!win)
1542 : : return false;
1543 : : }
1544 : :
1545 : : return true;
1546 : : }
1547 : :
1548 : : /* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */
1549 : :
1550 : : static unsigned HOST_WIDE_INT
1551 : 4555 : ix86_asan_shadow_offset (void)
1552 : : {
1553 : 4555 : return SUBTARGET_SHADOW_OFFSET;
1554 : : }
1555 : :
1556 : : /* Argument support functions. */
1557 : :
1558 : : /* Return true when register may be used to pass function parameters. */
1559 : : bool
1560 : 1455036437 : ix86_function_arg_regno_p (int regno)
1561 : : {
1562 : 1455036437 : int i;
1563 : 1455036437 : enum calling_abi call_abi;
1564 : 1455036437 : const int *parm_regs;
1565 : :
1566 : 1451613206 : if (TARGET_SSE && SSE_REGNO_P (regno)
1567 : 2405574979 : && regno < FIRST_SSE_REG + SSE_REGPARM_MAX)
1568 : : return true;
1569 : :
1570 : 1337661023 : if (!TARGET_64BIT)
1571 : 128358457 : return (regno < REGPARM_MAX
1572 : 128358457 : || (TARGET_MMX && MMX_REGNO_P (regno)
1573 : 11536480 : && regno < FIRST_MMX_REG + MMX_REGPARM_MAX));
1574 : :
1575 : : /* TODO: The function should depend on current function ABI but
1576 : : builtins.cc would need updating then. Therefore we use the
1577 : : default ABI. */
1578 : 1209302566 : call_abi = ix86_cfun_abi ();
1579 : :
1580 : : /* RAX is used as hidden argument to va_arg functions. */
1581 : 1209302566 : if (call_abi == SYSV_ABI && regno == AX_REG)
1582 : : return true;
1583 : :
1584 : 1195336742 : if (cfun
1585 : 1195336410 : && cfun->machine->call_saved_registers == TYPE_PRESERVE_NONE)
1586 : : parm_regs = x86_64_preserve_none_int_parameter_registers;
1587 : 1195323794 : else if (call_abi == MS_ABI)
1588 : : parm_regs = x86_64_ms_abi_int_parameter_registers;
1589 : : else
1590 : 1159338186 : parm_regs = x86_64_int_parameter_registers;
1591 : :
1592 : 15995470524 : for (i = 0; i < (call_abi == MS_ABI
1593 : 7997735262 : ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
1594 : 6887884589 : if (regno == parm_regs[i])
1595 : : return true;
1596 : : return false;
1597 : : }
1598 : :
1599 : : /* Return if we do not know how to pass ARG solely in registers. */
1600 : :
1601 : : static bool
1602 : 372233707 : ix86_must_pass_in_stack (const function_arg_info &arg)
1603 : : {
1604 : 372233707 : if (must_pass_in_stack_var_size_or_pad (arg))
1605 : : return true;
1606 : :
1607 : : /* For 32-bit, we want TImode aggregates to go on the stack. But watch out!
1608 : : The layout_type routine is crafty and tries to trick us into passing
1609 : : currently unsupported vector types on the stack by using TImode. */
1610 : 1754823 : return (!TARGET_64BIT && arg.mode == TImode
1611 : 372233670 : && arg.type && TREE_CODE (arg.type) != VECTOR_TYPE);
1612 : : }
1613 : :
1614 : : /* It returns the size, in bytes, of the area reserved for arguments passed
1615 : : in registers for the function represented by fndecl dependent to the used
1616 : : abi format. */
1617 : : int
1618 : 10607259 : ix86_reg_parm_stack_space (const_tree fndecl)
1619 : : {
1620 : 10607259 : enum calling_abi call_abi = SYSV_ABI;
1621 : 10607259 : if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
1622 : 10289530 : call_abi = ix86_function_abi (fndecl);
1623 : : else
1624 : 317729 : call_abi = ix86_function_type_abi (fndecl);
1625 : 10607259 : if (TARGET_64BIT && call_abi == MS_ABI)
1626 : 119228 : return 32;
1627 : : return 0;
1628 : : }
1629 : :
1630 : : /* We add this as a workaround in order to use libc_has_function
1631 : : hook in i386.md. */
1632 : : bool
1633 : 0 : ix86_libc_has_function (enum function_class fn_class)
1634 : : {
1635 : 0 : return targetm.libc_has_function (fn_class, NULL_TREE);
1636 : : }
1637 : :
1638 : : /* Returns value SYSV_ABI, MS_ABI dependent on fntype,
1639 : : specifying the call abi used. */
1640 : : enum calling_abi
1641 : 404015291 : ix86_function_type_abi (const_tree fntype)
1642 : : {
1643 : 404015291 : enum calling_abi abi = ix86_abi;
1644 : :
1645 : 404015291 : if (fntype == NULL_TREE || TYPE_ATTRIBUTES (fntype) == NULL_TREE)
1646 : : return abi;
1647 : :
1648 : 17211134 : if (abi == SYSV_ABI
1649 : 17211134 : && lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
1650 : : {
1651 : 2586532 : static int warned;
1652 : 2586532 : if (TARGET_X32 && !warned)
1653 : : {
1654 : 1 : error ("X32 does not support %<ms_abi%> attribute");
1655 : 1 : warned = 1;
1656 : : }
1657 : :
1658 : : abi = MS_ABI;
1659 : : }
1660 : 14624602 : else if (abi == MS_ABI
1661 : 14624602 : && lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
1662 : : abi = SYSV_ABI;
1663 : :
1664 : : return abi;
1665 : : }
1666 : :
1667 : : enum calling_abi
1668 : 197037935 : ix86_function_abi (const_tree fndecl)
1669 : : {
1670 : 197037935 : return fndecl ? ix86_function_type_abi (TREE_TYPE (fndecl)) : ix86_abi;
1671 : : }
1672 : :
1673 : : /* Returns value SYSV_ABI, MS_ABI dependent on cfun,
1674 : : specifying the call abi used. */
1675 : : enum calling_abi
1676 : 2046021803 : ix86_cfun_abi (void)
1677 : : {
1678 : 2046021803 : return cfun ? cfun->machine->call_abi : ix86_abi;
1679 : : }
1680 : :
1681 : : bool
1682 : 4989270 : ix86_function_ms_hook_prologue (const_tree fn)
1683 : : {
1684 : 4989270 : if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn)))
1685 : : {
1686 : 15 : if (decl_function_context (fn) != NULL_TREE)
1687 : 0 : error_at (DECL_SOURCE_LOCATION (fn),
1688 : : "%<ms_hook_prologue%> attribute is not compatible "
1689 : : "with nested function");
1690 : : else
1691 : : return true;
1692 : : }
1693 : : return false;
1694 : : }
1695 : :
1696 : : bool
1697 : 109183736 : ix86_function_naked (const_tree fn)
1698 : : {
1699 : 109183736 : if (fn && lookup_attribute ("naked", DECL_ATTRIBUTES (fn)))
1700 : : return true;
1701 : :
1702 : : return false;
1703 : : }
1704 : :
1705 : : /* Write the extra assembler code needed to declare a function properly. */
1706 : :
1707 : : void
1708 : 1522933 : ix86_asm_output_function_label (FILE *out_file, const char *fname,
1709 : : tree decl)
1710 : : {
1711 : 1522933 : bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
1712 : :
1713 : 1522933 : if (cfun)
1714 : 1519353 : cfun->machine->function_label_emitted = true;
1715 : :
1716 : 1522933 : if (is_ms_hook)
1717 : : {
1718 : 2 : int i, filler_count = (TARGET_64BIT ? 32 : 16);
1719 : 2 : unsigned int filler_cc = 0xcccccccc;
1720 : :
1721 : 18 : for (i = 0; i < filler_count; i += 4)
1722 : 16 : fprintf (out_file, ASM_LONG " %#x\n", filler_cc);
1723 : : }
1724 : :
1725 : : #ifdef SUBTARGET_ASM_UNWIND_INIT
1726 : : SUBTARGET_ASM_UNWIND_INIT (out_file);
1727 : : #endif
1728 : :
1729 : 1522933 : assemble_function_label_raw (out_file, fname);
1730 : :
1731 : : /* Output magic byte marker, if hot-patch attribute is set. */
1732 : 1522933 : if (is_ms_hook)
1733 : : {
1734 : 2 : if (TARGET_64BIT)
1735 : : {
1736 : : /* leaq [%rsp + 0], %rsp */
1737 : 2 : fputs (ASM_BYTE "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n",
1738 : : out_file);
1739 : : }
1740 : : else
1741 : : {
1742 : : /* movl.s %edi, %edi
1743 : : push %ebp
1744 : : movl.s %esp, %ebp */
1745 : 0 : fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", out_file);
1746 : : }
1747 : : }
1748 : 1522933 : }
1749 : :
1750 : : /* Output a user-defined label. In AT&T syntax, registers are prefixed
1751 : : with %, so labels require no punctuation. In Intel syntax, registers
1752 : : are unprefixed, so labels may clash with registers or other operators,
1753 : : and require quoting. */
1754 : : void
1755 : 34627783 : ix86_asm_output_labelref (FILE *file, const char *prefix, const char *label)
1756 : : {
1757 : 34627783 : if (ASSEMBLER_DIALECT == ASM_ATT)
1758 : 34626885 : fprintf (file, "%s%s", prefix, label);
1759 : : else
1760 : 898 : fprintf (file, "\"%s%s\"", prefix, label);
1761 : 34627783 : }
1762 : :
1763 : : /* Implementation of call abi switching target hook. Specific to FNDECL
1764 : : the specific call register sets are set. See also
1765 : : ix86_conditional_register_usage for more details. */
1766 : : void
1767 : 176704489 : ix86_call_abi_override (const_tree fndecl)
1768 : : {
1769 : 176704489 : cfun->machine->call_abi = ix86_function_abi (fndecl);
1770 : 176704489 : }
1771 : :
1772 : : /* Return 1 if pseudo register should be created and used to hold
1773 : : GOT address for PIC code. */
1774 : : bool
1775 : 166751543 : ix86_use_pseudo_pic_reg (void)
1776 : : {
1777 : 166751543 : if ((TARGET_64BIT
1778 : 155808855 : && (ix86_cmodel == CM_SMALL_PIC
1779 : : || TARGET_PECOFF))
1780 : 161276727 : || !flag_pic)
1781 : 162053889 : return false;
1782 : : return true;
1783 : : }
1784 : :
1785 : : /* Initialize large model PIC register. */
1786 : :
1787 : : static void
1788 : 47 : ix86_init_large_pic_reg (unsigned int tmp_regno)
1789 : : {
1790 : 47 : rtx_code_label *label;
1791 : 47 : rtx tmp_reg;
1792 : :
1793 : 47 : gcc_assert (Pmode == DImode);
1794 : 47 : label = gen_label_rtx ();
1795 : 47 : emit_label (label);
1796 : 47 : LABEL_PRESERVE_P (label) = 1;
1797 : 47 : tmp_reg = gen_rtx_REG (Pmode, tmp_regno);
1798 : 47 : gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno);
1799 : 47 : emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx,
1800 : : label));
1801 : 47 : emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
1802 : 47 : emit_insn (gen_add2_insn (pic_offset_table_rtx, tmp_reg));
1803 : 47 : const char *name = LABEL_NAME (label);
1804 : 47 : PUT_CODE (label, NOTE);
1805 : 47 : NOTE_KIND (label) = NOTE_INSN_DELETED_LABEL;
1806 : 47 : NOTE_DELETED_LABEL_NAME (label) = name;
1807 : 47 : }
1808 : :
1809 : : /* Create and initialize PIC register if required. */
1810 : : static void
1811 : 1455682 : ix86_init_pic_reg (void)
1812 : : {
1813 : 1455682 : edge entry_edge;
1814 : 1455682 : rtx_insn *seq;
1815 : :
1816 : 1455682 : if (!ix86_use_pseudo_pic_reg ())
1817 : : return;
1818 : :
1819 : 39790 : start_sequence ();
1820 : :
1821 : 39790 : if (TARGET_64BIT)
1822 : : {
1823 : 60 : if (ix86_cmodel == CM_LARGE_PIC)
1824 : 44 : ix86_init_large_pic_reg (R11_REG);
1825 : : else
1826 : 16 : emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
1827 : : }
1828 : : else
1829 : : {
1830 : : /* If there is future mcount call in the function it is more profitable
1831 : : to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM. */
1832 : 39730 : rtx reg = crtl->profile
1833 : 39730 : ? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM)
1834 : 39730 : : pic_offset_table_rtx;
1835 : 39730 : rtx_insn *insn = emit_insn (gen_set_got (reg));
1836 : 39730 : RTX_FRAME_RELATED_P (insn) = 1;
1837 : 39730 : if (crtl->profile)
1838 : 0 : emit_move_insn (pic_offset_table_rtx, reg);
1839 : 39730 : add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
1840 : : }
1841 : :
1842 : 39790 : seq = end_sequence ();
1843 : :
1844 : 39790 : entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
1845 : 39790 : insert_insn_on_edge (seq, entry_edge);
1846 : 39790 : commit_one_edge_insertion (entry_edge);
1847 : : }
1848 : :
1849 : : /* Initialize a variable CUM of type CUMULATIVE_ARGS
1850 : : for a call to a function whose data type is FNTYPE.
1851 : : For a library call, FNTYPE is 0. */
1852 : :
1853 : : void
1854 : 10344680 : init_cumulative_args (CUMULATIVE_ARGS *cum, /* Argument info to initialize */
1855 : : tree fntype, /* tree ptr for function decl */
1856 : : rtx libname, /* SYMBOL_REF of library name or 0 */
1857 : : tree fndecl,
1858 : : int caller)
1859 : : {
1860 : 10344680 : struct cgraph_node *local_info_node = NULL;
1861 : 10344680 : struct cgraph_node *target = NULL;
1862 : :
1863 : : /* Set silent_p to false to raise an error for invalid calls when
1864 : : expanding function body. */
1865 : 10344680 : cfun->machine->silent_p = false;
1866 : :
1867 : 10344680 : memset (cum, 0, sizeof (*cum));
1868 : :
1869 : 10344680 : tree preserve_none_type;
1870 : 10344680 : if (fndecl)
1871 : : {
1872 : 9997297 : target = cgraph_node::get (fndecl);
1873 : 9997297 : if (target)
1874 : : {
1875 : 9860415 : target = target->function_symbol ();
1876 : 9860415 : local_info_node = cgraph_node::local_info_node (target->decl);
1877 : 9860415 : cum->call_abi = ix86_function_abi (target->decl);
1878 : 9860415 : preserve_none_type = TREE_TYPE (target->decl);
1879 : : }
1880 : : else
1881 : : {
1882 : 136882 : cum->call_abi = ix86_function_abi (fndecl);
1883 : 136882 : preserve_none_type = TREE_TYPE (fndecl);
1884 : : }
1885 : : }
1886 : : else
1887 : : {
1888 : 347383 : cum->call_abi = ix86_function_type_abi (fntype);
1889 : 347383 : preserve_none_type = fntype;
1890 : : }
1891 : 10344680 : cum->preserve_none_abi
1892 : 10344680 : = (preserve_none_type
1893 : 20569564 : && (lookup_attribute ("preserve_none",
1894 : 10224884 : TYPE_ATTRIBUTES (preserve_none_type))
1895 : : != nullptr));
1896 : :
1897 : 10344680 : cum->caller = caller;
1898 : :
1899 : : /* Set up the number of registers to use for passing arguments. */
1900 : 10344680 : cum->nregs = ix86_regparm;
1901 : 10344680 : if (TARGET_64BIT)
1902 : : {
1903 : 9318654 : cum->nregs = (cum->call_abi == SYSV_ABI
1904 : 9318654 : ? X86_64_REGPARM_MAX
1905 : : : X86_64_MS_REGPARM_MAX);
1906 : : }
1907 : 10344680 : if (TARGET_SSE)
1908 : : {
1909 : 10335631 : cum->sse_nregs = SSE_REGPARM_MAX;
1910 : 10335631 : if (TARGET_64BIT)
1911 : : {
1912 : 9309725 : cum->sse_nregs = (cum->call_abi == SYSV_ABI
1913 : 9309725 : ? X86_64_SSE_REGPARM_MAX
1914 : : : X86_64_MS_SSE_REGPARM_MAX);
1915 : : }
1916 : : }
1917 : 10344680 : if (TARGET_MMX)
1918 : 11158026 : cum->mmx_nregs = MMX_REGPARM_MAX;
1919 : 10344680 : cum->warn_avx512f = true;
1920 : 10344680 : cum->warn_avx = true;
1921 : 10344680 : cum->warn_sse = true;
1922 : 10344680 : cum->warn_mmx = true;
1923 : :
1924 : : /* Because type might mismatch in between caller and callee, we need to
1925 : : use actual type of function for local calls.
1926 : : FIXME: cgraph_analyze can be told to actually record if function uses
1927 : : va_start so for local functions maybe_vaarg can be made aggressive
1928 : : helping K&R code.
1929 : : FIXME: once typesytem is fixed, we won't need this code anymore. */
1930 : 10344680 : if (local_info_node && local_info_node->local
1931 : 402765 : && local_info_node->can_change_signature)
1932 : 379947 : fntype = TREE_TYPE (target->decl);
1933 : 10344680 : cum->stdarg = stdarg_p (fntype);
1934 : 20689360 : cum->maybe_vaarg = (fntype
1935 : 10810001 : ? (!prototype_p (fntype) || stdarg_p (fntype))
1936 : 119796 : : !libname);
1937 : :
1938 : 10344680 : cum->decl = fndecl;
1939 : :
1940 : 10344680 : cum->warn_empty = !warn_abi || cum->stdarg;
1941 : 10344680 : if (!cum->warn_empty && fntype)
1942 : : {
1943 : 2748976 : function_args_iterator iter;
1944 : 2748976 : tree argtype;
1945 : 2748976 : bool seen_empty_type = false;
1946 : 7704227 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
1947 : : {
1948 : 7704164 : if (argtype == error_mark_node || VOID_TYPE_P (argtype))
1949 : : break;
1950 : 4973273 : if (TYPE_EMPTY_P (argtype))
1951 : : seen_empty_type = true;
1952 : 4899143 : else if (seen_empty_type)
1953 : : {
1954 : 18022 : cum->warn_empty = true;
1955 : 18022 : break;
1956 : : }
1957 : : }
1958 : : }
1959 : :
1960 : 10344680 : if (!TARGET_64BIT)
1961 : : {
1962 : : /* If there are variable arguments, then we won't pass anything
1963 : : in registers in 32-bit mode. */
1964 : 1026026 : if (stdarg_p (fntype))
1965 : : {
1966 : 8873 : cum->nregs = 0;
1967 : : /* Since in 32-bit, variable arguments are always passed on
1968 : : stack, there is scratch register available for indirect
1969 : : sibcall. */
1970 : 8873 : cfun->machine->arg_reg_available = true;
1971 : 8873 : cum->sse_nregs = 0;
1972 : 8873 : cum->mmx_nregs = 0;
1973 : 8873 : cum->warn_avx512f = false;
1974 : 8873 : cum->warn_avx = false;
1975 : 8873 : cum->warn_sse = false;
1976 : 8873 : cum->warn_mmx = false;
1977 : 8873 : return;
1978 : : }
1979 : :
1980 : : /* Use ecx and edx registers if function has fastcall attribute,
1981 : : else look for regparm information. */
1982 : 1017153 : if (fntype)
1983 : : {
1984 : 1003909 : unsigned int ccvt = ix86_get_callcvt (fntype);
1985 : 1003909 : if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
1986 : : {
1987 : 0 : cum->nregs = 1;
1988 : 0 : cum->fastcall = 1; /* Same first register as in fastcall. */
1989 : : }
1990 : 1003909 : else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
1991 : : {
1992 : 4 : cum->nregs = 2;
1993 : 4 : cum->fastcall = 1;
1994 : : }
1995 : : else
1996 : 1003905 : cum->nregs = ix86_function_regparm (fntype, fndecl);
1997 : : }
1998 : :
1999 : : /* Set up the number of SSE registers used for passing SFmode
2000 : : and DFmode arguments. Warn for mismatching ABI. */
2001 : 1017153 : cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
2002 : : }
2003 : :
2004 : 10335807 : cfun->machine->arg_reg_available = (cum->nregs > 0);
2005 : : }
2006 : :
2007 : : /* Return the "natural" mode for TYPE. In most cases, this is just TYPE_MODE.
2008 : : But in the case of vector types, it is some vector mode.
2009 : :
2010 : : When we have only some of our vector isa extensions enabled, then there
2011 : : are some modes for which vector_mode_supported_p is false. For these
2012 : : modes, the generic vector support in gcc will choose some non-vector mode
2013 : : in order to implement the type. By computing the natural mode, we'll
2014 : : select the proper ABI location for the operand and not depend on whatever
2015 : : the middle-end decides to do with these vector types.
2016 : :
2017 : : The midde-end can't deal with the vector types > 16 bytes. In this
2018 : : case, we return the original mode and warn ABI change if CUM isn't
2019 : : NULL.
2020 : :
2021 : : If INT_RETURN is true, warn ABI change if the vector mode isn't
2022 : : available for function return value. */
2023 : :
2024 : : static machine_mode
2025 : 213812851 : type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum,
2026 : : bool in_return)
2027 : : {
2028 : 213812851 : machine_mode mode = TYPE_MODE (type);
2029 : :
2030 : 213812851 : if (VECTOR_TYPE_P (type) && !VECTOR_MODE_P (mode))
2031 : : {
2032 : 438609 : HOST_WIDE_INT size = int_size_in_bytes (type);
2033 : 438609 : if ((size == 8 || size == 16 || size == 32 || size == 64)
2034 : : /* ??? Generic code allows us to create width 1 vectors. Ignore. */
2035 : 438609 : && TYPE_VECTOR_SUBPARTS (type) > 1)
2036 : : {
2037 : 403853 : machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
2038 : :
2039 : : /* There are no XFmode vector modes ... */
2040 : 403853 : if (innermode == XFmode)
2041 : : return mode;
2042 : :
2043 : : /* ... and no decimal float vector modes. */
2044 : 403308 : if (DECIMAL_FLOAT_MODE_P (innermode))
2045 : : return mode;
2046 : :
2047 : 403019 : if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type)))
2048 : : mode = MIN_MODE_VECTOR_FLOAT;
2049 : : else
2050 : 338920 : mode = MIN_MODE_VECTOR_INT;
2051 : :
2052 : : /* Get the mode which has this inner mode and number of units. */
2053 : 8536214 : FOR_EACH_MODE_FROM (mode, mode)
2054 : 17743410 : if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
2055 : 9610215 : && GET_MODE_INNER (mode) == innermode)
2056 : : {
2057 : 403019 : if (size == 64 && !TARGET_AVX512F && !TARGET_IAMCU)
2058 : : {
2059 : 280547 : static bool warnedavx512f;
2060 : 280547 : static bool warnedavx512f_ret;
2061 : :
2062 : 280547 : if (cum && cum->warn_avx512f && !warnedavx512f)
2063 : : {
2064 : 1194 : if (warning (OPT_Wpsabi, "AVX512F vector argument "
2065 : : "without AVX512F enabled changes the ABI"))
2066 : 2 : warnedavx512f = true;
2067 : : }
2068 : 279353 : else if (in_return && !warnedavx512f_ret)
2069 : : {
2070 : 276647 : if (warning (OPT_Wpsabi, "AVX512F vector return "
2071 : : "without AVX512F enabled changes the ABI"))
2072 : 2 : warnedavx512f_ret = true;
2073 : : }
2074 : :
2075 : 280547 : return TYPE_MODE (type);
2076 : : }
2077 : 122472 : else if (size == 32 && !TARGET_AVX && !TARGET_IAMCU)
2078 : : {
2079 : 121923 : static bool warnedavx;
2080 : 121923 : static bool warnedavx_ret;
2081 : :
2082 : 121923 : if (cum && cum->warn_avx && !warnedavx)
2083 : : {
2084 : 601 : if (warning (OPT_Wpsabi, "AVX vector argument "
2085 : : "without AVX enabled changes the ABI"))
2086 : 5 : warnedavx = true;
2087 : : }
2088 : 121322 : else if (in_return && !warnedavx_ret)
2089 : : {
2090 : 119351 : if (warning (OPT_Wpsabi, "AVX vector return "
2091 : : "without AVX enabled changes the ABI"))
2092 : 7 : warnedavx_ret = true;
2093 : : }
2094 : :
2095 : 121923 : return TYPE_MODE (type);
2096 : : }
2097 : 549 : else if (((size == 8 && TARGET_64BIT) || size == 16)
2098 : 546 : && !TARGET_SSE
2099 : 140 : && !TARGET_IAMCU)
2100 : : {
2101 : 140 : static bool warnedsse;
2102 : 140 : static bool warnedsse_ret;
2103 : :
2104 : 140 : if (cum && cum->warn_sse && !warnedsse)
2105 : : {
2106 : 19 : if (warning (OPT_Wpsabi, "SSE vector argument "
2107 : : "without SSE enabled changes the ABI"))
2108 : 6 : warnedsse = true;
2109 : : }
2110 : 121 : else if (!TARGET_64BIT && in_return && !warnedsse_ret)
2111 : : {
2112 : 0 : if (warning (OPT_Wpsabi, "SSE vector return "
2113 : : "without SSE enabled changes the ABI"))
2114 : 0 : warnedsse_ret = true;
2115 : : }
2116 : : }
2117 : 409 : else if ((size == 8 && !TARGET_64BIT)
2118 : 0 : && (!cfun
2119 : 0 : || cfun->machine->func_type == TYPE_NORMAL)
2120 : 0 : && !TARGET_MMX
2121 : 0 : && !TARGET_IAMCU)
2122 : : {
2123 : 0 : static bool warnedmmx;
2124 : 0 : static bool warnedmmx_ret;
2125 : :
2126 : 0 : if (cum && cum->warn_mmx && !warnedmmx)
2127 : : {
2128 : 0 : if (warning (OPT_Wpsabi, "MMX vector argument "
2129 : : "without MMX enabled changes the ABI"))
2130 : 0 : warnedmmx = true;
2131 : : }
2132 : 0 : else if (in_return && !warnedmmx_ret)
2133 : : {
2134 : 0 : if (warning (OPT_Wpsabi, "MMX vector return "
2135 : : "without MMX enabled changes the ABI"))
2136 : 0 : warnedmmx_ret = true;
2137 : : }
2138 : : }
2139 : 549 : return mode;
2140 : : }
2141 : :
2142 : 0 : gcc_unreachable ();
2143 : : }
2144 : : }
2145 : :
2146 : : return mode;
2147 : : }
2148 : :
2149 : : /* We want to pass a value in REGNO whose "natural" mode is MODE. However,
2150 : : this may not agree with the mode that the type system has chosen for the
2151 : : register, which is ORIG_MODE. If ORIG_MODE is not BLKmode, then we can
2152 : : go ahead and use it. Otherwise we have to build a PARALLEL instead. */
2153 : :
2154 : : static rtx
2155 : 35615400 : gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode,
2156 : : unsigned int regno)
2157 : : {
2158 : 35615400 : rtx tmp;
2159 : :
2160 : 35615400 : if (orig_mode != BLKmode)
2161 : 35615372 : tmp = gen_rtx_REG (orig_mode, regno);
2162 : : else
2163 : : {
2164 : 28 : tmp = gen_rtx_REG (mode, regno);
2165 : 28 : tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
2166 : 28 : tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
2167 : : }
2168 : :
2169 : 35615400 : return tmp;
2170 : : }
2171 : :
2172 : : /* x86-64 register passing implementation. See x86-64 ABI for details. Goal
2173 : : of this code is to classify each 8bytes of incoming argument by the register
2174 : : class and assign registers accordingly. */
2175 : :
2176 : : /* Return the union class of CLASS1 and CLASS2.
2177 : : See the x86-64 PS ABI for details. */
2178 : :
2179 : : static enum x86_64_reg_class
2180 : 42586207 : merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
2181 : : {
2182 : : /* Rule #1: If both classes are equal, this is the resulting class. */
2183 : 42035650 : if (class1 == class2)
2184 : : return class1;
2185 : :
2186 : : /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
2187 : : the other class. */
2188 : 37236745 : if (class1 == X86_64_NO_CLASS)
2189 : : return class2;
2190 : 37474176 : if (class2 == X86_64_NO_CLASS)
2191 : : return class1;
2192 : :
2193 : : /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
2194 : 1696905 : if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
2195 : : return X86_64_MEMORY_CLASS;
2196 : :
2197 : : /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
2198 : 1442705 : if ((class1 == X86_64_INTEGERSI_CLASS
2199 : 192779 : && (class2 == X86_64_SSESF_CLASS || class2 == X86_64_SSEHF_CLASS))
2200 : 1441499 : || (class2 == X86_64_INTEGERSI_CLASS
2201 : 663489 : && (class1 == X86_64_SSESF_CLASS || class1 == X86_64_SSEHF_CLASS)))
2202 : : return X86_64_INTEGERSI_CLASS;
2203 : 1437683 : if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
2204 : 568473 : || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
2205 : : return X86_64_INTEGER_CLASS;
2206 : :
2207 : : /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
2208 : : MEMORY is used. */
2209 : 111101 : if (class1 == X86_64_X87_CLASS
2210 : : || class1 == X86_64_X87UP_CLASS
2211 : 111101 : || class1 == X86_64_COMPLEX_X87_CLASS
2212 : : || class2 == X86_64_X87_CLASS
2213 : 110196 : || class2 == X86_64_X87UP_CLASS
2214 : 59006 : || class2 == X86_64_COMPLEX_X87_CLASS)
2215 : 52095 : return X86_64_MEMORY_CLASS;
2216 : :
2217 : : /* Rule #6: Otherwise class SSE is used. */
2218 : : return X86_64_SSE_CLASS;
2219 : : }
2220 : :
2221 : : /* Classify the argument of type TYPE and mode MODE.
2222 : : CLASSES will be filled by the register class used to pass each word
2223 : : of the operand. The number of words is returned. In case the parameter
2224 : : should be passed in memory, 0 is returned. As a special case for zero
2225 : : sized containers, classes[0] will be NO_CLASS and 1 is returned.
2226 : :
2227 : : BIT_OFFSET is used internally for handling records and specifies offset
2228 : : of the offset in bits modulo 512 to avoid overflow cases.
2229 : :
2230 : : See the x86-64 PS ABI for details.
2231 : : */
2232 : :
2233 : : static int
2234 : 357964792 : classify_argument (machine_mode mode, const_tree type,
2235 : : enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset,
2236 : : int &zero_width_bitfields)
2237 : : {
2238 : 357964792 : HOST_WIDE_INT bytes
2239 : 710883791 : = mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
2240 : 357964792 : int words = CEIL (bytes + (bit_offset % 64) / 8, UNITS_PER_WORD);
2241 : :
2242 : : /* Variable sized entities are always passed/returned in memory. */
2243 : 357964792 : if (bytes < 0)
2244 : : return 0;
2245 : :
2246 : 357963635 : if (mode != VOIDmode)
2247 : : {
2248 : : /* The value of "named" doesn't matter. */
2249 : 357000689 : function_arg_info arg (const_cast<tree> (type), mode, /*named=*/true);
2250 : 357000689 : if (targetm.calls.must_pass_in_stack (arg))
2251 : 37 : return 0;
2252 : : }
2253 : :
2254 : 357963598 : if (type && (AGGREGATE_TYPE_P (type)
2255 : 332042339 : || (TREE_CODE (type) == BITINT_TYPE && words > 1)))
2256 : : {
2257 : 26975495 : int i;
2258 : 26975495 : tree field;
2259 : 26975495 : enum x86_64_reg_class subclasses[MAX_CLASSES];
2260 : :
2261 : : /* On x86-64 we pass structures larger than 64 bytes on the stack. */
2262 : 26975495 : if (bytes > 64)
2263 : : return 0;
2264 : :
2265 : 70062307 : for (i = 0; i < words; i++)
2266 : 43883136 : classes[i] = X86_64_NO_CLASS;
2267 : :
2268 : : /* Zero sized arrays or structures are NO_CLASS. We return 0 to
2269 : : signalize memory class, so handle it as special case. */
2270 : 26179171 : if (!words)
2271 : : {
2272 : 74348 : classes[0] = X86_64_NO_CLASS;
2273 : 74348 : return 1;
2274 : : }
2275 : :
2276 : : /* Classify each field of record and merge classes. */
2277 : 26104823 : switch (TREE_CODE (type))
2278 : : {
2279 : 24105167 : case RECORD_TYPE:
2280 : : /* And now merge the fields of structure. */
2281 : 624413607 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2282 : : {
2283 : 600593540 : if (TREE_CODE (field) == FIELD_DECL)
2284 : : {
2285 : 37149195 : int num;
2286 : :
2287 : 37149195 : if (TREE_TYPE (field) == error_mark_node)
2288 : 4 : continue;
2289 : :
2290 : : /* Bitfields are always classified as integer. Handle them
2291 : : early, since later code would consider them to be
2292 : : misaligned integers. */
2293 : 37149191 : if (DECL_BIT_FIELD (field))
2294 : : {
2295 : 559818 : if (integer_zerop (DECL_SIZE (field)))
2296 : : {
2297 : 12902 : if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field))
2298 : 8048 : continue;
2299 : 4854 : if (zero_width_bitfields != 2)
2300 : : {
2301 : 4320 : zero_width_bitfields = 1;
2302 : 4320 : continue;
2303 : : }
2304 : : }
2305 : 547450 : for (i = (int_bit_position (field)
2306 : 547450 : + (bit_offset % 64)) / 8 / 8;
2307 : 1098007 : i < ((int_bit_position (field) + (bit_offset % 64))
2308 : 1098007 : + tree_to_shwi (DECL_SIZE (field))
2309 : 1098007 : + 63) / 8 / 8; i++)
2310 : 550557 : classes[i]
2311 : 1101114 : = merge_classes (X86_64_INTEGER_CLASS, classes[i]);
2312 : : }
2313 : : else
2314 : : {
2315 : 36589373 : int pos;
2316 : :
2317 : 36589373 : type = TREE_TYPE (field);
2318 : :
2319 : : /* Flexible array member is ignored. */
2320 : 36589373 : if (TYPE_MODE (type) == BLKmode
2321 : 413723 : && TREE_CODE (type) == ARRAY_TYPE
2322 : 166615 : && TYPE_SIZE (type) == NULL_TREE
2323 : 2004 : && TYPE_DOMAIN (type) != NULL_TREE
2324 : 36590618 : && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
2325 : : == NULL_TREE))
2326 : : {
2327 : 1245 : static bool warned;
2328 : :
2329 : 1245 : if (!warned && warn_psabi)
2330 : : {
2331 : 2 : warned = true;
2332 : 2 : inform (input_location,
2333 : : "the ABI of passing struct with"
2334 : : " a flexible array member has"
2335 : : " changed in GCC 4.4");
2336 : : }
2337 : 1245 : continue;
2338 : 1245 : }
2339 : 36588128 : num = classify_argument (TYPE_MODE (type), type,
2340 : : subclasses,
2341 : 36588128 : (int_bit_position (field)
2342 : 36588128 : + bit_offset) % 512,
2343 : : zero_width_bitfields);
2344 : 36588128 : if (!num)
2345 : : return 0;
2346 : 36303028 : pos = (int_bit_position (field)
2347 : 36303028 : + (bit_offset % 64)) / 8 / 8;
2348 : 75835681 : for (i = 0; i < num && (i + pos) < words; i++)
2349 : 39532653 : classes[i + pos]
2350 : 39532653 : = merge_classes (subclasses[i], classes[i + pos]);
2351 : : }
2352 : : }
2353 : : }
2354 : : break;
2355 : :
2356 : 427856 : case ARRAY_TYPE:
2357 : : /* Arrays are handled as small records. */
2358 : 427856 : {
2359 : 427856 : int num;
2360 : 427856 : num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
2361 : 427856 : TREE_TYPE (type), subclasses, bit_offset,
2362 : : zero_width_bitfields);
2363 : 427856 : if (!num)
2364 : : return 0;
2365 : :
2366 : : /* The partial classes are now full classes. */
2367 : 407568 : if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
2368 : 13565 : subclasses[0] = X86_64_SSE_CLASS;
2369 : 407568 : if (subclasses[0] == X86_64_SSEHF_CLASS && bytes != 2)
2370 : 4734 : subclasses[0] = X86_64_SSE_CLASS;
2371 : 407568 : if (subclasses[0] == X86_64_INTEGERSI_CLASS
2372 : 229331 : && !((bit_offset % 64) == 0 && bytes == 4))
2373 : 123596 : subclasses[0] = X86_64_INTEGER_CLASS;
2374 : :
2375 : 1252581 : for (i = 0; i < words; i++)
2376 : 845013 : classes[i] = subclasses[i % num];
2377 : :
2378 : : break;
2379 : : }
2380 : 290148 : case UNION_TYPE:
2381 : 290148 : case QUAL_UNION_TYPE:
2382 : : /* Unions are similar to RECORD_TYPE but offset is always 0.
2383 : : */
2384 : 3530964 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2385 : : {
2386 : 3274445 : if (TREE_CODE (field) == FIELD_DECL)
2387 : : {
2388 : 1662231 : int num;
2389 : :
2390 : 1662231 : if (TREE_TYPE (field) == error_mark_node)
2391 : 10 : continue;
2392 : :
2393 : 1662221 : num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
2394 : 1662221 : TREE_TYPE (field), subclasses,
2395 : : bit_offset, zero_width_bitfields);
2396 : 1662221 : if (!num)
2397 : : return 0;
2398 : 4131589 : for (i = 0; i < num && i < words; i++)
2399 : 2502997 : classes[i] = merge_classes (subclasses[i], classes[i]);
2400 : : }
2401 : : }
2402 : : break;
2403 : :
2404 : 1281652 : case BITINT_TYPE:
2405 : : /* _BitInt(N) for N > 64 is passed as structure containing
2406 : : (N + 63) / 64 64-bit elements. */
2407 : 1281652 : if (words > 2)
2408 : : return 0;
2409 : 74983 : classes[0] = classes[1] = X86_64_INTEGER_CLASS;
2410 : 74983 : return 2;
2411 : :
2412 : 0 : default:
2413 : 0 : gcc_unreachable ();
2414 : : }
2415 : :
2416 : 24484154 : if (words > 2)
2417 : : {
2418 : : /* When size > 16 bytes, if the first one isn't
2419 : : X86_64_SSE_CLASS or any other ones aren't
2420 : : X86_64_SSEUP_CLASS, everything should be passed in
2421 : : memory. */
2422 : 1140677 : if (classes[0] != X86_64_SSE_CLASS)
2423 : : return 0;
2424 : :
2425 : 192787 : for (i = 1; i < words; i++)
2426 : 174598 : if (classes[i] != X86_64_SSEUP_CLASS)
2427 : : return 0;
2428 : : }
2429 : :
2430 : : /* Final merger cleanup. */
2431 : 57417073 : for (i = 0; i < words; i++)
2432 : : {
2433 : : /* If one class is MEMORY, everything should be passed in
2434 : : memory. */
2435 : 34109159 : if (classes[i] == X86_64_MEMORY_CLASS)
2436 : : return 0;
2437 : :
2438 : : /* The X86_64_SSEUP_CLASS should be always preceded by
2439 : : X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. */
2440 : 34057777 : if (classes[i] == X86_64_SSEUP_CLASS
2441 : 148540 : && classes[i - 1] != X86_64_SSE_CLASS
2442 : 76550 : && classes[i - 1] != X86_64_SSEUP_CLASS)
2443 : : {
2444 : : /* The first one should never be X86_64_SSEUP_CLASS. */
2445 : 1916 : gcc_assert (i != 0);
2446 : 1916 : classes[i] = X86_64_SSE_CLASS;
2447 : : }
2448 : :
2449 : : /* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
2450 : : everything should be passed in memory. */
2451 : 34057777 : if (classes[i] == X86_64_X87UP_CLASS
2452 : 191404 : && (classes[i - 1] != X86_64_X87_CLASS))
2453 : : {
2454 : 2370 : static bool warned;
2455 : :
2456 : : /* The first one should never be X86_64_X87UP_CLASS. */
2457 : 2370 : gcc_assert (i != 0);
2458 : 2370 : if (!warned && warn_psabi)
2459 : : {
2460 : 1 : warned = true;
2461 : 1 : inform (input_location,
2462 : : "the ABI of passing union with %<long double%>"
2463 : : " has changed in GCC 4.4");
2464 : : }
2465 : 2370 : return 0;
2466 : : }
2467 : : }
2468 : : return words;
2469 : : }
2470 : :
2471 : : /* Compute alignment needed. We align all types to natural boundaries with
2472 : : exception of XFmode that is aligned to 64bits. */
2473 : 330988103 : if (mode != VOIDmode && mode != BLKmode)
2474 : : {
2475 : 329589705 : int mode_alignment = GET_MODE_BITSIZE (mode);
2476 : :
2477 : 329589705 : if (mode == XFmode)
2478 : : mode_alignment = 128;
2479 : 322452154 : else if (mode == XCmode)
2480 : 561579 : mode_alignment = 256;
2481 : 329589705 : if (COMPLEX_MODE_P (mode))
2482 : 2494654 : mode_alignment /= 2;
2483 : : /* Misaligned fields are always returned in memory. */
2484 : 329589705 : if (bit_offset % mode_alignment)
2485 : : return 0;
2486 : : }
2487 : :
2488 : : /* for V1xx modes, just use the base mode */
2489 : 330980470 : if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode
2490 : 421547216 : && GET_MODE_UNIT_SIZE (mode) == bytes)
2491 : 5360 : mode = GET_MODE_INNER (mode);
2492 : :
2493 : : /* Classification of atomic types. */
2494 : 330980470 : switch (mode)
2495 : : {
2496 : 208774 : case E_SDmode:
2497 : 208774 : case E_DDmode:
2498 : 208774 : classes[0] = X86_64_SSE_CLASS;
2499 : 208774 : return 1;
2500 : 99178 : case E_TDmode:
2501 : 99178 : classes[0] = X86_64_SSE_CLASS;
2502 : 99178 : classes[1] = X86_64_SSEUP_CLASS;
2503 : 99178 : return 2;
2504 : 210722012 : case E_DImode:
2505 : 210722012 : case E_SImode:
2506 : 210722012 : case E_HImode:
2507 : 210722012 : case E_QImode:
2508 : 210722012 : case E_CSImode:
2509 : 210722012 : case E_CHImode:
2510 : 210722012 : case E_CQImode:
2511 : 210722012 : {
2512 : 210722012 : int size = bit_offset + (int) GET_MODE_BITSIZE (mode);
2513 : :
2514 : : /* Analyze last 128 bits only. */
2515 : 210722012 : size = (size - 1) & 0x7f;
2516 : :
2517 : 210722012 : if (size < 32)
2518 : : {
2519 : 90632966 : classes[0] = X86_64_INTEGERSI_CLASS;
2520 : 90632966 : return 1;
2521 : : }
2522 : 120089046 : else if (size < 64)
2523 : : {
2524 : 110060489 : classes[0] = X86_64_INTEGER_CLASS;
2525 : 110060489 : return 1;
2526 : : }
2527 : 10028557 : else if (size < 64+32)
2528 : : {
2529 : 4265098 : classes[0] = X86_64_INTEGER_CLASS;
2530 : 4265098 : classes[1] = X86_64_INTEGERSI_CLASS;
2531 : 4265098 : return 2;
2532 : : }
2533 : 5763459 : else if (size < 64+64)
2534 : : {
2535 : 5763459 : classes[0] = classes[1] = X86_64_INTEGER_CLASS;
2536 : 5763459 : return 2;
2537 : : }
2538 : : else
2539 : : gcc_unreachable ();
2540 : : }
2541 : 1850601 : case E_CDImode:
2542 : 1850601 : case E_TImode:
2543 : 1850601 : classes[0] = classes[1] = X86_64_INTEGER_CLASS;
2544 : 1850601 : return 2;
2545 : 0 : case E_COImode:
2546 : 0 : case E_OImode:
2547 : : /* OImode shouldn't be used directly. */
2548 : 0 : gcc_unreachable ();
2549 : : case E_CTImode:
2550 : : return 0;
2551 : 1094400 : case E_HFmode:
2552 : 1094400 : case E_BFmode:
2553 : 1094400 : if (!(bit_offset % 64))
2554 : 1092140 : classes[0] = X86_64_SSEHF_CLASS;
2555 : : else
2556 : 2260 : classes[0] = X86_64_SSE_CLASS;
2557 : : return 1;
2558 : 9995137 : case E_SFmode:
2559 : 9995137 : if (!(bit_offset % 64))
2560 : 9942275 : classes[0] = X86_64_SSESF_CLASS;
2561 : : else
2562 : 52862 : classes[0] = X86_64_SSE_CLASS;
2563 : : return 1;
2564 : 4300356 : case E_DFmode:
2565 : 4300356 : classes[0] = X86_64_SSEDF_CLASS;
2566 : 4300356 : return 1;
2567 : 7136835 : case E_XFmode:
2568 : 7136835 : classes[0] = X86_64_X87_CLASS;
2569 : 7136835 : classes[1] = X86_64_X87UP_CLASS;
2570 : 7136835 : return 2;
2571 : 1306132 : case E_TFmode:
2572 : 1306132 : classes[0] = X86_64_SSE_CLASS;
2573 : 1306132 : classes[1] = X86_64_SSEUP_CLASS;
2574 : 1306132 : return 2;
2575 : 145054 : case E_HCmode:
2576 : 145054 : case E_BCmode:
2577 : 145054 : classes[0] = X86_64_SSE_CLASS;
2578 : 145054 : if (!(bit_offset % 64))
2579 : : return 1;
2580 : : else
2581 : : {
2582 : 98 : classes[1] = X86_64_SSEHF_CLASS;
2583 : 98 : return 2;
2584 : : }
2585 : 736581 : case E_SCmode:
2586 : 736581 : classes[0] = X86_64_SSE_CLASS;
2587 : 736581 : if (!(bit_offset % 64))
2588 : : return 1;
2589 : : else
2590 : : {
2591 : 1041 : static bool warned;
2592 : :
2593 : 1041 : if (!warned && warn_psabi)
2594 : : {
2595 : 1 : warned = true;
2596 : 1 : inform (input_location,
2597 : : "the ABI of passing structure with %<complex float%>"
2598 : : " member has changed in GCC 4.4");
2599 : : }
2600 : 1041 : classes[1] = X86_64_SSESF_CLASS;
2601 : 1041 : return 2;
2602 : : }
2603 : 747746 : case E_DCmode:
2604 : 747746 : classes[0] = X86_64_SSEDF_CLASS;
2605 : 747746 : classes[1] = X86_64_SSEDF_CLASS;
2606 : 747746 : return 2;
2607 : 561579 : case E_XCmode:
2608 : 561579 : classes[0] = X86_64_COMPLEX_X87_CLASS;
2609 : 561579 : return 1;
2610 : : case E_TCmode:
2611 : : /* This modes is larger than 16 bytes. */
2612 : : return 0;
2613 : 24538571 : case E_V8SFmode:
2614 : 24538571 : case E_V8SImode:
2615 : 24538571 : case E_V32QImode:
2616 : 24538571 : case E_V16HFmode:
2617 : 24538571 : case E_V16BFmode:
2618 : 24538571 : case E_V16HImode:
2619 : 24538571 : case E_V4DFmode:
2620 : 24538571 : case E_V4DImode:
2621 : 24538571 : classes[0] = X86_64_SSE_CLASS;
2622 : 24538571 : classes[1] = X86_64_SSEUP_CLASS;
2623 : 24538571 : classes[2] = X86_64_SSEUP_CLASS;
2624 : 24538571 : classes[3] = X86_64_SSEUP_CLASS;
2625 : 24538571 : return 4;
2626 : 26638113 : case E_V8DFmode:
2627 : 26638113 : case E_V16SFmode:
2628 : 26638113 : case E_V32HFmode:
2629 : 26638113 : case E_V32BFmode:
2630 : 26638113 : case E_V8DImode:
2631 : 26638113 : case E_V16SImode:
2632 : 26638113 : case E_V32HImode:
2633 : 26638113 : case E_V64QImode:
2634 : 26638113 : classes[0] = X86_64_SSE_CLASS;
2635 : 26638113 : classes[1] = X86_64_SSEUP_CLASS;
2636 : 26638113 : classes[2] = X86_64_SSEUP_CLASS;
2637 : 26638113 : classes[3] = X86_64_SSEUP_CLASS;
2638 : 26638113 : classes[4] = X86_64_SSEUP_CLASS;
2639 : 26638113 : classes[5] = X86_64_SSEUP_CLASS;
2640 : 26638113 : classes[6] = X86_64_SSEUP_CLASS;
2641 : 26638113 : classes[7] = X86_64_SSEUP_CLASS;
2642 : 26638113 : return 8;
2643 : 36188608 : case E_V4SFmode:
2644 : 36188608 : case E_V4SImode:
2645 : 36188608 : case E_V16QImode:
2646 : 36188608 : case E_V8HImode:
2647 : 36188608 : case E_V8HFmode:
2648 : 36188608 : case E_V8BFmode:
2649 : 36188608 : case E_V2DFmode:
2650 : 36188608 : case E_V2DImode:
2651 : 36188608 : classes[0] = X86_64_SSE_CLASS;
2652 : 36188608 : classes[1] = X86_64_SSEUP_CLASS;
2653 : 36188608 : return 2;
2654 : 3178643 : case E_V1TImode:
2655 : 3178643 : case E_V1DImode:
2656 : 3178643 : case E_V2SFmode:
2657 : 3178643 : case E_V2SImode:
2658 : 3178643 : case E_V4HImode:
2659 : 3178643 : case E_V4HFmode:
2660 : 3178643 : case E_V4BFmode:
2661 : 3178643 : case E_V2HFmode:
2662 : 3178643 : case E_V2BFmode:
2663 : 3178643 : case E_V8QImode:
2664 : 3178643 : classes[0] = X86_64_SSE_CLASS;
2665 : 3178643 : return 1;
2666 : : case E_BLKmode:
2667 : : case E_VOIDmode:
2668 : : return 0;
2669 : 37170 : default:
2670 : 37170 : gcc_assert (VECTOR_MODE_P (mode));
2671 : :
2672 : 37170 : if (bytes > 16)
2673 : : return 0;
2674 : :
2675 : 45432 : gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
2676 : :
2677 : 45432 : if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
2678 : 22276 : classes[0] = X86_64_INTEGERSI_CLASS;
2679 : : else
2680 : 440 : classes[0] = X86_64_INTEGER_CLASS;
2681 : 22716 : classes[1] = X86_64_INTEGER_CLASS;
2682 : 22716 : return 1 + (bytes > 8);
2683 : : }
2684 : : }
2685 : :
2686 : : /* Wrapper around classify_argument with the extra zero_width_bitfields
2687 : : argument, to diagnose GCC 12.1 ABI differences for C. */
2688 : :
2689 : : static int
2690 : 319286053 : classify_argument (machine_mode mode, const_tree type,
2691 : : enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
2692 : : {
2693 : 319286053 : int zero_width_bitfields = 0;
2694 : 319286053 : static bool warned = false;
2695 : 319286053 : int n = classify_argument (mode, type, classes, bit_offset,
2696 : : zero_width_bitfields);
2697 : 319286053 : if (!zero_width_bitfields || warned || !warn_psabi)
2698 : : return n;
2699 : 534 : enum x86_64_reg_class alt_classes[MAX_CLASSES];
2700 : 534 : zero_width_bitfields = 2;
2701 : 534 : if (classify_argument (mode, type, alt_classes, bit_offset,
2702 : : zero_width_bitfields) != n)
2703 : 0 : zero_width_bitfields = 3;
2704 : : else
2705 : 1286 : for (int i = 0; i < n; i++)
2706 : 760 : if (classes[i] != alt_classes[i])
2707 : : {
2708 : 8 : zero_width_bitfields = 3;
2709 : 8 : break;
2710 : : }
2711 : 534 : if (zero_width_bitfields == 3)
2712 : : {
2713 : 8 : warned = true;
2714 : 8 : const char *url
2715 : : = CHANGES_ROOT_URL "gcc-12/changes.html#zero_width_bitfields";
2716 : :
2717 : 8 : inform (input_location,
2718 : : "the ABI of passing C structures with zero-width bit-fields"
2719 : : " has changed in GCC %{12.1%}", url);
2720 : : }
2721 : : return n;
2722 : : }
2723 : :
2724 : : /* Examine the argument and return set number of register required in each
2725 : : class. Return true iff parameter should be passed in memory. */
2726 : :
2727 : : static bool
2728 : 214779098 : examine_argument (machine_mode mode, const_tree type, int in_return,
2729 : : int *int_nregs, int *sse_nregs)
2730 : : {
2731 : 214779098 : enum x86_64_reg_class regclass[MAX_CLASSES];
2732 : 214779098 : int n = classify_argument (mode, type, regclass, 0);
2733 : :
2734 : 214779098 : *int_nregs = 0;
2735 : 214779098 : *sse_nregs = 0;
2736 : :
2737 : 214779098 : if (!n)
2738 : : return true;
2739 : 630982180 : for (n--; n >= 0; n--)
2740 : 420546542 : switch (regclass[n])
2741 : : {
2742 : 139735320 : case X86_64_INTEGER_CLASS:
2743 : 139735320 : case X86_64_INTEGERSI_CLASS:
2744 : 139735320 : (*int_nregs)++;
2745 : 139735320 : break;
2746 : 72848966 : case X86_64_SSE_CLASS:
2747 : 72848966 : case X86_64_SSEHF_CLASS:
2748 : 72848966 : case X86_64_SSESF_CLASS:
2749 : 72848966 : case X86_64_SSEDF_CLASS:
2750 : 72848966 : (*sse_nregs)++;
2751 : 72848966 : break;
2752 : : case X86_64_NO_CLASS:
2753 : : case X86_64_SSEUP_CLASS:
2754 : : break;
2755 : 9657396 : case X86_64_X87_CLASS:
2756 : 9657396 : case X86_64_X87UP_CLASS:
2757 : 9657396 : case X86_64_COMPLEX_X87_CLASS:
2758 : 9657396 : if (!in_return)
2759 : : return true;
2760 : : break;
2761 : 0 : case X86_64_MEMORY_CLASS:
2762 : 0 : gcc_unreachable ();
2763 : : }
2764 : :
2765 : : return false;
2766 : : }
2767 : :
2768 : : /* Construct container for the argument used by GCC interface. See
2769 : : FUNCTION_ARG for the detailed description. */
2770 : :
2771 : : static rtx
2772 : 104506955 : construct_container (machine_mode mode, machine_mode orig_mode,
2773 : : const_tree type, int in_return, int nintregs, int nsseregs,
2774 : : const int *intreg, int sse_regno)
2775 : : {
2776 : : /* The following variables hold the static issued_error state. */
2777 : 104506955 : static bool issued_sse_arg_error;
2778 : 104506955 : static bool issued_sse_ret_error;
2779 : 104506955 : static bool issued_x87_ret_error;
2780 : :
2781 : 104506955 : machine_mode tmpmode;
2782 : 104506955 : int bytes
2783 : 208428102 : = mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
2784 : 104506955 : enum x86_64_reg_class regclass[MAX_CLASSES];
2785 : 104506955 : int n;
2786 : 104506955 : int i;
2787 : 104506955 : int nexps = 0;
2788 : 104506955 : int needed_sseregs, needed_intregs;
2789 : 104506955 : rtx exp[MAX_CLASSES];
2790 : 104506955 : rtx ret;
2791 : :
2792 : 104506955 : n = classify_argument (mode, type, regclass, 0);
2793 : 104506955 : if (!n)
2794 : : return NULL;
2795 : 104055601 : if (examine_argument (mode, type, in_return, &needed_intregs,
2796 : : &needed_sseregs))
2797 : : return NULL;
2798 : 104007339 : if (needed_intregs > nintregs || needed_sseregs > nsseregs)
2799 : : return NULL;
2800 : :
2801 : : /* We allowed the user to turn off SSE for kernel mode. Don't crash if
2802 : : some less clueful developer tries to use floating-point anyway. */
2803 : 102913291 : if (needed_sseregs
2804 : 35975449 : && (!TARGET_SSE || (VALID_SSE2_TYPE_MODE (mode) && !TARGET_SSE2)))
2805 : : {
2806 : : /* Return early if we shouldn't raise an error for invalid
2807 : : calls. */
2808 : 71 : if (cfun != NULL && cfun->machine->silent_p)
2809 : : return NULL;
2810 : 39 : if (in_return)
2811 : : {
2812 : 34 : if (!issued_sse_ret_error)
2813 : : {
2814 : 16 : if (VALID_SSE2_TYPE_MODE (mode))
2815 : 5 : error ("SSE register return with SSE2 disabled");
2816 : : else
2817 : 11 : error ("SSE register return with SSE disabled");
2818 : 16 : issued_sse_ret_error = true;
2819 : : }
2820 : : }
2821 : 5 : else if (!issued_sse_arg_error)
2822 : : {
2823 : 5 : if (VALID_SSE2_TYPE_MODE (mode))
2824 : 0 : error ("SSE register argument with SSE2 disabled");
2825 : : else
2826 : 5 : error ("SSE register argument with SSE disabled");
2827 : 5 : issued_sse_arg_error = true;
2828 : : }
2829 : 39 : return NULL;
2830 : : }
2831 : :
2832 : : /* Likewise, error if the ABI requires us to return values in the
2833 : : x87 registers and the user specified -mno-80387. */
2834 : 102913220 : if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return)
2835 : 1387400 : for (i = 0; i < n; i++)
2836 : 733204 : if (regclass[i] == X86_64_X87_CLASS
2837 : : || regclass[i] == X86_64_X87UP_CLASS
2838 : 733204 : || regclass[i] == X86_64_COMPLEX_X87_CLASS)
2839 : : {
2840 : : /* Return early if we shouldn't raise an error for invalid
2841 : : calls. */
2842 : 14 : if (cfun != NULL && cfun->machine->silent_p)
2843 : : return NULL;
2844 : 11 : if (!issued_x87_ret_error)
2845 : : {
2846 : 6 : error ("x87 register return with x87 disabled");
2847 : 6 : issued_x87_ret_error = true;
2848 : : }
2849 : 11 : return NULL;
2850 : : }
2851 : :
2852 : : /* First construct simple cases. Avoid SCmode, since we want to use
2853 : : single register to pass this type. */
2854 : 102913206 : if (n == 1 && mode != SCmode && mode != HCmode)
2855 : 67191217 : switch (regclass[0])
2856 : : {
2857 : 61050540 : case X86_64_INTEGER_CLASS:
2858 : 61050540 : case X86_64_INTEGERSI_CLASS:
2859 : 61050540 : return gen_rtx_REG (mode, intreg[0]);
2860 : 5938582 : case X86_64_SSE_CLASS:
2861 : 5938582 : case X86_64_SSEHF_CLASS:
2862 : 5938582 : case X86_64_SSESF_CLASS:
2863 : 5938582 : case X86_64_SSEDF_CLASS:
2864 : 5938582 : if (mode != BLKmode)
2865 : 11876356 : return gen_reg_or_parallel (mode, orig_mode,
2866 : 11876356 : GET_SSE_REGNO (sse_regno));
2867 : : break;
2868 : 173707 : case X86_64_X87_CLASS:
2869 : 173707 : case X86_64_COMPLEX_X87_CLASS:
2870 : 173707 : return gen_rtx_REG (mode, FIRST_STACK_REG);
2871 : : case X86_64_NO_CLASS:
2872 : : /* Zero sized array, struct or class. */
2873 : : return NULL;
2874 : 0 : default:
2875 : 0 : gcc_unreachable ();
2876 : : }
2877 : 35722393 : if (n == 2
2878 : 18445694 : && regclass[0] == X86_64_SSE_CLASS
2879 : 12496734 : && regclass[1] == X86_64_SSEUP_CLASS
2880 : 12492000 : && mode != BLKmode)
2881 : 24984000 : return gen_reg_or_parallel (mode, orig_mode,
2882 : 24984000 : GET_SSE_REGNO (sse_regno));
2883 : 23230393 : if (n == 4
2884 : 8163500 : && regclass[0] == X86_64_SSE_CLASS
2885 : 8163500 : && regclass[1] == X86_64_SSEUP_CLASS
2886 : 8163500 : && regclass[2] == X86_64_SSEUP_CLASS
2887 : 8163500 : && regclass[3] == X86_64_SSEUP_CLASS
2888 : 8163500 : && mode != BLKmode)
2889 : 16323622 : return gen_reg_or_parallel (mode, orig_mode,
2890 : 16323622 : GET_SSE_REGNO (sse_regno));
2891 : 15068582 : if (n == 8
2892 : 8849240 : && regclass[0] == X86_64_SSE_CLASS
2893 : 8849240 : && regclass[1] == X86_64_SSEUP_CLASS
2894 : 8849240 : && regclass[2] == X86_64_SSEUP_CLASS
2895 : 8849240 : && regclass[3] == X86_64_SSEUP_CLASS
2896 : 8849240 : && regclass[4] == X86_64_SSEUP_CLASS
2897 : 8849240 : && regclass[5] == X86_64_SSEUP_CLASS
2898 : 8849240 : && regclass[6] == X86_64_SSEUP_CLASS
2899 : 8849240 : && regclass[7] == X86_64_SSEUP_CLASS
2900 : 8849240 : && mode != BLKmode)
2901 : 17694208 : return gen_reg_or_parallel (mode, orig_mode,
2902 : 17694208 : GET_SSE_REGNO (sse_regno));
2903 : 6221478 : if (n == 2
2904 : 5953694 : && regclass[0] == X86_64_X87_CLASS
2905 : 2307916 : && regclass[1] == X86_64_X87UP_CLASS)
2906 : 2307916 : return gen_rtx_REG (XFmode, FIRST_STACK_REG);
2907 : :
2908 : 3913562 : if (n == 2
2909 : 3645778 : && regclass[0] == X86_64_INTEGER_CLASS
2910 : 3257401 : && regclass[1] == X86_64_INTEGER_CLASS
2911 : 3249167 : && (mode == CDImode || mode == TImode || mode == BLKmode)
2912 : 3249167 : && intreg[0] + 1 == intreg[1])
2913 : : {
2914 : 2921954 : if (mode == BLKmode)
2915 : : {
2916 : : /* Use TImode for BLKmode values in 2 integer registers. */
2917 : 499738 : exp[0] = gen_rtx_EXPR_LIST (VOIDmode,
2918 : 249869 : gen_rtx_REG (TImode, intreg[0]),
2919 : : GEN_INT (0));
2920 : 249869 : ret = gen_rtx_PARALLEL (mode, rtvec_alloc (1));
2921 : 249869 : XVECEXP (ret, 0, 0) = exp[0];
2922 : 249869 : return ret;
2923 : : }
2924 : : else
2925 : 2672085 : return gen_rtx_REG (mode, intreg[0]);
2926 : : }
2927 : :
2928 : : /* Otherwise figure out the entries of the PARALLEL. */
2929 : 2707040 : for (i = 0; i < n; i++)
2930 : : {
2931 : 1715432 : int pos;
2932 : :
2933 : 1715432 : switch (regclass[i])
2934 : : {
2935 : : case X86_64_NO_CLASS:
2936 : : break;
2937 : 914125 : case X86_64_INTEGER_CLASS:
2938 : 914125 : case X86_64_INTEGERSI_CLASS:
2939 : : /* Merge TImodes on aligned occasions here too. */
2940 : 914125 : if (i * 8 + 8 > bytes)
2941 : : {
2942 : 3221 : unsigned int tmpbits = (bytes - i * 8) * BITS_PER_UNIT;
2943 : 3221 : if (!int_mode_for_size (tmpbits, 0).exists (&tmpmode))
2944 : : /* We've requested 24 bytes we
2945 : : don't have mode for. Use DImode. */
2946 : 358 : tmpmode = DImode;
2947 : : }
2948 : 910904 : else if (regclass[i] == X86_64_INTEGERSI_CLASS)
2949 : : tmpmode = SImode;
2950 : : else
2951 : 786567 : tmpmode = DImode;
2952 : 1828250 : exp [nexps++]
2953 : 914125 : = gen_rtx_EXPR_LIST (VOIDmode,
2954 : 914125 : gen_rtx_REG (tmpmode, *intreg),
2955 : 914125 : GEN_INT (i*8));
2956 : 914125 : intreg++;
2957 : 914125 : break;
2958 : 592 : case X86_64_SSEHF_CLASS:
2959 : 592 : tmpmode = (mode == BFmode ? BFmode : HFmode);
2960 : 1184 : exp [nexps++]
2961 : 1184 : = gen_rtx_EXPR_LIST (VOIDmode,
2962 : : gen_rtx_REG (tmpmode,
2963 : 592 : GET_SSE_REGNO (sse_regno)),
2964 : 592 : GEN_INT (i*8));
2965 : 592 : sse_regno++;
2966 : 592 : break;
2967 : 2937 : case X86_64_SSESF_CLASS:
2968 : 5874 : exp [nexps++]
2969 : 5874 : = gen_rtx_EXPR_LIST (VOIDmode,
2970 : : gen_rtx_REG (SFmode,
2971 : 2937 : GET_SSE_REGNO (sse_regno)),
2972 : 2937 : GEN_INT (i*8));
2973 : 2937 : sse_regno++;
2974 : 2937 : break;
2975 : 512818 : case X86_64_SSEDF_CLASS:
2976 : 1025636 : exp [nexps++]
2977 : 1025636 : = gen_rtx_EXPR_LIST (VOIDmode,
2978 : : gen_rtx_REG (DFmode,
2979 : 512818 : GET_SSE_REGNO (sse_regno)),
2980 : 512818 : GEN_INT (i*8));
2981 : 512818 : sse_regno++;
2982 : 512818 : break;
2983 : 276880 : case X86_64_SSE_CLASS:
2984 : 276880 : pos = i;
2985 : 276880 : switch (n)
2986 : : {
2987 : : case 1:
2988 : : tmpmode = DImode;
2989 : : break;
2990 : 9310 : case 2:
2991 : 9310 : if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
2992 : : {
2993 : 0 : tmpmode = TImode;
2994 : 0 : i++;
2995 : : }
2996 : : else
2997 : : tmpmode = DImode;
2998 : : break;
2999 : 1689 : case 4:
3000 : 1689 : gcc_assert (i == 0
3001 : : && regclass[1] == X86_64_SSEUP_CLASS
3002 : : && regclass[2] == X86_64_SSEUP_CLASS
3003 : : && regclass[3] == X86_64_SSEUP_CLASS);
3004 : : tmpmode = OImode;
3005 : : i += 3;
3006 : : break;
3007 : 2136 : case 8:
3008 : 2136 : gcc_assert (i == 0
3009 : : && regclass[1] == X86_64_SSEUP_CLASS
3010 : : && regclass[2] == X86_64_SSEUP_CLASS
3011 : : && regclass[3] == X86_64_SSEUP_CLASS
3012 : : && regclass[4] == X86_64_SSEUP_CLASS
3013 : : && regclass[5] == X86_64_SSEUP_CLASS
3014 : : && regclass[6] == X86_64_SSEUP_CLASS
3015 : : && regclass[7] == X86_64_SSEUP_CLASS);
3016 : : tmpmode = XImode;
3017 : : i += 7;
3018 : : break;
3019 : 0 : default:
3020 : 0 : gcc_unreachable ();
3021 : : }
3022 : 553760 : exp [nexps++]
3023 : 553760 : = gen_rtx_EXPR_LIST (VOIDmode,
3024 : : gen_rtx_REG (tmpmode,
3025 : 276880 : GET_SSE_REGNO (sse_regno)),
3026 : 276880 : GEN_INT (pos*8));
3027 : 276880 : sse_regno++;
3028 : 276880 : break;
3029 : 0 : default:
3030 : 0 : gcc_unreachable ();
3031 : : }
3032 : : }
3033 : :
3034 : : /* Empty aligned struct, union or class. */
3035 : 991608 : if (nexps == 0)
3036 : : return NULL;
3037 : :
3038 : 991353 : ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
3039 : 2698705 : for (i = 0; i < nexps; i++)
3040 : 1707352 : XVECEXP (ret, 0, i) = exp [i];
3041 : : return ret;
3042 : : }
3043 : :
3044 : : /* Update the data in CUM to advance over an argument of mode MODE
3045 : : and data type TYPE. (TYPE is null for libcalls where that information
3046 : : may not be available.)
3047 : :
3048 : : Return a number of integer regsiters advanced over. */
3049 : :
3050 : : static int
3051 : 2105094 : function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
3052 : : const_tree type, HOST_WIDE_INT bytes,
3053 : : HOST_WIDE_INT words)
3054 : : {
3055 : 2105094 : int res = 0;
3056 : 2105094 : bool error_p = false;
3057 : :
3058 : 2105094 : if (TARGET_IAMCU)
3059 : : {
3060 : : /* Intel MCU psABI passes scalars and aggregates no larger than 8
3061 : : bytes in registers. */
3062 : 0 : if (!VECTOR_MODE_P (mode) && bytes <= 8)
3063 : 0 : goto pass_in_reg;
3064 : : return res;
3065 : : }
3066 : :
3067 : 2105094 : switch (mode)
3068 : : {
3069 : : default:
3070 : : break;
3071 : :
3072 : 93664 : case E_BLKmode:
3073 : 93664 : if (bytes < 0)
3074 : : break;
3075 : : /* FALLTHRU */
3076 : :
3077 : 2068436 : case E_DImode:
3078 : 2068436 : case E_SImode:
3079 : 2068436 : case E_HImode:
3080 : 2068436 : case E_QImode:
3081 : 93664 : pass_in_reg:
3082 : 2068436 : cum->words += words;
3083 : 2068436 : cum->nregs -= words;
3084 : 2068436 : cum->regno += words;
3085 : 2068436 : if (cum->nregs >= 0)
3086 : 45916 : res = words;
3087 : 2068436 : if (cum->nregs <= 0)
3088 : : {
3089 : 2035436 : cum->nregs = 0;
3090 : 2035436 : cfun->machine->arg_reg_available = false;
3091 : 2035436 : cum->regno = 0;
3092 : : }
3093 : : break;
3094 : :
3095 : 0 : case E_OImode:
3096 : : /* OImode shouldn't be used directly. */
3097 : 0 : gcc_unreachable ();
3098 : :
3099 : 4685 : case E_DFmode:
3100 : 4685 : if (cum->float_in_sse == -1)
3101 : 0 : error_p = true;
3102 : 4685 : if (cum->float_in_sse < 2)
3103 : : break;
3104 : : /* FALLTHRU */
3105 : 1359 : case E_SFmode:
3106 : 1359 : if (cum->float_in_sse == -1)
3107 : 0 : error_p = true;
3108 : 1359 : if (cum->float_in_sse < 1)
3109 : : break;
3110 : : /* FALLTHRU */
3111 : :
3112 : 52 : case E_V16HFmode:
3113 : 52 : case E_V16BFmode:
3114 : 52 : case E_V8SFmode:
3115 : 52 : case E_V8SImode:
3116 : 52 : case E_V64QImode:
3117 : 52 : case E_V32HImode:
3118 : 52 : case E_V16SImode:
3119 : 52 : case E_V8DImode:
3120 : 52 : case E_V32HFmode:
3121 : 52 : case E_V32BFmode:
3122 : 52 : case E_V16SFmode:
3123 : 52 : case E_V8DFmode:
3124 : 52 : case E_V32QImode:
3125 : 52 : case E_V16HImode:
3126 : 52 : case E_V4DFmode:
3127 : 52 : case E_V4DImode:
3128 : 52 : case E_TImode:
3129 : 52 : case E_V16QImode:
3130 : 52 : case E_V8HImode:
3131 : 52 : case E_V4SImode:
3132 : 52 : case E_V2DImode:
3133 : 52 : case E_V8HFmode:
3134 : 52 : case E_V8BFmode:
3135 : 52 : case E_V4SFmode:
3136 : 52 : case E_V2DFmode:
3137 : 52 : if (!type || !AGGREGATE_TYPE_P (type))
3138 : : {
3139 : 52 : cum->sse_words += words;
3140 : 52 : cum->sse_nregs -= 1;
3141 : 52 : cum->sse_regno += 1;
3142 : 52 : if (cum->sse_nregs <= 0)
3143 : : {
3144 : 4 : cum->sse_nregs = 0;
3145 : 4 : cum->sse_regno = 0;
3146 : : }
3147 : : }
3148 : : break;
3149 : :
3150 : 12 : case E_V8QImode:
3151 : 12 : case E_V4HImode:
3152 : 12 : case E_V4HFmode:
3153 : 12 : case E_V4BFmode:
3154 : 12 : case E_V2SImode:
3155 : 12 : case E_V2SFmode:
3156 : 12 : case E_V1TImode:
3157 : 12 : case E_V1DImode:
3158 : 12 : if (!type || !AGGREGATE_TYPE_P (type))
3159 : : {
3160 : 12 : cum->mmx_words += words;
3161 : 12 : cum->mmx_nregs -= 1;
3162 : 12 : cum->mmx_regno += 1;
3163 : 12 : if (cum->mmx_nregs <= 0)
3164 : : {
3165 : 0 : cum->mmx_nregs = 0;
3166 : 0 : cum->mmx_regno = 0;
3167 : : }
3168 : : }
3169 : : break;
3170 : : }
3171 : 2041532 : if (error_p)
3172 : : {
3173 : 0 : cum->float_in_sse = 0;
3174 : 0 : error ("calling %qD with SSE calling convention without "
3175 : : "SSE/SSE2 enabled", cum->decl);
3176 : 0 : sorry ("this is a GCC bug that can be worked around by adding "
3177 : : "attribute used to function called");
3178 : : }
3179 : :
3180 : : return res;
3181 : : }
3182 : :
3183 : : static int
3184 : 19076547 : function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode,
3185 : : const_tree type, HOST_WIDE_INT words, bool named)
3186 : : {
3187 : 19076547 : int int_nregs, sse_nregs;
3188 : :
3189 : : /* Unnamed 512 and 256bit vector mode parameters are passed on stack. */
3190 : 19076547 : if (!named && (VALID_AVX512F_REG_MODE (mode)
3191 : : || VALID_AVX256_REG_MODE (mode)))
3192 : : return 0;
3193 : :
3194 : 19076183 : if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
3195 : 19076183 : && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
3196 : : {
3197 : 16815798 : cum->nregs -= int_nregs;
3198 : 16815798 : cum->sse_nregs -= sse_nregs;
3199 : 16815798 : cum->regno += int_nregs;
3200 : 16815798 : cum->sse_regno += sse_nregs;
3201 : 16815798 : return int_nregs;
3202 : : }
3203 : : else
3204 : : {
3205 : 2260385 : int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
3206 : 2260385 : cum->words = ROUND_UP (cum->words, align);
3207 : 2260385 : cum->words += words;
3208 : 2260385 : return 0;
3209 : : }
3210 : : }
3211 : :
3212 : : static int
3213 : 446969 : function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
3214 : : HOST_WIDE_INT words)
3215 : : {
3216 : : /* Otherwise, this should be passed indirect. */
3217 : 446969 : gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
3218 : :
3219 : 446969 : cum->words += words;
3220 : 446969 : if (cum->nregs > 0)
3221 : : {
3222 : 289335 : cum->nregs -= 1;
3223 : 289335 : cum->regno += 1;
3224 : 289335 : return 1;
3225 : : }
3226 : : return 0;
3227 : : }
3228 : :
3229 : : /* Update the data in CUM to advance over argument ARG. */
3230 : :
3231 : : static void
3232 : 21628965 : ix86_function_arg_advance (cumulative_args_t cum_v,
3233 : : const function_arg_info &arg)
3234 : : {
3235 : 21628965 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
3236 : 21628965 : machine_mode mode = arg.mode;
3237 : 21628965 : HOST_WIDE_INT bytes, words;
3238 : 21628965 : int nregs;
3239 : :
3240 : : /* The argument of interrupt handler is a special case and is
3241 : : handled in ix86_function_arg. */
3242 : 21628965 : if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL)
3243 : : return;
3244 : :
3245 : 21628610 : bytes = arg.promoted_size_in_bytes ();
3246 : 21628610 : words = CEIL (bytes, UNITS_PER_WORD);
3247 : :
3248 : 21628610 : if (arg.type)
3249 : 21312048 : mode = type_natural_mode (arg.type, NULL, false);
3250 : :
3251 : 21628610 : if (TARGET_64BIT)
3252 : : {
3253 : 19523516 : enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
3254 : :
3255 : 19523516 : if (call_abi == MS_ABI)
3256 : 446969 : nregs = function_arg_advance_ms_64 (cum, bytes, words);
3257 : : else
3258 : 19076547 : nregs = function_arg_advance_64 (cum, mode, arg.type, words,
3259 : 19076547 : arg.named);
3260 : : }
3261 : : else
3262 : 2105094 : nregs = function_arg_advance_32 (cum, mode, arg.type, bytes, words);
3263 : :
3264 : 21628610 : if (!nregs)
3265 : : {
3266 : : /* Track if there are outgoing arguments on stack. */
3267 : 5663047 : if (cum->caller)
3268 : 2698089 : cfun->machine->outgoing_args_on_stack = true;
3269 : : }
3270 : : }
3271 : :
3272 : : /* Define where to put the arguments to a function.
3273 : : Value is zero to push the argument on the stack,
3274 : : or a hard register in which to store the argument.
3275 : :
3276 : : MODE is the argument's machine mode.
3277 : : TYPE is the data type of the argument (as a tree).
3278 : : This is null for libcalls where that information may
3279 : : not be available.
3280 : : CUM is a variable of type CUMULATIVE_ARGS which gives info about
3281 : : the preceding args and about the function being called.
3282 : : NAMED is nonzero if this argument is a named parameter
3283 : : (otherwise it is an extra parameter matching an ellipsis). */
3284 : :
3285 : : static rtx
3286 : 2532303 : function_arg_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
3287 : : machine_mode orig_mode, const_tree type,
3288 : : HOST_WIDE_INT bytes, HOST_WIDE_INT words)
3289 : : {
3290 : 2532303 : bool error_p = false;
3291 : :
3292 : : /* Avoid the AL settings for the Unix64 ABI. */
3293 : 2532303 : if (mode == VOIDmode)
3294 : 735822 : return constm1_rtx;
3295 : :
3296 : 1796481 : if (TARGET_IAMCU)
3297 : : {
3298 : : /* Intel MCU psABI passes scalars and aggregates no larger than 8
3299 : : bytes in registers. */
3300 : 0 : if (!VECTOR_MODE_P (mode) && bytes <= 8)
3301 : 0 : goto pass_in_reg;
3302 : : return NULL_RTX;
3303 : : }
3304 : :
3305 : 1796481 : switch (mode)
3306 : : {
3307 : : default:
3308 : : break;
3309 : :
3310 : 77694 : case E_BLKmode:
3311 : 77694 : if (bytes < 0)
3312 : : break;
3313 : : /* FALLTHRU */
3314 : 1763074 : case E_DImode:
3315 : 1763074 : case E_SImode:
3316 : 1763074 : case E_HImode:
3317 : 1763074 : case E_QImode:
3318 : 77694 : pass_in_reg:
3319 : 1763074 : if (words <= cum->nregs)
3320 : : {
3321 : 44084 : int regno = cum->regno;
3322 : :
3323 : : /* Fastcall allocates the first two DWORD (SImode) or
3324 : : smaller arguments to ECX and EDX if it isn't an
3325 : : aggregate type . */
3326 : 44084 : if (cum->fastcall)
3327 : : {
3328 : 6 : if (mode == BLKmode
3329 : 6 : || mode == DImode
3330 : 6 : || (type && AGGREGATE_TYPE_P (type)))
3331 : : break;
3332 : :
3333 : : /* ECX not EAX is the first allocated register. */
3334 : 6 : if (regno == AX_REG)
3335 : 44084 : regno = CX_REG;
3336 : : }
3337 : 44084 : return gen_rtx_REG (mode, regno);
3338 : : }
3339 : : break;
3340 : :
3341 : 3304 : case E_DFmode:
3342 : 3304 : if (cum->float_in_sse == -1)
3343 : 0 : error_p = true;
3344 : 3304 : if (cum->float_in_sse < 2)
3345 : : break;
3346 : : /* FALLTHRU */
3347 : 968 : case E_SFmode:
3348 : 968 : if (cum->float_in_sse == -1)
3349 : 0 : error_p = true;
3350 : 968 : if (cum->float_in_sse < 1)
3351 : : break;
3352 : : /* FALLTHRU */
3353 : 12 : case E_TImode:
3354 : : /* In 32bit, we pass TImode in xmm registers. */
3355 : 12 : case E_V16QImode:
3356 : 12 : case E_V8HImode:
3357 : 12 : case E_V4SImode:
3358 : 12 : case E_V2DImode:
3359 : 12 : case E_V8HFmode:
3360 : 12 : case E_V8BFmode:
3361 : 12 : case E_V4SFmode:
3362 : 12 : case E_V2DFmode:
3363 : 12 : if (!type || !AGGREGATE_TYPE_P (type))
3364 : : {
3365 : 12 : if (cum->sse_nregs)
3366 : 12 : return gen_reg_or_parallel (mode, orig_mode,
3367 : 12 : cum->sse_regno + FIRST_SSE_REG);
3368 : : }
3369 : : break;
3370 : :
3371 : 0 : case E_OImode:
3372 : 0 : case E_XImode:
3373 : : /* OImode and XImode shouldn't be used directly. */
3374 : 0 : gcc_unreachable ();
3375 : :
3376 : 9 : case E_V64QImode:
3377 : 9 : case E_V32HImode:
3378 : 9 : case E_V16SImode:
3379 : 9 : case E_V8DImode:
3380 : 9 : case E_V32HFmode:
3381 : 9 : case E_V32BFmode:
3382 : 9 : case E_V16SFmode:
3383 : 9 : case E_V8DFmode:
3384 : 9 : case E_V16HFmode:
3385 : 9 : case E_V16BFmode:
3386 : 9 : case E_V8SFmode:
3387 : 9 : case E_V8SImode:
3388 : 9 : case E_V32QImode:
3389 : 9 : case E_V16HImode:
3390 : 9 : case E_V4DFmode:
3391 : 9 : case E_V4DImode:
3392 : 9 : if (!type || !AGGREGATE_TYPE_P (type))
3393 : : {
3394 : 9 : if (cum->sse_nregs)
3395 : 9 : return gen_reg_or_parallel (mode, orig_mode,
3396 : 9 : cum->sse_regno + FIRST_SSE_REG);
3397 : : }
3398 : : break;
3399 : :
3400 : 6 : case E_V8QImode:
3401 : 6 : case E_V4HImode:
3402 : 6 : case E_V4HFmode:
3403 : 6 : case E_V4BFmode:
3404 : 6 : case E_V2SImode:
3405 : 6 : case E_V2SFmode:
3406 : 6 : case E_V1TImode:
3407 : 6 : case E_V1DImode:
3408 : 6 : if (!type || !AGGREGATE_TYPE_P (type))
3409 : : {
3410 : 6 : if (cum->mmx_nregs)
3411 : 6 : return gen_reg_or_parallel (mode, orig_mode,
3412 : 6 : cum->mmx_regno + FIRST_MMX_REG);
3413 : : }
3414 : : break;
3415 : : }
3416 : 4272 : if (error_p)
3417 : : {
3418 : 0 : cum->float_in_sse = 0;
3419 : 0 : error ("calling %qD with SSE calling convention without "
3420 : : "SSE/SSE2 enabled", cum->decl);
3421 : 0 : sorry ("this is a GCC bug that can be worked around by adding "
3422 : : "attribute used to function called");
3423 : : }
3424 : :
3425 : : return NULL_RTX;
3426 : : }
3427 : :
3428 : : static rtx
3429 : 18738977 : function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
3430 : : machine_mode orig_mode, const_tree type, bool named)
3431 : : {
3432 : : /* Handle a hidden AL argument containing number of registers
3433 : : for varargs x86-64 functions. */
3434 : 18738977 : if (mode == VOIDmode)
3435 : 5152255 : return GEN_INT (cum->maybe_vaarg
3436 : : ? (cum->sse_nregs < 0
3437 : : ? X86_64_SSE_REGPARM_MAX
3438 : : : cum->sse_regno)
3439 : : : -1);
3440 : :
3441 : 13586722 : switch (mode)
3442 : : {
3443 : : default:
3444 : : break;
3445 : :
3446 : 90099 : case E_V16HFmode:
3447 : 90099 : case E_V16BFmode:
3448 : 90099 : case E_V8SFmode:
3449 : 90099 : case E_V8SImode:
3450 : 90099 : case E_V32QImode:
3451 : 90099 : case E_V16HImode:
3452 : 90099 : case E_V4DFmode:
3453 : 90099 : case E_V4DImode:
3454 : 90099 : case E_V32HFmode:
3455 : 90099 : case E_V32BFmode:
3456 : 90099 : case E_V16SFmode:
3457 : 90099 : case E_V16SImode:
3458 : 90099 : case E_V64QImode:
3459 : 90099 : case E_V32HImode:
3460 : 90099 : case E_V8DFmode:
3461 : 90099 : case E_V8DImode:
3462 : : /* Unnamed 256 and 512bit vector mode parameters are passed on stack. */
3463 : 90099 : if (!named)
3464 : : return NULL;
3465 : : break;
3466 : : }
3467 : :
3468 : 13586358 : const int *parm_regs;
3469 : 13586358 : if (cum->preserve_none_abi)
3470 : : parm_regs = x86_64_preserve_none_int_parameter_registers;
3471 : : else
3472 : 13586291 : parm_regs = x86_64_int_parameter_registers;
3473 : :
3474 : 13586358 : return construct_container (mode, orig_mode, type, 0, cum->nregs,
3475 : 13586358 : cum->sse_nregs,
3476 : 13586358 : &parm_regs[cum->regno],
3477 : 13586358 : cum->sse_regno);
3478 : : }
3479 : :
3480 : : static rtx
3481 : 296328 : function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
3482 : : machine_mode orig_mode, bool named, const_tree type,
3483 : : HOST_WIDE_INT bytes)
3484 : : {
3485 : 296328 : unsigned int regno;
3486 : :
3487 : : /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
3488 : : We use value of -2 to specify that current function call is MSABI. */
3489 : 296328 : if (mode == VOIDmode)
3490 : 36293 : return GEN_INT (-2);
3491 : :
3492 : : /* If we've run out of registers, it goes on the stack. */
3493 : 260035 : if (cum->nregs == 0)
3494 : : return NULL_RTX;
3495 : :
3496 : 176280 : regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
3497 : :
3498 : : /* Only floating point modes are passed in anything but integer regs. */
3499 : 176280 : if (TARGET_SSE && (mode == SFmode || mode == DFmode))
3500 : : {
3501 : 38254 : if (named)
3502 : : {
3503 : 38254 : if (type == NULL_TREE || !AGGREGATE_TYPE_P (type))
3504 : 37260 : regno = cum->regno + FIRST_SSE_REG;
3505 : : }
3506 : : else
3507 : : {
3508 : 0 : rtx t1, t2;
3509 : :
3510 : : /* Unnamed floating parameters are passed in both the
3511 : : SSE and integer registers. */
3512 : 0 : t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
3513 : 0 : t2 = gen_rtx_REG (mode, regno);
3514 : 0 : t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
3515 : 0 : t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
3516 : 0 : return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
3517 : : }
3518 : : }
3519 : : /* Handle aggregated types passed in register. */
3520 : 176280 : if (orig_mode == BLKmode)
3521 : : {
3522 : 0 : if (bytes > 0 && bytes <= 8)
3523 : 0 : mode = (bytes > 4 ? DImode : SImode);
3524 : 0 : if (mode == BLKmode)
3525 : 0 : mode = DImode;
3526 : : }
3527 : :
3528 : 176280 : return gen_reg_or_parallel (mode, orig_mode, regno);
3529 : : }
3530 : :
3531 : : /* Return where to put the arguments to a function.
3532 : : Return zero to push the argument on the stack, or a hard register in which to store the argument.
3533 : :
3534 : : ARG describes the argument while CUM gives information about the
3535 : : preceding args and about the function being called. */
3536 : :
3537 : : static rtx
3538 : 21567789 : ix86_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
3539 : : {
3540 : 21567789 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
3541 : 21567789 : machine_mode mode = arg.mode;
3542 : 21567789 : HOST_WIDE_INT bytes, words;
3543 : 21567789 : rtx reg;
3544 : :
3545 : 21567789 : if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL)
3546 : : {
3547 : 181 : gcc_assert (arg.type != NULL_TREE);
3548 : 181 : if (POINTER_TYPE_P (arg.type))
3549 : : {
3550 : : /* This is the pointer argument. */
3551 : 118 : gcc_assert (TYPE_MODE (arg.type) == ptr_mode);
3552 : : /* It is at -WORD(AP) in the current frame in interrupt and
3553 : : exception handlers. */
3554 : 118 : reg = plus_constant (Pmode, arg_pointer_rtx, -UNITS_PER_WORD);
3555 : : }
3556 : : else
3557 : : {
3558 : 63 : gcc_assert (cfun->machine->func_type == TYPE_EXCEPTION
3559 : : && TREE_CODE (arg.type) == INTEGER_TYPE
3560 : : && TYPE_MODE (arg.type) == word_mode);
3561 : : /* The error code is the word-mode integer argument at
3562 : : -2 * WORD(AP) in the current frame of the exception
3563 : : handler. */
3564 : 63 : reg = gen_rtx_MEM (word_mode,
3565 : 63 : plus_constant (Pmode,
3566 : : arg_pointer_rtx,
3567 : 63 : -2 * UNITS_PER_WORD));
3568 : : }
3569 : 181 : return reg;
3570 : : }
3571 : :
3572 : 21567608 : bytes = arg.promoted_size_in_bytes ();
3573 : 21567608 : words = CEIL (bytes, UNITS_PER_WORD);
3574 : :
3575 : : /* To simplify the code below, represent vector types with a vector mode
3576 : : even if MMX/SSE are not active. */
3577 : 21567608 : if (arg.type && VECTOR_TYPE_P (arg.type))
3578 : 170259 : mode = type_natural_mode (arg.type, cum, false);
3579 : :
3580 : 21567608 : if (TARGET_64BIT)
3581 : : {
3582 : 19035305 : enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
3583 : :
3584 : 19035305 : if (call_abi == MS_ABI)
3585 : 296328 : reg = function_arg_ms_64 (cum, mode, arg.mode, arg.named,
3586 : 296328 : arg.type, bytes);
3587 : : else
3588 : 18738977 : reg = function_arg_64 (cum, mode, arg.mode, arg.type, arg.named);
3589 : : }
3590 : : else
3591 : 2532303 : reg = function_arg_32 (cum, mode, arg.mode, arg.type, bytes, words);
3592 : :
3593 : : /* Track if there are outgoing arguments on stack. */
3594 : 21567608 : if (reg == NULL_RTX && cum->caller)
3595 : 2176382 : cfun->machine->outgoing_args_on_stack = true;
3596 : :
3597 : : return reg;
3598 : : }
3599 : :
3600 : : /* A C expression that indicates when an argument must be passed by
3601 : : reference. If nonzero for an argument, a copy of that argument is
3602 : : made in memory and a pointer to the argument is passed instead of
3603 : : the argument itself. The pointer is passed in whatever way is
3604 : : appropriate for passing a pointer to that type. */
3605 : :
3606 : : static bool
3607 : 21548988 : ix86_pass_by_reference (cumulative_args_t cum_v, const function_arg_info &arg)
3608 : : {
3609 : 21548988 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
3610 : :
3611 : 21548988 : if (TARGET_64BIT)
3612 : : {
3613 : 19454155 : enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
3614 : :
3615 : : /* See Windows x64 Software Convention. */
3616 : 19454155 : if (call_abi == MS_ABI)
3617 : : {
3618 : 441370 : HOST_WIDE_INT msize = GET_MODE_SIZE (arg.mode);
3619 : :
3620 : 441370 : if (tree type = arg.type)
3621 : : {
3622 : : /* Arrays are passed by reference. */
3623 : 441370 : if (TREE_CODE (type) == ARRAY_TYPE)
3624 : : return true;
3625 : :
3626 : 441370 : if (RECORD_OR_UNION_TYPE_P (type))
3627 : : {
3628 : : /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
3629 : : are passed by reference. */
3630 : 15022 : msize = int_size_in_bytes (type);
3631 : : }
3632 : : }
3633 : :
3634 : : /* __m128 is passed by reference. */
3635 : 872811 : return msize != 1 && msize != 2 && msize != 4 && msize != 8;
3636 : : }
3637 : 19012785 : else if (arg.type && int_size_in_bytes (arg.type) == -1)
3638 : : return true;
3639 : : }
3640 : :
3641 : : return false;
3642 : : }
3643 : :
3644 : : /* Return true when TYPE should be 128bit aligned for 32bit argument
3645 : : passing ABI. XXX: This function is obsolete and is only used for
3646 : : checking psABI compatibility with previous versions of GCC. */
3647 : :
3648 : : static bool
3649 : 1956892 : ix86_compat_aligned_value_p (const_tree type)
3650 : : {
3651 : 1956892 : machine_mode mode = TYPE_MODE (type);
3652 : 1956892 : if (((TARGET_SSE && SSE_REG_MODE_P (mode))
3653 : 1956850 : || mode == TDmode
3654 : 1956850 : || mode == TFmode
3655 : : || mode == TCmode)
3656 : 1957104 : && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
3657 : : return true;
3658 : 1956680 : if (TYPE_ALIGN (type) < 128)
3659 : : return false;
3660 : :
3661 : 0 : if (AGGREGATE_TYPE_P (type))
3662 : : {
3663 : : /* Walk the aggregates recursively. */
3664 : 0 : switch (TREE_CODE (type))
3665 : : {
3666 : 0 : case RECORD_TYPE:
3667 : 0 : case UNION_TYPE:
3668 : 0 : case QUAL_UNION_TYPE:
3669 : 0 : {
3670 : 0 : tree field;
3671 : :
3672 : : /* Walk all the structure fields. */
3673 : 0 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
3674 : : {
3675 : 0 : if (TREE_CODE (field) == FIELD_DECL
3676 : 0 : && ix86_compat_aligned_value_p (TREE_TYPE (field)))
3677 : : return true;
3678 : : }
3679 : : break;
3680 : : }
3681 : :
3682 : 0 : case ARRAY_TYPE:
3683 : : /* Just for use if some languages passes arrays by value. */
3684 : 0 : if (ix86_compat_aligned_value_p (TREE_TYPE (type)))
3685 : : return true;
3686 : : break;
3687 : :
3688 : : default:
3689 : : gcc_unreachable ();
3690 : : }
3691 : : }
3692 : : return false;
3693 : : }
3694 : :
3695 : : /* Return the alignment boundary for MODE and TYPE with alignment ALIGN.
3696 : : XXX: This function is obsolete and is only used for checking psABI
3697 : : compatibility with previous versions of GCC. */
3698 : :
3699 : : static unsigned int
3700 : 5488551 : ix86_compat_function_arg_boundary (machine_mode mode,
3701 : : const_tree type, unsigned int align)
3702 : : {
3703 : : /* In 32bit, only _Decimal128 and __float128 are aligned to their
3704 : : natural boundaries. */
3705 : 5488551 : if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
3706 : : {
3707 : : /* i386 ABI defines all arguments to be 4 byte aligned. We have to
3708 : : make an exception for SSE modes since these require 128bit
3709 : : alignment.
3710 : :
3711 : : The handling here differs from field_alignment. ICC aligns MMX
3712 : : arguments to 4 byte boundaries, while structure fields are aligned
3713 : : to 8 byte boundaries. */
3714 : 1968834 : if (!type)
3715 : : {
3716 : 11942 : if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
3717 : 1968622 : align = PARM_BOUNDARY;
3718 : : }
3719 : : else
3720 : : {
3721 : 1956892 : if (!ix86_compat_aligned_value_p (type))
3722 : 1968622 : align = PARM_BOUNDARY;
3723 : : }
3724 : : }
3725 : 10583160 : if (align > BIGGEST_ALIGNMENT)
3726 : 76 : align = BIGGEST_ALIGNMENT;
3727 : 5488551 : return align;
3728 : : }
3729 : :
3730 : : /* Return true when TYPE should be 128bit aligned for 32bit argument
3731 : : passing ABI. */
3732 : :
3733 : : static bool
3734 : 1959534 : ix86_contains_aligned_value_p (const_tree type)
3735 : : {
3736 : 1959534 : machine_mode mode = TYPE_MODE (type);
3737 : :
3738 : 1959534 : if (mode == XFmode || mode == XCmode)
3739 : : return false;
3740 : :
3741 : 1957440 : if (TYPE_ALIGN (type) < 128)
3742 : : return false;
3743 : :
3744 : 2854 : if (AGGREGATE_TYPE_P (type))
3745 : : {
3746 : : /* Walk the aggregates recursively. */
3747 : 0 : switch (TREE_CODE (type))
3748 : : {
3749 : 0 : case RECORD_TYPE:
3750 : 0 : case UNION_TYPE:
3751 : 0 : case QUAL_UNION_TYPE:
3752 : 0 : {
3753 : 0 : tree field;
3754 : :
3755 : : /* Walk all the structure fields. */
3756 : 0 : for (field = TYPE_FIELDS (type);
3757 : 0 : field;
3758 : 0 : field = DECL_CHAIN (field))
3759 : : {
3760 : 0 : if (TREE_CODE (field) == FIELD_DECL
3761 : 0 : && ix86_contains_aligned_value_p (TREE_TYPE (field)))
3762 : : return true;
3763 : : }
3764 : : break;
3765 : : }
3766 : :
3767 : 0 : case ARRAY_TYPE:
3768 : : /* Just for use if some languages passes arrays by value. */
3769 : 0 : if (ix86_contains_aligned_value_p (TREE_TYPE (type)))
3770 : : return true;
3771 : : break;
3772 : :
3773 : : default:
3774 : : gcc_unreachable ();
3775 : : }
3776 : : }
3777 : : else
3778 : 2854 : return TYPE_ALIGN (type) >= 128;
3779 : :
3780 : : return false;
3781 : : }
3782 : :
3783 : : /* Gives the alignment boundary, in bits, of an argument with the
3784 : : specified mode and type. */
3785 : :
3786 : : static unsigned int
3787 : 10849965 : ix86_function_arg_boundary (machine_mode mode, const_tree type)
3788 : : {
3789 : 10849965 : unsigned int align;
3790 : 10849965 : if (type)
3791 : : {
3792 : : /* Since the main variant type is used for call, we convert it to
3793 : : the main variant type. */
3794 : 10810268 : type = TYPE_MAIN_VARIANT (type);
3795 : 10810268 : align = TYPE_ALIGN (type);
3796 : 10810268 : if (TYPE_EMPTY_P (type))
3797 : 24040 : return PARM_BOUNDARY;
3798 : : }
3799 : : else
3800 : 39697 : align = GET_MODE_ALIGNMENT (mode);
3801 : 12832306 : if (align < PARM_BOUNDARY)
3802 : 4080768 : align = PARM_BOUNDARY;
3803 : : else
3804 : : {
3805 : 6745157 : static bool warned;
3806 : 6745157 : unsigned int saved_align = align;
3807 : :
3808 : 6745157 : if (!TARGET_64BIT)
3809 : : {
3810 : : /* i386 ABI defines XFmode arguments to be 4 byte aligned. */
3811 : 1995288 : if (!type)
3812 : : {
3813 : 35754 : if (mode == XFmode || mode == XCmode)
3814 : : align = PARM_BOUNDARY;
3815 : : }
3816 : 1959534 : else if (!ix86_contains_aligned_value_p (type))
3817 : : align = PARM_BOUNDARY;
3818 : :
3819 : 38608 : if (align < 128)
3820 : 1968622 : align = PARM_BOUNDARY;
3821 : : }
3822 : :
3823 : 6745157 : if (warn_psabi
3824 : 5491193 : && !warned
3825 : 12233708 : && align != ix86_compat_function_arg_boundary (mode, type,
3826 : : saved_align))
3827 : : {
3828 : 76 : warned = true;
3829 : 76 : inform (input_location,
3830 : : "the ABI for passing parameters with %d-byte"
3831 : : " alignment has changed in GCC 4.6",
3832 : : align / BITS_PER_UNIT);
3833 : : }
3834 : : }
3835 : :
3836 : : return align;
3837 : : }
3838 : :
3839 : : /* Return true if N is a possible register number of function value. */
3840 : :
3841 : : static bool
3842 : 4587310 : ix86_function_value_regno_p (const unsigned int regno)
3843 : : {
3844 : 4587310 : switch (regno)
3845 : : {
3846 : : case AX_REG:
3847 : : return true;
3848 : 105131 : case DX_REG:
3849 : 105131 : return (!TARGET_64BIT || ix86_cfun_abi () != MS_ABI);
3850 : 104588 : case DI_REG:
3851 : 104588 : case SI_REG:
3852 : 104588 : return TARGET_64BIT && ix86_cfun_abi () != MS_ABI;
3853 : :
3854 : : /* Complex values are returned in %st(0)/%st(1) pair. */
3855 : 21583 : case ST0_REG:
3856 : 21583 : case ST1_REG:
3857 : : /* TODO: The function should depend on current function ABI but
3858 : : builtins.cc would need updating then. Therefore we use the
3859 : : default ABI. */
3860 : 21583 : if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
3861 : : return false;
3862 : 21583 : return TARGET_FLOAT_RETURNS_IN_80387;
3863 : :
3864 : : /* Complex values are returned in %xmm0/%xmm1 pair. */
3865 : 1286467 : case XMM0_REG:
3866 : 1286467 : case XMM1_REG:
3867 : 1286467 : return TARGET_SSE;
3868 : :
3869 : 11250 : case MM0_REG:
3870 : 11250 : if (TARGET_MACHO || TARGET_64BIT)
3871 : : return false;
3872 : 5082 : return TARGET_MMX;
3873 : : }
3874 : :
3875 : : return false;
3876 : : }
3877 : :
3878 : : /* Check whether the register REGNO should be zeroed on X86.
3879 : : When ALL_SSE_ZEROED is true, all SSE registers have been zeroed
3880 : : together, no need to zero it again.
3881 : : When NEED_ZERO_MMX is true, MMX registers should be cleared. */
3882 : :
3883 : : static bool
3884 : 1296 : zero_call_used_regno_p (const unsigned int regno,
3885 : : bool all_sse_zeroed,
3886 : : bool need_zero_mmx)
3887 : : {
3888 : 763 : return GENERAL_REGNO_P (regno)
3889 : 763 : || (!all_sse_zeroed && SSE_REGNO_P (regno))
3890 : 383 : || MASK_REGNO_P (regno)
3891 : 1671 : || (need_zero_mmx && MMX_REGNO_P (regno));
3892 : : }
3893 : :
3894 : : /* Return the machine_mode that is used to zero register REGNO. */
3895 : :
3896 : : static machine_mode
3897 : 921 : zero_call_used_regno_mode (const unsigned int regno)
3898 : : {
3899 : : /* NB: We only need to zero the lower 32 bits for integer registers
3900 : : and the lower 128 bits for vector registers since destination are
3901 : : zero-extended to the full register width. */
3902 : 921 : if (GENERAL_REGNO_P (regno))
3903 : : return SImode;
3904 : : else if (SSE_REGNO_P (regno))
3905 : 380 : return V4SFmode;
3906 : : else if (MASK_REGNO_P (regno))
3907 : : return HImode;
3908 : : else if (MMX_REGNO_P (regno))
3909 : 0 : return V2SImode;
3910 : : else
3911 : 0 : gcc_unreachable ();
3912 : : }
3913 : :
3914 : : /* Generate a rtx to zero all vector registers together if possible,
3915 : : otherwise, return NULL. */
3916 : :
3917 : : static rtx
3918 : 130 : zero_all_vector_registers (HARD_REG_SET need_zeroed_hardregs)
3919 : : {
3920 : 130 : if (!TARGET_AVX)
3921 : : return NULL;
3922 : :
3923 : 279 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
3924 : 276 : if ((LEGACY_SSE_REGNO_P (regno)
3925 : 252 : || (TARGET_64BIT
3926 : 252 : && (REX_SSE_REGNO_P (regno)
3927 : 228 : || (TARGET_AVX512F && EXT_REX_SSE_REGNO_P (regno)))))
3928 : 316 : && !TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
3929 : : return NULL;
3930 : :
3931 : 3 : return gen_avx_vzeroall ();
3932 : : }
3933 : :
3934 : : /* Generate insns to zero all st registers together.
3935 : : Return true when zeroing instructions are generated.
3936 : : Assume the number of st registers that are zeroed is num_of_st,
3937 : : we will emit the following sequence to zero them together:
3938 : : fldz; \
3939 : : fldz; \
3940 : : ...
3941 : : fldz; \
3942 : : fstp %%st(0); \
3943 : : fstp %%st(0); \
3944 : : ...
3945 : : fstp %%st(0);
3946 : : i.e., num_of_st fldz followed by num_of_st fstp to clear the stack
3947 : : mark stack slots empty.
3948 : :
3949 : : How to compute the num_of_st:
3950 : : There is no direct mapping from stack registers to hard register
3951 : : numbers. If one stack register needs to be cleared, we don't know
3952 : : where in the stack the value remains. So, if any stack register
3953 : : needs to be cleared, the whole stack should be cleared. However,
3954 : : x87 stack registers that hold the return value should be excluded.
3955 : : x87 returns in the top (two for complex values) register, so
3956 : : num_of_st should be 7/6 when x87 returns, otherwise it will be 8.
3957 : : return the value of num_of_st. */
3958 : :
3959 : :
3960 : : static int
3961 : 130 : zero_all_st_registers (HARD_REG_SET need_zeroed_hardregs)
3962 : : {
3963 : :
3964 : : /* If the FPU is disabled, no need to zero all st registers. */
3965 : 130 : if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
3966 : : return 0;
3967 : :
3968 : 10320 : unsigned int num_of_st = 0;
3969 : 10320 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
3970 : 10211 : if ((STACK_REGNO_P (regno) || MMX_REGNO_P (regno))
3971 : 10211 : && TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
3972 : : {
3973 : : num_of_st++;
3974 : : break;
3975 : : }
3976 : :
3977 : 129 : if (num_of_st == 0)
3978 : : return 0;
3979 : :
3980 : 20 : bool return_with_x87 = false;
3981 : 40 : return_with_x87 = (crtl->return_rtx
3982 : 20 : && (STACK_REG_P (crtl->return_rtx)));
3983 : :
3984 : 20 : bool complex_return = false;
3985 : 40 : complex_return = (crtl->return_rtx
3986 : 20 : && COMPLEX_MODE_P (GET_MODE (crtl->return_rtx)));
3987 : :
3988 : 20 : if (return_with_x87)
3989 : 2 : if (complex_return)
3990 : : num_of_st = 6;
3991 : : else
3992 : 1 : num_of_st = 7;
3993 : : else
3994 : : num_of_st = 8;
3995 : :
3996 : 20 : rtx st_reg = gen_rtx_REG (XFmode, FIRST_STACK_REG);
3997 : 177 : for (unsigned int i = 0; i < num_of_st; i++)
3998 : 157 : emit_insn (gen_rtx_SET (st_reg, CONST0_RTX (XFmode)));
3999 : :
4000 : 177 : for (unsigned int i = 0; i < num_of_st; i++)
4001 : : {
4002 : 157 : rtx insn;
4003 : 157 : insn = emit_insn (gen_rtx_SET (st_reg, st_reg));
4004 : 157 : add_reg_note (insn, REG_DEAD, st_reg);
4005 : : }
4006 : 20 : return num_of_st;
4007 : : }
4008 : :
4009 : :
4010 : : /* When the routine exit in MMX mode, if any ST register needs
4011 : : to be zeroed, we should clear all MMX registers except the
4012 : : RET_MMX_REGNO that holds the return value. */
4013 : : static bool
4014 : 0 : zero_all_mm_registers (HARD_REG_SET need_zeroed_hardregs,
4015 : : unsigned int ret_mmx_regno)
4016 : : {
4017 : 0 : bool need_zero_all_mm = false;
4018 : 0 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
4019 : 0 : if (STACK_REGNO_P (regno)
4020 : 0 : && TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
4021 : : {
4022 : : need_zero_all_mm = true;
4023 : : break;
4024 : : }
4025 : :
4026 : 0 : if (!need_zero_all_mm)
4027 : : return false;
4028 : :
4029 : : machine_mode mode = V2SImode;
4030 : 0 : for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++)
4031 : 0 : if (regno != ret_mmx_regno)
4032 : : {
4033 : 0 : rtx reg = gen_rtx_REG (mode, regno);
4034 : 0 : emit_insn (gen_rtx_SET (reg, CONST0_RTX (mode)));
4035 : : }
4036 : : return true;
4037 : : }
4038 : :
4039 : : /* TARGET_ZERO_CALL_USED_REGS. */
4040 : : /* Generate a sequence of instructions that zero registers specified by
4041 : : NEED_ZEROED_HARDREGS. Return the ZEROED_HARDREGS that are actually
4042 : : zeroed. */
4043 : : static HARD_REG_SET
4044 : 130 : ix86_zero_call_used_regs (HARD_REG_SET need_zeroed_hardregs)
4045 : : {
4046 : 130 : HARD_REG_SET zeroed_hardregs;
4047 : 130 : bool all_sse_zeroed = false;
4048 : 130 : int all_st_zeroed_num = 0;
4049 : 130 : bool all_mm_zeroed = false;
4050 : :
4051 : 130 : CLEAR_HARD_REG_SET (zeroed_hardregs);
4052 : :
4053 : : /* first, let's see whether we can zero all vector registers together. */
4054 : 130 : rtx zero_all_vec_insn = zero_all_vector_registers (need_zeroed_hardregs);
4055 : 130 : if (zero_all_vec_insn)
4056 : : {
4057 : 3 : emit_insn (zero_all_vec_insn);
4058 : 3 : all_sse_zeroed = true;
4059 : : }
4060 : :
4061 : : /* mm/st registers are shared registers set, we should follow the following
4062 : : rules to clear them:
4063 : : MMX exit mode x87 exit mode
4064 : : -------------|----------------------|---------------
4065 : : uses x87 reg | clear all MMX | clear all x87
4066 : : uses MMX reg | clear individual MMX | clear all x87
4067 : : x87 + MMX | clear all MMX | clear all x87
4068 : :
4069 : : first, we should decide which mode (MMX mode or x87 mode) the function
4070 : : exit with. */
4071 : :
4072 : 130 : bool exit_with_mmx_mode = (crtl->return_rtx
4073 : 130 : && (MMX_REG_P (crtl->return_rtx)));
4074 : :
4075 : 130 : if (!exit_with_mmx_mode)
4076 : : /* x87 exit mode, we should zero all st registers together. */
4077 : : {
4078 : 130 : all_st_zeroed_num = zero_all_st_registers (need_zeroed_hardregs);
4079 : :
4080 : 130 : if (all_st_zeroed_num > 0)
4081 : 180 : for (unsigned int regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
4082 : : /* x87 stack registers that hold the return value should be excluded.
4083 : : x87 returns in the top (two for complex values) register. */
4084 : 160 : if (all_st_zeroed_num == 8
4085 : 160 : || !((all_st_zeroed_num >= 6 && regno == REGNO (crtl->return_rtx))
4086 : : || (all_st_zeroed_num == 6
4087 : 7 : && (regno == (REGNO (crtl->return_rtx) + 1)))))
4088 : 157 : SET_HARD_REG_BIT (zeroed_hardregs, regno);
4089 : : }
4090 : : else
4091 : : /* MMX exit mode, check whether we can zero all mm registers. */
4092 : : {
4093 : 0 : unsigned int exit_mmx_regno = REGNO (crtl->return_rtx);
4094 : 0 : all_mm_zeroed = zero_all_mm_registers (need_zeroed_hardregs,
4095 : : exit_mmx_regno);
4096 : 0 : if (all_mm_zeroed)
4097 : 0 : for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++)
4098 : 0 : if (regno != exit_mmx_regno)
4099 : 0 : SET_HARD_REG_BIT (zeroed_hardregs, regno);
4100 : : }
4101 : :
4102 : : /* Now, generate instructions to zero all the other registers. */
4103 : :
4104 : 12090 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
4105 : : {
4106 : 11960 : if (!TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
4107 : 10664 : continue;
4108 : 1671 : if (!zero_call_used_regno_p (regno, all_sse_zeroed,
4109 : 1296 : exit_with_mmx_mode && !all_mm_zeroed))
4110 : 375 : continue;
4111 : :
4112 : 921 : SET_HARD_REG_BIT (zeroed_hardregs, regno);
4113 : :
4114 : 921 : machine_mode mode = zero_call_used_regno_mode (regno);
4115 : :
4116 : 921 : rtx reg = gen_rtx_REG (mode, regno);
4117 : 921 : rtx tmp = gen_rtx_SET (reg, CONST0_RTX (mode));
4118 : :
4119 : 921 : switch (mode)
4120 : : {
4121 : 533 : case E_SImode:
4122 : 533 : if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ())
4123 : : {
4124 : 533 : rtx clob = gen_rtx_CLOBBER (VOIDmode,
4125 : : gen_rtx_REG (CCmode,
4126 : : FLAGS_REG));
4127 : 533 : tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2,
4128 : : tmp,
4129 : : clob));
4130 : : }
4131 : : /* FALLTHRU. */
4132 : :
4133 : 921 : case E_V4SFmode:
4134 : 921 : case E_HImode:
4135 : 921 : case E_V2SImode:
4136 : 921 : emit_insn (tmp);
4137 : 921 : break;
4138 : :
4139 : 0 : default:
4140 : 0 : gcc_unreachable ();
4141 : : }
4142 : : }
4143 : 130 : return zeroed_hardregs;
4144 : : }
4145 : :
4146 : : /* Define how to find the value returned by a function.
4147 : : VALTYPE is the data type of the value (as a tree).
4148 : : If the precise function being called is known, FUNC is its FUNCTION_DECL;
4149 : : otherwise, FUNC is 0. */
4150 : :
4151 : : static rtx
4152 : 3872415 : function_value_32 (machine_mode orig_mode, machine_mode mode,
4153 : : const_tree fntype, const_tree fn)
4154 : : {
4155 : 3872415 : unsigned int regno;
4156 : :
4157 : : /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
4158 : : we normally prevent this case when mmx is not available. However
4159 : : some ABIs may require the result to be returned like DImode. */
4160 : 4139892 : if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
4161 : : regno = FIRST_MMX_REG;
4162 : :
4163 : : /* 16-byte vector modes in %xmm0. See ix86_return_in_memory for where
4164 : : we prevent this case when sse is not available. However some ABIs
4165 : : may require the result to be returned like integer TImode. */
4166 : 3863175 : else if (mode == TImode
4167 : 4121412 : || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
4168 : : regno = FIRST_SSE_REG;
4169 : :
4170 : : /* 32-byte vector modes in %ymm0. */
4171 : 3903778 : else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
4172 : : regno = FIRST_SSE_REG;
4173 : :
4174 : : /* 64-byte vector modes in %zmm0. */
4175 : 3760020 : else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
4176 : : regno = FIRST_SSE_REG;
4177 : :
4178 : : /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387). */
4179 : 3604938 : else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
4180 : : regno = FIRST_FLOAT_REG;
4181 : : else
4182 : : /* Most things go in %eax. */
4183 : 3542881 : regno = AX_REG;
4184 : :
4185 : : /* Return __bf16/ _Float16/_Complex _Foat16 by sse register. */
4186 : 3872415 : if (mode == HFmode || mode == BFmode)
4187 : : {
4188 : 1647 : if (!TARGET_SSE2)
4189 : : {
4190 : 0 : error ("SSE register return with SSE2 disabled");
4191 : 0 : regno = AX_REG;
4192 : : }
4193 : : else
4194 : : regno = FIRST_SSE_REG;
4195 : : }
4196 : :
4197 : 3872415 : if (mode == HCmode)
4198 : : {
4199 : 80 : if (!TARGET_SSE2)
4200 : 0 : error ("SSE register return with SSE2 disabled");
4201 : :
4202 : 80 : rtx ret = gen_rtx_PARALLEL (mode, rtvec_alloc(1));
4203 : 160 : XVECEXP (ret, 0, 0)
4204 : 160 : = gen_rtx_EXPR_LIST (VOIDmode,
4205 : : gen_rtx_REG (SImode,
4206 : 80 : TARGET_SSE2 ? FIRST_SSE_REG : AX_REG),
4207 : : GEN_INT (0));
4208 : 80 : return ret;
4209 : : }
4210 : :
4211 : : /* Override FP return register with %xmm0 for local functions when
4212 : : SSE math is enabled or for functions with sseregparm attribute. */
4213 : 3872335 : if ((fn || fntype) && (mode == SFmode || mode == DFmode))
4214 : : {
4215 : 48327 : int sse_level = ix86_function_sseregparm (fntype, fn, false);
4216 : 48327 : if (sse_level == -1)
4217 : : {
4218 : 0 : error ("calling %qD with SSE calling convention without "
4219 : : "SSE/SSE2 enabled", fn);
4220 : 0 : sorry ("this is a GCC bug that can be worked around by adding "
4221 : : "attribute used to function called");
4222 : : }
4223 : 48327 : else if ((sse_level >= 1 && mode == SFmode)
4224 : 48327 : || (sse_level == 2 && mode == DFmode))
4225 : : regno = FIRST_SSE_REG;
4226 : : }
4227 : :
4228 : : /* OImode shouldn't be used directly. */
4229 : 3872335 : gcc_assert (mode != OImode);
4230 : :
4231 : 3872335 : return gen_rtx_REG (orig_mode, regno);
4232 : : }
4233 : :
4234 : : static rtx
4235 : 90973890 : function_value_64 (machine_mode orig_mode, machine_mode mode,
4236 : : const_tree valtype)
4237 : : {
4238 : 90973890 : rtx ret;
4239 : :
4240 : : /* Handle libcalls, which don't provide a type node. */
4241 : 90973890 : if (valtype == NULL)
4242 : : {
4243 : 104933 : unsigned int regno;
4244 : :
4245 : 104933 : switch (mode)
4246 : : {
4247 : : case E_BFmode:
4248 : : case E_HFmode:
4249 : : case E_HCmode:
4250 : : case E_SFmode:
4251 : : case E_SCmode:
4252 : : case E_DFmode:
4253 : : case E_DCmode:
4254 : : case E_TFmode:
4255 : : case E_SDmode:
4256 : : case E_DDmode:
4257 : : case E_TDmode:
4258 : : regno = FIRST_SSE_REG;
4259 : : break;
4260 : 1035 : case E_XFmode:
4261 : 1035 : case E_XCmode:
4262 : 1035 : regno = FIRST_FLOAT_REG;
4263 : 1035 : break;
4264 : : case E_TCmode:
4265 : : return NULL;
4266 : 56753 : default:
4267 : 56753 : regno = AX_REG;
4268 : : }
4269 : :
4270 : 104933 : return gen_rtx_REG (mode, regno);
4271 : : }
4272 : 90868957 : else if (POINTER_TYPE_P (valtype))
4273 : : {
4274 : : /* Pointers are always returned in word_mode. */
4275 : 14303967 : mode = word_mode;
4276 : : }
4277 : :
4278 : 90868957 : ret = construct_container (mode, orig_mode, valtype, 1,
4279 : : X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
4280 : : x86_64_int_return_registers, 0);
4281 : :
4282 : : /* For zero sized structures, construct_container returns NULL, but we
4283 : : need to keep rest of compiler happy by returning meaningful value. */
4284 : 90868957 : if (!ret)
4285 : 195153 : ret = gen_rtx_REG (orig_mode, AX_REG);
4286 : :
4287 : : return ret;
4288 : : }
4289 : :
4290 : : static rtx
4291 : 0 : function_value_ms_32 (machine_mode orig_mode, machine_mode mode,
4292 : : const_tree fntype, const_tree fn, const_tree valtype)
4293 : : {
4294 : 0 : unsigned int regno;
4295 : :
4296 : : /* Floating point return values in %st(0)
4297 : : (unless -mno-fp-ret-in-387 or aggregate type of up to 8 bytes). */
4298 : 0 : if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387
4299 : 0 : && (GET_MODE_SIZE (mode) > 8
4300 : 0 : || valtype == NULL_TREE || !AGGREGATE_TYPE_P (valtype)))
4301 : : {
4302 : 0 : regno = FIRST_FLOAT_REG;
4303 : 0 : return gen_rtx_REG (orig_mode, regno);
4304 : : }
4305 : : else
4306 : 0 : return function_value_32(orig_mode, mode, fntype,fn);
4307 : : }
4308 : :
4309 : : static rtx
4310 : 762440 : function_value_ms_64 (machine_mode orig_mode, machine_mode mode,
4311 : : const_tree valtype)
4312 : : {
4313 : 762440 : unsigned int regno = AX_REG;
4314 : :
4315 : 762440 : if (TARGET_SSE)
4316 : : {
4317 : 1523426 : switch (GET_MODE_SIZE (mode))
4318 : : {
4319 : 13985 : case 16:
4320 : 13985 : if (valtype != NULL_TREE
4321 : 13985 : && !VECTOR_INTEGER_TYPE_P (valtype)
4322 : 7146 : && !VECTOR_INTEGER_TYPE_P (valtype)
4323 : 7146 : && !INTEGRAL_TYPE_P (valtype)
4324 : 21131 : && !VECTOR_FLOAT_TYPE_P (valtype))
4325 : : break;
4326 : 13985 : if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
4327 : : && !COMPLEX_MODE_P (mode))
4328 : 197510 : regno = FIRST_SSE_REG;
4329 : : break;
4330 : 728054 : case 8:
4331 : 728054 : case 4:
4332 : 728054 : if (valtype != NULL_TREE && AGGREGATE_TYPE_P (valtype))
4333 : : break;
4334 : 713302 : if (mode == SFmode || mode == DFmode)
4335 : 197510 : regno = FIRST_SSE_REG;
4336 : : break;
4337 : : default:
4338 : : break;
4339 : : }
4340 : : }
4341 : 762440 : return gen_rtx_REG (orig_mode, regno);
4342 : : }
4343 : :
4344 : : static rtx
4345 : 95608745 : ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
4346 : : machine_mode orig_mode, machine_mode mode)
4347 : : {
4348 : 95608745 : const_tree fn, fntype;
4349 : :
4350 : 95608745 : fn = NULL_TREE;
4351 : 95608745 : if (fntype_or_decl && DECL_P (fntype_or_decl))
4352 : 3523152 : fn = fntype_or_decl;
4353 : 3523152 : fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
4354 : :
4355 : 95608745 : if (ix86_function_type_abi (fntype) == MS_ABI)
4356 : : {
4357 : 762440 : if (TARGET_64BIT)
4358 : 762440 : return function_value_ms_64 (orig_mode, mode, valtype);
4359 : : else
4360 : 0 : return function_value_ms_32 (orig_mode, mode, fntype, fn, valtype);
4361 : : }
4362 : 94846305 : else if (TARGET_64BIT)
4363 : 90973890 : return function_value_64 (orig_mode, mode, valtype);
4364 : : else
4365 : 3872415 : return function_value_32 (orig_mode, mode, fntype, fn);
4366 : : }
4367 : :
4368 : : static rtx
4369 : 95500628 : ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool)
4370 : : {
4371 : 95500628 : machine_mode mode, orig_mode;
4372 : :
4373 : 95500628 : orig_mode = TYPE_MODE (valtype);
4374 : 95500628 : mode = type_natural_mode (valtype, NULL, true);
4375 : 95500628 : return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
4376 : : }
4377 : :
4378 : : /* Pointer function arguments and return values are promoted to
4379 : : word_mode for normal functions. */
4380 : :
4381 : : static machine_mode
4382 : 31832629 : ix86_promote_function_mode (const_tree type, machine_mode mode,
4383 : : int *punsignedp, const_tree fntype,
4384 : : int for_return)
4385 : : {
4386 : 31832629 : if (cfun->machine->func_type == TYPE_NORMAL
4387 : 31831636 : && type != NULL_TREE
4388 : 31798137 : && POINTER_TYPE_P (type))
4389 : : {
4390 : 15993154 : *punsignedp = POINTERS_EXTEND_UNSIGNED;
4391 : 15993154 : return word_mode;
4392 : : }
4393 : 15839475 : return default_promote_function_mode (type, mode, punsignedp, fntype,
4394 : 15839475 : for_return);
4395 : : }
4396 : :
4397 : : /* Return true if a structure, union or array with MODE containing FIELD
4398 : : should be accessed using BLKmode. */
4399 : :
4400 : : static bool
4401 : 122931313 : ix86_member_type_forces_blk (const_tree field, machine_mode mode)
4402 : : {
4403 : : /* Union with XFmode must be in BLKmode. */
4404 : 122931313 : return (mode == XFmode
4405 : 123067199 : && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE
4406 : 122808 : || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE));
4407 : : }
4408 : :
4409 : : rtx
4410 : 108117 : ix86_libcall_value (machine_mode mode)
4411 : : {
4412 : 108117 : return ix86_function_value_1 (NULL, NULL, mode, mode);
4413 : : }
4414 : :
4415 : : /* Return true iff type is returned in memory. */
4416 : :
4417 : : static bool
4418 : 96778248 : ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
4419 : : {
4420 : 96778248 : const machine_mode mode = type_natural_mode (type, NULL, true);
4421 : 96778248 : HOST_WIDE_INT size;
4422 : :
4423 : 96778248 : if (TARGET_64BIT)
4424 : : {
4425 : 92320852 : if (ix86_function_type_abi (fntype) == MS_ABI)
4426 : : {
4427 : 702115 : size = int_size_in_bytes (type);
4428 : :
4429 : : /* __m128 is returned in xmm0. */
4430 : 702115 : if ((!type || VECTOR_INTEGER_TYPE_P (type)
4431 : 682622 : || INTEGRAL_TYPE_P (type)
4432 : 216890 : || VECTOR_FLOAT_TYPE_P (type))
4433 : 501053 : && (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
4434 : : && !COMPLEX_MODE_P (mode)
4435 : 1203168 : && (GET_MODE_SIZE (mode) == 16 || size == 16))
4436 : : return false;
4437 : :
4438 : : /* Otherwise, the size must be exactly in [1248]. */
4439 : 1339972 : return size != 1 && size != 2 && size != 4 && size != 8;
4440 : : }
4441 : : else
4442 : : {
4443 : 91618737 : int needed_intregs, needed_sseregs;
4444 : :
4445 : 91618737 : return examine_argument (mode, type, 1,
4446 : : &needed_intregs, &needed_sseregs);
4447 : : }
4448 : : }
4449 : : else
4450 : : {
4451 : 4457396 : size = int_size_in_bytes (type);
4452 : :
4453 : : /* Intel MCU psABI returns scalars and aggregates no larger than 8
4454 : : bytes in registers. */
4455 : 4457396 : if (TARGET_IAMCU)
4456 : 0 : return VECTOR_MODE_P (mode) || size < 0 || size > 8;
4457 : :
4458 : 4457396 : if (mode == BLKmode)
4459 : : return true;
4460 : :
4461 : 4457396 : if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
4462 : : return false;
4463 : :
4464 : 4457396 : if (VECTOR_MODE_P (mode) || mode == TImode)
4465 : : {
4466 : : /* User-created vectors small enough to fit in EAX. */
4467 : 267449 : if (size < 8)
4468 : : return false;
4469 : :
4470 : : /* Unless ABI prescibes otherwise,
4471 : : MMX/3dNow values are returned in MM0 if available. */
4472 : :
4473 : 267449 : if (size == 8)
4474 : 9232 : return TARGET_VECT8_RETURNS || !TARGET_MMX;
4475 : :
4476 : : /* SSE values are returned in XMM0 if available. */
4477 : 258217 : if (size == 16)
4478 : 108807 : return !TARGET_SSE;
4479 : :
4480 : : /* AVX values are returned in YMM0 if available. */
4481 : 149410 : if (size == 32)
4482 : 71870 : return !TARGET_AVX;
4483 : :
4484 : : /* AVX512F values are returned in ZMM0 if available. */
4485 : 77540 : if (size == 64)
4486 : 77540 : return !TARGET_AVX512F;
4487 : : }
4488 : :
4489 : 4189947 : if (mode == XFmode)
4490 : : return false;
4491 : :
4492 : 4178799 : if (size > 12)
4493 : : return true;
4494 : :
4495 : : /* OImode shouldn't be used directly. */
4496 : 3224439 : gcc_assert (mode != OImode);
4497 : :
4498 : : return false;
4499 : : }
4500 : : }
4501 : :
4502 : : /* Implement TARGET_PUSH_ARGUMENT. */
4503 : :
4504 : : static bool
4505 : 9208905 : ix86_push_argument (unsigned int npush)
4506 : : {
4507 : : /* If SSE2 is available, use vector move to put large argument onto
4508 : : stack. NB: In 32-bit mode, use 8-byte vector move. */
4509 : 11610436 : return ((!TARGET_SSE2 || npush < (TARGET_64BIT ? 16 : 8))
4510 : 8944751 : && TARGET_PUSH_ARGS
4511 : 18153558 : && !ACCUMULATE_OUTGOING_ARGS);
4512 : : }
4513 : :
4514 : :
4515 : : /* Create the va_list data type. */
4516 : :
4517 : : static tree
4518 : 279928 : ix86_build_builtin_va_list_64 (void)
4519 : : {
4520 : 279928 : tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4521 : :
4522 : 279928 : record = lang_hooks.types.make_type (RECORD_TYPE);
4523 : 279928 : type_decl = build_decl (BUILTINS_LOCATION,
4524 : : TYPE_DECL, get_identifier ("__va_list_tag"), record);
4525 : :
4526 : 279928 : f_gpr = build_decl (BUILTINS_LOCATION,
4527 : : FIELD_DECL, get_identifier ("gp_offset"),
4528 : : unsigned_type_node);
4529 : 279928 : f_fpr = build_decl (BUILTINS_LOCATION,
4530 : : FIELD_DECL, get_identifier ("fp_offset"),
4531 : : unsigned_type_node);
4532 : 279928 : f_ovf = build_decl (BUILTINS_LOCATION,
4533 : : FIELD_DECL, get_identifier ("overflow_arg_area"),
4534 : : ptr_type_node);
4535 : 279928 : f_sav = build_decl (BUILTINS_LOCATION,
4536 : : FIELD_DECL, get_identifier ("reg_save_area"),
4537 : : ptr_type_node);
4538 : :
4539 : 279928 : va_list_gpr_counter_field = f_gpr;
4540 : 279928 : va_list_fpr_counter_field = f_fpr;
4541 : :
4542 : 279928 : DECL_FIELD_CONTEXT (f_gpr) = record;
4543 : 279928 : DECL_FIELD_CONTEXT (f_fpr) = record;
4544 : 279928 : DECL_FIELD_CONTEXT (f_ovf) = record;
4545 : 279928 : DECL_FIELD_CONTEXT (f_sav) = record;
4546 : :
4547 : 279928 : TYPE_STUB_DECL (record) = type_decl;
4548 : 279928 : TYPE_NAME (record) = type_decl;
4549 : 279928 : TYPE_FIELDS (record) = f_gpr;
4550 : 279928 : DECL_CHAIN (f_gpr) = f_fpr;
4551 : 279928 : DECL_CHAIN (f_fpr) = f_ovf;
4552 : 279928 : DECL_CHAIN (f_ovf) = f_sav;
4553 : :
4554 : 279928 : layout_type (record);
4555 : :
4556 : 279928 : TYPE_ATTRIBUTES (record) = tree_cons (get_identifier ("sysv_abi va_list"),
4557 : 279928 : NULL_TREE, TYPE_ATTRIBUTES (record));
4558 : :
4559 : : /* The correct type is an array type of one element. */
4560 : 279928 : return build_array_type (record, build_index_type (size_zero_node));
4561 : : }
4562 : :
4563 : : /* Setup the builtin va_list data type and for 64-bit the additional
4564 : : calling convention specific va_list data types. */
4565 : :
4566 : : static tree
4567 : 287011 : ix86_build_builtin_va_list (void)
4568 : : {
4569 : 287011 : if (TARGET_64BIT)
4570 : : {
4571 : : /* Initialize ABI specific va_list builtin types.
4572 : :
4573 : : In lto1, we can encounter two va_list types:
4574 : : - one as a result of the type-merge across TUs, and
4575 : : - the one constructed here.
4576 : : These two types will not have the same TYPE_MAIN_VARIANT, and therefore
4577 : : a type identity check in canonical_va_list_type based on
4578 : : TYPE_MAIN_VARIANT (which we used to have) will not work.
4579 : : Instead, we tag each va_list_type_node with its unique attribute, and
4580 : : look for the attribute in the type identity check in
4581 : : canonical_va_list_type.
4582 : :
4583 : : Tagging sysv_va_list_type_node directly with the attribute is
4584 : : problematic since it's a array of one record, which will degrade into a
4585 : : pointer to record when used as parameter (see build_va_arg comments for
4586 : : an example), dropping the attribute in the process. So we tag the
4587 : : record instead. */
4588 : :
4589 : : /* For SYSV_ABI we use an array of one record. */
4590 : 279928 : sysv_va_list_type_node = ix86_build_builtin_va_list_64 ();
4591 : :
4592 : : /* For MS_ABI we use plain pointer to argument area. */
4593 : 279928 : tree char_ptr_type = build_pointer_type (char_type_node);
4594 : 279928 : tree attr = tree_cons (get_identifier ("ms_abi va_list"), NULL_TREE,
4595 : 279928 : TYPE_ATTRIBUTES (char_ptr_type));
4596 : 279928 : ms_va_list_type_node = build_type_attribute_variant (char_ptr_type, attr);
4597 : :
4598 : 279928 : return ((ix86_abi == MS_ABI)
4599 : 279928 : ? ms_va_list_type_node
4600 : 279928 : : sysv_va_list_type_node);
4601 : : }
4602 : : else
4603 : : {
4604 : : /* For i386 we use plain pointer to argument area. */
4605 : 7083 : return build_pointer_type (char_type_node);
4606 : : }
4607 : : }
4608 : :
4609 : : /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
4610 : :
4611 : : static void
4612 : 15561 : setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
4613 : : {
4614 : 15561 : rtx save_area, mem;
4615 : 15561 : alias_set_type set;
4616 : 15561 : int i, max;
4617 : :
4618 : : /* GPR size of varargs save area. */
4619 : 15561 : if (cfun->va_list_gpr_size)
4620 : 15124 : ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
4621 : : else
4622 : 437 : ix86_varargs_gpr_size = 0;
4623 : :
4624 : : /* FPR size of varargs save area. We don't need it if we don't pass
4625 : : anything in SSE registers. */
4626 : 15561 : if (TARGET_SSE && cfun->va_list_fpr_size)
4627 : 14523 : ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
4628 : : else
4629 : 1038 : ix86_varargs_fpr_size = 0;
4630 : :
4631 : 15561 : if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
4632 : : return;
4633 : :
4634 : 15293 : save_area = frame_pointer_rtx;
4635 : 15293 : set = get_varargs_alias_set ();
4636 : :
4637 : 15293 : max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
4638 : 15293 : if (max > X86_64_REGPARM_MAX)
4639 : : max = X86_64_REGPARM_MAX;
4640 : :
4641 : 15293 : const int *parm_regs;
4642 : 15293 : if (cum->preserve_none_abi)
4643 : : parm_regs = x86_64_preserve_none_int_parameter_registers;
4644 : : else
4645 : 15292 : parm_regs = x86_64_int_parameter_registers;
4646 : :
4647 : 84841 : for (i = cum->regno; i < max; i++)
4648 : : {
4649 : 69548 : mem = gen_rtx_MEM (word_mode,
4650 : 69548 : plus_constant (Pmode, save_area, i * UNITS_PER_WORD));
4651 : 69548 : MEM_NOTRAP_P (mem) = 1;
4652 : 69548 : set_mem_alias_set (mem, set);
4653 : 69548 : emit_move_insn (mem,
4654 : 69548 : gen_rtx_REG (word_mode, parm_regs[i]));
4655 : : }
4656 : :
4657 : 15293 : if (ix86_varargs_fpr_size)
4658 : : {
4659 : 14523 : machine_mode smode;
4660 : 14523 : rtx_code_label *label;
4661 : 14523 : rtx test;
4662 : :
4663 : : /* Now emit code to save SSE registers. The AX parameter contains number
4664 : : of SSE parameter registers used to call this function, though all we
4665 : : actually check here is the zero/non-zero status. */
4666 : :
4667 : 14523 : label = gen_label_rtx ();
4668 : 14523 : test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx);
4669 : 14523 : emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1),
4670 : : label));
4671 : :
4672 : : /* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if
4673 : : we used movdqa (i.e. TImode) instead? Perhaps even better would
4674 : : be if we could determine the real mode of the data, via a hook
4675 : : into pass_stdarg. Ignore all that for now. */
4676 : 14523 : smode = V4SFmode;
4677 : 14523 : if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode))
4678 : 4034 : crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode);
4679 : :
4680 : 14523 : max = cum->sse_regno + cfun->va_list_fpr_size / 16;
4681 : 14523 : if (max > X86_64_SSE_REGPARM_MAX)
4682 : : max = X86_64_SSE_REGPARM_MAX;
4683 : :
4684 : 129104 : for (i = cum->sse_regno; i < max; ++i)
4685 : : {
4686 : 114581 : mem = plus_constant (Pmode, save_area,
4687 : 114581 : i * 16 + ix86_varargs_gpr_size);
4688 : 114581 : mem = gen_rtx_MEM (smode, mem);
4689 : 114581 : MEM_NOTRAP_P (mem) = 1;
4690 : 114581 : set_mem_alias_set (mem, set);
4691 : 114581 : set_mem_align (mem, GET_MODE_ALIGNMENT (smode));
4692 : :
4693 : 114581 : emit_move_insn (mem, gen_rtx_REG (smode, GET_SSE_REGNO (i)));
4694 : : }
4695 : :
4696 : 14523 : emit_label (label);
4697 : : }
4698 : : }
4699 : :
4700 : : static void
4701 : 5652 : setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
4702 : : {
4703 : 5652 : alias_set_type set = get_varargs_alias_set ();
4704 : 5652 : int i;
4705 : :
4706 : : /* Reset to zero, as there might be a sysv vaarg used
4707 : : before. */
4708 : 5652 : ix86_varargs_gpr_size = 0;
4709 : 5652 : ix86_varargs_fpr_size = 0;
4710 : :
4711 : 14154 : for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
4712 : : {
4713 : 8502 : rtx reg, mem;
4714 : :
4715 : 8502 : mem = gen_rtx_MEM (Pmode,
4716 : 8502 : plus_constant (Pmode, virtual_incoming_args_rtx,
4717 : 8502 : i * UNITS_PER_WORD));
4718 : 8502 : MEM_NOTRAP_P (mem) = 1;
4719 : 8502 : set_mem_alias_set (mem, set);
4720 : :
4721 : 8502 : reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
4722 : 8502 : emit_move_insn (mem, reg);
4723 : : }
4724 : 5652 : }
4725 : :
4726 : : static void
4727 : 21359 : ix86_setup_incoming_varargs (cumulative_args_t cum_v,
4728 : : const function_arg_info &arg,
4729 : : int *, int no_rtl)
4730 : : {
4731 : 21359 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
4732 : 21359 : CUMULATIVE_ARGS next_cum;
4733 : 21359 : tree fntype;
4734 : :
4735 : : /* This argument doesn't appear to be used anymore. Which is good,
4736 : : because the old code here didn't suppress rtl generation. */
4737 : 21359 : gcc_assert (!no_rtl);
4738 : :
4739 : 21359 : if (!TARGET_64BIT)
4740 : 146 : return;
4741 : :
4742 : 21213 : fntype = TREE_TYPE (current_function_decl);
4743 : :
4744 : : /* For varargs, we do not want to skip the dummy va_dcl argument.
4745 : : For stdargs, we do want to skip the last named argument. */
4746 : 21213 : next_cum = *cum;
4747 : 21213 : if ((!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl))
4748 : 77 : || arg.type != NULL_TREE)
4749 : 21225 : && stdarg_p (fntype))
4750 : 21148 : ix86_function_arg_advance (pack_cumulative_args (&next_cum), arg);
4751 : :
4752 : 21213 : if (cum->call_abi == MS_ABI)
4753 : 5652 : setup_incoming_varargs_ms_64 (&next_cum);
4754 : : else
4755 : 15561 : setup_incoming_varargs_64 (&next_cum);
4756 : : }
4757 : :
4758 : : /* Checks if TYPE is of kind va_list char *. */
4759 : :
4760 : : static bool
4761 : 72803 : is_va_list_char_pointer (tree type)
4762 : : {
4763 : 72803 : tree canonic;
4764 : :
4765 : : /* For 32-bit it is always true. */
4766 : 72803 : if (!TARGET_64BIT)
4767 : : return true;
4768 : 72641 : canonic = ix86_canonical_va_list_type (type);
4769 : 72641 : return (canonic == ms_va_list_type_node
4770 : 72641 : || (ix86_abi == MS_ABI && canonic == va_list_type_node));
4771 : : }
4772 : :
4773 : : /* Implement va_start. */
4774 : :
4775 : : static void
4776 : 20875 : ix86_va_start (tree valist, rtx nextarg)
4777 : : {
4778 : 20875 : HOST_WIDE_INT words, n_gpr, n_fpr;
4779 : 20875 : tree f_gpr, f_fpr, f_ovf, f_sav;
4780 : 20875 : tree gpr, fpr, ovf, sav, t;
4781 : 20875 : tree type;
4782 : 20875 : rtx ovf_rtx;
4783 : :
4784 : 20875 : if (flag_split_stack
4785 : 12 : && cfun->machine->split_stack_varargs_pointer == NULL_RTX)
4786 : : {
4787 : 12 : unsigned int scratch_regno;
4788 : :
4789 : : /* When we are splitting the stack, we can't refer to the stack
4790 : : arguments using internal_arg_pointer, because they may be on
4791 : : the old stack. The split stack prologue will arrange to
4792 : : leave a pointer to the old stack arguments in a scratch
4793 : : register, which we here copy to a pseudo-register. The split
4794 : : stack prologue can't set the pseudo-register directly because
4795 : : it (the prologue) runs before any registers have been saved. */
4796 : :
4797 : 12 : scratch_regno = split_stack_prologue_scratch_regno ();
4798 : 12 : if (scratch_regno != INVALID_REGNUM)
4799 : : {
4800 : 12 : rtx reg;
4801 : 12 : rtx_insn *seq;
4802 : :
4803 : 16 : reg = gen_reg_rtx (Pmode);
4804 : 12 : cfun->machine->split_stack_varargs_pointer = reg;
4805 : :
4806 : 12 : start_sequence ();
4807 : 16 : emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno));
4808 : 12 : seq = end_sequence ();
4809 : :
4810 : 12 : push_topmost_sequence ();
4811 : 12 : emit_insn_after (seq, entry_of_function ());
4812 : 12 : pop_topmost_sequence ();
4813 : : }
4814 : : }
4815 : :
4816 : : /* Only 64bit target needs something special. */
4817 : 20875 : if (is_va_list_char_pointer (TREE_TYPE (valist)))
4818 : : {
4819 : 5656 : if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
4820 : 5652 : std_expand_builtin_va_start (valist, nextarg);
4821 : : else
4822 : : {
4823 : 4 : rtx va_r, next;
4824 : :
4825 : 4 : va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
4826 : 8 : next = expand_binop (ptr_mode, add_optab,
4827 : 4 : cfun->machine->split_stack_varargs_pointer,
4828 : : crtl->args.arg_offset_rtx,
4829 : : NULL_RTX, 0, OPTAB_LIB_WIDEN);
4830 : 4 : convert_move (va_r, next, 0);
4831 : : }
4832 : 5656 : return;
4833 : : }
4834 : :
4835 : 15219 : f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
4836 : 15219 : f_fpr = DECL_CHAIN (f_gpr);
4837 : 15219 : f_ovf = DECL_CHAIN (f_fpr);
4838 : 15219 : f_sav = DECL_CHAIN (f_ovf);
4839 : :
4840 : 15219 : valist = build_simple_mem_ref (valist);
4841 : 15219 : TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node);
4842 : : /* The following should be folded into the MEM_REF offset. */
4843 : 15219 : gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist),
4844 : : f_gpr, NULL_TREE);
4845 : 15219 : fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
4846 : : f_fpr, NULL_TREE);
4847 : 15219 : ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
4848 : : f_ovf, NULL_TREE);
4849 : 15219 : sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
4850 : : f_sav, NULL_TREE);
4851 : :
4852 : : /* Count number of gp and fp argument registers used. */
4853 : 15219 : words = crtl->args.info.words;
4854 : 15219 : n_gpr = crtl->args.info.regno;
4855 : 15219 : n_fpr = crtl->args.info.sse_regno;
4856 : :
4857 : 15219 : if (cfun->va_list_gpr_size)
4858 : : {
4859 : 14996 : type = TREE_TYPE (gpr);
4860 : 14996 : t = build2 (MODIFY_EXPR, type,
4861 : 14996 : gpr, build_int_cst (type, n_gpr * 8));
4862 : 14996 : TREE_SIDE_EFFECTS (t) = 1;
4863 : 14996 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4864 : : }
4865 : :
4866 : 15219 : if (TARGET_SSE && cfun->va_list_fpr_size)
4867 : : {
4868 : 14383 : type = TREE_TYPE (fpr);
4869 : 14383 : t = build2 (MODIFY_EXPR, type, fpr,
4870 : 14383 : build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
4871 : 14383 : TREE_SIDE_EFFECTS (t) = 1;
4872 : 14383 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4873 : : }
4874 : :
4875 : : /* Find the overflow area. */
4876 : 15219 : type = TREE_TYPE (ovf);
4877 : 15219 : if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
4878 : 15211 : ovf_rtx = crtl->args.internal_arg_pointer;
4879 : : else
4880 : : ovf_rtx = cfun->machine->split_stack_varargs_pointer;
4881 : 15219 : t = make_tree (type, ovf_rtx);
4882 : 15219 : if (words != 0)
4883 : 486 : t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD);
4884 : :
4885 : 15219 : t = build2 (MODIFY_EXPR, type, ovf, t);
4886 : 15219 : TREE_SIDE_EFFECTS (t) = 1;
4887 : 15219 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4888 : :
4889 : 15219 : if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
4890 : : {
4891 : : /* Find the register save area.
4892 : : Prologue of the function save it right above stack frame. */
4893 : 15165 : type = TREE_TYPE (sav);
4894 : 15165 : t = make_tree (type, frame_pointer_rtx);
4895 : 15165 : if (!ix86_varargs_gpr_size)
4896 : 169 : t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX);
4897 : :
4898 : 15165 : t = build2 (MODIFY_EXPR, type, sav, t);
4899 : 15165 : TREE_SIDE_EFFECTS (t) = 1;
4900 : 15165 : expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4901 : : }
4902 : : }
4903 : :
4904 : : /* Implement va_arg. */
4905 : :
4906 : : static tree
4907 : 51928 : ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
4908 : : gimple_seq *post_p)
4909 : : {
4910 : 51928 : static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
4911 : 51928 : tree f_gpr, f_fpr, f_ovf, f_sav;
4912 : 51928 : tree gpr, fpr, ovf, sav, t;
4913 : 51928 : int size, rsize;
4914 : 51928 : tree lab_false, lab_over = NULL_TREE;
4915 : 51928 : tree addr, t2;
4916 : 51928 : rtx container;
4917 : 51928 : int indirect_p = 0;
4918 : 51928 : tree ptrtype;
4919 : 51928 : machine_mode nat_mode;
4920 : 51928 : unsigned int arg_boundary;
4921 : 51928 : unsigned int type_align;
4922 : :
4923 : : /* Only 64bit target needs something special. */
4924 : 51928 : if (is_va_list_char_pointer (TREE_TYPE (valist)))
4925 : 260 : return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
4926 : :
4927 : 51668 : f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
4928 : 51668 : f_fpr = DECL_CHAIN (f_gpr);
4929 : 51668 : f_ovf = DECL_CHAIN (f_fpr);
4930 : 51668 : f_sav = DECL_CHAIN (f_ovf);
4931 : :
4932 : 51668 : gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
4933 : : valist, f_gpr, NULL_TREE);
4934 : :
4935 : 51668 : fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
4936 : 51668 : ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
4937 : 51668 : sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
4938 : :
4939 : 51668 : indirect_p = pass_va_arg_by_reference (type);
4940 : 51668 : if (indirect_p)
4941 : 103 : type = build_pointer_type (type);
4942 : 51668 : size = arg_int_size_in_bytes (type);
4943 : 51668 : rsize = CEIL (size, UNITS_PER_WORD);
4944 : :
4945 : 51668 : nat_mode = type_natural_mode (type, NULL, false);
4946 : 51668 : switch (nat_mode)
4947 : : {
4948 : 28 : case E_V16HFmode:
4949 : 28 : case E_V16BFmode:
4950 : 28 : case E_V8SFmode:
4951 : 28 : case E_V8SImode:
4952 : 28 : case E_V32QImode:
4953 : 28 : case E_V16HImode:
4954 : 28 : case E_V4DFmode:
4955 : 28 : case E_V4DImode:
4956 : 28 : case E_V32HFmode:
4957 : 28 : case E_V32BFmode:
4958 : 28 : case E_V16SFmode:
4959 : 28 : case E_V16SImode:
4960 : 28 : case E_V64QImode:
4961 : 28 : case E_V32HImode:
4962 : 28 : case E_V8DFmode:
4963 : 28 : case E_V8DImode:
4964 : : /* Unnamed 256 and 512bit vector mode parameters are passed on stack. */
4965 : 28 : if (!TARGET_64BIT_MS_ABI)
4966 : : {
4967 : : container = NULL;
4968 : : break;
4969 : : }
4970 : : /* FALLTHRU */
4971 : :
4972 : 51640 : default:
4973 : 51640 : container = construct_container (nat_mode, TYPE_MODE (type),
4974 : : type, 0, X86_64_REGPARM_MAX,
4975 : : X86_64_SSE_REGPARM_MAX, intreg,
4976 : : 0);
4977 : 51640 : break;
4978 : : }
4979 : :
4980 : : /* Pull the value out of the saved registers. */
4981 : :
4982 : 51668 : addr = create_tmp_var (ptr_type_node, "addr");
4983 : 51668 : type_align = TYPE_ALIGN (type);
4984 : :
4985 : 51668 : if (container)
4986 : : {
4987 : 28577 : int needed_intregs, needed_sseregs;
4988 : 28577 : bool need_temp;
4989 : 28577 : tree int_addr, sse_addr;
4990 : :
4991 : 28577 : lab_false = create_artificial_label (UNKNOWN_LOCATION);
4992 : 28577 : lab_over = create_artificial_label (UNKNOWN_LOCATION);
4993 : :
4994 : 28577 : examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
4995 : :
4996 : 28577 : bool container_in_reg = false;
4997 : 28577 : if (REG_P (container))
4998 : : container_in_reg = true;
4999 : 1641 : else if (GET_CODE (container) == PARALLEL
5000 : 1641 : && GET_MODE (container) == BLKmode
5001 : 580 : && XVECLEN (container, 0) == 1)
5002 : : {
5003 : : /* Check if it is a PARALLEL BLKmode container of an EXPR_LIST
5004 : : expression in a TImode register. In this case, temp isn't
5005 : : needed. Otherwise, the TImode variable will be put in the
5006 : : GPR save area which guarantees only 8-byte alignment. */
5007 : 509 : rtx x = XVECEXP (container, 0, 0);
5008 : 509 : if (GET_CODE (x) == EXPR_LIST
5009 : 509 : && REG_P (XEXP (x, 0))
5010 : 509 : && XEXP (x, 1) == const0_rtx)
5011 : : container_in_reg = true;
5012 : : }
5013 : :
5014 : 680 : need_temp = (!container_in_reg
5015 : 1150 : && ((needed_intregs && TYPE_ALIGN (type) > 64)
5016 : 680 : || TYPE_ALIGN (type) > 128));
5017 : :
5018 : : /* In case we are passing structure, verify that it is consecutive block
5019 : : on the register save area. If not we need to do moves. */
5020 : 680 : if (!need_temp && !container_in_reg)
5021 : : {
5022 : : /* Verify that all registers are strictly consecutive */
5023 : 966 : if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
5024 : : {
5025 : : int i;
5026 : :
5027 : 815 : for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
5028 : : {
5029 : 529 : rtx slot = XVECEXP (container, 0, i);
5030 : 529 : if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
5031 : 529 : || INTVAL (XEXP (slot, 1)) != i * 16)
5032 : : need_temp = true;
5033 : : }
5034 : : }
5035 : : else
5036 : : {
5037 : : int i;
5038 : :
5039 : 1120 : for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
5040 : : {
5041 : 726 : rtx slot = XVECEXP (container, 0, i);
5042 : 726 : if (REGNO (XEXP (slot, 0)) != (unsigned int) i
5043 : 726 : || INTVAL (XEXP (slot, 1)) != i * 8)
5044 : : need_temp = true;
5045 : : }
5046 : : }
5047 : : }
5048 : 28577 : if (!need_temp)
5049 : : {
5050 : : int_addr = addr;
5051 : : sse_addr = addr;
5052 : : }
5053 : : else
5054 : : {
5055 : 877 : int_addr = create_tmp_var (ptr_type_node, "int_addr");
5056 : 877 : sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
5057 : : }
5058 : :
5059 : : /* First ensure that we fit completely in registers. */
5060 : 28577 : if (needed_intregs)
5061 : : {
5062 : 17913 : t = build_int_cst (TREE_TYPE (gpr),
5063 : 17913 : (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
5064 : 17913 : t = build2 (GE_EXPR, boolean_type_node, gpr, t);
5065 : 17913 : t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
5066 : 17913 : t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
5067 : 17913 : gimplify_and_add (t, pre_p);
5068 : : }
5069 : 28577 : if (needed_sseregs)
5070 : : {
5071 : 11056 : t = build_int_cst (TREE_TYPE (fpr),
5072 : : (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
5073 : 11056 : + X86_64_REGPARM_MAX * 8);
5074 : 11056 : t = build2 (GE_EXPR, boolean_type_node, fpr, t);
5075 : 11056 : t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
5076 : 11056 : t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
5077 : 11056 : gimplify_and_add (t, pre_p);
5078 : : }
5079 : :
5080 : : /* Compute index to start of area used for integer regs. */
5081 : 28577 : if (needed_intregs)
5082 : : {
5083 : : /* int_addr = gpr + sav; */
5084 : 17913 : t = fold_build_pointer_plus (sav, gpr);
5085 : 17913 : gimplify_assign (int_addr, t, pre_p);
5086 : : }
5087 : 28577 : if (needed_sseregs)
5088 : : {
5089 : : /* sse_addr = fpr + sav; */
5090 : 11056 : t = fold_build_pointer_plus (sav, fpr);
5091 : 11056 : gimplify_assign (sse_addr, t, pre_p);
5092 : : }
5093 : 28577 : if (need_temp)
5094 : : {
5095 : 877 : int i, prev_size = 0;
5096 : 877 : tree temp = create_tmp_var (type, "va_arg_tmp");
5097 : 877 : TREE_ADDRESSABLE (temp) = 1;
5098 : :
5099 : : /* addr = &temp; */
5100 : 877 : t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
5101 : 877 : gimplify_assign (addr, t, pre_p);
5102 : :
5103 : 2241 : for (i = 0; i < XVECLEN (container, 0); i++)
5104 : : {
5105 : 1364 : rtx slot = XVECEXP (container, 0, i);
5106 : 1364 : rtx reg = XEXP (slot, 0);
5107 : 1364 : machine_mode mode = GET_MODE (reg);
5108 : 1364 : tree piece_type;
5109 : 1364 : tree addr_type;
5110 : 1364 : tree daddr_type;
5111 : 1364 : tree src_addr, src;
5112 : 1364 : int src_offset;
5113 : 1364 : tree dest_addr, dest;
5114 : 1364 : int cur_size = GET_MODE_SIZE (mode);
5115 : :
5116 : 1364 : gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
5117 : 1364 : prev_size = INTVAL (XEXP (slot, 1));
5118 : 1364 : if (prev_size + cur_size > size)
5119 : : {
5120 : 30 : cur_size = size - prev_size;
5121 : 30 : unsigned int nbits = cur_size * BITS_PER_UNIT;
5122 : 30 : if (!int_mode_for_size (nbits, 1).exists (&mode))
5123 : 10 : mode = QImode;
5124 : : }
5125 : 1364 : piece_type = lang_hooks.types.type_for_mode (mode, 1);
5126 : 1364 : if (mode == GET_MODE (reg))
5127 : 1334 : addr_type = build_pointer_type (piece_type);
5128 : : else
5129 : 30 : addr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
5130 : : true);
5131 : 1364 : daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
5132 : : true);
5133 : :
5134 : 1364 : if (SSE_REGNO_P (REGNO (reg)))
5135 : : {
5136 : 534 : src_addr = sse_addr;
5137 : 534 : src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
5138 : : }
5139 : : else
5140 : : {
5141 : 830 : src_addr = int_addr;
5142 : 830 : src_offset = REGNO (reg) * 8;
5143 : : }
5144 : 1364 : src_addr = fold_convert (addr_type, src_addr);
5145 : 1364 : src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset);
5146 : :
5147 : 1364 : dest_addr = fold_convert (daddr_type, addr);
5148 : 1364 : dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size);
5149 : 2728 : if (cur_size == GET_MODE_SIZE (mode))
5150 : : {
5151 : 1354 : src = build_va_arg_indirect_ref (src_addr);
5152 : 1354 : dest = build_va_arg_indirect_ref (dest_addr);
5153 : :
5154 : 1354 : gimplify_assign (dest, src, pre_p);
5155 : : }
5156 : : else
5157 : : {
5158 : 10 : tree copy
5159 : 20 : = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
5160 : : 3, dest_addr, src_addr,
5161 : 10 : size_int (cur_size));
5162 : 10 : gimplify_and_add (copy, pre_p);
5163 : : }
5164 : 1364 : prev_size += cur_size;
5165 : : }
5166 : : }
5167 : :
5168 : 28577 : if (needed_intregs)
5169 : : {
5170 : 17913 : t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
5171 : 17913 : build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
5172 : 17913 : gimplify_assign (gpr, t, pre_p);
5173 : : /* The GPR save area guarantees only 8-byte alignment. */
5174 : 17913 : if (!need_temp)
5175 : 17109 : type_align = MIN (type_align, 64);
5176 : : }
5177 : :
5178 : 28577 : if (needed_sseregs)
5179 : : {
5180 : 11056 : t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
5181 : 11056 : build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
5182 : 11056 : gimplify_assign (unshare_expr (fpr), t, pre_p);
5183 : : }
5184 : :
5185 : 28577 : gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
5186 : :
5187 : 28577 : gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
5188 : : }
5189 : :
5190 : : /* ... otherwise out of the overflow area. */
5191 : :
5192 : : /* When we align parameter on stack for caller, if the parameter
5193 : : alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
5194 : : aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee
5195 : : here with caller. */
5196 : 51668 : arg_boundary = ix86_function_arg_boundary (VOIDmode, type);
5197 : 51668 : if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
5198 : : arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
5199 : :
5200 : : /* Care for on-stack alignment if needed. */
5201 : 51668 : if (arg_boundary <= 64 || size == 0)
5202 : 34631 : t = ovf;
5203 : : else
5204 : : {
5205 : 17037 : HOST_WIDE_INT align = arg_boundary / 8;
5206 : 17037 : t = fold_build_pointer_plus_hwi (ovf, align - 1);
5207 : 17037 : t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
5208 : 17037 : build_int_cst (TREE_TYPE (t), -align));
5209 : : }
5210 : :
5211 : 51668 : gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
5212 : 51668 : gimplify_assign (addr, t, pre_p);
5213 : :
5214 : 51668 : t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD);
5215 : 51668 : gimplify_assign (unshare_expr (ovf), t, pre_p);
5216 : :
5217 : 51668 : if (container)
5218 : 28577 : gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
5219 : :
5220 : 51668 : type = build_aligned_type (type, type_align);
5221 : 51668 : ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
5222 : 51668 : addr = fold_convert (ptrtype, addr);
5223 : :
5224 : 51668 : if (indirect_p)
5225 : 103 : addr = build_va_arg_indirect_ref (addr);
5226 : 51668 : return build_va_arg_indirect_ref (addr);
5227 : : }
5228 : :
5229 : : /* Return true if OPNUM's MEM should be matched
5230 : : in movabs* patterns. */
5231 : :
5232 : : bool
5233 : 17941 : ix86_check_movabs (rtx insn, int opnum)
5234 : : {
5235 : 17941 : rtx set, mem;
5236 : :
5237 : 17941 : set = PATTERN (insn);
5238 : 17941 : if (GET_CODE (set) == PARALLEL)
5239 : 0 : set = XVECEXP (set, 0, 0);
5240 : 17941 : gcc_assert (GET_CODE (set) == SET);
5241 : 17941 : mem = XEXP (set, opnum);
5242 : 17941 : while (SUBREG_P (mem))
5243 : 0 : mem = SUBREG_REG (mem);
5244 : 17941 : gcc_assert (MEM_P (mem));
5245 : 17941 : return volatile_ok || !MEM_VOLATILE_P (mem);
5246 : : }
5247 : :
5248 : : /* Return true if XVECEXP idx of INSN satisfies MOVS arguments. */
5249 : : bool
5250 : 174480 : ix86_check_movs (rtx insn, int idx)
5251 : : {
5252 : 174480 : rtx pat = PATTERN (insn);
5253 : 174480 : gcc_assert (GET_CODE (pat) == PARALLEL);
5254 : :
5255 : 174480 : rtx set = XVECEXP (pat, 0, idx);
5256 : 174480 : gcc_assert (GET_CODE (set) == SET);
5257 : :
5258 : 174480 : rtx dst = SET_DEST (set);
5259 : 174480 : gcc_assert (MEM_P (dst));
5260 : :
5261 : 174480 : rtx src = SET_SRC (set);
5262 : 174480 : gcc_assert (MEM_P (src));
5263 : :
5264 : 174480 : return (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (dst))
5265 : 348960 : && (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (src))
5266 : 0 : || Pmode == word_mode));
5267 : : }
5268 : :
5269 : : /* Return false if INSN contains a MEM with a non-default address space. */
5270 : : bool
5271 : 66730 : ix86_check_no_addr_space (rtx insn)
5272 : : {
5273 : 66730 : subrtx_var_iterator::array_type array;
5274 : 1468476 : FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), ALL)
5275 : : {
5276 : 1401746 : rtx x = *iter;
5277 : 1535206 : if (MEM_P (x) && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x)))
5278 : 0 : return false;
5279 : : }
5280 : 66730 : return true;
5281 : 66730 : }
5282 : :
5283 : : /* Initialize the table of extra 80387 mathematical constants. */
5284 : :
5285 : : static void
5286 : 2427 : init_ext_80387_constants (void)
5287 : : {
5288 : 2427 : static const char * cst[5] =
5289 : : {
5290 : : "0.3010299956639811952256464283594894482", /* 0: fldlg2 */
5291 : : "0.6931471805599453094286904741849753009", /* 1: fldln2 */
5292 : : "1.4426950408889634073876517827983434472", /* 2: fldl2e */
5293 : : "3.3219280948873623478083405569094566090", /* 3: fldl2t */
5294 : : "3.1415926535897932385128089594061862044", /* 4: fldpi */
5295 : : };
5296 : 2427 : int i;
5297 : :
5298 : 14562 : for (i = 0; i < 5; i++)
5299 : : {
5300 : 12135 : real_from_string (&ext_80387_constants_table[i], cst[i]);
5301 : : /* Ensure each constant is rounded to XFmode precision. */
5302 : 12135 : real_convert (&ext_80387_constants_table[i],
5303 : 24270 : XFmode, &ext_80387_constants_table[i]);
5304 : : }
5305 : :
5306 : 2427 : ext_80387_constants_init = 1;
5307 : 2427 : }
5308 : :
5309 : : /* Return non-zero if the constant is something that
5310 : : can be loaded with a special instruction. */
5311 : :
5312 : : int
5313 : 5103482 : standard_80387_constant_p (rtx x)
5314 : : {
5315 : 5103482 : machine_mode mode = GET_MODE (x);
5316 : :
5317 : 5103482 : const REAL_VALUE_TYPE *r;
5318 : :
5319 : 5103482 : if (!(CONST_DOUBLE_P (x) && X87_FLOAT_MODE_P (mode)))
5320 : : return -1;
5321 : :
5322 : 4635785 : if (x == CONST0_RTX (mode))
5323 : : return 1;
5324 : 2110773 : if (x == CONST1_RTX (mode))
5325 : : return 2;
5326 : :
5327 : 1227063 : r = CONST_DOUBLE_REAL_VALUE (x);
5328 : :
5329 : : /* For XFmode constants, try to find a special 80387 instruction when
5330 : : optimizing for size or on those CPUs that benefit from them. */
5331 : 1227063 : if (mode == XFmode
5332 : 804882 : && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS)
5333 : 2031945 : && !flag_rounding_math)
5334 : : {
5335 : 797195 : int i;
5336 : :
5337 : 797195 : if (! ext_80387_constants_init)
5338 : 2420 : init_ext_80387_constants ();
5339 : :
5340 : 4772556 : for (i = 0; i < 5; i++)
5341 : 3984294 : if (real_identical (r, &ext_80387_constants_table[i]))
5342 : 8933 : return i + 3;
5343 : : }
5344 : :
5345 : : /* Load of the constant -0.0 or -1.0 will be split as
5346 : : fldz;fchs or fld1;fchs sequence. */
5347 : 1218130 : if (real_isnegzero (r))
5348 : : return 8;
5349 : 1202157 : if (real_identical (r, &dconstm1))
5350 : 300963 : return 9;
5351 : :
5352 : : return 0;
5353 : : }
5354 : :
5355 : : /* Return the opcode of the special instruction to be used to load
5356 : : the constant X. */
5357 : :
5358 : : const char *
5359 : 54947 : standard_80387_constant_opcode (rtx x)
5360 : : {
5361 : 54947 : switch (standard_80387_constant_p (x))
5362 : : {
5363 : : case 1:
5364 : : return "fldz";
5365 : 33962 : case 2:
5366 : 33962 : return "fld1";
5367 : 1 : case 3:
5368 : 1 : return "fldlg2";
5369 : 10 : case 4:
5370 : 10 : return "fldln2";
5371 : 12 : case 5:
5372 : 12 : return "fldl2e";
5373 : 2 : case 6:
5374 : 2 : return "fldl2t";
5375 : 192 : case 7:
5376 : 192 : return "fldpi";
5377 : 0 : case 8:
5378 : 0 : case 9:
5379 : 0 : return "#";
5380 : 0 : default:
5381 : 0 : gcc_unreachable ();
5382 : : }
5383 : : }
5384 : :
5385 : : /* Return the CONST_DOUBLE representing the 80387 constant that is
5386 : : loaded by the specified special instruction. The argument IDX
5387 : : matches the return value from standard_80387_constant_p. */
5388 : :
5389 : : rtx
5390 : 24 : standard_80387_constant_rtx (int idx)
5391 : : {
5392 : 24 : int i;
5393 : :
5394 : 24 : if (! ext_80387_constants_init)
5395 : 7 : init_ext_80387_constants ();
5396 : :
5397 : 24 : switch (idx)
5398 : : {
5399 : 24 : case 3:
5400 : 24 : case 4:
5401 : 24 : case 5:
5402 : 24 : case 6:
5403 : 24 : case 7:
5404 : 24 : i = idx - 3;
5405 : 24 : break;
5406 : :
5407 : 0 : default:
5408 : 0 : gcc_unreachable ();
5409 : : }
5410 : :
5411 : 24 : return const_double_from_real_value (ext_80387_constants_table[i],
5412 : 24 : XFmode);
5413 : : }
5414 : :
5415 : : /* Return 1 if X is all bits 0, 2 if X is all bits 1
5416 : : and 3 if X is all bits 1 with zero extend
5417 : : in supported SSE/AVX vector mode. */
5418 : :
5419 : : int
5420 : 50590305 : standard_sse_constant_p (rtx x, machine_mode pred_mode)
5421 : : {
5422 : 50590305 : machine_mode mode;
5423 : :
5424 : 50590305 : if (!TARGET_SSE)
5425 : : return 0;
5426 : :
5427 : 50426225 : mode = GET_MODE (x);
5428 : :
5429 : 50426225 : if (x == const0_rtx || const0_operand (x, mode))
5430 : 11978152 : return 1;
5431 : :
5432 : 38448073 : if (x == constm1_rtx
5433 : 38298178 : || vector_all_ones_operand (x, mode)
5434 : 76277440 : || ((GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
5435 : 31775663 : || GET_MODE_CLASS (pred_mode) == MODE_VECTOR_FLOAT)
5436 : 6053704 : && float_vector_all_ones_operand (x, mode)))
5437 : : {
5438 : : /* VOIDmode integer constant, get mode from the predicate. */
5439 : 620625 : if (mode == VOIDmode)
5440 : 149895 : mode = pred_mode;
5441 : :
5442 : 1241250 : switch (GET_MODE_SIZE (mode))
5443 : : {
5444 : 29261 : case 64:
5445 : 29261 : if (TARGET_AVX512F)
5446 : : return 2;
5447 : : break;
5448 : 38877 : case 32:
5449 : 38877 : if (TARGET_AVX2)
5450 : : return 2;
5451 : : break;
5452 : 541625 : case 16:
5453 : 541625 : if (TARGET_SSE2)
5454 : : return 2;
5455 : : break;
5456 : 0 : case 0:
5457 : : /* VOIDmode */
5458 : 0 : gcc_unreachable ();
5459 : : default:
5460 : : break;
5461 : : }
5462 : : }
5463 : :
5464 : 37839015 : if (vector_all_ones_zero_extend_half_operand (x, mode)
5465 : 37839015 : || vector_all_ones_zero_extend_quarter_operand (x, mode))
5466 : 686 : return 3;
5467 : :
5468 : : return 0;
5469 : : }
5470 : :
5471 : : /* Return the opcode of the special instruction to be used to load
5472 : : the constant operands[1] into operands[0]. */
5473 : :
5474 : : const char *
5475 : 452954 : standard_sse_constant_opcode (rtx_insn *insn, rtx *operands)
5476 : : {
5477 : 452954 : machine_mode mode;
5478 : 452954 : rtx x = operands[1];
5479 : :
5480 : 452954 : gcc_assert (TARGET_SSE);
5481 : :
5482 : 452954 : mode = GET_MODE (x);
5483 : :
5484 : 452954 : if (x == const0_rtx || const0_operand (x, mode))
5485 : : {
5486 : 442560 : switch (get_attr_mode (insn))
5487 : : {
5488 : 425618 : case MODE_TI:
5489 : 425618 : if (!EXT_REX_SSE_REG_P (operands[0]))
5490 : : return "%vpxor\t%0, %d0";
5491 : : /* FALLTHRU */
5492 : 5728 : case MODE_XI:
5493 : 5728 : case MODE_OI:
5494 : 5728 : if (EXT_REX_SSE_REG_P (operands[0]))
5495 : : {
5496 : 70 : if (TARGET_AVX512VL)
5497 : : return "vpxord\t%x0, %x0, %x0";
5498 : : else
5499 : 30 : return "vpxord\t%g0, %g0, %g0";
5500 : : }
5501 : : return "vpxor\t%x0, %x0, %x0";
5502 : :
5503 : 2067 : case MODE_V2DF:
5504 : 2067 : if (!EXT_REX_SSE_REG_P (operands[0]))
5505 : : return "%vxorpd\t%0, %d0";
5506 : : /* FALLTHRU */
5507 : 851 : case MODE_V8DF:
5508 : 851 : case MODE_V4DF:
5509 : 851 : if (EXT_REX_SSE_REG_P (operands[0]))
5510 : : {
5511 : 4 : if (TARGET_AVX512DQ)
5512 : : {
5513 : 0 : if (TARGET_AVX512VL)
5514 : : return "vxorpd\t%x0, %x0, %x0";
5515 : : else
5516 : 0 : return "vxorpd\t%g0, %g0, %g0";
5517 : : }
5518 : : else
5519 : : {
5520 : 4 : if (TARGET_AVX512VL)
5521 : : return "vpxorq\t%x0, %x0, %x0";
5522 : : else
5523 : 4 : return "vpxorq\t%g0, %g0, %g0";
5524 : : }
5525 : : }
5526 : : return "vxorpd\t%x0, %x0, %x0";
5527 : :
5528 : 6429 : case MODE_V4SF:
5529 : 6429 : if (!EXT_REX_SSE_REG_P (operands[0]))
5530 : : return "%vxorps\t%0, %d0";
5531 : : /* FALLTHRU */
5532 : 1894 : case MODE_V16SF:
5533 : 1894 : case MODE_V8SF:
5534 : 1894 : if (EXT_REX_SSE_REG_P (operands[0]))
5535 : : {
5536 : 30 : if (TARGET_AVX512DQ)
5537 : : {
5538 : 21 : if (TARGET_AVX512VL)
5539 : : return "vxorps\t%x0, %x0, %x0";
5540 : : else
5541 : 0 : return "vxorps\t%g0, %g0, %g0";
5542 : : }
5543 : : else
5544 : : {
5545 : 9 : if (TARGET_AVX512VL)
5546 : : return "vpxord\t%x0, %x0, %x0";
5547 : : else
5548 : 6 : return "vpxord\t%g0, %g0, %g0";
5549 : : }
5550 : : }
5551 : : return "vxorps\t%x0, %x0, %x0";
5552 : :
5553 : 0 : default:
5554 : 0 : gcc_unreachable ();
5555 : : }
5556 : : }
5557 : 10394 : else if (x == constm1_rtx
5558 : 10383 : || vector_all_ones_operand (x, mode)
5559 : 10461 : || (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
5560 : 45 : && float_vector_all_ones_operand (x, mode)))
5561 : : {
5562 : 10372 : enum attr_mode insn_mode = get_attr_mode (insn);
5563 : :
5564 : 10372 : switch (insn_mode)
5565 : : {
5566 : 2 : case MODE_XI:
5567 : 2 : case MODE_V8DF:
5568 : 2 : case MODE_V16SF:
5569 : 2 : gcc_assert (TARGET_AVX512F);
5570 : : return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
5571 : :
5572 : 954 : case MODE_OI:
5573 : 954 : case MODE_V4DF:
5574 : 954 : case MODE_V8SF:
5575 : 954 : gcc_assert (TARGET_AVX2);
5576 : : /* FALLTHRU */
5577 : 10370 : case MODE_TI:
5578 : 10370 : case MODE_V2DF:
5579 : 10370 : case MODE_V4SF:
5580 : 10370 : gcc_assert (TARGET_SSE2);
5581 : 10370 : if (EXT_REX_SSE_REG_P (operands[0]))
5582 : : {
5583 : 2 : if (TARGET_AVX512VL)
5584 : : return "vpternlogd\t{$0xFF, %0, %0, %0|%0, %0, %0, 0xFF}";
5585 : : else
5586 : 0 : return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
5587 : : }
5588 : 10368 : return (TARGET_AVX
5589 : 10368 : ? "vpcmpeqd\t%0, %0, %0"
5590 : 10368 : : "pcmpeqd\t%0, %0");
5591 : :
5592 : 0 : default:
5593 : 0 : gcc_unreachable ();
5594 : : }
5595 : : }
5596 : 22 : else if (vector_all_ones_zero_extend_half_operand (x, mode))
5597 : : {
5598 : 40 : if (GET_MODE_SIZE (mode) == 64)
5599 : : {
5600 : 5 : gcc_assert (TARGET_AVX512F);
5601 : : return "vpcmpeqd\t%t0, %t0, %t0";
5602 : : }
5603 : 30 : else if (GET_MODE_SIZE (mode) == 32)
5604 : : {
5605 : 15 : gcc_assert (TARGET_AVX);
5606 : : return "vpcmpeqd\t%x0, %x0, %x0";
5607 : : }
5608 : 0 : gcc_unreachable ();
5609 : : }
5610 : 2 : else if (vector_all_ones_zero_extend_quarter_operand (x, mode))
5611 : : {
5612 : 2 : gcc_assert (TARGET_AVX512F);
5613 : : return "vpcmpeqd\t%x0, %x0, %x0";
5614 : : }
5615 : :
5616 : 0 : gcc_unreachable ();
5617 : : }
5618 : :
5619 : : /* Returns true if INSN can be transformed from a memory load
5620 : : to a supported FP constant load. */
5621 : :
5622 : : bool
5623 : 2214022 : ix86_standard_x87sse_constant_load_p (const rtx_insn *insn, rtx dst)
5624 : : {
5625 : 2214022 : rtx src = find_constant_src (insn);
5626 : :
5627 : 2214022 : gcc_assert (REG_P (dst));
5628 : :
5629 : 2214022 : if (src == NULL
5630 : 622625 : || (SSE_REGNO_P (REGNO (dst))
5631 : 489681 : && standard_sse_constant_p (src, GET_MODE (dst)) != 1)
5632 : 166175 : || (!TARGET_AVX512VL
5633 : 166114 : && EXT_REX_SSE_REGNO_P (REGNO (dst))
5634 : 0 : && standard_sse_constant_p (src, GET_MODE (dst)) == 1)
5635 : 2380197 : || (STACK_REGNO_P (REGNO (dst))
5636 : 132944 : && standard_80387_constant_p (src) < 1))
5637 : 2138225 : return false;
5638 : :
5639 : : return true;
5640 : : }
5641 : :
5642 : : /* Predicate for pre-reload splitters with associated instructions,
5643 : : which can match any time before the split1 pass (usually combine),
5644 : : then are unconditionally split in that pass and should not be
5645 : : matched again afterwards. */
5646 : :
5647 : : bool
5648 : 16764937 : ix86_pre_reload_split (void)
5649 : : {
5650 : 16764937 : return (can_create_pseudo_p ()
5651 : 25288784 : && !(cfun->curr_properties & PROP_rtl_split_insns));
5652 : : }
5653 : :
5654 : : /* Return the opcode of the TYPE_SSEMOV instruction. To move from
5655 : : or to xmm16-xmm31/ymm16-ymm31 registers, we either require
5656 : : TARGET_AVX512VL or it is a register to register move which can
5657 : : be done with zmm register move. */
5658 : :
5659 : : static const char *
5660 : 3906990 : ix86_get_ssemov (rtx *operands, unsigned size,
5661 : : enum attr_mode insn_mode, machine_mode mode)
5662 : : {
5663 : 3906990 : char buf[128];
5664 : 3906990 : bool misaligned_p = (misaligned_operand (operands[0], mode)
5665 : 3906990 : || misaligned_operand (operands[1], mode));
5666 : 3906990 : bool evex_reg_p = (size == 64
5667 : 3824358 : || EXT_REX_SSE_REG_P (operands[0])
5668 : 7730698 : || EXT_REX_SSE_REG_P (operands[1]));
5669 : :
5670 : 3906990 : bool egpr_p = (TARGET_APX_EGPR
5671 : 3906990 : && (x86_extended_rex2reg_mentioned_p (operands[0])
5672 : 179 : || x86_extended_rex2reg_mentioned_p (operands[1])));
5673 : 192 : bool egpr_vl = egpr_p && TARGET_AVX512VL;
5674 : :
5675 : 3906990 : machine_mode scalar_mode;
5676 : :
5677 : 3906990 : const char *opcode = NULL;
5678 : 3906990 : enum
5679 : : {
5680 : : opcode_int,
5681 : : opcode_float,
5682 : : opcode_double
5683 : 3906990 : } type = opcode_int;
5684 : :
5685 : 3906990 : switch (insn_mode)
5686 : : {
5687 : : case MODE_V16SF:
5688 : : case MODE_V8SF:
5689 : : case MODE_V4SF:
5690 : : scalar_mode = E_SFmode;
5691 : : type = opcode_float;
5692 : : break;
5693 : 207550 : case MODE_V8DF:
5694 : 207550 : case MODE_V4DF:
5695 : 207550 : case MODE_V2DF:
5696 : 207550 : scalar_mode = E_DFmode;
5697 : 207550 : type = opcode_double;
5698 : 207550 : break;
5699 : 1381548 : case MODE_XI:
5700 : 1381548 : case MODE_OI:
5701 : 1381548 : case MODE_TI:
5702 : 1381548 : scalar_mode = GET_MODE_INNER (mode);
5703 : : break;
5704 : 0 : default:
5705 : 0 : gcc_unreachable ();
5706 : : }
5707 : :
5708 : : /* NB: To move xmm16-xmm31/ymm16-ymm31 registers without AVX512VL,
5709 : : we can only use zmm register move without memory operand. */
5710 : 3906990 : if (evex_reg_p
5711 : 84158 : && !TARGET_AVX512VL
5712 : 3955824 : && GET_MODE_SIZE (mode) < 64)
5713 : : {
5714 : : /* NB: Even though ix86_hard_regno_mode_ok doesn't allow
5715 : : xmm16-xmm31 nor ymm16-ymm31 in 128/256 bit modes when
5716 : : AVX512VL is disabled, LRA can still generate reg to
5717 : : reg moves with xmm16-xmm31 and ymm16-ymm31 in 128/256 bit
5718 : : modes. */
5719 : 0 : if (memory_operand (operands[0], mode)
5720 : 0 : || memory_operand (operands[1], mode))
5721 : 0 : gcc_unreachable ();
5722 : 0 : size = 64;
5723 : 0 : switch (type)
5724 : : {
5725 : 0 : case opcode_int:
5726 : 0 : if (scalar_mode == E_HFmode || scalar_mode == E_BFmode)
5727 : 0 : opcode = (misaligned_p
5728 : 0 : ? (TARGET_AVX512BW ? "vmovdqu16" : "vmovdqu64")
5729 : : : "vmovdqa64");
5730 : : else
5731 : 0 : opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32";
5732 : : break;
5733 : 0 : case opcode_float:
5734 : 0 : opcode = misaligned_p ? "vmovups" : "vmovaps";
5735 : : break;
5736 : 0 : case opcode_double:
5737 : 0 : opcode = misaligned_p ? "vmovupd" : "vmovapd";
5738 : : break;
5739 : : }
5740 : : }
5741 : 3906990 : else if (SCALAR_FLOAT_MODE_P (scalar_mode))
5742 : : {
5743 : 2704255 : switch (scalar_mode)
5744 : : {
5745 : 36029 : case E_HFmode:
5746 : 36029 : case E_BFmode:
5747 : 36029 : if (evex_reg_p || egpr_vl)
5748 : 11225 : opcode = (misaligned_p
5749 : 164 : ? (TARGET_AVX512BW
5750 : : ? "vmovdqu16"
5751 : : : "vmovdqu64")
5752 : : : "vmovdqa64");
5753 : 24804 : else if (egpr_p)
5754 : 657939 : opcode = (misaligned_p
5755 : 0 : ? (TARGET_AVX512BW
5756 : 0 : ? "vmovdqu16"
5757 : : : "%vmovups")
5758 : : : "%vmovaps");
5759 : : else
5760 : 306925 : opcode = (misaligned_p
5761 : 24804 : ? (TARGET_AVX512BW && evex_reg_p
5762 : : ? "vmovdqu16"
5763 : : : "%vmovdqu")
5764 : : : "%vmovdqa");
5765 : : break;
5766 : 2317892 : case E_SFmode:
5767 : 2317892 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5768 : : break;
5769 : 207550 : case E_DFmode:
5770 : 207550 : opcode = misaligned_p ? "%vmovupd" : "%vmovapd";
5771 : : break;
5772 : 142784 : case E_TFmode:
5773 : 142784 : if (evex_reg_p || egpr_vl)
5774 : 14 : opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
5775 : 142770 : else if (egpr_p)
5776 : 0 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5777 : : else
5778 : 142770 : opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
5779 : : break;
5780 : 0 : default:
5781 : 0 : gcc_unreachable ();
5782 : : }
5783 : : }
5784 : 1202735 : else if (SCALAR_INT_MODE_P (scalar_mode))
5785 : : {
5786 : 1202735 : switch (scalar_mode)
5787 : : {
5788 : 51015 : case E_QImode:
5789 : 51015 : if (evex_reg_p || egpr_vl)
5790 : 3915307 : opcode = (misaligned_p
5791 : 8317 : ? (TARGET_AVX512BW
5792 : 4752 : ? "vmovdqu8"
5793 : : : "vmovdqu64")
5794 : : : "vmovdqa64");
5795 : 42698 : else if (egpr_p)
5796 : 30 : opcode = (misaligned_p
5797 : 0 : ? (TARGET_AVX512BW
5798 : : ? "vmovdqu8"
5799 : : : "%vmovups")
5800 : : : "%vmovaps");
5801 : : else
5802 : 42668 : opcode = (misaligned_p
5803 : : ? (TARGET_AVX512BW && evex_reg_p
5804 : : ? "vmovdqu8"
5805 : : : "%vmovdqu")
5806 : : : "%vmovdqa");
5807 : : break;
5808 : 39841 : case E_HImode:
5809 : 39841 : if (evex_reg_p || egpr_vl)
5810 : 3389 : opcode = (misaligned_p
5811 : 175 : ? (TARGET_AVX512BW
5812 : : ? "vmovdqu16"
5813 : : : "vmovdqu64")
5814 : : : "vmovdqa64");
5815 : 36452 : else if (egpr_p)
5816 : 657939 : opcode = (misaligned_p
5817 : 27 : ? (TARGET_AVX512BW
5818 : 0 : ? "vmovdqu16"
5819 : : : "%vmovups")
5820 : : : "%vmovaps");
5821 : : else
5822 : 282121 : opcode = (misaligned_p
5823 : 36425 : ? (TARGET_AVX512BW && evex_reg_p
5824 : : ? "vmovdqu16"
5825 : : : "%vmovdqu")
5826 : : : "%vmovdqa");
5827 : : break;
5828 : 168811 : case E_SImode:
5829 : 168811 : if (evex_reg_p || egpr_vl)
5830 : 7838 : opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32";
5831 : 160973 : else if (egpr_p)
5832 : 14 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5833 : : else
5834 : 160959 : opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
5835 : : break;
5836 : 932027 : case E_DImode:
5837 : 932027 : case E_TImode:
5838 : 932027 : case E_OImode:
5839 : 932027 : if (evex_reg_p || egpr_vl)
5840 : 18211 : opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
5841 : 913816 : else if (egpr_p)
5842 : 26 : opcode = misaligned_p ? "%vmovups" : "%vmovaps";
5843 : : else
5844 : 913790 : opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
5845 : : break;
5846 : 11041 : case E_XImode:
5847 : 46340 : opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
5848 : : break;
5849 : 0 : default:
5850 : 0 : gcc_unreachable ();
5851 : : }
5852 : : }
5853 : : else
5854 : 0 : gcc_unreachable ();
5855 : :
5856 : 3906990 : switch (size)
5857 : : {
5858 : 82632 : case 64:
5859 : 82632 : snprintf (buf, sizeof (buf), "%s\t{%%g1, %%g0|%%g0, %%g1}",
5860 : : opcode);
5861 : 82632 : break;
5862 : 88783 : case 32:
5863 : 88783 : snprintf (buf, sizeof (buf), "%s\t{%%t1, %%t0|%%t0, %%t1}",
5864 : : opcode);
5865 : 88783 : break;
5866 : 3735575 : case 16:
5867 : 3735575 : snprintf (buf, sizeof (buf), "%s\t{%%x1, %%x0|%%x0, %%x1}",
5868 : : opcode);
5869 : 3735575 : break;
5870 : 0 : default:
5871 : 0 : gcc_unreachable ();
5872 : : }
5873 : 3906990 : output_asm_insn (buf, operands);
5874 : 3906990 : return "";
5875 : : }
5876 : :
5877 : : /* Return the template of the TYPE_SSEMOV instruction to move
5878 : : operands[1] into operands[0]. */
5879 : :
5880 : : const char *
5881 : 6304209 : ix86_output_ssemov (rtx_insn *insn, rtx *operands)
5882 : : {
5883 : 6304209 : machine_mode mode = GET_MODE (operands[0]);
5884 : 6304209 : if (get_attr_type (insn) != TYPE_SSEMOV
5885 : 6304209 : || mode != GET_MODE (operands[1]))
5886 : 0 : gcc_unreachable ();
5887 : :
5888 : 6304209 : enum attr_mode insn_mode = get_attr_mode (insn);
5889 : :
5890 : 6304209 : switch (insn_mode)
5891 : : {
5892 : 82632 : case MODE_XI:
5893 : 82632 : case MODE_V8DF:
5894 : 82632 : case MODE_V16SF:
5895 : 82632 : return ix86_get_ssemov (operands, 64, insn_mode, mode);
5896 : :
5897 : 88783 : case MODE_OI:
5898 : 88783 : case MODE_V4DF:
5899 : 88783 : case MODE_V8SF:
5900 : 88783 : return ix86_get_ssemov (operands, 32, insn_mode, mode);
5901 : :
5902 : 3735575 : case MODE_TI:
5903 : 3735575 : case MODE_V2DF:
5904 : 3735575 : case MODE_V4SF:
5905 : 3735575 : return ix86_get_ssemov (operands, 16, insn_mode, mode);
5906 : :
5907 : 658724 : case MODE_DI:
5908 : : /* Handle broken assemblers that require movd instead of movq. */
5909 : 658724 : if (GENERAL_REG_P (operands[0]))
5910 : : {
5911 : : if (HAVE_AS_IX86_INTERUNIT_MOVQ)
5912 : : return "%vmovq\t{%1, %q0|%q0, %1}";
5913 : : else
5914 : : return "%vmovd\t{%1, %q0|%q0, %1}";
5915 : : }
5916 : 585093 : else if (GENERAL_REG_P (operands[1]))
5917 : : {
5918 : : if (HAVE_AS_IX86_INTERUNIT_MOVQ)
5919 : : return "%vmovq\t{%q1, %0|%0, %q1}";
5920 : : else
5921 : : return "%vmovd\t{%q1, %0|%0, %q1}";
5922 : : }
5923 : : else
5924 : 424127 : return "%vmovq\t{%1, %0|%0, %1}";
5925 : :
5926 : 198393 : case MODE_SI:
5927 : 198393 : if (GENERAL_REG_P (operands[0]))
5928 : : return "%vmovd\t{%1, %k0|%k0, %1}";
5929 : 143119 : else if (GENERAL_REG_P (operands[1]))
5930 : : return "%vmovd\t{%k1, %0|%0, %k1}";
5931 : : else
5932 : 61433 : return "%vmovd\t{%1, %0|%0, %1}";
5933 : :
5934 : 53393 : case MODE_HI:
5935 : 53393 : if (GENERAL_REG_P (operands[0]))
5936 : : return "vmovw\t{%1, %k0|%k0, %1}";
5937 : 53359 : else if (GENERAL_REG_P (operands[1]))
5938 : : return "vmovw\t{%k1, %0|%0, %k1}";
5939 : : else
5940 : 53272 : return "vmovw\t{%1, %0|%0, %1}";
5941 : :
5942 : 786275 : case MODE_DF:
5943 : 786275 : if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
5944 : : return "vmovsd\t{%d1, %0|%0, %d1}";
5945 : : else
5946 : 785223 : return "%vmovsd\t{%1, %0|%0, %1}";
5947 : :
5948 : 696677 : case MODE_SF:
5949 : 696677 : if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
5950 : : return "vmovss\t{%d1, %0|%0, %d1}";
5951 : : else
5952 : 695891 : return "%vmovss\t{%1, %0|%0, %1}";
5953 : :
5954 : 96 : case MODE_HF:
5955 : 96 : case MODE_BF:
5956 : 96 : if (REG_P (operands[0]) && REG_P (operands[1]))
5957 : : return "vmovsh\t{%d1, %0|%0, %d1}";
5958 : : else
5959 : 0 : return "vmovsh\t{%1, %0|%0, %1}";
5960 : :
5961 : 36 : case MODE_V1DF:
5962 : 36 : gcc_assert (!TARGET_AVX);
5963 : : return "movlpd\t{%1, %0|%0, %1}";
5964 : :
5965 : 3625 : case MODE_V2SF:
5966 : 3625 : if (TARGET_AVX && REG_P (operands[0]))
5967 : : return "vmovlps\t{%1, %d0|%d0, %1}";
5968 : : else
5969 : 3545 : return "%vmovlps\t{%1, %0|%0, %1}";
5970 : :
5971 : 0 : default:
5972 : 0 : gcc_unreachable ();
5973 : : }
5974 : : }
5975 : :
5976 : : /* Returns true if OP contains a symbol reference */
5977 : :
5978 : : bool
5979 : 557248059 : symbolic_reference_mentioned_p (rtx op)
5980 : : {
5981 : 557248059 : const char *fmt;
5982 : 557248059 : int i;
5983 : :
5984 : 557248059 : if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
5985 : : return true;
5986 : :
5987 : 421374007 : fmt = GET_RTX_FORMAT (GET_CODE (op));
5988 : 715529759 : for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
5989 : : {
5990 : 570723053 : if (fmt[i] == 'E')
5991 : : {
5992 : 1970579 : int j;
5993 : :
5994 : 3928606 : for (j = XVECLEN (op, i) - 1; j >= 0; j--)
5995 : 3244740 : if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
5996 : : return true;
5997 : : }
5998 : :
5999 : 568752474 : else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
6000 : : return true;
6001 : : }
6002 : :
6003 : : return false;
6004 : : }
6005 : :
6006 : : /* Return true if it is appropriate to emit `ret' instructions in the
6007 : : body of a function. Do this only if the epilogue is simple, needing a
6008 : : couple of insns. Prior to reloading, we can't tell how many registers
6009 : : must be saved, so return false then. Return false if there is no frame
6010 : : marker to de-allocate. */
6011 : :
6012 : : bool
6013 : 0 : ix86_can_use_return_insn_p (void)
6014 : : {
6015 : 0 : if (ix86_function_ms_hook_prologue (current_function_decl))
6016 : : return false;
6017 : :
6018 : 0 : if (ix86_function_naked (current_function_decl))
6019 : : return false;
6020 : :
6021 : : /* Don't use `ret' instruction in interrupt handler. */
6022 : 0 : if (! reload_completed
6023 : 0 : || frame_pointer_needed
6024 : 0 : || cfun->machine->func_type != TYPE_NORMAL)
6025 : : return 0;
6026 : :
6027 : : /* Don't allow more than 32k pop, since that's all we can do
6028 : : with one instruction. */
6029 : 0 : if (crtl->args.pops_args && crtl->args.size >= 32768)
6030 : : return 0;
6031 : :
6032 : 0 : struct ix86_frame &frame = cfun->machine->frame;
6033 : 0 : return (frame.stack_pointer_offset == UNITS_PER_WORD
6034 : 0 : && (frame.nregs + frame.nsseregs) == 0);
6035 : : }
6036 : :
6037 : : /* Return stack frame size. get_frame_size () returns used stack slots
6038 : : during compilation, which may be optimized out later. If stack frame
6039 : : is needed, stack_frame_required should be true. */
6040 : :
6041 : : static HOST_WIDE_INT
6042 : 8112521 : ix86_get_frame_size (void)
6043 : : {
6044 : 8112521 : if (cfun->machine->stack_frame_required)
6045 : 8045732 : return get_frame_size ();
6046 : : else
6047 : : return 0;
6048 : : }
6049 : :
6050 : : /* Value should be nonzero if functions must have frame pointers.
6051 : : Zero means the frame pointer need not be set up (and parms may
6052 : : be accessed via the stack pointer) in functions that seem suitable. */
6053 : :
6054 : : static bool
6055 : 1205460 : ix86_frame_pointer_required (void)
6056 : : {
6057 : : /* If we accessed previous frames, then the generated code expects
6058 : : to be able to access the saved ebp value in our frame. */
6059 : 1205460 : if (cfun->machine->accesses_prev_frame)
6060 : : return true;
6061 : :
6062 : : /* Several x86 os'es need a frame pointer for other reasons,
6063 : : usually pertaining to setjmp. */
6064 : 1205427 : if (SUBTARGET_FRAME_POINTER_REQUIRED)
6065 : : return true;
6066 : :
6067 : : /* For older 32-bit runtimes setjmp requires valid frame-pointer. */
6068 : 1205427 : if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
6069 : : return true;
6070 : :
6071 : : /* Win64 SEH, very large frames need a frame-pointer as maximum stack
6072 : : allocation is 4GB. */
6073 : 1205427 : if (TARGET_64BIT_MS_ABI && ix86_get_frame_size () > SEH_MAX_FRAME_SIZE)
6074 : : return true;
6075 : :
6076 : : /* SSE saves require frame-pointer when stack is misaligned. */
6077 : 1205427 : if (TARGET_64BIT_MS_ABI && ix86_incoming_stack_boundary < 128)
6078 : : return true;
6079 : :
6080 : : /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
6081 : : turns off the frame pointer by default. Turn it back on now if
6082 : : we've not got a leaf function. */
6083 : 1205426 : if (TARGET_OMIT_LEAF_FRAME_POINTER
6084 : 1205426 : && (!crtl->is_leaf
6085 : 0 : || ix86_current_function_calls_tls_descriptor))
6086 : 0 : return true;
6087 : :
6088 : : /* Several versions of mcount for the x86 assumes that there is a
6089 : : frame, so we cannot allow profiling without a frame pointer. */
6090 : 1205426 : if (crtl->profile && !flag_fentry)
6091 : : return true;
6092 : :
6093 : : return false;
6094 : : }
6095 : :
6096 : : /* Record that the current function accesses previous call frames. */
6097 : :
6098 : : void
6099 : 966 : ix86_setup_frame_addresses (void)
6100 : : {
6101 : 966 : cfun->machine->accesses_prev_frame = 1;
6102 : 966 : }
6103 : :
6104 : : #if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)
6105 : : # define USE_HIDDEN_LINKONCE 1
6106 : : #else
6107 : : # define USE_HIDDEN_LINKONCE 0
6108 : : #endif
6109 : :
6110 : : /* Label count for call and return thunks. It is used to make unique
6111 : : labels in call and return thunks. */
6112 : : static int indirectlabelno;
6113 : :
6114 : : /* True if call thunk function is needed. */
6115 : : static bool indirect_thunk_needed = false;
6116 : :
6117 : : /* Bit masks of integer registers, which contain branch target, used
6118 : : by call thunk functions. */
6119 : : static HARD_REG_SET indirect_thunks_used;
6120 : :
6121 : : /* True if return thunk function is needed. */
6122 : : static bool indirect_return_needed = false;
6123 : :
6124 : : /* True if return thunk function via CX is needed. */
6125 : : static bool indirect_return_via_cx;
6126 : :
6127 : : #ifndef INDIRECT_LABEL
6128 : : # define INDIRECT_LABEL "LIND"
6129 : : #endif
6130 : :
6131 : : /* Indicate what prefix is needed for an indirect branch. */
6132 : : enum indirect_thunk_prefix
6133 : : {
6134 : : indirect_thunk_prefix_none,
6135 : : indirect_thunk_prefix_nt
6136 : : };
6137 : :
6138 : : /* Return the prefix needed for an indirect branch INSN. */
6139 : :
6140 : : enum indirect_thunk_prefix
6141 : 67 : indirect_thunk_need_prefix (rtx_insn *insn)
6142 : : {
6143 : 67 : enum indirect_thunk_prefix need_prefix;
6144 : 67 : if ((cfun->machine->indirect_branch_type
6145 : 67 : == indirect_branch_thunk_extern)
6146 : 67 : && ix86_notrack_prefixed_insn_p (insn))
6147 : : {
6148 : : /* NOTRACK prefix is only used with external thunk so that it
6149 : : can be properly updated to support CET at run-time. */
6150 : : need_prefix = indirect_thunk_prefix_nt;
6151 : : }
6152 : : else
6153 : : need_prefix = indirect_thunk_prefix_none;
6154 : 67 : return need_prefix;
6155 : : }
6156 : :
6157 : : /* Fills in the label name that should be used for the indirect thunk. */
6158 : :
6159 : : static void
6160 : 73 : indirect_thunk_name (char name[32], unsigned int regno,
6161 : : enum indirect_thunk_prefix need_prefix,
6162 : : bool ret_p)
6163 : : {
6164 : 73 : if (regno != INVALID_REGNUM && regno != CX_REG && ret_p)
6165 : 0 : gcc_unreachable ();
6166 : :
6167 : 73 : if (USE_HIDDEN_LINKONCE)
6168 : : {
6169 : 73 : const char *prefix;
6170 : :
6171 : 73 : if (need_prefix == indirect_thunk_prefix_nt
6172 : 73 : && regno != INVALID_REGNUM)
6173 : : {
6174 : : /* NOTRACK prefix is only used with external thunk via
6175 : : register so that NOTRACK prefix can be added to indirect
6176 : : branch via register to support CET at run-time. */
6177 : : prefix = "_nt";
6178 : : }
6179 : : else
6180 : 71 : prefix = "";
6181 : :
6182 : 73 : const char *ret = ret_p ? "return" : "indirect";
6183 : :
6184 : 73 : if (regno != INVALID_REGNUM)
6185 : : {
6186 : 55 : const char *reg_prefix;
6187 : 55 : if (LEGACY_INT_REGNO_P (regno))
6188 : 53 : reg_prefix = TARGET_64BIT ? "r" : "e";
6189 : : else
6190 : : reg_prefix = "";
6191 : 55 : sprintf (name, "__x86_%s_thunk%s_%s%s",
6192 : : ret, prefix, reg_prefix, reg_names[regno]);
6193 : : }
6194 : : else
6195 : 18 : sprintf (name, "__x86_%s_thunk%s", ret, prefix);
6196 : : }
6197 : : else
6198 : : {
6199 : : if (regno != INVALID_REGNUM)
6200 : : ASM_GENERATE_INTERNAL_LABEL (name, "LITR", regno);
6201 : : else
6202 : : {
6203 : : if (ret_p)
6204 : : ASM_GENERATE_INTERNAL_LABEL (name, "LRT", 0);
6205 : : else
6206 : 73 : ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0);
6207 : : }
6208 : : }
6209 : 73 : }
6210 : :
6211 : : /* Output a call and return thunk for indirect branch. If REGNO != -1,
6212 : : the function address is in REGNO and the call and return thunk looks like:
6213 : :
6214 : : call L2
6215 : : L1:
6216 : : pause
6217 : : lfence
6218 : : jmp L1
6219 : : L2:
6220 : : mov %REG, (%sp)
6221 : : ret
6222 : :
6223 : : Otherwise, the function address is on the top of stack and the
6224 : : call and return thunk looks like:
6225 : :
6226 : : call L2
6227 : : L1:
6228 : : pause
6229 : : lfence
6230 : : jmp L1
6231 : : L2:
6232 : : lea WORD_SIZE(%sp), %sp
6233 : : ret
6234 : : */
6235 : :
6236 : : static void
6237 : 38 : output_indirect_thunk (unsigned int regno)
6238 : : {
6239 : 38 : char indirectlabel1[32];
6240 : 38 : char indirectlabel2[32];
6241 : :
6242 : 38 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel1, INDIRECT_LABEL,
6243 : : indirectlabelno++);
6244 : 38 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel2, INDIRECT_LABEL,
6245 : : indirectlabelno++);
6246 : :
6247 : : /* Call */
6248 : 38 : fputs ("\tcall\t", asm_out_file);
6249 : 38 : assemble_name_raw (asm_out_file, indirectlabel2);
6250 : 38 : fputc ('\n', asm_out_file);
6251 : :
6252 : 38 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
6253 : :
6254 : : /* AMD and Intel CPUs prefer each a different instruction as loop filler.
6255 : : Usage of both pause + lfence is compromise solution. */
6256 : 38 : fprintf (asm_out_file, "\tpause\n\tlfence\n");
6257 : :
6258 : : /* Jump. */
6259 : 38 : fputs ("\tjmp\t", asm_out_file);
6260 : 38 : assemble_name_raw (asm_out_file, indirectlabel1);
6261 : 38 : fputc ('\n', asm_out_file);
6262 : :
6263 : 38 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
6264 : :
6265 : : /* The above call insn pushed a word to stack. Adjust CFI info. */
6266 : 38 : if (flag_asynchronous_unwind_tables && dwarf2out_do_frame ())
6267 : : {
6268 : 38 : if (! dwarf2out_do_cfi_asm ())
6269 : : {
6270 : 0 : dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> ();
6271 : 0 : xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
6272 : 0 : xcfi->dw_cfi_oprnd1.dw_cfi_addr = ggc_strdup (indirectlabel2);
6273 : 0 : vec_safe_push (cfun->fde->dw_fde_cfi, xcfi);
6274 : : }
6275 : 38 : dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> ();
6276 : 38 : xcfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
6277 : 38 : xcfi->dw_cfi_oprnd1.dw_cfi_offset = 2 * UNITS_PER_WORD;
6278 : 38 : vec_safe_push (cfun->fde->dw_fde_cfi, xcfi);
6279 : 38 : dwarf2out_emit_cfi (xcfi);
6280 : : }
6281 : :
6282 : 38 : if (regno != INVALID_REGNUM)
6283 : : {
6284 : : /* MOV. */
6285 : 27 : rtx xops[2];
6286 : 27 : xops[0] = gen_rtx_MEM (word_mode, stack_pointer_rtx);
6287 : 27 : xops[1] = gen_rtx_REG (word_mode, regno);
6288 : 27 : output_asm_insn ("mov\t{%1, %0|%0, %1}", xops);
6289 : : }
6290 : : else
6291 : : {
6292 : : /* LEA. */
6293 : 11 : rtx xops[2];
6294 : 11 : xops[0] = stack_pointer_rtx;
6295 : 11 : xops[1] = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
6296 : 11 : output_asm_insn ("lea\t{%E1, %0|%0, %E1}", xops);
6297 : : }
6298 : :
6299 : 38 : fputs ("\tret\n", asm_out_file);
6300 : 38 : if ((ix86_harden_sls & harden_sls_return))
6301 : 1 : fputs ("\tint3\n", asm_out_file);
6302 : 38 : }
6303 : :
6304 : : /* Output a funtion with a call and return thunk for indirect branch.
6305 : : If REGNO != INVALID_REGNUM, the function address is in REGNO.
6306 : : Otherwise, the function address is on the top of stack. Thunk is
6307 : : used for function return if RET_P is true. */
6308 : :
6309 : : static void
6310 : 22 : output_indirect_thunk_function (enum indirect_thunk_prefix need_prefix,
6311 : : unsigned int regno, bool ret_p)
6312 : : {
6313 : 22 : char name[32];
6314 : 22 : tree decl;
6315 : :
6316 : : /* Create __x86_indirect_thunk. */
6317 : 22 : indirect_thunk_name (name, regno, need_prefix, ret_p);
6318 : 22 : decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
6319 : : get_identifier (name),
6320 : : build_function_type_list (void_type_node, NULL_TREE));
6321 : 22 : DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
6322 : : NULL_TREE, void_type_node);
6323 : 22 : TREE_PUBLIC (decl) = 1;
6324 : 22 : TREE_STATIC (decl) = 1;
6325 : 22 : DECL_IGNORED_P (decl) = 1;
6326 : :
6327 : : #if TARGET_MACHO
6328 : : if (TARGET_MACHO)
6329 : : {
6330 : : switch_to_section (darwin_sections[picbase_thunk_section]);
6331 : : fputs ("\t.weak_definition\t", asm_out_file);
6332 : : assemble_name (asm_out_file, name);
6333 : : fputs ("\n\t.private_extern\t", asm_out_file);
6334 : : assemble_name (asm_out_file, name);
6335 : : putc ('\n', asm_out_file);
6336 : : ASM_OUTPUT_LABEL (asm_out_file, name);
6337 : : DECL_WEAK (decl) = 1;
6338 : : }
6339 : : else
6340 : : #endif
6341 : 22 : if (USE_HIDDEN_LINKONCE)
6342 : : {
6343 : 22 : cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
6344 : :
6345 : 22 : targetm.asm_out.unique_section (decl, 0);
6346 : 22 : switch_to_section (get_named_section (decl, NULL, 0));
6347 : :
6348 : 22 : targetm.asm_out.globalize_label (asm_out_file, name);
6349 : 22 : fputs ("\t.hidden\t", asm_out_file);
6350 : 22 : assemble_name (asm_out_file, name);
6351 : 22 : putc ('\n', asm_out_file);
6352 : 22 : ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
6353 : : }
6354 : : else
6355 : : {
6356 : : switch_to_section (text_section);
6357 : 22 : ASM_OUTPUT_LABEL (asm_out_file, name);
6358 : : }
6359 : :
6360 : 22 : DECL_INITIAL (decl) = make_node (BLOCK);
6361 : 22 : current_function_decl = decl;
6362 : 22 : allocate_struct_function (decl, false);
6363 : 22 : init_function_start (decl);
6364 : : /* We're about to hide the function body from callees of final_* by
6365 : : emitting it directly; tell them we're a thunk, if they care. */
6366 : 22 : cfun->is_thunk = true;
6367 : 22 : first_function_block_is_cold = false;
6368 : : /* Make sure unwind info is emitted for the thunk if needed. */
6369 : 22 : final_start_function (emit_barrier (), asm_out_file, 1);
6370 : :
6371 : 22 : output_indirect_thunk (regno);
6372 : :
6373 : 22 : final_end_function ();
6374 : 22 : init_insn_lengths ();
6375 : 22 : free_after_compilation (cfun);
6376 : 22 : set_cfun (NULL);
6377 : 22 : current_function_decl = NULL;
6378 : 22 : }
6379 : :
6380 : : static int pic_labels_used;
6381 : :
6382 : : /* Fills in the label name that should be used for a pc thunk for
6383 : : the given register. */
6384 : :
6385 : : static void
6386 : 36735 : get_pc_thunk_name (char name[32], unsigned int regno)
6387 : : {
6388 : 36735 : gcc_assert (!TARGET_64BIT);
6389 : :
6390 : 36735 : if (USE_HIDDEN_LINKONCE)
6391 : 36735 : sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]);
6392 : : else
6393 : 36735 : ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
6394 : 36735 : }
6395 : :
6396 : :
6397 : : /* This function generates code for -fpic that loads %ebx with
6398 : : the return address of the caller and then returns. */
6399 : :
6400 : : static void
6401 : 230024 : ix86_code_end (void)
6402 : : {
6403 : 230024 : rtx xops[2];
6404 : 230024 : unsigned int regno;
6405 : :
6406 : 230024 : if (indirect_return_needed)
6407 : 6 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6408 : : INVALID_REGNUM, true);
6409 : 230024 : if (indirect_return_via_cx)
6410 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6411 : : CX_REG, true);
6412 : 230024 : if (indirect_thunk_needed)
6413 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6414 : : INVALID_REGNUM, false);
6415 : :
6416 : 2070216 : for (regno = FIRST_REX_INT_REG; regno <= LAST_REX_INT_REG; regno++)
6417 : : {
6418 : 1840192 : if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
6419 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6420 : : regno, false);
6421 : : }
6422 : :
6423 : 3910408 : for (regno = FIRST_REX2_INT_REG; regno <= LAST_REX2_INT_REG; regno++)
6424 : : {
6425 : 3680384 : if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
6426 : 0 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6427 : : regno, false);
6428 : : }
6429 : :
6430 : 2070216 : for (regno = FIRST_INT_REG; regno <= LAST_INT_REG; regno++)
6431 : : {
6432 : 1840192 : char name[32];
6433 : 1840192 : tree decl;
6434 : :
6435 : 1840192 : if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
6436 : 16 : output_indirect_thunk_function (indirect_thunk_prefix_none,
6437 : : regno, false);
6438 : :
6439 : 1840192 : if (!(pic_labels_used & (1 << regno)))
6440 : 1836634 : continue;
6441 : :
6442 : 3558 : get_pc_thunk_name (name, regno);
6443 : :
6444 : 3558 : decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
6445 : : get_identifier (name),
6446 : : build_function_type_list (void_type_node, NULL_TREE));
6447 : 3558 : DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
6448 : : NULL_TREE, void_type_node);
6449 : 3558 : TREE_PUBLIC (decl) = 1;
6450 : 3558 : TREE_STATIC (decl) = 1;
6451 : 3558 : DECL_IGNORED_P (decl) = 1;
6452 : :
6453 : : #if TARGET_MACHO
6454 : : if (TARGET_MACHO)
6455 : : {
6456 : : switch_to_section (darwin_sections[picbase_thunk_section]);
6457 : : fputs ("\t.weak_definition\t", asm_out_file);
6458 : : assemble_name (asm_out_file, name);
6459 : : fputs ("\n\t.private_extern\t", asm_out_file);
6460 : : assemble_name (asm_out_file, name);
6461 : : putc ('\n', asm_out_file);
6462 : : ASM_OUTPUT_LABEL (asm_out_file, name);
6463 : : DECL_WEAK (decl) = 1;
6464 : : }
6465 : : else
6466 : : #endif
6467 : 3558 : if (USE_HIDDEN_LINKONCE)
6468 : : {
6469 : 3558 : cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
6470 : :
6471 : 3558 : targetm.asm_out.unique_section (decl, 0);
6472 : 3558 : switch_to_section (get_named_section (decl, NULL, 0));
6473 : :
6474 : 3558 : targetm.asm_out.globalize_label (asm_out_file, name);
6475 : 3558 : fputs ("\t.hidden\t", asm_out_file);
6476 : 3558 : assemble_name (asm_out_file, name);
6477 : 3558 : putc ('\n', asm_out_file);
6478 : 3558 : ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
6479 : : }
6480 : : else
6481 : : {
6482 : : switch_to_section (text_section);
6483 : 3558 : ASM_OUTPUT_LABEL (asm_out_file, name);
6484 : : }
6485 : :
6486 : 3558 : DECL_INITIAL (decl) = make_node (BLOCK);
6487 : 3558 : current_function_decl = decl;
6488 : 3558 : allocate_struct_function (decl, false);
6489 : 3558 : init_function_start (decl);
6490 : : /* We're about to hide the function body from callees of final_* by
6491 : : emitting it directly; tell them we're a thunk, if they care. */
6492 : 3558 : cfun->is_thunk = true;
6493 : 3558 : first_function_block_is_cold = false;
6494 : : /* Make sure unwind info is emitted for the thunk if needed. */
6495 : 3558 : final_start_function (emit_barrier (), asm_out_file, 1);
6496 : :
6497 : : /* Pad stack IP move with 4 instructions (two NOPs count
6498 : : as one instruction). */
6499 : 3558 : if (TARGET_PAD_SHORT_FUNCTION)
6500 : : {
6501 : : int i = 8;
6502 : :
6503 : 0 : while (i--)
6504 : 0 : fputs ("\tnop\n", asm_out_file);
6505 : : }
6506 : :
6507 : 7116 : xops[0] = gen_rtx_REG (Pmode, regno);
6508 : 7116 : xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
6509 : 3558 : output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
6510 : 3558 : fputs ("\tret\n", asm_out_file);
6511 : 3558 : final_end_function ();
6512 : 3558 : init_insn_lengths ();
6513 : 3558 : free_after_compilation (cfun);
6514 : 3558 : set_cfun (NULL);
6515 : 3558 : current_function_decl = NULL;
6516 : : }
6517 : :
6518 : 230024 : if (flag_split_stack)
6519 : 4712 : file_end_indicate_split_stack ();
6520 : 230024 : }
6521 : :
6522 : : /* Emit code for the SET_GOT patterns. */
6523 : :
6524 : : const char *
6525 : 33177 : output_set_got (rtx dest, rtx label)
6526 : : {
6527 : 33177 : rtx xops[3];
6528 : :
6529 : 33177 : xops[0] = dest;
6530 : :
6531 : 33177 : if (TARGET_VXWORKS_RTP && flag_pic)
6532 : : {
6533 : : /* Load (*VXWORKS_GOTT_BASE) into the PIC register. */
6534 : : xops[2] = gen_rtx_MEM (Pmode,
6535 : : gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
6536 : : output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
6537 : :
6538 : : /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
6539 : : Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
6540 : : an unadorned address. */
6541 : : xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
6542 : : SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
6543 : : output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
6544 : : return "";
6545 : : }
6546 : :
6547 : 66354 : xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
6548 : :
6549 : 33177 : if (flag_pic)
6550 : : {
6551 : 33177 : char name[32];
6552 : 33177 : get_pc_thunk_name (name, REGNO (dest));
6553 : 33177 : pic_labels_used |= 1 << REGNO (dest);
6554 : :
6555 : 66354 : xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
6556 : 33177 : xops[2] = gen_rtx_MEM (QImode, xops[2]);
6557 : 33177 : output_asm_insn ("%!call\t%X2", xops);
6558 : :
6559 : : #if TARGET_MACHO
6560 : : /* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here.
6561 : : This is what will be referenced by the Mach-O PIC subsystem. */
6562 : : if (machopic_should_output_picbase_label () || !label)
6563 : : ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
6564 : :
6565 : : /* When we are restoring the pic base at the site of a nonlocal label,
6566 : : and we decided to emit the pic base above, we will still output a
6567 : : local label used for calculating the correction offset (even though
6568 : : the offset will be 0 in that case). */
6569 : : if (label)
6570 : : targetm.asm_out.internal_label (asm_out_file, "L",
6571 : : CODE_LABEL_NUMBER (label));
6572 : : #endif
6573 : : }
6574 : : else
6575 : : {
6576 : 0 : if (TARGET_MACHO)
6577 : : /* We don't need a pic base, we're not producing pic. */
6578 : : gcc_unreachable ();
6579 : :
6580 : 0 : xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
6581 : 0 : output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
6582 : 0 : targetm.asm_out.internal_label (asm_out_file, "L",
6583 : 0 : CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
6584 : : }
6585 : :
6586 : 33177 : if (!TARGET_MACHO)
6587 : 33177 : output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
6588 : :
6589 : 33177 : return "";
6590 : : }
6591 : :
6592 : : /* Generate an "push" pattern for input ARG. */
6593 : :
6594 : : rtx
6595 : 1880826 : gen_push (rtx arg, bool ppx_p)
6596 : : {
6597 : 1880826 : struct machine_function *m = cfun->machine;
6598 : :
6599 : 1880826 : if (m->fs.cfa_reg == stack_pointer_rtx)
6600 : 1610779 : m->fs.cfa_offset += UNITS_PER_WORD;
6601 : 1880826 : m->fs.sp_offset += UNITS_PER_WORD;
6602 : :
6603 : 1880826 : if (REG_P (arg) && GET_MODE (arg) != word_mode)
6604 : 37 : arg = gen_rtx_REG (word_mode, REGNO (arg));
6605 : :
6606 : 1880826 : rtx stack = gen_rtx_MEM (word_mode,
6607 : 1880826 : gen_rtx_PRE_DEC (Pmode,
6608 : : stack_pointer_rtx));
6609 : 3761566 : return ppx_p ? gen_pushp_di (stack, arg) : gen_rtx_SET (stack, arg);
6610 : : }
6611 : :
6612 : : rtx
6613 : 23 : gen_pushfl (void)
6614 : : {
6615 : 23 : struct machine_function *m = cfun->machine;
6616 : 23 : rtx flags, mem;
6617 : :
6618 : 23 : if (m->fs.cfa_reg == stack_pointer_rtx)
6619 : 0 : m->fs.cfa_offset += UNITS_PER_WORD;
6620 : 23 : m->fs.sp_offset += UNITS_PER_WORD;
6621 : :
6622 : 23 : flags = gen_rtx_REG (CCmode, FLAGS_REG);
6623 : :
6624 : 23 : mem = gen_rtx_MEM (word_mode,
6625 : 23 : gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
6626 : :
6627 : 23 : return gen_pushfl2 (word_mode, mem, flags);
6628 : : }
6629 : :
6630 : : /* Generate an "pop" pattern for input ARG. */
6631 : :
6632 : : rtx
6633 : 1463989 : gen_pop (rtx arg, bool ppx_p)
6634 : : {
6635 : 1463989 : if (REG_P (arg) && GET_MODE (arg) != word_mode)
6636 : 33 : arg = gen_rtx_REG (word_mode, REGNO (arg));
6637 : :
6638 : 1463989 : rtx stack = gen_rtx_MEM (word_mode,
6639 : 1463989 : gen_rtx_POST_INC (Pmode,
6640 : : stack_pointer_rtx));
6641 : :
6642 : 2927892 : return ppx_p ? gen_popp_di (arg, stack) : gen_rtx_SET (arg, stack);
6643 : : }
6644 : :
6645 : : rtx
6646 : 21 : gen_popfl (void)
6647 : : {
6648 : 21 : rtx flags, mem;
6649 : :
6650 : 21 : flags = gen_rtx_REG (CCmode, FLAGS_REG);
6651 : :
6652 : 21 : mem = gen_rtx_MEM (word_mode,
6653 : 21 : gen_rtx_POST_INC (Pmode, stack_pointer_rtx));
6654 : :
6655 : 21 : return gen_popfl1 (word_mode, flags, mem);
6656 : : }
6657 : :
6658 : : /* Generate a "push2" pattern for input ARG. */
6659 : : rtx
6660 : 17 : gen_push2 (rtx mem, rtx reg1, rtx reg2, bool ppx_p = false)
6661 : : {
6662 : 17 : struct machine_function *m = cfun->machine;
6663 : 17 : const int offset = UNITS_PER_WORD * 2;
6664 : :
6665 : 17 : if (m->fs.cfa_reg == stack_pointer_rtx)
6666 : 14 : m->fs.cfa_offset += offset;
6667 : 17 : m->fs.sp_offset += offset;
6668 : :
6669 : 17 : if (REG_P (reg1) && GET_MODE (reg1) != word_mode)
6670 : 0 : reg1 = gen_rtx_REG (word_mode, REGNO (reg1));
6671 : :
6672 : 17 : if (REG_P (reg2) && GET_MODE (reg2) != word_mode)
6673 : 0 : reg2 = gen_rtx_REG (word_mode, REGNO (reg2));
6674 : :
6675 : 17 : return ppx_p ? gen_push2p_di (mem, reg1, reg2)
6676 : 4 : : gen_push2_di (mem, reg1, reg2);
6677 : : }
6678 : :
6679 : : /* Return >= 0 if there is an unused call-clobbered register available
6680 : : for the entire function. */
6681 : :
6682 : : static unsigned int
6683 : 0 : ix86_select_alt_pic_regnum (void)
6684 : : {
6685 : 0 : if (ix86_use_pseudo_pic_reg ())
6686 : : return INVALID_REGNUM;
6687 : :
6688 : 0 : if (crtl->is_leaf
6689 : 0 : && !crtl->profile
6690 : 0 : && !ix86_current_function_calls_tls_descriptor)
6691 : : {
6692 : 0 : int i, drap;
6693 : : /* Can't use the same register for both PIC and DRAP. */
6694 : 0 : if (crtl->drap_reg)
6695 : 0 : drap = REGNO (crtl->drap_reg);
6696 : : else
6697 : : drap = -1;
6698 : 0 : for (i = 2; i >= 0; --i)
6699 : 0 : if (i != drap && !df_regs_ever_live_p (i))
6700 : : return i;
6701 : : }
6702 : :
6703 : : return INVALID_REGNUM;
6704 : : }
6705 : :
6706 : : /* Return true if REGNO is used by the epilogue. */
6707 : :
6708 : : bool
6709 : 1635427518 : ix86_epilogue_uses (int regno)
6710 : : {
6711 : : /* If there are no caller-saved registers, we preserve all registers,
6712 : : except for MMX and x87 registers which aren't supported when saving
6713 : : and restoring registers. Don't explicitly save SP register since
6714 : : it is always preserved. */
6715 : 1635427518 : return (epilogue_completed
6716 : 258638710 : && (cfun->machine->call_saved_registers
6717 : 258638710 : == TYPE_NO_CALLER_SAVED_REGISTERS)
6718 : 26404 : && !fixed_regs[regno]
6719 : 4897 : && !STACK_REGNO_P (regno)
6720 : 1635432319 : && !MMX_REGNO_P (regno));
6721 : : }
6722 : :
6723 : : /* Return nonzero if register REGNO can be used as a scratch register
6724 : : in peephole2. */
6725 : :
6726 : : static bool
6727 : 1228958 : ix86_hard_regno_scratch_ok (unsigned int regno)
6728 : : {
6729 : : /* If there are no caller-saved registers, we can't use any register
6730 : : as a scratch register after epilogue and use REGNO as scratch
6731 : : register only if it has been used before to avoid saving and
6732 : : restoring it. */
6733 : 1228958 : return ((cfun->machine->call_saved_registers
6734 : 1228958 : != TYPE_NO_CALLER_SAVED_REGISTERS)
6735 : 1228958 : || (!epilogue_completed
6736 : 0 : && df_regs_ever_live_p (regno)));
6737 : : }
6738 : :
6739 : : /* Return TRUE if we need to save REGNO. */
6740 : :
6741 : : bool
6742 : 348640360 : ix86_save_reg (unsigned int regno, bool maybe_eh_return, bool ignore_outlined)
6743 : : {
6744 : 348640360 : rtx reg;
6745 : :
6746 : 348640360 : switch (cfun->machine->call_saved_registers)
6747 : : {
6748 : : case TYPE_DEFAULT_CALL_SAVED_REGISTERS:
6749 : : break;
6750 : :
6751 : 55712 : case TYPE_NO_CALLER_SAVED_REGISTERS:
6752 : : /* If there are no caller-saved registers, we preserve all
6753 : : registers, except for MMX and x87 registers which aren't
6754 : : supported when saving and restoring registers. Don't
6755 : : explicitly save SP register since it is always preserved.
6756 : :
6757 : : Don't preserve registers used for function return value. */
6758 : 55712 : reg = crtl->return_rtx;
6759 : 55712 : if (reg)
6760 : : {
6761 : 768 : unsigned int i = REGNO (reg);
6762 : 768 : unsigned int nregs = REG_NREGS (reg);
6763 : 1522 : while (nregs-- > 0)
6764 : 768 : if ((i + nregs) == regno)
6765 : : return false;
6766 : : }
6767 : :
6768 : 55698 : return (df_regs_ever_live_p (regno)
6769 : 6540 : && !fixed_regs[regno]
6770 : 5598 : && !STACK_REGNO_P (regno)
6771 : 5598 : && !MMX_REGNO_P (regno)
6772 : 61296 : && (regno != HARD_FRAME_POINTER_REGNUM
6773 : 287 : || !frame_pointer_needed));
6774 : :
6775 : : case TYPE_NO_CALLEE_SAVED_REGISTERS:
6776 : : case TYPE_PRESERVE_NONE:
6777 : : return false;
6778 : :
6779 : 2400 : case TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP:
6780 : 2400 : if (regno != HARD_FRAME_POINTER_REGNUM)
6781 : : return false;
6782 : : break;
6783 : : }
6784 : :
6785 : 382281299 : if (regno == REAL_PIC_OFFSET_TABLE_REGNUM
6786 : 10600235 : && pic_offset_table_rtx)
6787 : : {
6788 : 378209 : if (ix86_use_pseudo_pic_reg ())
6789 : : {
6790 : : /* REAL_PIC_OFFSET_TABLE_REGNUM used by call to
6791 : : _mcount in prologue. */
6792 : 378209 : if (!TARGET_64BIT && flag_pic && crtl->profile)
6793 : : return true;
6794 : : }
6795 : 0 : else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
6796 : 0 : || crtl->profile
6797 : 0 : || crtl->calls_eh_return
6798 : 0 : || crtl->uses_const_pool
6799 : 0 : || cfun->has_nonlocal_label)
6800 : 0 : return ix86_select_alt_pic_regnum () == INVALID_REGNUM;
6801 : : }
6802 : :
6803 : 348569811 : if (crtl->calls_eh_return && maybe_eh_return)
6804 : : {
6805 : : unsigned i;
6806 : 13603 : for (i = 0; ; i++)
6807 : : {
6808 : 20739 : unsigned test = EH_RETURN_DATA_REGNO (i);
6809 : 14049 : if (test == INVALID_REGNUM)
6810 : : break;
6811 : 14049 : if (test == regno)
6812 : : return true;
6813 : 13603 : }
6814 : : }
6815 : :
6816 : 348569365 : if (ignore_outlined && cfun->machine->call_ms2sysv)
6817 : : {
6818 : 2650688 : unsigned count = cfun->machine->call_ms2sysv_extra_regs
6819 : : + xlogue_layout::MIN_REGS;
6820 : 2650688 : if (xlogue_layout::is_stub_managed_reg (regno, count))
6821 : : return false;
6822 : : }
6823 : :
6824 : 348069496 : if (crtl->drap_reg
6825 : 2144346 : && regno == REGNO (crtl->drap_reg)
6826 : 348123616 : && !cfun->machine->no_drap_save_restore)
6827 : : return true;
6828 : :
6829 : 348015376 : return (df_regs_ever_live_p (regno)
6830 : 367377428 : && !call_used_or_fixed_reg_p (regno)
6831 : 366752444 : && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
6832 : : }
6833 : :
6834 : : /* Return number of saved general prupose registers. */
6835 : :
6836 : : static int
6837 : 8038375 : ix86_nsaved_regs (void)
6838 : : {
6839 : 8038375 : int nregs = 0;
6840 : 8038375 : int regno;
6841 : :
6842 : 747568875 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6843 : 739530500 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
6844 : 8232880 : nregs ++;
6845 : 8038375 : return nregs;
6846 : : }
6847 : :
6848 : : /* Return number of saved SSE registers. */
6849 : :
6850 : : static int
6851 : 8072005 : ix86_nsaved_sseregs (void)
6852 : : {
6853 : 8072005 : int nregs = 0;
6854 : 8072005 : int regno;
6855 : :
6856 : 7274189 : if (!TARGET_64BIT_MS_ABI
6857 : 8072005 : && (cfun->machine->call_saved_registers
6858 : 7846624 : != TYPE_NO_CALLER_SAVED_REGISTERS))
6859 : : return 0;
6860 : 21027579 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
6861 : 20801476 : if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
6862 : 1896315 : nregs ++;
6863 : : return nregs;
6864 : : }
6865 : :
6866 : : /* Given FROM and TO register numbers, say whether this elimination is
6867 : : allowed. If stack alignment is needed, we can only replace argument
6868 : : pointer with hard frame pointer, or replace frame pointer with stack
6869 : : pointer. Otherwise, frame pointer elimination is automatically
6870 : : handled and all other eliminations are valid. */
6871 : :
6872 : : static bool
6873 : 47566273 : ix86_can_eliminate (const int from, const int to)
6874 : : {
6875 : 47566273 : if (stack_realign_fp)
6876 : 1659980 : return ((from == ARG_POINTER_REGNUM
6877 : 1659980 : && to == HARD_FRAME_POINTER_REGNUM)
6878 : 1659980 : || (from == FRAME_POINTER_REGNUM
6879 : 1659980 : && to == STACK_POINTER_REGNUM));
6880 : : else
6881 : 85365484 : return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true;
6882 : : }
6883 : :
6884 : : /* Return the offset between two registers, one to be eliminated, and the other
6885 : : its replacement, at the start of a routine. */
6886 : :
6887 : : HOST_WIDE_INT
6888 : 138582830 : ix86_initial_elimination_offset (int from, int to)
6889 : : {
6890 : 138582830 : struct ix86_frame &frame = cfun->machine->frame;
6891 : :
6892 : 138582830 : if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
6893 : 10338904 : return frame.hard_frame_pointer_offset;
6894 : 128243926 : else if (from == FRAME_POINTER_REGNUM
6895 : 128243926 : && to == HARD_FRAME_POINTER_REGNUM)
6896 : 8004446 : return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
6897 : : else
6898 : : {
6899 : 120239480 : gcc_assert (to == STACK_POINTER_REGNUM);
6900 : :
6901 : 120239480 : if (from == ARG_POINTER_REGNUM)
6902 : 112235034 : return frame.stack_pointer_offset;
6903 : :
6904 : 8004446 : gcc_assert (from == FRAME_POINTER_REGNUM);
6905 : 8004446 : return frame.stack_pointer_offset - frame.frame_pointer_offset;
6906 : : }
6907 : : }
6908 : :
6909 : : /* Emits a warning for unsupported msabi to sysv pro/epilogues. */
6910 : : void
6911 : 0 : warn_once_call_ms2sysv_xlogues (const char *feature)
6912 : : {
6913 : 0 : static bool warned_once = false;
6914 : 0 : if (!warned_once)
6915 : : {
6916 : 0 : warning (0, "%<-mcall-ms2sysv-xlogues%> is not compatible with %s",
6917 : : feature);
6918 : 0 : warned_once = true;
6919 : : }
6920 : 0 : }
6921 : :
6922 : : /* Return the probing interval for -fstack-clash-protection. */
6923 : :
6924 : : static HOST_WIDE_INT
6925 : 488 : get_probe_interval (void)
6926 : : {
6927 : 335 : if (flag_stack_clash_protection)
6928 : 405 : return (HOST_WIDE_INT_1U
6929 : 405 : << param_stack_clash_protection_probe_interval);
6930 : : else
6931 : : return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
6932 : : }
6933 : :
6934 : : /* When using -fsplit-stack, the allocation routines set a field in
6935 : : the TCB to the bottom of the stack plus this much space, measured
6936 : : in bytes. */
6937 : :
6938 : : #define SPLIT_STACK_AVAILABLE 256
6939 : :
6940 : : /* Return true if push2/pop2 can be generated. */
6941 : :
6942 : : static bool
6943 : 8039011 : ix86_can_use_push2pop2 (void)
6944 : : {
6945 : : /* Use push2/pop2 only if the incoming stack is 16-byte aligned. */
6946 : 8039011 : unsigned int incoming_stack_boundary
6947 : 8039011 : = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
6948 : 8039011 : ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
6949 : 8039011 : return incoming_stack_boundary % 128 == 0;
6950 : : }
6951 : :
6952 : : /* Helper function to determine whether push2/pop2 can be used in prologue or
6953 : : epilogue for register save/restore. */
6954 : : static bool
6955 : 8038375 : ix86_pro_and_epilogue_can_use_push2pop2 (int nregs)
6956 : : {
6957 : 8038375 : if (!ix86_can_use_push2pop2 ())
6958 : : return false;
6959 : 8002493 : int aligned = cfun->machine->fs.sp_offset % 16 == 0;
6960 : 8002493 : return TARGET_APX_PUSH2POP2
6961 : 2769 : && !cfun->machine->frame.save_regs_using_mov
6962 : 2757 : && cfun->machine->func_type == TYPE_NORMAL
6963 : 8005242 : && (nregs + aligned) >= 3;
6964 : : }
6965 : :
6966 : : /* Check if push/pop should be used to save/restore registers. */
6967 : : static bool
6968 : 8745251 : save_regs_using_push_pop (HOST_WIDE_INT to_allocate)
6969 : : {
6970 : 3092993 : return ((!to_allocate && cfun->machine->frame.nregs <= 1)
6971 : 5899610 : || (TARGET_64BIT && to_allocate >= HOST_WIDE_INT_C (0x80000000))
6972 : : /* If static stack checking is enabled and done with probes,
6973 : : the registers need to be saved before allocating the frame. */
6974 : 5898913 : || flag_stack_check == STATIC_BUILTIN_STACK_CHECK
6975 : : /* If stack clash probing needs a loop, then it needs a
6976 : : scratch register. But the returned register is only guaranteed
6977 : : to be safe to use after register saves are complete. So if
6978 : : stack clash protections are enabled and the allocated frame is
6979 : : larger than the probe interval, then use pushes to save
6980 : : callee saved registers. */
6981 : 14644084 : || (flag_stack_clash_protection
6982 : 335 : && !ix86_target_stack_probe ()
6983 : 335 : && to_allocate > get_probe_interval ()));
6984 : : }
6985 : :
6986 : : /* Fill structure ix86_frame about frame of currently computed function. */
6987 : :
6988 : : static void
6989 : 8038375 : ix86_compute_frame_layout (void)
6990 : : {
6991 : 8038375 : struct ix86_frame *frame = &cfun->machine->frame;
6992 : 8038375 : struct machine_function *m = cfun->machine;
6993 : 8038375 : unsigned HOST_WIDE_INT stack_alignment_needed;
6994 : 8038375 : HOST_WIDE_INT offset;
6995 : 8038375 : unsigned HOST_WIDE_INT preferred_alignment;
6996 : 8038375 : HOST_WIDE_INT size = ix86_get_frame_size ();
6997 : 8038375 : HOST_WIDE_INT to_allocate;
6998 : :
6999 : : /* m->call_ms2sysv is initially enabled in ix86_expand_call for all 64-bit
7000 : : * ms_abi functions that call a sysv function. We now need to prune away
7001 : : * cases where it should be disabled. */
7002 : 8038375 : if (TARGET_64BIT && m->call_ms2sysv)
7003 : : {
7004 : 35225 : gcc_assert (TARGET_64BIT_MS_ABI);
7005 : 35225 : gcc_assert (TARGET_CALL_MS2SYSV_XLOGUES);
7006 : 35225 : gcc_assert (!TARGET_SEH);
7007 : 35225 : gcc_assert (TARGET_SSE);
7008 : 35225 : gcc_assert (!ix86_using_red_zone ());
7009 : :
7010 : 35225 : if (crtl->calls_eh_return)
7011 : : {
7012 : 0 : gcc_assert (!reload_completed);
7013 : 0 : m->call_ms2sysv = false;
7014 : 0 : warn_once_call_ms2sysv_xlogues ("__builtin_eh_return");
7015 : : }
7016 : :
7017 : 35225 : else if (ix86_static_chain_on_stack)
7018 : : {
7019 : 0 : gcc_assert (!reload_completed);
7020 : 0 : m->call_ms2sysv = false;
7021 : 0 : warn_once_call_ms2sysv_xlogues ("static call chains");
7022 : : }
7023 : :
7024 : : /* Finally, compute which registers the stub will manage. */
7025 : : else
7026 : : {
7027 : 35225 : unsigned count = xlogue_layout::count_stub_managed_regs ();
7028 : 35225 : m->call_ms2sysv_extra_regs = count - xlogue_layout::MIN_REGS;
7029 : 35225 : m->call_ms2sysv_pad_in = 0;
7030 : : }
7031 : : }
7032 : :
7033 : 8038375 : frame->nregs = ix86_nsaved_regs ();
7034 : 8038375 : frame->nsseregs = ix86_nsaved_sseregs ();
7035 : :
7036 : : /* 64-bit MS ABI seem to require stack alignment to be always 16,
7037 : : except for function prologues, leaf functions and when the defult
7038 : : incoming stack boundary is overriden at command line or via
7039 : : force_align_arg_pointer attribute.
7040 : :
7041 : : Darwin's ABI specifies 128b alignment for both 32 and 64 bit variants
7042 : : at call sites, including profile function calls.
7043 : :
7044 : : For APX push2/pop2, the stack also requires 128b alignment. */
7045 : 8038375 : if ((ix86_pro_and_epilogue_can_use_push2pop2 (frame->nregs)
7046 : 62 : && crtl->preferred_stack_boundary < 128)
7047 : 8038436 : || (((TARGET_64BIT_MS_ABI || TARGET_MACHO)
7048 : 225379 : && crtl->preferred_stack_boundary < 128)
7049 : 0 : && (!crtl->is_leaf || cfun->calls_alloca != 0
7050 : 0 : || ix86_current_function_calls_tls_descriptor
7051 : 0 : || (TARGET_MACHO && crtl->profile)
7052 : 0 : || ix86_incoming_stack_boundary < 128)))
7053 : : {
7054 : 1 : crtl->preferred_stack_boundary = 128;
7055 : 1 : if (crtl->stack_alignment_needed < 128)
7056 : 1 : crtl->stack_alignment_needed = 128;
7057 : : }
7058 : :
7059 : 8038375 : stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7060 : 8038375 : preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7061 : :
7062 : 8038375 : gcc_assert (!size || stack_alignment_needed);
7063 : 8836162 : gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7064 : 8038375 : gcc_assert (preferred_alignment <= stack_alignment_needed);
7065 : :
7066 : : /* The only ABI saving SSE regs should be 64-bit ms_abi or with
7067 : : no_caller_saved_registers attribue. */
7068 : 8038375 : gcc_assert (TARGET_64BIT
7069 : : || (cfun->machine->call_saved_registers
7070 : : == TYPE_NO_CALLER_SAVED_REGISTERS)
7071 : : || !frame->nsseregs);
7072 : 8038375 : if (TARGET_64BIT && m->call_ms2sysv)
7073 : : {
7074 : 35225 : gcc_assert (stack_alignment_needed >= 16);
7075 : 35225 : gcc_assert ((cfun->machine->call_saved_registers
7076 : : == TYPE_NO_CALLER_SAVED_REGISTERS)
7077 : : || !frame->nsseregs);
7078 : : }
7079 : :
7080 : : /* For SEH we have to limit the amount of code movement into the prologue.
7081 : : At present we do this via a BLOCKAGE, at which point there's very little
7082 : : scheduling that can be done, which means that there's very little point
7083 : : in doing anything except PUSHs. */
7084 : 8038375 : if (TARGET_SEH)
7085 : : m->use_fast_prologue_epilogue = false;
7086 : 8038375 : else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
7087 : : {
7088 : 7716285 : int count = frame->nregs;
7089 : 7716285 : struct cgraph_node *node = cgraph_node::get (current_function_decl);
7090 : :
7091 : : /* The fast prologue uses move instead of push to save registers. This
7092 : : is significantly longer, but also executes faster as modern hardware
7093 : : can execute the moves in parallel, but can't do that for push/pop.
7094 : :
7095 : : Be careful about choosing what prologue to emit: When function takes
7096 : : many instructions to execute we may use slow version as well as in
7097 : : case function is known to be outside hot spot (this is known with
7098 : : feedback only). Weight the size of function by number of registers
7099 : : to save as it is cheap to use one or two push instructions but very
7100 : : slow to use many of them.
7101 : :
7102 : : Calling this hook multiple times with the same frame requirements
7103 : : must produce the same layout, since the RA might otherwise be
7104 : : unable to reach a fixed point or might fail its final sanity checks.
7105 : : This means that once we've assumed that a function does or doesn't
7106 : : have a particular size, we have to stick to that assumption
7107 : : regardless of how the function has changed since. */
7108 : 7716285 : if (count)
7109 : 2599276 : count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7110 : 7716285 : if (node->frequency < NODE_FREQUENCY_NORMAL
7111 : 7048594 : || (flag_branch_probabilities
7112 : 966 : && node->frequency < NODE_FREQUENCY_HOT))
7113 : 667996 : m->use_fast_prologue_epilogue = false;
7114 : : else
7115 : : {
7116 : 7048289 : if (count != frame->expensive_count)
7117 : : {
7118 : 286528 : frame->expensive_count = count;
7119 : 286528 : frame->expensive_p = expensive_function_p (count);
7120 : : }
7121 : 7048289 : m->use_fast_prologue_epilogue = !frame->expensive_p;
7122 : : }
7123 : : }
7124 : :
7125 : 8038375 : frame->save_regs_using_mov
7126 : 8038375 : = TARGET_PROLOGUE_USING_MOVE && m->use_fast_prologue_epilogue;
7127 : :
7128 : : /* Skip return address and error code in exception handler. */
7129 : 8038375 : offset = INCOMING_FRAME_SP_OFFSET;
7130 : :
7131 : : /* Skip pushed static chain. */
7132 : 8038375 : if (ix86_static_chain_on_stack)
7133 : 0 : offset += UNITS_PER_WORD;
7134 : :
7135 : : /* Skip saved base pointer. */
7136 : 8038375 : if (frame_pointer_needed)
7137 : 2741142 : offset += UNITS_PER_WORD;
7138 : 8038375 : frame->hfp_save_offset = offset;
7139 : :
7140 : : /* The traditional frame pointer location is at the top of the frame. */
7141 : 8038375 : frame->hard_frame_pointer_offset = offset;
7142 : :
7143 : : /* Register save area */
7144 : 8038375 : offset += frame->nregs * UNITS_PER_WORD;
7145 : 8038375 : frame->reg_save_offset = offset;
7146 : :
7147 : : /* Calculate the size of the va-arg area (not including padding, if any). */
7148 : 8038375 : frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7149 : :
7150 : : /* Also adjust stack_realign_offset for the largest alignment of
7151 : : stack slot actually used. */
7152 : 8038375 : if (stack_realign_fp
7153 : 7739913 : || (cfun->machine->max_used_stack_alignment != 0
7154 : 123 : && (offset % cfun->machine->max_used_stack_alignment) != 0))
7155 : : {
7156 : : /* We may need a 16-byte aligned stack for the remainder of the
7157 : : register save area, but the stack frame for the local function
7158 : : may require a greater alignment if using AVX/2/512. In order
7159 : : to avoid wasting space, we first calculate the space needed for
7160 : : the rest of the register saves, add that to the stack pointer,
7161 : : and then realign the stack to the boundary of the start of the
7162 : : frame for the local function. */
7163 : 298528 : HOST_WIDE_INT space_needed = 0;
7164 : 298528 : HOST_WIDE_INT sse_reg_space_needed = 0;
7165 : :
7166 : 298528 : if (TARGET_64BIT)
7167 : : {
7168 : 296738 : if (m->call_ms2sysv)
7169 : : {
7170 : 6415 : m->call_ms2sysv_pad_in = 0;
7171 : 6415 : space_needed = xlogue_layout::get_instance ().get_stack_space_used ();
7172 : : }
7173 : :
7174 : 290323 : else if (frame->nsseregs)
7175 : : /* The only ABI that has saved SSE registers (Win64) also has a
7176 : : 16-byte aligned default stack. However, many programs violate
7177 : : the ABI, and Wine64 forces stack realignment to compensate. */
7178 : 6447 : space_needed = frame->nsseregs * 16;
7179 : :
7180 : 296738 : sse_reg_space_needed = space_needed = ROUND_UP (space_needed, 16);
7181 : :
7182 : : /* 64-bit frame->va_arg_size should always be a multiple of 16, but
7183 : : rounding to be pedantic. */
7184 : 296738 : space_needed = ROUND_UP (space_needed + frame->va_arg_size, 16);
7185 : : }
7186 : : else
7187 : 1790 : space_needed = frame->va_arg_size;
7188 : :
7189 : : /* Record the allocation size required prior to the realignment AND. */
7190 : 298528 : frame->stack_realign_allocate = space_needed;
7191 : :
7192 : : /* The re-aligned stack starts at frame->stack_realign_offset. Values
7193 : : before this point are not directly comparable with values below
7194 : : this point. Use sp_valid_at to determine if the stack pointer is
7195 : : valid for a given offset, fp_valid_at for the frame pointer, or
7196 : : choose_baseaddr to have a base register chosen for you.
7197 : :
7198 : : Note that the result of (frame->stack_realign_offset
7199 : : & (stack_alignment_needed - 1)) may not equal zero. */
7200 : 298528 : offset = ROUND_UP (offset + space_needed, stack_alignment_needed);
7201 : 298528 : frame->stack_realign_offset = offset - space_needed;
7202 : 298528 : frame->sse_reg_save_offset = frame->stack_realign_offset
7203 : 298528 : + sse_reg_space_needed;
7204 : 298528 : }
7205 : : else
7206 : : {
7207 : 7739847 : frame->stack_realign_offset = offset;
7208 : :
7209 : 7739847 : if (TARGET_64BIT && m->call_ms2sysv)
7210 : : {
7211 : 28810 : m->call_ms2sysv_pad_in = !!(offset & UNITS_PER_WORD);
7212 : 28810 : offset += xlogue_layout::get_instance ().get_stack_space_used ();
7213 : : }
7214 : :
7215 : : /* Align and set SSE register save area. */
7216 : 7711037 : else if (frame->nsseregs)
7217 : : {
7218 : : /* If the incoming stack boundary is at least 16 bytes, or DRAP is
7219 : : required and the DRAP re-alignment boundary is at least 16 bytes,
7220 : : then we want the SSE register save area properly aligned. */
7221 : 183177 : if (ix86_incoming_stack_boundary >= 128
7222 : 6400 : || (stack_realign_drap && stack_alignment_needed >= 16))
7223 : 183177 : offset = ROUND_UP (offset, 16);
7224 : 183177 : offset += frame->nsseregs * 16;
7225 : : }
7226 : 7739847 : frame->sse_reg_save_offset = offset;
7227 : 7739847 : offset += frame->va_arg_size;
7228 : : }
7229 : :
7230 : : /* Align start of frame for local function. When a function call
7231 : : is removed, it may become a leaf function. But if argument may
7232 : : be passed on stack, we need to align the stack when there is no
7233 : : tail call. */
7234 : 8038375 : if (m->call_ms2sysv
7235 : 8003150 : || frame->va_arg_size != 0
7236 : 7924680 : || size != 0
7237 : 4260031 : || !crtl->is_leaf
7238 : 1966222 : || (!crtl->tail_call_emit
7239 : 1660652 : && cfun->machine->outgoing_args_on_stack)
7240 : 1966172 : || cfun->calls_alloca
7241 : 10002965 : || ix86_current_function_calls_tls_descriptor)
7242 : 6074188 : offset = ROUND_UP (offset, stack_alignment_needed);
7243 : :
7244 : : /* Frame pointer points here. */
7245 : 8038375 : frame->frame_pointer_offset = offset;
7246 : :
7247 : 8038375 : offset += size;
7248 : :
7249 : : /* Add outgoing arguments area. Can be skipped if we eliminated
7250 : : all the function calls as dead code.
7251 : : Skipping is however impossible when function calls alloca. Alloca
7252 : : expander assumes that last crtl->outgoing_args_size
7253 : : of stack frame are unused. */
7254 : 8038375 : if (ACCUMULATE_OUTGOING_ARGS
7255 : 8655582 : && (!crtl->is_leaf || cfun->calls_alloca
7256 : 391063 : || ix86_current_function_calls_tls_descriptor))
7257 : : {
7258 : 226144 : offset += crtl->outgoing_args_size;
7259 : 226144 : frame->outgoing_arguments_size = crtl->outgoing_args_size;
7260 : : }
7261 : : else
7262 : 7812231 : frame->outgoing_arguments_size = 0;
7263 : :
7264 : : /* Align stack boundary. Only needed if we're calling another function
7265 : : or using alloca. */
7266 : 2684509 : if (!crtl->is_leaf || cfun->calls_alloca
7267 : 10719485 : || ix86_current_function_calls_tls_descriptor)
7268 : 5359056 : offset = ROUND_UP (offset, preferred_alignment);
7269 : :
7270 : : /* We've reached end of stack frame. */
7271 : 8038375 : frame->stack_pointer_offset = offset;
7272 : :
7273 : : /* Size prologue needs to allocate. */
7274 : 8038375 : to_allocate = offset - frame->sse_reg_save_offset;
7275 : :
7276 : 8038375 : if (save_regs_using_push_pop (to_allocate))
7277 : 2487327 : frame->save_regs_using_mov = false;
7278 : :
7279 : 8038375 : if (ix86_using_red_zone ()
7280 : 7015023 : && crtl->sp_is_unchanging
7281 : 6380649 : && crtl->is_leaf
7282 : 2584273 : && !cfun->machine->asm_redzone_clobber_seen
7283 : 2584260 : && !ix86_pc_thunk_call_expanded
7284 : 10622635 : && !ix86_current_function_calls_tls_descriptor)
7285 : : {
7286 : 2584260 : frame->red_zone_size = to_allocate;
7287 : 2584260 : if (frame->save_regs_using_mov)
7288 : 139705 : frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7289 : 2584260 : if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7290 : 110313 : frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7291 : : }
7292 : : else
7293 : 5454115 : frame->red_zone_size = 0;
7294 : 8038375 : frame->stack_pointer_offset -= frame->red_zone_size;
7295 : :
7296 : : /* The SEH frame pointer location is near the bottom of the frame.
7297 : : This is enforced by the fact that the difference between the
7298 : : stack pointer and the frame pointer is limited to 240 bytes in
7299 : : the unwind data structure. */
7300 : 8038375 : if (TARGET_SEH)
7301 : : {
7302 : : /* Force the frame pointer to point at or below the lowest register save
7303 : : area, see the SEH code in config/i386/winnt.cc for the rationale. */
7304 : : frame->hard_frame_pointer_offset = frame->sse_reg_save_offset;
7305 : :
7306 : : /* If we can leave the frame pointer where it is, do so; however return
7307 : : the establisher frame for __builtin_frame_address (0) or else if the
7308 : : frame overflows the SEH maximum frame size.
7309 : :
7310 : : Note that the value returned by __builtin_frame_address (0) is quite
7311 : : constrained, because setjmp is piggybacked on the SEH machinery with
7312 : : recent versions of MinGW:
7313 : :
7314 : : # elif defined(__SEH__)
7315 : : # if defined(__aarch64__) || defined(_ARM64_)
7316 : : # define setjmp(BUF) _setjmp((BUF), __builtin_sponentry())
7317 : : # elif (__MINGW_GCC_VERSION < 40702)
7318 : : # define setjmp(BUF) _setjmp((BUF), mingw_getsp())
7319 : : # else
7320 : : # define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))
7321 : : # endif
7322 : :
7323 : : and the second argument passed to _setjmp, if not null, is forwarded
7324 : : to the TargetFrame parameter of RtlUnwindEx by longjmp (after it has
7325 : : built an ExceptionRecord on the fly describing the setjmp buffer). */
7326 : : const HOST_WIDE_INT diff
7327 : : = frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
7328 : : if (diff <= 255 && !crtl->accesses_prior_frames)
7329 : : {
7330 : : /* The resulting diff will be a multiple of 16 lower than 255,
7331 : : i.e. at most 240 as required by the unwind data structure. */
7332 : : frame->hard_frame_pointer_offset += (diff & 15);
7333 : : }
7334 : : else if (diff <= SEH_MAX_FRAME_SIZE && !crtl->accesses_prior_frames)
7335 : : {
7336 : : /* Ideally we'd determine what portion of the local stack frame
7337 : : (within the constraint of the lowest 240) is most heavily used.
7338 : : But without that complication, simply bias the frame pointer
7339 : : by 128 bytes so as to maximize the amount of the local stack
7340 : : frame that is addressable with 8-bit offsets. */
7341 : : frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128;
7342 : : }
7343 : : else
7344 : : frame->hard_frame_pointer_offset = frame->hfp_save_offset;
7345 : : }
7346 : 8038375 : }
7347 : :
7348 : : /* This is semi-inlined memory_address_length, but simplified
7349 : : since we know that we're always dealing with reg+offset, and
7350 : : to avoid having to create and discard all that rtl. */
7351 : :
7352 : : static inline int
7353 : 999152 : choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
7354 : : {
7355 : 999152 : int len = 4;
7356 : :
7357 : 0 : if (offset == 0)
7358 : : {
7359 : : /* EBP and R13 cannot be encoded without an offset. */
7360 : 0 : len = (regno == BP_REG || regno == R13_REG);
7361 : : }
7362 : 990928 : else if (IN_RANGE (offset, -128, 127))
7363 : 609256 : len = 1;
7364 : :
7365 : : /* ESP and R12 must be encoded with a SIB byte. */
7366 : 0 : if (regno == SP_REG || regno == R12_REG)
7367 : 0 : len++;
7368 : :
7369 : 999152 : return len;
7370 : : }
7371 : :
7372 : : /* Determine if the stack pointer is valid for accessing the CFA_OFFSET in
7373 : : the frame save area. The register is saved at CFA - CFA_OFFSET. */
7374 : :
7375 : : static bool
7376 : 3481991 : sp_valid_at (HOST_WIDE_INT cfa_offset)
7377 : : {
7378 : 3481991 : const struct machine_frame_state &fs = cfun->machine->fs;
7379 : 3481991 : if (fs.sp_realigned && cfa_offset <= fs.sp_realigned_offset)
7380 : : {
7381 : : /* Validate that the cfa_offset isn't in a "no-man's land". */
7382 : 46106 : gcc_assert (cfa_offset <= fs.sp_realigned_fp_last);
7383 : : return false;
7384 : : }
7385 : 3435885 : return fs.sp_valid;
7386 : : }
7387 : :
7388 : : /* Determine if the frame pointer is valid for accessing the CFA_OFFSET in
7389 : : the frame save area. The register is saved at CFA - CFA_OFFSET. */
7390 : :
7391 : : static inline bool
7392 : 1383703 : fp_valid_at (HOST_WIDE_INT cfa_offset)
7393 : : {
7394 : 1383703 : const struct machine_frame_state &fs = cfun->machine->fs;
7395 : 1383703 : if (fs.sp_realigned && cfa_offset > fs.sp_realigned_fp_last)
7396 : : {
7397 : : /* Validate that the cfa_offset isn't in a "no-man's land". */
7398 : 28328 : gcc_assert (cfa_offset >= fs.sp_realigned_offset);
7399 : : return false;
7400 : : }
7401 : 1355375 : return fs.fp_valid;
7402 : : }
7403 : :
7404 : : /* Choose a base register based upon alignment requested, speed and/or
7405 : : size. */
7406 : :
7407 : : static void
7408 : 1383703 : choose_basereg (HOST_WIDE_INT cfa_offset, rtx &base_reg,
7409 : : HOST_WIDE_INT &base_offset,
7410 : : unsigned int align_reqested, unsigned int *align)
7411 : : {
7412 : 1383703 : const struct machine_function *m = cfun->machine;
7413 : 1383703 : unsigned int hfp_align;
7414 : 1383703 : unsigned int drap_align;
7415 : 1383703 : unsigned int sp_align;
7416 : 1383703 : bool hfp_ok = fp_valid_at (cfa_offset);
7417 : 1383703 : bool drap_ok = m->fs.drap_valid;
7418 : 1383703 : bool sp_ok = sp_valid_at (cfa_offset);
7419 : :
7420 : 1383703 : hfp_align = drap_align = sp_align = INCOMING_STACK_BOUNDARY;
7421 : :
7422 : : /* Filter out any registers that don't meet the requested alignment
7423 : : criteria. */
7424 : 1383703 : if (align_reqested)
7425 : : {
7426 : 971142 : if (m->fs.realigned)
7427 : 28160 : hfp_align = drap_align = sp_align = crtl->stack_alignment_needed;
7428 : : /* SEH unwind code does do not currently support REG_CFA_EXPRESSION
7429 : : notes (which we would need to use a realigned stack pointer),
7430 : : so disable on SEH targets. */
7431 : 942982 : else if (m->fs.sp_realigned)
7432 : 28328 : sp_align = crtl->stack_alignment_needed;
7433 : :
7434 : 971142 : hfp_ok = hfp_ok && hfp_align >= align_reqested;
7435 : 971142 : drap_ok = drap_ok && drap_align >= align_reqested;
7436 : 971142 : sp_ok = sp_ok && sp_align >= align_reqested;
7437 : : }
7438 : :
7439 : 1383703 : if (m->use_fast_prologue_epilogue)
7440 : : {
7441 : : /* Choose the base register most likely to allow the most scheduling
7442 : : opportunities. Generally FP is valid throughout the function,
7443 : : while DRAP must be reloaded within the epilogue. But choose either
7444 : : over the SP due to increased encoding size. */
7445 : :
7446 : 678654 : if (hfp_ok)
7447 : : {
7448 : 117262 : base_reg = hard_frame_pointer_rtx;
7449 : 117262 : base_offset = m->fs.fp_offset - cfa_offset;
7450 : : }
7451 : 561392 : else if (drap_ok)
7452 : : {
7453 : 0 : base_reg = crtl->drap_reg;
7454 : 0 : base_offset = 0 - cfa_offset;
7455 : : }
7456 : 561392 : else if (sp_ok)
7457 : : {
7458 : 561392 : base_reg = stack_pointer_rtx;
7459 : 561392 : base_offset = m->fs.sp_offset - cfa_offset;
7460 : : }
7461 : : }
7462 : : else
7463 : : {
7464 : 705049 : HOST_WIDE_INT toffset;
7465 : 705049 : int len = 16, tlen;
7466 : :
7467 : : /* Choose the base register with the smallest address encoding.
7468 : : With a tie, choose FP > DRAP > SP. */
7469 : 705049 : if (sp_ok)
7470 : : {
7471 : 687831 : base_reg = stack_pointer_rtx;
7472 : 687831 : base_offset = m->fs.sp_offset - cfa_offset;
7473 : 1367438 : len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset);
7474 : : }
7475 : 705049 : if (drap_ok)
7476 : : {
7477 : 0 : toffset = 0 - cfa_offset;
7478 : 0 : tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset);
7479 : 0 : if (tlen <= len)
7480 : : {
7481 : 0 : base_reg = crtl->drap_reg;
7482 : 0 : base_offset = toffset;
7483 : 0 : len = tlen;
7484 : : }
7485 : : }
7486 : 705049 : if (hfp_ok)
7487 : : {
7488 : 311321 : toffset = m->fs.fp_offset - cfa_offset;
7489 : 311321 : tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset);
7490 : 311321 : if (tlen <= len)
7491 : : {
7492 : 220677 : base_reg = hard_frame_pointer_rtx;
7493 : 220677 : base_offset = toffset;
7494 : : }
7495 : : }
7496 : : }
7497 : :
7498 : : /* Set the align return value. */
7499 : 1383703 : if (align)
7500 : : {
7501 : 971142 : if (base_reg == stack_pointer_rtx)
7502 : 690127 : *align = sp_align;
7503 : 281015 : else if (base_reg == crtl->drap_reg)
7504 : 0 : *align = drap_align;
7505 : 281015 : else if (base_reg == hard_frame_pointer_rtx)
7506 : 281015 : *align = hfp_align;
7507 : : }
7508 : 1383703 : }
7509 : :
7510 : : /* Return an RTX that points to CFA_OFFSET within the stack frame and
7511 : : the alignment of address. If ALIGN is non-null, it should point to
7512 : : an alignment value (in bits) that is preferred or zero and will
7513 : : recieve the alignment of the base register that was selected,
7514 : : irrespective of rather or not CFA_OFFSET is a multiple of that
7515 : : alignment value. If it is possible for the base register offset to be
7516 : : non-immediate then SCRATCH_REGNO should specify a scratch register to
7517 : : use.
7518 : :
7519 : : The valid base registers are taken from CFUN->MACHINE->FS. */
7520 : :
7521 : : static rtx
7522 : 1383703 : choose_baseaddr (HOST_WIDE_INT cfa_offset, unsigned int *align,
7523 : : unsigned int scratch_regno = INVALID_REGNUM)
7524 : : {
7525 : 1383703 : rtx base_reg = NULL;
7526 : 1383703 : HOST_WIDE_INT base_offset = 0;
7527 : :
7528 : : /* If a specific alignment is requested, try to get a base register
7529 : : with that alignment first. */
7530 : 1383703 : if (align && *align)
7531 : 971142 : choose_basereg (cfa_offset, base_reg, base_offset, *align, align);
7532 : :
7533 : 1383703 : if (!base_reg)
7534 : 412561 : choose_basereg (cfa_offset, base_reg, base_offset, 0, align);
7535 : :
7536 : 1383703 : gcc_assert (base_reg != NULL);
7537 : :
7538 : 1383703 : rtx base_offset_rtx = GEN_INT (base_offset);
7539 : :
7540 : 1433136 : if (!x86_64_immediate_operand (base_offset_rtx, Pmode))
7541 : : {
7542 : 1 : gcc_assert (scratch_regno != INVALID_REGNUM);
7543 : :
7544 : 1 : rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
7545 : 1 : emit_move_insn (scratch_reg, base_offset_rtx);
7546 : :
7547 : 1 : return gen_rtx_PLUS (Pmode, base_reg, scratch_reg);
7548 : : }
7549 : :
7550 : 1433135 : return plus_constant (Pmode, base_reg, base_offset);
7551 : : }
7552 : :
7553 : : /* Emit code to save registers in the prologue. */
7554 : :
7555 : : static void
7556 : 425486 : ix86_emit_save_regs (void)
7557 : : {
7558 : 425486 : int regno;
7559 : 425486 : rtx_insn *insn;
7560 : 425486 : bool use_ppx = TARGET_APX_PPX && !crtl->calls_eh_return;
7561 : :
7562 : 425486 : if (!TARGET_APX_PUSH2POP2
7563 : 87 : || !ix86_can_use_push2pop2 ()
7564 : 425571 : || cfun->machine->func_type != TYPE_NORMAL)
7565 : : {
7566 : 39562386 : for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7567 : 39136984 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7568 : : {
7569 : 1201446 : insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno),
7570 : : use_ppx));
7571 : 1201446 : RTX_FRAME_RELATED_P (insn) = 1;
7572 : : }
7573 : : }
7574 : : else
7575 : : {
7576 : 84 : int regno_list[2];
7577 : 84 : regno_list[0] = regno_list[1] = -1;
7578 : 84 : int loaded_regnum = 0;
7579 : 84 : bool aligned = cfun->machine->fs.sp_offset % 16 == 0;
7580 : :
7581 : 7812 : for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
7582 : 7728 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7583 : : {
7584 : 121 : if (aligned)
7585 : : {
7586 : 40 : regno_list[loaded_regnum++] = regno;
7587 : 40 : if (loaded_regnum == 2)
7588 : : {
7589 : 17 : gcc_assert (regno_list[0] != -1
7590 : : && regno_list[1] != -1
7591 : : && regno_list[0] != regno_list[1]);
7592 : 17 : const int offset = UNITS_PER_WORD * 2;
7593 : 17 : rtx mem = gen_rtx_MEM (TImode,
7594 : 17 : gen_rtx_PRE_DEC (Pmode,
7595 : : stack_pointer_rtx));
7596 : 17 : insn = emit_insn (gen_push2 (mem,
7597 : : gen_rtx_REG (word_mode,
7598 : : regno_list[0]),
7599 : : gen_rtx_REG (word_mode,
7600 : : regno_list[1]),
7601 : : use_ppx));
7602 : 17 : RTX_FRAME_RELATED_P (insn) = 1;
7603 : 17 : rtx dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (3));
7604 : :
7605 : 51 : for (int i = 0; i < 2; i++)
7606 : : {
7607 : 68 : rtx dwarf_reg = gen_rtx_REG (word_mode,
7608 : 34 : regno_list[i]);
7609 : 34 : rtx sp_offset = plus_constant (Pmode,
7610 : : stack_pointer_rtx,
7611 : 34 : + UNITS_PER_WORD
7612 : 34 : * (1 - i));
7613 : 34 : rtx tmp = gen_rtx_SET (gen_frame_mem (DImode,
7614 : : sp_offset),
7615 : : dwarf_reg);
7616 : 34 : RTX_FRAME_RELATED_P (tmp) = 1;
7617 : 34 : XVECEXP (dwarf, 0, i + 1) = tmp;
7618 : : }
7619 : 17 : rtx sp_tmp = gen_rtx_SET (stack_pointer_rtx,
7620 : : plus_constant (Pmode,
7621 : : stack_pointer_rtx,
7622 : : -offset));
7623 : 17 : RTX_FRAME_RELATED_P (sp_tmp) = 1;
7624 : 17 : XVECEXP (dwarf, 0, 0) = sp_tmp;
7625 : 17 : add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf);
7626 : :
7627 : 17 : loaded_regnum = 0;
7628 : 17 : regno_list[0] = regno_list[1] = -1;
7629 : : }
7630 : : }
7631 : : else
7632 : : {
7633 : 81 : insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno),
7634 : : use_ppx));
7635 : 81 : RTX_FRAME_RELATED_P (insn) = 1;
7636 : 81 : aligned = true;
7637 : : }
7638 : : }
7639 : 84 : if (loaded_regnum == 1)
7640 : : {
7641 : 6 : insn = emit_insn (gen_push (gen_rtx_REG (word_mode,
7642 : 6 : regno_list[0]),
7643 : : use_ppx));
7644 : 6 : RTX_FRAME_RELATED_P (insn) = 1;
7645 : : }
7646 : : }
7647 : 425486 : }
7648 : :
7649 : : /* Emit a single register save at CFA - CFA_OFFSET. */
7650 : :
7651 : : static void
7652 : 617191 : ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
7653 : : HOST_WIDE_INT cfa_offset)
7654 : : {
7655 : 617191 : struct machine_function *m = cfun->machine;
7656 : 617191 : rtx reg = gen_rtx_REG (mode, regno);
7657 : 617191 : rtx mem, addr, base, insn;
7658 : 617191 : unsigned int align = GET_MODE_ALIGNMENT (mode);
7659 : :
7660 : 617191 : addr = choose_baseaddr (cfa_offset, &align);
7661 : 617191 : mem = gen_frame_mem (mode, addr);
7662 : :
7663 : : /* The location aligment depends upon the base register. */
7664 : 617191 : align = MIN (GET_MODE_ALIGNMENT (mode), align);
7665 : 617191 : gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1)));
7666 : 617191 : set_mem_align (mem, align);
7667 : :
7668 : 617191 : insn = emit_insn (gen_rtx_SET (mem, reg));
7669 : 617191 : RTX_FRAME_RELATED_P (insn) = 1;
7670 : :
7671 : 617191 : base = addr;
7672 : 617191 : if (GET_CODE (base) == PLUS)
7673 : 605293 : base = XEXP (base, 0);
7674 : 617191 : gcc_checking_assert (REG_P (base));
7675 : :
7676 : : /* When saving registers into a re-aligned local stack frame, avoid
7677 : : any tricky guessing by dwarf2out. */
7678 : 617191 : if (m->fs.realigned)
7679 : : {
7680 : 12800 : gcc_checking_assert (stack_realign_drap);
7681 : :
7682 : 12800 : if (regno == REGNO (crtl->drap_reg))
7683 : : {
7684 : : /* A bit of a hack. We force the DRAP register to be saved in
7685 : : the re-aligned stack frame, which provides us with a copy
7686 : : of the CFA that will last past the prologue. Install it. */
7687 : 0 : gcc_checking_assert (cfun->machine->fs.fp_valid);
7688 : 0 : addr = plus_constant (Pmode, hard_frame_pointer_rtx,
7689 : 0 : cfun->machine->fs.fp_offset - cfa_offset);
7690 : 0 : mem = gen_rtx_MEM (mode, addr);
7691 : 0 : add_reg_note (insn, REG_CFA_DEF_CFA, mem);
7692 : : }
7693 : : else
7694 : : {
7695 : : /* The frame pointer is a stable reference within the
7696 : : aligned frame. Use it. */
7697 : 12800 : gcc_checking_assert (cfun->machine->fs.fp_valid);
7698 : 12800 : addr = plus_constant (Pmode, hard_frame_pointer_rtx,
7699 : 12800 : cfun->machine->fs.fp_offset - cfa_offset);
7700 : 12800 : mem = gen_rtx_MEM (mode, addr);
7701 : 12800 : add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
7702 : : }
7703 : : }
7704 : :
7705 : 604391 : else if (base == stack_pointer_rtx && m->fs.sp_realigned
7706 : 12881 : && cfa_offset >= m->fs.sp_realigned_offset)
7707 : : {
7708 : 12881 : gcc_checking_assert (stack_realign_fp);
7709 : 12881 : add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
7710 : : }
7711 : :
7712 : : /* The memory may not be relative to the current CFA register,
7713 : : which means that we may need to generate a new pattern for
7714 : : use by the unwind info. */
7715 : 591510 : else if (base != m->fs.cfa_reg)
7716 : : {
7717 : 45084 : addr = plus_constant (Pmode, m->fs.cfa_reg,
7718 : 45084 : m->fs.cfa_offset - cfa_offset);
7719 : 45084 : mem = gen_rtx_MEM (mode, addr);
7720 : 45084 : add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (mem, reg));
7721 : : }
7722 : 617191 : }
7723 : :
7724 : : /* Emit code to save registers using MOV insns.
7725 : : First register is stored at CFA - CFA_OFFSET. */
7726 : : static void
7727 : 45957 : ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
7728 : : {
7729 : 45957 : unsigned int regno;
7730 : :
7731 : 4274001 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7732 : 4228044 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7733 : : {
7734 : : /* Skip registers, already processed by shrink wrap separate. */
7735 : 194578 : if (!cfun->machine->reg_is_wrapped_separately[regno])
7736 : 86327 : ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
7737 : 208382 : cfa_offset -= UNITS_PER_WORD;
7738 : : }
7739 : 45957 : }
7740 : :
7741 : : /* Emit code to save SSE registers using MOV insns.
7742 : : First register is stored at CFA - CFA_OFFSET. */
7743 : : static void
7744 : 33351 : ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
7745 : : {
7746 : 33351 : unsigned int regno;
7747 : :
7748 : 3101643 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7749 : 3068292 : if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
7750 : : {
7751 : 333525 : ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
7752 : 333525 : cfa_offset -= GET_MODE_SIZE (V4SFmode);
7753 : : }
7754 : 33351 : }
7755 : :
7756 : : static GTY(()) rtx queued_cfa_restores;
7757 : :
7758 : : /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
7759 : : manipulation insn. The value is on the stack at CFA - CFA_OFFSET.
7760 : : Don't add the note if the previously saved value will be left untouched
7761 : : within stack red-zone till return, as unwinders can find the same value
7762 : : in the register and on the stack. */
7763 : :
7764 : : static void
7765 : 2284648 : ix86_add_cfa_restore_note (rtx_insn *insn, rtx reg, HOST_WIDE_INT cfa_offset)
7766 : : {
7767 : 2284648 : if (!crtl->shrink_wrapped
7768 : 2265984 : && cfa_offset <= cfun->machine->fs.red_zone_offset)
7769 : : return;
7770 : :
7771 : 771131 : if (insn)
7772 : : {
7773 : 361132 : add_reg_note (insn, REG_CFA_RESTORE, reg);
7774 : 361132 : RTX_FRAME_RELATED_P (insn) = 1;
7775 : : }
7776 : : else
7777 : 409999 : queued_cfa_restores
7778 : 409999 : = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
7779 : : }
7780 : :
7781 : : /* Add queued REG_CFA_RESTORE notes if any to INSN. */
7782 : :
7783 : : static void
7784 : 2510799 : ix86_add_queued_cfa_restore_notes (rtx insn)
7785 : : {
7786 : 2510799 : rtx last;
7787 : 2510799 : if (!queued_cfa_restores)
7788 : : return;
7789 : 409999 : for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
7790 : : ;
7791 : 52857 : XEXP (last, 1) = REG_NOTES (insn);
7792 : 52857 : REG_NOTES (insn) = queued_cfa_restores;
7793 : 52857 : queued_cfa_restores = NULL_RTX;
7794 : 52857 : RTX_FRAME_RELATED_P (insn) = 1;
7795 : : }
7796 : :
7797 : : /* Expand prologue or epilogue stack adjustment.
7798 : : The pattern exist to put a dependency on all ebp-based memory accesses.
7799 : : STYLE should be negative if instructions should be marked as frame related,
7800 : : zero if %r11 register is live and cannot be freely used and positive
7801 : : otherwise. */
7802 : :
7803 : : static rtx
7804 : 1571875 : pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
7805 : : int style, bool set_cfa)
7806 : : {
7807 : 1571875 : struct machine_function *m = cfun->machine;
7808 : 1571875 : rtx addend = offset;
7809 : 1571875 : rtx insn;
7810 : 1571875 : bool add_frame_related_expr = false;
7811 : :
7812 : 1788157 : if (!x86_64_immediate_operand (offset, Pmode))
7813 : : {
7814 : : /* r11 is used by indirect sibcall return as well, set before the
7815 : : epilogue and used after the epilogue. */
7816 : 204 : if (style)
7817 : 179 : addend = gen_rtx_REG (Pmode, R11_REG);
7818 : : else
7819 : : {
7820 : 25 : gcc_assert (src != hard_frame_pointer_rtx
7821 : : && dest != hard_frame_pointer_rtx);
7822 : : addend = hard_frame_pointer_rtx;
7823 : : }
7824 : 204 : emit_insn (gen_rtx_SET (addend, offset));
7825 : 204 : if (style < 0)
7826 : 92 : add_frame_related_expr = true;
7827 : : }
7828 : :
7829 : : /* Shrink wrap separate may insert prologue between TEST and JMP. In order
7830 : : not to affect EFlags, emit add without reg clobbering. */
7831 : 1571875 : if (crtl->shrink_wrapped_separate)
7832 : 98603 : insn = emit_insn (gen_pro_epilogue_adjust_stack_add_nocc
7833 : 98603 : (Pmode, dest, src, addend));
7834 : : else
7835 : 1473272 : insn = emit_insn (gen_pro_epilogue_adjust_stack_add
7836 : 1473272 : (Pmode, dest, src, addend));
7837 : :
7838 : 1571875 : if (style >= 0)
7839 : 693600 : ix86_add_queued_cfa_restore_notes (insn);
7840 : :
7841 : 1571875 : if (set_cfa)
7842 : : {
7843 : 1215095 : rtx r;
7844 : :
7845 : 1215095 : gcc_assert (m->fs.cfa_reg == src);
7846 : 1215095 : m->fs.cfa_offset += INTVAL (offset);
7847 : 1215095 : m->fs.cfa_reg = dest;
7848 : :
7849 : 1409099 : r = gen_rtx_PLUS (Pmode, src, offset);
7850 : 1215095 : r = gen_rtx_SET (dest, r);
7851 : 1215095 : add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
7852 : 1215095 : RTX_FRAME_RELATED_P (insn) = 1;
7853 : : }
7854 : 356780 : else if (style < 0)
7855 : : {
7856 : 291023 : RTX_FRAME_RELATED_P (insn) = 1;
7857 : 291023 : if (add_frame_related_expr)
7858 : : {
7859 : 23 : rtx r = gen_rtx_PLUS (Pmode, src, offset);
7860 : 23 : r = gen_rtx_SET (dest, r);
7861 : 23 : add_reg_note (insn, REG_FRAME_RELATED_EXPR, r);
7862 : : }
7863 : : }
7864 : :
7865 : 1571875 : if (dest == stack_pointer_rtx)
7866 : : {
7867 : 1571875 : HOST_WIDE_INT ooffset = m->fs.sp_offset;
7868 : 1571875 : bool valid = m->fs.sp_valid;
7869 : 1571875 : bool realigned = m->fs.sp_realigned;
7870 : :
7871 : 1571875 : if (src == hard_frame_pointer_rtx)
7872 : : {
7873 : 29230 : valid = m->fs.fp_valid;
7874 : 29230 : realigned = false;
7875 : 29230 : ooffset = m->fs.fp_offset;
7876 : : }
7877 : 1542645 : else if (src == crtl->drap_reg)
7878 : : {
7879 : 0 : valid = m->fs.drap_valid;
7880 : 0 : realigned = false;
7881 : 0 : ooffset = 0;
7882 : : }
7883 : : else
7884 : : {
7885 : : /* Else there are two possibilities: SP itself, which we set
7886 : : up as the default above. Or EH_RETURN_STACKADJ_RTX, which is
7887 : : taken care of this by hand along the eh_return path. */
7888 : 1542645 : gcc_checking_assert (src == stack_pointer_rtx
7889 : : || offset == const0_rtx);
7890 : : }
7891 : :
7892 : 1571875 : m->fs.sp_offset = ooffset - INTVAL (offset);
7893 : 1571875 : m->fs.sp_valid = valid;
7894 : 1571875 : m->fs.sp_realigned = realigned;
7895 : : }
7896 : 1571875 : return insn;
7897 : : }
7898 : :
7899 : : /* Find an available register to be used as dynamic realign argument
7900 : : pointer regsiter. Such a register will be written in prologue and
7901 : : used in begin of body, so it must not be
7902 : : 1. parameter passing register.
7903 : : 2. GOT pointer.
7904 : : We reuse static-chain register if it is available. Otherwise, we
7905 : : use DI for i386 and R13 for x86-64. We chose R13 since it has
7906 : : shorter encoding.
7907 : :
7908 : : Return: the regno of chosen register. */
7909 : :
7910 : : static unsigned int
7911 : 7131 : find_drap_reg (void)
7912 : : {
7913 : 7131 : tree decl = cfun->decl;
7914 : :
7915 : : /* Always use callee-saved register if there are no caller-saved
7916 : : registers. */
7917 : 7131 : if (TARGET_64BIT)
7918 : : {
7919 : : /* Use R13 for nested function or function need static chain.
7920 : : Since function with tail call may use any caller-saved
7921 : : registers in epilogue, DRAP must not use caller-saved
7922 : : register in such case. */
7923 : 6850 : if (DECL_STATIC_CHAIN (decl)
7924 : 6808 : || (cfun->machine->call_saved_registers
7925 : 6808 : == TYPE_NO_CALLER_SAVED_REGISTERS)
7926 : 13658 : || crtl->tail_call_emit)
7927 : 187 : return R13_REG;
7928 : :
7929 : : return R10_REG;
7930 : : }
7931 : : else
7932 : : {
7933 : : /* Use DI for nested function or function need static chain.
7934 : : Since function with tail call may use any caller-saved
7935 : : registers in epilogue, DRAP must not use caller-saved
7936 : : register in such case. */
7937 : 281 : if (DECL_STATIC_CHAIN (decl)
7938 : 281 : || (cfun->machine->call_saved_registers
7939 : 281 : == TYPE_NO_CALLER_SAVED_REGISTERS)
7940 : 281 : || crtl->tail_call_emit
7941 : 542 : || crtl->calls_eh_return)
7942 : : return DI_REG;
7943 : :
7944 : : /* Reuse static chain register if it isn't used for parameter
7945 : : passing. */
7946 : 261 : if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2)
7947 : : {
7948 : 261 : unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl));
7949 : 261 : if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0)
7950 : : return CX_REG;
7951 : : }
7952 : 0 : return DI_REG;
7953 : : }
7954 : : }
7955 : :
7956 : : /* Return minimum incoming stack alignment. */
7957 : :
7958 : : static unsigned int
7959 : 1585874 : ix86_minimum_incoming_stack_boundary (bool sibcall)
7960 : : {
7961 : 1585874 : unsigned int incoming_stack_boundary;
7962 : :
7963 : : /* Stack of interrupt handler is aligned to 128 bits in 64bit mode. */
7964 : 1585874 : if (cfun->machine->func_type != TYPE_NORMAL)
7965 : 118 : incoming_stack_boundary = TARGET_64BIT ? 128 : MIN_STACK_BOUNDARY;
7966 : : /* Prefer the one specified at command line. */
7967 : 1585756 : else if (ix86_user_incoming_stack_boundary)
7968 : : incoming_stack_boundary = ix86_user_incoming_stack_boundary;
7969 : : /* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary
7970 : : if -mstackrealign is used, it isn't used for sibcall check and
7971 : : estimated stack alignment is 128bit. */
7972 : 1585734 : else if (!sibcall
7973 : 1456321 : && ix86_force_align_arg_pointer
7974 : 4572 : && crtl->stack_alignment_estimated == 128)
7975 : 596 : incoming_stack_boundary = MIN_STACK_BOUNDARY;
7976 : : else
7977 : 1585138 : incoming_stack_boundary = ix86_default_incoming_stack_boundary;
7978 : :
7979 : : /* Incoming stack alignment can be changed on individual functions
7980 : : via force_align_arg_pointer attribute. We use the smallest
7981 : : incoming stack boundary. */
7982 : 1585874 : if (incoming_stack_boundary > MIN_STACK_BOUNDARY
7983 : 3171142 : && lookup_attribute ("force_align_arg_pointer",
7984 : 1585268 : TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7985 : 5708 : incoming_stack_boundary = MIN_STACK_BOUNDARY;
7986 : :
7987 : : /* The incoming stack frame has to be aligned at least at
7988 : : parm_stack_boundary. */
7989 : 1585874 : if (incoming_stack_boundary < crtl->parm_stack_boundary)
7990 : : incoming_stack_boundary = crtl->parm_stack_boundary;
7991 : :
7992 : : /* Stack at entrance of main is aligned by runtime. We use the
7993 : : smallest incoming stack boundary. */
7994 : 1585874 : if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
7995 : 139324 : && DECL_NAME (current_function_decl)
7996 : 139324 : && MAIN_NAME_P (DECL_NAME (current_function_decl))
7997 : 1588344 : && DECL_FILE_SCOPE_P (current_function_decl))
7998 : 2470 : incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7999 : :
8000 : 1585874 : return incoming_stack_boundary;
8001 : : }
8002 : :
8003 : : /* Update incoming stack boundary and estimated stack alignment. */
8004 : :
8005 : : static void
8006 : 1456456 : ix86_update_stack_boundary (void)
8007 : : {
8008 : 1456456 : ix86_incoming_stack_boundary
8009 : 1456456 : = ix86_minimum_incoming_stack_boundary (false);
8010 : :
8011 : : /* x86_64 vararg needs 16byte stack alignment for register save area. */
8012 : 1456456 : if (TARGET_64BIT
8013 : 1330932 : && cfun->stdarg
8014 : 21214 : && crtl->stack_alignment_estimated < 128)
8015 : 10165 : crtl->stack_alignment_estimated = 128;
8016 : :
8017 : : /* __tls_get_addr needs to be called with 16-byte aligned stack. */
8018 : 1456456 : if (ix86_tls_descriptor_calls_expanded_in_cfun
8019 : 1301 : && crtl->preferred_stack_boundary < 128)
8020 : 953 : crtl->preferred_stack_boundary = 128;
8021 : :
8022 : : /* For 32-bit MS ABI, both the incoming and preferred stack boundaries
8023 : : are 32 bits, but if force_align_arg_pointer is specified, it should
8024 : : prefer 128 bits for a backward-compatibility reason, which is also
8025 : : what the doc suggests. */
8026 : 1456456 : if (lookup_attribute ("force_align_arg_pointer",
8027 : 1456456 : TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))
8028 : 1456456 : && crtl->preferred_stack_boundary < 128)
8029 : 4 : crtl->preferred_stack_boundary = 128;
8030 : 1456456 : }
8031 : :
8032 : : /* Handle the TARGET_GET_DRAP_RTX hook. Return NULL if no DRAP is
8033 : : needed or an rtx for DRAP otherwise. */
8034 : :
8035 : : static rtx
8036 : 1565777 : ix86_get_drap_rtx (void)
8037 : : {
8038 : : /* We must use DRAP if there are outgoing arguments on stack or
8039 : : the stack pointer register is clobbered by asm statment and
8040 : : ACCUMULATE_OUTGOING_ARGS is false. */
8041 : 1565777 : if (ix86_force_drap
8042 : 1565777 : || ((cfun->machine->outgoing_args_on_stack
8043 : 1237048 : || crtl->sp_is_clobbered_by_asm)
8044 : 326784 : && !ACCUMULATE_OUTGOING_ARGS))
8045 : 306590 : crtl->need_drap = true;
8046 : :
8047 : 1565777 : if (stack_realign_drap)
8048 : : {
8049 : : /* Assign DRAP to vDRAP and returns vDRAP */
8050 : 7131 : unsigned int regno = find_drap_reg ();
8051 : 7131 : rtx drap_vreg;
8052 : 7131 : rtx arg_ptr;
8053 : 7131 : rtx_insn *seq, *insn;
8054 : :
8055 : 7412 : arg_ptr = gen_rtx_REG (Pmode, regno);
8056 : 7131 : crtl->drap_reg = arg_ptr;
8057 : :
8058 : 7131 : start_sequence ();
8059 : 7131 : drap_vreg = copy_to_reg (arg_ptr);
8060 : 7131 : seq = end_sequence ();
8061 : :
8062 : 7131 : insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
8063 : 7131 : if (!optimize)
8064 : : {
8065 : 1882 : add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg);
8066 : 1882 : RTX_FRAME_RELATED_P (insn) = 1;
8067 : : }
8068 : 7131 : return drap_vreg;
8069 : : }
8070 : : else
8071 : : return NULL;
8072 : : }
8073 : :
8074 : : /* Handle the TARGET_INTERNAL_ARG_POINTER hook. */
8075 : :
8076 : : static rtx
8077 : 1456456 : ix86_internal_arg_pointer (void)
8078 : : {
8079 : 1456456 : return virtual_incoming_args_rtx;
8080 : : }
8081 : :
8082 : : struct scratch_reg {
8083 : : rtx reg;
8084 : : bool saved;
8085 : : };
8086 : :
8087 : : /* Return a short-lived scratch register for use on function entry.
8088 : : In 32-bit mode, it is valid only after the registers are saved
8089 : : in the prologue. This register must be released by means of
8090 : : release_scratch_register_on_entry once it is dead. */
8091 : :
8092 : : static void
8093 : 25 : get_scratch_register_on_entry (struct scratch_reg *sr)
8094 : : {
8095 : 25 : int regno;
8096 : :
8097 : 25 : sr->saved = false;
8098 : :
8099 : 25 : if (TARGET_64BIT)
8100 : : {
8101 : : /* We always use R11 in 64-bit mode. */
8102 : : regno = R11_REG;
8103 : : }
8104 : : else
8105 : : {
8106 : 0 : tree decl = current_function_decl, fntype = TREE_TYPE (decl);
8107 : 0 : bool fastcall_p
8108 : 0 : = lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
8109 : 0 : bool thiscall_p
8110 : 0 : = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
8111 : 0 : bool static_chain_p = DECL_STATIC_CHAIN (decl);
8112 : 0 : int regparm = ix86_function_regparm (fntype, decl);
8113 : 0 : int drap_regno
8114 : 0 : = crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM;
8115 : :
8116 : : /* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax
8117 : : for the static chain register. */
8118 : 0 : if ((regparm < 1 || (fastcall_p && !static_chain_p))
8119 : 0 : && drap_regno != AX_REG)
8120 : : regno = AX_REG;
8121 : : /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
8122 : : for the static chain register. */
8123 : 0 : else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
8124 : : regno = AX_REG;
8125 : 0 : else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
8126 : : regno = DX_REG;
8127 : : /* ecx is the static chain register. */
8128 : 0 : else if (regparm < 3 && !fastcall_p && !thiscall_p
8129 : 0 : && !static_chain_p
8130 : 0 : && drap_regno != CX_REG)
8131 : : regno = CX_REG;
8132 : 0 : else if (ix86_save_reg (BX_REG, true, false))
8133 : : regno = BX_REG;
8134 : : /* esi is the static chain register. */
8135 : 0 : else if (!(regparm == 3 && static_chain_p)
8136 : 0 : && ix86_save_reg (SI_REG, true, false))
8137 : : regno = SI_REG;
8138 : 0 : else if (ix86_save_reg (DI_REG, true, false))
8139 : : regno = DI_REG;
8140 : : else
8141 : : {
8142 : 0 : regno = (drap_regno == AX_REG ? DX_REG : AX_REG);
8143 : 0 : sr->saved = true;
8144 : : }
8145 : : }
8146 : :
8147 : 25 : sr->reg = gen_rtx_REG (Pmode, regno);
8148 : 25 : if (sr->saved)
8149 : : {
8150 : 0 : rtx_insn *insn = emit_insn (gen_push (sr->reg));
8151 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
8152 : : }
8153 : 25 : }
8154 : :
8155 : : /* Release a scratch register obtained from the preceding function.
8156 : :
8157 : : If RELEASE_VIA_POP is true, we just pop the register off the stack
8158 : : to release it. This is what non-Linux systems use with -fstack-check.
8159 : :
8160 : : Otherwise we use OFFSET to locate the saved register and the
8161 : : allocated stack space becomes part of the local frame and is
8162 : : deallocated by the epilogue. */
8163 : :
8164 : : static void
8165 : 25 : release_scratch_register_on_entry (struct scratch_reg *sr, HOST_WIDE_INT offset,
8166 : : bool release_via_pop)
8167 : : {
8168 : 25 : if (sr->saved)
8169 : : {
8170 : 0 : if (release_via_pop)
8171 : : {
8172 : 0 : struct machine_function *m = cfun->machine;
8173 : 0 : rtx x, insn = emit_insn (gen_pop (sr->reg));
8174 : :
8175 : : /* The RX FRAME_RELATED_P mechanism doesn't know about pop. */
8176 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
8177 : 0 : x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
8178 : 0 : x = gen_rtx_SET (stack_pointer_rtx, x);
8179 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
8180 : 0 : m->fs.sp_offset -= UNITS_PER_WORD;
8181 : : }
8182 : : else
8183 : : {
8184 : 0 : rtx x = plus_constant (Pmode, stack_pointer_rtx, offset);
8185 : 0 : x = gen_rtx_SET (sr->reg, gen_rtx_MEM (word_mode, x));
8186 : 0 : emit_insn (x);
8187 : : }
8188 : : }
8189 : 25 : }
8190 : :
8191 : : /* Emit code to adjust the stack pointer by SIZE bytes while probing it.
8192 : :
8193 : : If INT_REGISTERS_SAVED is true, then integer registers have already been
8194 : : pushed on the stack.
8195 : :
8196 : : If PROTECTION AREA is true, then probe PROBE_INTERVAL plus a small dope
8197 : : beyond SIZE bytes.
8198 : :
8199 : : This assumes no knowledge of the current probing state, i.e. it is never
8200 : : allowed to allocate more than PROBE_INTERVAL bytes of stack space without
8201 : : a suitable probe. */
8202 : :
8203 : : static void
8204 : 126 : ix86_adjust_stack_and_probe (HOST_WIDE_INT size,
8205 : : const bool int_registers_saved,
8206 : : const bool protection_area)
8207 : : {
8208 : 126 : struct machine_function *m = cfun->machine;
8209 : :
8210 : : /* If this function does not statically allocate stack space, then
8211 : : no probes are needed. */
8212 : 126 : if (!size)
8213 : : {
8214 : : /* However, the allocation of space via pushes for register
8215 : : saves could be viewed as allocating space, but without the
8216 : : need to probe. */
8217 : 43 : if (m->frame.nregs || m->frame.nsseregs || frame_pointer_needed)
8218 : 23 : dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
8219 : : else
8220 : 20 : dump_stack_clash_frame_info (NO_PROBE_NO_FRAME, false);
8221 : 43 : return;
8222 : : }
8223 : :
8224 : : /* If we are a noreturn function, then we have to consider the
8225 : : possibility that we're called via a jump rather than a call.
8226 : :
8227 : : Thus we don't have the implicit probe generated by saving the
8228 : : return address into the stack at the call. Thus, the stack
8229 : : pointer could be anywhere in the guard page. The safe thing
8230 : : to do is emit a probe now.
8231 : :
8232 : : The probe can be avoided if we have already emitted any callee
8233 : : register saves into the stack or have a frame pointer (which will
8234 : : have been saved as well). Those saves will function as implicit
8235 : : probes.
8236 : :
8237 : : ?!? This should be revamped to work like aarch64 and s390 where
8238 : : we track the offset from the most recent probe. Normally that
8239 : : offset would be zero. For a noreturn function we would reset
8240 : : it to PROBE_INTERVAL - (STACK_BOUNDARY / BITS_PER_UNIT). Then
8241 : : we just probe when we cross PROBE_INTERVAL. */
8242 : 83 : if (TREE_THIS_VOLATILE (cfun->decl)
8243 : 15 : && !(m->frame.nregs || m->frame.nsseregs || frame_pointer_needed))
8244 : : {
8245 : : /* We can safely use any register here since we're just going to push
8246 : : its value and immediately pop it back. But we do try and avoid
8247 : : argument passing registers so as not to introduce dependencies in
8248 : : the pipeline. For 32 bit we use %esi and for 64 bit we use %rax. */
8249 : 15 : rtx dummy_reg = gen_rtx_REG (word_mode, TARGET_64BIT ? AX_REG : SI_REG);
8250 : 15 : rtx_insn *insn_push = emit_insn (gen_push (dummy_reg));
8251 : 15 : rtx_insn *insn_pop = emit_insn (gen_pop (dummy_reg));
8252 : 15 : m->fs.sp_offset -= UNITS_PER_WORD;
8253 : 15 : if (m->fs.cfa_reg == stack_pointer_rtx)
8254 : : {
8255 : 15 : m->fs.cfa_offset -= UNITS_PER_WORD;
8256 : 15 : rtx x = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
8257 : 15 : x = gen_rtx_SET (stack_pointer_rtx, x);
8258 : 15 : add_reg_note (insn_push, REG_CFA_ADJUST_CFA, x);
8259 : 15 : RTX_FRAME_RELATED_P (insn_push) = 1;
8260 : 15 : x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
8261 : 15 : x = gen_rtx_SET (stack_pointer_rtx, x);
8262 : 15 : add_reg_note (insn_pop, REG_CFA_ADJUST_CFA, x);
8263 : 15 : RTX_FRAME_RELATED_P (insn_pop) = 1;
8264 : : }
8265 : 15 : emit_insn (gen_blockage ());
8266 : : }
8267 : :
8268 : 83 : const HOST_WIDE_INT probe_interval = get_probe_interval ();
8269 : 83 : const int dope = 4 * UNITS_PER_WORD;
8270 : :
8271 : : /* If there is protection area, take it into account in the size. */
8272 : 83 : if (protection_area)
8273 : 25 : size += probe_interval + dope;
8274 : :
8275 : : /* If we allocate less than the size of the guard statically,
8276 : : then no probing is necessary, but we do need to allocate
8277 : : the stack. */
8278 : 58 : else if (size < (1 << param_stack_clash_protection_guard_size))
8279 : : {
8280 : 37 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8281 : : GEN_INT (-size), -1,
8282 : 37 : m->fs.cfa_reg == stack_pointer_rtx);
8283 : 37 : dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
8284 : 37 : return;
8285 : : }
8286 : :
8287 : : /* We're allocating a large enough stack frame that we need to
8288 : : emit probes. Either emit them inline or in a loop depending
8289 : : on the size. */
8290 : 46 : if (size <= 4 * probe_interval)
8291 : : {
8292 : : HOST_WIDE_INT i;
8293 : 49 : for (i = probe_interval; i <= size; i += probe_interval)
8294 : : {
8295 : : /* Allocate PROBE_INTERVAL bytes. */
8296 : 28 : rtx insn
8297 : 28 : = pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8298 : : GEN_INT (-probe_interval), -1,
8299 : 28 : m->fs.cfa_reg == stack_pointer_rtx);
8300 : 28 : add_reg_note (insn, REG_STACK_CHECK, const0_rtx);
8301 : :
8302 : : /* And probe at *sp. */
8303 : 28 : emit_stack_probe (stack_pointer_rtx);
8304 : 28 : emit_insn (gen_blockage ());
8305 : : }
8306 : :
8307 : : /* We need to allocate space for the residual, but we do not need
8308 : : to probe the residual... */
8309 : 21 : HOST_WIDE_INT residual = (i - probe_interval - size);
8310 : 21 : if (residual)
8311 : : {
8312 : 21 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8313 : : GEN_INT (residual), -1,
8314 : 21 : m->fs.cfa_reg == stack_pointer_rtx);
8315 : :
8316 : : /* ...except if there is a protection area to maintain. */
8317 : 21 : if (protection_area)
8318 : 12 : emit_stack_probe (stack_pointer_rtx);
8319 : : }
8320 : :
8321 : 21 : dump_stack_clash_frame_info (PROBE_INLINE, residual != 0);
8322 : : }
8323 : : else
8324 : : {
8325 : : /* We expect the GP registers to be saved when probes are used
8326 : : as the probing sequences might need a scratch register and
8327 : : the routine to allocate one assumes the integer registers
8328 : : have already been saved. */
8329 : 25 : gcc_assert (int_registers_saved);
8330 : :
8331 : 25 : struct scratch_reg sr;
8332 : 25 : get_scratch_register_on_entry (&sr);
8333 : :
8334 : : /* If we needed to save a register, then account for any space
8335 : : that was pushed (we are not going to pop the register when
8336 : : we do the restore). */
8337 : 25 : if (sr.saved)
8338 : 0 : size -= UNITS_PER_WORD;
8339 : :
8340 : : /* Step 1: round SIZE down to a multiple of the interval. */
8341 : 25 : HOST_WIDE_INT rounded_size = size & -probe_interval;
8342 : :
8343 : : /* Step 2: compute final value of the loop counter. Use lea if
8344 : : possible. */
8345 : 25 : rtx addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size);
8346 : 25 : rtx insn;
8347 : 25 : if (address_no_seg_operand (addr, Pmode))
8348 : 13 : insn = emit_insn (gen_rtx_SET (sr.reg, addr));
8349 : : else
8350 : : {
8351 : 12 : emit_move_insn (sr.reg, GEN_INT (-rounded_size));
8352 : 12 : insn = emit_insn (gen_rtx_SET (sr.reg,
8353 : : gen_rtx_PLUS (Pmode, sr.reg,
8354 : : stack_pointer_rtx)));
8355 : : }
8356 : 25 : if (m->fs.cfa_reg == stack_pointer_rtx)
8357 : : {
8358 : 22 : add_reg_note (insn, REG_CFA_DEF_CFA,
8359 : 22 : plus_constant (Pmode, sr.reg,
8360 : 22 : m->fs.cfa_offset + rounded_size));
8361 : 22 : RTX_FRAME_RELATED_P (insn) = 1;
8362 : : }
8363 : :
8364 : : /* Step 3: the loop. */
8365 : 25 : rtx size_rtx = GEN_INT (rounded_size);
8366 : 25 : insn = emit_insn (gen_adjust_stack_and_probe (Pmode, sr.reg, sr.reg,
8367 : : size_rtx));
8368 : 25 : if (m->fs.cfa_reg == stack_pointer_rtx)
8369 : : {
8370 : 22 : m->fs.cfa_offset += rounded_size;
8371 : 22 : add_reg_note (insn, REG_CFA_DEF_CFA,
8372 : 22 : plus_constant (Pmode, stack_pointer_rtx,
8373 : 22 : m->fs.cfa_offset));
8374 : 22 : RTX_FRAME_RELATED_P (insn) = 1;
8375 : : }
8376 : 25 : m->fs.sp_offset += rounded_size;
8377 : 25 : emit_insn (gen_blockage ());
8378 : :
8379 : : /* Step 4: adjust SP if we cannot assert at compile-time that SIZE
8380 : : is equal to ROUNDED_SIZE. */
8381 : :
8382 : 25 : if (size != rounded_size)
8383 : : {
8384 : 25 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8385 : : GEN_INT (rounded_size - size), -1,
8386 : 25 : m->fs.cfa_reg == stack_pointer_rtx);
8387 : :
8388 : 25 : if (protection_area)
8389 : 13 : emit_stack_probe (stack_pointer_rtx);
8390 : : }
8391 : :
8392 : 25 : dump_stack_clash_frame_info (PROBE_LOOP, size != rounded_size);
8393 : :
8394 : : /* This does not deallocate the space reserved for the scratch
8395 : : register. That will be deallocated in the epilogue. */
8396 : 25 : release_scratch_register_on_entry (&sr, size, false);
8397 : : }
8398 : :
8399 : : /* Adjust back to account for the protection area. */
8400 : 46 : if (protection_area)
8401 : 25 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8402 : 25 : GEN_INT (probe_interval + dope), -1,
8403 : 25 : m->fs.cfa_reg == stack_pointer_rtx);
8404 : :
8405 : : /* Make sure nothing is scheduled before we are done. */
8406 : 46 : emit_insn (gen_blockage ());
8407 : : }
8408 : :
8409 : : /* Adjust the stack pointer up to REG while probing it. */
8410 : :
8411 : : const char *
8412 : 25 : output_adjust_stack_and_probe (rtx reg)
8413 : : {
8414 : 25 : static int labelno = 0;
8415 : 25 : char loop_lab[32];
8416 : 25 : rtx xops[2];
8417 : :
8418 : 25 : ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
8419 : :
8420 : : /* Loop. */
8421 : 25 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
8422 : :
8423 : : /* SP = SP + PROBE_INTERVAL. */
8424 : 25 : xops[0] = stack_pointer_rtx;
8425 : 37 : xops[1] = GEN_INT (get_probe_interval ());
8426 : 25 : output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
8427 : :
8428 : : /* Probe at SP. */
8429 : 25 : xops[1] = const0_rtx;
8430 : 25 : output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops);
8431 : :
8432 : : /* Test if SP == LAST_ADDR. */
8433 : 25 : xops[0] = stack_pointer_rtx;
8434 : 25 : xops[1] = reg;
8435 : 25 : output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
8436 : :
8437 : : /* Branch. */
8438 : 25 : fputs ("\tjne\t", asm_out_file);
8439 : 25 : assemble_name_raw (asm_out_file, loop_lab);
8440 : 25 : fputc ('\n', asm_out_file);
8441 : :
8442 : 25 : return "";
8443 : : }
8444 : :
8445 : : /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
8446 : : inclusive. These are offsets from the current stack pointer.
8447 : :
8448 : : INT_REGISTERS_SAVED is true if integer registers have already been
8449 : : pushed on the stack. */
8450 : :
8451 : : static void
8452 : 0 : ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
8453 : : const bool int_registers_saved)
8454 : : {
8455 : 0 : const HOST_WIDE_INT probe_interval = get_probe_interval ();
8456 : :
8457 : : /* See if we have a constant small number of probes to generate. If so,
8458 : : that's the easy case. The run-time loop is made up of 6 insns in the
8459 : : generic case while the compile-time loop is made up of n insns for n #
8460 : : of intervals. */
8461 : 0 : if (size <= 6 * probe_interval)
8462 : : {
8463 : : HOST_WIDE_INT i;
8464 : :
8465 : : /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
8466 : : it exceeds SIZE. If only one probe is needed, this will not
8467 : : generate any code. Then probe at FIRST + SIZE. */
8468 : 0 : for (i = probe_interval; i < size; i += probe_interval)
8469 : 0 : emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
8470 : 0 : -(first + i)));
8471 : :
8472 : 0 : emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
8473 : 0 : -(first + size)));
8474 : : }
8475 : :
8476 : : /* Otherwise, do the same as above, but in a loop. Note that we must be
8477 : : extra careful with variables wrapping around because we might be at
8478 : : the very top (or the very bottom) of the address space and we have
8479 : : to be able to handle this case properly; in particular, we use an
8480 : : equality test for the loop condition. */
8481 : : else
8482 : : {
8483 : : /* We expect the GP registers to be saved when probes are used
8484 : : as the probing sequences might need a scratch register and
8485 : : the routine to allocate one assumes the integer registers
8486 : : have already been saved. */
8487 : 0 : gcc_assert (int_registers_saved);
8488 : :
8489 : 0 : HOST_WIDE_INT rounded_size, last;
8490 : 0 : struct scratch_reg sr;
8491 : :
8492 : 0 : get_scratch_register_on_entry (&sr);
8493 : :
8494 : :
8495 : : /* Step 1: round SIZE to the previous multiple of the interval. */
8496 : :
8497 : 0 : rounded_size = ROUND_DOWN (size, probe_interval);
8498 : :
8499 : :
8500 : : /* Step 2: compute initial and final value of the loop counter. */
8501 : :
8502 : : /* TEST_OFFSET = FIRST. */
8503 : 0 : emit_move_insn (sr.reg, GEN_INT (-first));
8504 : :
8505 : : /* LAST_OFFSET = FIRST + ROUNDED_SIZE. */
8506 : 0 : last = first + rounded_size;
8507 : :
8508 : :
8509 : : /* Step 3: the loop
8510 : :
8511 : : do
8512 : : {
8513 : : TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
8514 : : probe at TEST_ADDR
8515 : : }
8516 : : while (TEST_ADDR != LAST_ADDR)
8517 : :
8518 : : probes at FIRST + N * PROBE_INTERVAL for values of N from 1
8519 : : until it is equal to ROUNDED_SIZE. */
8520 : :
8521 : 0 : emit_insn
8522 : 0 : (gen_probe_stack_range (Pmode, sr.reg, sr.reg, GEN_INT (-last)));
8523 : :
8524 : :
8525 : : /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
8526 : : that SIZE is equal to ROUNDED_SIZE. */
8527 : :
8528 : 0 : if (size != rounded_size)
8529 : 0 : emit_stack_probe (plus_constant (Pmode,
8530 : 0 : gen_rtx_PLUS (Pmode,
8531 : : stack_pointer_rtx,
8532 : : sr.reg),
8533 : 0 : rounded_size - size));
8534 : :
8535 : 0 : release_scratch_register_on_entry (&sr, size, true);
8536 : : }
8537 : :
8538 : : /* Make sure nothing is scheduled before we are done. */
8539 : 0 : emit_insn (gen_blockage ());
8540 : 0 : }
8541 : :
8542 : : /* Probe a range of stack addresses from REG to END, inclusive. These are
8543 : : offsets from the current stack pointer. */
8544 : :
8545 : : const char *
8546 : 0 : output_probe_stack_range (rtx reg, rtx end)
8547 : : {
8548 : 0 : static int labelno = 0;
8549 : 0 : char loop_lab[32];
8550 : 0 : rtx xops[3];
8551 : :
8552 : 0 : ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
8553 : :
8554 : : /* Loop. */
8555 : 0 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
8556 : :
8557 : : /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
8558 : 0 : xops[0] = reg;
8559 : 0 : xops[1] = GEN_INT (get_probe_interval ());
8560 : 0 : output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
8561 : :
8562 : : /* Probe at TEST_ADDR. */
8563 : 0 : xops[0] = stack_pointer_rtx;
8564 : 0 : xops[1] = reg;
8565 : 0 : xops[2] = const0_rtx;
8566 : 0 : output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops);
8567 : :
8568 : : /* Test if TEST_ADDR == LAST_ADDR. */
8569 : 0 : xops[0] = reg;
8570 : 0 : xops[1] = end;
8571 : 0 : output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
8572 : :
8573 : : /* Branch. */
8574 : 0 : fputs ("\tjne\t", asm_out_file);
8575 : 0 : assemble_name_raw (asm_out_file, loop_lab);
8576 : 0 : fputc ('\n', asm_out_file);
8577 : :
8578 : 0 : return "";
8579 : : }
8580 : :
8581 : : /* Data passed to ix86_update_stack_alignment. */
8582 : : struct stack_access_data
8583 : : {
8584 : : /* The stack access register. */
8585 : : const_rtx reg;
8586 : : /* Pointer to stack alignment. */
8587 : : unsigned int *stack_alignment;
8588 : : };
8589 : :
8590 : : /* Update the maximum stack slot alignment from memory alignment in PAT. */
8591 : :
8592 : : static void
8593 : 53131990 : ix86_update_stack_alignment (rtx, const_rtx pat, void *data)
8594 : : {
8595 : : /* This insn may reference stack slot. Update the maximum stack slot
8596 : : alignment if the memory is referenced by the stack access register. */
8597 : 53131990 : stack_access_data *p = (stack_access_data *) data;
8598 : :
8599 : 53131990 : subrtx_iterator::array_type array;
8600 : 205643889 : FOR_EACH_SUBRTX (iter, array, pat, ALL)
8601 : : {
8602 : 174442879 : auto op = *iter;
8603 : 174442879 : if (MEM_P (op))
8604 : : {
8605 : 27438472 : if (reg_mentioned_p (p->reg, XEXP (op, 0)))
8606 : : {
8607 : 21930980 : unsigned int alignment = MEM_ALIGN (op);
8608 : :
8609 : 21930980 : if (alignment > *p->stack_alignment)
8610 : 57932 : *p->stack_alignment = alignment;
8611 : : break;
8612 : : }
8613 : : else
8614 : 5507492 : iter.skip_subrtxes ();
8615 : : }
8616 : : }
8617 : 53131990 : }
8618 : :
8619 : : /* Helper function for ix86_find_all_reg_uses. */
8620 : :
8621 : : static void
8622 : 44590348 : ix86_find_all_reg_uses_1 (HARD_REG_SET ®set,
8623 : : rtx set, unsigned int regno,
8624 : : auto_bitmap &worklist)
8625 : : {
8626 : 44590348 : rtx dest = SET_DEST (set);
8627 : :
8628 : 44590348 : if (!REG_P (dest))
8629 : 40328057 : return;
8630 : :
8631 : : /* Reject non-Pmode modes. */
8632 : 33863910 : if (GET_MODE (dest) != Pmode)
8633 : : return;
8634 : :
8635 : 17863199 : unsigned int dst_regno = REGNO (dest);
8636 : :
8637 : 17863199 : if (TEST_HARD_REG_BIT (regset, dst_regno))
8638 : : return;
8639 : :
8640 : 4262291 : const_rtx src = SET_SRC (set);
8641 : :
8642 : 4262291 : subrtx_iterator::array_type array;
8643 : 8474591 : FOR_EACH_SUBRTX (iter, array, src, ALL)
8644 : : {
8645 : 5509422 : auto op = *iter;
8646 : :
8647 : 5509422 : if (MEM_P (op))
8648 : 2952208 : iter.skip_subrtxes ();
8649 : :
8650 : 5509422 : if (REG_P (op) && REGNO (op) == regno)
8651 : : {
8652 : : /* Add this register to register set. */
8653 : 1465571 : add_to_hard_reg_set (®set, Pmode, dst_regno);
8654 : 1297122 : bitmap_set_bit (worklist, dst_regno);
8655 : 1297122 : break;
8656 : : }
8657 : : }
8658 : 4262291 : }
8659 : :
8660 : : /* Find all registers defined with register REGNO. */
8661 : :
8662 : : static void
8663 : 2304332 : ix86_find_all_reg_uses (HARD_REG_SET ®set,
8664 : : unsigned int regno, auto_bitmap &worklist)
8665 : : {
8666 : 2304332 : for (df_ref ref = DF_REG_USE_CHAIN (regno);
8667 : 79695711 : ref != NULL;
8668 : 77391379 : ref = DF_REF_NEXT_REG (ref))
8669 : : {
8670 : 77391379 : if (DF_REF_IS_ARTIFICIAL (ref))
8671 : 16445515 : continue;
8672 : :
8673 : 60945864 : rtx_insn *insn = DF_REF_INSN (ref);
8674 : :
8675 : 60945864 : if (!NONJUMP_INSN_P (insn))
8676 : 16947020 : continue;
8677 : :
8678 : 43998844 : unsigned int ref_regno = DF_REF_REGNO (ref);
8679 : :
8680 : 43998844 : rtx set = single_set (insn);
8681 : 43998844 : if (set)
8682 : : {
8683 : 43245814 : ix86_find_all_reg_uses_1 (regset, set,
8684 : : ref_regno, worklist);
8685 : 43245814 : continue;
8686 : : }
8687 : :
8688 : 753030 : rtx pat = PATTERN (insn);
8689 : 753030 : if (GET_CODE (pat) != PARALLEL)
8690 : 126901 : continue;
8691 : :
8692 : 2333784 : for (int i = 0; i < XVECLEN (pat, 0); i++)
8693 : : {
8694 : 1707655 : rtx exp = XVECEXP (pat, 0, i);
8695 : :
8696 : 1707655 : if (GET_CODE (exp) == SET)
8697 : 1344534 : ix86_find_all_reg_uses_1 (regset, exp,
8698 : : ref_regno, worklist);
8699 : : }
8700 : : }
8701 : 2304332 : }
8702 : :
8703 : : /* Set stack_frame_required to false if stack frame isn't required.
8704 : : Update STACK_ALIGNMENT to the largest alignment, in bits, of stack
8705 : : slot used if stack frame is required and CHECK_STACK_SLOT is true. */
8706 : :
8707 : : static void
8708 : 1455609 : ix86_find_max_used_stack_alignment (unsigned int &stack_alignment,
8709 : : bool check_stack_slot)
8710 : : {
8711 : 1455609 : HARD_REG_SET set_up_by_prologue, prologue_used;
8712 : 1455609 : basic_block bb;
8713 : :
8714 : 5822436 : CLEAR_HARD_REG_SET (prologue_used);
8715 : 1455609 : CLEAR_HARD_REG_SET (set_up_by_prologue);
8716 : 1581249 : add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM);
8717 : 1455609 : add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM);
8718 : 1455609 : add_to_hard_reg_set (&set_up_by_prologue, Pmode,
8719 : : HARD_FRAME_POINTER_REGNUM);
8720 : :
8721 : 1455609 : bool require_stack_frame = false;
8722 : :
8723 : 15653587 : FOR_EACH_BB_FN (bb, cfun)
8724 : : {
8725 : 14197978 : rtx_insn *insn;
8726 : 87386047 : FOR_BB_INSNS (bb, insn)
8727 : 81023364 : if (NONDEBUG_INSN_P (insn)
8728 : 81023364 : && requires_stack_frame_p (insn, prologue_used,
8729 : : set_up_by_prologue))
8730 : : {
8731 : : require_stack_frame = true;
8732 : : break;
8733 : : }
8734 : : }
8735 : :
8736 : 1455609 : cfun->machine->stack_frame_required = require_stack_frame;
8737 : :
8738 : : /* Stop if we don't need to check stack slot. */
8739 : 1455609 : if (!check_stack_slot)
8740 : 768532 : return;
8741 : :
8742 : : /* The preferred stack alignment is the minimum stack alignment. */
8743 : 687077 : if (stack_alignment > crtl->preferred_stack_boundary)
8744 : 142574 : stack_alignment = crtl->preferred_stack_boundary;
8745 : :
8746 : : HARD_REG_SET stack_slot_access;
8747 : 687077 : CLEAR_HARD_REG_SET (stack_slot_access);
8748 : :
8749 : : /* Stack slot can be accessed by stack pointer, frame pointer or
8750 : : registers defined by stack pointer or frame pointer. */
8751 : 687077 : auto_bitmap worklist;
8752 : :
8753 : 747050 : add_to_hard_reg_set (&stack_slot_access, Pmode, STACK_POINTER_REGNUM);
8754 : 687077 : bitmap_set_bit (worklist, STACK_POINTER_REGNUM);
8755 : :
8756 : 687077 : if (frame_pointer_needed)
8757 : : {
8758 : 329162 : add_to_hard_reg_set (&stack_slot_access, Pmode,
8759 : : HARD_FRAME_POINTER_REGNUM);
8760 : 320133 : bitmap_set_bit (worklist, HARD_FRAME_POINTER_REGNUM);
8761 : : }
8762 : :
8763 : 2304332 : unsigned int regno;
8764 : :
8765 : 2304332 : do
8766 : : {
8767 : 2304332 : regno = bitmap_clear_first_set_bit (worklist);
8768 : 2304332 : ix86_find_all_reg_uses (stack_slot_access, regno, worklist);
8769 : : }
8770 : 2304332 : while (!bitmap_empty_p (worklist));
8771 : :
8772 : 687077 : hard_reg_set_iterator hrsi;
8773 : 687077 : stack_access_data data;
8774 : :
8775 : 687077 : data.stack_alignment = &stack_alignment;
8776 : :
8777 : 2991409 : EXECUTE_IF_SET_IN_HARD_REG_SET (stack_slot_access, 0, regno, hrsi)
8778 : 2304332 : for (df_ref ref = DF_REG_USE_CHAIN (regno);
8779 : 79695711 : ref != NULL;
8780 : 77391379 : ref = DF_REF_NEXT_REG (ref))
8781 : : {
8782 : 77391379 : if (DF_REF_IS_ARTIFICIAL (ref))
8783 : 16445515 : continue;
8784 : :
8785 : 60945864 : rtx_insn *insn = DF_REF_INSN (ref);
8786 : :
8787 : 60945864 : if (!NONJUMP_INSN_P (insn))
8788 : 16947020 : continue;
8789 : :
8790 : 43998844 : data.reg = DF_REF_REG (ref);
8791 : 43998844 : note_stores (insn, ix86_update_stack_alignment, &data);
8792 : : }
8793 : 687077 : }
8794 : :
8795 : : /* Finalize stack_realign_needed and frame_pointer_needed flags, which
8796 : : will guide prologue/epilogue to be generated in correct form. */
8797 : :
8798 : : static void
8799 : 3383026 : ix86_finalize_stack_frame_flags (void)
8800 : : {
8801 : : /* Check if stack realign is really needed after reload, and
8802 : : stores result in cfun */
8803 : 3383026 : unsigned int incoming_stack_boundary
8804 : 3383026 : = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
8805 : 3383026 : ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
8806 : 3383026 : unsigned int stack_alignment
8807 : 1147110 : = (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
8808 : 4530136 : ? crtl->max_used_stack_slot_alignment
8809 : 3383026 : : crtl->stack_alignment_needed);
8810 : 3383026 : unsigned int stack_realign
8811 : 3383026 : = (incoming_stack_boundary < stack_alignment);
8812 : 3383026 : bool recompute_frame_layout_p = false;
8813 : :
8814 : 3383026 : if (crtl->stack_realign_finalized)
8815 : : {
8816 : : /* After stack_realign_needed is finalized, we can't no longer
8817 : : change it. */
8818 : 1927417 : gcc_assert (crtl->stack_realign_needed == stack_realign);
8819 : 1927417 : return;
8820 : : }
8821 : :
8822 : : /* It is always safe to compute max_used_stack_alignment. We
8823 : : compute it only if 128-bit aligned load/store may be generated
8824 : : on misaligned stack slot which will lead to segfault. */
8825 : 2911218 : bool check_stack_slot
8826 : 1455609 : = (stack_realign || crtl->max_used_stack_slot_alignment >= 128);
8827 : 1455609 : ix86_find_max_used_stack_alignment (stack_alignment,
8828 : : check_stack_slot);
8829 : :
8830 : : /* If the only reason for frame_pointer_needed is that we conservatively
8831 : : assumed stack realignment might be needed or -fno-omit-frame-pointer
8832 : : is used, but in the end nothing that needed the stack alignment had
8833 : : been spilled nor stack access, clear frame_pointer_needed and say we
8834 : : don't need stack realignment.
8835 : :
8836 : : When vector register is used for piecewise move and store, we don't
8837 : : increase stack_alignment_needed as there is no register spill for
8838 : : piecewise move and store. Since stack_realign_needed is set to true
8839 : : by checking stack_alignment_estimated which is updated by pseudo
8840 : : vector register usage, we also need to check stack_realign_needed to
8841 : : eliminate frame pointer. */
8842 : 1455609 : if ((stack_realign
8843 : 1390980 : || (!flag_omit_frame_pointer && optimize)
8844 : 1380747 : || crtl->stack_realign_needed)
8845 : 75447 : && frame_pointer_needed
8846 : 75447 : && crtl->is_leaf
8847 : 51110 : && crtl->sp_is_unchanging
8848 : 51058 : && !ix86_current_function_calls_tls_descriptor
8849 : 51058 : && !crtl->accesses_prior_frames
8850 : 51058 : && !cfun->calls_alloca
8851 : 51058 : && !crtl->calls_eh_return
8852 : : /* See ira_setup_eliminable_regset for the rationale. */
8853 : 51058 : && !(STACK_CHECK_MOVING_SP
8854 : 51058 : && flag_stack_check
8855 : 0 : && flag_exceptions
8856 : 0 : && cfun->can_throw_non_call_exceptions)
8857 : 51058 : && !ix86_frame_pointer_required ()
8858 : 51057 : && ix86_get_frame_size () == 0
8859 : 33630 : && ix86_nsaved_sseregs () == 0
8860 : 1489239 : && ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0)
8861 : : {
8862 : 33630 : if (cfun->machine->stack_frame_required)
8863 : : {
8864 : : /* Stack frame is required. If stack alignment needed is less
8865 : : than incoming stack boundary, don't realign stack. */
8866 : 237 : stack_realign = incoming_stack_boundary < stack_alignment;
8867 : 237 : if (!stack_realign)
8868 : : {
8869 : 237 : crtl->max_used_stack_slot_alignment
8870 : 237 : = incoming_stack_boundary;
8871 : 237 : crtl->stack_alignment_needed
8872 : 237 : = incoming_stack_boundary;
8873 : : /* Also update preferred_stack_boundary for leaf
8874 : : functions. */
8875 : 237 : crtl->preferred_stack_boundary
8876 : 237 : = incoming_stack_boundary;
8877 : : }
8878 : : }
8879 : : else
8880 : : {
8881 : : /* If drap has been set, but it actually isn't live at the
8882 : : start of the function, there is no reason to set it up. */
8883 : 33393 : if (crtl->drap_reg)
8884 : : {
8885 : 32 : basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
8886 : 64 : if (! REGNO_REG_SET_P (DF_LR_IN (bb),
8887 : : REGNO (crtl->drap_reg)))
8888 : : {
8889 : 32 : crtl->drap_reg = NULL_RTX;
8890 : 32 : crtl->need_drap = false;
8891 : : }
8892 : : }
8893 : : else
8894 : 33361 : cfun->machine->no_drap_save_restore = true;
8895 : :
8896 : 33393 : frame_pointer_needed = false;
8897 : 33393 : stack_realign = false;
8898 : 33393 : crtl->max_used_stack_slot_alignment = incoming_stack_boundary;
8899 : 33393 : crtl->stack_alignment_needed = incoming_stack_boundary;
8900 : 33393 : crtl->stack_alignment_estimated = incoming_stack_boundary;
8901 : 33393 : if (crtl->preferred_stack_boundary > incoming_stack_boundary)
8902 : 1 : crtl->preferred_stack_boundary = incoming_stack_boundary;
8903 : 33393 : df_finish_pass (true);
8904 : 33393 : df_scan_alloc (NULL);
8905 : 33393 : df_scan_blocks ();
8906 : 33393 : df_compute_regs_ever_live (true);
8907 : 33393 : df_analyze ();
8908 : :
8909 : 33393 : if (flag_var_tracking)
8910 : : {
8911 : : /* Since frame pointer is no longer available, replace it with
8912 : : stack pointer - UNITS_PER_WORD in debug insns. */
8913 : 130 : df_ref ref, next;
8914 : 130 : for (ref = DF_REG_USE_CHAIN (HARD_FRAME_POINTER_REGNUM);
8915 : 130 : ref; ref = next)
8916 : : {
8917 : 0 : next = DF_REF_NEXT_REG (ref);
8918 : 0 : if (!DF_REF_INSN_INFO (ref))
8919 : 0 : continue;
8920 : :
8921 : : /* Make sure the next ref is for a different instruction,
8922 : : so that we're not affected by the rescan. */
8923 : 0 : rtx_insn *insn = DF_REF_INSN (ref);
8924 : 0 : while (next && DF_REF_INSN (next) == insn)
8925 : 0 : next = DF_REF_NEXT_REG (next);
8926 : :
8927 : 0 : if (DEBUG_INSN_P (insn))
8928 : : {
8929 : : bool changed = false;
8930 : 0 : for (; ref != next; ref = DF_REF_NEXT_REG (ref))
8931 : : {
8932 : 0 : rtx *loc = DF_REF_LOC (ref);
8933 : 0 : if (*loc == hard_frame_pointer_rtx)
8934 : : {
8935 : 0 : *loc = plus_constant (Pmode,
8936 : : stack_pointer_rtx,
8937 : 0 : -UNITS_PER_WORD);
8938 : 0 : changed = true;
8939 : : }
8940 : : }
8941 : 0 : if (changed)
8942 : 0 : df_insn_rescan (insn);
8943 : : }
8944 : : }
8945 : : }
8946 : :
8947 : : recompute_frame_layout_p = true;
8948 : : }
8949 : : }
8950 : 1421979 : else if (crtl->max_used_stack_slot_alignment >= 128
8951 : 652372 : && cfun->machine->stack_frame_required)
8952 : : {
8953 : : /* We don't need to realign stack. max_used_stack_alignment is
8954 : : used to decide how stack frame should be aligned. This is
8955 : : independent of any psABIs nor 32-bit vs 64-bit. */
8956 : 608595 : cfun->machine->max_used_stack_alignment
8957 : 608595 : = stack_alignment / BITS_PER_UNIT;
8958 : : }
8959 : :
8960 : 1455609 : if (crtl->stack_realign_needed != stack_realign)
8961 : 33851 : recompute_frame_layout_p = true;
8962 : 1455609 : crtl->stack_realign_needed = stack_realign;
8963 : 1455609 : crtl->stack_realign_finalized = true;
8964 : 1455609 : if (recompute_frame_layout_p)
8965 : 33929 : ix86_compute_frame_layout ();
8966 : : }
8967 : :
8968 : : /* Delete SET_GOT right after entry block if it is allocated to reg. */
8969 : :
8970 : : static void
8971 : 0 : ix86_elim_entry_set_got (rtx reg)
8972 : : {
8973 : 0 : basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
8974 : 0 : rtx_insn *c_insn = BB_HEAD (bb);
8975 : 0 : if (!NONDEBUG_INSN_P (c_insn))
8976 : 0 : c_insn = next_nonnote_nondebug_insn (c_insn);
8977 : 0 : if (c_insn && NONJUMP_INSN_P (c_insn))
8978 : : {
8979 : 0 : rtx pat = PATTERN (c_insn);
8980 : 0 : if (GET_CODE (pat) == PARALLEL)
8981 : : {
8982 : 0 : rtx set = XVECEXP (pat, 0, 0);
8983 : 0 : if (GET_CODE (set) == SET
8984 : 0 : && GET_CODE (SET_SRC (set)) == UNSPEC
8985 : 0 : && XINT (SET_SRC (set), 1) == UNSPEC_SET_GOT
8986 : 0 : && REGNO (SET_DEST (set)) == REGNO (reg))
8987 : 0 : delete_insn (c_insn);
8988 : : }
8989 : : }
8990 : 0 : }
8991 : :
8992 : : static rtx
8993 : 193166 : gen_frame_set (rtx reg, rtx frame_reg, int offset, bool store)
8994 : : {
8995 : 193166 : rtx addr, mem;
8996 : :
8997 : 193166 : if (offset)
8998 : 184480 : addr = plus_constant (Pmode, frame_reg, offset);
8999 : 193166 : mem = gen_frame_mem (GET_MODE (reg), offset ? addr : frame_reg);
9000 : 193166 : return gen_rtx_SET (store ? mem : reg, store ? reg : mem);
9001 : : }
9002 : :
9003 : : static inline rtx
9004 : 100333 : gen_frame_load (rtx reg, rtx frame_reg, int offset)
9005 : : {
9006 : 100333 : return gen_frame_set (reg, frame_reg, offset, false);
9007 : : }
9008 : :
9009 : : static inline rtx
9010 : 92833 : gen_frame_store (rtx reg, rtx frame_reg, int offset)
9011 : : {
9012 : 92833 : return gen_frame_set (reg, frame_reg, offset, true);
9013 : : }
9014 : :
9015 : : static void
9016 : 7045 : ix86_emit_outlined_ms2sysv_save (const struct ix86_frame &frame)
9017 : : {
9018 : 7045 : struct machine_function *m = cfun->machine;
9019 : 7045 : const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS
9020 : 7045 : + m->call_ms2sysv_extra_regs;
9021 : 7045 : rtvec v = rtvec_alloc (ncregs + 1);
9022 : 7045 : unsigned int align, i, vi = 0;
9023 : 7045 : rtx_insn *insn;
9024 : 7045 : rtx sym, addr;
9025 : 7045 : rtx rax = gen_rtx_REG (word_mode, AX_REG);
9026 : 7045 : const class xlogue_layout &xlogue = xlogue_layout::get_instance ();
9027 : :
9028 : : /* AL should only be live with sysv_abi. */
9029 : 7045 : gcc_assert (!ix86_eax_live_at_start_p ());
9030 : 7045 : gcc_assert (m->fs.sp_offset >= frame.sse_reg_save_offset);
9031 : :
9032 : : /* Setup RAX as the stub's base pointer. We use stack_realign_offset rather
9033 : : we've actually realigned the stack or not. */
9034 : 7045 : align = GET_MODE_ALIGNMENT (V4SFmode);
9035 : 7045 : addr = choose_baseaddr (frame.stack_realign_offset
9036 : 7045 : + xlogue.get_stub_ptr_offset (), &align, AX_REG);
9037 : 7045 : gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode));
9038 : :
9039 : 7045 : emit_insn (gen_rtx_SET (rax, addr));
9040 : :
9041 : : /* Get the stub symbol. */
9042 : 8327 : sym = xlogue.get_stub_rtx (frame_pointer_needed ? XLOGUE_STUB_SAVE_HFP
9043 : : : XLOGUE_STUB_SAVE);
9044 : 7045 : RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
9045 : :
9046 : 99878 : for (i = 0; i < ncregs; ++i)
9047 : : {
9048 : 92833 : const xlogue_layout::reginfo &r = xlogue.get_reginfo (i);
9049 : 92833 : rtx reg = gen_rtx_REG ((SSE_REGNO_P (r.regno) ? V4SFmode : word_mode),
9050 : 92833 : r.regno);
9051 : 92833 : RTVEC_ELT (v, vi++) = gen_frame_store (reg, rax, -r.offset);
9052 : : }
9053 : :
9054 : 7045 : gcc_assert (vi == (unsigned)GET_NUM_ELEM (v));
9055 : :
9056 : 7045 : insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, v));
9057 : 7045 : RTX_FRAME_RELATED_P (insn) = true;
9058 : 7045 : }
9059 : :
9060 : : /* Generate and return an insn body to AND X with Y. */
9061 : :
9062 : : static rtx_insn *
9063 : 31363 : gen_and2_insn (rtx x, rtx y)
9064 : : {
9065 : 31363 : enum insn_code icode = optab_handler (and_optab, GET_MODE (x));
9066 : :
9067 : 31363 : gcc_assert (insn_operand_matches (icode, 0, x));
9068 : 31363 : gcc_assert (insn_operand_matches (icode, 1, x));
9069 : 31363 : gcc_assert (insn_operand_matches (icode, 2, y));
9070 : :
9071 : 31363 : return GEN_FCN (icode) (x, x, y);
9072 : : }
9073 : :
9074 : : /* Expand the prologue into a bunch of separate insns. */
9075 : :
9076 : : void
9077 : 1501583 : ix86_expand_prologue (void)
9078 : : {
9079 : 1501583 : struct machine_function *m = cfun->machine;
9080 : 1501583 : rtx insn, t;
9081 : 1501583 : HOST_WIDE_INT allocate;
9082 : 1501583 : bool int_registers_saved;
9083 : 1501583 : bool sse_registers_saved;
9084 : 1501583 : bool save_stub_call_needed;
9085 : 1501583 : rtx static_chain = NULL_RTX;
9086 : :
9087 : 1501583 : ix86_last_zero_store_uid = 0;
9088 : 1501583 : if (ix86_function_naked (current_function_decl))
9089 : : {
9090 : 74 : if (flag_stack_usage_info)
9091 : 0 : current_function_static_stack_size = 0;
9092 : 74 : return;
9093 : : }
9094 : :
9095 : 1501509 : ix86_finalize_stack_frame_flags ();
9096 : :
9097 : : /* DRAP should not coexist with stack_realign_fp */
9098 : 1501509 : gcc_assert (!(crtl->drap_reg && stack_realign_fp));
9099 : :
9100 : 1501509 : memset (&m->fs, 0, sizeof (m->fs));
9101 : :
9102 : : /* Initialize CFA state for before the prologue. */
9103 : 1501509 : m->fs.cfa_reg = stack_pointer_rtx;
9104 : 1501509 : m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET;
9105 : :
9106 : : /* Track SP offset to the CFA. We continue tracking this after we've
9107 : : swapped the CFA register away from SP. In the case of re-alignment
9108 : : this is fudged; we're interested to offsets within the local frame. */
9109 : 1501509 : m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
9110 : 1501509 : m->fs.sp_valid = true;
9111 : 1501509 : m->fs.sp_realigned = false;
9112 : :
9113 : 1501509 : const struct ix86_frame &frame = cfun->machine->frame;
9114 : :
9115 : 1501509 : if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
9116 : : {
9117 : : /* We should have already generated an error for any use of
9118 : : ms_hook on a nested function. */
9119 : 0 : gcc_checking_assert (!ix86_static_chain_on_stack);
9120 : :
9121 : : /* Check if profiling is active and we shall use profiling before
9122 : : prologue variant. If so sorry. */
9123 : 0 : if (crtl->profile && flag_fentry != 0)
9124 : 0 : sorry ("%<ms_hook_prologue%> attribute is not compatible "
9125 : : "with %<-mfentry%> for 32-bit");
9126 : :
9127 : : /* In ix86_asm_output_function_label we emitted:
9128 : : 8b ff movl.s %edi,%edi
9129 : : 55 push %ebp
9130 : : 8b ec movl.s %esp,%ebp
9131 : :
9132 : : This matches the hookable function prologue in Win32 API
9133 : : functions in Microsoft Windows XP Service Pack 2 and newer.
9134 : : Wine uses this to enable Windows apps to hook the Win32 API
9135 : : functions provided by Wine.
9136 : :
9137 : : What that means is that we've already set up the frame pointer. */
9138 : :
9139 : 0 : if (frame_pointer_needed
9140 : 0 : && !(crtl->drap_reg && crtl->stack_realign_needed))
9141 : : {
9142 : 0 : rtx push, mov;
9143 : :
9144 : : /* We've decided to use the frame pointer already set up.
9145 : : Describe this to the unwinder by pretending that both
9146 : : push and mov insns happen right here.
9147 : :
9148 : : Putting the unwind info here at the end of the ms_hook
9149 : : is done so that we can make absolutely certain we get
9150 : : the required byte sequence at the start of the function,
9151 : : rather than relying on an assembler that can produce
9152 : : the exact encoding required.
9153 : :
9154 : : However it does mean (in the unpatched case) that we have
9155 : : a 1 insn window where the asynchronous unwind info is
9156 : : incorrect. However, if we placed the unwind info at
9157 : : its correct location we would have incorrect unwind info
9158 : : in the patched case. Which is probably all moot since
9159 : : I don't expect Wine generates dwarf2 unwind info for the
9160 : : system libraries that use this feature. */
9161 : :
9162 : 0 : insn = emit_insn (gen_blockage ());
9163 : :
9164 : 0 : push = gen_push (hard_frame_pointer_rtx);
9165 : 0 : mov = gen_rtx_SET (hard_frame_pointer_rtx,
9166 : : stack_pointer_rtx);
9167 : 0 : RTX_FRAME_RELATED_P (push) = 1;
9168 : 0 : RTX_FRAME_RELATED_P (mov) = 1;
9169 : :
9170 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9171 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9172 : : gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov)));
9173 : :
9174 : : /* Note that gen_push incremented m->fs.cfa_offset, even
9175 : : though we didn't emit the push insn here. */
9176 : 0 : m->fs.cfa_reg = hard_frame_pointer_rtx;
9177 : 0 : m->fs.fp_offset = m->fs.cfa_offset;
9178 : 0 : m->fs.fp_valid = true;
9179 : 0 : }
9180 : : else
9181 : : {
9182 : : /* The frame pointer is not needed so pop %ebp again.
9183 : : This leaves us with a pristine state. */
9184 : 0 : emit_insn (gen_pop (hard_frame_pointer_rtx));
9185 : : }
9186 : : }
9187 : :
9188 : : /* The first insn of a function that accepts its static chain on the
9189 : : stack is to push the register that would be filled in by a direct
9190 : : call. This insn will be skipped by the trampoline. */
9191 : 1501509 : else if (ix86_static_chain_on_stack)
9192 : : {
9193 : 0 : static_chain = ix86_static_chain (cfun->decl, false);
9194 : 0 : insn = emit_insn (gen_push (static_chain));
9195 : 0 : emit_insn (gen_blockage ());
9196 : :
9197 : : /* We don't want to interpret this push insn as a register save,
9198 : : only as a stack adjustment. The real copy of the register as
9199 : : a save will be done later, if needed. */
9200 : 0 : t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
9201 : 0 : t = gen_rtx_SET (stack_pointer_rtx, t);
9202 : 0 : add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
9203 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9204 : : }
9205 : :
9206 : : /* Emit prologue code to adjust stack alignment and setup DRAP, in case
9207 : : of DRAP is needed and stack realignment is really needed after reload */
9208 : 1501509 : if (stack_realign_drap)
9209 : : {
9210 : 6916 : int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
9211 : :
9212 : : /* Can't use DRAP in interrupt function. */
9213 : 6916 : if (cfun->machine->func_type != TYPE_NORMAL)
9214 : 0 : sorry ("Dynamic Realign Argument Pointer (DRAP) not supported "
9215 : : "in interrupt service routine. This may be worked "
9216 : : "around by avoiding functions with aggregate return.");
9217 : :
9218 : : /* Only need to push parameter pointer reg if it is caller saved. */
9219 : 6916 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
9220 : : {
9221 : : /* Push arg pointer reg */
9222 : 136 : insn = emit_insn (gen_push (crtl->drap_reg));
9223 : 136 : RTX_FRAME_RELATED_P (insn) = 1;
9224 : : }
9225 : :
9226 : : /* Grab the argument pointer. */
9227 : 7197 : t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
9228 : 6916 : insn = emit_insn (gen_rtx_SET (crtl->drap_reg, t));
9229 : 6916 : RTX_FRAME_RELATED_P (insn) = 1;
9230 : 6916 : m->fs.cfa_reg = crtl->drap_reg;
9231 : 6916 : m->fs.cfa_offset = 0;
9232 : :
9233 : : /* Align the stack. */
9234 : 6916 : insn = emit_insn (gen_and2_insn (stack_pointer_rtx,
9235 : 6916 : GEN_INT (-align_bytes)));
9236 : 6916 : RTX_FRAME_RELATED_P (insn) = 1;
9237 : :
9238 : : /* Replicate the return address on the stack so that return
9239 : : address can be reached via (argp - 1) slot. This is needed
9240 : : to implement macro RETURN_ADDR_RTX and intrinsic function
9241 : : expand_builtin_return_addr etc. */
9242 : 7478 : t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
9243 : 6916 : t = gen_frame_mem (word_mode, t);
9244 : 6916 : insn = emit_insn (gen_push (t));
9245 : 6916 : RTX_FRAME_RELATED_P (insn) = 1;
9246 : :
9247 : : /* For the purposes of frame and register save area addressing,
9248 : : we've started over with a new frame. */
9249 : 6916 : m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
9250 : 6916 : m->fs.realigned = true;
9251 : :
9252 : 6916 : if (static_chain)
9253 : : {
9254 : : /* Replicate static chain on the stack so that static chain
9255 : : can be reached via (argp - 2) slot. This is needed for
9256 : : nested function with stack realignment. */
9257 : 0 : insn = emit_insn (gen_push (static_chain));
9258 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9259 : : }
9260 : : }
9261 : :
9262 : 1501509 : int_registers_saved = (frame.nregs == 0);
9263 : 1501509 : sse_registers_saved = (frame.nsseregs == 0);
9264 : 1501509 : save_stub_call_needed = (m->call_ms2sysv);
9265 : 1501509 : gcc_assert (sse_registers_saved || !save_stub_call_needed);
9266 : :
9267 : 1501509 : if (frame_pointer_needed && !m->fs.fp_valid)
9268 : : {
9269 : : /* Note: AT&T enter does NOT have reversed args. Enter is probably
9270 : : slower on all targets. Also sdb didn't like it. */
9271 : 476389 : insn = emit_insn (gen_push (hard_frame_pointer_rtx));
9272 : 476389 : RTX_FRAME_RELATED_P (insn) = 1;
9273 : :
9274 : 476389 : if (m->fs.sp_offset == frame.hard_frame_pointer_offset)
9275 : : {
9276 : 476389 : insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
9277 : 476389 : RTX_FRAME_RELATED_P (insn) = 1;
9278 : :
9279 : 476389 : if (m->fs.cfa_reg == stack_pointer_rtx)
9280 : 469473 : m->fs.cfa_reg = hard_frame_pointer_rtx;
9281 : 476389 : m->fs.fp_offset = m->fs.sp_offset;
9282 : 476389 : m->fs.fp_valid = true;
9283 : : }
9284 : : }
9285 : :
9286 : 1501509 : if (!int_registers_saved)
9287 : : {
9288 : : /* If saving registers via PUSH, do so now. */
9289 : 471443 : if (!frame.save_regs_using_mov)
9290 : : {
9291 : 425486 : ix86_emit_save_regs ();
9292 : 425486 : m->fs.apx_ppx_used = TARGET_APX_PPX && !crtl->calls_eh_return;
9293 : 425486 : int_registers_saved = true;
9294 : 425486 : gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
9295 : : }
9296 : :
9297 : : /* When using red zone we may start register saving before allocating
9298 : : the stack frame saving one cycle of the prologue. However, avoid
9299 : : doing this if we have to probe the stack; at least on x86_64 the
9300 : : stack probe can turn into a call that clobbers a red zone location. */
9301 : 45957 : else if (ix86_using_red_zone ()
9302 : 45957 : && (! TARGET_STACK_PROBE
9303 : 0 : || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
9304 : : {
9305 : 41770 : HOST_WIDE_INT allocate_offset;
9306 : 41770 : if (crtl->shrink_wrapped_separate)
9307 : : {
9308 : 41718 : allocate_offset = m->fs.sp_offset - frame.stack_pointer_offset;
9309 : :
9310 : : /* Adjust the total offset at the beginning of the function. */
9311 : 41718 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9312 : : GEN_INT (allocate_offset), -1,
9313 : 41718 : m->fs.cfa_reg == stack_pointer_rtx);
9314 : 41718 : m->fs.sp_offset = cfun->machine->frame.stack_pointer_offset;
9315 : : }
9316 : :
9317 : 41770 : ix86_emit_save_regs_using_mov (frame.reg_save_offset);
9318 : 41770 : int_registers_saved = true;
9319 : : }
9320 : : }
9321 : :
9322 : 1501509 : if (frame.red_zone_size != 0)
9323 : 140614 : cfun->machine->red_zone_used = true;
9324 : :
9325 : 1501509 : if (stack_realign_fp)
9326 : : {
9327 : 24447 : int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
9328 : 24797 : gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
9329 : :
9330 : : /* Record last valid frame pointer offset. */
9331 : 24447 : m->fs.sp_realigned_fp_last = frame.reg_save_offset;
9332 : :
9333 : : /* The computation of the size of the re-aligned stack frame means
9334 : : that we must allocate the size of the register save area before
9335 : : performing the actual alignment. Otherwise we cannot guarantee
9336 : : that there's enough storage above the realignment point. */
9337 : 24447 : allocate = frame.reg_save_offset - m->fs.sp_offset
9338 : 24447 : + frame.stack_realign_allocate;
9339 : 24447 : if (allocate)
9340 : 2691 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9341 : : GEN_INT (-allocate), -1, false);
9342 : :
9343 : : /* Align the stack. */
9344 : 24447 : emit_insn (gen_and2_insn (stack_pointer_rtx, GEN_INT (-align_bytes)));
9345 : 24447 : m->fs.sp_offset = ROUND_UP (m->fs.sp_offset, align_bytes);
9346 : 24447 : m->fs.sp_realigned_offset = m->fs.sp_offset
9347 : 24447 : - frame.stack_realign_allocate;
9348 : : /* The stack pointer may no longer be equal to CFA - m->fs.sp_offset.
9349 : : Beyond this point, stack access should be done via choose_baseaddr or
9350 : : by using sp_valid_at and fp_valid_at to determine the correct base
9351 : : register. Henceforth, any CFA offset should be thought of as logical
9352 : : and not physical. */
9353 : 24447 : gcc_assert (m->fs.sp_realigned_offset >= m->fs.sp_realigned_fp_last);
9354 : 24447 : gcc_assert (m->fs.sp_realigned_offset == frame.stack_realign_offset);
9355 : 24447 : m->fs.sp_realigned = true;
9356 : :
9357 : : /* SEH unwind emit doesn't currently support REG_CFA_EXPRESSION, which
9358 : : is needed to describe where a register is saved using a realigned
9359 : : stack pointer, so we need to invalidate the stack pointer for that
9360 : : target. */
9361 : 24447 : if (TARGET_SEH)
9362 : : m->fs.sp_valid = false;
9363 : :
9364 : : /* If SP offset is non-immediate after allocation of the stack frame,
9365 : : then emit SSE saves or stub call prior to allocating the rest of the
9366 : : stack frame. This is less efficient for the out-of-line stub because
9367 : : we can't combine allocations across the call barrier, but it's better
9368 : : than using a scratch register. */
9369 : 24447 : else if (!x86_64_immediate_operand (GEN_INT (frame.stack_pointer_offset
9370 : : - m->fs.sp_realigned_offset),
9371 : 24447 : Pmode))
9372 : : {
9373 : 3 : if (!sse_registers_saved)
9374 : : {
9375 : 1 : ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
9376 : 1 : sse_registers_saved = true;
9377 : : }
9378 : 2 : else if (save_stub_call_needed)
9379 : : {
9380 : 1 : ix86_emit_outlined_ms2sysv_save (frame);
9381 : 1 : save_stub_call_needed = false;
9382 : : }
9383 : : }
9384 : : }
9385 : :
9386 : 1501509 : allocate = frame.stack_pointer_offset - m->fs.sp_offset;
9387 : :
9388 : 1501509 : if (flag_stack_usage_info)
9389 : : {
9390 : : /* We start to count from ARG_POINTER. */
9391 : 355 : HOST_WIDE_INT stack_size = frame.stack_pointer_offset;
9392 : :
9393 : : /* If it was realigned, take into account the fake frame. */
9394 : 355 : if (stack_realign_drap)
9395 : : {
9396 : 1 : if (ix86_static_chain_on_stack)
9397 : 0 : stack_size += UNITS_PER_WORD;
9398 : :
9399 : 1 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
9400 : 0 : stack_size += UNITS_PER_WORD;
9401 : :
9402 : : /* This over-estimates by 1 minimal-stack-alignment-unit but
9403 : : mitigates that by counting in the new return address slot. */
9404 : 1 : current_function_dynamic_stack_size
9405 : 1 : += crtl->stack_alignment_needed / BITS_PER_UNIT;
9406 : : }
9407 : :
9408 : 355 : current_function_static_stack_size = stack_size;
9409 : : }
9410 : :
9411 : : /* On SEH target with very large frame size, allocate an area to save
9412 : : SSE registers (as the very large allocation won't be described). */
9413 : 1501509 : if (TARGET_SEH
9414 : : && frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE
9415 : : && !sse_registers_saved)
9416 : : {
9417 : : HOST_WIDE_INT sse_size
9418 : : = frame.sse_reg_save_offset - frame.reg_save_offset;
9419 : :
9420 : : gcc_assert (int_registers_saved);
9421 : :
9422 : : /* No need to do stack checking as the area will be immediately
9423 : : written. */
9424 : : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9425 : : GEN_INT (-sse_size), -1,
9426 : : m->fs.cfa_reg == stack_pointer_rtx);
9427 : : allocate -= sse_size;
9428 : : ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
9429 : : sse_registers_saved = true;
9430 : : }
9431 : :
9432 : : /* If stack clash protection is requested, then probe the stack, unless it
9433 : : is already probed on the target. */
9434 : 1501509 : if (allocate >= 0
9435 : 1501505 : && flag_stack_clash_protection
9436 : 1501606 : && !ix86_target_stack_probe ())
9437 : : {
9438 : 97 : ix86_adjust_stack_and_probe (allocate, int_registers_saved, false);
9439 : 97 : allocate = 0;
9440 : : }
9441 : :
9442 : : /* The stack has already been decremented by the instruction calling us
9443 : : so probe if the size is non-negative to preserve the protection area. */
9444 : 1501412 : else if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
9445 : : {
9446 : 45 : const HOST_WIDE_INT probe_interval = get_probe_interval ();
9447 : :
9448 : 45 : if (STACK_CHECK_MOVING_SP)
9449 : : {
9450 : 45 : if (crtl->is_leaf
9451 : 17 : && !cfun->calls_alloca
9452 : 17 : && allocate <= probe_interval)
9453 : : ;
9454 : :
9455 : : else
9456 : : {
9457 : 29 : ix86_adjust_stack_and_probe (allocate, int_registers_saved, true);
9458 : 29 : allocate = 0;
9459 : : }
9460 : : }
9461 : :
9462 : : else
9463 : : {
9464 : : HOST_WIDE_INT size = allocate;
9465 : :
9466 : : if (TARGET_64BIT && size >= HOST_WIDE_INT_C (0x80000000))
9467 : : size = 0x80000000 - get_stack_check_protect () - 1;
9468 : :
9469 : : if (TARGET_STACK_PROBE)
9470 : : {
9471 : : if (crtl->is_leaf && !cfun->calls_alloca)
9472 : : {
9473 : : if (size > probe_interval)
9474 : : ix86_emit_probe_stack_range (0, size, int_registers_saved);
9475 : : }
9476 : : else
9477 : : ix86_emit_probe_stack_range (0,
9478 : : size + get_stack_check_protect (),
9479 : : int_registers_saved);
9480 : : }
9481 : : else
9482 : : {
9483 : : if (crtl->is_leaf && !cfun->calls_alloca)
9484 : : {
9485 : : if (size > probe_interval
9486 : : && size > get_stack_check_protect ())
9487 : : ix86_emit_probe_stack_range (get_stack_check_protect (),
9488 : : (size
9489 : : - get_stack_check_protect ()),
9490 : : int_registers_saved);
9491 : : }
9492 : : else
9493 : : ix86_emit_probe_stack_range (get_stack_check_protect (), size,
9494 : : int_registers_saved);
9495 : : }
9496 : : }
9497 : : }
9498 : :
9499 : 1501505 : if (allocate == 0)
9500 : : ;
9501 : 833775 : else if (!ix86_target_stack_probe ()
9502 : 833775 : || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
9503 : : {
9504 : 833730 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
9505 : : GEN_INT (-allocate), -1,
9506 : 833730 : m->fs.cfa_reg == stack_pointer_rtx);
9507 : : }
9508 : : else
9509 : : {
9510 : 45 : rtx eax = gen_rtx_REG (Pmode, AX_REG);
9511 : 45 : rtx r10 = NULL;
9512 : 45 : const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx);
9513 : 45 : bool eax_live = ix86_eax_live_at_start_p ();
9514 : 45 : bool r10_live = false;
9515 : :
9516 : 45 : if (TARGET_64BIT)
9517 : 45 : r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0);
9518 : :
9519 : 45 : if (eax_live)
9520 : : {
9521 : 0 : insn = emit_insn (gen_push (eax));
9522 : 0 : allocate -= UNITS_PER_WORD;
9523 : : /* Note that SEH directives need to continue tracking the stack
9524 : : pointer even after the frame pointer has been set up. */
9525 : 0 : if (sp_is_cfa_reg || TARGET_SEH)
9526 : : {
9527 : 0 : if (sp_is_cfa_reg)
9528 : 0 : m->fs.cfa_offset += UNITS_PER_WORD;
9529 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9530 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9531 : 0 : gen_rtx_SET (stack_pointer_rtx,
9532 : : plus_constant (Pmode,
9533 : : stack_pointer_rtx,
9534 : : -UNITS_PER_WORD)));
9535 : : }
9536 : : }
9537 : :
9538 : 45 : if (r10_live)
9539 : : {
9540 : 0 : r10 = gen_rtx_REG (Pmode, R10_REG);
9541 : 0 : insn = emit_insn (gen_push (r10));
9542 : 0 : allocate -= UNITS_PER_WORD;
9543 : 0 : if (sp_is_cfa_reg || TARGET_SEH)
9544 : : {
9545 : 0 : if (sp_is_cfa_reg)
9546 : 0 : m->fs.cfa_offset += UNITS_PER_WORD;
9547 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9548 : 0 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9549 : 0 : gen_rtx_SET (stack_pointer_rtx,
9550 : : plus_constant (Pmode,
9551 : : stack_pointer_rtx,
9552 : : -UNITS_PER_WORD)));
9553 : : }
9554 : : }
9555 : :
9556 : 45 : emit_move_insn (eax, GEN_INT (allocate));
9557 : 45 : emit_insn (gen_allocate_stack_worker_probe (Pmode, eax, eax));
9558 : :
9559 : : /* Use the fact that AX still contains ALLOCATE. */
9560 : 45 : insn = emit_insn (gen_pro_epilogue_adjust_stack_sub
9561 : 45 : (Pmode, stack_pointer_rtx, stack_pointer_rtx, eax));
9562 : :
9563 : 45 : if (sp_is_cfa_reg || TARGET_SEH)
9564 : : {
9565 : 37 : if (sp_is_cfa_reg)
9566 : 37 : m->fs.cfa_offset += allocate;
9567 : 37 : RTX_FRAME_RELATED_P (insn) = 1;
9568 : 37 : add_reg_note (insn, REG_FRAME_RELATED_EXPR,
9569 : 37 : gen_rtx_SET (stack_pointer_rtx,
9570 : : plus_constant (Pmode, stack_pointer_rtx,
9571 : : -allocate)));
9572 : : }
9573 : 45 : m->fs.sp_offset += allocate;
9574 : :
9575 : : /* Use stack_pointer_rtx for relative addressing so that code works for
9576 : : realigned stack. But this means that we need a blockage to prevent
9577 : : stores based on the frame pointer from being scheduled before. */
9578 : 45 : if (r10_live && eax_live)
9579 : : {
9580 : 0 : t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
9581 : 0 : emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
9582 : : gen_frame_mem (word_mode, t));
9583 : 0 : t = plus_constant (Pmode, t, UNITS_PER_WORD);
9584 : 0 : emit_move_insn (gen_rtx_REG (word_mode, AX_REG),
9585 : : gen_frame_mem (word_mode, t));
9586 : 0 : emit_insn (gen_memory_blockage ());
9587 : : }
9588 : 45 : else if (eax_live || r10_live)
9589 : : {
9590 : 0 : t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
9591 : 0 : emit_move_insn (gen_rtx_REG (word_mode,
9592 : : (eax_live ? AX_REG : R10_REG)),
9593 : : gen_frame_mem (word_mode, t));
9594 : 0 : emit_insn (gen_memory_blockage ());
9595 : : }
9596 : : }
9597 : 1501509 : gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset);
9598 : :
9599 : : /* If we havn't already set up the frame pointer, do so now. */
9600 : 1501509 : if (frame_pointer_needed && !m->fs.fp_valid)
9601 : : {
9602 : 0 : insn = gen_add3_insn (hard_frame_pointer_rtx, stack_pointer_rtx,
9603 : 0 : GEN_INT (frame.stack_pointer_offset
9604 : : - frame.hard_frame_pointer_offset));
9605 : 0 : insn = emit_insn (insn);
9606 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9607 : 0 : add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL);
9608 : :
9609 : 0 : if (m->fs.cfa_reg == stack_pointer_rtx)
9610 : 0 : m->fs.cfa_reg = hard_frame_pointer_rtx;
9611 : 0 : m->fs.fp_offset = frame.hard_frame_pointer_offset;
9612 : 0 : m->fs.fp_valid = true;
9613 : : }
9614 : :
9615 : 1501509 : if (!int_registers_saved)
9616 : 4187 : ix86_emit_save_regs_using_mov (frame.reg_save_offset);
9617 : 1501509 : if (!sse_registers_saved)
9618 : 33350 : ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
9619 : 1468159 : else if (save_stub_call_needed)
9620 : 7044 : ix86_emit_outlined_ms2sysv_save (frame);
9621 : :
9622 : : /* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT
9623 : : in PROLOGUE. */
9624 : 1501509 : if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry)
9625 : : {
9626 : 0 : rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM);
9627 : 0 : insn = emit_insn (gen_set_got (pic));
9628 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9629 : 0 : add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
9630 : 0 : emit_insn (gen_prologue_use (pic));
9631 : : /* Deleting already emmitted SET_GOT if exist and allocated to
9632 : : REAL_PIC_OFFSET_TABLE_REGNUM. */
9633 : 0 : ix86_elim_entry_set_got (pic);
9634 : : }
9635 : :
9636 : 1501509 : if (crtl->drap_reg && !crtl->stack_realign_needed)
9637 : : {
9638 : : /* vDRAP is setup but after reload it turns out stack realign
9639 : : isn't necessary, here we will emit prologue to setup DRAP
9640 : : without stack realign adjustment */
9641 : 183 : t = choose_baseaddr (0, NULL);
9642 : 183 : emit_insn (gen_rtx_SET (crtl->drap_reg, t));
9643 : : }
9644 : :
9645 : : /* Prevent instructions from being scheduled into register save push
9646 : : sequence when access to the redzone area is done through frame pointer.
9647 : : The offset between the frame pointer and the stack pointer is calculated
9648 : : relative to the value of the stack pointer at the end of the function
9649 : : prologue, and moving instructions that access redzone area via frame
9650 : : pointer inside push sequence violates this assumption. */
9651 : 1501509 : if (frame_pointer_needed && frame.red_zone_size)
9652 : 127738 : emit_insn (gen_memory_blockage ());
9653 : :
9654 : : /* SEH requires that the prologue end within 256 bytes of the start of
9655 : : the function. Prevent instruction schedules that would extend that.
9656 : : Further, prevent alloca modifications to the stack pointer from being
9657 : : combined with prologue modifications. */
9658 : : if (TARGET_SEH)
9659 : : emit_insn (gen_prologue_use (stack_pointer_rtx));
9660 : : }
9661 : :
9662 : : /* Emit code to restore REG using a POP or POPP insn. */
9663 : :
9664 : : static void
9665 : 1463934 : ix86_emit_restore_reg_using_pop (rtx reg, bool ppx_p)
9666 : : {
9667 : 1463934 : struct machine_function *m = cfun->machine;
9668 : 1463934 : rtx_insn *insn = emit_insn (gen_pop (reg, ppx_p));
9669 : :
9670 : 1463934 : ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset);
9671 : 1463934 : m->fs.sp_offset -= UNITS_PER_WORD;
9672 : :
9673 : 1463934 : if (m->fs.cfa_reg == crtl->drap_reg
9674 : 1463934 : && REGNO (reg) == REGNO (crtl->drap_reg))
9675 : : {
9676 : : /* Previously we'd represented the CFA as an expression
9677 : : like *(%ebp - 8). We've just popped that value from
9678 : : the stack, which means we need to reset the CFA to
9679 : : the drap register. This will remain until we restore
9680 : : the stack pointer. */
9681 : 4021 : add_reg_note (insn, REG_CFA_DEF_CFA, reg);
9682 : 4021 : RTX_FRAME_RELATED_P (insn) = 1;
9683 : :
9684 : : /* This means that the DRAP register is valid for addressing too. */
9685 : 4021 : m->fs.drap_valid = true;
9686 : 4021 : return;
9687 : : }
9688 : :
9689 : 1459913 : if (m->fs.cfa_reg == stack_pointer_rtx)
9690 : : {
9691 : 1382706 : rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
9692 : 1017273 : x = gen_rtx_SET (stack_pointer_rtx, x);
9693 : 1017273 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
9694 : 1017273 : RTX_FRAME_RELATED_P (insn) = 1;
9695 : :
9696 : 1199982 : m->fs.cfa_offset -= UNITS_PER_WORD;
9697 : : }
9698 : :
9699 : : /* When the frame pointer is the CFA, and we pop it, we are
9700 : : swapping back to the stack pointer as the CFA. This happens
9701 : : for stack frames that don't allocate other data, so we assume
9702 : : the stack pointer is now pointing at the return address, i.e.
9703 : : the function entry state, which makes the offset be 1 word. */
9704 : 1459913 : if (reg == hard_frame_pointer_rtx)
9705 : : {
9706 : 237014 : m->fs.fp_valid = false;
9707 : 237014 : if (m->fs.cfa_reg == hard_frame_pointer_rtx)
9708 : : {
9709 : 232980 : m->fs.cfa_reg = stack_pointer_rtx;
9710 : 232980 : m->fs.cfa_offset -= UNITS_PER_WORD;
9711 : :
9712 : 232980 : add_reg_note (insn, REG_CFA_DEF_CFA,
9713 : 232980 : plus_constant (Pmode, stack_pointer_rtx,
9714 : 232980 : m->fs.cfa_offset));
9715 : 232980 : RTX_FRAME_RELATED_P (insn) = 1;
9716 : : }
9717 : : }
9718 : : }
9719 : :
9720 : : /* Emit code to restore REG using a POP2 insn. */
9721 : : static void
9722 : 17 : ix86_emit_restore_reg_using_pop2 (rtx reg1, rtx reg2, bool ppx_p = false)
9723 : : {
9724 : 17 : struct machine_function *m = cfun->machine;
9725 : 17 : const int offset = UNITS_PER_WORD * 2;
9726 : 17 : rtx_insn *insn;
9727 : :
9728 : 17 : rtx mem = gen_rtx_MEM (TImode, gen_rtx_POST_INC (Pmode,
9729 : : stack_pointer_rtx));
9730 : :
9731 : 17 : if (ppx_p)
9732 : 13 : insn = emit_insn (gen_pop2p_di (reg1, mem, reg2));
9733 : : else
9734 : 4 : insn = emit_insn (gen_pop2_di (reg1, mem, reg2));
9735 : :
9736 : 17 : RTX_FRAME_RELATED_P (insn) = 1;
9737 : :
9738 : 17 : rtx dwarf = NULL_RTX;
9739 : 17 : dwarf = alloc_reg_note (REG_CFA_RESTORE, reg1, dwarf);
9740 : 17 : dwarf = alloc_reg_note (REG_CFA_RESTORE, reg2, dwarf);
9741 : 17 : REG_NOTES (insn) = dwarf;
9742 : 17 : m->fs.sp_offset -= offset;
9743 : :
9744 : 17 : if (m->fs.cfa_reg == crtl->drap_reg
9745 : 17 : && (REGNO (reg1) == REGNO (crtl->drap_reg)
9746 : 3 : || REGNO (reg2) == REGNO (crtl->drap_reg)))
9747 : : {
9748 : : /* Previously we'd represented the CFA as an expression
9749 : : like *(%ebp - 8). We've just popped that value from
9750 : : the stack, which means we need to reset the CFA to
9751 : : the drap register. This will remain until we restore
9752 : : the stack pointer. */
9753 : 1 : add_reg_note (insn, REG_CFA_DEF_CFA,
9754 : 1 : REGNO (reg1) == REGNO (crtl->drap_reg) ? reg1 : reg2);
9755 : 1 : RTX_FRAME_RELATED_P (insn) = 1;
9756 : :
9757 : : /* This means that the DRAP register is valid for addressing too. */
9758 : 1 : m->fs.drap_valid = true;
9759 : 1 : return;
9760 : : }
9761 : :
9762 : 16 : if (m->fs.cfa_reg == stack_pointer_rtx)
9763 : : {
9764 : 14 : rtx x = plus_constant (Pmode, stack_pointer_rtx, offset);
9765 : 14 : x = gen_rtx_SET (stack_pointer_rtx, x);
9766 : 14 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
9767 : 14 : RTX_FRAME_RELATED_P (insn) = 1;
9768 : :
9769 : 14 : m->fs.cfa_offset -= offset;
9770 : : }
9771 : :
9772 : : /* When the frame pointer is the CFA, and we pop it, we are
9773 : : swapping back to the stack pointer as the CFA. This happens
9774 : : for stack frames that don't allocate other data, so we assume
9775 : : the stack pointer is now pointing at the return address, i.e.
9776 : : the function entry state, which makes the offset be 1 word. */
9777 : 16 : if (reg1 == hard_frame_pointer_rtx || reg2 == hard_frame_pointer_rtx)
9778 : : {
9779 : 0 : m->fs.fp_valid = false;
9780 : 0 : if (m->fs.cfa_reg == hard_frame_pointer_rtx)
9781 : : {
9782 : 0 : m->fs.cfa_reg = stack_pointer_rtx;
9783 : 0 : m->fs.cfa_offset -= offset;
9784 : :
9785 : 0 : add_reg_note (insn, REG_CFA_DEF_CFA,
9786 : 0 : plus_constant (Pmode, stack_pointer_rtx,
9787 : 0 : m->fs.cfa_offset));
9788 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
9789 : : }
9790 : : }
9791 : : }
9792 : :
9793 : : /* Emit code to restore saved registers using POP insns. */
9794 : :
9795 : : static void
9796 : 1327545 : ix86_emit_restore_regs_using_pop (bool ppx_p)
9797 : : {
9798 : 1327545 : unsigned int regno;
9799 : :
9800 : 123461685 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9801 : 122134140 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true))
9802 : 1226603 : ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno), ppx_p);
9803 : 1327545 : }
9804 : :
9805 : : /* Emit code to restore saved registers using POP2 insns. */
9806 : :
9807 : : static void
9808 : 546 : ix86_emit_restore_regs_using_pop2 (void)
9809 : : {
9810 : 546 : int regno;
9811 : 546 : int regno_list[2];
9812 : 546 : regno_list[0] = regno_list[1] = -1;
9813 : 546 : int loaded_regnum = 0;
9814 : 546 : bool aligned = cfun->machine->fs.sp_offset % 16 == 0;
9815 : :
9816 : 50778 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9817 : 50232 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true))
9818 : : {
9819 : 121 : if (aligned)
9820 : : {
9821 : 115 : regno_list[loaded_regnum++] = regno;
9822 : 115 : if (loaded_regnum == 2)
9823 : : {
9824 : 17 : gcc_assert (regno_list[0] != -1
9825 : : && regno_list[1] != -1
9826 : : && regno_list[0] != regno_list[1]);
9827 : :
9828 : 17 : ix86_emit_restore_reg_using_pop2 (gen_rtx_REG (word_mode,
9829 : : regno_list[0]),
9830 : : gen_rtx_REG (word_mode,
9831 : : regno_list[1]),
9832 : 17 : TARGET_APX_PPX);
9833 : 17 : loaded_regnum = 0;
9834 : 17 : regno_list[0] = regno_list[1] = -1;
9835 : : }
9836 : : }
9837 : : else
9838 : : {
9839 : 12 : ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno),
9840 : 6 : TARGET_APX_PPX);
9841 : 6 : aligned = true;
9842 : : }
9843 : : }
9844 : :
9845 : 546 : if (loaded_regnum == 1)
9846 : 81 : ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno_list[0]),
9847 : 81 : TARGET_APX_PPX);
9848 : 546 : }
9849 : :
9850 : : /* Emit code and notes for the LEAVE instruction. If insn is non-null,
9851 : : omits the emit and only attaches the notes. */
9852 : :
9853 : : static void
9854 : 240625 : ix86_emit_leave (rtx_insn *insn)
9855 : : {
9856 : 240625 : struct machine_function *m = cfun->machine;
9857 : :
9858 : 240625 : if (!insn)
9859 : 239654 : insn = emit_insn (gen_leave (word_mode));
9860 : :
9861 : 240625 : ix86_add_queued_cfa_restore_notes (insn);
9862 : :
9863 : 240625 : gcc_assert (m->fs.fp_valid);
9864 : 240625 : m->fs.sp_valid = true;
9865 : 240625 : m->fs.sp_realigned = false;
9866 : 240625 : m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD;
9867 : 240625 : m->fs.fp_valid = false;
9868 : :
9869 : 240625 : if (m->fs.cfa_reg == hard_frame_pointer_rtx)
9870 : : {
9871 : 237637 : m->fs.cfa_reg = stack_pointer_rtx;
9872 : 237637 : m->fs.cfa_offset = m->fs.sp_offset;
9873 : :
9874 : 237637 : add_reg_note (insn, REG_CFA_DEF_CFA,
9875 : 237637 : plus_constant (Pmode, stack_pointer_rtx,
9876 : 237637 : m->fs.sp_offset));
9877 : 237637 : RTX_FRAME_RELATED_P (insn) = 1;
9878 : : }
9879 : 240625 : ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx,
9880 : : m->fs.fp_offset);
9881 : 240625 : }
9882 : :
9883 : : /* Emit code to restore saved registers using MOV insns.
9884 : : First register is restored from CFA - CFA_OFFSET. */
9885 : : static void
9886 : 98120 : ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
9887 : : bool maybe_eh_return)
9888 : : {
9889 : 98120 : struct machine_function *m = cfun->machine;
9890 : 98120 : unsigned int regno;
9891 : :
9892 : 9125160 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9893 : 9027040 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
9894 : : {
9895 : :
9896 : : /* Skip registers, already processed by shrink wrap separate. */
9897 : 273303 : if (!cfun->machine->reg_is_wrapped_separately[regno])
9898 : : {
9899 : 143459 : rtx reg = gen_rtx_REG (word_mode, regno);
9900 : 143459 : rtx mem;
9901 : 143459 : rtx_insn *insn;
9902 : :
9903 : 143459 : mem = choose_baseaddr (cfa_offset, NULL);
9904 : 143459 : mem = gen_frame_mem (word_mode, mem);
9905 : 143459 : insn = emit_move_insn (reg, mem);
9906 : :
9907 : 143459 : if (m->fs.cfa_reg == crtl->drap_reg
9908 : 143459 : && regno == REGNO (crtl->drap_reg))
9909 : : {
9910 : : /* Previously we'd represented the CFA as an expression
9911 : : like *(%ebp - 8). We've just popped that value from
9912 : : the stack, which means we need to reset the CFA to
9913 : : the drap register. This will remain until we restore
9914 : : the stack pointer. */
9915 : 2988 : add_reg_note (insn, REG_CFA_DEF_CFA, reg);
9916 : 2988 : RTX_FRAME_RELATED_P (insn) = 1;
9917 : :
9918 : : /* DRAP register is valid for addressing. */
9919 : 2988 : m->fs.drap_valid = true;
9920 : : }
9921 : : else
9922 : 140471 : ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
9923 : : }
9924 : 292567 : cfa_offset -= UNITS_PER_WORD;
9925 : : }
9926 : 98120 : }
9927 : :
9928 : : /* Emit code to restore saved registers using MOV insns.
9929 : : First register is restored from CFA - CFA_OFFSET. */
9930 : : static void
9931 : 33927 : ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
9932 : : bool maybe_eh_return)
9933 : : {
9934 : 33927 : unsigned int regno;
9935 : :
9936 : 3155211 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9937 : 3121284 : if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
9938 : : {
9939 : 339285 : rtx reg = gen_rtx_REG (V4SFmode, regno);
9940 : 339285 : rtx mem;
9941 : 339285 : unsigned int align = GET_MODE_ALIGNMENT (V4SFmode);
9942 : :
9943 : 339285 : mem = choose_baseaddr (cfa_offset, &align);
9944 : 339285 : mem = gen_rtx_MEM (V4SFmode, mem);
9945 : :
9946 : : /* The location aligment depends upon the base register. */
9947 : 339285 : align = MIN (GET_MODE_ALIGNMENT (V4SFmode), align);
9948 : 339285 : gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1)));
9949 : 339285 : set_mem_align (mem, align);
9950 : 339285 : emit_insn (gen_rtx_SET (reg, mem));
9951 : :
9952 : 339285 : ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
9953 : :
9954 : 339285 : cfa_offset -= GET_MODE_SIZE (V4SFmode);
9955 : : }
9956 : 33927 : }
9957 : :
9958 : : static void
9959 : 7621 : ix86_emit_outlined_ms2sysv_restore (const struct ix86_frame &frame,
9960 : : bool use_call, int style)
9961 : : {
9962 : 7621 : struct machine_function *m = cfun->machine;
9963 : 7621 : const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS
9964 : 7621 : + m->call_ms2sysv_extra_regs;
9965 : 7621 : rtvec v;
9966 : 7621 : unsigned int elems_needed, align, i, vi = 0;
9967 : 7621 : rtx_insn *insn;
9968 : 7621 : rtx sym, tmp;
9969 : 7621 : rtx rsi = gen_rtx_REG (word_mode, SI_REG);
9970 : 7621 : rtx r10 = NULL_RTX;
9971 : 7621 : const class xlogue_layout &xlogue = xlogue_layout::get_instance ();
9972 : 7621 : HOST_WIDE_INT stub_ptr_offset = xlogue.get_stub_ptr_offset ();
9973 : 7621 : HOST_WIDE_INT rsi_offset = frame.stack_realign_offset + stub_ptr_offset;
9974 : 7621 : rtx rsi_frame_load = NULL_RTX;
9975 : 7621 : HOST_WIDE_INT rsi_restore_offset = (HOST_WIDE_INT)-1;
9976 : 7621 : enum xlogue_stub stub;
9977 : :
9978 : 7621 : gcc_assert (!m->fs.fp_valid || frame_pointer_needed);
9979 : :
9980 : : /* If using a realigned stack, we should never start with padding. */
9981 : 7621 : gcc_assert (!stack_realign_fp || !xlogue.get_stack_align_off_in ());
9982 : :
9983 : : /* Setup RSI as the stub's base pointer. */
9984 : 7621 : align = GET_MODE_ALIGNMENT (V4SFmode);
9985 : 7621 : tmp = choose_baseaddr (rsi_offset, &align, SI_REG);
9986 : 7621 : gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode));
9987 : :
9988 : 7621 : emit_insn (gen_rtx_SET (rsi, tmp));
9989 : :
9990 : : /* Get a symbol for the stub. */
9991 : 7621 : if (frame_pointer_needed)
9992 : 5955 : stub = use_call ? XLOGUE_STUB_RESTORE_HFP
9993 : : : XLOGUE_STUB_RESTORE_HFP_TAIL;
9994 : : else
9995 : 1666 : stub = use_call ? XLOGUE_STUB_RESTORE
9996 : : : XLOGUE_STUB_RESTORE_TAIL;
9997 : 7621 : sym = xlogue.get_stub_rtx (stub);
9998 : :
9999 : 7621 : elems_needed = ncregs;
10000 : 7621 : if (use_call)
10001 : 6498 : elems_needed += 1;
10002 : : else
10003 : 1275 : elems_needed += frame_pointer_needed ? 5 : 3;
10004 : 7621 : v = rtvec_alloc (elems_needed);
10005 : :
10006 : : /* We call the epilogue stub when we need to pop incoming args or we are
10007 : : doing a sibling call as the tail. Otherwise, we will emit a jmp to the
10008 : : epilogue stub and it is the tail-call. */
10009 : 7621 : if (use_call)
10010 : 6498 : RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
10011 : : else
10012 : : {
10013 : 1123 : RTVEC_ELT (v, vi++) = ret_rtx;
10014 : 1123 : RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
10015 : 1123 : if (frame_pointer_needed)
10016 : : {
10017 : 971 : rtx rbp = gen_rtx_REG (DImode, BP_REG);
10018 : 971 : gcc_assert (m->fs.fp_valid);
10019 : 971 : gcc_assert (m->fs.cfa_reg == hard_frame_pointer_rtx);
10020 : :
10021 : 971 : tmp = plus_constant (DImode, rbp, 8);
10022 : 971 : RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, tmp);
10023 : 971 : RTVEC_ELT (v, vi++) = gen_rtx_SET (rbp, gen_rtx_MEM (DImode, rbp));
10024 : 971 : tmp = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
10025 : 971 : RTVEC_ELT (v, vi++) = gen_rtx_CLOBBER (VOIDmode, tmp);
10026 : : }
10027 : : else
10028 : : {
10029 : : /* If no hard frame pointer, we set R10 to the SP restore value. */
10030 : 152 : gcc_assert (!m->fs.fp_valid);
10031 : 152 : gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
10032 : 152 : gcc_assert (m->fs.sp_valid);
10033 : :
10034 : 152 : r10 = gen_rtx_REG (DImode, R10_REG);
10035 : 152 : tmp = plus_constant (Pmode, rsi, stub_ptr_offset);
10036 : 152 : emit_insn (gen_rtx_SET (r10, tmp));
10037 : :
10038 : 152 : RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, r10);
10039 : : }
10040 : : }
10041 : :
10042 : : /* Generate frame load insns and restore notes. */
10043 : 107954 : for (i = 0; i < ncregs; ++i)
10044 : : {
10045 : 100333 : const xlogue_layout::reginfo &r = xlogue.get_reginfo (i);
10046 : 100333 : machine_mode mode = SSE_REGNO_P (r.regno) ? V4SFmode : word_mode;
10047 : 100333 : rtx reg, frame_load;
10048 : :
10049 : 100333 : reg = gen_rtx_REG (mode, r.regno);
10050 : 100333 : frame_load = gen_frame_load (reg, rsi, r.offset);
10051 : :
10052 : : /* Save RSI frame load insn & note to add last. */
10053 : 100333 : if (r.regno == SI_REG)
10054 : : {
10055 : 7621 : gcc_assert (!rsi_frame_load);
10056 : 7621 : rsi_frame_load = frame_load;
10057 : 7621 : rsi_restore_offset = r.offset;
10058 : : }
10059 : : else
10060 : : {
10061 : 92712 : RTVEC_ELT (v, vi++) = frame_load;
10062 : 92712 : ix86_add_cfa_restore_note (NULL, reg, r.offset);
10063 : : }
10064 : : }
10065 : :
10066 : : /* Add RSI frame load & restore note at the end. */
10067 : 7621 : gcc_assert (rsi_frame_load);
10068 : 7621 : gcc_assert (rsi_restore_offset != (HOST_WIDE_INT)-1);
10069 : 7621 : RTVEC_ELT (v, vi++) = rsi_frame_load;
10070 : 7621 : ix86_add_cfa_restore_note (NULL, gen_rtx_REG (DImode, SI_REG),
10071 : : rsi_restore_offset);
10072 : :
10073 : : /* Finally, for tail-call w/o a hard frame pointer, set SP to R10. */
10074 : 7621 : if (!use_call && !frame_pointer_needed)
10075 : : {
10076 : 152 : gcc_assert (m->fs.sp_valid);
10077 : 152 : gcc_assert (!m->fs.sp_realigned);
10078 : :
10079 : : /* At this point, R10 should point to frame.stack_realign_offset. */
10080 : 152 : if (m->fs.cfa_reg == stack_pointer_rtx)
10081 : 152 : m->fs.cfa_offset += m->fs.sp_offset - frame.stack_realign_offset;
10082 : 152 : m->fs.sp_offset = frame.stack_realign_offset;
10083 : : }
10084 : :
10085 : 7621 : gcc_assert (vi == (unsigned int)GET_NUM_ELEM (v));
10086 : 7621 : tmp = gen_rtx_PARALLEL (VOIDmode, v);
10087 : 7621 : if (use_call)
10088 : 6498 : insn = emit_insn (tmp);
10089 : : else
10090 : : {
10091 : 1123 : insn = emit_jump_insn (tmp);
10092 : 1123 : JUMP_LABEL (insn) = ret_rtx;
10093 : :
10094 : 1123 : if (frame_pointer_needed)
10095 : 971 : ix86_emit_leave (insn);
10096 : : else
10097 : : {
10098 : : /* Need CFA adjust note. */
10099 : 152 : tmp = gen_rtx_SET (stack_pointer_rtx, r10);
10100 : 152 : add_reg_note (insn, REG_CFA_ADJUST_CFA, tmp);
10101 : : }
10102 : : }
10103 : :
10104 : 7621 : RTX_FRAME_RELATED_P (insn) = true;
10105 : 7621 : ix86_add_queued_cfa_restore_notes (insn);
10106 : :
10107 : : /* If we're not doing a tail-call, we need to adjust the stack. */
10108 : 7621 : if (use_call && m->fs.sp_valid)
10109 : : {
10110 : 3706 : HOST_WIDE_INT dealloc = m->fs.sp_offset - frame.stack_realign_offset;
10111 : 3706 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10112 : : GEN_INT (dealloc), style,
10113 : 3706 : m->fs.cfa_reg == stack_pointer_rtx);
10114 : : }
10115 : 7621 : }
10116 : :
10117 : : /* Restore function stack, frame, and registers. */
10118 : :
10119 : : void
10120 : 1621810 : ix86_expand_epilogue (int style)
10121 : : {
10122 : 1621810 : struct machine_function *m = cfun->machine;
10123 : 1621810 : struct machine_frame_state frame_state_save = m->fs;
10124 : 1621810 : bool restore_regs_via_mov;
10125 : 1621810 : bool using_drap;
10126 : 1621810 : bool restore_stub_is_tail = false;
10127 : :
10128 : 1621810 : if (ix86_function_naked (current_function_decl))
10129 : : {
10130 : : /* The program should not reach this point. */
10131 : 74 : emit_insn (gen_ud2 ());
10132 : 120346 : return;
10133 : : }
10134 : :
10135 : 1621736 : ix86_finalize_stack_frame_flags ();
10136 : 1621736 : const struct ix86_frame &frame = cfun->machine->frame;
10137 : :
10138 : 1621736 : m->fs.sp_realigned = stack_realign_fp;
10139 : 31507 : m->fs.sp_valid = stack_realign_fp
10140 : 1597239 : || !frame_pointer_needed
10141 : 2074905 : || crtl->sp_is_unchanging;
10142 : 1621736 : gcc_assert (!m->fs.sp_valid
10143 : : || m->fs.sp_offset == frame.stack_pointer_offset);
10144 : :
10145 : : /* The FP must be valid if the frame pointer is present. */
10146 : 1621736 : gcc_assert (frame_pointer_needed == m->fs.fp_valid);
10147 : 1621736 : gcc_assert (!m->fs.fp_valid
10148 : : || m->fs.fp_offset == frame.hard_frame_pointer_offset);
10149 : :
10150 : : /* We must have *some* valid pointer to the stack frame. */
10151 : 1621736 : gcc_assert (m->fs.sp_valid || m->fs.fp_valid);
10152 : :
10153 : : /* The DRAP is never valid at this point. */
10154 : 1621736 : gcc_assert (!m->fs.drap_valid);
10155 : :
10156 : : /* See the comment about red zone and frame
10157 : : pointer usage in ix86_expand_prologue. */
10158 : 1621736 : if (frame_pointer_needed && frame.red_zone_size)
10159 : 127771 : emit_insn (gen_memory_blockage ());
10160 : :
10161 : 1621736 : using_drap = crtl->drap_reg && crtl->stack_realign_needed;
10162 : 7010 : gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg);
10163 : :
10164 : : /* Determine the CFA offset of the end of the red-zone. */
10165 : 1621736 : m->fs.red_zone_offset = 0;
10166 : 1621736 : if (ix86_using_red_zone () && crtl->args.pops_args < 65536)
10167 : : {
10168 : : /* The red-zone begins below return address and error code in
10169 : : exception handler. */
10170 : 1445814 : m->fs.red_zone_offset = RED_ZONE_SIZE + INCOMING_FRAME_SP_OFFSET;
10171 : :
10172 : : /* When the register save area is in the aligned portion of
10173 : : the stack, determine the maximum runtime displacement that
10174 : : matches up with the aligned frame. */
10175 : 1445814 : if (stack_realign_drap)
10176 : 8298 : m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT
10177 : 4149 : + UNITS_PER_WORD);
10178 : : }
10179 : :
10180 : 1621736 : HOST_WIDE_INT reg_save_offset = frame.reg_save_offset;
10181 : :
10182 : : /* Special care must be taken for the normal return case of a function
10183 : : using eh_return: the eax and edx registers are marked as saved, but
10184 : : not restored along this path. Adjust the save location to match. */
10185 : 1621736 : if (crtl->calls_eh_return && style != 2)
10186 : 37 : reg_save_offset -= 2 * UNITS_PER_WORD;
10187 : :
10188 : : /* EH_RETURN requires the use of moves to function properly. */
10189 : 1621736 : if (crtl->calls_eh_return)
10190 : : restore_regs_via_mov = true;
10191 : : /* SEH requires the use of pops to identify the epilogue. */
10192 : 1621678 : else if (TARGET_SEH)
10193 : : restore_regs_via_mov = false;
10194 : : /* If we already save reg with pushp, don't use move at epilogue. */
10195 : 1621678 : else if (m->fs.apx_ppx_used)
10196 : : restore_regs_via_mov = false;
10197 : : /* If we're only restoring one register and sp cannot be used then
10198 : : using a move instruction to restore the register since it's
10199 : : less work than reloading sp and popping the register. */
10200 : 1621594 : else if (!sp_valid_at (frame.hfp_save_offset) && frame.nregs <= 1)
10201 : : restore_regs_via_mov = true;
10202 : 1561515 : else if (crtl->shrink_wrapped_separate
10203 : 1506544 : || (TARGET_EPILOGUE_USING_MOVE
10204 : 56619 : && cfun->machine->use_fast_prologue_epilogue
10205 : 56567 : && (frame.nregs > 1
10206 : 56558 : || m->fs.sp_offset != reg_save_offset)))
10207 : : restore_regs_via_mov = true;
10208 : 1506312 : else if (frame_pointer_needed
10209 : 415073 : && !frame.nregs
10210 : 321240 : && m->fs.sp_offset != reg_save_offset)
10211 : : restore_regs_via_mov = true;
10212 : 1357289 : else if (frame_pointer_needed
10213 : 266050 : && TARGET_USE_LEAVE
10214 : 265975 : && cfun->machine->use_fast_prologue_epilogue
10215 : 209726 : && frame.nregs == 1)
10216 : : restore_regs_via_mov = true;
10217 : : else
10218 : 1621736 : restore_regs_via_mov = false;
10219 : :
10220 : 1621736 : if (crtl->shrink_wrapped_separate)
10221 : 54992 : gcc_assert (restore_regs_via_mov);
10222 : :
10223 : 1566744 : if (restore_regs_via_mov || frame.nsseregs)
10224 : : {
10225 : : /* Ensure that the entire register save area is addressable via
10226 : : the stack pointer, if we will restore SSE regs via sp. */
10227 : 327219 : if (TARGET_64BIT
10228 : 314987 : && m->fs.sp_offset > 0x7fffffff
10229 : 26 : && sp_valid_at (frame.stack_realign_offset + 1)
10230 : 327244 : && (frame.nsseregs + frame.nregs) != 0)
10231 : : {
10232 : 6 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10233 : 6 : GEN_INT (m->fs.sp_offset
10234 : : - frame.sse_reg_save_offset),
10235 : : style,
10236 : 6 : m->fs.cfa_reg == stack_pointer_rtx);
10237 : : }
10238 : : }
10239 : :
10240 : : /* If there are any SSE registers to restore, then we have to do it
10241 : : via moves, since there's obviously no pop for SSE regs. */
10242 : 1621736 : if (frame.nsseregs)
10243 : 33927 : ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset,
10244 : : style == 2);
10245 : :
10246 : 1621736 : if (m->call_ms2sysv)
10247 : : {
10248 : 7621 : int pop_incoming_args = crtl->args.pops_args && crtl->args.size;
10249 : :
10250 : : /* We cannot use a tail-call for the stub if:
10251 : : 1. We have to pop incoming args,
10252 : : 2. We have additional int regs to restore, or
10253 : : 3. A sibling call will be the tail-call, or
10254 : : 4. We are emitting an eh_return_internal epilogue.
10255 : :
10256 : : TODO: Item 4 has not yet tested!
10257 : :
10258 : : If any of the above are true, we will call the stub rather than
10259 : : jump to it. */
10260 : 7621 : restore_stub_is_tail = !(pop_incoming_args || frame.nregs || style != 1);
10261 : 7621 : ix86_emit_outlined_ms2sysv_restore (frame, !restore_stub_is_tail, style);
10262 : : }
10263 : :
10264 : : /* If using out-of-line stub that is a tail-call, then...*/
10265 : 1621736 : if (m->call_ms2sysv && restore_stub_is_tail)
10266 : : {
10267 : : /* TODO: parinoid tests. (remove eventually) */
10268 : 1123 : gcc_assert (m->fs.sp_valid);
10269 : 1123 : gcc_assert (!m->fs.sp_realigned);
10270 : 1123 : gcc_assert (!m->fs.fp_valid);
10271 : 1123 : gcc_assert (!m->fs.realigned);
10272 : 1123 : gcc_assert (m->fs.sp_offset == UNITS_PER_WORD);
10273 : 1123 : gcc_assert (!crtl->drap_reg);
10274 : 1123 : gcc_assert (!frame.nregs);
10275 : 1123 : gcc_assert (!crtl->shrink_wrapped_separate);
10276 : : }
10277 : 1620613 : else if (restore_regs_via_mov)
10278 : : {
10279 : 292522 : rtx t;
10280 : :
10281 : 292522 : if (frame.nregs)
10282 : 98120 : ix86_emit_restore_regs_using_mov (reg_save_offset, style == 2);
10283 : :
10284 : : /* eh_return epilogues need %ecx added to the stack pointer. */
10285 : 292522 : if (style == 2)
10286 : : {
10287 : 37 : rtx sa = EH_RETURN_STACKADJ_RTX;
10288 : 29 : rtx_insn *insn;
10289 : :
10290 : 29 : gcc_assert (!crtl->shrink_wrapped_separate);
10291 : :
10292 : : /* Stack realignment doesn't work with eh_return. */
10293 : 29 : if (crtl->stack_realign_needed)
10294 : 0 : sorry ("Stack realignment not supported with "
10295 : : "%<__builtin_eh_return%>");
10296 : :
10297 : : /* regparm nested functions don't work with eh_return. */
10298 : 29 : if (ix86_static_chain_on_stack)
10299 : 0 : sorry ("regparm nested function not supported with "
10300 : : "%<__builtin_eh_return%>");
10301 : :
10302 : 29 : if (frame_pointer_needed)
10303 : : {
10304 : 35 : t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
10305 : 43 : t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
10306 : 27 : emit_insn (gen_rtx_SET (sa, t));
10307 : :
10308 : : /* NB: eh_return epilogues must restore the frame pointer
10309 : : in word_mode since the upper 32 bits of RBP register
10310 : : can have any values. */
10311 : 27 : t = gen_frame_mem (word_mode, hard_frame_pointer_rtx);
10312 : 27 : rtx frame_reg = gen_rtx_REG (word_mode,
10313 : : HARD_FRAME_POINTER_REGNUM);
10314 : 27 : insn = emit_move_insn (frame_reg, t);
10315 : :
10316 : : /* Note that we use SA as a temporary CFA, as the return
10317 : : address is at the proper place relative to it. We
10318 : : pretend this happens at the FP restore insn because
10319 : : prior to this insn the FP would be stored at the wrong
10320 : : offset relative to SA, and after this insn we have no
10321 : : other reasonable register to use for the CFA. We don't
10322 : : bother resetting the CFA to the SP for the duration of
10323 : : the return insn, unless the control flow instrumentation
10324 : : is done. In this case the SP is used later and we have
10325 : : to reset CFA to SP. */
10326 : 27 : add_reg_note (insn, REG_CFA_DEF_CFA,
10327 : 35 : plus_constant (Pmode, sa, UNITS_PER_WORD));
10328 : 27 : ix86_add_queued_cfa_restore_notes (insn);
10329 : 27 : add_reg_note (insn, REG_CFA_RESTORE, frame_reg);
10330 : 27 : RTX_FRAME_RELATED_P (insn) = 1;
10331 : :
10332 : 27 : m->fs.cfa_reg = sa;
10333 : 27 : m->fs.cfa_offset = UNITS_PER_WORD;
10334 : 27 : m->fs.fp_valid = false;
10335 : :
10336 : 27 : pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
10337 : : const0_rtx, style,
10338 : 27 : flag_cf_protection);
10339 : : }
10340 : : else
10341 : : {
10342 : 2 : t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
10343 : 2 : t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD);
10344 : 2 : insn = emit_insn (gen_rtx_SET (stack_pointer_rtx, t));
10345 : 2 : ix86_add_queued_cfa_restore_notes (insn);
10346 : :
10347 : 2 : gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
10348 : 2 : if (m->fs.cfa_offset != UNITS_PER_WORD)
10349 : : {
10350 : 2 : m->fs.cfa_offset = UNITS_PER_WORD;
10351 : 2 : add_reg_note (insn, REG_CFA_DEF_CFA,
10352 : 2 : plus_constant (Pmode, stack_pointer_rtx,
10353 : 2 : UNITS_PER_WORD));
10354 : 2 : RTX_FRAME_RELATED_P (insn) = 1;
10355 : : }
10356 : : }
10357 : 29 : m->fs.sp_offset = UNITS_PER_WORD;
10358 : 29 : m->fs.sp_valid = true;
10359 : 29 : m->fs.sp_realigned = false;
10360 : : }
10361 : : }
10362 : : else
10363 : : {
10364 : : /* SEH requires that the function end with (1) a stack adjustment
10365 : : if necessary, (2) a sequence of pops, and (3) a return or
10366 : : jump instruction. Prevent insns from the function body from
10367 : : being scheduled into this sequence. */
10368 : 1328091 : if (TARGET_SEH)
10369 : : {
10370 : : /* Prevent a catch region from being adjacent to the standard
10371 : : epilogue sequence. Unfortunately neither crtl->uses_eh_lsda
10372 : : nor several other flags that would be interesting to test are
10373 : : set up yet. */
10374 : : if (flag_non_call_exceptions)
10375 : : emit_insn (gen_nops (const1_rtx));
10376 : : else
10377 : : emit_insn (gen_blockage ());
10378 : : }
10379 : :
10380 : : /* First step is to deallocate the stack frame so that we can
10381 : : pop the registers. If the stack pointer was realigned, it needs
10382 : : to be restored now. Also do it on SEH target for very large
10383 : : frame as the emitted instructions aren't allowed by the ABI
10384 : : in epilogues. */
10385 : 1328091 : if (!m->fs.sp_valid || m->fs.sp_realigned
10386 : : || (TARGET_SEH
10387 : : && (m->fs.sp_offset - reg_save_offset
10388 : : >= SEH_MAX_FRAME_SIZE)))
10389 : : {
10390 : 29218 : pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx,
10391 : 29218 : GEN_INT (m->fs.fp_offset
10392 : : - reg_save_offset),
10393 : : style, false);
10394 : : }
10395 : 1298873 : else if (m->fs.sp_offset != reg_save_offset)
10396 : : {
10397 : 607819 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10398 : : GEN_INT (m->fs.sp_offset
10399 : : - reg_save_offset),
10400 : : style,
10401 : 607819 : m->fs.cfa_reg == stack_pointer_rtx);
10402 : : }
10403 : :
10404 : 1328091 : if (TARGET_APX_PUSH2POP2
10405 : 549 : && ix86_can_use_push2pop2 ()
10406 : 1328638 : && m->func_type == TYPE_NORMAL)
10407 : 546 : ix86_emit_restore_regs_using_pop2 ();
10408 : : else
10409 : 1327545 : ix86_emit_restore_regs_using_pop (TARGET_APX_PPX);
10410 : : }
10411 : :
10412 : : /* If we used a stack pointer and haven't already got rid of it,
10413 : : then do so now. */
10414 : 1621736 : if (m->fs.fp_valid)
10415 : : {
10416 : : /* If the stack pointer is valid and pointing at the frame
10417 : : pointer store address, then we only need a pop. */
10418 : 476668 : if (sp_valid_at (frame.hfp_save_offset)
10419 : 476668 : && m->fs.sp_offset == frame.hfp_save_offset)
10420 : 237002 : ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
10421 : : /* Leave results in shorter dependency chains on CPUs that are
10422 : : able to grok it fast. */
10423 : 239666 : else if (TARGET_USE_LEAVE
10424 : 12 : || optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun))
10425 : 239678 : || !cfun->machine->use_fast_prologue_epilogue)
10426 : 239654 : ix86_emit_leave (NULL);
10427 : : else
10428 : : {
10429 : 12 : pro_epilogue_adjust_stack (stack_pointer_rtx,
10430 : : hard_frame_pointer_rtx,
10431 : 12 : const0_rtx, style, !using_drap);
10432 : 12 : ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
10433 : : }
10434 : : }
10435 : :
10436 : 1621736 : if (using_drap)
10437 : : {
10438 : 7010 : int param_ptr_offset = UNITS_PER_WORD;
10439 : 7010 : rtx_insn *insn;
10440 : :
10441 : 7010 : gcc_assert (stack_realign_drap);
10442 : :
10443 : 7010 : if (ix86_static_chain_on_stack)
10444 : 0 : param_ptr_offset += UNITS_PER_WORD;
10445 : 7010 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
10446 : 230 : param_ptr_offset += UNITS_PER_WORD;
10447 : :
10448 : 7311 : insn = emit_insn (gen_rtx_SET
10449 : : (stack_pointer_rtx,
10450 : : plus_constant (Pmode, crtl->drap_reg,
10451 : : -param_ptr_offset)));
10452 : 7010 : m->fs.cfa_reg = stack_pointer_rtx;
10453 : 7010 : m->fs.cfa_offset = param_ptr_offset;
10454 : 7010 : m->fs.sp_offset = param_ptr_offset;
10455 : 7010 : m->fs.realigned = false;
10456 : :
10457 : 7311 : add_reg_note (insn, REG_CFA_DEF_CFA,
10458 : 7010 : plus_constant (Pmode, stack_pointer_rtx,
10459 : 7010 : param_ptr_offset));
10460 : 7010 : RTX_FRAME_RELATED_P (insn) = 1;
10461 : :
10462 : 7010 : if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
10463 : 230 : ix86_emit_restore_reg_using_pop (crtl->drap_reg);
10464 : : }
10465 : :
10466 : : /* At this point the stack pointer must be valid, and we must have
10467 : : restored all of the registers. We may not have deallocated the
10468 : : entire stack frame. We've delayed this until now because it may
10469 : : be possible to merge the local stack deallocation with the
10470 : : deallocation forced by ix86_static_chain_on_stack. */
10471 : 1621736 : gcc_assert (m->fs.sp_valid);
10472 : 1621736 : gcc_assert (!m->fs.sp_realigned);
10473 : 1621736 : gcc_assert (!m->fs.fp_valid);
10474 : 1621736 : gcc_assert (!m->fs.realigned);
10475 : 1755949 : if (m->fs.sp_offset != UNITS_PER_WORD)
10476 : : {
10477 : 52812 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10478 : : GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
10479 : : style, true);
10480 : : }
10481 : : else
10482 : 1568924 : ix86_add_queued_cfa_restore_notes (get_last_insn ());
10483 : :
10484 : : /* Sibcall epilogues don't want a return instruction. */
10485 : 1621736 : if (style == 0)
10486 : : {
10487 : 120198 : m->fs = frame_state_save;
10488 : 120198 : return;
10489 : : }
10490 : :
10491 : 1501538 : if (cfun->machine->func_type != TYPE_NORMAL)
10492 : 118 : emit_jump_insn (gen_interrupt_return ());
10493 : 1501420 : else if (crtl->args.pops_args && crtl->args.size)
10494 : : {
10495 : 25892 : rtx popc = GEN_INT (crtl->args.pops_args);
10496 : :
10497 : : /* i386 can only pop 64K bytes. If asked to pop more, pop return
10498 : : address, do explicit add, and jump indirectly to the caller. */
10499 : :
10500 : 25892 : if (crtl->args.pops_args >= 65536)
10501 : : {
10502 : 0 : rtx ecx = gen_rtx_REG (SImode, CX_REG);
10503 : 0 : rtx_insn *insn;
10504 : :
10505 : : /* There is no "pascal" calling convention in any 64bit ABI. */
10506 : 0 : gcc_assert (!TARGET_64BIT);
10507 : :
10508 : 0 : insn = emit_insn (gen_pop (ecx));
10509 : 0 : m->fs.cfa_offset -= UNITS_PER_WORD;
10510 : 0 : m->fs.sp_offset -= UNITS_PER_WORD;
10511 : :
10512 : 0 : rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
10513 : 0 : x = gen_rtx_SET (stack_pointer_rtx, x);
10514 : 0 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
10515 : 0 : add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
10516 : 0 : RTX_FRAME_RELATED_P (insn) = 1;
10517 : :
10518 : 0 : pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
10519 : : popc, -1, true);
10520 : 0 : emit_jump_insn (gen_simple_return_indirect_internal (ecx));
10521 : : }
10522 : : else
10523 : 25892 : emit_jump_insn (gen_simple_return_pop_internal (popc));
10524 : : }
10525 : 1475528 : else if (!m->call_ms2sysv || !restore_stub_is_tail)
10526 : : {
10527 : : /* In case of return from EH a simple return cannot be used
10528 : : as a return address will be compared with a shadow stack
10529 : : return address. Use indirect jump instead. */
10530 : 1474405 : if (style == 2 && flag_cf_protection)
10531 : : {
10532 : : /* Register used in indirect jump must be in word_mode. But
10533 : : Pmode may not be the same as word_mode for x32. */
10534 : 17 : rtx ecx = gen_rtx_REG (word_mode, CX_REG);
10535 : 17 : rtx_insn *insn;
10536 : :
10537 : 17 : insn = emit_insn (gen_pop (ecx));
10538 : 17 : m->fs.cfa_offset -= UNITS_PER_WORD;
10539 : 17 : m->fs.sp_offset -= UNITS_PER_WORD;
10540 : :
10541 : 33 : rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
10542 : 17 : x = gen_rtx_SET (stack_pointer_rtx, x);
10543 : 17 : add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
10544 : 17 : add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
10545 : 17 : RTX_FRAME_RELATED_P (insn) = 1;
10546 : :
10547 : 17 : emit_jump_insn (gen_simple_return_indirect_internal (ecx));
10548 : 17 : }
10549 : : else
10550 : 1474388 : emit_jump_insn (gen_simple_return_internal ());
10551 : : }
10552 : :
10553 : : /* Restore the state back to the state from the prologue,
10554 : : so that it's correct for the next epilogue. */
10555 : 1501538 : m->fs = frame_state_save;
10556 : : }
10557 : :
10558 : : /* Reset from the function's potential modifications. */
10559 : :
10560 : : static void
10561 : 1461025 : ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED)
10562 : : {
10563 : 1461025 : if (pic_offset_table_rtx
10564 : 1461025 : && !ix86_use_pseudo_pic_reg ())
10565 : 0 : SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
10566 : :
10567 : 1461025 : if (TARGET_MACHO)
10568 : : {
10569 : : rtx_insn *insn = get_last_insn ();
10570 : : rtx_insn *deleted_debug_label = NULL;
10571 : :
10572 : : /* Mach-O doesn't support labels at the end of objects, so if
10573 : : it looks like we might want one, take special action.
10574 : : First, collect any sequence of deleted debug labels. */
10575 : : while (insn
10576 : : && NOTE_P (insn)
10577 : : && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
10578 : : {
10579 : : /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
10580 : : notes only, instead set their CODE_LABEL_NUMBER to -1,
10581 : : otherwise there would be code generation differences
10582 : : in between -g and -g0. */
10583 : : if (NOTE_P (insn) && NOTE_KIND (insn)
10584 : : == NOTE_INSN_DELETED_DEBUG_LABEL)
10585 : : deleted_debug_label = insn;
10586 : : insn = PREV_INSN (insn);
10587 : : }
10588 : :
10589 : : /* If we have:
10590 : : label:
10591 : : barrier
10592 : : then this needs to be detected, so skip past the barrier. */
10593 : :
10594 : : if (insn && BARRIER_P (insn))
10595 : : insn = PREV_INSN (insn);
10596 : :
10597 : : /* Up to now we've only seen notes or barriers. */
10598 : : if (insn)
10599 : : {
10600 : : if (LABEL_P (insn)
10601 : : || (NOTE_P (insn)
10602 : : && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
10603 : : /* Trailing label. */
10604 : : fputs ("\tnop\n", file);
10605 : : else if (cfun && ! cfun->is_thunk)
10606 : : {
10607 : : /* See if we have a completely empty function body, skipping
10608 : : the special case of the picbase thunk emitted as asm. */
10609 : : while (insn && ! INSN_P (insn))
10610 : : insn = PREV_INSN (insn);
10611 : : /* If we don't find any insns, we've got an empty function body;
10612 : : I.e. completely empty - without a return or branch. This is
10613 : : taken as the case where a function body has been removed
10614 : : because it contains an inline __builtin_unreachable(). GCC
10615 : : declares that reaching __builtin_unreachable() means UB so
10616 : : we're not obliged to do anything special; however, we want
10617 : : non-zero-sized function bodies. To meet this, and help the
10618 : : user out, let's trap the case. */
10619 : : if (insn == NULL)
10620 : : fputs ("\tud2\n", file);
10621 : : }
10622 : : }
10623 : : else if (deleted_debug_label)
10624 : : for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
10625 : : if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
10626 : : CODE_LABEL_NUMBER (insn) = -1;
10627 : : }
10628 : 1461025 : }
10629 : :
10630 : : /* Implement TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY. */
10631 : :
10632 : : void
10633 : 59 : ix86_print_patchable_function_entry (FILE *file,
10634 : : unsigned HOST_WIDE_INT patch_area_size,
10635 : : bool record_p)
10636 : : {
10637 : 59 : if (cfun->machine->function_label_emitted)
10638 : : {
10639 : : /* NB: When ix86_print_patchable_function_entry is called after
10640 : : function table has been emitted, we have inserted or queued
10641 : : a pseudo UNSPECV_PATCHABLE_AREA instruction at the proper
10642 : : place. There is nothing to do here. */
10643 : : return;
10644 : : }
10645 : :
10646 : 8 : default_print_patchable_function_entry (file, patch_area_size,
10647 : : record_p);
10648 : : }
10649 : :
10650 : : /* Output patchable area. NB: default_print_patchable_function_entry
10651 : : isn't available in i386.md. */
10652 : :
10653 : : void
10654 : 51 : ix86_output_patchable_area (unsigned int patch_area_size,
10655 : : bool record_p)
10656 : : {
10657 : 51 : default_print_patchable_function_entry (asm_out_file,
10658 : : patch_area_size,
10659 : : record_p);
10660 : 51 : }
10661 : :
10662 : : /* Return a scratch register to use in the split stack prologue. The
10663 : : split stack prologue is used for -fsplit-stack. It is the first
10664 : : instructions in the function, even before the regular prologue.
10665 : : The scratch register can be any caller-saved register which is not
10666 : : used for parameters or for the static chain. */
10667 : :
10668 : : static unsigned int
10669 : 25150 : split_stack_prologue_scratch_regno (void)
10670 : : {
10671 : 25150 : if (TARGET_64BIT)
10672 : : return R11_REG;
10673 : : else
10674 : : {
10675 : 7122 : bool is_fastcall, is_thiscall;
10676 : 7122 : int regparm;
10677 : :
10678 : 7122 : is_fastcall = (lookup_attribute ("fastcall",
10679 : 7122 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
10680 : : != NULL);
10681 : 7122 : is_thiscall = (lookup_attribute ("thiscall",
10682 : 7122 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
10683 : : != NULL);
10684 : 7122 : regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
10685 : :
10686 : 7122 : if (is_fastcall)
10687 : : {
10688 : 0 : if (DECL_STATIC_CHAIN (cfun->decl))
10689 : : {
10690 : 0 : sorry ("%<-fsplit-stack%> does not support fastcall with "
10691 : : "nested function");
10692 : 0 : return INVALID_REGNUM;
10693 : : }
10694 : : return AX_REG;
10695 : : }
10696 : 7122 : else if (is_thiscall)
10697 : : {
10698 : 0 : if (!DECL_STATIC_CHAIN (cfun->decl))
10699 : : return DX_REG;
10700 : 0 : return AX_REG;
10701 : : }
10702 : 7122 : else if (regparm < 3)
10703 : : {
10704 : 7122 : if (!DECL_STATIC_CHAIN (cfun->decl))
10705 : : return CX_REG;
10706 : : else
10707 : : {
10708 : 465 : if (regparm >= 2)
10709 : : {
10710 : 0 : sorry ("%<-fsplit-stack%> does not support 2 register "
10711 : : "parameters for a nested function");
10712 : 0 : return INVALID_REGNUM;
10713 : : }
10714 : : return DX_REG;
10715 : : }
10716 : : }
10717 : : else
10718 : : {
10719 : : /* FIXME: We could make this work by pushing a register
10720 : : around the addition and comparison. */
10721 : 0 : sorry ("%<-fsplit-stack%> does not support 3 register parameters");
10722 : 0 : return INVALID_REGNUM;
10723 : : }
10724 : : }
10725 : : }
10726 : :
10727 : : /* A SYMBOL_REF for the function which allocates new stackspace for
10728 : : -fsplit-stack. */
10729 : :
10730 : : static GTY(()) rtx split_stack_fn;
10731 : :
10732 : : /* A SYMBOL_REF for the more stack function when using the large
10733 : : model. */
10734 : :
10735 : : static GTY(()) rtx split_stack_fn_large;
10736 : :
10737 : : /* Return location of the stack guard value in the TLS block. */
10738 : :
10739 : : rtx
10740 : 259791 : ix86_split_stack_guard (void)
10741 : : {
10742 : 259791 : int offset;
10743 : 259791 : addr_space_t as = DEFAULT_TLS_SEG_REG;
10744 : 259791 : rtx r;
10745 : :
10746 : 259791 : gcc_assert (flag_split_stack);
10747 : :
10748 : : #ifdef TARGET_THREAD_SPLIT_STACK_OFFSET
10749 : 259791 : offset = TARGET_THREAD_SPLIT_STACK_OFFSET;
10750 : : #else
10751 : : gcc_unreachable ();
10752 : : #endif
10753 : :
10754 : 259791 : r = GEN_INT (offset);
10755 : 357699 : r = gen_const_mem (Pmode, r);
10756 : 259791 : set_mem_addr_space (r, as);
10757 : :
10758 : 259791 : return r;
10759 : : }
10760 : :
10761 : : /* Handle -fsplit-stack. These are the first instructions in the
10762 : : function, even before the regular prologue. */
10763 : :
10764 : : void
10765 : 259781 : ix86_expand_split_stack_prologue (void)
10766 : : {
10767 : 259781 : HOST_WIDE_INT allocate;
10768 : 259781 : unsigned HOST_WIDE_INT args_size;
10769 : 259781 : rtx_code_label *label;
10770 : 259781 : rtx limit, current, allocate_rtx, call_fusage;
10771 : 259781 : rtx_insn *call_insn;
10772 : 259781 : unsigned int scratch_regno = INVALID_REGNUM;
10773 : 259781 : rtx scratch_reg = NULL_RTX;
10774 : 259781 : rtx_code_label *varargs_label = NULL;
10775 : 259781 : rtx fn;
10776 : :
10777 : 259781 : gcc_assert (flag_split_stack && reload_completed);
10778 : :
10779 : 259781 : ix86_finalize_stack_frame_flags ();
10780 : 259781 : struct ix86_frame &frame = cfun->machine->frame;
10781 : 259781 : allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
10782 : :
10783 : : /* This is the label we will branch to if we have enough stack
10784 : : space. We expect the basic block reordering pass to reverse this
10785 : : branch if optimizing, so that we branch in the unlikely case. */
10786 : 259781 : label = gen_label_rtx ();
10787 : :
10788 : : /* We need to compare the stack pointer minus the frame size with
10789 : : the stack boundary in the TCB. The stack boundary always gives
10790 : : us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we
10791 : : can compare directly. Otherwise we need to do an addition. */
10792 : :
10793 : 259781 : limit = ix86_split_stack_guard ();
10794 : :
10795 : 259781 : if (allocate >= SPLIT_STACK_AVAILABLE
10796 : 234794 : || flag_force_indirect_call)
10797 : : {
10798 : 25002 : scratch_regno = split_stack_prologue_scratch_regno ();
10799 : 25002 : if (scratch_regno == INVALID_REGNUM)
10800 : 0 : return;
10801 : : }
10802 : :
10803 : 259781 : if (allocate >= SPLIT_STACK_AVAILABLE)
10804 : : {
10805 : 24987 : rtx offset;
10806 : :
10807 : : /* We need a scratch register to hold the stack pointer minus
10808 : : the required frame size. Since this is the very start of the
10809 : : function, the scratch register can be any caller-saved
10810 : : register which is not used for parameters. */
10811 : 24987 : offset = GEN_INT (- allocate);
10812 : :
10813 : 32055 : scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
10814 : 24987 : if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode))
10815 : : {
10816 : : /* We don't use gen_add in this case because it will
10817 : : want to split to lea, but when not optimizing the insn
10818 : : will not be split after this point. */
10819 : 32055 : emit_insn (gen_rtx_SET (scratch_reg,
10820 : : gen_rtx_PLUS (Pmode, stack_pointer_rtx,
10821 : : offset)));
10822 : : }
10823 : : else
10824 : : {
10825 : 0 : emit_move_insn (scratch_reg, offset);
10826 : 0 : emit_insn (gen_add2_insn (scratch_reg, stack_pointer_rtx));
10827 : : }
10828 : : current = scratch_reg;
10829 : : }
10830 : : else
10831 : 234794 : current = stack_pointer_rtx;
10832 : :
10833 : 259781 : ix86_expand_branch (GEU, current, limit, label);
10834 : 259781 : rtx_insn *jump_insn = get_last_insn ();
10835 : 259781 : JUMP_LABEL (jump_insn) = label;
10836 : :
10837 : : /* Mark the jump as very likely to be taken. */
10838 : 259781 : add_reg_br_prob_note (jump_insn, profile_probability::very_likely ());
10839 : :
10840 : 259781 : if (split_stack_fn == NULL_RTX)
10841 : : {
10842 : 5451 : split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack");
10843 : 4347 : SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL;
10844 : : }
10845 : 259781 : fn = split_stack_fn;
10846 : :
10847 : : /* Get more stack space. We pass in the desired stack space and the
10848 : : size of the arguments to copy to the new stack. In 32-bit mode
10849 : : we push the parameters; __morestack will return on a new stack
10850 : : anyhow. In 64-bit mode we pass the parameters in r10 and
10851 : : r11. */
10852 : 259781 : allocate_rtx = GEN_INT (allocate);
10853 : 259781 : args_size = crtl->args.size >= 0 ? (HOST_WIDE_INT) crtl->args.size : 0;
10854 : 259781 : call_fusage = NULL_RTX;
10855 : 259781 : rtx pop = NULL_RTX;
10856 : 259781 : if (TARGET_64BIT)
10857 : : {
10858 : 161873 : rtx reg10, reg11;
10859 : :
10860 : 161873 : reg10 = gen_rtx_REG (DImode, R10_REG);
10861 : 161873 : reg11 = gen_rtx_REG (DImode, R11_REG);
10862 : :
10863 : : /* If this function uses a static chain, it will be in %r10.
10864 : : Preserve it across the call to __morestack. */
10865 : 161873 : if (DECL_STATIC_CHAIN (cfun->decl))
10866 : : {
10867 : 7505 : rtx rax;
10868 : :
10869 : 7505 : rax = gen_rtx_REG (word_mode, AX_REG);
10870 : 7505 : emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG));
10871 : 7505 : use_reg (&call_fusage, rax);
10872 : : }
10873 : :
10874 : 161873 : if (flag_force_indirect_call
10875 : 161858 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
10876 : : {
10877 : 16 : HOST_WIDE_INT argval;
10878 : :
10879 : 16 : if (split_stack_fn_large == NULL_RTX)
10880 : : {
10881 : 7 : split_stack_fn_large
10882 : 7 : = gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model");
10883 : 7 : SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL;
10884 : : }
10885 : :
10886 : 16 : fn = split_stack_fn_large;
10887 : :
10888 : 16 : if (ix86_cmodel == CM_LARGE_PIC)
10889 : : {
10890 : 3 : rtx_code_label *label;
10891 : 3 : rtx x;
10892 : :
10893 : 3 : gcc_assert (Pmode == DImode);
10894 : :
10895 : 3 : label = gen_label_rtx ();
10896 : 3 : emit_label (label);
10897 : 3 : LABEL_PRESERVE_P (label) = 1;
10898 : 3 : emit_insn (gen_set_rip_rex64 (reg10, label));
10899 : 3 : emit_insn (gen_set_got_offset_rex64 (reg11, label));
10900 : 3 : emit_insn (gen_add2_insn (reg10, reg11));
10901 : 3 : x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fn), UNSPEC_GOT);
10902 : 3 : x = gen_rtx_CONST (Pmode, x);
10903 : 3 : emit_move_insn (reg11, x);
10904 : 3 : x = gen_rtx_PLUS (Pmode, reg10, reg11);
10905 : 3 : x = gen_const_mem (Pmode, x);
10906 : 3 : fn = copy_to_suggested_reg (x, reg11, Pmode);
10907 : : }
10908 : 13 : else if (ix86_cmodel == CM_LARGE)
10909 : 1 : fn = copy_to_suggested_reg (fn, reg11, Pmode);
10910 : :
10911 : : /* When using the large model we need to load the address
10912 : : into a register, and we've run out of registers. So we
10913 : : switch to a different calling convention, and we call a
10914 : : different function: __morestack_large. We pass the
10915 : : argument size in the upper 32 bits of r10 and pass the
10916 : : frame size in the lower 32 bits. */
10917 : 16 : gcc_assert ((allocate & HOST_WIDE_INT_C (0xffffffff)) == allocate);
10918 : 16 : gcc_assert ((args_size & 0xffffffff) == args_size);
10919 : :
10920 : 16 : argval = ((args_size << 16) << 16) + allocate;
10921 : 16 : emit_move_insn (reg10, GEN_INT (argval));
10922 : 16 : }
10923 : : else
10924 : : {
10925 : 161857 : emit_move_insn (reg10, allocate_rtx);
10926 : 161857 : emit_move_insn (reg11, GEN_INT (args_size));
10927 : 161857 : use_reg (&call_fusage, reg11);
10928 : : }
10929 : :
10930 : 161873 : use_reg (&call_fusage, reg10);
10931 : : }
10932 : : else
10933 : : {
10934 : 97908 : if (flag_force_indirect_call && flag_pic)
10935 : : {
10936 : 0 : rtx x;
10937 : :
10938 : 0 : gcc_assert (Pmode == SImode);
10939 : :
10940 : 0 : scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
10941 : :
10942 : 0 : emit_insn (gen_set_got (scratch_reg));
10943 : 0 : x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn),
10944 : : UNSPEC_GOT);
10945 : 0 : x = gen_rtx_CONST (Pmode, x);
10946 : 0 : x = gen_rtx_PLUS (Pmode, scratch_reg, x);
10947 : 0 : x = gen_const_mem (Pmode, x);
10948 : 0 : fn = copy_to_suggested_reg (x, scratch_reg, Pmode);
10949 : : }
10950 : :
10951 : 97908 : rtx_insn *insn = emit_insn (gen_push (GEN_INT (args_size)));
10952 : 195816 : add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (UNITS_PER_WORD));
10953 : 97908 : insn = emit_insn (gen_push (allocate_rtx));
10954 : 195816 : add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (2 * UNITS_PER_WORD));
10955 : 195816 : pop = GEN_INT (2 * UNITS_PER_WORD);
10956 : : }
10957 : :
10958 : 259781 : if (flag_force_indirect_call && !register_operand (fn, VOIDmode))
10959 : : {
10960 : 12 : scratch_reg = gen_rtx_REG (word_mode, scratch_regno);
10961 : :
10962 : 12 : if (GET_MODE (fn) != word_mode)
10963 : 0 : fn = gen_rtx_ZERO_EXTEND (word_mode, fn);
10964 : :
10965 : 12 : fn = copy_to_suggested_reg (fn, scratch_reg, word_mode);
10966 : : }
10967 : :
10968 : 259781 : call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn),
10969 : 259781 : GEN_INT (UNITS_PER_WORD), constm1_rtx,
10970 : : pop, false);
10971 : 259781 : add_function_usage_to (call_insn, call_fusage);
10972 : 259781 : if (!TARGET_64BIT)
10973 : 97908 : add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (0));
10974 : : /* Indicate that this function can't jump to non-local gotos. */
10975 : 259781 : make_reg_eh_region_note_nothrow_nononlocal (call_insn);
10976 : :
10977 : : /* In order to make call/return prediction work right, we now need
10978 : : to execute a return instruction. See
10979 : : libgcc/config/i386/morestack.S for the details on how this works.
10980 : :
10981 : : For flow purposes gcc must not see this as a return
10982 : : instruction--we need control flow to continue at the subsequent
10983 : : label. Therefore, we use an unspec. */
10984 : 259781 : gcc_assert (crtl->args.pops_args < 65536);
10985 : 259781 : rtx_insn *ret_insn
10986 : 259781 : = emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args)));
10987 : :
10988 : 259781 : if ((flag_cf_protection & CF_BRANCH))
10989 : : {
10990 : : /* Insert ENDBR since __morestack will jump back here via indirect
10991 : : call. */
10992 : 21 : rtx cet_eb = gen_nop_endbr ();
10993 : 21 : emit_insn_after (cet_eb, ret_insn);
10994 : : }
10995 : :
10996 : : /* If we are in 64-bit mode and this function uses a static chain,
10997 : : we saved %r10 in %rax before calling _morestack. */
10998 : 259781 : if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl))
10999 : 7505 : emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
11000 : : gen_rtx_REG (word_mode, AX_REG));
11001 : :
11002 : : /* If this function calls va_start, we need to store a pointer to
11003 : : the arguments on the old stack, because they may not have been
11004 : : all copied to the new stack. At this point the old stack can be
11005 : : found at the frame pointer value used by __morestack, because
11006 : : __morestack has set that up before calling back to us. Here we
11007 : : store that pointer in a scratch register, and in
11008 : : ix86_expand_prologue we store the scratch register in a stack
11009 : : slot. */
11010 : 259781 : if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
11011 : : {
11012 : 12 : rtx frame_reg;
11013 : 12 : int words;
11014 : :
11015 : 12 : scratch_regno = split_stack_prologue_scratch_regno ();
11016 : 16 : scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
11017 : 16 : frame_reg = gen_rtx_REG (Pmode, BP_REG);
11018 : :
11019 : : /* 64-bit:
11020 : : fp -> old fp value
11021 : : return address within this function
11022 : : return address of caller of this function
11023 : : stack arguments
11024 : : So we add three words to get to the stack arguments.
11025 : :
11026 : : 32-bit:
11027 : : fp -> old fp value
11028 : : return address within this function
11029 : : first argument to __morestack
11030 : : second argument to __morestack
11031 : : return address of caller of this function
11032 : : stack arguments
11033 : : So we add five words to get to the stack arguments.
11034 : : */
11035 : 12 : words = TARGET_64BIT ? 3 : 5;
11036 : 20 : emit_insn (gen_rtx_SET (scratch_reg,
11037 : : plus_constant (Pmode, frame_reg,
11038 : : words * UNITS_PER_WORD)));
11039 : :
11040 : 12 : varargs_label = gen_label_rtx ();
11041 : 12 : emit_jump_insn (gen_jump (varargs_label));
11042 : 12 : JUMP_LABEL (get_last_insn ()) = varargs_label;
11043 : :
11044 : 12 : emit_barrier ();
11045 : : }
11046 : :
11047 : 259781 : emit_label (label);
11048 : 259781 : LABEL_NUSES (label) = 1;
11049 : :
11050 : : /* If this function calls va_start, we now have to set the scratch
11051 : : register for the case where we do not call __morestack. In this
11052 : : case we need to set it based on the stack pointer. */
11053 : 259781 : if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
11054 : : {
11055 : 20 : emit_insn (gen_rtx_SET (scratch_reg,
11056 : : plus_constant (Pmode, stack_pointer_rtx,
11057 : : UNITS_PER_WORD)));
11058 : :
11059 : 12 : emit_label (varargs_label);
11060 : 12 : LABEL_NUSES (varargs_label) = 1;
11061 : : }
11062 : : }
11063 : :
11064 : : /* We may have to tell the dataflow pass that the split stack prologue
11065 : : is initializing a scratch register. */
11066 : :
11067 : : static void
11068 : 15580214 : ix86_live_on_entry (bitmap regs)
11069 : : {
11070 : 15580214 : if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
11071 : : {
11072 : 124 : gcc_assert (flag_split_stack);
11073 : 124 : bitmap_set_bit (regs, split_stack_prologue_scratch_regno ());
11074 : : }
11075 : 15580214 : }
11076 : :
11077 : : /* Extract the parts of an RTL expression that is a valid memory address
11078 : : for an instruction. Return false if the structure of the address is
11079 : : grossly off. */
11080 : :
11081 : : bool
11082 : 4306745040 : ix86_decompose_address (rtx addr, struct ix86_address *out)
11083 : : {
11084 : 4306745040 : rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
11085 : 4306745040 : rtx base_reg, index_reg;
11086 : 4306745040 : HOST_WIDE_INT scale = 1;
11087 : 4306745040 : rtx scale_rtx = NULL_RTX;
11088 : 4306745040 : rtx tmp;
11089 : 4306745040 : addr_space_t seg = ADDR_SPACE_GENERIC;
11090 : :
11091 : : /* Allow zero-extended SImode addresses,
11092 : : they will be emitted with addr32 prefix. */
11093 : 4306745040 : if (TARGET_64BIT && GET_MODE (addr) == DImode)
11094 : : {
11095 : 2225471973 : if (GET_CODE (addr) == ZERO_EXTEND
11096 : 2365858 : && GET_MODE (XEXP (addr, 0)) == SImode)
11097 : : {
11098 : 2262795 : addr = XEXP (addr, 0);
11099 : 2262795 : if (CONST_INT_P (addr))
11100 : : return false;
11101 : : }
11102 : 2223209178 : else if (GET_CODE (addr) == AND)
11103 : : {
11104 : 2598639 : rtx mask = XEXP (addr, 1);
11105 : 2598639 : rtx shift_val;
11106 : :
11107 : 2598639 : if (const_32bit_mask (mask, DImode)
11108 : : /* For ASHIFT inside AND, combine will not generate
11109 : : canonical zero-extend. Merge mask for AND and shift_count
11110 : : to check if it is canonical zero-extend. */
11111 : 2598639 : || (CONST_INT_P (mask)
11112 : 1714948 : && GET_CODE (XEXP (addr, 0)) == ASHIFT
11113 : 158259 : && CONST_INT_P (shift_val = XEXP (XEXP (addr, 0), 1))
11114 : 152661 : && ((UINTVAL (mask)
11115 : 152661 : | ((HOST_WIDE_INT_1U << INTVAL (shift_val)) - 1))
11116 : : == HOST_WIDE_INT_UC (0xffffffff))))
11117 : : {
11118 : 91058 : addr = lowpart_subreg (SImode, XEXP (addr, 0), DImode);
11119 : 91058 : if (addr == NULL_RTX)
11120 : : return false;
11121 : :
11122 : 91058 : if (CONST_INT_P (addr))
11123 : : return false;
11124 : : }
11125 : : }
11126 : : }
11127 : :
11128 : : /* Allow SImode subregs of DImode addresses,
11129 : : they will be emitted with addr32 prefix. */
11130 : 4306745040 : if (TARGET_64BIT && GET_MODE (addr) == SImode)
11131 : : {
11132 : 17453995 : if (SUBREG_P (addr)
11133 : 230502 : && GET_MODE (SUBREG_REG (addr)) == DImode)
11134 : : {
11135 : 208588 : addr = SUBREG_REG (addr);
11136 : 208588 : if (CONST_INT_P (addr))
11137 : : return false;
11138 : : }
11139 : : }
11140 : :
11141 : 4306745040 : if (REG_P (addr))
11142 : : base = addr;
11143 : : else if (SUBREG_P (addr))
11144 : : {
11145 : 478990 : if (REG_P (SUBREG_REG (addr)))
11146 : : base = addr;
11147 : : else
11148 : : return false;
11149 : : }
11150 : : else if (GET_CODE (addr) == PLUS)
11151 : : {
11152 : : rtx addends[4], op;
11153 : : int n = 0, i;
11154 : :
11155 : : op = addr;
11156 : 3167521888 : do
11157 : : {
11158 : 3167521888 : if (n >= 4)
11159 : 651272816 : return false;
11160 : 3167517951 : addends[n++] = XEXP (op, 1);
11161 : 3167517951 : op = XEXP (op, 0);
11162 : : }
11163 : 3167517951 : while (GET_CODE (op) == PLUS);
11164 : 3110377638 : if (n >= 4)
11165 : : return false;
11166 : 3110371550 : addends[n] = op;
11167 : :
11168 : 8087314840 : for (i = n; i >= 0; --i)
11169 : : {
11170 : 5628206081 : op = addends[i];
11171 : 5628206081 : switch (GET_CODE (op))
11172 : : {
11173 : 59876341 : case MULT:
11174 : 59876341 : if (index)
11175 : : return false;
11176 : 59837162 : index = XEXP (op, 0);
11177 : 59837162 : scale_rtx = XEXP (op, 1);
11178 : 59837162 : break;
11179 : :
11180 : 12613418 : case ASHIFT:
11181 : 12613418 : if (index)
11182 : : return false;
11183 : 12543276 : index = XEXP (op, 0);
11184 : 12543276 : tmp = XEXP (op, 1);
11185 : 12543276 : if (!CONST_INT_P (tmp))
11186 : : return false;
11187 : 12528887 : scale = INTVAL (tmp);
11188 : 12528887 : if ((unsigned HOST_WIDE_INT) scale > 3)
11189 : : return false;
11190 : 12119577 : scale = 1 << scale;
11191 : 12119577 : break;
11192 : :
11193 : 769342 : case ZERO_EXTEND:
11194 : 769342 : op = XEXP (op, 0);
11195 : 769342 : if (GET_CODE (op) != UNSPEC)
11196 : : return false;
11197 : : /* FALLTHRU */
11198 : :
11199 : 622811 : case UNSPEC:
11200 : 622811 : if (XINT (op, 1) == UNSPEC_TP
11201 : 615485 : && TARGET_TLS_DIRECT_SEG_REFS
11202 : 615485 : && seg == ADDR_SPACE_GENERIC)
11203 : 615485 : seg = DEFAULT_TLS_SEG_REG;
11204 : : else
11205 : : return false;
11206 : : break;
11207 : :
11208 : 469730 : case SUBREG:
11209 : 469730 : if (!REG_P (SUBREG_REG (op)))
11210 : : return false;
11211 : : /* FALLTHRU */
11212 : :
11213 : 2523705240 : case REG:
11214 : 2523705240 : if (!base)
11215 : : base = op;
11216 : 76383268 : else if (!index)
11217 : : index = op;
11218 : : else
11219 : : return false;
11220 : : break;
11221 : :
11222 : 2381429621 : case CONST:
11223 : 2381429621 : case CONST_INT:
11224 : 2381429621 : case SYMBOL_REF:
11225 : 2381429621 : case LABEL_REF:
11226 : 2381429621 : if (disp)
11227 : : return false;
11228 : : disp = op;
11229 : : break;
11230 : :
11231 : : default:
11232 : : return false;
11233 : : }
11234 : : }
11235 : : }
11236 : : else if (GET_CODE (addr) == MULT)
11237 : : {
11238 : 3423311 : index = XEXP (addr, 0); /* index*scale */
11239 : 3423311 : scale_rtx = XEXP (addr, 1);
11240 : : }
11241 : : else if (GET_CODE (addr) == ASHIFT)
11242 : : {
11243 : : /* We're called for lea too, which implements ashift on occasion. */
11244 : 3275722 : index = XEXP (addr, 0);
11245 : 3275722 : tmp = XEXP (addr, 1);
11246 : 3275722 : if (!CONST_INT_P (tmp))
11247 : : return false;
11248 : 2889329 : scale = INTVAL (tmp);
11249 : 2889329 : if ((unsigned HOST_WIDE_INT) scale > 3)
11250 : : return false;
11251 : 2128934 : scale = 1 << scale;
11252 : : }
11253 : : else
11254 : : disp = addr; /* displacement */
11255 : :
11256 : 2464661004 : if (index)
11257 : : {
11258 : 144458319 : if (REG_P (index))
11259 : : ;
11260 : 3760379 : else if (SUBREG_P (index)
11261 : 268847 : && REG_P (SUBREG_REG (index)))
11262 : : ;
11263 : : else
11264 : : return false;
11265 : : }
11266 : :
11267 : : /* Extract the integral value of scale. */
11268 : 3650772635 : if (scale_rtx)
11269 : : {
11270 : 55230239 : if (!CONST_INT_P (scale_rtx))
11271 : : return false;
11272 : 54667051 : scale = INTVAL (scale_rtx);
11273 : : }
11274 : :
11275 : 3650209447 : base_reg = base && SUBREG_P (base) ? SUBREG_REG (base) : base;
11276 : 3650209447 : index_reg = index && SUBREG_P (index) ? SUBREG_REG (index) : index;
11277 : :
11278 : : /* Avoid useless 0 displacement. */
11279 : 3650209447 : if (disp == const0_rtx && (base || index))
11280 : 3650209447 : disp = NULL_RTX;
11281 : :
11282 : : /* Allow arg pointer and stack pointer as index if there is not scaling. */
11283 : 2677533353 : if (base_reg && index_reg && scale == 1
11284 : 3725179274 : && (REGNO (index_reg) == ARG_POINTER_REGNUM
11285 : : || REGNO (index_reg) == FRAME_POINTER_REGNUM
11286 : : || REGNO (index_reg) == SP_REG))
11287 : : {
11288 : : std::swap (base, index);
11289 : : std::swap (base_reg, index_reg);
11290 : : }
11291 : :
11292 : : /* Special case: %ebp cannot be encoded as a base without a displacement.
11293 : : Similarly %r13. */
11294 : 314044065 : if (!disp && base_reg
11295 : 3960195336 : && (REGNO (base_reg) == ARG_POINTER_REGNUM
11296 : : || REGNO (base_reg) == FRAME_POINTER_REGNUM
11297 : : || REGNO (base_reg) == BP_REG
11298 : : || REGNO (base_reg) == R13_REG))
11299 : : disp = const0_rtx;
11300 : :
11301 : : /* Special case: on K6, [%esi] makes the instruction vector decoded.
11302 : : Avoid this by transforming to [%esi+0].
11303 : : Reload calls address legitimization without cfun defined, so we need
11304 : : to test cfun for being non-NULL. */
11305 : 0 : if (TARGET_CPU_P (K6) && cfun && optimize_function_for_speed_p (cfun)
11306 : 0 : && base_reg && !index_reg && !disp
11307 : 3650209447 : && REGNO (base_reg) == SI_REG)
11308 : 0 : disp = const0_rtx;
11309 : :
11310 : : /* Special case: encode reg+reg instead of reg*2. */
11311 : 3650209447 : if (!base && index && scale == 2)
11312 : 972676094 : base = index, base_reg = index_reg, scale = 1;
11313 : :
11314 : : /* Special case: scaling cannot be encoded without base or displacement. */
11315 : 972676094 : if (!base && !disp && index && scale != 1)
11316 : 3169412 : disp = const0_rtx;
11317 : :
11318 : 3650209447 : out->base = base;
11319 : 3650209447 : out->index = index;
11320 : 3650209447 : out->disp = disp;
11321 : 3650209447 : out->scale = scale;
11322 : 3650209447 : out->seg = seg;
11323 : :
11324 : 3650209447 : return true;
11325 : : }
11326 : :
11327 : : /* Return cost of the memory address x.
11328 : : For i386, it is better to use a complex address than let gcc copy
11329 : : the address into a reg and make a new pseudo. But not if the address
11330 : : requires to two regs - that would mean more pseudos with longer
11331 : : lifetimes. */
11332 : : static int
11333 : 10050801 : ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
11334 : : {
11335 : 10050801 : struct ix86_address parts;
11336 : 10050801 : int cost = 1;
11337 : 10050801 : int ok = ix86_decompose_address (x, &parts);
11338 : :
11339 : 10050801 : gcc_assert (ok);
11340 : :
11341 : 10050801 : if (parts.base && SUBREG_P (parts.base))
11342 : 268 : parts.base = SUBREG_REG (parts.base);
11343 : 10050801 : if (parts.index && SUBREG_P (parts.index))
11344 : 20 : parts.index = SUBREG_REG (parts.index);
11345 : :
11346 : : /* Attempt to minimize number of registers in the address by increasing
11347 : : address cost for each used register. We don't increase address cost
11348 : : for "pic_offset_table_rtx". When a memopt with "pic_offset_table_rtx"
11349 : : is not invariant itself it most likely means that base or index is not
11350 : : invariant. Therefore only "pic_offset_table_rtx" could be hoisted out,
11351 : : which is not profitable for x86. */
11352 : 10050801 : if (parts.base
11353 : 8724852 : && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
11354 : 18516895 : && (current_pass->type == GIMPLE_PASS
11355 : 2250528 : || !pic_offset_table_rtx
11356 : 116394 : || !REG_P (parts.base)
11357 : 116394 : || REGNO (pic_offset_table_rtx) != REGNO (parts.base)))
11358 : : cost++;
11359 : :
11360 : 10050801 : if (parts.index
11361 : 5040318 : && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
11362 : 15077638 : && (current_pass->type == GIMPLE_PASS
11363 : 544041 : || !pic_offset_table_rtx
11364 : 44120 : || !REG_P (parts.index)
11365 : 44120 : || REGNO (pic_offset_table_rtx) != REGNO (parts.index)))
11366 : 5025630 : cost++;
11367 : :
11368 : : /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
11369 : : since it's predecode logic can't detect the length of instructions
11370 : : and it degenerates to vector decoded. Increase cost of such
11371 : : addresses here. The penalty is minimally 2 cycles. It may be worthwhile
11372 : : to split such addresses or even refuse such addresses at all.
11373 : :
11374 : : Following addressing modes are affected:
11375 : : [base+scale*index]
11376 : : [scale*index+disp]
11377 : : [base+index]
11378 : :
11379 : : The first and last case may be avoidable by explicitly coding the zero in
11380 : : memory address, but I don't have AMD-K6 machine handy to check this
11381 : : theory. */
11382 : :
11383 : 10050801 : if (TARGET_CPU_P (K6)
11384 : 0 : && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
11385 : 0 : || (parts.disp && !parts.base && parts.index && parts.scale != 1)
11386 : 0 : || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
11387 : 0 : cost += 10;
11388 : :
11389 : 10050801 : return cost;
11390 : : }
11391 : :
11392 : : /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
11393 : : this is used for to form addresses to local data when -fPIC is in
11394 : : use. */
11395 : :
11396 : : static bool
11397 : 0 : darwin_local_data_pic (rtx disp)
11398 : : {
11399 : 0 : return (GET_CODE (disp) == UNSPEC
11400 : 0 : && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
11401 : : }
11402 : :
11403 : : /* True if the function symbol operand X should be loaded from GOT.
11404 : : If CALL_P is true, X is a call operand.
11405 : :
11406 : : NB: -mno-direct-extern-access doesn't force load from GOT for
11407 : : call.
11408 : :
11409 : : NB: In 32-bit mode, only non-PIC is allowed in inline assembly
11410 : : statements, since a PIC register could not be available at the
11411 : : call site. */
11412 : :
11413 : : bool
11414 : 1803447734 : ix86_force_load_from_GOT_p (rtx x, bool call_p)
11415 : : {
11416 : 94481148 : return ((TARGET_64BIT || (!flag_pic && HAVE_AS_IX86_GOT32X))
11417 : : && !TARGET_PECOFF && !TARGET_MACHO
11418 : 1800637819 : && (!flag_pic || this_is_asm_operands)
11419 : 1780984259 : && ix86_cmodel != CM_LARGE
11420 : 1780978479 : && ix86_cmodel != CM_LARGE_PIC
11421 : 1780978478 : && GET_CODE (x) == SYMBOL_REF
11422 : 1780978476 : && ((!call_p
11423 : 1775584899 : && (!ix86_direct_extern_access
11424 : 1775583535 : || (SYMBOL_REF_DECL (x)
11425 : 1589376189 : && lookup_attribute ("nodirect_extern_access",
11426 : 1589376189 : DECL_ATTRIBUTES (SYMBOL_REF_DECL (x))))))
11427 : 1780976667 : || (SYMBOL_REF_FUNCTION_P (x)
11428 : 668908930 : && (!flag_plt
11429 : 668904611 : || (SYMBOL_REF_DECL (x)
11430 : 668904611 : && lookup_attribute ("noplt",
11431 : 668904611 : DECL_ATTRIBUTES (SYMBOL_REF_DECL (x)))))))
11432 : 1803454253 : && !SYMBOL_REF_LOCAL_P (x));
11433 : : }
11434 : :
11435 : : /* Determine if a given RTX is a valid constant. We already know this
11436 : : satisfies CONSTANT_P. */
11437 : :
11438 : : static bool
11439 : 1527284220 : ix86_legitimate_constant_p (machine_mode mode, rtx x)
11440 : : {
11441 : 1527284220 : switch (GET_CODE (x))
11442 : : {
11443 : 132190967 : case CONST:
11444 : 132190967 : x = XEXP (x, 0);
11445 : :
11446 : 132190967 : if (GET_CODE (x) == PLUS)
11447 : : {
11448 : 132077049 : if (!CONST_INT_P (XEXP (x, 1)))
11449 : : return false;
11450 : 132077049 : x = XEXP (x, 0);
11451 : : }
11452 : :
11453 : 132190967 : if (TARGET_MACHO && darwin_local_data_pic (x))
11454 : : return true;
11455 : :
11456 : : /* Only some unspecs are valid as "constants". */
11457 : 132190967 : if (GET_CODE (x) == UNSPEC)
11458 : 476967 : switch (XINT (x, 1))
11459 : : {
11460 : 21254 : case UNSPEC_GOT:
11461 : 21254 : case UNSPEC_GOTOFF:
11462 : 21254 : case UNSPEC_PLTOFF:
11463 : 21254 : return TARGET_64BIT;
11464 : 454879 : case UNSPEC_TPOFF:
11465 : 454879 : case UNSPEC_NTPOFF:
11466 : 454879 : x = XVECEXP (x, 0, 0);
11467 : 454879 : return (GET_CODE (x) == SYMBOL_REF
11468 : 454879 : && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
11469 : 748 : case UNSPEC_DTPOFF:
11470 : 748 : x = XVECEXP (x, 0, 0);
11471 : 748 : return (GET_CODE (x) == SYMBOL_REF
11472 : 748 : && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
11473 : 0 : case UNSPEC_SECREL32:
11474 : 0 : x = XVECEXP (x, 0, 0);
11475 : 0 : return GET_CODE (x) == SYMBOL_REF;
11476 : : default:
11477 : : return false;
11478 : : }
11479 : :
11480 : : /* We must have drilled down to a symbol. */
11481 : 131714000 : if (GET_CODE (x) == LABEL_REF)
11482 : : return true;
11483 : 131710175 : if (GET_CODE (x) != SYMBOL_REF)
11484 : : return false;
11485 : : /* FALLTHRU */
11486 : :
11487 : 903477149 : case SYMBOL_REF:
11488 : : /* TLS symbols are never valid. */
11489 : 903477149 : if (SYMBOL_REF_TLS_MODEL (x))
11490 : : return false;
11491 : :
11492 : : /* DLLIMPORT symbols are never valid. */
11493 : 903382044 : if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
11494 : : && SYMBOL_REF_DLLIMPORT_P (x))
11495 : : return false;
11496 : :
11497 : : #if TARGET_MACHO
11498 : : /* mdynamic-no-pic */
11499 : : if (MACHO_DYNAMIC_NO_PIC_P)
11500 : : return machopic_symbol_defined_p (x);
11501 : : #endif
11502 : :
11503 : : /* External function address should be loaded
11504 : : via the GOT slot to avoid PLT. */
11505 : 903382044 : if (ix86_force_load_from_GOT_p (x))
11506 : : return false;
11507 : :
11508 : : break;
11509 : :
11510 : 603008443 : CASE_CONST_SCALAR_INT:
11511 : 603008443 : if (ix86_endbr_immediate_operand (x, VOIDmode))
11512 : : return false;
11513 : :
11514 : 603008242 : switch (mode)
11515 : : {
11516 : 1567581 : case E_TImode:
11517 : 1567581 : if (TARGET_64BIT)
11518 : : return true;
11519 : : /* FALLTHRU */
11520 : 21509 : case E_OImode:
11521 : 21509 : case E_XImode:
11522 : 21509 : if (!standard_sse_constant_p (x, mode)
11523 : 34591 : && GET_MODE_SIZE (TARGET_AVX512F
11524 : : ? XImode
11525 : : : (TARGET_AVX
11526 : : ? OImode
11527 : : : (TARGET_SSE2
11528 : 13082 : ? TImode : DImode))) < GET_MODE_SIZE (mode))
11529 : : return false;
11530 : : default:
11531 : : break;
11532 : : }
11533 : : break;
11534 : :
11535 : 8166028 : case CONST_VECTOR:
11536 : 8166028 : if (!standard_sse_constant_p (x, mode))
11537 : : return false;
11538 : : break;
11539 : :
11540 : 7659526 : case CONST_DOUBLE:
11541 : 7659526 : if (mode == E_BFmode)
11542 : : return false;
11543 : :
11544 : : default:
11545 : : break;
11546 : : }
11547 : :
11548 : : /* Otherwise we handle everything else in the move patterns. */
11549 : : return true;
11550 : : }
11551 : :
11552 : : /* Determine if it's legal to put X into the constant pool. This
11553 : : is not possible for the address of thread-local symbols, which
11554 : : is checked above. */
11555 : :
11556 : : static bool
11557 : 61240192 : ix86_cannot_force_const_mem (machine_mode mode, rtx x)
11558 : : {
11559 : : /* We can put any immediate constant in memory. */
11560 : 61240192 : switch (GET_CODE (x))
11561 : : {
11562 : : CASE_CONST_ANY:
11563 : : return false;
11564 : :
11565 : 1766908 : default:
11566 : 1766908 : break;
11567 : : }
11568 : :
11569 : 1766908 : return !ix86_legitimate_constant_p (mode, x);
11570 : : }
11571 : :
11572 : : /* Return a unique alias set for the GOT. */
11573 : :
11574 : : alias_set_type
11575 : 184172 : ix86_GOT_alias_set (void)
11576 : : {
11577 : 184172 : static alias_set_type set = -1;
11578 : 184172 : if (set == -1)
11579 : 2892 : set = new_alias_set ();
11580 : 184172 : return set;
11581 : : }
11582 : :
11583 : : /* Nonzero if the constant value X is a legitimate general operand
11584 : : when generating PIC code. It is given that flag_pic is on and
11585 : : that X satisfies CONSTANT_P. */
11586 : :
11587 : : bool
11588 : 122476163 : legitimate_pic_operand_p (rtx x)
11589 : : {
11590 : 122476163 : rtx inner;
11591 : :
11592 : 122476163 : switch (GET_CODE (x))
11593 : : {
11594 : 2453112 : case CONST:
11595 : 2453112 : inner = XEXP (x, 0);
11596 : 2453112 : if (GET_CODE (inner) == PLUS
11597 : 348654 : && CONST_INT_P (XEXP (inner, 1)))
11598 : 348654 : inner = XEXP (inner, 0);
11599 : :
11600 : : /* Only some unspecs are valid as "constants". */
11601 : 2453112 : if (GET_CODE (inner) == UNSPEC)
11602 : 2211732 : switch (XINT (inner, 1))
11603 : : {
11604 : 2151341 : case UNSPEC_GOT:
11605 : 2151341 : case UNSPEC_GOTOFF:
11606 : 2151341 : case UNSPEC_PLTOFF:
11607 : 2151341 : return TARGET_64BIT;
11608 : 0 : case UNSPEC_TPOFF:
11609 : 0 : x = XVECEXP (inner, 0, 0);
11610 : 0 : return (GET_CODE (x) == SYMBOL_REF
11611 : 0 : && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
11612 : 0 : case UNSPEC_SECREL32:
11613 : 0 : x = XVECEXP (inner, 0, 0);
11614 : 0 : return GET_CODE (x) == SYMBOL_REF;
11615 : 0 : case UNSPEC_MACHOPIC_OFFSET:
11616 : 0 : return legitimate_pic_address_disp_p (x);
11617 : : default:
11618 : : return false;
11619 : : }
11620 : : /* FALLTHRU */
11621 : :
11622 : 6688606 : case SYMBOL_REF:
11623 : 6688606 : case LABEL_REF:
11624 : 6688606 : return legitimate_pic_address_disp_p (x);
11625 : :
11626 : : default:
11627 : : return true;
11628 : : }
11629 : : }
11630 : :
11631 : : /* Determine if a given CONST RTX is a valid memory displacement
11632 : : in PIC mode. */
11633 : :
11634 : : bool
11635 : 62063159 : legitimate_pic_address_disp_p (rtx disp)
11636 : : {
11637 : 62063159 : bool saw_plus;
11638 : :
11639 : : /* In 64bit mode we can allow direct addresses of symbols and labels
11640 : : when they are not dynamic symbols. */
11641 : 62063159 : if (TARGET_64BIT)
11642 : : {
11643 : 37949295 : rtx op0 = disp, op1;
11644 : :
11645 : 37949295 : switch (GET_CODE (disp))
11646 : : {
11647 : : case LABEL_REF:
11648 : : return true;
11649 : :
11650 : 10504488 : case CONST:
11651 : 10504488 : if (GET_CODE (XEXP (disp, 0)) != PLUS)
11652 : : break;
11653 : 1112435 : op0 = XEXP (XEXP (disp, 0), 0);
11654 : 1112435 : op1 = XEXP (XEXP (disp, 0), 1);
11655 : 1112435 : if (!CONST_INT_P (op1))
11656 : : break;
11657 : 1112435 : if (GET_CODE (op0) == UNSPEC
11658 : 293 : && (XINT (op0, 1) == UNSPEC_DTPOFF
11659 : 293 : || XINT (op0, 1) == UNSPEC_NTPOFF)
11660 : 1112728 : && trunc_int_for_mode (INTVAL (op1), SImode) == INTVAL (op1))
11661 : : return true;
11662 : 1112142 : if (INTVAL (op1) >= 16*1024*1024
11663 : 1112142 : || INTVAL (op1) < -16*1024*1024)
11664 : : break;
11665 : 1112054 : if (GET_CODE (op0) == LABEL_REF)
11666 : : return true;
11667 : 1112054 : if (GET_CODE (op0) == CONST
11668 : 0 : && GET_CODE (XEXP (op0, 0)) == UNSPEC
11669 : 0 : && XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL)
11670 : : return true;
11671 : 1112054 : if (GET_CODE (op0) == UNSPEC
11672 : 0 : && XINT (op0, 1) == UNSPEC_PCREL)
11673 : : return true;
11674 : 1112054 : if (GET_CODE (op0) != SYMBOL_REF)
11675 : : break;
11676 : : /* FALLTHRU */
11677 : :
11678 : 28343026 : case SYMBOL_REF:
11679 : : /* TLS references should always be enclosed in UNSPEC.
11680 : : The dllimported symbol needs always to be resolved. */
11681 : 28343026 : if (SYMBOL_REF_TLS_MODEL (op0)
11682 : : || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0)))
11683 : : return false;
11684 : :
11685 : 28193315 : if (TARGET_PECOFF)
11686 : : {
11687 : : #if TARGET_PECOFF
11688 : : if (is_imported_p (op0))
11689 : : return true;
11690 : : #endif
11691 : :
11692 : : if (SYMBOL_REF_FAR_ADDR_P (op0) || !SYMBOL_REF_LOCAL_P (op0))
11693 : : break;
11694 : :
11695 : : /* Non-external-weak function symbols need to be resolved only
11696 : : for the large model. Non-external symbols don't need to be
11697 : : resolved for large and medium models. For the small model,
11698 : : we don't need to resolve anything here. */
11699 : : if ((ix86_cmodel != CM_LARGE_PIC
11700 : : && SYMBOL_REF_FUNCTION_P (op0)
11701 : : && !(SYMBOL_REF_EXTERNAL_P (op0) && SYMBOL_REF_WEAK (op0)))
11702 : : || !SYMBOL_REF_EXTERNAL_P (op0)
11703 : : || ix86_cmodel == CM_SMALL_PIC)
11704 : : return true;
11705 : : }
11706 : 28193315 : else if (!SYMBOL_REF_FAR_ADDR_P (op0)
11707 : 28193311 : && (SYMBOL_REF_LOCAL_P (op0)
11708 : 17072337 : || ((ix86_direct_extern_access
11709 : 33933498 : && !(SYMBOL_REF_DECL (op0)
11710 : 16861320 : && lookup_attribute ("nodirect_extern_access",
11711 : 16861320 : DECL_ATTRIBUTES (SYMBOL_REF_DECL (op0)))))
11712 : : && HAVE_LD_PIE_COPYRELOC
11713 : 17072019 : && flag_pie
11714 : 37248 : && !SYMBOL_REF_WEAK (op0)
11715 : 36860 : && !SYMBOL_REF_FUNCTION_P (op0)))
11716 : 39322031 : && ix86_cmodel != CM_LARGE_PIC)
11717 : : return true;
11718 : : break;
11719 : :
11720 : : default:
11721 : : break;
11722 : : }
11723 : : }
11724 : 50574302 : if (GET_CODE (disp) != CONST)
11725 : : return false;
11726 : 14494920 : disp = XEXP (disp, 0);
11727 : :
11728 : 14494920 : if (TARGET_64BIT)
11729 : : {
11730 : : /* We are unsafe to allow PLUS expressions. This limit allowed distance
11731 : : of GOT tables. We should not need these anyway. */
11732 : 9442601 : if (GET_CODE (disp) != UNSPEC
11733 : 9392053 : || (XINT (disp, 1) != UNSPEC_GOTPCREL
11734 : 9392053 : && XINT (disp, 1) != UNSPEC_GOTOFF
11735 : : && XINT (disp, 1) != UNSPEC_PCREL
11736 : : && XINT (disp, 1) != UNSPEC_PLTOFF))
11737 : : return false;
11738 : :
11739 : 9392053 : if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
11740 : 9392053 : && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
11741 : : return false;
11742 : : return true;
11743 : : }
11744 : :
11745 : 5052319 : saw_plus = false;
11746 : 5052319 : if (GET_CODE (disp) == PLUS)
11747 : : {
11748 : 576651 : if (!CONST_INT_P (XEXP (disp, 1)))
11749 : : return false;
11750 : 576651 : disp = XEXP (disp, 0);
11751 : 576651 : saw_plus = true;
11752 : : }
11753 : :
11754 : 5052319 : if (TARGET_MACHO && darwin_local_data_pic (disp))
11755 : : return true;
11756 : :
11757 : 5052319 : if (GET_CODE (disp) != UNSPEC)
11758 : : return false;
11759 : :
11760 : 4892687 : switch (XINT (disp, 1))
11761 : : {
11762 : 2221907 : case UNSPEC_GOT:
11763 : 2221907 : if (saw_plus)
11764 : : return false;
11765 : : /* We need to check for both symbols and labels because VxWorks loads
11766 : : text labels with @GOT rather than @GOTOFF. See gotoff_operand for
11767 : : details. */
11768 : 2221906 : return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
11769 : 2221906 : || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
11770 : 2670780 : case UNSPEC_GOTOFF:
11771 : : /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
11772 : : While ABI specify also 32bit relocation but we don't produce it in
11773 : : small PIC model at all. */
11774 : 2670780 : if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
11775 : 2670780 : || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
11776 : : && !TARGET_64BIT)
11777 : 5341560 : return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
11778 : : return false;
11779 : 0 : case UNSPEC_GOTTPOFF:
11780 : 0 : case UNSPEC_GOTNTPOFF:
11781 : 0 : case UNSPEC_INDNTPOFF:
11782 : 0 : if (saw_plus)
11783 : : return false;
11784 : 0 : disp = XVECEXP (disp, 0, 0);
11785 : 0 : return (GET_CODE (disp) == SYMBOL_REF
11786 : 0 : && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
11787 : 0 : case UNSPEC_NTPOFF:
11788 : 0 : disp = XVECEXP (disp, 0, 0);
11789 : 0 : return (GET_CODE (disp) == SYMBOL_REF
11790 : 0 : && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
11791 : 0 : case UNSPEC_DTPOFF:
11792 : 0 : disp = XVECEXP (disp, 0, 0);
11793 : 0 : return (GET_CODE (disp) == SYMBOL_REF
11794 : 0 : && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
11795 : 0 : case UNSPEC_SECREL32:
11796 : 0 : disp = XVECEXP (disp, 0, 0);
11797 : 0 : return GET_CODE (disp) == SYMBOL_REF;
11798 : : }
11799 : :
11800 : : return false;
11801 : : }
11802 : :
11803 : : /* Determine if op is suitable RTX for an address register.
11804 : : Return naked register if a register or a register subreg is
11805 : : found, otherwise return NULL_RTX. */
11806 : :
11807 : : static rtx
11808 : 1339357311 : ix86_validate_address_register (rtx op)
11809 : : {
11810 : 1339357311 : machine_mode mode = GET_MODE (op);
11811 : :
11812 : : /* Only SImode or DImode registers can form the address. */
11813 : 1339357311 : if (mode != SImode && mode != DImode)
11814 : : return NULL_RTX;
11815 : :
11816 : 1339349837 : if (REG_P (op))
11817 : : return op;
11818 : 704110 : else if (SUBREG_P (op))
11819 : : {
11820 : 704110 : rtx reg = SUBREG_REG (op);
11821 : :
11822 : 704110 : if (!REG_P (reg))
11823 : : return NULL_RTX;
11824 : :
11825 : 704110 : mode = GET_MODE (reg);
11826 : :
11827 : : /* Don't allow SUBREGs that span more than a word. It can
11828 : : lead to spill failures when the register is one word out
11829 : : of a two word structure. */
11830 : 1453070 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
11831 : : return NULL_RTX;
11832 : :
11833 : : /* Allow only SUBREGs of non-eliminable hard registers. */
11834 : 195027 : if (register_no_elim_operand (reg, mode))
11835 : : return reg;
11836 : : }
11837 : :
11838 : : /* Op is not a register. */
11839 : : return NULL_RTX;
11840 : : }
11841 : :
11842 : : /* Determine which memory address register set insn can use. */
11843 : :
11844 : : static enum attr_addr
11845 : 249599111 : ix86_memory_address_reg_class (rtx_insn* insn)
11846 : : {
11847 : : /* LRA can do some initialization with NULL insn,
11848 : : return maximum register class in this case. */
11849 : 249599111 : enum attr_addr addr_rclass = ADDR_GPR32;
11850 : :
11851 : 249599111 : if (!insn)
11852 : : return addr_rclass;
11853 : :
11854 : 71373685 : if (asm_noperands (PATTERN (insn)) >= 0
11855 : 71373685 : || GET_CODE (PATTERN (insn)) == ASM_INPUT)
11856 : 59814 : return ix86_apx_inline_asm_use_gpr32 ? ADDR_GPR32 : ADDR_GPR16;
11857 : :
11858 : : /* Return maximum register class for unrecognized instructions. */
11859 : 71343778 : if (INSN_CODE (insn) < 0)
11860 : : return addr_rclass;
11861 : :
11862 : : /* Try to recognize the insn before calling get_attr_addr.
11863 : : Save current recog_data and current alternative. */
11864 : 71343778 : struct recog_data_d saved_recog_data = recog_data;
11865 : 71343778 : int saved_alternative = which_alternative;
11866 : :
11867 : : /* Update recog_data for processing of alternatives. */
11868 : 71343778 : extract_insn_cached (insn);
11869 : :
11870 : : /* If current alternative is not set, loop throught enabled
11871 : : alternatives and get the most limited register class. */
11872 : 71343778 : if (saved_alternative == -1)
11873 : : {
11874 : 71343778 : alternative_mask enabled = get_enabled_alternatives (insn);
11875 : :
11876 : 1234012901 : for (int i = 0; i < recog_data.n_alternatives; i++)
11877 : : {
11878 : 1162669123 : if (!TEST_BIT (enabled, i))
11879 : 344215190 : continue;
11880 : :
11881 : 818453933 : which_alternative = i;
11882 : 818453933 : addr_rclass = MIN (addr_rclass, get_attr_addr (insn));
11883 : : }
11884 : : }
11885 : : else
11886 : : {
11887 : 0 : which_alternative = saved_alternative;
11888 : 0 : addr_rclass = get_attr_addr (insn);
11889 : : }
11890 : :
11891 : 71343778 : recog_data = saved_recog_data;
11892 : 71343778 : which_alternative = saved_alternative;
11893 : :
11894 : 71343778 : return addr_rclass;
11895 : : }
11896 : :
11897 : : /* Return memory address register class insn can use. */
11898 : :
11899 : : enum reg_class
11900 : 209745590 : ix86_insn_base_reg_class (rtx_insn* insn)
11901 : : {
11902 : 209745590 : switch (ix86_memory_address_reg_class (insn))
11903 : : {
11904 : : case ADDR_GPR8:
11905 : : return LEGACY_GENERAL_REGS;
11906 : : case ADDR_GPR16:
11907 : : return GENERAL_GPR16;
11908 : : case ADDR_GPR32:
11909 : : break;
11910 : 0 : default:
11911 : 0 : gcc_unreachable ();
11912 : : }
11913 : :
11914 : : return BASE_REG_CLASS;
11915 : : }
11916 : :
11917 : : bool
11918 : 1130200 : ix86_regno_ok_for_insn_base_p (int regno, rtx_insn* insn)
11919 : : {
11920 : 1130200 : switch (ix86_memory_address_reg_class (insn))
11921 : : {
11922 : 0 : case ADDR_GPR8:
11923 : 0 : return LEGACY_INT_REGNO_P (regno);
11924 : 0 : case ADDR_GPR16:
11925 : 0 : return GENERAL_GPR16_REGNO_P (regno);
11926 : 1130200 : case ADDR_GPR32:
11927 : 1130200 : break;
11928 : 0 : default:
11929 : 0 : gcc_unreachable ();
11930 : : }
11931 : :
11932 : 1130200 : return GENERAL_REGNO_P (regno);
11933 : : }
11934 : :
11935 : : enum reg_class
11936 : 38723321 : ix86_insn_index_reg_class (rtx_insn* insn)
11937 : : {
11938 : 38723321 : switch (ix86_memory_address_reg_class (insn))
11939 : : {
11940 : : case ADDR_GPR8:
11941 : : return LEGACY_INDEX_REGS;
11942 : : case ADDR_GPR16:
11943 : : return INDEX_GPR16;
11944 : : case ADDR_GPR32:
11945 : : break;
11946 : 0 : default:
11947 : 0 : gcc_unreachable ();
11948 : : }
11949 : :
11950 : : return INDEX_REG_CLASS;
11951 : : }
11952 : :
11953 : : /* Recognizes RTL expressions that are valid memory addresses for an
11954 : : instruction. The MODE argument is the machine mode for the MEM
11955 : : expression that wants to use this address.
11956 : :
11957 : : It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should
11958 : : convert common non-canonical forms to canonical form so that they will
11959 : : be recognized. */
11960 : :
11961 : : static bool
11962 : 2194236092 : ix86_legitimate_address_p (machine_mode, rtx addr, bool strict,
11963 : : code_helper = ERROR_MARK)
11964 : : {
11965 : 2194236092 : struct ix86_address parts;
11966 : 2194236092 : rtx base, index, disp;
11967 : 2194236092 : HOST_WIDE_INT scale;
11968 : 2194236092 : addr_space_t seg;
11969 : :
11970 : 2194236092 : if (ix86_decompose_address (addr, &parts) == 0)
11971 : : /* Decomposition failed. */
11972 : : return false;
11973 : :
11974 : 2183136794 : base = parts.base;
11975 : 2183136794 : index = parts.index;
11976 : 2183136794 : disp = parts.disp;
11977 : 2183136794 : scale = parts.scale;
11978 : 2183136794 : seg = parts.seg;
11979 : :
11980 : : /* Validate base register. */
11981 : 2183136794 : if (base)
11982 : : {
11983 : 1259002214 : rtx reg = ix86_validate_address_register (base);
11984 : :
11985 : 1259002214 : if (reg == NULL_RTX)
11986 : : return false;
11987 : :
11988 : 1258543009 : unsigned int regno = REGNO (reg);
11989 : 1258543009 : if ((strict && !REGNO_OK_FOR_BASE_P (regno))
11990 : 1254161395 : || (!strict && !REGNO_OK_FOR_BASE_NONSTRICT_P (regno)))
11991 : : /* Base is not valid. */
11992 : : return false;
11993 : : }
11994 : :
11995 : : /* Validate index register. */
11996 : 2181351464 : if (index)
11997 : : {
11998 : 80355097 : rtx reg = ix86_validate_address_register (index);
11999 : :
12000 : 80355097 : if (reg == NULL_RTX)
12001 : : return false;
12002 : :
12003 : 80297565 : unsigned int regno = REGNO (reg);
12004 : 80297565 : if ((strict && !REGNO_OK_FOR_INDEX_P (regno))
12005 : 80288619 : || (!strict && !REGNO_OK_FOR_INDEX_NONSTRICT_P (regno)))
12006 : : /* Index is not valid. */
12007 : : return false;
12008 : : }
12009 : :
12010 : : /* Index and base should have the same mode. */
12011 : 2181292806 : if (base && index
12012 : 70771337 : && GET_MODE (base) != GET_MODE (index))
12013 : : return false;
12014 : :
12015 : : /* Address override works only on the (%reg) part of %fs:(%reg). */
12016 : 2181280690 : if (seg != ADDR_SPACE_GENERIC
12017 : 2181280690 : && ((base && GET_MODE (base) != word_mode)
12018 : 303947 : || (index && GET_MODE (index) != word_mode)))
12019 : : return false;
12020 : :
12021 : : /* Validate scale factor. */
12022 : 2181280661 : if (scale != 1)
12023 : : {
12024 : 39289571 : if (!index)
12025 : : /* Scale without index. */
12026 : : return false;
12027 : :
12028 : 39289571 : if (scale != 2 && scale != 4 && scale != 8)
12029 : : /* Scale is not a valid multiplier. */
12030 : : return false;
12031 : : }
12032 : :
12033 : : /* Validate displacement. */
12034 : 2178157340 : if (disp)
12035 : : {
12036 : 1960101789 : if (ix86_endbr_immediate_operand (disp, VOIDmode))
12037 : : return false;
12038 : :
12039 : 1960101746 : if (GET_CODE (disp) == CONST
12040 : 141920444 : && GET_CODE (XEXP (disp, 0)) == UNSPEC
12041 : 14804280 : && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
12042 : 14804280 : switch (XINT (XEXP (disp, 0), 1))
12043 : : {
12044 : : /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit
12045 : : when used. While ABI specify also 32bit relocations, we
12046 : : don't produce them at all and use IP relative instead.
12047 : : Allow GOT in 32bit mode for both PIC and non-PIC if symbol
12048 : : should be loaded via GOT. */
12049 : 2221957 : case UNSPEC_GOT:
12050 : 2221957 : if (!TARGET_64BIT
12051 : 2221957 : && ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
12052 : 0 : goto is_legitimate_pic;
12053 : : /* FALLTHRU */
12054 : 4475770 : case UNSPEC_GOTOFF:
12055 : 4475770 : gcc_assert (flag_pic);
12056 : 4475770 : if (!TARGET_64BIT)
12057 : 4475668 : goto is_legitimate_pic;
12058 : :
12059 : : /* 64bit address unspec. */
12060 : : return false;
12061 : :
12062 : 9392025 : case UNSPEC_GOTPCREL:
12063 : 9392025 : if (ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
12064 : 2484 : goto is_legitimate_pic;
12065 : : /* FALLTHRU */
12066 : 9389541 : case UNSPEC_PCREL:
12067 : 9389541 : gcc_assert (flag_pic);
12068 : 9389541 : goto is_legitimate_pic;
12069 : :
12070 : : case UNSPEC_GOTTPOFF:
12071 : : case UNSPEC_GOTNTPOFF:
12072 : : case UNSPEC_INDNTPOFF:
12073 : : case UNSPEC_NTPOFF:
12074 : : case UNSPEC_DTPOFF:
12075 : : case UNSPEC_SECREL32:
12076 : : break;
12077 : :
12078 : : default:
12079 : : /* Invalid address unspec. */
12080 : : return false;
12081 : : }
12082 : :
12083 : 1238797626 : else if (SYMBOLIC_CONST (disp)
12084 : 2072413630 : && (flag_pic
12085 : : #if TARGET_MACHO
12086 : : || (MACHOPIC_INDIRECT
12087 : : && !machopic_operand_p (disp))
12088 : : #endif
12089 : : ))
12090 : : {
12091 : :
12092 : 55216744 : is_legitimate_pic:
12093 : 55216744 : if (TARGET_64BIT && (index || base))
12094 : : {
12095 : : /* foo@dtpoff(%rX) is ok. */
12096 : 36087 : if (GET_CODE (disp) != CONST
12097 : 6763 : || GET_CODE (XEXP (disp, 0)) != PLUS
12098 : 6763 : || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
12099 : 4439 : || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
12100 : 4439 : || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
12101 : 4439 : && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF
12102 : 0 : && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_SECREL32))
12103 : : /* Non-constant pic memory reference. */
12104 : : return false;
12105 : : }
12106 : 55180657 : else if ((!TARGET_MACHO || flag_pic)
12107 : 55180657 : && ! legitimate_pic_address_disp_p (disp))
12108 : : /* Displacement is an invalid pic construct. */
12109 : : return false;
12110 : : #if TARGET_MACHO
12111 : : else if (MACHO_DYNAMIC_NO_PIC_P
12112 : : && !ix86_legitimate_constant_p (Pmode, disp))
12113 : : /* displacment must be referenced via non_lazy_pointer */
12114 : : return false;
12115 : : #endif
12116 : :
12117 : : /* This code used to verify that a symbolic pic displacement
12118 : : includes the pic_offset_table_rtx register.
12119 : :
12120 : : While this is good idea, unfortunately these constructs may
12121 : : be created by "adds using lea" optimization for incorrect
12122 : : code like:
12123 : :
12124 : : int a;
12125 : : int foo(int i)
12126 : : {
12127 : : return *(&a+i);
12128 : : }
12129 : :
12130 : : This code is nonsensical, but results in addressing
12131 : : GOT table with pic_offset_table_rtx base. We can't
12132 : : just refuse it easily, since it gets matched by
12133 : : "addsi3" pattern, that later gets split to lea in the
12134 : : case output register differs from input. While this
12135 : : can be handled by separate addsi pattern for this case
12136 : : that never results in lea, this seems to be easier and
12137 : : correct fix for crash to disable this test. */
12138 : : }
12139 : 1903948415 : else if (GET_CODE (disp) != LABEL_REF
12140 : 1903700873 : && !CONST_INT_P (disp)
12141 : 849031875 : && (GET_CODE (disp) != CONST
12142 : 128503939 : || !ix86_legitimate_constant_p (Pmode, disp))
12143 : 2627322132 : && (GET_CODE (disp) != SYMBOL_REF
12144 : 729886518 : || !ix86_legitimate_constant_p (Pmode, disp)))
12145 : : /* Displacement is not constant. */
12146 : 57082789 : return false;
12147 : 1846865626 : else if (TARGET_64BIT
12148 : 1846865626 : && !x86_64_immediate_operand (disp, VOIDmode))
12149 : : /* Displacement is out of range. */
12150 : : return false;
12151 : : /* In x32 mode, constant addresses are sign extended to 64bit, so
12152 : : we have to prevent addresses from 0x80000000 to 0xffffffff. */
12153 : 45501 : else if (TARGET_X32 && !(index || base)
12154 : 16755 : && CONST_INT_P (disp)
12155 : 1846400953 : && val_signbit_known_set_p (SImode, INTVAL (disp)))
12156 : : return false;
12157 : : }
12158 : :
12159 : : /* Everything looks valid. */
12160 : : return true;
12161 : : }
12162 : :
12163 : : /* Determine if a given RTX is a valid constant address. */
12164 : :
12165 : : bool
12166 : 2621675000 : constant_address_p (rtx x)
12167 : : {
12168 : 2699534418 : return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
12169 : : }
12170 : :
12171 : :
12172 : : /* Return a legitimate reference for ORIG (an address) using the
12173 : : register REG. If REG is 0, a new pseudo is generated.
12174 : :
12175 : : There are two types of references that must be handled:
12176 : :
12177 : : 1. Global data references must load the address from the GOT, via
12178 : : the PIC reg. An insn is emitted to do this load, and the reg is
12179 : : returned.
12180 : :
12181 : : 2. Static data references, constant pool addresses, and code labels
12182 : : compute the address as an offset from the GOT, whose base is in
12183 : : the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
12184 : : differentiate them from global data objects. The returned
12185 : : address is the PIC reg + an unspec constant.
12186 : :
12187 : : TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
12188 : : reg also appears in the address. */
12189 : :
12190 : : rtx
12191 : 391147 : legitimize_pic_address (rtx orig, rtx reg)
12192 : : {
12193 : 391147 : rtx addr = orig;
12194 : 391147 : rtx new_rtx = orig;
12195 : :
12196 : : #if TARGET_MACHO
12197 : : if (TARGET_MACHO && !TARGET_64BIT)
12198 : : {
12199 : : if (reg == 0)
12200 : : reg = gen_reg_rtx (Pmode);
12201 : : /* Use the generic Mach-O PIC machinery. */
12202 : : return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
12203 : : }
12204 : : #endif
12205 : :
12206 : 391147 : if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES)
12207 : : {
12208 : : #if TARGET_PECOFF
12209 : : rtx tmp = legitimize_pe_coff_symbol (addr, true);
12210 : : if (tmp)
12211 : : return tmp;
12212 : : #endif
12213 : : }
12214 : :
12215 : 391147 : if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
12216 : : new_rtx = addr;
12217 : 296874 : else if ((!TARGET_64BIT
12218 : 99623 : || /* TARGET_64BIT && */ ix86_cmodel != CM_SMALL_PIC)
12219 : : && !TARGET_PECOFF
12220 : 494204 : && gotoff_operand (addr, Pmode))
12221 : : {
12222 : : /* This symbol may be referenced via a displacement
12223 : : from the PIC base address (@GOTOFF). */
12224 : 95169 : if (GET_CODE (addr) == CONST)
12225 : 2971 : addr = XEXP (addr, 0);
12226 : :
12227 : 95169 : if (GET_CODE (addr) == PLUS)
12228 : : {
12229 : 5942 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
12230 : : UNSPEC_GOTOFF);
12231 : 5942 : new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
12232 : : }
12233 : : else
12234 : 184384 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
12235 : :
12236 : 190326 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12237 : :
12238 : 95169 : if (TARGET_64BIT)
12239 : 12 : new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
12240 : :
12241 : 95169 : if (reg != 0)
12242 : : {
12243 : 3 : gcc_assert (REG_P (reg));
12244 : 3 : new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx,
12245 : : new_rtx, reg, 1, OPTAB_DIRECT);
12246 : : }
12247 : : else
12248 : 190323 : new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
12249 : : }
12250 : 376276 : else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
12251 : : /* We can't always use @GOTOFF for text labels
12252 : : on VxWorks, see gotoff_operand. */
12253 : 201705 : || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
12254 : : {
12255 : : #if TARGET_PECOFF
12256 : : rtx tmp = legitimize_pe_coff_symbol (addr, true);
12257 : : if (tmp)
12258 : : return tmp;
12259 : : #endif
12260 : :
12261 : : /* For x64 PE-COFF there is no GOT table,
12262 : : so we use address directly. */
12263 : 174568 : if (TARGET_64BIT && TARGET_PECOFF)
12264 : : {
12265 : : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
12266 : : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12267 : : }
12268 : 174568 : else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
12269 : : {
12270 : 92487 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
12271 : : UNSPEC_GOTPCREL);
12272 : 92487 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12273 : 92487 : new_rtx = gen_const_mem (Pmode, new_rtx);
12274 : 92484 : set_mem_alias_set (new_rtx, GOT_ALIAS_SET);
12275 : : }
12276 : : else
12277 : : {
12278 : : /* This symbol must be referenced via a load
12279 : : from the Global Offset Table (@GOT). */
12280 : 164146 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
12281 : 164146 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12282 : :
12283 : 82084 : if (TARGET_64BIT)
12284 : 22 : new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
12285 : :
12286 : 82084 : if (reg != 0)
12287 : : {
12288 : 0 : gcc_assert (REG_P (reg));
12289 : 0 : new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx,
12290 : : new_rtx, reg, 1, OPTAB_DIRECT);
12291 : : }
12292 : : else
12293 : 164146 : new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
12294 : :
12295 : 164146 : new_rtx = gen_const_mem (Pmode, new_rtx);
12296 : 82084 : set_mem_alias_set (new_rtx, GOT_ALIAS_SET);
12297 : : }
12298 : :
12299 : 256633 : new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
12300 : : }
12301 : : else
12302 : : {
12303 : 27137 : if (CONST_INT_P (addr)
12304 : 27137 : && !x86_64_immediate_operand (addr, VOIDmode))
12305 : 8 : new_rtx = copy_to_suggested_reg (addr, reg, Pmode);
12306 : 27129 : else if (GET_CODE (addr) == CONST)
12307 : : {
12308 : 16898 : addr = XEXP (addr, 0);
12309 : :
12310 : : /* We must match stuff we generate before. Assume the only
12311 : : unspecs that can get here are ours. Not that we could do
12312 : : anything with them anyway.... */
12313 : 16898 : if (GET_CODE (addr) == UNSPEC
12314 : 9006 : || (GET_CODE (addr) == PLUS
12315 : 9006 : && GET_CODE (XEXP (addr, 0)) == UNSPEC))
12316 : : return orig;
12317 : 6726 : gcc_assert (GET_CODE (addr) == PLUS);
12318 : : }
12319 : :
12320 : 16965 : if (GET_CODE (addr) == PLUS)
12321 : : {
12322 : 8483 : rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
12323 : :
12324 : : /* Check first to see if this is a constant
12325 : : offset from a @GOTOFF symbol reference. */
12326 : 8483 : if (!TARGET_PECOFF
12327 : 13413 : && gotoff_operand (op0, Pmode)
12328 : 8483 : && CONST_INT_P (op1))
12329 : : {
12330 : 4 : if (!TARGET_64BIT)
12331 : : {
12332 : 0 : new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
12333 : : UNSPEC_GOTOFF);
12334 : 0 : new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
12335 : 0 : new_rtx = gen_rtx_CONST (Pmode, new_rtx);
12336 : :
12337 : 0 : if (reg != 0)
12338 : : {
12339 : 0 : gcc_assert (REG_P (reg));
12340 : 0 : new_rtx = expand_simple_binop (Pmode, PLUS,
12341 : : pic_offset_table_rtx,
12342 : : new_rtx, reg, 1,
12343 : : OPTAB_DIRECT);
12344 : : }
12345 : : else
12346 : 0 : new_rtx
12347 : 0 : = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
12348 : : }
12349 : : else
12350 : : {
12351 : 4 : if (INTVAL (op1) < -16*1024*1024
12352 : 4 : || INTVAL (op1) >= 16*1024*1024)
12353 : : {
12354 : 4 : if (!x86_64_immediate_operand (op1, Pmode))
12355 : 4 : op1 = force_reg (Pmode, op1);
12356 : :
12357 : 4 : new_rtx
12358 : 4 : = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
12359 : : }
12360 : : }
12361 : : }
12362 : : else
12363 : : {
12364 : 8479 : rtx base = legitimize_pic_address (op0, reg);
12365 : 8479 : machine_mode mode = GET_MODE (base);
12366 : 8479 : new_rtx
12367 : 8479 : = legitimize_pic_address (op1, base == reg ? NULL_RTX : reg);
12368 : :
12369 : 8479 : if (CONST_INT_P (new_rtx))
12370 : : {
12371 : 6714 : if (INTVAL (new_rtx) < -16*1024*1024
12372 : 6714 : || INTVAL (new_rtx) >= 16*1024*1024)
12373 : : {
12374 : 0 : if (!x86_64_immediate_operand (new_rtx, mode))
12375 : 0 : new_rtx = force_reg (mode, new_rtx);
12376 : :
12377 : 0 : new_rtx
12378 : 0 : = gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx);
12379 : : }
12380 : : else
12381 : 6714 : new_rtx = plus_constant (mode, base, INTVAL (new_rtx));
12382 : : }
12383 : : else
12384 : : {
12385 : : /* For %rip addressing, we have to use
12386 : : just disp32, not base nor index. */
12387 : 1765 : if (TARGET_64BIT
12388 : 99 : && (GET_CODE (base) == SYMBOL_REF
12389 : 99 : || GET_CODE (base) == LABEL_REF))
12390 : 7 : base = force_reg (mode, base);
12391 : 1765 : if (GET_CODE (new_rtx) == PLUS
12392 : 1644 : && CONSTANT_P (XEXP (new_rtx, 1)))
12393 : : {
12394 : 1640 : base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0));
12395 : 1640 : new_rtx = XEXP (new_rtx, 1);
12396 : : }
12397 : 1765 : new_rtx = gen_rtx_PLUS (mode, base, new_rtx);
12398 : : }
12399 : : }
12400 : : }
12401 : : }
12402 : : return new_rtx;
12403 : : }
12404 : :
12405 : : /* Load the thread pointer. If TO_REG is true, force it into a register. */
12406 : :
12407 : : static rtx
12408 : 22483 : get_thread_pointer (machine_mode tp_mode, bool to_reg)
12409 : : {
12410 : 22483 : rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
12411 : :
12412 : 22483 : if (GET_MODE (tp) != tp_mode)
12413 : : {
12414 : 11 : gcc_assert (GET_MODE (tp) == SImode);
12415 : 11 : gcc_assert (tp_mode == DImode);
12416 : :
12417 : 11 : tp = gen_rtx_ZERO_EXTEND (tp_mode, tp);
12418 : : }
12419 : :
12420 : 22483 : if (to_reg)
12421 : 7769 : tp = copy_to_mode_reg (tp_mode, tp);
12422 : :
12423 : 22483 : return tp;
12424 : : }
12425 : :
12426 : : /* Construct the SYMBOL_REF for the _tls_index symbol. */
12427 : :
12428 : : static GTY(()) rtx ix86_tls_index_symbol;
12429 : :
12430 : : #if TARGET_WIN32_TLS
12431 : : static rtx
12432 : : ix86_tls_index (void)
12433 : : {
12434 : : if (!ix86_tls_index_symbol)
12435 : : ix86_tls_index_symbol = gen_rtx_SYMBOL_REF (SImode, "_tls_index");
12436 : :
12437 : : if (flag_pic)
12438 : : return gen_rtx_CONST (Pmode, gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_index_symbol), UNSPEC_PCREL));
12439 : : else
12440 : : return ix86_tls_index_symbol;
12441 : : }
12442 : : #endif
12443 : :
12444 : : /* Construct the SYMBOL_REF for the tls_get_addr function. */
12445 : :
12446 : : static GTY(()) rtx ix86_tls_symbol;
12447 : :
12448 : : static rtx
12449 : 6585 : ix86_tls_get_addr (void)
12450 : : {
12451 : 6585 : if (!ix86_tls_symbol)
12452 : : {
12453 : 354 : const char *sym
12454 : 391 : = ((TARGET_ANY_GNU_TLS && !TARGET_64BIT)
12455 : 391 : ? "___tls_get_addr" : "__tls_get_addr");
12456 : :
12457 : 428 : ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym);
12458 : : }
12459 : :
12460 : 6585 : if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF)
12461 : : {
12462 : 0 : rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol),
12463 : : UNSPEC_PLTOFF);
12464 : 0 : return gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
12465 : : gen_rtx_CONST (Pmode, unspec));
12466 : : }
12467 : :
12468 : 6585 : return ix86_tls_symbol;
12469 : : }
12470 : :
12471 : : /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol. */
12472 : :
12473 : : static GTY(()) rtx ix86_tls_module_base_symbol;
12474 : :
12475 : : rtx
12476 : 18 : ix86_tls_module_base (void)
12477 : : {
12478 : 18 : if (!ix86_tls_module_base_symbol)
12479 : : {
12480 : 3 : ix86_tls_module_base_symbol
12481 : 3 : = gen_rtx_SYMBOL_REF (ptr_mode, "_TLS_MODULE_BASE_");
12482 : :
12483 : 3 : SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
12484 : 3 : |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
12485 : : }
12486 : :
12487 : 18 : return ix86_tls_module_base_symbol;
12488 : : }
12489 : :
12490 : : /* A subroutine of ix86_legitimize_address and ix86_expand_move. FOR_MOV is
12491 : : false if we expect this to be used for a memory address and true if
12492 : : we expect to load the address into a register. */
12493 : :
12494 : : rtx
12495 : 29068 : legitimize_tls_address (rtx x, enum tls_model model, bool for_mov)
12496 : : {
12497 : 29068 : rtx dest, base, off;
12498 : 29068 : rtx pic = NULL_RTX, tp = NULL_RTX;
12499 : 29068 : machine_mode tp_mode = Pmode;
12500 : 29068 : int type;
12501 : :
12502 : : #if TARGET_WIN32_TLS
12503 : : off = gen_const_mem (SImode, ix86_tls_index ());
12504 : : set_mem_alias_set (off, GOT_ALIAS_SET);
12505 : :
12506 : : tp = gen_const_mem (Pmode, GEN_INT (TARGET_64BIT ? 88 : 44));
12507 : : set_mem_addr_space (tp, DEFAULT_TLS_SEG_REG);
12508 : :
12509 : : if (TARGET_64BIT)
12510 : : off = convert_to_mode (Pmode, off, 1);
12511 : :
12512 : : base = force_reg (Pmode, off);
12513 : : tp = copy_to_mode_reg (Pmode, tp);
12514 : :
12515 : : tp = gen_const_mem (Pmode, gen_rtx_PLUS (Pmode, tp, gen_rtx_MULT (Pmode, base, GEN_INT (UNITS_PER_WORD))));
12516 : : set_mem_alias_set (tp, GOT_ALIAS_SET);
12517 : :
12518 : : base = force_reg (Pmode, tp);
12519 : :
12520 : : return gen_rtx_PLUS (Pmode, base, gen_rtx_CONST (Pmode, gen_rtx_UNSPEC (SImode, gen_rtvec (1, x), UNSPEC_SECREL32)));
12521 : : #else
12522 : : /* Fall back to global dynamic model if tool chain cannot support local
12523 : : dynamic. */
12524 : 29068 : if (TARGET_SUN_TLS && !TARGET_64BIT
12525 : : && !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM
12526 : : && model == TLS_MODEL_LOCAL_DYNAMIC)
12527 : : model = TLS_MODEL_GLOBAL_DYNAMIC;
12528 : :
12529 : 29068 : switch (model)
12530 : : {
12531 : 6164 : case TLS_MODEL_GLOBAL_DYNAMIC:
12532 : 6164 : if (!TARGET_64BIT)
12533 : : {
12534 : 1901 : if (flag_pic && !TARGET_PECOFF)
12535 : 1901 : pic = pic_offset_table_rtx;
12536 : : else
12537 : : {
12538 : 0 : pic = gen_reg_rtx (Pmode);
12539 : 0 : emit_insn (gen_set_got (pic));
12540 : : }
12541 : : }
12542 : :
12543 : 6164 : if (TARGET_GNU2_TLS)
12544 : : {
12545 : 14 : dest = gen_reg_rtx (ptr_mode);
12546 : 14 : if (TARGET_64BIT)
12547 : 14 : emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, dest, x));
12548 : : else
12549 : 0 : emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic));
12550 : :
12551 : 14 : tp = get_thread_pointer (ptr_mode, true);
12552 : 14 : dest = gen_rtx_PLUS (ptr_mode, tp, dest);
12553 : 22 : if (GET_MODE (dest) != Pmode)
12554 : 6 : dest = gen_rtx_ZERO_EXTEND (Pmode, dest);
12555 : 22 : dest = force_reg (Pmode, dest);
12556 : :
12557 : 22 : if (GET_MODE (x) != Pmode)
12558 : 3 : x = gen_rtx_ZERO_EXTEND (Pmode, x);
12559 : :
12560 : 14 : set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
12561 : : }
12562 : : else
12563 : : {
12564 : 6150 : rtx caddr = ix86_tls_get_addr ();
12565 : :
12566 : 8051 : dest = gen_reg_rtx (Pmode);
12567 : 6150 : if (TARGET_64BIT)
12568 : : {
12569 : 4249 : rtx rax = gen_rtx_REG (Pmode, AX_REG);
12570 : 4249 : rtx_insn *insns;
12571 : :
12572 : 4249 : start_sequence ();
12573 : 4249 : emit_call_insn
12574 : 4249 : (gen_tls_global_dynamic_64 (Pmode, rax, x, caddr));
12575 : 4249 : insns = end_sequence ();
12576 : :
12577 : 4249 : if (GET_MODE (x) != Pmode)
12578 : 1 : x = gen_rtx_ZERO_EXTEND (Pmode, x);
12579 : :
12580 : 4249 : RTL_CONST_CALL_P (insns) = 1;
12581 : 4249 : emit_libcall_block (insns, dest, rax, x);
12582 : : }
12583 : : else
12584 : 1901 : emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr));
12585 : : }
12586 : : break;
12587 : :
12588 : 443 : case TLS_MODEL_LOCAL_DYNAMIC:
12589 : 443 : if (!TARGET_64BIT)
12590 : : {
12591 : 110 : if (flag_pic)
12592 : 110 : pic = pic_offset_table_rtx;
12593 : : else
12594 : : {
12595 : 0 : pic = gen_reg_rtx (Pmode);
12596 : 0 : emit_insn (gen_set_got (pic));
12597 : : }
12598 : : }
12599 : :
12600 : 443 : if (TARGET_GNU2_TLS)
12601 : : {
12602 : 8 : rtx tmp = ix86_tls_module_base ();
12603 : :
12604 : 8 : base = gen_reg_rtx (ptr_mode);
12605 : 8 : if (TARGET_64BIT)
12606 : 8 : emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, base, tmp));
12607 : : else
12608 : 0 : emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic));
12609 : :
12610 : 8 : tp = get_thread_pointer (ptr_mode, true);
12611 : 14 : if (GET_MODE (base) != Pmode)
12612 : 2 : base = gen_rtx_ZERO_EXTEND (Pmode, base);
12613 : 14 : base = force_reg (Pmode, base);
12614 : : }
12615 : : else
12616 : : {
12617 : 435 : rtx caddr = ix86_tls_get_addr ();
12618 : :
12619 : 545 : base = gen_reg_rtx (Pmode);
12620 : 435 : if (TARGET_64BIT)
12621 : : {
12622 : 325 : rtx rax = gen_rtx_REG (Pmode, AX_REG);
12623 : 325 : rtx_insn *insns;
12624 : 325 : rtx eqv;
12625 : :
12626 : 325 : start_sequence ();
12627 : 325 : emit_call_insn
12628 : 325 : (gen_tls_local_dynamic_base_64 (Pmode, rax, caddr));
12629 : 325 : insns = end_sequence ();
12630 : :
12631 : : /* Attach a unique REG_EQUAL, to allow the RTL optimizers to
12632 : : share the LD_BASE result with other LD model accesses. */
12633 : 325 : eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12634 : : UNSPEC_TLS_LD_BASE);
12635 : :
12636 : 325 : RTL_CONST_CALL_P (insns) = 1;
12637 : 325 : emit_libcall_block (insns, base, rax, eqv);
12638 : : }
12639 : : else
12640 : 110 : emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr));
12641 : : }
12642 : :
12643 : 559 : off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
12644 : 559 : off = gen_rtx_CONST (Pmode, off);
12645 : :
12646 : 675 : dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
12647 : :
12648 : 443 : if (TARGET_GNU2_TLS)
12649 : : {
12650 : 14 : if (GET_MODE (tp) != Pmode)
12651 : : {
12652 : 2 : dest = lowpart_subreg (ptr_mode, dest, Pmode);
12653 : 2 : dest = gen_rtx_PLUS (ptr_mode, tp, dest);
12654 : 2 : dest = gen_rtx_ZERO_EXTEND (Pmode, dest);
12655 : : }
12656 : : else
12657 : 6 : dest = gen_rtx_PLUS (Pmode, tp, dest);
12658 : 14 : dest = force_reg (Pmode, dest);
12659 : :
12660 : 14 : if (GET_MODE (x) != Pmode)
12661 : 1 : x = gen_rtx_ZERO_EXTEND (Pmode, x);
12662 : :
12663 : 8 : set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
12664 : : }
12665 : : break;
12666 : :
12667 : 9584 : case TLS_MODEL_INITIAL_EXEC:
12668 : 9584 : if (TARGET_64BIT)
12669 : : {
12670 : : /* Generate DImode references to avoid %fs:(%reg32)
12671 : : problems and linker IE->LE relaxation bug. */
12672 : : tp_mode = DImode;
12673 : : pic = NULL;
12674 : : type = UNSPEC_GOTNTPOFF;
12675 : : }
12676 : 744 : else if (flag_pic)
12677 : : {
12678 : 743 : pic = pic_offset_table_rtx;
12679 : 743 : type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
12680 : : }
12681 : 1 : else if (!TARGET_ANY_GNU_TLS)
12682 : : {
12683 : 0 : pic = gen_reg_rtx (Pmode);
12684 : 0 : emit_insn (gen_set_got (pic));
12685 : 0 : type = UNSPEC_GOTTPOFF;
12686 : : }
12687 : : else
12688 : : {
12689 : : pic = NULL;
12690 : : type = UNSPEC_INDNTPOFF;
12691 : : }
12692 : :
12693 : 9584 : off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type);
12694 : 9584 : off = gen_rtx_CONST (tp_mode, off);
12695 : 9584 : if (pic)
12696 : 743 : off = gen_rtx_PLUS (tp_mode, pic, off);
12697 : 9584 : off = gen_const_mem (tp_mode, off);
12698 : 9584 : set_mem_alias_set (off, GOT_ALIAS_SET);
12699 : :
12700 : 9584 : if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
12701 : : {
12702 : 9584 : base = get_thread_pointer (tp_mode,
12703 : 9584 : for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
12704 : 9584 : off = force_reg (tp_mode, off);
12705 : 9584 : dest = gen_rtx_PLUS (tp_mode, base, off);
12706 : 10332 : if (tp_mode != Pmode)
12707 : 4 : dest = convert_to_mode (Pmode, dest, 1);
12708 : : }
12709 : : else
12710 : : {
12711 : 0 : base = get_thread_pointer (Pmode, true);
12712 : 0 : dest = gen_reg_rtx (Pmode);
12713 : 0 : emit_insn (gen_sub3_insn (dest, base, off));
12714 : : }
12715 : : break;
12716 : :
12717 : 12877 : case TLS_MODEL_LOCAL_EXEC:
12718 : 26505 : off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
12719 : : (TARGET_64BIT || TARGET_ANY_GNU_TLS)
12720 : : ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
12721 : 13628 : off = gen_rtx_CONST (Pmode, off);
12722 : :
12723 : 12877 : if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
12724 : : {
12725 : 13628 : base = get_thread_pointer (Pmode,
12726 : 12877 : for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
12727 : 13628 : return gen_rtx_PLUS (Pmode, base, off);
12728 : : }
12729 : : else
12730 : : {
12731 : 0 : base = get_thread_pointer (Pmode, true);
12732 : 0 : dest = gen_reg_rtx (Pmode);
12733 : 0 : emit_insn (gen_sub3_insn (dest, base, off));
12734 : : }
12735 : 0 : break;
12736 : :
12737 : 0 : default:
12738 : 0 : gcc_unreachable ();
12739 : : }
12740 : :
12741 : : return dest;
12742 : : #endif
12743 : : }
12744 : :
12745 : : /* Return true if the TLS address requires insn using integer registers.
12746 : : It's used to prevent KMOV/VMOV in TLS code sequences which require integer
12747 : : MOV instructions, refer to PR103275. */
12748 : : bool
12749 : 15326250 : ix86_gpr_tls_address_pattern_p (rtx mem)
12750 : : {
12751 : 15326250 : gcc_assert (MEM_P (mem));
12752 : :
12753 : 15326250 : rtx addr = XEXP (mem, 0);
12754 : 15326250 : subrtx_var_iterator::array_type array;
12755 : 53271221 : FOR_EACH_SUBRTX_VAR (iter, array, addr, ALL)
12756 : : {
12757 : 37951878 : rtx op = *iter;
12758 : 37951878 : if (GET_CODE (op) == UNSPEC)
12759 : 197301 : switch (XINT (op, 1))
12760 : : {
12761 : : case UNSPEC_GOTNTPOFF:
12762 : 6907 : return true;
12763 : 0 : case UNSPEC_TPOFF:
12764 : 0 : if (!TARGET_64BIT)
12765 : : return true;
12766 : : break;
12767 : : default:
12768 : : break;
12769 : : }
12770 : : }
12771 : :
12772 : 15319343 : return false;
12773 : 15326250 : }
12774 : :
12775 : : /* Return true if OP refers to a TLS address. */
12776 : : bool
12777 : 230120108 : ix86_tls_address_pattern_p (rtx op)
12778 : : {
12779 : 230120108 : subrtx_var_iterator::array_type array;
12780 : 1364668872 : FOR_EACH_SUBRTX_VAR (iter, array, op, ALL)
12781 : : {
12782 : 1134565037 : rtx op = *iter;
12783 : 1134565037 : if (MEM_P (op))
12784 : : {
12785 : 102884673 : rtx *x = &XEXP (op, 0);
12786 : 162619037 : while (GET_CODE (*x) == PLUS)
12787 : : {
12788 : : int i;
12789 : 179219388 : for (i = 0; i < 2; i++)
12790 : : {
12791 : 119485024 : rtx u = XEXP (*x, i);
12792 : 119485024 : if (GET_CODE (u) == ZERO_EXTEND)
12793 : 86040 : u = XEXP (u, 0);
12794 : 119485024 : if (GET_CODE (u) == UNSPEC
12795 : 16295 : && XINT (u, 1) == UNSPEC_TP)
12796 : 16273 : return true;
12797 : : }
12798 : 59734364 : x = &XEXP (*x, 0);
12799 : : }
12800 : :
12801 : 102868400 : iter.skip_subrtxes ();
12802 : : }
12803 : : }
12804 : :
12805 : 230103835 : return false;
12806 : 230120108 : }
12807 : :
12808 : : /* Rewrite *LOC so that it refers to a default TLS address space. */
12809 : : static void
12810 : 16273 : ix86_rewrite_tls_address_1 (rtx *loc)
12811 : : {
12812 : 16273 : subrtx_ptr_iterator::array_type array;
12813 : 48982 : FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
12814 : : {
12815 : 48982 : rtx *loc = *iter;
12816 : 48982 : if (MEM_P (*loc))
12817 : : {
12818 : 16454 : rtx addr = XEXP (*loc, 0);
12819 : 16454 : rtx *x = &addr;
12820 : 21197 : while (GET_CODE (*x) == PLUS)
12821 : : {
12822 : : int i;
12823 : 30525 : for (i = 0; i < 2; i++)
12824 : : {
12825 : 25782 : rtx u = XEXP (*x, i);
12826 : 25782 : if (GET_CODE (u) == ZERO_EXTEND)
12827 : 19 : u = XEXP (u, 0);
12828 : 25782 : if (GET_CODE (u) == UNSPEC
12829 : 16273 : && XINT (u, 1) == UNSPEC_TP)
12830 : : {
12831 : : /* NB: Since address override only applies to the
12832 : : (reg32) part in fs:(reg32), return if address
12833 : : override is used. */
12834 : 17842 : if (Pmode != word_mode
12835 : 16273 : && REG_P (XEXP (*x, 1 - i)))
12836 : 16273 : return;
12837 : :
12838 : 16271 : addr_space_t as = DEFAULT_TLS_SEG_REG;
12839 : :
12840 : 16271 : *x = XEXP (*x, 1 - i);
12841 : :
12842 : 16271 : *loc = replace_equiv_address_nv (*loc, addr, true);
12843 : 16271 : set_mem_addr_space (*loc, as);
12844 : 16271 : return;
12845 : : }
12846 : : }
12847 : 4743 : x = &XEXP (*x, 0);
12848 : : }
12849 : :
12850 : 181 : iter.skip_subrtxes ();
12851 : : }
12852 : : }
12853 : 16273 : }
12854 : :
12855 : : /* Rewrite instruction pattern involvning TLS address
12856 : : so that it refers to a default TLS address space. */
12857 : : rtx
12858 : 16273 : ix86_rewrite_tls_address (rtx pattern)
12859 : : {
12860 : 16273 : pattern = copy_insn (pattern);
12861 : 16273 : ix86_rewrite_tls_address_1 (&pattern);
12862 : 16273 : return pattern;
12863 : : }
12864 : :
12865 : : /* Try machine-dependent ways of modifying an illegitimate address
12866 : : to be legitimate. If we find one, return the new, valid address.
12867 : : This macro is used in only one place: `memory_address' in explow.cc.
12868 : :
12869 : : OLDX is the address as it was before break_out_memory_refs was called.
12870 : : In some cases it is useful to look at this to decide what needs to be done.
12871 : :
12872 : : It is always safe for this macro to do nothing. It exists to recognize
12873 : : opportunities to optimize the output.
12874 : :
12875 : : For the 80386, we handle X+REG by loading X into a register R and
12876 : : using R+REG. R will go in a general reg and indexing will be used.
12877 : : However, if REG is a broken-out memory address or multiplication,
12878 : : nothing needs to be done because REG can certainly go in a general reg.
12879 : :
12880 : : When -fpic is used, special handling is needed for symbolic references.
12881 : : See comments by legitimize_pic_address in i386.cc for details. */
12882 : :
12883 : : static rtx
12884 : 574638 : ix86_legitimize_address (rtx x, rtx, machine_mode mode)
12885 : : {
12886 : 574638 : bool changed = false;
12887 : 574638 : unsigned log;
12888 : :
12889 : 574638 : log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
12890 : 148734 : if (log)
12891 : 19242 : return legitimize_tls_address (x, (enum tls_model) log, false);
12892 : 555396 : if (GET_CODE (x) == CONST
12893 : 507 : && GET_CODE (XEXP (x, 0)) == PLUS
12894 : 507 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
12895 : 555903 : && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
12896 : : {
12897 : 4 : rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
12898 : : (enum tls_model) log, false);
12899 : 5 : return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
12900 : : }
12901 : :
12902 : 555392 : if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
12903 : : {
12904 : : #if TARGET_PECOFF
12905 : : rtx tmp = legitimize_pe_coff_symbol (x, true);
12906 : : if (tmp)
12907 : : return tmp;
12908 : : #endif
12909 : : }
12910 : :
12911 : 555392 : if (flag_pic && SYMBOLIC_CONST (x))
12912 : 129876 : return legitimize_pic_address (x, 0);
12913 : :
12914 : : #if TARGET_MACHO
12915 : : if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x))
12916 : : return machopic_indirect_data_reference (x, 0);
12917 : : #endif
12918 : :
12919 : : /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
12920 : 425516 : if (GET_CODE (x) == ASHIFT
12921 : 0 : && CONST_INT_P (XEXP (x, 1))
12922 : 0 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
12923 : : {
12924 : 0 : changed = true;
12925 : 0 : log = INTVAL (XEXP (x, 1));
12926 : 0 : x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
12927 : : GEN_INT (1 << log));
12928 : : }
12929 : :
12930 : 425516 : if (GET_CODE (x) == PLUS)
12931 : : {
12932 : : /* Canonicalize shifts by 0, 1, 2, 3 into multiply. */
12933 : :
12934 : 96055 : if (GET_CODE (XEXP (x, 0)) == ASHIFT
12935 : 512 : && CONST_INT_P (XEXP (XEXP (x, 0), 1))
12936 : 512 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
12937 : : {
12938 : 512 : changed = true;
12939 : 512 : log = INTVAL (XEXP (XEXP (x, 0), 1));
12940 : 1492 : XEXP (x, 0) = gen_rtx_MULT (Pmode,
12941 : : force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
12942 : : GEN_INT (1 << log));
12943 : : }
12944 : :
12945 : 96055 : if (GET_CODE (XEXP (x, 1)) == ASHIFT
12946 : 0 : && CONST_INT_P (XEXP (XEXP (x, 1), 1))
12947 : 0 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
12948 : : {
12949 : 0 : changed = true;
12950 : 0 : log = INTVAL (XEXP (XEXP (x, 1), 1));
12951 : 0 : XEXP (x, 1) = gen_rtx_MULT (Pmode,
12952 : : force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
12953 : : GEN_INT (1 << log));
12954 : : }
12955 : :
12956 : : /* Put multiply first if it isn't already. */
12957 : 96055 : if (GET_CODE (XEXP (x, 1)) == MULT)
12958 : : {
12959 : 0 : std::swap (XEXP (x, 0), XEXP (x, 1));
12960 : 0 : changed = true;
12961 : : }
12962 : :
12963 : : /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
12964 : : into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be
12965 : : created by virtual register instantiation, register elimination, and
12966 : : similar optimizations. */
12967 : 96055 : if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
12968 : : {
12969 : 9713 : changed = true;
12970 : 15331 : x = gen_rtx_PLUS (Pmode,
12971 : : gen_rtx_PLUS (Pmode, XEXP (x, 0),
12972 : : XEXP (XEXP (x, 1), 0)),
12973 : : XEXP (XEXP (x, 1), 1));
12974 : : }
12975 : :
12976 : : /* Canonicalize
12977 : : (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
12978 : : into (plus (plus (mult (reg) (const)) (reg)) (const)). */
12979 : 86342 : else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
12980 : 56828 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
12981 : 45252 : && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
12982 : 0 : && CONSTANT_P (XEXP (x, 1)))
12983 : : {
12984 : 0 : rtx constant;
12985 : 0 : rtx other = NULL_RTX;
12986 : :
12987 : 0 : if (CONST_INT_P (XEXP (x, 1)))
12988 : : {
12989 : 0 : constant = XEXP (x, 1);
12990 : 0 : other = XEXP (XEXP (XEXP (x, 0), 1), 1);
12991 : : }
12992 : 0 : else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
12993 : : {
12994 : : constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
12995 : : other = XEXP (x, 1);
12996 : : }
12997 : : else
12998 : : constant = 0;
12999 : :
13000 : 0 : if (constant)
13001 : : {
13002 : 0 : changed = true;
13003 : 0 : x = gen_rtx_PLUS (Pmode,
13004 : : gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
13005 : : XEXP (XEXP (XEXP (x, 0), 1), 0)),
13006 : : plus_constant (Pmode, other,
13007 : : INTVAL (constant)));
13008 : : }
13009 : : }
13010 : :
13011 : 96055 : if (changed && ix86_legitimate_address_p (mode, x, false))
13012 : 9748 : return x;
13013 : :
13014 : 86307 : if (GET_CODE (XEXP (x, 0)) == MULT)
13015 : : {
13016 : 18773 : changed = true;
13017 : 18773 : XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0));
13018 : : }
13019 : :
13020 : 86307 : if (GET_CODE (XEXP (x, 1)) == MULT)
13021 : : {
13022 : 0 : changed = true;
13023 : 0 : XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1));
13024 : : }
13025 : :
13026 : 86307 : if (changed
13027 : 18782 : && REG_P (XEXP (x, 1))
13028 : 15306 : && REG_P (XEXP (x, 0)))
13029 : : return x;
13030 : :
13031 : 71002 : if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
13032 : : {
13033 : 1757 : changed = true;
13034 : 1757 : x = legitimize_pic_address (x, 0);
13035 : : }
13036 : :
13037 : 71002 : if (changed && ix86_legitimate_address_p (mode, x, false))
13038 : 3751 : return x;
13039 : :
13040 : 67251 : if (REG_P (XEXP (x, 0)))
13041 : : {
13042 : 12010 : rtx temp = gen_reg_rtx (Pmode);
13043 : 9964 : rtx val = force_operand (XEXP (x, 1), temp);
13044 : 9964 : if (val != temp)
13045 : : {
13046 : 2706 : val = convert_to_mode (Pmode, val, 1);
13047 : 2427 : emit_move_insn (temp, val);
13048 : : }
13049 : :
13050 : 9964 : XEXP (x, 1) = temp;
13051 : 9964 : return x;
13052 : : }
13053 : :
13054 : 57287 : else if (REG_P (XEXP (x, 1)))
13055 : : {
13056 : 3545 : rtx temp = gen_reg_rtx (Pmode);
13057 : 2785 : rtx val = force_operand (XEXP (x, 0), temp);
13058 : 2785 : if (val != temp)
13059 : : {
13060 : 0 : val = convert_to_mode (Pmode, val, 1);
13061 : 0 : emit_move_insn (temp, val);
13062 : : }
13063 : :
13064 : 2785 : XEXP (x, 0) = temp;
13065 : 2785 : return x;
13066 : : }
13067 : : }
13068 : :
13069 : : return x;
13070 : : }
13071 : :
13072 : : /* Print an integer constant expression in assembler syntax. Addition
13073 : : and subtraction are the only arithmetic that may appear in these
13074 : : expressions. FILE is the stdio stream to write to, X is the rtx, and
13075 : : CODE is the operand print code from the output string. */
13076 : :
13077 : : static void
13078 : 3596589 : output_pic_addr_const (FILE *file, rtx x, int code)
13079 : : {
13080 : 3821686 : char buf[256];
13081 : :
13082 : 3821686 : switch (GET_CODE (x))
13083 : : {
13084 : 0 : case PC:
13085 : 0 : gcc_assert (flag_pic);
13086 : 0 : putc ('.', file);
13087 : 0 : break;
13088 : :
13089 : 844954 : case SYMBOL_REF:
13090 : 844954 : if (TARGET_64BIT || ! TARGET_MACHO_SYMBOL_STUBS)
13091 : 844954 : output_addr_const (file, x);
13092 : : else
13093 : : {
13094 : : const char *name = XSTR (x, 0);
13095 : :
13096 : : /* Mark the decl as referenced so that cgraph will
13097 : : output the function. */
13098 : : if (SYMBOL_REF_DECL (x))
13099 : : mark_decl_referenced (SYMBOL_REF_DECL (x));
13100 : :
13101 : : #if TARGET_MACHO
13102 : : if (MACHOPIC_INDIRECT
13103 : : && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
13104 : : name = machopic_indirection_name (x, /*stub_p=*/true);
13105 : : #endif
13106 : : assemble_name (file, name);
13107 : : }
13108 : 844954 : if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
13109 : 844954 : && code == 'P' && ix86_call_use_plt_p (x))
13110 : 383720 : fputs ("@PLT", file);
13111 : : break;
13112 : :
13113 : 2480 : case LABEL_REF:
13114 : 2480 : x = XEXP (x, 0);
13115 : : /* FALLTHRU */
13116 : 2480 : case CODE_LABEL:
13117 : 2480 : ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
13118 : 2480 : assemble_name (asm_out_file, buf);
13119 : 2480 : break;
13120 : :
13121 : 2552105 : CASE_CONST_SCALAR_INT:
13122 : 2552105 : output_addr_const (file, x);
13123 : 2552105 : break;
13124 : :
13125 : 206408 : case CONST:
13126 : : /* This used to output parentheses around the expression,
13127 : : but that does not work on the 386 (either ATT or BSD assembler). */
13128 : 206408 : output_pic_addr_const (file, XEXP (x, 0), code);
13129 : 206408 : break;
13130 : :
13131 : 0 : case CONST_DOUBLE:
13132 : : /* We can't handle floating point constants;
13133 : : TARGET_PRINT_OPERAND must handle them. */
13134 : 0 : output_operand_lossage ("floating constant misused");
13135 : 0 : break;
13136 : :
13137 : 18689 : case PLUS:
13138 : : /* Some assemblers need integer constants to appear first. */
13139 : 18689 : if (CONST_INT_P (XEXP (x, 0)))
13140 : : {
13141 : 0 : output_pic_addr_const (file, XEXP (x, 0), code);
13142 : 0 : putc ('+', file);
13143 : 0 : output_pic_addr_const (file, XEXP (x, 1), code);
13144 : : }
13145 : : else
13146 : : {
13147 : 18689 : gcc_assert (CONST_INT_P (XEXP (x, 1)));
13148 : 18689 : output_pic_addr_const (file, XEXP (x, 1), code);
13149 : 18689 : putc ('+', file);
13150 : 18689 : output_pic_addr_const (file, XEXP (x, 0), code);
13151 : : }
13152 : : break;
13153 : :
13154 : 0 : case MINUS:
13155 : 0 : if (!TARGET_MACHO)
13156 : 0 : putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
13157 : 0 : output_pic_addr_const (file, XEXP (x, 0), code);
13158 : 0 : putc ('-', file);
13159 : 0 : output_pic_addr_const (file, XEXP (x, 1), code);
13160 : 0 : if (!TARGET_MACHO)
13161 : 0 : putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
13162 : 0 : break;
13163 : :
13164 : 197050 : case UNSPEC:
13165 : 197050 : gcc_assert (XVECLEN (x, 0) == 1);
13166 : 197050 : output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
13167 : 197050 : switch (XINT (x, 1))
13168 : : {
13169 : 42354 : case UNSPEC_GOT:
13170 : 42354 : fputs ("@GOT", file);
13171 : 42354 : break;
13172 : 76619 : case UNSPEC_GOTOFF:
13173 : 76619 : fputs ("@GOTOFF", file);
13174 : 76619 : break;
13175 : 31 : case UNSPEC_PLTOFF:
13176 : 31 : fputs ("@PLTOFF", file);
13177 : 31 : break;
13178 : 0 : case UNSPEC_PCREL:
13179 : 0 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
13180 : : "(%rip)" : "[rip]", file);
13181 : 0 : break;
13182 : 74033 : case UNSPEC_GOTPCREL:
13183 : 74033 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
13184 : : "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
13185 : 74033 : break;
13186 : 0 : case UNSPEC_GOTTPOFF:
13187 : : /* FIXME: This might be @TPOFF in Sun ld too. */
13188 : 0 : fputs ("@gottpoff", file);
13189 : 0 : break;
13190 : 0 : case UNSPEC_TPOFF:
13191 : 0 : fputs ("@tpoff", file);
13192 : 0 : break;
13193 : 1353 : case UNSPEC_NTPOFF:
13194 : 1353 : if (TARGET_64BIT)
13195 : 1353 : fputs ("@tpoff", file);
13196 : : else
13197 : 0 : fputs ("@ntpoff", file);
13198 : : break;
13199 : 333 : case UNSPEC_DTPOFF:
13200 : 333 : fputs ("@dtpoff", file);
13201 : 333 : break;
13202 : 2327 : case UNSPEC_GOTNTPOFF:
13203 : 2327 : if (TARGET_64BIT)
13204 : 2079 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
13205 : : "@gottpoff(%rip)": "@gottpoff[rip]", file);
13206 : : else
13207 : 248 : fputs ("@gotntpoff", file);
13208 : : break;
13209 : 0 : case UNSPEC_INDNTPOFF:
13210 : 0 : fputs ("@indntpoff", file);
13211 : 0 : break;
13212 : 0 : case UNSPEC_SECREL32:
13213 : 0 : fputs ("@secrel32", file);
13214 : 0 : break;
13215 : : #if TARGET_MACHO
13216 : : case UNSPEC_MACHOPIC_OFFSET:
13217 : : putc ('-', file);
13218 : : machopic_output_function_base_name (file);
13219 : : break;
13220 : : #endif
13221 : 0 : default:
13222 : 0 : output_operand_lossage ("invalid UNSPEC as operand");
13223 : 0 : break;
13224 : : }
13225 : : break;
13226 : :
13227 : 0 : default:
13228 : 0 : output_operand_lossage ("invalid expression as operand");
13229 : : }
13230 : 3596589 : }
13231 : :
13232 : : /* This is called from dwarf2out.cc via TARGET_ASM_OUTPUT_DWARF_DTPREL.
13233 : : We need to emit DTP-relative relocations. */
13234 : :
13235 : : static void ATTRIBUTE_UNUSED
13236 : 698 : i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
13237 : : {
13238 : 698 : fputs (ASM_LONG, file);
13239 : 698 : output_addr_const (file, x);
13240 : : #if TARGET_WIN32_TLS
13241 : : fputs ("@secrel32", file);
13242 : : #else
13243 : 698 : fputs ("@dtpoff", file);
13244 : : #endif
13245 : 698 : switch (size)
13246 : : {
13247 : : case 4:
13248 : : break;
13249 : 535 : case 8:
13250 : 535 : fputs (", 0", file);
13251 : 535 : break;
13252 : 0 : default:
13253 : 0 : gcc_unreachable ();
13254 : : }
13255 : 698 : }
13256 : :
13257 : : /* Return true if X is a representation of the PIC register. This copes
13258 : : with calls from ix86_find_base_term, where the register might have
13259 : : been replaced by a cselib value. */
13260 : :
13261 : : static bool
13262 : 29061755 : ix86_pic_register_p (rtx x)
13263 : : {
13264 : 29061755 : if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
13265 : 764215 : return (pic_offset_table_rtx
13266 : 764215 : && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
13267 : 28297540 : else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT)
13268 : : return true;
13269 : 28296100 : else if (!REG_P (x))
13270 : : return false;
13271 : 27680876 : else if (pic_offset_table_rtx)
13272 : : {
13273 : 27663750 : if (REGNO (x) == REGNO (pic_offset_table_rtx))
13274 : : return true;
13275 : 381595 : if (HARD_REGISTER_P (x)
13276 : 361284 : && !HARD_REGISTER_P (pic_offset_table_rtx)
13277 : 742879 : && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
13278 : : return true;
13279 : : return false;
13280 : : }
13281 : : else
13282 : 17126 : return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
13283 : : }
13284 : :
13285 : : /* Helper function for ix86_delegitimize_address.
13286 : : Attempt to delegitimize TLS local-exec accesses. */
13287 : :
13288 : : static rtx
13289 : 3558982015 : ix86_delegitimize_tls_address (rtx orig_x)
13290 : : {
13291 : 3558982015 : rtx x = orig_x, unspec;
13292 : 3558982015 : struct ix86_address addr;
13293 : :
13294 : 3558982015 : if (!TARGET_TLS_DIRECT_SEG_REFS)
13295 : : return orig_x;
13296 : 3558982015 : if (MEM_P (x))
13297 : 42149537 : x = XEXP (x, 0);
13298 : 5130484449 : if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
13299 : : return orig_x;
13300 : 1720802412 : if (ix86_decompose_address (x, &addr) == 0
13301 : 2005654624 : || addr.seg != DEFAULT_TLS_SEG_REG
13302 : 246351 : || addr.disp == NULL_RTX
13303 : 1721001110 : || GET_CODE (addr.disp) != CONST)
13304 : : return orig_x;
13305 : 107308 : unspec = XEXP (addr.disp, 0);
13306 : 107308 : if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
13307 : 65586 : unspec = XEXP (unspec, 0);
13308 : 107308 : if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF)
13309 : : return orig_x;
13310 : 107255 : x = XVECEXP (unspec, 0, 0);
13311 : 107255 : gcc_assert (GET_CODE (x) == SYMBOL_REF);
13312 : 107255 : if (unspec != XEXP (addr.disp, 0))
13313 : 86353 : x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1));
13314 : 107255 : if (addr.index)
13315 : : {
13316 : 187 : rtx idx = addr.index;
13317 : 187 : if (addr.scale != 1)
13318 : 187 : idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
13319 : 187 : x = gen_rtx_PLUS (Pmode, idx, x);
13320 : : }
13321 : 107255 : if (addr.base)
13322 : 2 : x = gen_rtx_PLUS (Pmode, addr.base, x);
13323 : 107255 : if (MEM_P (orig_x))
13324 : 198 : x = replace_equiv_address_nv (orig_x, x);
13325 : : return x;
13326 : : }
13327 : :
13328 : : /* In the name of slightly smaller debug output, and to cater to
13329 : : general assembler lossage, recognize PIC+GOTOFF and turn it back
13330 : : into a direct symbol reference.
13331 : :
13332 : : On Darwin, this is necessary to avoid a crash, because Darwin
13333 : : has a different PIC label for each routine but the DWARF debugging
13334 : : information is not associated with any particular routine, so it's
13335 : : necessary to remove references to the PIC label from RTL stored by
13336 : : the DWARF output code.
13337 : :
13338 : : This helper is used in the normal ix86_delegitimize_address
13339 : : entrypoint (e.g. used in the target delegitimization hook) and
13340 : : in ix86_find_base_term. As compile time memory optimization, we
13341 : : avoid allocating rtxes that will not change anything on the outcome
13342 : : of the callers (find_base_value and find_base_term). */
13343 : :
13344 : : static inline rtx
13345 : 3586006441 : ix86_delegitimize_address_1 (rtx x, bool base_term_p)
13346 : : {
13347 : 3586006441 : rtx orig_x = delegitimize_mem_from_attrs (x);
13348 : : /* addend is NULL or some rtx if x is something+GOTOFF where
13349 : : something doesn't include the PIC register. */
13350 : 3586006441 : rtx addend = NULL_RTX;
13351 : : /* reg_addend is NULL or a multiple of some register. */
13352 : 3586006441 : rtx reg_addend = NULL_RTX;
13353 : : /* const_addend is NULL or a const_int. */
13354 : 3586006441 : rtx const_addend = NULL_RTX;
13355 : : /* This is the result, or NULL. */
13356 : 3586006441 : rtx result = NULL_RTX;
13357 : :
13358 : 3586006441 : x = orig_x;
13359 : :
13360 : 3586006441 : if (MEM_P (x))
13361 : 63504440 : x = XEXP (x, 0);
13362 : :
13363 : 3586006441 : if (TARGET_64BIT)
13364 : : {
13365 : 239365473 : if (GET_CODE (x) == CONST
13366 : 8257326 : && GET_CODE (XEXP (x, 0)) == PLUS
13367 : 6500216 : && GET_MODE (XEXP (x, 0)) == Pmode
13368 : 6500167 : && CONST_INT_P (XEXP (XEXP (x, 0), 1))
13369 : 6500167 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC
13370 : 239370044 : && XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL)
13371 : : {
13372 : : /* find_base_{value,term} only care about MEMs with arg_pointer_rtx
13373 : : base. A CONST can't be arg_pointer_rtx based. */
13374 : 0 : if (base_term_p && MEM_P (orig_x))
13375 : : return orig_x;
13376 : 0 : rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0);
13377 : 0 : x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2);
13378 : 0 : if (MEM_P (orig_x))
13379 : 0 : x = replace_equiv_address_nv (orig_x, x);
13380 : 0 : return x;
13381 : : }
13382 : :
13383 : 239365473 : if (GET_CODE (x) == CONST
13384 : 8257326 : && GET_CODE (XEXP (x, 0)) == UNSPEC
13385 : 1757159 : && (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL
13386 : 572092 : || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)
13387 : 1185067 : && (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL))
13388 : : {
13389 : 257917 : x = XVECEXP (XEXP (x, 0), 0, 0);
13390 : 257917 : if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x))
13391 : : {
13392 : 9 : x = lowpart_subreg (GET_MODE (orig_x), x, GET_MODE (x));
13393 : 9 : if (x == NULL_RTX)
13394 : : return orig_x;
13395 : : }
13396 : 257917 : return x;
13397 : : }
13398 : :
13399 : 239107556 : if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC)
13400 : 239106440 : return ix86_delegitimize_tls_address (orig_x);
13401 : :
13402 : : /* Fall thru into the code shared with -m32 for -mcmodel=large -fpic
13403 : : and -mcmodel=medium -fpic. */
13404 : : }
13405 : :
13406 : 3346642084 : if (GET_CODE (x) != PLUS
13407 : 1598268376 : || GET_CODE (XEXP (x, 1)) != CONST)
13408 : 3318138123 : return ix86_delegitimize_tls_address (orig_x);
13409 : :
13410 : 28503961 : if (ix86_pic_register_p (XEXP (x, 0)))
13411 : : /* %ebx + GOT/GOTOFF */
13412 : : ;
13413 : 1300534 : else if (GET_CODE (XEXP (x, 0)) == PLUS)
13414 : : {
13415 : : /* %ebx + %reg * scale + GOT/GOTOFF */
13416 : 483832 : reg_addend = XEXP (x, 0);
13417 : 483832 : if (ix86_pic_register_p (XEXP (reg_addend, 0)))
13418 : 409870 : reg_addend = XEXP (reg_addend, 1);
13419 : 73962 : else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
13420 : 42691 : reg_addend = XEXP (reg_addend, 0);
13421 : : else
13422 : : {
13423 : 31271 : reg_addend = NULL_RTX;
13424 : 31271 : addend = XEXP (x, 0);
13425 : : }
13426 : : }
13427 : : else
13428 : : addend = XEXP (x, 0);
13429 : :
13430 : 28503961 : x = XEXP (XEXP (x, 1), 0);
13431 : 28503961 : if (GET_CODE (x) == PLUS
13432 : 1464654 : && CONST_INT_P (XEXP (x, 1)))
13433 : : {
13434 : 1464654 : const_addend = XEXP (x, 1);
13435 : 1464654 : x = XEXP (x, 0);
13436 : : }
13437 : :
13438 : 28503961 : if (GET_CODE (x) == UNSPEC
13439 : 27818387 : && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend)
13440 : 6721401 : || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))
13441 : 1051878 : || (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC
13442 : 0 : && !MEM_P (orig_x) && !addend)))
13443 : 26766509 : result = XVECEXP (x, 0, 0);
13444 : :
13445 : 26766509 : if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x)
13446 : : && !MEM_P (orig_x))
13447 : : result = XVECEXP (x, 0, 0);
13448 : :
13449 : 26766509 : if (! result)
13450 : 1737452 : return ix86_delegitimize_tls_address (orig_x);
13451 : :
13452 : : /* For (PLUS something CONST_INT) both find_base_{value,term} just
13453 : : recurse on the first operand. */
13454 : 26766509 : if (const_addend && !base_term_p)
13455 : 346677 : result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
13456 : 26766509 : if (reg_addend)
13457 : 876770 : result = gen_rtx_PLUS (Pmode, reg_addend, result);
13458 : 26766509 : if (addend)
13459 : : {
13460 : : /* If the rest of original X doesn't involve the PIC register, add
13461 : : addend and subtract pic_offset_table_rtx. This can happen e.g.
13462 : : for code like:
13463 : : leal (%ebx, %ecx, 4), %ecx
13464 : : ...
13465 : : movl foo@GOTOFF(%ecx), %edx
13466 : : in which case we return (%ecx - %ebx) + foo
13467 : : or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
13468 : : and reload has completed. Don't do the latter for debug,
13469 : : as _GLOBAL_OFFSET_TABLE_ can't be expressed in the assembly. */
13470 : 135039 : if (pic_offset_table_rtx
13471 : 135039 : && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
13472 : 2334 : result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
13473 : : pic_offset_table_rtx),
13474 : : result);
13475 : 134261 : else if (base_term_p
13476 : 129192 : && pic_offset_table_rtx
13477 : : && !TARGET_MACHO
13478 : : && !TARGET_VXWORKS_RTP)
13479 : : {
13480 : 258384 : rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
13481 : 258384 : tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
13482 : 258384 : result = gen_rtx_PLUS (Pmode, tmp, result);
13483 : 129192 : }
13484 : : else
13485 : : return orig_x;
13486 : : }
13487 : 53522841 : if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x))
13488 : : {
13489 : 0 : result = lowpart_subreg (GET_MODE (orig_x), result, Pmode);
13490 : 0 : if (result == NULL_RTX)
13491 : : return orig_x;
13492 : : }
13493 : : return result;
13494 : : }
13495 : :
13496 : : /* The normal instantiation of the above template. */
13497 : :
13498 : : static rtx
13499 : 308409804 : ix86_delegitimize_address (rtx x)
13500 : : {
13501 : 308409804 : return ix86_delegitimize_address_1 (x, false);
13502 : : }
13503 : :
13504 : : /* If X is a machine specific address (i.e. a symbol or label being
13505 : : referenced as a displacement from the GOT implemented using an
13506 : : UNSPEC), then return the base term. Otherwise return X. */
13507 : :
13508 : : rtx
13509 : 6748197667 : ix86_find_base_term (rtx x)
13510 : : {
13511 : 6748197667 : rtx term;
13512 : :
13513 : 6748197667 : if (TARGET_64BIT)
13514 : : {
13515 : 3470601030 : if (GET_CODE (x) != CONST)
13516 : : return x;
13517 : 39843491 : term = XEXP (x, 0);
13518 : 39843491 : if (GET_CODE (term) == PLUS
13519 : 39828872 : && CONST_INT_P (XEXP (term, 1)))
13520 : 39828872 : term = XEXP (term, 0);
13521 : 39843491 : if (GET_CODE (term) != UNSPEC
13522 : 40414 : || (XINT (term, 1) != UNSPEC_GOTPCREL
13523 : 40414 : && XINT (term, 1) != UNSPEC_PCREL))
13524 : : return x;
13525 : :
13526 : 0 : return XVECEXP (term, 0, 0);
13527 : : }
13528 : :
13529 : 3277596637 : return ix86_delegitimize_address_1 (x, true);
13530 : : }
13531 : :
13532 : : /* Return true if X shouldn't be emitted into the debug info.
13533 : : Disallow UNSPECs other than @gotoff - we can't emit _GLOBAL_OFFSET_TABLE_
13534 : : symbol easily into the .debug_info section, so we need not to
13535 : : delegitimize, but instead assemble as @gotoff.
13536 : : Disallow _GLOBAL_OFFSET_TABLE_ SYMBOL_REF - the assembler magically
13537 : : assembles that as _GLOBAL_OFFSET_TABLE_-. expression. */
13538 : :
13539 : : static bool
13540 : 1781074 : ix86_const_not_ok_for_debug_p (rtx x)
13541 : : {
13542 : 1781074 : if (GET_CODE (x) == UNSPEC && XINT (x, 1) != UNSPEC_GOTOFF)
13543 : : return true;
13544 : :
13545 : 1781052 : if (SYMBOL_REF_P (x) && strcmp (XSTR (x, 0), GOT_SYMBOL_NAME) == 0)
13546 : 0 : return true;
13547 : :
13548 : : return false;
13549 : : }
13550 : :
13551 : : static void
13552 : 6981873 : put_condition_code (enum rtx_code code, machine_mode mode, bool reverse,
13553 : : bool fp, FILE *file)
13554 : : {
13555 : 6981873 : const char *suffix;
13556 : :
13557 : 6981873 : if (mode == CCFPmode)
13558 : : {
13559 : 558143 : code = ix86_fp_compare_code_to_integer (code);
13560 : 558143 : mode = CCmode;
13561 : : }
13562 : 6981873 : if (reverse)
13563 : 194788 : code = reverse_condition (code);
13564 : :
13565 : 6981873 : switch (code)
13566 : : {
13567 : 2746193 : case EQ:
13568 : 2746193 : gcc_assert (mode != CCGZmode);
13569 : 2746193 : switch (mode)
13570 : : {
13571 : : case E_CCAmode:
13572 : : suffix = "a";
13573 : : break;
13574 : : case E_CCCmode:
13575 : 27938 : suffix = "c";
13576 : : break;
13577 : : case E_CCOmode:
13578 : 6981873 : suffix = "o";
13579 : : break;
13580 : : case E_CCPmode:
13581 : 231990 : suffix = "p";
13582 : : break;
13583 : : case E_CCSmode:
13584 : 116159 : suffix = "s";
13585 : : break;
13586 : 2726164 : default:
13587 : 2726164 : suffix = "e";
13588 : 2726164 : break;
13589 : : }
13590 : : break;
13591 : 2252091 : case NE:
13592 : 2252091 : gcc_assert (mode != CCGZmode);
13593 : 2252091 : switch (mode)
13594 : : {
13595 : : case E_CCAmode:
13596 : : suffix = "na";
13597 : : break;
13598 : : case E_CCCmode:
13599 : 14298 : suffix = "nc";
13600 : : break;
13601 : 10762 : case E_CCOmode:
13602 : 10762 : suffix = "no";
13603 : 10762 : break;
13604 : : case E_CCPmode:
13605 : 4385 : suffix = "np";
13606 : : break;
13607 : : case E_CCSmode:
13608 : 51260 : suffix = "ns";
13609 : : break;
13610 : 2240453 : default:
13611 : 2240453 : suffix = "ne";
13612 : 2240453 : break;
13613 : : }
13614 : : break;
13615 : 249953 : case GT:
13616 : 249953 : gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
13617 : : suffix = "g";
13618 : : break;
13619 : 164331 : case GTU:
13620 : : /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
13621 : : Those same assemblers have the same but opposite lossage on cmov. */
13622 : 164331 : if (mode == CCmode)
13623 : 164393 : suffix = fp ? "nbe" : "a";
13624 : : else
13625 : 0 : gcc_unreachable ();
13626 : : break;
13627 : 231262 : case LT:
13628 : 231262 : switch (mode)
13629 : : {
13630 : : case E_CCNOmode:
13631 : : case E_CCGOCmode:
13632 : : suffix = "s";
13633 : : break;
13634 : :
13635 : : case E_CCmode:
13636 : : case E_CCGCmode:
13637 : : case E_CCGZmode:
13638 : 6981873 : suffix = "l";
13639 : : break;
13640 : :
13641 : 0 : default:
13642 : 0 : gcc_unreachable ();
13643 : : }
13644 : : break;
13645 : 425065 : case LTU:
13646 : 425065 : if (mode == CCmode || mode == CCGZmode)
13647 : : suffix = "b";
13648 : 26654 : else if (mode == CCCmode)
13649 : 27938 : suffix = fp ? "b" : "c";
13650 : : else
13651 : 0 : gcc_unreachable ();
13652 : : break;
13653 : 141213 : case GE:
13654 : 141213 : switch (mode)
13655 : : {
13656 : : case E_CCNOmode:
13657 : : case E_CCGOCmode:
13658 : : suffix = "ns";
13659 : : break;
13660 : :
13661 : : case E_CCmode:
13662 : : case E_CCGCmode:
13663 : : case E_CCGZmode:
13664 : 6981873 : suffix = "ge";
13665 : : break;
13666 : :
13667 : 0 : default:
13668 : 0 : gcc_unreachable ();
13669 : : }
13670 : : break;
13671 : 185917 : case GEU:
13672 : 185917 : if (mode == CCmode || mode == CCGZmode)
13673 : : suffix = "nb";
13674 : 13442 : else if (mode == CCCmode)
13675 : 14298 : suffix = fp ? "nb" : "nc";
13676 : : else
13677 : 0 : gcc_unreachable ();
13678 : : break;
13679 : 237462 : case LE:
13680 : 237462 : gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
13681 : : suffix = "le";
13682 : : break;
13683 : 112011 : case LEU:
13684 : 112011 : if (mode == CCmode)
13685 : : suffix = "be";
13686 : : else
13687 : 0 : gcc_unreachable ();
13688 : : break;
13689 : 231989 : case UNORDERED:
13690 : 231996 : suffix = fp ? "u" : "p";
13691 : : break;
13692 : 4386 : case ORDERED:
13693 : 4391 : suffix = fp ? "nu" : "np";
13694 : : break;
13695 : 0 : default:
13696 : 0 : gcc_unreachable ();
13697 : : }
13698 : 6981873 : fputs (suffix, file);
13699 : 6981873 : }
13700 : :
13701 : : /* Print the name of register X to FILE based on its machine mode and number.
13702 : : If CODE is 'w', pretend the mode is HImode.
13703 : : If CODE is 'b', pretend the mode is QImode.
13704 : : If CODE is 'k', pretend the mode is SImode.
13705 : : If CODE is 'q', pretend the mode is DImode.
13706 : : If CODE is 'x', pretend the mode is V4SFmode.
13707 : : If CODE is 't', pretend the mode is V8SFmode.
13708 : : If CODE is 'g', pretend the mode is V16SFmode.
13709 : : If CODE is 'h', pretend the reg is the 'high' byte register.
13710 : : If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
13711 : : If CODE is 'd', duplicate the operand for AVX instruction.
13712 : : If CODE is 'V', print naked full integer register name without %.
13713 : : */
13714 : :
13715 : : void
13716 : 121581077 : print_reg (rtx x, int code, FILE *file)
13717 : : {
13718 : 121581077 : const char *reg;
13719 : 121581077 : int msize;
13720 : 121581077 : unsigned int regno;
13721 : 121581077 : bool duplicated;
13722 : :
13723 : 121581077 : if (ASSEMBLER_DIALECT == ASM_ATT && code != 'V')
13724 : 121578860 : putc ('%', file);
13725 : :
13726 : 121581077 : if (x == pc_rtx)
13727 : : {
13728 : 5652101 : gcc_assert (TARGET_64BIT);
13729 : 5652101 : fputs ("rip", file);
13730 : 5652101 : return;
13731 : : }
13732 : :
13733 : 115928976 : if (code == 'y' && STACK_TOP_P (x))
13734 : : {
13735 : 298223 : fputs ("st(0)", file);
13736 : 298223 : return;
13737 : : }
13738 : :
13739 : 115630753 : if (code == 'w')
13740 : : msize = 2;
13741 : : else if (code == 'b')
13742 : : msize = 1;
13743 : : else if (code == 'k')
13744 : : msize = 4;
13745 : : else if (code == 'q')
13746 : : msize = 8;
13747 : : else if (code == 'h')
13748 : : msize = 0;
13749 : : else if (code == 'x')
13750 : : msize = 16;
13751 : : else if (code == 't')
13752 : : msize = 32;
13753 : : else if (code == 'g')
13754 : : msize = 64;
13755 : : else
13756 : 197595946 : msize = GET_MODE_SIZE (GET_MODE (x));
13757 : :
13758 : 115630753 : regno = REGNO (x);
13759 : :
13760 : 115630753 : if (regno == ARG_POINTER_REGNUM
13761 : 115630753 : || regno == FRAME_POINTER_REGNUM
13762 : 115630753 : || regno == FPSR_REG)
13763 : : {
13764 : 0 : output_operand_lossage
13765 : 0 : ("invalid use of register '%s'", reg_names[regno]);
13766 : 0 : return;
13767 : : }
13768 : 115630753 : else if (regno == FLAGS_REG)
13769 : : {
13770 : 1 : output_operand_lossage ("invalid use of asm flag output");
13771 : 1 : return;
13772 : : }
13773 : :
13774 : 115630752 : if (code == 'V')
13775 : : {
13776 : 1 : if (GENERAL_REGNO_P (regno))
13777 : 2 : msize = GET_MODE_SIZE (word_mode);
13778 : : else
13779 : 0 : error ("%<V%> modifier on non-integer register");
13780 : : }
13781 : :
13782 : 115630752 : duplicated = code == 'd' && TARGET_AVX;
13783 : :
13784 : 115630752 : switch (msize)
13785 : : {
13786 : 76125304 : case 16:
13787 : 76125304 : case 12:
13788 : 76125304 : case 8:
13789 : 142631341 : if (GENERAL_REGNO_P (regno) && msize > GET_MODE_SIZE (word_mode))
13790 : 5 : warning (0, "unsupported size for integer register");
13791 : : /* FALLTHRU */
13792 : 112207717 : case 4:
13793 : 112207717 : if (LEGACY_INT_REGNO_P (regno))
13794 : 122139961 : putc (msize > 4 && TARGET_64BIT ? 'r' : 'e', file);
13795 : : /* FALLTHRU */
13796 : 113096126 : case 2:
13797 : 21605136 : normal:
13798 : 113096126 : reg = hi_reg_name[regno];
13799 : 113096126 : break;
13800 : 2292289 : case 1:
13801 : 2292289 : if (regno >= ARRAY_SIZE (qi_reg_name))
13802 : 283594 : goto normal;
13803 : 2008695 : if (!ANY_QI_REGNO_P (regno))
13804 : 0 : error ("unsupported size for integer register");
13805 : 2008695 : reg = qi_reg_name[regno];
13806 : 2008695 : break;
13807 : 27279 : case 0:
13808 : 27279 : if (regno >= ARRAY_SIZE (qi_high_reg_name))
13809 : 0 : goto normal;
13810 : 27279 : reg = qi_high_reg_name[regno];
13811 : 27279 : break;
13812 : 498652 : case 32:
13813 : 498652 : case 64:
13814 : 498652 : if (SSE_REGNO_P (regno))
13815 : : {
13816 : 498652 : gcc_assert (!duplicated);
13817 : 694916 : putc (msize == 32 ? 'y' : 'z', file);
13818 : 498652 : reg = hi_reg_name[regno] + 1;
13819 : 498652 : break;
13820 : : }
13821 : 0 : goto normal;
13822 : 0 : default:
13823 : 0 : gcc_unreachable ();
13824 : : }
13825 : :
13826 : 115630752 : fputs (reg, file);
13827 : :
13828 : : /* Irritatingly, AMD extended registers use
13829 : : different naming convention: "r%d[bwd]" */
13830 : 115630752 : if (REX_INT_REGNO_P (regno) || REX2_INT_REGNO_P (regno))
13831 : : {
13832 : 10251137 : gcc_assert (TARGET_64BIT);
13833 : 10251137 : switch (msize)
13834 : : {
13835 : 0 : case 0:
13836 : 0 : error ("extended registers have no high halves");
13837 : 0 : break;
13838 : 199401 : case 1:
13839 : 199401 : putc ('b', file);
13840 : 199401 : break;
13841 : 29333 : case 2:
13842 : 29333 : putc ('w', file);
13843 : 29333 : break;
13844 : 2581567 : case 4:
13845 : 2581567 : putc ('d', file);
13846 : 2581567 : break;
13847 : : case 8:
13848 : : /* no suffix */
13849 : : break;
13850 : 0 : default:
13851 : 0 : error ("unsupported operand size for extended register");
13852 : 0 : break;
13853 : : }
13854 : 10251137 : return;
13855 : : }
13856 : :
13857 : 105379615 : if (duplicated)
13858 : : {
13859 : 16690 : if (ASSEMBLER_DIALECT == ASM_ATT)
13860 : 16669 : fprintf (file, ", %%%s", reg);
13861 : : else
13862 : 21 : fprintf (file, ", %s", reg);
13863 : : }
13864 : : }
13865 : :
13866 : : /* Meaning of CODE:
13867 : : L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
13868 : : C -- print opcode suffix for set/cmov insn.
13869 : : c -- like C, but print reversed condition
13870 : : F,f -- likewise, but for floating-point.
13871 : : O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
13872 : : otherwise nothing
13873 : : R -- print embedded rounding and sae.
13874 : : r -- print only sae.
13875 : : z -- print the opcode suffix for the size of the current operand.
13876 : : Z -- likewise, with special suffixes for x87 instructions.
13877 : : * -- print a star (in certain assembler syntax)
13878 : : A -- print an absolute memory reference.
13879 : : E -- print address with DImode register names if TARGET_64BIT.
13880 : : w -- print the operand as if it's a "word" (HImode) even if it isn't.
13881 : : s -- print a shift double count, followed by the assemblers argument
13882 : : delimiter.
13883 : : b -- print the QImode name of the register for the indicated operand.
13884 : : %b0 would print %al if operands[0] is reg 0.
13885 : : w -- likewise, print the HImode name of the register.
13886 : : k -- likewise, print the SImode name of the register.
13887 : : q -- likewise, print the DImode name of the register.
13888 : : x -- likewise, print the V4SFmode name of the register.
13889 : : t -- likewise, print the V8SFmode name of the register.
13890 : : g -- likewise, print the V16SFmode name of the register.
13891 : : h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
13892 : : y -- print "st(0)" instead of "st" as a register.
13893 : : d -- print duplicated register operand for AVX instruction.
13894 : : D -- print condition for SSE cmp instruction.
13895 : : P -- if PIC, print an @PLT suffix. For -fno-plt, load function
13896 : : address from GOT.
13897 : : p -- print raw symbol name.
13898 : : X -- don't print any sort of PIC '@' suffix for a symbol.
13899 : : & -- print some in-use local-dynamic symbol name.
13900 : : H -- print a memory address offset by 8; used for sse high-parts
13901 : : Y -- print condition for XOP pcom* instruction.
13902 : : V -- print naked full integer register name without %.
13903 : : v -- print segment override prefix
13904 : : + -- print a branch hint as 'cs' or 'ds' prefix
13905 : : ; -- print a semicolon (after prefixes due to bug in older gas).
13906 : : ~ -- print "i" if TARGET_AVX2, "f" otherwise.
13907 : : ^ -- print addr32 prefix if Pmode != word_mode
13908 : : M -- print addr32 prefix for TARGET_X32 with VSIB address.
13909 : : ! -- print NOTRACK prefix for jxx/call/ret instructions if required.
13910 : : N -- print maskz if it's constant 0 operand.
13911 : : G -- print embedded flag for ccmp/ctest.
13912 : : */
13913 : :
13914 : : void
13915 : 174252741 : ix86_print_operand (FILE *file, rtx x, int code)
13916 : : {
13917 : 174451235 : if (code)
13918 : : {
13919 : 61078334 : switch (code)
13920 : : {
13921 : 198490 : case 'A':
13922 : 198490 : switch (ASSEMBLER_DIALECT)
13923 : : {
13924 : 198490 : case ASM_ATT:
13925 : 198490 : putc ('*', file);
13926 : 198490 : break;
13927 : :
13928 : 0 : case ASM_INTEL:
13929 : : /* Intel syntax. For absolute addresses, registers should not
13930 : : be surrounded by braces. */
13931 : 0 : if (!REG_P (x))
13932 : : {
13933 : 0 : putc ('[', file);
13934 : 0 : ix86_print_operand (file, x, 0);
13935 : 0 : putc (']', file);
13936 : 0 : return;
13937 : : }
13938 : : break;
13939 : :
13940 : 0 : default:
13941 : 0 : gcc_unreachable ();
13942 : : }
13943 : :
13944 : 198490 : ix86_print_operand (file, x, 0);
13945 : 198490 : return;
13946 : :
13947 : 3510836 : case 'E':
13948 : : /* Wrap address in an UNSPEC to declare special handling. */
13949 : 3510836 : if (TARGET_64BIT)
13950 : 3032667 : x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR);
13951 : :
13952 : 3510836 : output_address (VOIDmode, x);
13953 : 3510836 : return;
13954 : :
13955 : 0 : case 'L':
13956 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13957 : 0 : putc ('l', file);
13958 : 0 : return;
13959 : :
13960 : 0 : case 'W':
13961 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13962 : 0 : putc ('w', file);
13963 : 0 : return;
13964 : :
13965 : 0 : case 'B':
13966 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13967 : 0 : putc ('b', file);
13968 : 0 : return;
13969 : :
13970 : 0 : case 'Q':
13971 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13972 : 0 : putc ('l', file);
13973 : 0 : return;
13974 : :
13975 : 0 : case 'S':
13976 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13977 : 0 : putc ('s', file);
13978 : 0 : return;
13979 : :
13980 : 0 : case 'T':
13981 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
13982 : 0 : putc ('t', file);
13983 : 0 : return;
13984 : :
13985 : : case 'O':
13986 : : #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
13987 : : if (ASSEMBLER_DIALECT != ASM_ATT)
13988 : : return;
13989 : :
13990 : : switch (GET_MODE_SIZE (GET_MODE (x)))
13991 : : {
13992 : : case 2:
13993 : : putc ('w', file);
13994 : : break;
13995 : :
13996 : : case 4:
13997 : : putc ('l', file);
13998 : : break;
13999 : :
14000 : : case 8:
14001 : : putc ('q', file);
14002 : : break;
14003 : :
14004 : : default:
14005 : : output_operand_lossage ("invalid operand size for operand "
14006 : : "code 'O'");
14007 : : return;
14008 : : }
14009 : :
14010 : : putc ('.', file);
14011 : : #endif
14012 : : return;
14013 : :
14014 : 37324 : case 'z':
14015 : 37324 : if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
14016 : : {
14017 : : /* Opcodes don't get size suffixes if using Intel opcodes. */
14018 : 37322 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14019 : : return;
14020 : :
14021 : 74644 : switch (GET_MODE_SIZE (GET_MODE (x)))
14022 : : {
14023 : 6 : case 1:
14024 : 6 : putc ('b', file);
14025 : 6 : return;
14026 : :
14027 : 6 : case 2:
14028 : 6 : putc ('w', file);
14029 : 6 : return;
14030 : :
14031 : 36819 : case 4:
14032 : 36819 : putc ('l', file);
14033 : 36819 : return;
14034 : :
14035 : 491 : case 8:
14036 : 491 : putc ('q', file);
14037 : 491 : return;
14038 : :
14039 : 0 : default:
14040 : 0 : output_operand_lossage ("invalid operand size for operand "
14041 : : "code 'z'");
14042 : 0 : return;
14043 : : }
14044 : : }
14045 : :
14046 : 2 : if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
14047 : : {
14048 : 1 : if (this_is_asm_operands)
14049 : 1 : warning_for_asm (this_is_asm_operands,
14050 : : "non-integer operand used with operand code %<z%>");
14051 : : else
14052 : 0 : warning (0, "non-integer operand used with operand code %<z%>");
14053 : : }
14054 : : /* FALLTHRU */
14055 : :
14056 : 386379 : case 'Z':
14057 : : /* 387 opcodes don't get size suffixes if using Intel opcodes. */
14058 : 386379 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14059 : : return;
14060 : :
14061 : 386379 : if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
14062 : : {
14063 : 29060 : switch (GET_MODE_SIZE (GET_MODE (x)))
14064 : : {
14065 : 3501 : case 2:
14066 : : #ifdef HAVE_AS_IX86_FILDS
14067 : 3501 : putc ('s', file);
14068 : : #endif
14069 : 3501 : return;
14070 : :
14071 : 3920 : case 4:
14072 : 3920 : putc ('l', file);
14073 : 3920 : return;
14074 : :
14075 : 7109 : case 8:
14076 : : #ifdef HAVE_AS_IX86_FILDQ
14077 : 7109 : putc ('q', file);
14078 : : #else
14079 : : fputs ("ll", file);
14080 : : #endif
14081 : 7109 : return;
14082 : :
14083 : : default:
14084 : : break;
14085 : : }
14086 : : }
14087 : 371849 : else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
14088 : : {
14089 : : /* 387 opcodes don't get size suffixes
14090 : : if the operands are registers. */
14091 : 371847 : if (STACK_REG_P (x))
14092 : : return;
14093 : :
14094 : 697276 : switch (GET_MODE_SIZE (GET_MODE (x)))
14095 : : {
14096 : 23105 : case 4:
14097 : 23105 : putc ('s', file);
14098 : 23105 : return;
14099 : :
14100 : 32321 : case 8:
14101 : 32321 : putc ('l', file);
14102 : 32321 : return;
14103 : :
14104 : 293210 : case 12:
14105 : 293210 : case 16:
14106 : 293210 : putc ('t', file);
14107 : 293210 : return;
14108 : :
14109 : : default:
14110 : : break;
14111 : : }
14112 : : }
14113 : : else
14114 : : {
14115 : 2 : output_operand_lossage ("invalid operand type used with "
14116 : : "operand code '%c'", code);
14117 : 2 : return;
14118 : : }
14119 : :
14120 : 2 : output_operand_lossage ("invalid operand size for operand code '%c'",
14121 : : code);
14122 : 2 : return;
14123 : :
14124 : : case 'd':
14125 : : case 'b':
14126 : : case 'w':
14127 : : case 'k':
14128 : : case 'q':
14129 : : case 'h':
14130 : : case 't':
14131 : : case 'g':
14132 : : case 'y':
14133 : : case 'x':
14134 : : case 'X':
14135 : : case 'P':
14136 : : case 'p':
14137 : : case 'V':
14138 : : break;
14139 : :
14140 : 0 : case 's':
14141 : 0 : if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
14142 : : {
14143 : 0 : ix86_print_operand (file, x, 0);
14144 : 0 : fputs (", ", file);
14145 : : }
14146 : 0 : return;
14147 : :
14148 : 494 : case 'Y':
14149 : 494 : switch (GET_CODE (x))
14150 : : {
14151 : 182 : case NE:
14152 : 182 : fputs ("neq", file);
14153 : 182 : break;
14154 : 32 : case EQ:
14155 : 32 : fputs ("eq", file);
14156 : 32 : break;
14157 : 64 : case GE:
14158 : 64 : case GEU:
14159 : 64 : fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
14160 : 64 : break;
14161 : 40 : case GT:
14162 : 40 : case GTU:
14163 : 40 : fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
14164 : 40 : break;
14165 : 64 : case LE:
14166 : 64 : case LEU:
14167 : 64 : fputs ("le", file);
14168 : 64 : break;
14169 : 112 : case LT:
14170 : 112 : case LTU:
14171 : 112 : fputs ("lt", file);
14172 : 112 : break;
14173 : 0 : case UNORDERED:
14174 : 0 : fputs ("unord", file);
14175 : 0 : break;
14176 : 0 : case ORDERED:
14177 : 0 : fputs ("ord", file);
14178 : 0 : break;
14179 : 0 : case UNEQ:
14180 : 0 : fputs ("ueq", file);
14181 : 0 : break;
14182 : 0 : case UNGE:
14183 : 0 : fputs ("nlt", file);
14184 : 0 : break;
14185 : 0 : case UNGT:
14186 : 0 : fputs ("nle", file);
14187 : 0 : break;
14188 : 0 : case UNLE:
14189 : 0 : fputs ("ule", file);
14190 : 0 : break;
14191 : 0 : case UNLT:
14192 : 0 : fputs ("ult", file);
14193 : 0 : break;
14194 : 0 : case LTGT:
14195 : 0 : fputs ("une", file);
14196 : 0 : break;
14197 : 0 : default:
14198 : 0 : output_operand_lossage ("operand is not a condition code, "
14199 : : "invalid operand code 'Y'");
14200 : 0 : return;
14201 : : }
14202 : 494 : return;
14203 : :
14204 : 9141 : case 'D':
14205 : : /* Little bit of braindamage here. The SSE compare instructions
14206 : : does use completely different names for the comparisons that the
14207 : : fp conditional moves. */
14208 : 9141 : switch (GET_CODE (x))
14209 : : {
14210 : 3 : case UNEQ:
14211 : 3 : if (TARGET_AVX)
14212 : : {
14213 : 3 : fputs ("eq_us", file);
14214 : 3 : break;
14215 : : }
14216 : : /* FALLTHRU */
14217 : 4327 : case EQ:
14218 : 4327 : fputs ("eq", file);
14219 : 4327 : break;
14220 : 0 : case UNLT:
14221 : 0 : if (TARGET_AVX)
14222 : : {
14223 : 0 : fputs ("nge", file);
14224 : 0 : break;
14225 : : }
14226 : : /* FALLTHRU */
14227 : 1789 : case LT:
14228 : 1789 : fputs ("lt", file);
14229 : 1789 : break;
14230 : 0 : case UNLE:
14231 : 0 : if (TARGET_AVX)
14232 : : {
14233 : 0 : fputs ("ngt", file);
14234 : 0 : break;
14235 : : }
14236 : : /* FALLTHRU */
14237 : 682 : case LE:
14238 : 682 : fputs ("le", file);
14239 : 682 : break;
14240 : 92 : case UNORDERED:
14241 : 92 : fputs ("unord", file);
14242 : 92 : break;
14243 : 24 : case LTGT:
14244 : 24 : if (TARGET_AVX)
14245 : : {
14246 : 24 : fputs ("neq_oq", file);
14247 : 24 : break;
14248 : : }
14249 : : /* FALLTHRU */
14250 : 982 : case NE:
14251 : 982 : fputs ("neq", file);
14252 : 982 : break;
14253 : 0 : case GE:
14254 : 0 : if (TARGET_AVX)
14255 : : {
14256 : 0 : fputs ("ge", file);
14257 : 0 : break;
14258 : : }
14259 : : /* FALLTHRU */
14260 : 405 : case UNGE:
14261 : 405 : fputs ("nlt", file);
14262 : 405 : break;
14263 : 0 : case GT:
14264 : 0 : if (TARGET_AVX)
14265 : : {
14266 : 0 : fputs ("gt", file);
14267 : 0 : break;
14268 : : }
14269 : : /* FALLTHRU */
14270 : 754 : case UNGT:
14271 : 754 : fputs ("nle", file);
14272 : 754 : break;
14273 : 83 : case ORDERED:
14274 : 83 : fputs ("ord", file);
14275 : 83 : break;
14276 : 0 : default:
14277 : 0 : output_operand_lossage ("operand is not a condition code, "
14278 : : "invalid operand code 'D'");
14279 : 0 : return;
14280 : : }
14281 : 9141 : return;
14282 : :
14283 : 6981873 : case 'F':
14284 : 6981873 : case 'f':
14285 : : #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
14286 : : if (ASSEMBLER_DIALECT == ASM_ATT)
14287 : : putc ('.', file);
14288 : : gcc_fallthrough ();
14289 : : #endif
14290 : :
14291 : 6981873 : case 'C':
14292 : 6981873 : case 'c':
14293 : 6981873 : if (!COMPARISON_P (x))
14294 : : {
14295 : 0 : output_operand_lossage ("operand is not a condition code, "
14296 : : "invalid operand code '%c'", code);
14297 : 0 : return;
14298 : : }
14299 : 6981873 : put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
14300 : 6981873 : code == 'c' || code == 'f',
14301 : 6981873 : code == 'F' || code == 'f',
14302 : : file);
14303 : 6981873 : return;
14304 : :
14305 : 21 : case 'G':
14306 : 21 : {
14307 : 21 : int dfv = INTVAL (x);
14308 : 21 : const char *dfv_suffix = ix86_ccmp_dfv_mapping[dfv];
14309 : 21 : fputs (dfv_suffix, file);
14310 : : }
14311 : 21 : return;
14312 : :
14313 : 1255 : case 'H':
14314 : 1255 : if (!offsettable_memref_p (x))
14315 : : {
14316 : 1 : output_operand_lossage ("operand is not an offsettable memory "
14317 : : "reference, invalid operand code 'H'");
14318 : 1 : return;
14319 : : }
14320 : : /* It doesn't actually matter what mode we use here, as we're
14321 : : only going to use this for printing. */
14322 : 1254 : x = adjust_address_nv (x, DImode, 8);
14323 : : /* Output 'qword ptr' for intel assembler dialect. */
14324 : 1254 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14325 : 0 : code = 'q';
14326 : : break;
14327 : :
14328 : 76342 : case 'K':
14329 : 76342 : if (!CONST_INT_P (x))
14330 : : {
14331 : 1 : output_operand_lossage ("operand is not an integer, invalid "
14332 : : "operand code 'K'");
14333 : 1 : return;
14334 : : }
14335 : :
14336 : 76341 : if (INTVAL (x) & IX86_HLE_ACQUIRE)
14337 : : #ifdef HAVE_AS_IX86_HLE
14338 : 22 : fputs ("xacquire ", file);
14339 : : #else
14340 : : fputs ("\n" ASM_BYTE "0xf2\n\t", file);
14341 : : #endif
14342 : 76319 : else if (INTVAL (x) & IX86_HLE_RELEASE)
14343 : : #ifdef HAVE_AS_IX86_HLE
14344 : 24 : fputs ("xrelease ", file);
14345 : : #else
14346 : : fputs ("\n" ASM_BYTE "0xf3\n\t", file);
14347 : : #endif
14348 : : /* We do not want to print value of the operand. */
14349 : 76341 : return;
14350 : :
14351 : 41132 : case 'N':
14352 : 41132 : if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
14353 : 14459 : fputs ("{z}", file);
14354 : 41132 : return;
14355 : :
14356 : 4031 : case 'r':
14357 : 4031 : if (!CONST_INT_P (x) || INTVAL (x) != ROUND_SAE)
14358 : : {
14359 : 2 : output_operand_lossage ("operand is not a specific integer, "
14360 : : "invalid operand code 'r'");
14361 : 2 : return;
14362 : : }
14363 : :
14364 : 4029 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14365 : 1 : fputs (", ", file);
14366 : :
14367 : 4029 : fputs ("{sae}", file);
14368 : :
14369 : 4029 : if (ASSEMBLER_DIALECT == ASM_ATT)
14370 : 4028 : fputs (", ", file);
14371 : :
14372 : 4029 : return;
14373 : :
14374 : 6049 : case 'R':
14375 : 6049 : if (!CONST_INT_P (x))
14376 : : {
14377 : 1 : output_operand_lossage ("operand is not an integer, invalid "
14378 : : "operand code 'R'");
14379 : 1 : return;
14380 : : }
14381 : :
14382 : 6048 : if (ASSEMBLER_DIALECT == ASM_INTEL)
14383 : 2 : fputs (", ", file);
14384 : :
14385 : 6048 : switch (INTVAL (x))
14386 : : {
14387 : 5237 : case ROUND_NEAREST_INT | ROUND_SAE:
14388 : 5237 : fputs ("{rn-sae}", file);
14389 : 5237 : break;
14390 : 637 : case ROUND_NEG_INF | ROUND_SAE:
14391 : 637 : fputs ("{rd-sae}", file);
14392 : 637 : break;
14393 : 52 : case ROUND_POS_INF | ROUND_SAE:
14394 : 52 : fputs ("{ru-sae}", file);
14395 : 52 : break;
14396 : 121 : case ROUND_ZERO | ROUND_SAE:
14397 : 121 : fputs ("{rz-sae}", file);
14398 : 121 : break;
14399 : 1 : default:
14400 : 1 : output_operand_lossage ("operand is not a specific integer, "
14401 : : "invalid operand code 'R'");
14402 : : }
14403 : :
14404 : 6048 : if (ASSEMBLER_DIALECT == ASM_ATT)
14405 : 6046 : fputs (", ", file);
14406 : :
14407 : 6048 : return;
14408 : :
14409 : 8195 : case 'v':
14410 : 8195 : if (MEM_P (x))
14411 : : {
14412 : 8343 : switch (MEM_ADDR_SPACE (x))
14413 : : {
14414 : : case ADDR_SPACE_GENERIC:
14415 : : break;
14416 : 0 : case ADDR_SPACE_SEG_FS:
14417 : 0 : fputs ("fs ", file);
14418 : 0 : break;
14419 : 0 : case ADDR_SPACE_SEG_GS:
14420 : 0 : fputs ("gs ", file);
14421 : 0 : break;
14422 : 0 : default:
14423 : 0 : gcc_unreachable ();
14424 : : }
14425 : : }
14426 : : else
14427 : 0 : output_operand_lossage ("operand is not a memory reference, "
14428 : : "invalid operand code 'v'");
14429 : 8195 : return;
14430 : :
14431 : 0 : case '*':
14432 : 0 : if (ASSEMBLER_DIALECT == ASM_ATT)
14433 : 0 : putc ('*', file);
14434 : 0 : return;
14435 : :
14436 : 271 : case '&':
14437 : 271 : {
14438 : 271 : const char *name = get_some_local_dynamic_name ();
14439 : 271 : if (name == NULL)
14440 : 1 : output_operand_lossage ("'%%&' used without any "
14441 : : "local dynamic TLS references");
14442 : : else
14443 : 270 : assemble_name (file, name);
14444 : 271 : return;
14445 : : }
14446 : :
14447 : 6361604 : case '+':
14448 : 6361604 : {
14449 : 6361604 : rtx x;
14450 : :
14451 : 6361604 : if (!optimize
14452 : 4960507 : || optimize_function_for_size_p (cfun)
14453 : 11138218 : || (!TARGET_BRANCH_PREDICTION_HINTS_NOT_TAKEN
14454 : 4776614 : && !TARGET_BRANCH_PREDICTION_HINTS_TAKEN))
14455 : 6361604 : return;
14456 : :
14457 : 0 : x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
14458 : 0 : if (x)
14459 : : {
14460 : 0 : int pred_val = profile_probability::from_reg_br_prob_note
14461 : 0 : (XINT (x, 0)).to_reg_br_prob_base ();
14462 : :
14463 : 0 : bool taken = pred_val > REG_BR_PROB_BASE / 2;
14464 : : /* We use 3e (DS) prefix for taken branches and
14465 : : 2e (CS) prefix for not taken branches. */
14466 : 0 : if (taken && TARGET_BRANCH_PREDICTION_HINTS_TAKEN)
14467 : 0 : fputs ("ds ; ", file);
14468 : 0 : else if (!taken && TARGET_BRANCH_PREDICTION_HINTS_NOT_TAKEN)
14469 : 0 : fputs ("cs ; ", file);
14470 : : }
14471 : 0 : return;
14472 : : }
14473 : :
14474 : : case ';':
14475 : : #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
14476 : : putc (';', file);
14477 : : #endif
14478 : : return;
14479 : :
14480 : 3509 : case '~':
14481 : 3509 : putc (TARGET_AVX2 ? 'i' : 'f', file);
14482 : 3509 : return;
14483 : :
14484 : 1693 : case 'M':
14485 : 1693 : if (TARGET_X32)
14486 : : {
14487 : : /* NB: 32-bit indices in VSIB address are sign-extended
14488 : : to 64 bits. In x32, if 32-bit address 0xf7fa3010 is
14489 : : sign-extended to 0xfffffffff7fa3010 which is invalid
14490 : : address. Add addr32 prefix if there is no base
14491 : : register nor symbol. */
14492 : 40 : bool ok;
14493 : 40 : struct ix86_address parts;
14494 : 40 : ok = ix86_decompose_address (x, &parts);
14495 : 40 : gcc_assert (ok && parts.index == NULL_RTX);
14496 : 40 : if (parts.base == NULL_RTX
14497 : 40 : && (parts.disp == NULL_RTX
14498 : 34 : || !symbolic_operand (parts.disp,
14499 : 34 : GET_MODE (parts.disp))))
14500 : 34 : fputs ("addr32 ", file);
14501 : : }
14502 : 1693 : return;
14503 : :
14504 : 17044 : case '^':
14505 : 20205 : if (Pmode != word_mode)
14506 : 0 : fputs ("addr32 ", file);
14507 : 17044 : return;
14508 : :
14509 : 14624640 : case '!':
14510 : 14624640 : if (ix86_notrack_prefixed_insn_p (current_output_insn))
14511 : 6613 : fputs ("notrack ", file);
14512 : 14624640 : return;
14513 : :
14514 : 1 : default:
14515 : 1 : output_operand_lossage ("invalid operand code '%c'", code);
14516 : : }
14517 : : }
14518 : :
14519 : 141813834 : if (REG_P (x))
14520 : 84594060 : print_reg (x, code, file);
14521 : :
14522 : 57219774 : else if (MEM_P (x))
14523 : : {
14524 : 32695688 : rtx addr = XEXP (x, 0);
14525 : :
14526 : : /* No `byte ptr' prefix for call instructions ... */
14527 : 32695688 : if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P')
14528 : : {
14529 : 268 : machine_mode mode = GET_MODE (x);
14530 : 268 : const char *size;
14531 : :
14532 : : /* Check for explicit size override codes. */
14533 : 268 : if (code == 'b')
14534 : : size = "BYTE";
14535 : : else if (code == 'w')
14536 : : size = "WORD";
14537 : : else if (code == 'k')
14538 : : size = "DWORD";
14539 : : else if (code == 'q')
14540 : : size = "QWORD";
14541 : : else if (code == 'x')
14542 : : size = "XMMWORD";
14543 : : else if (code == 't')
14544 : : size = "YMMWORD";
14545 : : else if (code == 'g')
14546 : : size = "ZMMWORD";
14547 : 193 : else if (mode == BLKmode)
14548 : : /* ... or BLKmode operands, when not overridden. */
14549 : : size = NULL;
14550 : : else
14551 : 382 : switch (GET_MODE_SIZE (mode))
14552 : : {
14553 : : case 1: size = "BYTE"; break;
14554 : : case 2: size = "WORD"; break;
14555 : : case 4: size = "DWORD"; break;
14556 : : case 8: size = "QWORD"; break;
14557 : : case 12: size = "TBYTE"; break;
14558 : 4 : case 16:
14559 : 4 : if (mode == XFmode)
14560 : : size = "TBYTE";
14561 : : else
14562 : : size = "XMMWORD";
14563 : : break;
14564 : : case 32: size = "YMMWORD"; break;
14565 : : case 64: size = "ZMMWORD"; break;
14566 : 0 : default:
14567 : 0 : gcc_unreachable ();
14568 : : }
14569 : : if (size)
14570 : : {
14571 : 266 : fputs (size, file);
14572 : 266 : fputs (" PTR ", file);
14573 : : }
14574 : : }
14575 : :
14576 : 32695688 : if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
14577 : 0 : output_operand_lossage ("invalid constraints for operand");
14578 : : else
14579 : 32695688 : ix86_print_operand_address_as
14580 : 32939664 : (file, addr, MEM_ADDR_SPACE (x), code == 'p' || code == 'P');
14581 : : }
14582 : :
14583 : 24524086 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == HFmode)
14584 : : {
14585 : 753 : long l = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x),
14586 : 753 : REAL_MODE_FORMAT (HFmode));
14587 : 753 : if (ASSEMBLER_DIALECT == ASM_ATT)
14588 : 753 : putc ('$', file);
14589 : 753 : fprintf (file, "0x%04x", (unsigned int) l);
14590 : 753 : }
14591 : :
14592 : 24523333 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode)
14593 : : {
14594 : 21542 : long l;
14595 : :
14596 : 21542 : REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
14597 : :
14598 : 21542 : if (ASSEMBLER_DIALECT == ASM_ATT)
14599 : 21542 : putc ('$', file);
14600 : : /* Sign extend 32bit SFmode immediate to 8 bytes. */
14601 : 21542 : if (code == 'q')
14602 : 355 : fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x",
14603 : : (unsigned long long) (int) l);
14604 : : else
14605 : 21187 : fprintf (file, "0x%08x", (unsigned int) l);
14606 : : }
14607 : :
14608 : 24501791 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == DFmode)
14609 : : {
14610 : 3554 : long l[2];
14611 : :
14612 : 3554 : REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), l);
14613 : :
14614 : 3554 : if (ASSEMBLER_DIALECT == ASM_ATT)
14615 : 3554 : putc ('$', file);
14616 : 3554 : fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff);
14617 : 3554 : }
14618 : :
14619 : : /* These float cases don't actually occur as immediate operands. */
14620 : 24498237 : else if (CONST_DOUBLE_P (x) && GET_MODE (x) == XFmode)
14621 : : {
14622 : 0 : char dstr[30];
14623 : :
14624 : 0 : real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
14625 : 0 : fputs (dstr, file);
14626 : 0 : }
14627 : :
14628 : : /* Print bcst_mem_operand. */
14629 : 24498237 : else if (GET_CODE (x) == VEC_DUPLICATE)
14630 : : {
14631 : 313 : machine_mode vmode = GET_MODE (x);
14632 : : /* Must be bcst_memory_operand. */
14633 : 313 : gcc_assert (bcst_mem_operand (x, vmode));
14634 : :
14635 : 313 : rtx mem = XEXP (x,0);
14636 : 313 : ix86_print_operand (file, mem, 0);
14637 : :
14638 : 313 : switch (vmode)
14639 : : {
14640 : 28 : case E_V2DImode:
14641 : 28 : case E_V2DFmode:
14642 : 28 : fputs ("{1to2}", file);
14643 : 28 : break;
14644 : 74 : case E_V4SImode:
14645 : 74 : case E_V4SFmode:
14646 : 74 : case E_V4DImode:
14647 : 74 : case E_V4DFmode:
14648 : 74 : fputs ("{1to4}", file);
14649 : 74 : break;
14650 : 93 : case E_V8SImode:
14651 : 93 : case E_V8SFmode:
14652 : 93 : case E_V8DFmode:
14653 : 93 : case E_V8DImode:
14654 : 93 : case E_V8HFmode:
14655 : 93 : fputs ("{1to8}", file);
14656 : 93 : break;
14657 : 110 : case E_V16SFmode:
14658 : 110 : case E_V16SImode:
14659 : 110 : case E_V16HFmode:
14660 : 110 : fputs ("{1to16}", file);
14661 : 110 : break;
14662 : 8 : case E_V32HFmode:
14663 : 8 : fputs ("{1to32}", file);
14664 : 8 : break;
14665 : 0 : default:
14666 : 0 : gcc_unreachable ();
14667 : : }
14668 : : }
14669 : :
14670 : : else
14671 : : {
14672 : : /* We have patterns that allow zero sets of memory, for instance.
14673 : : In 64-bit mode, we should probably support all 8-byte vectors,
14674 : : since we can in fact encode that into an immediate. */
14675 : 24497924 : if (GET_CODE (x) == CONST_VECTOR)
14676 : : {
14677 : 114 : if (x != CONST0_RTX (GET_MODE (x)))
14678 : 2 : output_operand_lossage ("invalid vector immediate");
14679 : 114 : x = const0_rtx;
14680 : : }
14681 : :
14682 : 24497924 : if (code == 'P')
14683 : : {
14684 : 5872137 : if (ix86_force_load_from_GOT_p (x, true))
14685 : : {
14686 : : /* For inline assembly statement, load function address
14687 : : from GOT with 'P' operand modifier to avoid PLT. */
14688 : 4 : x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
14689 : : (TARGET_64BIT
14690 : : ? UNSPEC_GOTPCREL
14691 : : : UNSPEC_GOT));
14692 : 4 : x = gen_rtx_CONST (Pmode, x);
14693 : 4 : x = gen_const_mem (Pmode, x);
14694 : 4 : ix86_print_operand (file, x, 'A');
14695 : 4 : return;
14696 : : }
14697 : : }
14698 : 18625787 : else if (code != 'p')
14699 : : {
14700 : 18625678 : if (CONST_INT_P (x))
14701 : : {
14702 : 15340094 : if (ASSEMBLER_DIALECT == ASM_ATT)
14703 : 15339869 : putc ('$', file);
14704 : : }
14705 : 3285584 : else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
14706 : 9389 : || GET_CODE (x) == LABEL_REF)
14707 : : {
14708 : 3285582 : if (ASSEMBLER_DIALECT == ASM_ATT)
14709 : 3285557 : putc ('$', file);
14710 : : else
14711 : 25 : fputs ("OFFSET FLAT:", file);
14712 : : }
14713 : : }
14714 : 24497920 : if (CONST_INT_P (x))
14715 : 15340180 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
14716 : 9157740 : else if (flag_pic || MACHOPIC_INDIRECT)
14717 : 512462 : output_pic_addr_const (file, x, code);
14718 : : else
14719 : 8645278 : output_addr_const (file, x);
14720 : : }
14721 : : }
14722 : :
14723 : : static bool
14724 : 21083179 : ix86_print_operand_punct_valid_p (unsigned char code)
14725 : : {
14726 : 21083179 : return (code == '*' || code == '+' || code == '&' || code == ';'
14727 : 14641684 : || code == '~' || code == '^' || code == '!');
14728 : : }
14729 : :
14730 : : /* Print a memory operand whose address is ADDR. */
14731 : :
14732 : : static void
14733 : 36208777 : ix86_print_operand_address_as (FILE *file, rtx addr,
14734 : : addr_space_t as, bool raw)
14735 : : {
14736 : 36208777 : struct ix86_address parts;
14737 : 36208777 : rtx base, index, disp;
14738 : 36208777 : int scale;
14739 : 36208777 : int ok;
14740 : 36208777 : bool vsib = false;
14741 : 36208777 : int code = 0;
14742 : :
14743 : 36208777 : if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR)
14744 : : {
14745 : 1693 : ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
14746 : 1693 : gcc_assert (parts.index == NULL_RTX);
14747 : 1693 : parts.index = XVECEXP (addr, 0, 1);
14748 : 1693 : parts.scale = INTVAL (XVECEXP (addr, 0, 2));
14749 : 1693 : addr = XVECEXP (addr, 0, 0);
14750 : 1693 : vsib = true;
14751 : : }
14752 : 36207084 : else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR)
14753 : : {
14754 : 3032667 : gcc_assert (TARGET_64BIT);
14755 : 3032667 : ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
14756 : 3032667 : code = 'q';
14757 : : }
14758 : : else
14759 : 33174417 : ok = ix86_decompose_address (addr, &parts);
14760 : :
14761 : 36208777 : gcc_assert (ok);
14762 : :
14763 : 36208777 : base = parts.base;
14764 : 36208777 : index = parts.index;
14765 : 36208777 : disp = parts.disp;
14766 : 36208777 : scale = parts.scale;
14767 : :
14768 : 36208777 : if (ADDR_SPACE_GENERIC_P (as))
14769 : 35929218 : as = parts.seg;
14770 : : else
14771 : 279559 : gcc_assert (ADDR_SPACE_GENERIC_P (parts.seg));
14772 : :
14773 : 36208777 : if (!ADDR_SPACE_GENERIC_P (as) && !raw)
14774 : : {
14775 : 279575 : if (ASSEMBLER_DIALECT == ASM_ATT)
14776 : 279573 : putc ('%', file);
14777 : :
14778 : 279575 : switch (as)
14779 : : {
14780 : 180014 : case ADDR_SPACE_SEG_FS:
14781 : 180014 : fputs ("fs:", file);
14782 : 180014 : break;
14783 : 99561 : case ADDR_SPACE_SEG_GS:
14784 : 99561 : fputs ("gs:", file);
14785 : 99561 : break;
14786 : 0 : default:
14787 : 0 : gcc_unreachable ();
14788 : : }
14789 : : }
14790 : :
14791 : : /* Use one byte shorter RIP relative addressing for 64bit mode. */
14792 : 36208777 : if (TARGET_64BIT && !base && !index && !raw)
14793 : : {
14794 : 5910727 : rtx symbol = disp;
14795 : :
14796 : 5910727 : if (GET_CODE (disp) == CONST
14797 : 2125267 : && GET_CODE (XEXP (disp, 0)) == PLUS
14798 : 2043237 : && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
14799 : 2043237 : symbol = XEXP (XEXP (disp, 0), 0);
14800 : :
14801 : 5910727 : if (GET_CODE (symbol) == LABEL_REF
14802 : 5910727 : || (GET_CODE (symbol) == SYMBOL_REF
14803 : 5653102 : && SYMBOL_REF_TLS_MODEL (symbol) == 0))
14804 : 5652101 : base = pc_rtx;
14805 : : }
14806 : :
14807 : 36208777 : if (!base && !index)
14808 : : {
14809 : : /* Displacement only requires special attention. */
14810 : 597356 : if (CONST_INT_P (disp))
14811 : : {
14812 : 268829 : if (ASSEMBLER_DIALECT == ASM_INTEL && ADDR_SPACE_GENERIC_P (as))
14813 : 1 : fputs ("ds:", file);
14814 : 268829 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
14815 : : }
14816 : : /* Load the external function address via the GOT slot to avoid PLT. */
14817 : 328527 : else if (GET_CODE (disp) == CONST
14818 : 109692 : && GET_CODE (XEXP (disp, 0)) == UNSPEC
14819 : 82269 : && (XINT (XEXP (disp, 0), 1) == UNSPEC_GOTPCREL
14820 : 8236 : || XINT (XEXP (disp, 0), 1) == UNSPEC_GOT)
14821 : 402560 : && ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
14822 : 24 : output_pic_addr_const (file, disp, 0);
14823 : 328503 : else if (flag_pic)
14824 : 112836 : output_pic_addr_const (file, disp, 0);
14825 : : else
14826 : 215667 : output_addr_const (file, disp);
14827 : : }
14828 : : else
14829 : : {
14830 : : /* Print SImode register names to force addr32 prefix. */
14831 : 35611421 : if (SImode_address_operand (addr, VOIDmode))
14832 : : {
14833 : 37 : if (flag_checking)
14834 : : {
14835 : 37 : gcc_assert (TARGET_64BIT);
14836 : 37 : switch (GET_CODE (addr))
14837 : : {
14838 : 0 : case SUBREG:
14839 : 0 : gcc_assert (GET_MODE (addr) == SImode);
14840 : 0 : gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode);
14841 : : break;
14842 : 37 : case ZERO_EXTEND:
14843 : 37 : case AND:
14844 : 37 : gcc_assert (GET_MODE (addr) == DImode);
14845 : : break;
14846 : 0 : default:
14847 : 0 : gcc_unreachable ();
14848 : : }
14849 : : }
14850 : 37 : gcc_assert (!code);
14851 : : code = 'k';
14852 : : }
14853 : 35611384 : else if (code == 0
14854 : 32581149 : && TARGET_X32
14855 : 483 : && disp
14856 : 411 : && CONST_INT_P (disp)
14857 : 314 : && INTVAL (disp) < -16*1024*1024)
14858 : : {
14859 : : /* X32 runs in 64-bit mode, where displacement, DISP, in
14860 : : address DISP(%r64), is encoded as 32-bit immediate sign-
14861 : : extended from 32-bit to 64-bit. For -0x40000300(%r64),
14862 : : address is %r64 + 0xffffffffbffffd00. When %r64 <
14863 : : 0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64,
14864 : : which is invalid for x32. The correct address is %r64
14865 : : - 0x40000300 == 0xf7ffdd64. To properly encode
14866 : : -0x40000300(%r64) for x32, we zero-extend negative
14867 : : displacement by forcing addr32 prefix which truncates
14868 : : 0xfffffffff7ffdd64 to 0xf7ffdd64. In theory, we should
14869 : : zero-extend all negative displacements, including -1(%rsp).
14870 : : However, for small negative displacements, sign-extension
14871 : : won't cause overflow. We only zero-extend negative
14872 : : displacements if they < -16*1024*1024, which is also used
14873 : : to check legitimate address displacements for PIC. */
14874 : 38 : code = 'k';
14875 : : }
14876 : :
14877 : : /* Since the upper 32 bits of RSP are always zero for x32,
14878 : : we can encode %esp as %rsp to avoid 0x67 prefix if
14879 : : there is no index register. */
14880 : 978 : if (TARGET_X32 && Pmode == SImode
14881 : 35611826 : && !index && base && REG_P (base) && REGNO (base) == SP_REG)
14882 : : code = 'q';
14883 : :
14884 : 35611421 : if (ASSEMBLER_DIALECT == ASM_ATT)
14885 : : {
14886 : 35611104 : if (disp)
14887 : : {
14888 : 31674573 : if (flag_pic)
14889 : 2755528 : output_pic_addr_const (file, disp, 0);
14890 : 28919045 : else if (GET_CODE (disp) == LABEL_REF)
14891 : 8079 : output_asm_label (disp);
14892 : : else
14893 : 28910966 : output_addr_const (file, disp);
14894 : : }
14895 : :
14896 : 35611104 : putc ('(', file);
14897 : 35611104 : if (base)
14898 : 35197646 : print_reg (base, code, file);
14899 : 35611104 : if (index)
14900 : : {
14901 : 1789001 : putc (',', file);
14902 : 3576357 : print_reg (index, vsib ? 0 : code, file);
14903 : 1789001 : if (scale != 1 || vsib)
14904 : 1012335 : fprintf (file, ",%d", scale);
14905 : : }
14906 : 35611104 : putc (')', file);
14907 : : }
14908 : : else
14909 : : {
14910 : 317 : rtx offset = NULL_RTX;
14911 : :
14912 : 317 : if (disp)
14913 : : {
14914 : : /* Pull out the offset of a symbol; print any symbol itself. */
14915 : 257 : if (GET_CODE (disp) == CONST
14916 : 19 : && GET_CODE (XEXP (disp, 0)) == PLUS
14917 : 19 : && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
14918 : : {
14919 : 19 : offset = XEXP (XEXP (disp, 0), 1);
14920 : 19 : disp = gen_rtx_CONST (VOIDmode,
14921 : : XEXP (XEXP (disp, 0), 0));
14922 : : }
14923 : :
14924 : 257 : if (flag_pic)
14925 : 0 : output_pic_addr_const (file, disp, 0);
14926 : 257 : else if (GET_CODE (disp) == LABEL_REF)
14927 : 0 : output_asm_label (disp);
14928 : 257 : else if (CONST_INT_P (disp))
14929 : : offset = disp;
14930 : : else
14931 : 123 : output_addr_const (file, disp);
14932 : : }
14933 : :
14934 : 317 : putc ('[', file);
14935 : 317 : if (base)
14936 : : {
14937 : 274 : print_reg (base, code, file);
14938 : 274 : if (offset)
14939 : : {
14940 : 153 : if (INTVAL (offset) >= 0)
14941 : 19 : putc ('+', file);
14942 : 153 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
14943 : : }
14944 : : }
14945 : 43 : else if (offset)
14946 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
14947 : : else
14948 : 43 : putc ('0', file);
14949 : :
14950 : 317 : if (index)
14951 : : {
14952 : 96 : putc ('+', file);
14953 : 144 : print_reg (index, vsib ? 0 : code, file);
14954 : 96 : if (scale != 1 || vsib)
14955 : 94 : fprintf (file, "*%d", scale);
14956 : : }
14957 : 317 : putc (']', file);
14958 : : }
14959 : : }
14960 : 36208777 : }
14961 : :
14962 : : static void
14963 : 3513090 : ix86_print_operand_address (FILE *file, machine_mode /*mode*/, rtx addr)
14964 : : {
14965 : 3513090 : if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
14966 : 1 : output_operand_lossage ("invalid constraints for operand");
14967 : : else
14968 : 3513089 : ix86_print_operand_address_as (file, addr, ADDR_SPACE_GENERIC, false);
14969 : 3513090 : }
14970 : :
14971 : : /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */
14972 : :
14973 : : static bool
14974 : 13785 : i386_asm_output_addr_const_extra (FILE *file, rtx x)
14975 : : {
14976 : 13785 : rtx op;
14977 : :
14978 : 13785 : if (GET_CODE (x) != UNSPEC)
14979 : : return false;
14980 : :
14981 : 13785 : op = XVECEXP (x, 0, 0);
14982 : 13785 : switch (XINT (x, 1))
14983 : : {
14984 : 1272 : case UNSPEC_GOTOFF:
14985 : 1272 : output_addr_const (file, op);
14986 : 1272 : fputs ("@gotoff", file);
14987 : 1272 : break;
14988 : 0 : case UNSPEC_GOTTPOFF:
14989 : 0 : output_addr_const (file, op);
14990 : : /* FIXME: This might be @TPOFF in Sun ld. */
14991 : 0 : fputs ("@gottpoff", file);
14992 : 0 : break;
14993 : 0 : case UNSPEC_TPOFF:
14994 : 0 : output_addr_const (file, op);
14995 : 0 : fputs ("@tpoff", file);
14996 : 0 : break;
14997 : 10311 : case UNSPEC_NTPOFF:
14998 : 10311 : output_addr_const (file, op);
14999 : 10311 : if (TARGET_64BIT)
15000 : 9583 : fputs ("@tpoff", file);
15001 : : else
15002 : 728 : fputs ("@ntpoff", file);
15003 : : break;
15004 : 30 : case UNSPEC_DTPOFF:
15005 : 30 : output_addr_const (file, op);
15006 : 30 : fputs ("@dtpoff", file);
15007 : 30 : break;
15008 : 2171 : case UNSPEC_GOTNTPOFF:
15009 : 2171 : output_addr_const (file, op);
15010 : 2171 : if (TARGET_64BIT)
15011 : 2171 : fputs (ASSEMBLER_DIALECT == ASM_ATT ?
15012 : : "@gottpoff(%rip)" : "@gottpoff[rip]", file);
15013 : : else
15014 : 0 : fputs ("@gotntpoff", file);
15015 : : break;
15016 : 1 : case UNSPEC_INDNTPOFF:
15017 : 1 : output_addr_const (file, op);
15018 : 1 : fputs ("@indntpoff", file);
15019 : 1 : break;
15020 : 0 : case UNSPEC_SECREL32:
15021 : 0 : output_addr_const (file, op);
15022 : 0 : fputs ("@secrel32", file);
15023 : 0 : break;
15024 : : #if TARGET_MACHO
15025 : : case UNSPEC_MACHOPIC_OFFSET:
15026 : : output_addr_const (file, op);
15027 : : putc ('-', file);
15028 : : machopic_output_function_base_name (file);
15029 : : break;
15030 : : #endif
15031 : :
15032 : : default:
15033 : : return false;
15034 : : }
15035 : :
15036 : : return true;
15037 : : }
15038 : :
15039 : :
15040 : : /* Output code to perform a 387 binary operation in INSN, one of PLUS,
15041 : : MINUS, MULT or DIV. OPERANDS are the insn operands, where operands[3]
15042 : : is the expression of the binary operation. The output may either be
15043 : : emitted here, or returned to the caller, like all output_* functions.
15044 : :
15045 : : There is no guarantee that the operands are the same mode, as they
15046 : : might be within FLOAT or FLOAT_EXTEND expressions. */
15047 : :
15048 : : #ifndef SYSV386_COMPAT
15049 : : /* Set to 1 for compatibility with brain-damaged assemblers. No-one
15050 : : wants to fix the assemblers because that causes incompatibility
15051 : : with gcc. No-one wants to fix gcc because that causes
15052 : : incompatibility with assemblers... You can use the option of
15053 : : -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way. */
15054 : : #define SYSV386_COMPAT 1
15055 : : #endif
15056 : :
15057 : : const char *
15058 : 606584 : output_387_binary_op (rtx_insn *insn, rtx *operands)
15059 : : {
15060 : 606584 : static char buf[40];
15061 : 606584 : const char *p;
15062 : 606584 : bool is_sse
15063 : 606584 : = (SSE_REG_P (operands[0])
15064 : 661658 : || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]));
15065 : :
15066 : 55074 : if (is_sse)
15067 : : p = "%v";
15068 : 55074 : else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
15069 : 55067 : || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
15070 : : p = "fi";
15071 : : else
15072 : 606584 : p = "f";
15073 : :
15074 : 606584 : strcpy (buf, p);
15075 : :
15076 : 606584 : switch (GET_CODE (operands[3]))
15077 : : {
15078 : : case PLUS:
15079 : : p = "add"; break;
15080 : : case MINUS:
15081 : : p = "sub"; break;
15082 : 95215 : case MULT:
15083 : 95215 : p = "mul"; break;
15084 : 27870 : case DIV:
15085 : 27870 : p = "div"; break;
15086 : 0 : default:
15087 : 0 : gcc_unreachable ();
15088 : : }
15089 : :
15090 : 606584 : strcat (buf, p);
15091 : :
15092 : 606584 : if (is_sse)
15093 : : {
15094 : 551510 : p = GET_MODE (operands[0]) == SFmode ? "ss" : "sd";
15095 : 551510 : strcat (buf, p);
15096 : :
15097 : 551510 : if (TARGET_AVX)
15098 : : p = "\t{%2, %1, %0|%0, %1, %2}";
15099 : : else
15100 : 533026 : p = "\t{%2, %0|%0, %2}";
15101 : :
15102 : 551510 : strcat (buf, p);
15103 : 551510 : return buf;
15104 : : }
15105 : :
15106 : : /* Even if we do not want to check the inputs, this documents input
15107 : : constraints. Which helps in understanding the following code. */
15108 : 55074 : if (flag_checking)
15109 : : {
15110 : 55073 : if (STACK_REG_P (operands[0])
15111 : 55073 : && ((REG_P (operands[1])
15112 : 53473 : && REGNO (operands[0]) == REGNO (operands[1])
15113 : 49382 : && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
15114 : 5691 : || (REG_P (operands[2])
15115 : 5691 : && REGNO (operands[0]) == REGNO (operands[2])
15116 : 5691 : && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
15117 : 110146 : && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
15118 : : ; /* ok */
15119 : : else
15120 : 0 : gcc_unreachable ();
15121 : : }
15122 : :
15123 : 55074 : switch (GET_CODE (operands[3]))
15124 : : {
15125 : 40417 : case MULT:
15126 : 40417 : case PLUS:
15127 : 40417 : if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
15128 : 2007 : std::swap (operands[1], operands[2]);
15129 : :
15130 : : /* know operands[0] == operands[1]. */
15131 : :
15132 : 40417 : if (MEM_P (operands[2]))
15133 : : {
15134 : : p = "%Z2\t%2";
15135 : : break;
15136 : : }
15137 : :
15138 : 36119 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
15139 : : {
15140 : 21118 : if (STACK_TOP_P (operands[0]))
15141 : : /* How is it that we are storing to a dead operand[2]?
15142 : : Well, presumably operands[1] is dead too. We can't
15143 : : store the result to st(0) as st(0) gets popped on this
15144 : : instruction. Instead store to operands[2] (which I
15145 : : think has to be st(1)). st(1) will be popped later.
15146 : : gcc <= 2.8.1 didn't have this check and generated
15147 : : assembly code that the Unixware assembler rejected. */
15148 : : p = "p\t{%0, %2|%2, %0}"; /* st(1) = st(0) op st(1); pop */
15149 : : else
15150 : : p = "p\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0); pop */
15151 : : break;
15152 : : }
15153 : :
15154 : 15001 : if (STACK_TOP_P (operands[0]))
15155 : : p = "\t{%y2, %0|%0, %y2}"; /* st(0) = st(0) op st(r2) */
15156 : : else
15157 : : p = "\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0) */
15158 : : break;
15159 : :
15160 : 14657 : case MINUS:
15161 : 14657 : case DIV:
15162 : 14657 : if (MEM_P (operands[1]))
15163 : : {
15164 : : p = "r%Z1\t%1";
15165 : : break;
15166 : : }
15167 : :
15168 : 14219 : if (MEM_P (operands[2]))
15169 : : {
15170 : : p = "%Z2\t%2";
15171 : : break;
15172 : : }
15173 : :
15174 : 12714 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
15175 : : {
15176 : : #if SYSV386_COMPAT
15177 : : /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
15178 : : derived assemblers, confusingly reverse the direction of
15179 : : the operation for fsub{r} and fdiv{r} when the
15180 : : destination register is not st(0). The Intel assembler
15181 : : doesn't have this brain damage. Read !SYSV386_COMPAT to
15182 : : figure out what the hardware really does. */
15183 : 6049 : if (STACK_TOP_P (operands[0]))
15184 : : p = "{p\t%0, %2|rp\t%2, %0}";
15185 : : else
15186 : : p = "{rp\t%2, %0|p\t%0, %2}";
15187 : : #else
15188 : : if (STACK_TOP_P (operands[0]))
15189 : : /* As above for fmul/fadd, we can't store to st(0). */
15190 : : p = "rp\t{%0, %2|%2, %0}"; /* st(1) = st(0) op st(1); pop */
15191 : : else
15192 : : p = "p\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0); pop */
15193 : : #endif
15194 : : break;
15195 : : }
15196 : :
15197 : 6665 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
15198 : : {
15199 : : #if SYSV386_COMPAT
15200 : 3147 : if (STACK_TOP_P (operands[0]))
15201 : : p = "{rp\t%0, %1|p\t%1, %0}";
15202 : : else
15203 : : p = "{p\t%1, %0|rp\t%0, %1}";
15204 : : #else
15205 : : if (STACK_TOP_P (operands[0]))
15206 : : p = "p\t{%0, %1|%1, %0}"; /* st(1) = st(1) op st(0); pop */
15207 : : else
15208 : : p = "rp\t{%1, %0|%0, %1}"; /* st(r2) = st(0) op st(r2); pop */
15209 : : #endif
15210 : : break;
15211 : : }
15212 : :
15213 : 3518 : if (STACK_TOP_P (operands[0]))
15214 : : {
15215 : 2679 : if (STACK_TOP_P (operands[1]))
15216 : : p = "\t{%y2, %0|%0, %y2}"; /* st(0) = st(0) op st(r2) */
15217 : : else
15218 : : p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
15219 : : break;
15220 : : }
15221 : 839 : else if (STACK_TOP_P (operands[1]))
15222 : : {
15223 : : #if SYSV386_COMPAT
15224 : : p = "{\t%1, %0|r\t%0, %1}";
15225 : : #else
15226 : : p = "r\t{%1, %0|%0, %1}"; /* st(r2) = st(0) op st(r2) */
15227 : : #endif
15228 : : }
15229 : : else
15230 : : {
15231 : : #if SYSV386_COMPAT
15232 : : p = "{r\t%2, %0|\t%0, %2}";
15233 : : #else
15234 : : p = "\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0) */
15235 : : #endif
15236 : : }
15237 : : break;
15238 : :
15239 : 0 : default:
15240 : 0 : gcc_unreachable ();
15241 : : }
15242 : :
15243 : 55074 : strcat (buf, p);
15244 : 55074 : return buf;
15245 : : }
15246 : :
15247 : : /* Return needed mode for entity in optimize_mode_switching pass. */
15248 : :
15249 : : static int
15250 : 1637 : ix86_dirflag_mode_needed (rtx_insn *insn)
15251 : : {
15252 : 1637 : if (CALL_P (insn))
15253 : : {
15254 : 337 : if (cfun->machine->func_type == TYPE_NORMAL)
15255 : : return X86_DIRFLAG_ANY;
15256 : : else
15257 : : /* No need to emit CLD in interrupt handler for TARGET_CLD. */
15258 : 337 : return TARGET_CLD ? X86_DIRFLAG_ANY : X86_DIRFLAG_RESET;
15259 : : }
15260 : :
15261 : 1300 : if (recog_memoized (insn) < 0)
15262 : : return X86_DIRFLAG_ANY;
15263 : :
15264 : 1298 : if (get_attr_type (insn) == TYPE_STR)
15265 : : {
15266 : : /* Emit cld instruction if stringops are used in the function. */
15267 : 1 : if (cfun->machine->func_type == TYPE_NORMAL)
15268 : 0 : return TARGET_CLD ? X86_DIRFLAG_RESET : X86_DIRFLAG_ANY;
15269 : : else
15270 : : return X86_DIRFLAG_RESET;
15271 : : }
15272 : :
15273 : : return X86_DIRFLAG_ANY;
15274 : : }
15275 : :
15276 : : /* Check if a 256bit or 512 bit AVX register is referenced inside of EXP. */
15277 : :
15278 : : static bool
15279 : 2125994 : ix86_check_avx_upper_register (const_rtx exp)
15280 : : {
15281 : : /* construct_container may return a parallel with expr_list
15282 : : which contains the real reg and mode */
15283 : 2125994 : subrtx_iterator::array_type array;
15284 : 8088347 : FOR_EACH_SUBRTX (iter, array, exp, NONCONST)
15285 : : {
15286 : 6118433 : const_rtx x = *iter;
15287 : 2470077 : if (SSE_REG_P (x)
15288 : 803612 : && !EXT_REX_SSE_REG_P (x)
15289 : 7713819 : && GET_MODE_BITSIZE (GET_MODE (x)) > 128)
15290 : 156080 : return true;
15291 : : }
15292 : :
15293 : 1969914 : return false;
15294 : 2125994 : }
15295 : :
15296 : : /* Check if a 256bit or 512bit AVX register is referenced in stores. */
15297 : :
15298 : : static void
15299 : 48610 : ix86_check_avx_upper_stores (rtx dest, const_rtx, void *data)
15300 : : {
15301 : 48610 : if (SSE_REG_P (dest)
15302 : 12479 : && !EXT_REX_SSE_REG_P (dest)
15303 : 73568 : && GET_MODE_BITSIZE (GET_MODE (dest)) > 128)
15304 : : {
15305 : 724 : bool *used = (bool *) data;
15306 : 724 : *used = true;
15307 : : }
15308 : 48610 : }
15309 : :
15310 : : /* Return needed mode for entity in optimize_mode_switching pass. */
15311 : :
15312 : : static int
15313 : 1994365 : ix86_avx_u128_mode_needed (rtx_insn *insn)
15314 : : {
15315 : 1994365 : if (DEBUG_INSN_P (insn))
15316 : : return AVX_U128_ANY;
15317 : :
15318 : 1994365 : if (CALL_P (insn))
15319 : : {
15320 : 46584 : rtx link;
15321 : :
15322 : : /* Needed mode is set to AVX_U128_CLEAN if there are
15323 : : no 256bit or 512bit modes used in function arguments. */
15324 : 46584 : for (link = CALL_INSN_FUNCTION_USAGE (insn);
15325 : 118398 : link;
15326 : 71814 : link = XEXP (link, 1))
15327 : : {
15328 : 72855 : if (GET_CODE (XEXP (link, 0)) == USE)
15329 : : {
15330 : 71483 : rtx arg = XEXP (XEXP (link, 0), 0);
15331 : :
15332 : 71483 : if (ix86_check_avx_upper_register (arg))
15333 : : return AVX_U128_DIRTY;
15334 : : }
15335 : : }
15336 : :
15337 : : /* Needed mode is set to AVX_U128_CLEAN if there are no 256bit
15338 : : nor 512bit registers used in the function return register. */
15339 : 45543 : bool avx_upper_reg_found = false;
15340 : 45543 : note_stores (insn, ix86_check_avx_upper_stores,
15341 : : &avx_upper_reg_found);
15342 : 45543 : if (avx_upper_reg_found)
15343 : : return AVX_U128_DIRTY;
15344 : :
15345 : : /* If the function is known to preserve some SSE registers,
15346 : : RA and previous passes can legitimately rely on that for
15347 : : modes wider than 256 bits. It's only safe to issue a
15348 : : vzeroupper if all SSE registers are clobbered. */
15349 : 45372 : const function_abi &abi = insn_callee_abi (insn);
15350 : 45372 : if (vzeroupper_pattern (PATTERN (insn), VOIDmode)
15351 : : /* Should be safe to issue an vzeroupper before sibling_call_p.
15352 : : Also there not mode_exit for sibling_call, so there could be
15353 : : missing vzeroupper for that. */
15354 : 45372 : || !(SIBLING_CALL_P (insn)
15355 : 44154 : || hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
15356 : 44154 : abi.mode_clobbers (V4DImode))))
15357 : 9144 : return AVX_U128_ANY;
15358 : :
15359 : 36228 : return AVX_U128_CLEAN;
15360 : : }
15361 : :
15362 : 1947781 : rtx set = single_set (insn);
15363 : 1947781 : if (set)
15364 : : {
15365 : 1879137 : rtx dest = SET_DEST (set);
15366 : 1879137 : rtx src = SET_SRC (set);
15367 : 1407325 : if (SSE_REG_P (dest)
15368 : 534599 : && !EXT_REX_SSE_REG_P (dest)
15369 : 2936843 : && GET_MODE_BITSIZE (GET_MODE (dest)) > 128)
15370 : : {
15371 : : /* This is an YMM/ZMM load. Return AVX_U128_DIRTY if the
15372 : : source isn't zero. */
15373 : 165537 : if (standard_sse_constant_p (src, GET_MODE (dest)) != 1)
15374 : : return AVX_U128_DIRTY;
15375 : : else
15376 : : return AVX_U128_ANY;
15377 : : }
15378 : : else
15379 : : {
15380 : 1713600 : if (ix86_check_avx_upper_register (src))
15381 : : return AVX_U128_DIRTY;
15382 : : }
15383 : :
15384 : : /* This isn't YMM/ZMM load/store. */
15385 : : return AVX_U128_ANY;
15386 : : }
15387 : :
15388 : : /* Require DIRTY mode if a 256bit or 512bit AVX register is referenced.
15389 : : Hardware changes state only when a 256bit register is written to,
15390 : : but we need to prevent the compiler from moving optimal insertion
15391 : : point above eventual read from 256bit or 512 bit register. */
15392 : 68644 : if (ix86_check_avx_upper_register (PATTERN (insn)))
15393 : : return AVX_U128_DIRTY;
15394 : :
15395 : : return AVX_U128_ANY;
15396 : : }
15397 : :
15398 : : /* Return mode that i387 must be switched into
15399 : : prior to the execution of insn. */
15400 : :
15401 : : static int
15402 : 449254 : ix86_i387_mode_needed (int entity, rtx_insn *insn)
15403 : : {
15404 : 449254 : enum attr_i387_cw mode;
15405 : :
15406 : : /* The mode UNINITIALIZED is used to store control word after a
15407 : : function call or ASM pattern. The mode ANY specify that function
15408 : : has no requirements on the control word and make no changes in the
15409 : : bits we are interested in. */
15410 : :
15411 : 449254 : if (CALL_P (insn)
15412 : 449254 : || (NONJUMP_INSN_P (insn)
15413 : 369157 : && (asm_noperands (PATTERN (insn)) >= 0
15414 : 369157 : || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
15415 : 15387 : return I387_CW_UNINITIALIZED;
15416 : :
15417 : 433867 : if (recog_memoized (insn) < 0)
15418 : : return I387_CW_ANY;
15419 : :
15420 : 432977 : mode = get_attr_i387_cw (insn);
15421 : :
15422 : 432977 : switch (entity)
15423 : : {
15424 : 0 : case I387_ROUNDEVEN:
15425 : 0 : if (mode == I387_CW_ROUNDEVEN)
15426 : : return mode;
15427 : : break;
15428 : :
15429 : 426985 : case I387_TRUNC:
15430 : 426985 : if (mode == I387_CW_TRUNC)
15431 : : return mode;
15432 : : break;
15433 : :
15434 : 4573 : case I387_FLOOR:
15435 : 4573 : if (mode == I387_CW_FLOOR)
15436 : : return mode;
15437 : : break;
15438 : :
15439 : 1419 : case I387_CEIL:
15440 : 1419 : if (mode == I387_CW_CEIL)
15441 : : return mode;
15442 : : break;
15443 : :
15444 : 0 : default:
15445 : 0 : gcc_unreachable ();
15446 : : }
15447 : :
15448 : : return I387_CW_ANY;
15449 : : }
15450 : :
15451 : : /* Return mode that entity must be switched into
15452 : : prior to the execution of insn. */
15453 : :
15454 : : static int
15455 : 2445256 : ix86_mode_needed (int entity, rtx_insn *insn, HARD_REG_SET)
15456 : : {
15457 : 2445256 : switch (entity)
15458 : : {
15459 : 1637 : case X86_DIRFLAG:
15460 : 1637 : return ix86_dirflag_mode_needed (insn);
15461 : 1994365 : case AVX_U128:
15462 : 1994365 : return ix86_avx_u128_mode_needed (insn);
15463 : 449254 : case I387_ROUNDEVEN:
15464 : 449254 : case I387_TRUNC:
15465 : 449254 : case I387_FLOOR:
15466 : 449254 : case I387_CEIL:
15467 : 449254 : return ix86_i387_mode_needed (entity, insn);
15468 : 0 : default:
15469 : 0 : gcc_unreachable ();
15470 : : }
15471 : : return 0;
15472 : : }
15473 : :
15474 : : /* Calculate mode of upper 128bit AVX registers after the insn. */
15475 : :
15476 : : static int
15477 : 1994365 : ix86_avx_u128_mode_after (int mode, rtx_insn *insn)
15478 : : {
15479 : 1994365 : rtx pat = PATTERN (insn);
15480 : :
15481 : 1994365 : if (vzeroupper_pattern (pat, VOIDmode)
15482 : 1994365 : || vzeroall_pattern (pat, VOIDmode))
15483 : 209 : return AVX_U128_CLEAN;
15484 : :
15485 : : /* We know that state is clean after CALL insn if there are no
15486 : : 256bit or 512bit registers used in the function return register. */
15487 : 1994156 : if (CALL_P (insn))
15488 : : {
15489 : 46538 : bool avx_upper_reg_found = false;
15490 : 46538 : note_stores (insn, ix86_check_avx_upper_stores, &avx_upper_reg_found);
15491 : :
15492 : 46538 : if (avx_upper_reg_found)
15493 : : return AVX_U128_DIRTY;
15494 : :
15495 : : /* If the function desn't clobber any sse registers or only clobber
15496 : : 128-bit part, Then vzeroupper isn't issued before the function exit.
15497 : : the status not CLEAN but ANY after the function. */
15498 : 45985 : const function_abi &abi = insn_callee_abi (insn);
15499 : 45985 : if (!(SIBLING_CALL_P (insn)
15500 : 44772 : || hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
15501 : 44772 : abi.mode_clobbers (V4DImode))))
15502 : 9440 : return AVX_U128_ANY;
15503 : :
15504 : 36545 : return AVX_U128_CLEAN;
15505 : : }
15506 : :
15507 : : /* Otherwise, return current mode. Remember that if insn
15508 : : references AVX 256bit or 512bit registers, the mode was already
15509 : : changed to DIRTY from MODE_NEEDED. */
15510 : : return mode;
15511 : : }
15512 : :
15513 : : /* Return the mode that an insn results in. */
15514 : :
15515 : : static int
15516 : 2444452 : ix86_mode_after (int entity, int mode, rtx_insn *insn, HARD_REG_SET)
15517 : : {
15518 : 2444452 : switch (entity)
15519 : : {
15520 : : case X86_DIRFLAG:
15521 : : return mode;
15522 : 1994365 : case AVX_U128:
15523 : 1994365 : return ix86_avx_u128_mode_after (mode, insn);
15524 : : case I387_ROUNDEVEN:
15525 : : case I387_TRUNC:
15526 : : case I387_FLOOR:
15527 : : case I387_CEIL:
15528 : : return mode;
15529 : 0 : default:
15530 : 0 : gcc_unreachable ();
15531 : : }
15532 : : }
15533 : :
15534 : : static int
15535 : 118 : ix86_dirflag_mode_entry (void)
15536 : : {
15537 : : /* For TARGET_CLD or in the interrupt handler we can't assume
15538 : : direction flag state at function entry. */
15539 : 118 : if (TARGET_CLD
15540 : 116 : || cfun->machine->func_type != TYPE_NORMAL)
15541 : 118 : return X86_DIRFLAG_ANY;
15542 : :
15543 : : return X86_DIRFLAG_RESET;
15544 : : }
15545 : :
15546 : : static int
15547 : 119363 : ix86_avx_u128_mode_entry (void)
15548 : : {
15549 : 119363 : tree arg;
15550 : :
15551 : : /* Entry mode is set to AVX_U128_DIRTY if there are
15552 : : 256bit or 512bit modes used in function arguments. */
15553 : 300796 : for (arg = DECL_ARGUMENTS (current_function_decl); arg;
15554 : 181433 : arg = TREE_CHAIN (arg))
15555 : : {
15556 : 215309 : rtx incoming = DECL_INCOMING_RTL (arg);
15557 : :
15558 : 215309 : if (incoming && ix86_check_avx_upper_register (incoming))
15559 : : return AVX_U128_DIRTY;
15560 : : }
15561 : :
15562 : : return AVX_U128_CLEAN;
15563 : : }
15564 : :
15565 : : /* Return a mode that ENTITY is assumed to be
15566 : : switched to at function entry. */
15567 : :
15568 : : static int
15569 : 73938 : ix86_mode_entry (int entity)
15570 : : {
15571 : 73938 : switch (entity)
15572 : : {
15573 : 118 : case X86_DIRFLAG:
15574 : 118 : return ix86_dirflag_mode_entry ();
15575 : 72716 : case AVX_U128:
15576 : 72716 : return ix86_avx_u128_mode_entry ();
15577 : : case I387_ROUNDEVEN:
15578 : : case I387_TRUNC:
15579 : : case I387_FLOOR:
15580 : : case I387_CEIL:
15581 : : return I387_CW_ANY;
15582 : 0 : default:
15583 : 0 : gcc_unreachable ();
15584 : : }
15585 : : }
15586 : :
15587 : : static int
15588 : 71523 : ix86_avx_u128_mode_exit (void)
15589 : : {
15590 : 71523 : rtx reg = crtl->return_rtx;
15591 : :
15592 : : /* Exit mode is set to AVX_U128_DIRTY if there are 256bit
15593 : : or 512 bit modes used in the function return register. */
15594 : 71523 : if (reg && ix86_check_avx_upper_register (reg))
15595 : : return AVX_U128_DIRTY;
15596 : :
15597 : : /* Exit mode is set to AVX_U128_DIRTY if there are 256bit or 512bit
15598 : : modes used in function arguments, otherwise return AVX_U128_CLEAN.
15599 : : */
15600 : 46647 : return ix86_avx_u128_mode_entry ();
15601 : : }
15602 : :
15603 : : /* Return a mode that ENTITY is assumed to be
15604 : : switched to at function exit. */
15605 : :
15606 : : static int
15607 : 72600 : ix86_mode_exit (int entity)
15608 : : {
15609 : 72600 : switch (entity)
15610 : : {
15611 : : case X86_DIRFLAG:
15612 : : return X86_DIRFLAG_ANY;
15613 : 71523 : case AVX_U128:
15614 : 71523 : return ix86_avx_u128_mode_exit ();
15615 : 1045 : case I387_ROUNDEVEN:
15616 : 1045 : case I387_TRUNC:
15617 : 1045 : case I387_FLOOR:
15618 : 1045 : case I387_CEIL:
15619 : 1045 : return I387_CW_ANY;
15620 : 0 : default:
15621 : 0 : gcc_unreachable ();
15622 : : }
15623 : : }
15624 : :
15625 : : static int
15626 : 2149471 : ix86_mode_priority (int, int n)
15627 : : {
15628 : 2149471 : return n;
15629 : : }
15630 : :
15631 : : /* Output code to initialize control word copies used by trunc?f?i and
15632 : : rounding patterns. CURRENT_MODE is set to current control word,
15633 : : while NEW_MODE is set to new control word. */
15634 : :
15635 : : static void
15636 : 3244 : emit_i387_cw_initialization (int mode)
15637 : : {
15638 : 3244 : rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
15639 : 3244 : rtx new_mode;
15640 : :
15641 : 3244 : enum ix86_stack_slot slot;
15642 : :
15643 : 3244 : rtx reg = gen_reg_rtx (HImode);
15644 : :
15645 : 3244 : emit_insn (gen_x86_fnstcw_1 (stored_mode));
15646 : 3244 : emit_move_insn (reg, copy_rtx (stored_mode));
15647 : :
15648 : 3244 : switch (mode)
15649 : : {
15650 : 0 : case I387_CW_ROUNDEVEN:
15651 : : /* round to nearest */
15652 : 0 : emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
15653 : 0 : slot = SLOT_CW_ROUNDEVEN;
15654 : 0 : break;
15655 : :
15656 : 3024 : case I387_CW_TRUNC:
15657 : : /* round toward zero (truncate) */
15658 : 3024 : emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
15659 : 3024 : slot = SLOT_CW_TRUNC;
15660 : 3024 : break;
15661 : :
15662 : 153 : case I387_CW_FLOOR:
15663 : : /* round down toward -oo */
15664 : 153 : emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
15665 : 153 : emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
15666 : 153 : slot = SLOT_CW_FLOOR;
15667 : 153 : break;
15668 : :
15669 : 67 : case I387_CW_CEIL:
15670 : : /* round up toward +oo */
15671 : 67 : emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
15672 : 67 : emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
15673 : 67 : slot = SLOT_CW_CEIL;
15674 : 67 : break;
15675 : :
15676 : 0 : default:
15677 : 0 : gcc_unreachable ();
15678 : : }
15679 : :
15680 : 3244 : gcc_assert (slot < MAX_386_STACK_LOCALS);
15681 : :
15682 : 3244 : new_mode = assign_386_stack_local (HImode, slot);
15683 : 3244 : emit_move_insn (new_mode, reg);
15684 : 3244 : }
15685 : :
15686 : : /* Generate one or more insns to set ENTITY to MODE. */
15687 : :
15688 : : static void
15689 : 45601 : ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
15690 : : HARD_REG_SET regs_live ATTRIBUTE_UNUSED)
15691 : : {
15692 : 45601 : switch (entity)
15693 : : {
15694 : 263 : case X86_DIRFLAG:
15695 : 263 : if (mode == X86_DIRFLAG_RESET)
15696 : 263 : emit_insn (gen_cld ());
15697 : : break;
15698 : 37194 : case AVX_U128:
15699 : 37194 : if (mode == AVX_U128_CLEAN)
15700 : 18048 : ix86_expand_avx_vzeroupper ();
15701 : : break;
15702 : 8144 : case I387_ROUNDEVEN:
15703 : 8144 : case I387_TRUNC:
15704 : 8144 : case I387_FLOOR:
15705 : 8144 : case I387_CEIL:
15706 : 8144 : if (mode != I387_CW_ANY
15707 : 8144 : && mode != I387_CW_UNINITIALIZED)
15708 : 3244 : emit_i387_cw_initialization (mode);
15709 : : break;
15710 : 0 : default:
15711 : 0 : gcc_unreachable ();
15712 : : }
15713 : 45601 : }
15714 : :
15715 : : /* Output code for INSN to convert a float to a signed int. OPERANDS
15716 : : are the insn operands. The output may be [HSD]Imode and the input
15717 : : operand may be [SDX]Fmode. */
15718 : :
15719 : : const char *
15720 : 7376 : output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp)
15721 : : {
15722 : 7376 : bool stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG);
15723 : 7376 : bool dimode_p = GET_MODE (operands[0]) == DImode;
15724 : 7376 : int round_mode = get_attr_i387_cw (insn);
15725 : :
15726 : 7376 : static char buf[40];
15727 : 7376 : const char *p;
15728 : :
15729 : : /* Jump through a hoop or two for DImode, since the hardware has no
15730 : : non-popping instruction. We used to do this a different way, but
15731 : : that was somewhat fragile and broke with post-reload splitters. */
15732 : 7376 : if ((dimode_p || fisttp) && !stack_top_dies)
15733 : 25 : output_asm_insn ("fld\t%y1", operands);
15734 : :
15735 : 7376 : gcc_assert (STACK_TOP_P (operands[1]));
15736 : 7376 : gcc_assert (MEM_P (operands[0]));
15737 : 7376 : gcc_assert (GET_MODE (operands[1]) != TFmode);
15738 : :
15739 : 7376 : if (fisttp)
15740 : : return "fisttp%Z0\t%0";
15741 : :
15742 : 7375 : strcpy (buf, "fist");
15743 : :
15744 : 7375 : if (round_mode != I387_CW_ANY)
15745 : 7327 : output_asm_insn ("fldcw\t%3", operands);
15746 : :
15747 : 7375 : p = "p%Z0\t%0";
15748 : 7375 : strcat (buf, p + !(stack_top_dies || dimode_p));
15749 : :
15750 : 7375 : output_asm_insn (buf, operands);
15751 : :
15752 : 7375 : if (round_mode != I387_CW_ANY)
15753 : 7327 : output_asm_insn ("fldcw\t%2", operands);
15754 : :
15755 : : return "";
15756 : : }
15757 : :
15758 : : /* Output code for x87 ffreep insn. The OPNO argument, which may only
15759 : : have the values zero or one, indicates the ffreep insn's operand
15760 : : from the OPERANDS array. */
15761 : :
15762 : : static const char *
15763 : 282646 : output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
15764 : : {
15765 : 0 : if (TARGET_USE_FFREEP)
15766 : : #ifdef HAVE_AS_IX86_FFREEP
15767 : 0 : return opno ? "ffreep\t%y1" : "ffreep\t%y0";
15768 : : #else
15769 : : {
15770 : : static char retval[32];
15771 : : int regno = REGNO (operands[opno]);
15772 : :
15773 : : gcc_assert (STACK_REGNO_P (regno));
15774 : :
15775 : : regno -= FIRST_STACK_REG;
15776 : :
15777 : : snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
15778 : : return retval;
15779 : : }
15780 : : #endif
15781 : :
15782 : 0 : return opno ? "fstp\t%y1" : "fstp\t%y0";
15783 : : }
15784 : :
15785 : :
15786 : : /* Output code for INSN to compare OPERANDS. EFLAGS_P is 1 when fcomi
15787 : : should be used. UNORDERED_P is true when fucom should be used. */
15788 : :
15789 : : const char *
15790 : 107803 : output_fp_compare (rtx_insn *insn, rtx *operands,
15791 : : bool eflags_p, bool unordered_p)
15792 : : {
15793 : 107803 : rtx *xops = eflags_p ? &operands[0] : &operands[1];
15794 : 107803 : bool stack_top_dies;
15795 : :
15796 : 107803 : static char buf[40];
15797 : 107803 : const char *p;
15798 : :
15799 : 107803 : gcc_assert (STACK_TOP_P (xops[0]));
15800 : :
15801 : 107803 : stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG);
15802 : :
15803 : 107803 : if (eflags_p)
15804 : : {
15805 : 107803 : p = unordered_p ? "fucomi" : "fcomi";
15806 : 107803 : strcpy (buf, p);
15807 : :
15808 : 107803 : p = "p\t{%y1, %0|%0, %y1}";
15809 : 107803 : strcat (buf, p + !stack_top_dies);
15810 : :
15811 : 107803 : return buf;
15812 : : }
15813 : :
15814 : 0 : if (STACK_REG_P (xops[1])
15815 : 0 : && stack_top_dies
15816 : 0 : && find_regno_note (insn, REG_DEAD, FIRST_STACK_REG + 1))
15817 : : {
15818 : 0 : gcc_assert (REGNO (xops[1]) == FIRST_STACK_REG + 1);
15819 : :
15820 : : /* If both the top of the 387 stack die, and the other operand
15821 : : is also a stack register that dies, then this must be a
15822 : : `fcompp' float compare. */
15823 : 0 : p = unordered_p ? "fucompp" : "fcompp";
15824 : 0 : strcpy (buf, p);
15825 : : }
15826 : 0 : else if (const0_operand (xops[1], VOIDmode))
15827 : : {
15828 : 0 : gcc_assert (!unordered_p);
15829 : 0 : strcpy (buf, "ftst");
15830 : : }
15831 : : else
15832 : : {
15833 : 0 : if (GET_MODE_CLASS (GET_MODE (xops[1])) == MODE_INT)
15834 : : {
15835 : 0 : gcc_assert (!unordered_p);
15836 : : p = "ficom";
15837 : : }
15838 : : else
15839 : 0 : p = unordered_p ? "fucom" : "fcom";
15840 : :
15841 : 0 : strcpy (buf, p);
15842 : :
15843 : 0 : p = "p%Z2\t%y2";
15844 : 0 : strcat (buf, p + !stack_top_dies);
15845 : : }
15846 : :
15847 : 0 : output_asm_insn (buf, operands);
15848 : 0 : return "fnstsw\t%0";
15849 : : }
15850 : :
15851 : : void
15852 : 160738 : ix86_output_addr_vec_elt (FILE *file, int value)
15853 : : {
15854 : 160738 : const char *directive = ASM_LONG;
15855 : :
15856 : : #ifdef ASM_QUAD
15857 : 160738 : if (TARGET_LP64)
15858 : 149168 : directive = ASM_QUAD;
15859 : : #else
15860 : : gcc_assert (!TARGET_64BIT);
15861 : : #endif
15862 : :
15863 : 160738 : fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
15864 : 160738 : }
15865 : :
15866 : : void
15867 : 22713 : ix86_output_addr_diff_elt (FILE *file, int value, int rel)
15868 : : {
15869 : 22713 : const char *directive = ASM_LONG;
15870 : :
15871 : : #ifdef ASM_QUAD
15872 : 33912 : if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
15873 : : directive = ASM_QUAD;
15874 : : #else
15875 : : gcc_assert (!TARGET_64BIT);
15876 : : #endif
15877 : : /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand. */
15878 : 22713 : if (TARGET_64BIT || TARGET_VXWORKS_RTP)
15879 : 11199 : fprintf (file, "%s%s%d-%s%d\n",
15880 : : directive, LPREFIX, value, LPREFIX, rel);
15881 : : #if TARGET_MACHO
15882 : : else if (TARGET_MACHO)
15883 : : {
15884 : : fprintf (file, ASM_LONG "%s%d-", LPREFIX, value);
15885 : : machopic_output_function_base_name (file);
15886 : : putc ('\n', file);
15887 : : }
15888 : : #endif
15889 : 11514 : else if (HAVE_AS_GOTOFF_IN_DATA)
15890 : 11514 : fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
15891 : : else
15892 : : asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
15893 : : GOT_SYMBOL_NAME, LPREFIX, value);
15894 : 22713 : }
15895 : :
15896 : : #define LEA_MAX_STALL (3)
15897 : : #define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1)
15898 : :
15899 : : /* Increase given DISTANCE in half-cycles according to
15900 : : dependencies between PREV and NEXT instructions.
15901 : : Add 1 half-cycle if there is no dependency and
15902 : : go to next cycle if there is some dependecy. */
15903 : :
15904 : : static unsigned int
15905 : 2144 : increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance)
15906 : : {
15907 : 2144 : df_ref def, use;
15908 : :
15909 : 2144 : if (!prev || !next)
15910 : 758 : return distance + (distance & 1) + 2;
15911 : :
15912 : 1386 : if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev))
15913 : 225 : return distance + 1;
15914 : :
15915 : 1932 : FOR_EACH_INSN_USE (use, next)
15916 : 2461 : FOR_EACH_INSN_DEF (def, prev)
15917 : 1690 : if (!DF_REF_IS_ARTIFICIAL (def)
15918 : 1690 : && DF_REF_REGNO (use) == DF_REF_REGNO (def))
15919 : 737 : return distance + (distance & 1) + 2;
15920 : :
15921 : 424 : return distance + 1;
15922 : : }
15923 : :
15924 : : /* Function checks if instruction INSN defines register number
15925 : : REGNO1 or REGNO2. */
15926 : :
15927 : : bool
15928 : 2091 : insn_defines_reg (unsigned int regno1, unsigned int regno2,
15929 : : rtx_insn *insn)
15930 : : {
15931 : 2091 : df_ref def;
15932 : :
15933 : 3783 : FOR_EACH_INSN_DEF (def, insn)
15934 : 2090 : if (DF_REF_REG_DEF_P (def)
15935 : 2090 : && !DF_REF_IS_ARTIFICIAL (def)
15936 : 2090 : && (regno1 == DF_REF_REGNO (def)
15937 : 1706 : || regno2 == DF_REF_REGNO (def)))
15938 : : return true;
15939 : :
15940 : : return false;
15941 : : }
15942 : :
15943 : : /* Function checks if instruction INSN uses register number
15944 : : REGNO as a part of address expression. */
15945 : :
15946 : : static bool
15947 : 1190 : insn_uses_reg_mem (unsigned int regno, rtx insn)
15948 : : {
15949 : 1190 : df_ref use;
15950 : :
15951 : 2500 : FOR_EACH_INSN_USE (use, insn)
15952 : 1398 : if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use))
15953 : : return true;
15954 : :
15955 : : return false;
15956 : : }
15957 : :
15958 : : /* Search backward for non-agu definition of register number REGNO1
15959 : : or register number REGNO2 in basic block starting from instruction
15960 : : START up to head of basic block or instruction INSN.
15961 : :
15962 : : Function puts true value into *FOUND var if definition was found
15963 : : and false otherwise.
15964 : :
15965 : : Distance in half-cycles between START and found instruction or head
15966 : : of BB is added to DISTANCE and returned. */
15967 : :
15968 : : static int
15969 : 625 : distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2,
15970 : : rtx_insn *insn, int distance,
15971 : : rtx_insn *start, bool *found)
15972 : : {
15973 : 625 : basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL;
15974 : 625 : rtx_insn *prev = start;
15975 : 625 : rtx_insn *next = NULL;
15976 : :
15977 : 625 : *found = false;
15978 : :
15979 : 625 : while (prev
15980 : 1877 : && prev != insn
15981 : 1877 : && distance < LEA_SEARCH_THRESHOLD)
15982 : : {
15983 : 1673 : if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev))
15984 : : {
15985 : 954 : distance = increase_distance (prev, next, distance);
15986 : 954 : if (insn_defines_reg (regno1, regno2, prev))
15987 : : {
15988 : 236 : if (recog_memoized (prev) < 0
15989 : 236 : || get_attr_type (prev) != TYPE_LEA)
15990 : : {
15991 : 200 : *found = true;
15992 : 200 : return distance;
15993 : : }
15994 : : }
15995 : :
15996 : : next = prev;
15997 : : }
15998 : 1473 : if (prev == BB_HEAD (bb))
15999 : : break;
16000 : :
16001 : 1252 : prev = PREV_INSN (prev);
16002 : : }
16003 : :
16004 : : return distance;
16005 : : }
16006 : :
16007 : : /* Search backward for non-agu definition of register number REGNO1
16008 : : or register number REGNO2 in INSN's basic block until
16009 : : 1. Pass LEA_SEARCH_THRESHOLD instructions, or
16010 : : 2. Reach neighbor BBs boundary, or
16011 : : 3. Reach agu definition.
16012 : : Returns the distance between the non-agu definition point and INSN.
16013 : : If no definition point, returns -1. */
16014 : :
16015 : : static int
16016 : 428 : distance_non_agu_define (unsigned int regno1, unsigned int regno2,
16017 : : rtx_insn *insn)
16018 : : {
16019 : 428 : basic_block bb = BLOCK_FOR_INSN (insn);
16020 : 428 : int distance = 0;
16021 : 428 : bool found = false;
16022 : :
16023 : 428 : if (insn != BB_HEAD (bb))
16024 : 428 : distance = distance_non_agu_define_in_bb (regno1, regno2, insn,
16025 : : distance, PREV_INSN (insn),
16026 : : &found);
16027 : :
16028 : 428 : if (!found && distance < LEA_SEARCH_THRESHOLD)
16029 : : {
16030 : 166 : edge e;
16031 : 166 : edge_iterator ei;
16032 : 166 : bool simple_loop = false;
16033 : :
16034 : 337 : FOR_EACH_EDGE (e, ei, bb->preds)
16035 : 208 : if (e->src == bb)
16036 : : {
16037 : : simple_loop = true;
16038 : : break;
16039 : : }
16040 : :
16041 : 166 : if (simple_loop)
16042 : 37 : distance = distance_non_agu_define_in_bb (regno1, regno2,
16043 : : insn, distance,
16044 : 37 : BB_END (bb), &found);
16045 : : else
16046 : : {
16047 : 129 : int shortest_dist = -1;
16048 : 129 : bool found_in_bb = false;
16049 : :
16050 : 289 : FOR_EACH_EDGE (e, ei, bb->preds)
16051 : : {
16052 : 160 : int bb_dist
16053 : 320 : = distance_non_agu_define_in_bb (regno1, regno2,
16054 : : insn, distance,
16055 : 160 : BB_END (e->src),
16056 : : &found_in_bb);
16057 : 160 : if (found_in_bb)
16058 : : {
16059 : 24 : if (shortest_dist < 0)
16060 : : shortest_dist = bb_dist;
16061 : 0 : else if (bb_dist > 0)
16062 : 0 : shortest_dist = MIN (bb_dist, shortest_dist);
16063 : :
16064 : 24 : found = true;
16065 : : }
16066 : : }
16067 : :
16068 : 129 : distance = shortest_dist;
16069 : : }
16070 : : }
16071 : :
16072 : 428 : if (!found)
16073 : : return -1;
16074 : :
16075 : 200 : return distance >> 1;
16076 : : }
16077 : :
16078 : : /* Return the distance in half-cycles between INSN and the next
16079 : : insn that uses register number REGNO in memory address added
16080 : : to DISTANCE. Return -1 if REGNO0 is set.
16081 : :
16082 : : Put true value into *FOUND if register usage was found and
16083 : : false otherwise.
16084 : : Put true value into *REDEFINED if register redefinition was
16085 : : found and false otherwise. */
16086 : :
16087 : : static int
16088 : 764 : distance_agu_use_in_bb (unsigned int regno,
16089 : : rtx_insn *insn, int distance, rtx_insn *start,
16090 : : bool *found, bool *redefined)
16091 : : {
16092 : 764 : basic_block bb = NULL;
16093 : 764 : rtx_insn *next = start;
16094 : 764 : rtx_insn *prev = NULL;
16095 : :
16096 : 764 : *found = false;
16097 : 764 : *redefined = false;
16098 : :
16099 : 764 : if (start != NULL_RTX)
16100 : : {
16101 : 747 : bb = BLOCK_FOR_INSN (start);
16102 : 747 : if (start != BB_HEAD (bb))
16103 : : /* If insn and start belong to the same bb, set prev to insn,
16104 : : so the call to increase_distance will increase the distance
16105 : : between insns by 1. */
16106 : 407 : prev = insn;
16107 : : }
16108 : :
16109 : 2578 : while (next
16110 : 2578 : && next != insn
16111 : 2578 : && distance < LEA_SEARCH_THRESHOLD)
16112 : : {
16113 : 2381 : if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next))
16114 : : {
16115 : 1190 : distance = increase_distance(prev, next, distance);
16116 : 1190 : if (insn_uses_reg_mem (regno, next))
16117 : : {
16118 : : /* Return DISTANCE if OP0 is used in memory
16119 : : address in NEXT. */
16120 : 88 : *found = true;
16121 : 88 : return distance;
16122 : : }
16123 : :
16124 : 1102 : if (insn_defines_reg (regno, INVALID_REGNUM, next))
16125 : : {
16126 : : /* Return -1 if OP0 is set in NEXT. */
16127 : 157 : *redefined = true;
16128 : 157 : return -1;
16129 : : }
16130 : :
16131 : : prev = next;
16132 : : }
16133 : :
16134 : 2136 : if (next == BB_END (bb))
16135 : : break;
16136 : :
16137 : 1814 : next = NEXT_INSN (next);
16138 : : }
16139 : :
16140 : : return distance;
16141 : : }
16142 : :
16143 : : /* Return the distance between INSN and the next insn that uses
16144 : : register number REGNO0 in memory address. Return -1 if no such
16145 : : a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set. */
16146 : :
16147 : : static int
16148 : 428 : distance_agu_use (unsigned int regno0, rtx_insn *insn)
16149 : : {
16150 : 428 : basic_block bb = BLOCK_FOR_INSN (insn);
16151 : 428 : int distance = 0;
16152 : 428 : bool found = false;
16153 : 428 : bool redefined = false;
16154 : :
16155 : 428 : if (insn != BB_END (bb))
16156 : 407 : distance = distance_agu_use_in_bb (regno0, insn, distance,
16157 : : NEXT_INSN (insn),
16158 : : &found, &redefined);
16159 : :
16160 : 428 : if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD)
16161 : : {
16162 : 249 : edge e;
16163 : 249 : edge_iterator ei;
16164 : 249 : bool simple_loop = false;
16165 : :
16166 : 536 : FOR_EACH_EDGE (e, ei, bb->succs)
16167 : 357 : if (e->dest == bb)
16168 : : {
16169 : : simple_loop = true;
16170 : : break;
16171 : : }
16172 : :
16173 : 249 : if (simple_loop)
16174 : 70 : distance = distance_agu_use_in_bb (regno0, insn,
16175 : : distance, BB_HEAD (bb),
16176 : : &found, &redefined);
16177 : : else
16178 : : {
16179 : 179 : int shortest_dist = -1;
16180 : 179 : bool found_in_bb = false;
16181 : 179 : bool redefined_in_bb = false;
16182 : :
16183 : 466 : FOR_EACH_EDGE (e, ei, bb->succs)
16184 : : {
16185 : 287 : int bb_dist
16186 : 574 : = distance_agu_use_in_bb (regno0, insn,
16187 : 287 : distance, BB_HEAD (e->dest),
16188 : : &found_in_bb, &redefined_in_bb);
16189 : 287 : if (found_in_bb)
16190 : : {
16191 : 17 : if (shortest_dist < 0)
16192 : : shortest_dist = bb_dist;
16193 : 2 : else if (bb_dist > 0)
16194 : 2 : shortest_dist = MIN (bb_dist, shortest_dist);
16195 : :
16196 : 17 : found = true;
16197 : : }
16198 : : }
16199 : :
16200 : 179 : distance = shortest_dist;
16201 : : }
16202 : : }
16203 : :
16204 : 428 : if (!found || redefined)
16205 : : return -1;
16206 : :
16207 : 86 : return distance >> 1;
16208 : : }
16209 : :
16210 : : /* Define this macro to tune LEA priority vs ADD, it take effect when
16211 : : there is a dilemma of choosing LEA or ADD
16212 : : Negative value: ADD is more preferred than LEA
16213 : : Zero: Neutral
16214 : : Positive value: LEA is more preferred than ADD. */
16215 : : #define IX86_LEA_PRIORITY 0
16216 : :
16217 : : /* Return true if usage of lea INSN has performance advantage
16218 : : over a sequence of instructions. Instructions sequence has
16219 : : SPLIT_COST cycles higher latency than lea latency. */
16220 : :
16221 : : static bool
16222 : 1624 : ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
16223 : : unsigned int regno2, int split_cost, bool has_scale)
16224 : : {
16225 : 1624 : int dist_define, dist_use;
16226 : :
16227 : : /* For Atom processors newer than Bonnell, if using a 2-source or
16228 : : 3-source LEA for non-destructive destination purposes, or due to
16229 : : wanting ability to use SCALE, the use of LEA is justified. */
16230 : 1624 : if (!TARGET_CPU_P (BONNELL))
16231 : : {
16232 : 1196 : if (has_scale)
16233 : : return true;
16234 : 1177 : if (split_cost < 1)
16235 : : return false;
16236 : 406 : if (regno0 == regno1 || regno0 == regno2)
16237 : : return false;
16238 : : return true;
16239 : : }
16240 : :
16241 : : /* Remember recog_data content. */
16242 : 428 : struct recog_data_d recog_data_save = recog_data;
16243 : :
16244 : 428 : dist_define = distance_non_agu_define (regno1, regno2, insn);
16245 : 428 : dist_use = distance_agu_use (regno0, insn);
16246 : :
16247 : : /* distance_non_agu_define can call get_attr_type which can call
16248 : : recog_memoized, restore recog_data back to previous content. */
16249 : 428 : recog_data = recog_data_save;
16250 : :
16251 : 428 : if (dist_define < 0 || dist_define >= LEA_MAX_STALL)
16252 : : {
16253 : : /* If there is no non AGU operand definition, no AGU
16254 : : operand usage and split cost is 0 then both lea
16255 : : and non lea variants have same priority. Currently
16256 : : we prefer lea for 64 bit code and non lea on 32 bit
16257 : : code. */
16258 : 230 : if (dist_use < 0 && split_cost == 0)
16259 : 100 : return TARGET_64BIT || IX86_LEA_PRIORITY;
16260 : : else
16261 : : return true;
16262 : : }
16263 : :
16264 : : /* With longer definitions distance lea is more preferable.
16265 : : Here we change it to take into account splitting cost and
16266 : : lea priority. */
16267 : 198 : dist_define += split_cost + IX86_LEA_PRIORITY;
16268 : :
16269 : : /* If there is no use in memory addess then we just check
16270 : : that split cost exceeds AGU stall. */
16271 : 198 : if (dist_use < 0)
16272 : 195 : return dist_define > LEA_MAX_STALL;
16273 : :
16274 : : /* If this insn has both backward non-agu dependence and forward
16275 : : agu dependence, the one with short distance takes effect. */
16276 : 3 : return dist_define >= dist_use;
16277 : : }
16278 : :
16279 : : /* Return true if we need to split op0 = op1 + op2 into a sequence of
16280 : : move and add to avoid AGU stalls. */
16281 : :
16282 : : bool
16283 : 8965804 : ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[])
16284 : : {
16285 : 8965804 : unsigned int regno0, regno1, regno2;
16286 : :
16287 : : /* Check if we need to optimize. */
16288 : 8965804 : if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
16289 : 8964988 : return false;
16290 : :
16291 : 816 : regno0 = true_regnum (operands[0]);
16292 : 816 : regno1 = true_regnum (operands[1]);
16293 : 816 : regno2 = true_regnum (operands[2]);
16294 : :
16295 : : /* We need to split only adds with non destructive
16296 : : destination operand. */
16297 : 816 : if (regno0 == regno1 || regno0 == regno2)
16298 : : return false;
16299 : : else
16300 : 245 : return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false);
16301 : : }
16302 : :
16303 : : /* Return true if we should emit lea instruction instead of mov
16304 : : instruction. */
16305 : :
16306 : : bool
16307 : 29172810 : ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[])
16308 : : {
16309 : 29172810 : unsigned int regno0, regno1;
16310 : :
16311 : : /* Check if we need to optimize. */
16312 : 29172810 : if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
16313 : 29170533 : return false;
16314 : :
16315 : : /* Use lea for reg to reg moves only. */
16316 : 2277 : if (!REG_P (operands[0]) || !REG_P (operands[1]))
16317 : : return false;
16318 : :
16319 : 460 : regno0 = true_regnum (operands[0]);
16320 : 460 : regno1 = true_regnum (operands[1]);
16321 : :
16322 : 460 : return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false);
16323 : : }
16324 : :
16325 : : /* Return true if we need to split lea into a sequence of
16326 : : instructions to avoid AGU stalls during peephole2. */
16327 : :
16328 : : bool
16329 : 11135000 : ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
16330 : : {
16331 : 11135000 : unsigned int regno0, regno1, regno2;
16332 : 11135000 : int split_cost;
16333 : 11135000 : struct ix86_address parts;
16334 : 11135000 : int ok;
16335 : :
16336 : : /* The "at least two components" test below might not catch simple
16337 : : move or zero extension insns if parts.base is non-NULL and parts.disp
16338 : : is const0_rtx as the only components in the address, e.g. if the
16339 : : register is %rbp or %r13. As this test is much cheaper and moves or
16340 : : zero extensions are the common case, do this check first. */
16341 : 11135000 : if (REG_P (operands[1])
16342 : 11135000 : || (SImode_address_operand (operands[1], VOIDmode)
16343 : 130045 : && REG_P (XEXP (operands[1], 0))))
16344 : 4088198 : return false;
16345 : :
16346 : 7046802 : ok = ix86_decompose_address (operands[1], &parts);
16347 : 7046802 : gcc_assert (ok);
16348 : :
16349 : : /* There should be at least two components in the address. */
16350 : 7046802 : if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX)
16351 : 7046802 : + (parts.disp != NULL_RTX) + (parts.scale > 1) < 2)
16352 : : return false;
16353 : :
16354 : : /* We should not split into add if non legitimate pic
16355 : : operand is used as displacement. */
16356 : 2658804 : if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp))
16357 : : return false;
16358 : :
16359 : 2609734 : regno0 = true_regnum (operands[0]) ;
16360 : 2609734 : regno1 = INVALID_REGNUM;
16361 : 2609734 : regno2 = INVALID_REGNUM;
16362 : :
16363 : 2609734 : if (parts.base)
16364 : 2539484 : regno1 = true_regnum (parts.base);
16365 : 2609734 : if (parts.index)
16366 : 461736 : regno2 = true_regnum (parts.index);
16367 : :
16368 : : /* Use add for a = a + b and a = b + a since it is faster and shorter
16369 : : than lea for most processors. For the processors like BONNELL, if
16370 : : the destination register of LEA holds an actual address which will
16371 : : be used soon, LEA is better and otherwise ADD is better. */
16372 : 2609734 : if (!TARGET_CPU_P (BONNELL)
16373 : 2609607 : && parts.scale == 1
16374 : 2374257 : && (!parts.disp || parts.disp == const0_rtx)
16375 : 169138 : && (regno0 == regno1 || regno0 == regno2))
16376 : : return true;
16377 : :
16378 : : /* Split with -Oz if the encoding requires fewer bytes. */
16379 : 2603212 : if (optimize_size > 1
16380 : 27 : && parts.scale > 1
16381 : 4 : && !parts.base
16382 : 4 : && (!parts.disp || parts.disp == const0_rtx))
16383 : : return true;
16384 : :
16385 : : /* Check we need to optimize. */
16386 : 2603208 : if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
16387 : 2602869 : return false;
16388 : :
16389 : 339 : split_cost = 0;
16390 : :
16391 : : /* Compute how many cycles we will add to execution time
16392 : : if split lea into a sequence of instructions. */
16393 : 339 : if (parts.base || parts.index)
16394 : : {
16395 : : /* Have to use mov instruction if non desctructive
16396 : : destination form is used. */
16397 : 339 : if (regno1 != regno0 && regno2 != regno0)
16398 : 259 : split_cost += 1;
16399 : :
16400 : : /* Have to add index to base if both exist. */
16401 : 339 : if (parts.base && parts.index)
16402 : 54 : split_cost += 1;
16403 : :
16404 : : /* Have to use shift and adds if scale is 2 or greater. */
16405 : 339 : if (parts.scale > 1)
16406 : : {
16407 : 29 : if (regno0 != regno1)
16408 : 22 : split_cost += 1;
16409 : 7 : else if (regno2 == regno0)
16410 : 1 : split_cost += 4;
16411 : : else
16412 : 6 : split_cost += parts.scale;
16413 : : }
16414 : :
16415 : : /* Have to use add instruction with immediate if
16416 : : disp is non zero. */
16417 : 339 : if (parts.disp && parts.disp != const0_rtx)
16418 : 278 : split_cost += 1;
16419 : :
16420 : : /* Subtract the price of lea. */
16421 : 339 : split_cost -= 1;
16422 : : }
16423 : :
16424 : 339 : return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost,
16425 : 339 : parts.scale > 1);
16426 : : }
16427 : :
16428 : : /* Return true if it is ok to optimize an ADD operation to LEA
16429 : : operation to avoid flag register consumation. For most processors,
16430 : : ADD is faster than LEA. For the processors like BONNELL, if the
16431 : : destination register of LEA holds an actual address which will be
16432 : : used soon, LEA is better and otherwise ADD is better. */
16433 : :
16434 : : bool
16435 : 9030638 : ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[])
16436 : : {
16437 : 9030638 : unsigned int regno0 = true_regnum (operands[0]);
16438 : 9030638 : unsigned int regno1 = true_regnum (operands[1]);
16439 : 9030638 : unsigned int regno2 = true_regnum (operands[2]);
16440 : :
16441 : : /* If a = b + c, (a!=b && a!=c), must use lea form. */
16442 : 9030638 : if (regno0 != regno1 && regno0 != regno2)
16443 : : return true;
16444 : :
16445 : 7012747 : if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
16446 : 7012167 : return false;
16447 : :
16448 : 580 : return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false);
16449 : : }
16450 : :
16451 : : /* Return true if destination reg of SET_BODY is shift count of
16452 : : USE_BODY. */
16453 : :
16454 : : static bool
16455 : 94 : ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
16456 : : {
16457 : 94 : rtx set_dest;
16458 : 94 : rtx shift_rtx;
16459 : 94 : int i;
16460 : :
16461 : : /* Retrieve destination of SET_BODY. */
16462 : 94 : switch (GET_CODE (set_body))
16463 : : {
16464 : 76 : case SET:
16465 : 76 : set_dest = SET_DEST (set_body);
16466 : 76 : if (!set_dest || !REG_P (set_dest))
16467 : : return false;
16468 : 75 : break;
16469 : 9 : case PARALLEL:
16470 : 27 : for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
16471 : 18 : if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
16472 : : use_body))
16473 : : return true;
16474 : : /* FALLTHROUGH */
16475 : : default:
16476 : : return false;
16477 : : }
16478 : :
16479 : : /* Retrieve shift count of USE_BODY. */
16480 : 75 : switch (GET_CODE (use_body))
16481 : : {
16482 : 25 : case SET:
16483 : 25 : shift_rtx = XEXP (use_body, 1);
16484 : 25 : break;
16485 : 25 : case PARALLEL:
16486 : 75 : for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
16487 : 50 : if (ix86_dep_by_shift_count_body (set_body,
16488 : 50 : XVECEXP (use_body, 0, i)))
16489 : : return true;
16490 : : /* FALLTHROUGH */
16491 : : default:
16492 : : return false;
16493 : : }
16494 : :
16495 : 25 : if (shift_rtx
16496 : 25 : && (GET_CODE (shift_rtx) == ASHIFT
16497 : 21 : || GET_CODE (shift_rtx) == LSHIFTRT
16498 : 5 : || GET_CODE (shift_rtx) == ASHIFTRT
16499 : 0 : || GET_CODE (shift_rtx) == ROTATE
16500 : 0 : || GET_CODE (shift_rtx) == ROTATERT))
16501 : : {
16502 : 25 : rtx shift_count = XEXP (shift_rtx, 1);
16503 : :
16504 : : /* Return true if shift count is dest of SET_BODY. */
16505 : 25 : if (REG_P (shift_count))
16506 : : {
16507 : : /* Add check since it can be invoked before register
16508 : : allocation in pre-reload schedule. */
16509 : 0 : if (reload_completed
16510 : 0 : && true_regnum (set_dest) == true_regnum (shift_count))
16511 : : return true;
16512 : 0 : else if (REGNO(set_dest) == REGNO(shift_count))
16513 : : return true;
16514 : : }
16515 : : }
16516 : :
16517 : : return false;
16518 : : }
16519 : :
16520 : : /* Return true if destination reg of SET_INSN is shift count of
16521 : : USE_INSN. */
16522 : :
16523 : : bool
16524 : 26 : ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
16525 : : {
16526 : 26 : return ix86_dep_by_shift_count_body (PATTERN (set_insn),
16527 : 26 : PATTERN (use_insn));
16528 : : }
16529 : :
16530 : : /* Return TRUE if the operands to a vec_interleave_{high,low}v2df
16531 : : are ok, keeping in mind the possible movddup alternative. */
16532 : :
16533 : : bool
16534 : 86074 : ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high)
16535 : : {
16536 : 86074 : if (MEM_P (operands[0]))
16537 : 2091 : return rtx_equal_p (operands[0], operands[1 + high]);
16538 : 83983 : if (MEM_P (operands[1]) && MEM_P (operands[2]))
16539 : 896 : return false;
16540 : : return true;
16541 : : }
16542 : :
16543 : : /* A subroutine of ix86_build_signbit_mask. If VECT is true,
16544 : : then replicate the value for all elements of the vector
16545 : : register. */
16546 : :
16547 : : rtx
16548 : 74772 : ix86_build_const_vector (machine_mode mode, bool vect, rtx value)
16549 : : {
16550 : 74772 : int i, n_elt;
16551 : 74772 : rtvec v;
16552 : 74772 : machine_mode scalar_mode;
16553 : :
16554 : 74772 : switch (mode)
16555 : : {
16556 : 1036 : case E_V64QImode:
16557 : 1036 : case E_V32QImode:
16558 : 1036 : case E_V16QImode:
16559 : 1036 : case E_V32HImode:
16560 : 1036 : case E_V16HImode:
16561 : 1036 : case E_V8HImode:
16562 : 1036 : case E_V16SImode:
16563 : 1036 : case E_V8SImode:
16564 : 1036 : case E_V4SImode:
16565 : 1036 : case E_V2SImode:
16566 : 1036 : case E_V8DImode:
16567 : 1036 : case E_V4DImode:
16568 : 1036 : case E_V2DImode:
16569 : 1036 : gcc_assert (vect);
16570 : : /* FALLTHRU */
16571 : 74772 : case E_V2HFmode:
16572 : 74772 : case E_V4HFmode:
16573 : 74772 : case E_V8HFmode:
16574 : 74772 : case E_V16HFmode:
16575 : 74772 : case E_V32HFmode:
16576 : 74772 : case E_V16SFmode:
16577 : 74772 : case E_V8SFmode:
16578 : 74772 : case E_V4SFmode:
16579 : 74772 : case E_V2SFmode:
16580 : 74772 : case E_V8DFmode:
16581 : 74772 : case E_V4DFmode:
16582 : 74772 : case E_V2DFmode:
16583 : 74772 : case E_V32BFmode:
16584 : 74772 : case E_V16BFmode:
16585 : 74772 : case E_V8BFmode:
16586 : 74772 : case E_V4BFmode:
16587 : 74772 : case E_V2BFmode:
16588 : 74772 : n_elt = GET_MODE_NUNITS (mode);
16589 : 74772 : v = rtvec_alloc (n_elt);
16590 : 74772 : scalar_mode = GET_MODE_INNER (mode);
16591 : :
16592 : 74772 : RTVEC_ELT (v, 0) = value;
16593 : :
16594 : 231440 : for (i = 1; i < n_elt; ++i)
16595 : 156668 : RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode);
16596 : :
16597 : 74772 : return gen_rtx_CONST_VECTOR (mode, v);
16598 : :
16599 : 0 : default:
16600 : 0 : gcc_unreachable ();
16601 : : }
16602 : : }
16603 : :
16604 : : /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
16605 : : and ix86_expand_int_vcond. Create a mask for the sign bit in MODE
16606 : : for an SSE register. If VECT is true, then replicate the mask for
16607 : : all elements of the vector register. If INVERT is true, then create
16608 : : a mask excluding the sign bit. */
16609 : :
16610 : : rtx
16611 : 53866 : ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert)
16612 : : {
16613 : 53866 : machine_mode vec_mode, imode;
16614 : 53866 : wide_int w;
16615 : 53866 : rtx mask, v;
16616 : :
16617 : 53866 : switch (mode)
16618 : : {
16619 : : case E_V2HFmode:
16620 : : case E_V4HFmode:
16621 : : case E_V8HFmode:
16622 : : case E_V16HFmode:
16623 : : case E_V32HFmode:
16624 : : case E_V32BFmode:
16625 : : case E_V16BFmode:
16626 : : case E_V8BFmode:
16627 : : case E_V4BFmode:
16628 : : case E_V2BFmode:
16629 : : vec_mode = mode;
16630 : : imode = HImode;
16631 : : break;
16632 : :
16633 : 23147 : case E_V16SImode:
16634 : 23147 : case E_V16SFmode:
16635 : 23147 : case E_V8SImode:
16636 : 23147 : case E_V4SImode:
16637 : 23147 : case E_V8SFmode:
16638 : 23147 : case E_V4SFmode:
16639 : 23147 : case E_V2SFmode:
16640 : 23147 : case E_V2SImode:
16641 : 23147 : vec_mode = mode;
16642 : 23147 : imode = SImode;
16643 : 23147 : break;
16644 : :
16645 : 27728 : case E_V8DImode:
16646 : 27728 : case E_V4DImode:
16647 : 27728 : case E_V2DImode:
16648 : 27728 : case E_V8DFmode:
16649 : 27728 : case E_V4DFmode:
16650 : 27728 : case E_V2DFmode:
16651 : 27728 : vec_mode = mode;
16652 : 27728 : imode = DImode;
16653 : 27728 : break;
16654 : :
16655 : 2591 : case E_TImode:
16656 : 2591 : case E_TFmode:
16657 : 2591 : vec_mode = VOIDmode;
16658 : 2591 : imode = TImode;
16659 : 2591 : break;
16660 : :
16661 : 0 : default:
16662 : 0 : gcc_unreachable ();
16663 : : }
16664 : :
16665 : 53866 : machine_mode inner_mode = GET_MODE_INNER (mode);
16666 : 107732 : w = wi::set_bit_in_zero (GET_MODE_BITSIZE (inner_mode) - 1,
16667 : 107732 : GET_MODE_BITSIZE (inner_mode));
16668 : 53866 : if (invert)
16669 : 17586 : w = wi::bit_not (w);
16670 : :
16671 : : /* Force this value into the low part of a fp vector constant. */
16672 : 53866 : mask = immed_wide_int_const (w, imode);
16673 : 53866 : mask = gen_lowpart (inner_mode, mask);
16674 : :
16675 : 53866 : if (vec_mode == VOIDmode)
16676 : 2591 : return force_reg (inner_mode, mask);
16677 : :
16678 : 51275 : v = ix86_build_const_vector (vec_mode, vect, mask);
16679 : 51275 : return force_reg (vec_mode, v);
16680 : 53866 : }
16681 : :
16682 : : /* Return HOST_WIDE_INT for const vector OP in MODE. */
16683 : :
16684 : : HOST_WIDE_INT
16685 : 157546 : ix86_convert_const_vector_to_integer (rtx op, machine_mode mode)
16686 : : {
16687 : 336649 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
16688 : 0 : gcc_unreachable ();
16689 : :
16690 : 157546 : int nunits = GET_MODE_NUNITS (mode);
16691 : 315092 : wide_int val = wi::zero (GET_MODE_BITSIZE (mode));
16692 : 157546 : machine_mode innermode = GET_MODE_INNER (mode);
16693 : 157546 : unsigned int innermode_bits = GET_MODE_BITSIZE (innermode);
16694 : :
16695 : 157546 : switch (mode)
16696 : : {
16697 : : case E_V2QImode:
16698 : : case E_V4QImode:
16699 : : case E_V2HImode:
16700 : : case E_V8QImode:
16701 : : case E_V4HImode:
16702 : : case E_V2SImode:
16703 : 520424 : for (int i = 0; i < nunits; ++i)
16704 : : {
16705 : 365118 : int v = INTVAL (XVECEXP (op, 0, i));
16706 : 365118 : wide_int wv = wi::shwi (v, innermode_bits);
16707 : 365118 : val = wi::insert (val, wv, innermode_bits * i, innermode_bits);
16708 : 365118 : }
16709 : : break;
16710 : : case E_V2HFmode:
16711 : : case E_V2BFmode:
16712 : : case E_V4HFmode:
16713 : : case E_V4BFmode:
16714 : : case E_V2SFmode:
16715 : 6730 : for (int i = 0; i < nunits; ++i)
16716 : : {
16717 : 4490 : rtx x = XVECEXP (op, 0, i);
16718 : 4490 : int v = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x),
16719 : 4490 : REAL_MODE_FORMAT (innermode));
16720 : 4490 : wide_int wv = wi::shwi (v, innermode_bits);
16721 : 4490 : val = wi::insert (val, wv, innermode_bits * i, innermode_bits);
16722 : 4490 : }
16723 : : break;
16724 : 0 : default:
16725 : 0 : gcc_unreachable ();
16726 : : }
16727 : :
16728 : 157546 : return val.to_shwi ();
16729 : 157546 : }
16730 : :
16731 : 32 : int ix86_get_flags_cc (rtx_code code)
16732 : : {
16733 : 32 : switch (code)
16734 : : {
16735 : : case NE: return X86_CCNE;
16736 : : case EQ: return X86_CCE;
16737 : : case GE: return X86_CCNL;
16738 : : case GT: return X86_CCNLE;
16739 : : case LE: return X86_CCLE;
16740 : : case LT: return X86_CCL;
16741 : : case GEU: return X86_CCNB;
16742 : : case GTU: return X86_CCNBE;
16743 : : case LEU: return X86_CCBE;
16744 : : case LTU: return X86_CCB;
16745 : : default: return -1;
16746 : : }
16747 : : }
16748 : :
16749 : : /* Return TRUE or FALSE depending on whether the first SET in INSN
16750 : : has source and destination with matching CC modes, and that the
16751 : : CC mode is at least as constrained as REQ_MODE. */
16752 : :
16753 : : bool
16754 : 53007820 : ix86_match_ccmode (rtx insn, machine_mode req_mode)
16755 : : {
16756 : 53007820 : rtx set;
16757 : 53007820 : machine_mode set_mode;
16758 : :
16759 : 53007820 : set = PATTERN (insn);
16760 : 53007820 : if (GET_CODE (set) == PARALLEL)
16761 : 471627 : set = XVECEXP (set, 0, 0);
16762 : 53007820 : gcc_assert (GET_CODE (set) == SET);
16763 : 53007820 : gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
16764 : :
16765 : 53007820 : set_mode = GET_MODE (SET_DEST (set));
16766 : 53007820 : switch (set_mode)
16767 : : {
16768 : 1359164 : case E_CCNOmode:
16769 : 1359164 : if (req_mode != CCNOmode
16770 : 73517 : && (req_mode != CCmode
16771 : 0 : || XEXP (SET_SRC (set), 1) != const0_rtx))
16772 : : return false;
16773 : : break;
16774 : 5152199 : case E_CCmode:
16775 : 5152199 : if (req_mode == CCGCmode)
16776 : : return false;
16777 : : /* FALLTHRU */
16778 : 8814046 : case E_CCGCmode:
16779 : 8814046 : if (req_mode == CCGOCmode || req_mode == CCNOmode)
16780 : : return false;
16781 : : /* FALLTHRU */
16782 : 9850805 : case E_CCGOCmode:
16783 : 9850805 : if (req_mode == CCZmode)
16784 : : return false;
16785 : : /* FALLTHRU */
16786 : : case E_CCZmode:
16787 : : break;
16788 : :
16789 : 0 : case E_CCGZmode:
16790 : :
16791 : 0 : case E_CCAmode:
16792 : 0 : case E_CCCmode:
16793 : 0 : case E_CCOmode:
16794 : 0 : case E_CCPmode:
16795 : 0 : case E_CCSmode:
16796 : 0 : if (set_mode != req_mode)
16797 : : return false;
16798 : : break;
16799 : :
16800 : 0 : default:
16801 : 0 : gcc_unreachable ();
16802 : : }
16803 : :
16804 : 52925548 : return GET_MODE (SET_SRC (set)) == set_mode;
16805 : : }
16806 : :
16807 : : machine_mode
16808 : 13350210 : ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
16809 : : {
16810 : 13350210 : machine_mode mode = GET_MODE (op0);
16811 : :
16812 : 13350210 : if (SCALAR_FLOAT_MODE_P (mode))
16813 : : {
16814 : 133716 : gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
16815 : : return CCFPmode;
16816 : : }
16817 : :
16818 : 13216494 : switch (code)
16819 : : {
16820 : : /* Only zero flag is needed. */
16821 : : case EQ: /* ZF=0 */
16822 : : case NE: /* ZF!=0 */
16823 : : return CCZmode;
16824 : : /* Codes needing carry flag. */
16825 : 955656 : case GEU: /* CF=0 */
16826 : 955656 : case LTU: /* CF=1 */
16827 : 955656 : rtx geu;
16828 : : /* Detect overflow checks. They need just the carry flag. */
16829 : 955656 : if (GET_CODE (op0) == PLUS
16830 : 955656 : && (rtx_equal_p (op1, XEXP (op0, 0))
16831 : 117022 : || rtx_equal_p (op1, XEXP (op0, 1))))
16832 : 17145 : return CCCmode;
16833 : : /* Similarly for *setcc_qi_addqi3_cconly_overflow_1_* patterns.
16834 : : Match LTU of op0
16835 : : (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))
16836 : : and op1
16837 : : (ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))
16838 : : where CC_CCC is either CC or CCC. */
16839 : 938511 : else if (code == LTU
16840 : 364518 : && GET_CODE (op0) == NEG
16841 : 5041 : && GET_CODE (geu = XEXP (op0, 0)) == GEU
16842 : 3664 : && REG_P (XEXP (geu, 0))
16843 : 3345 : && (GET_MODE (XEXP (geu, 0)) == CCCmode
16844 : 37 : || GET_MODE (XEXP (geu, 0)) == CCmode)
16845 : 3334 : && REGNO (XEXP (geu, 0)) == FLAGS_REG
16846 : 3334 : && XEXP (geu, 1) == const0_rtx
16847 : 3334 : && GET_CODE (op1) == LTU
16848 : 3334 : && REG_P (XEXP (op1, 0))
16849 : 3334 : && GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0))
16850 : 3334 : && REGNO (XEXP (op1, 0)) == FLAGS_REG
16851 : 941845 : && XEXP (op1, 1) == const0_rtx)
16852 : : return CCCmode;
16853 : : /* Similarly for *x86_cmc pattern.
16854 : : Match LTU of op0 (neg:QI (ltu:QI (reg:CCC FLAGS_REG) (const_int 0)))
16855 : : and op1 (geu:QI (reg:CCC FLAGS_REG) (const_int 0)).
16856 : : It is sufficient to test that the operand modes are CCCmode. */
16857 : 935177 : else if (code == LTU
16858 : 361184 : && GET_CODE (op0) == NEG
16859 : 1707 : && GET_CODE (XEXP (op0, 0)) == LTU
16860 : 377 : && GET_MODE (XEXP (XEXP (op0, 0), 0)) == CCCmode
16861 : 3 : && GET_CODE (op1) == GEU
16862 : 3 : && GET_MODE (XEXP (op1, 0)) == CCCmode)
16863 : : return CCCmode;
16864 : : /* Similarly for the comparison of addcarry/subborrow pattern. */
16865 : 361181 : else if (code == LTU
16866 : 361181 : && GET_CODE (op0) == ZERO_EXTEND
16867 : 15861 : && GET_CODE (op1) == PLUS
16868 : 9959 : && ix86_carry_flag_operator (XEXP (op1, 0), VOIDmode)
16869 : 9959 : && GET_CODE (XEXP (op1, 1)) == ZERO_EXTEND)
16870 : : return CCCmode;
16871 : : else
16872 : 925215 : return CCmode;
16873 : : case GTU: /* CF=0 & ZF=0 */
16874 : : case LEU: /* CF=1 | ZF=1 */
16875 : : return CCmode;
16876 : : /* Codes possibly doable only with sign flag when
16877 : : comparing against zero. */
16878 : 780393 : case GE: /* SF=OF or SF=0 */
16879 : 780393 : case LT: /* SF<>OF or SF=1 */
16880 : 780393 : if (op1 == const0_rtx)
16881 : : return CCGOCmode;
16882 : : else
16883 : : /* For other cases Carry flag is not required. */
16884 : 440841 : return CCGCmode;
16885 : : /* Codes doable only with sign flag when comparing
16886 : : against zero, but we miss jump instruction for it
16887 : : so we need to use relational tests against overflow
16888 : : that thus needs to be zero. */
16889 : 901829 : case GT: /* ZF=0 & SF=OF */
16890 : 901829 : case LE: /* ZF=1 | SF<>OF */
16891 : 901829 : if (op1 == const0_rtx)
16892 : : return CCNOmode;
16893 : : else
16894 : 609248 : return CCGCmode;
16895 : : default:
16896 : : /* CCmode should be used in all other cases. */
16897 : : return CCmode;
16898 : : }
16899 : : }
16900 : :
16901 : : /* Return TRUE or FALSE depending on whether the ptest instruction
16902 : : INSN has source and destination with suitable matching CC modes. */
16903 : :
16904 : : bool
16905 : 38843 : ix86_match_ptest_ccmode (rtx insn)
16906 : : {
16907 : 38843 : rtx set, src;
16908 : 38843 : machine_mode set_mode;
16909 : :
16910 : 38843 : set = PATTERN (insn);
16911 : 38843 : gcc_assert (GET_CODE (set) == SET);
16912 : 38843 : src = SET_SRC (set);
16913 : 38843 : gcc_assert (GET_CODE (src) == UNSPEC
16914 : : && XINT (src, 1) == UNSPEC_PTEST);
16915 : :
16916 : 38843 : set_mode = GET_MODE (src);
16917 : 38843 : if (set_mode != CCZmode
16918 : : && set_mode != CCCmode
16919 : : && set_mode != CCmode)
16920 : : return false;
16921 : 38843 : return GET_MODE (SET_DEST (set)) == set_mode;
16922 : : }
16923 : :
16924 : : /* Return the fixed registers used for condition codes. */
16925 : :
16926 : : static bool
16927 : 10123063 : ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
16928 : : {
16929 : 10123063 : *p1 = FLAGS_REG;
16930 : 10123063 : *p2 = INVALID_REGNUM;
16931 : 10123063 : return true;
16932 : : }
16933 : :
16934 : : /* If two condition code modes are compatible, return a condition code
16935 : : mode which is compatible with both. Otherwise, return
16936 : : VOIDmode. */
16937 : :
16938 : : static machine_mode
16939 : 30742 : ix86_cc_modes_compatible (machine_mode m1, machine_mode m2)
16940 : : {
16941 : 30742 : if (m1 == m2)
16942 : : return m1;
16943 : :
16944 : 30137 : if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
16945 : : return VOIDmode;
16946 : :
16947 : 30137 : if ((m1 == CCGCmode && m2 == CCGOCmode)
16948 : 30137 : || (m1 == CCGOCmode && m2 == CCGCmode))
16949 : : return CCGCmode;
16950 : :
16951 : 30137 : if ((m1 == CCNOmode && m2 == CCGOCmode)
16952 : 29947 : || (m1 == CCGOCmode && m2 == CCNOmode))
16953 : : return CCNOmode;
16954 : :
16955 : 29817 : if (m1 == CCZmode
16956 : 17428 : && (m2 == CCGCmode || m2 == CCGOCmode || m2 == CCNOmode))
16957 : : return m2;
16958 : 15821 : else if (m2 == CCZmode
16959 : 12137 : && (m1 == CCGCmode || m1 == CCGOCmode || m1 == CCNOmode))
16960 : : return m1;
16961 : :
16962 : 5354 : switch (m1)
16963 : : {
16964 : 0 : default:
16965 : 0 : gcc_unreachable ();
16966 : :
16967 : 5354 : case E_CCmode:
16968 : 5354 : case E_CCGCmode:
16969 : 5354 : case E_CCGOCmode:
16970 : 5354 : case E_CCNOmode:
16971 : 5354 : case E_CCAmode:
16972 : 5354 : case E_CCCmode:
16973 : 5354 : case E_CCOmode:
16974 : 5354 : case E_CCPmode:
16975 : 5354 : case E_CCSmode:
16976 : 5354 : case E_CCZmode:
16977 : 5354 : switch (m2)
16978 : : {
16979 : : default:
16980 : : return VOIDmode;
16981 : :
16982 : : case E_CCmode:
16983 : : case E_CCGCmode:
16984 : : case E_CCGOCmode:
16985 : : case E_CCNOmode:
16986 : : case E_CCAmode:
16987 : : case E_CCCmode:
16988 : : case E_CCOmode:
16989 : : case E_CCPmode:
16990 : : case E_CCSmode:
16991 : : case E_CCZmode:
16992 : : return CCmode;
16993 : : }
16994 : :
16995 : : case E_CCFPmode:
16996 : : /* These are only compatible with themselves, which we already
16997 : : checked above. */
16998 : : return VOIDmode;
16999 : : }
17000 : : }
17001 : :
17002 : : /* Return strategy to use for floating-point. We assume that fcomi is always
17003 : : preferrable where available, since that is also true when looking at size
17004 : : (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test). */
17005 : :
17006 : : enum ix86_fpcmp_strategy
17007 : 5549064 : ix86_fp_comparison_strategy (enum rtx_code)
17008 : : {
17009 : : /* Do fcomi/sahf based test when profitable. */
17010 : :
17011 : 5549064 : if (TARGET_CMOVE)
17012 : : return IX86_FPCMP_COMI;
17013 : :
17014 : 0 : if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
17015 : 0 : return IX86_FPCMP_SAHF;
17016 : :
17017 : : return IX86_FPCMP_ARITH;
17018 : : }
17019 : :
17020 : : /* Convert comparison codes we use to represent FP comparison to integer
17021 : : code that will result in proper branch. Return UNKNOWN if no such code
17022 : : is available. */
17023 : :
17024 : : enum rtx_code
17025 : 582125 : ix86_fp_compare_code_to_integer (enum rtx_code code)
17026 : : {
17027 : 582125 : switch (code)
17028 : : {
17029 : : case GT:
17030 : : return GTU;
17031 : 18842 : case GE:
17032 : 18842 : return GEU;
17033 : : case ORDERED:
17034 : : case UNORDERED:
17035 : : return code;
17036 : 118051 : case UNEQ:
17037 : 118051 : return EQ;
17038 : 21266 : case UNLT:
17039 : 21266 : return LTU;
17040 : 31030 : case UNLE:
17041 : 31030 : return LEU;
17042 : 112471 : case LTGT:
17043 : 112471 : return NE;
17044 : 19 : case EQ:
17045 : 19 : case NE:
17046 : 19 : if (TARGET_AVX10_2)
17047 : : return code;
17048 : : /* FALLTHRU. */
17049 : 206 : default:
17050 : 206 : return UNKNOWN;
17051 : : }
17052 : : }
17053 : :
17054 : : /* Zero extend possibly SImode EXP to Pmode register. */
17055 : : rtx
17056 : 40380 : ix86_zero_extend_to_Pmode (rtx exp)
17057 : : {
17058 : 52586 : return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
17059 : : }
17060 : :
17061 : : /* Return true if the function is called via PLT. */
17062 : :
17063 : : bool
17064 : 961905 : ix86_call_use_plt_p (rtx call_op)
17065 : : {
17066 : 961905 : if (SYMBOL_REF_LOCAL_P (call_op))
17067 : : {
17068 : 191529 : if (SYMBOL_REF_DECL (call_op)
17069 : 191529 : && TREE_CODE (SYMBOL_REF_DECL (call_op)) == FUNCTION_DECL)
17070 : : {
17071 : : /* NB: All ifunc functions must be called via PLT. */
17072 : 108430 : cgraph_node *node
17073 : 108430 : = cgraph_node::get (SYMBOL_REF_DECL (call_op));
17074 : 108430 : if (node && node->ifunc_resolver)
17075 : : return true;
17076 : : }
17077 : 191509 : return false;
17078 : : }
17079 : : return true;
17080 : : }
17081 : :
17082 : : /* Implement TARGET_IFUNC_REF_LOCAL_OK. If this hook returns true,
17083 : : the PLT entry will be used as the function address for local IFUNC
17084 : : functions. When the PIC register is needed for PLT call, indirect
17085 : : call via the PLT entry will fail since the PIC register may not be
17086 : : set up properly for indirect call. In this case, we should return
17087 : : false. */
17088 : :
17089 : : static bool
17090 : 746991268 : ix86_ifunc_ref_local_ok (void)
17091 : : {
17092 : 746991268 : return !flag_pic || (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC);
17093 : : }
17094 : :
17095 : : /* Return true if the function being called was marked with attribute
17096 : : "noplt" or using -fno-plt and we are compiling for non-PIC. We need
17097 : : to handle the non-PIC case in the backend because there is no easy
17098 : : interface for the front-end to force non-PLT calls to use the GOT.
17099 : : This is currently used only with 64-bit or 32-bit GOT32X ELF targets
17100 : : to call the function marked "noplt" indirectly. */
17101 : :
17102 : : bool
17103 : 5855444 : ix86_nopic_noplt_attribute_p (rtx call_op)
17104 : : {
17105 : 5380327 : if (flag_pic || ix86_cmodel == CM_LARGE
17106 : : || !(TARGET_64BIT || HAVE_AS_IX86_GOT32X)
17107 : : || TARGET_MACHO || TARGET_SEH || TARGET_PECOFF
17108 : 11235771 : || SYMBOL_REF_LOCAL_P (call_op))
17109 : : return false;
17110 : :
17111 : 3756805 : tree symbol_decl = SYMBOL_REF_DECL (call_op);
17112 : :
17113 : 3756805 : if (!flag_plt
17114 : 3756805 : || (symbol_decl != NULL_TREE
17115 : 3756773 : && lookup_attribute ("noplt", DECL_ATTRIBUTES (symbol_decl))))
17116 : 34 : return true;
17117 : :
17118 : : return false;
17119 : : }
17120 : :
17121 : : /* Helper to output the jmp/call. */
17122 : : static void
17123 : 33 : ix86_output_jmp_thunk_or_indirect (const char *thunk_name, const int regno)
17124 : : {
17125 : 33 : if (thunk_name != NULL)
17126 : : {
17127 : 22 : if ((REX_INT_REGNO_P (regno) || REX2_INT_REGNO_P (regno))
17128 : 1 : && ix86_indirect_branch_cs_prefix)
17129 : 1 : fprintf (asm_out_file, "\tcs\n");
17130 : 22 : fprintf (asm_out_file, "\tjmp\t");
17131 : 22 : assemble_name (asm_out_file, thunk_name);
17132 : 22 : putc ('\n', asm_out_file);
17133 : 22 : if ((ix86_harden_sls & harden_sls_indirect_jmp))
17134 : 2 : fputs ("\tint3\n", asm_out_file);
17135 : : }
17136 : : else
17137 : 11 : output_indirect_thunk (regno);
17138 : 33 : }
17139 : :
17140 : : /* Output indirect branch via a call and return thunk. CALL_OP is a
17141 : : register which contains the branch target. XASM is the assembly
17142 : : template for CALL_OP. Branch is a tail call if SIBCALL_P is true.
17143 : : A normal call is converted to:
17144 : :
17145 : : call __x86_indirect_thunk_reg
17146 : :
17147 : : and a tail call is converted to:
17148 : :
17149 : : jmp __x86_indirect_thunk_reg
17150 : : */
17151 : :
17152 : : static void
17153 : 50 : ix86_output_indirect_branch_via_reg (rtx call_op, bool sibcall_p)
17154 : : {
17155 : 50 : char thunk_name_buf[32];
17156 : 50 : char *thunk_name;
17157 : 50 : enum indirect_thunk_prefix need_prefix
17158 : 50 : = indirect_thunk_need_prefix (current_output_insn);
17159 : 50 : int regno = REGNO (call_op);
17160 : :
17161 : 50 : if (cfun->machine->indirect_branch_type
17162 : 50 : != indirect_branch_thunk_inline)
17163 : : {
17164 : 39 : if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
17165 : 16 : SET_HARD_REG_BIT (indirect_thunks_used, regno);
17166 : :
17167 : 39 : indirect_thunk_name (thunk_name_buf, regno, need_prefix, false);
17168 : 39 : thunk_name = thunk_name_buf;
17169 : : }
17170 : : else
17171 : : thunk_name = NULL;
17172 : :
17173 : 50 : if (sibcall_p)
17174 : 27 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17175 : : else
17176 : : {
17177 : 23 : if (thunk_name != NULL)
17178 : : {
17179 : 17 : if ((REX_INT_REGNO_P (regno) || REX_INT_REGNO_P (regno))
17180 : 1 : && ix86_indirect_branch_cs_prefix)
17181 : 1 : fprintf (asm_out_file, "\tcs\n");
17182 : 17 : fprintf (asm_out_file, "\tcall\t");
17183 : 17 : assemble_name (asm_out_file, thunk_name);
17184 : 17 : putc ('\n', asm_out_file);
17185 : 17 : return;
17186 : : }
17187 : :
17188 : 6 : char indirectlabel1[32];
17189 : 6 : char indirectlabel2[32];
17190 : :
17191 : 6 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel1,
17192 : : INDIRECT_LABEL,
17193 : : indirectlabelno++);
17194 : 6 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel2,
17195 : : INDIRECT_LABEL,
17196 : : indirectlabelno++);
17197 : :
17198 : : /* Jump. */
17199 : 6 : fputs ("\tjmp\t", asm_out_file);
17200 : 6 : assemble_name_raw (asm_out_file, indirectlabel2);
17201 : 6 : fputc ('\n', asm_out_file);
17202 : :
17203 : 6 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
17204 : :
17205 : 6 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17206 : :
17207 : 6 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
17208 : :
17209 : : /* Call. */
17210 : 6 : fputs ("\tcall\t", asm_out_file);
17211 : 6 : assemble_name_raw (asm_out_file, indirectlabel1);
17212 : 6 : fputc ('\n', asm_out_file);
17213 : : }
17214 : : }
17215 : :
17216 : : /* Output indirect branch via a call and return thunk. CALL_OP is
17217 : : the branch target. XASM is the assembly template for CALL_OP.
17218 : : Branch is a tail call if SIBCALL_P is true. A normal call is
17219 : : converted to:
17220 : :
17221 : : jmp L2
17222 : : L1:
17223 : : push CALL_OP
17224 : : jmp __x86_indirect_thunk
17225 : : L2:
17226 : : call L1
17227 : :
17228 : : and a tail call is converted to:
17229 : :
17230 : : push CALL_OP
17231 : : jmp __x86_indirect_thunk
17232 : : */
17233 : :
17234 : : static void
17235 : 0 : ix86_output_indirect_branch_via_push (rtx call_op, const char *xasm,
17236 : : bool sibcall_p)
17237 : : {
17238 : 0 : char thunk_name_buf[32];
17239 : 0 : char *thunk_name;
17240 : 0 : char push_buf[64];
17241 : 0 : enum indirect_thunk_prefix need_prefix
17242 : 0 : = indirect_thunk_need_prefix (current_output_insn);
17243 : 0 : int regno = -1;
17244 : :
17245 : 0 : if (cfun->machine->indirect_branch_type
17246 : 0 : != indirect_branch_thunk_inline)
17247 : : {
17248 : 0 : if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
17249 : 0 : indirect_thunk_needed = true;
17250 : 0 : indirect_thunk_name (thunk_name_buf, regno, need_prefix, false);
17251 : 0 : thunk_name = thunk_name_buf;
17252 : : }
17253 : : else
17254 : : thunk_name = NULL;
17255 : :
17256 : 0 : snprintf (push_buf, sizeof (push_buf), "push{%c}\t%s",
17257 : 0 : TARGET_64BIT ? 'q' : 'l', xasm);
17258 : :
17259 : 0 : if (sibcall_p)
17260 : : {
17261 : 0 : output_asm_insn (push_buf, &call_op);
17262 : 0 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17263 : : }
17264 : : else
17265 : : {
17266 : 0 : char indirectlabel1[32];
17267 : 0 : char indirectlabel2[32];
17268 : :
17269 : 0 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel1,
17270 : : INDIRECT_LABEL,
17271 : : indirectlabelno++);
17272 : 0 : ASM_GENERATE_INTERNAL_LABEL (indirectlabel2,
17273 : : INDIRECT_LABEL,
17274 : : indirectlabelno++);
17275 : :
17276 : : /* Jump. */
17277 : 0 : fputs ("\tjmp\t", asm_out_file);
17278 : 0 : assemble_name_raw (asm_out_file, indirectlabel2);
17279 : 0 : fputc ('\n', asm_out_file);
17280 : :
17281 : 0 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
17282 : :
17283 : : /* An external function may be called via GOT, instead of PLT. */
17284 : 0 : if (MEM_P (call_op))
17285 : : {
17286 : 0 : struct ix86_address parts;
17287 : 0 : rtx addr = XEXP (call_op, 0);
17288 : 0 : if (ix86_decompose_address (addr, &parts)
17289 : 0 : && parts.base == stack_pointer_rtx)
17290 : : {
17291 : : /* Since call will adjust stack by -UNITS_PER_WORD,
17292 : : we must convert "disp(stack, index, scale)" to
17293 : : "disp+UNITS_PER_WORD(stack, index, scale)". */
17294 : 0 : if (parts.index)
17295 : : {
17296 : 0 : addr = gen_rtx_MULT (Pmode, parts.index,
17297 : : GEN_INT (parts.scale));
17298 : 0 : addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
17299 : : addr);
17300 : : }
17301 : : else
17302 : : addr = stack_pointer_rtx;
17303 : :
17304 : 0 : rtx disp;
17305 : 0 : if (parts.disp != NULL_RTX)
17306 : 0 : disp = plus_constant (Pmode, parts.disp,
17307 : 0 : UNITS_PER_WORD);
17308 : : else
17309 : 0 : disp = GEN_INT (UNITS_PER_WORD);
17310 : :
17311 : 0 : addr = gen_rtx_PLUS (Pmode, addr, disp);
17312 : 0 : call_op = gen_rtx_MEM (GET_MODE (call_op), addr);
17313 : : }
17314 : : }
17315 : :
17316 : 0 : output_asm_insn (push_buf, &call_op);
17317 : :
17318 : 0 : ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
17319 : :
17320 : 0 : ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
17321 : :
17322 : : /* Call. */
17323 : 0 : fputs ("\tcall\t", asm_out_file);
17324 : 0 : assemble_name_raw (asm_out_file, indirectlabel1);
17325 : 0 : fputc ('\n', asm_out_file);
17326 : : }
17327 : 0 : }
17328 : :
17329 : : /* Output indirect branch via a call and return thunk. CALL_OP is
17330 : : the branch target. XASM is the assembly template for CALL_OP.
17331 : : Branch is a tail call if SIBCALL_P is true. */
17332 : :
17333 : : static void
17334 : 50 : ix86_output_indirect_branch (rtx call_op, const char *xasm,
17335 : : bool sibcall_p)
17336 : : {
17337 : 50 : if (REG_P (call_op))
17338 : 50 : ix86_output_indirect_branch_via_reg (call_op, sibcall_p);
17339 : : else
17340 : 0 : ix86_output_indirect_branch_via_push (call_op, xasm, sibcall_p);
17341 : 50 : }
17342 : :
17343 : : /* Output indirect jump. CALL_OP is the jump target. */
17344 : :
17345 : : const char *
17346 : 10350 : ix86_output_indirect_jmp (rtx call_op)
17347 : : {
17348 : 10350 : if (cfun->machine->indirect_branch_type != indirect_branch_keep)
17349 : : {
17350 : : /* We can't have red-zone since "call" in the indirect thunk
17351 : : pushes the return address onto stack, destroying red-zone. */
17352 : 4 : if (ix86_red_zone_used)
17353 : 0 : gcc_unreachable ();
17354 : :
17355 : 4 : ix86_output_indirect_branch (call_op, "%0", true);
17356 : : }
17357 : : else
17358 : 10346 : output_asm_insn ("%!jmp\t%A0", &call_op);
17359 : 10350 : return (ix86_harden_sls & harden_sls_indirect_jmp) ? "int3" : "";
17360 : : }
17361 : :
17362 : : /* Output return instrumentation for current function if needed. */
17363 : :
17364 : : static void
17365 : 1696146 : output_return_instrumentation (void)
17366 : : {
17367 : 1696146 : if (ix86_instrument_return != instrument_return_none
17368 : 6 : && flag_fentry
17369 : 1696152 : && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (cfun->decl))
17370 : : {
17371 : 5 : if (ix86_flag_record_return)
17372 : 5 : fprintf (asm_out_file, "1:\n");
17373 : 5 : switch (ix86_instrument_return)
17374 : : {
17375 : 2 : case instrument_return_call:
17376 : 2 : fprintf (asm_out_file, "\tcall\t__return__\n");
17377 : 2 : break;
17378 : 3 : case instrument_return_nop5:
17379 : : /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
17380 : 3 : fprintf (asm_out_file, ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
17381 : 3 : break;
17382 : : case instrument_return_none:
17383 : : break;
17384 : : }
17385 : :
17386 : 5 : if (ix86_flag_record_return)
17387 : : {
17388 : 5 : fprintf (asm_out_file, "\t.section __return_loc, \"a\",@progbits\n");
17389 : 5 : fprintf (asm_out_file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
17390 : 5 : fprintf (asm_out_file, "\t.previous\n");
17391 : : }
17392 : : }
17393 : 1696146 : }
17394 : :
17395 : : /* Output function return. CALL_OP is the jump target. Add a REP
17396 : : prefix to RET if LONG_P is true and function return is kept. */
17397 : :
17398 : : const char *
17399 : 1570682 : ix86_output_function_return (bool long_p)
17400 : : {
17401 : 1570682 : output_return_instrumentation ();
17402 : :
17403 : 1570682 : if (cfun->machine->function_return_type != indirect_branch_keep)
17404 : : {
17405 : 17 : char thunk_name[32];
17406 : 17 : enum indirect_thunk_prefix need_prefix
17407 : 17 : = indirect_thunk_need_prefix (current_output_insn);
17408 : :
17409 : 17 : if (cfun->machine->function_return_type
17410 : 17 : != indirect_branch_thunk_inline)
17411 : : {
17412 : 12 : bool need_thunk = (cfun->machine->function_return_type
17413 : : == indirect_branch_thunk);
17414 : 12 : indirect_thunk_name (thunk_name, INVALID_REGNUM, need_prefix,
17415 : : true);
17416 : 12 : indirect_return_needed |= need_thunk;
17417 : 12 : fprintf (asm_out_file, "\tjmp\t");
17418 : 12 : assemble_name (asm_out_file, thunk_name);
17419 : 12 : putc ('\n', asm_out_file);
17420 : : }
17421 : : else
17422 : 5 : output_indirect_thunk (INVALID_REGNUM);
17423 : :
17424 : 17 : return "";
17425 : : }
17426 : :
17427 : 3140847 : output_asm_insn (long_p ? "rep%; ret" : "ret", nullptr);
17428 : 1570665 : return (ix86_harden_sls & harden_sls_return) ? "int3" : "";
17429 : : }
17430 : :
17431 : : /* Output indirect function return. RET_OP is the function return
17432 : : target. */
17433 : :
17434 : : const char *
17435 : 17 : ix86_output_indirect_function_return (rtx ret_op)
17436 : : {
17437 : 17 : if (cfun->machine->function_return_type != indirect_branch_keep)
17438 : : {
17439 : 0 : char thunk_name[32];
17440 : 0 : enum indirect_thunk_prefix need_prefix
17441 : 0 : = indirect_thunk_need_prefix (current_output_insn);
17442 : 0 : unsigned int regno = REGNO (ret_op);
17443 : 0 : gcc_assert (regno == CX_REG);
17444 : :
17445 : 0 : if (cfun->machine->function_return_type
17446 : 0 : != indirect_branch_thunk_inline)
17447 : : {
17448 : 0 : bool need_thunk = (cfun->machine->function_return_type
17449 : : == indirect_branch_thunk);
17450 : 0 : indirect_thunk_name (thunk_name, regno, need_prefix, true);
17451 : :
17452 : 0 : if (need_thunk)
17453 : : {
17454 : 0 : indirect_return_via_cx = true;
17455 : 0 : SET_HARD_REG_BIT (indirect_thunks_used, CX_REG);
17456 : : }
17457 : 0 : fprintf (asm_out_file, "\tjmp\t");
17458 : 0 : assemble_name (asm_out_file, thunk_name);
17459 : 0 : putc ('\n', asm_out_file);
17460 : : }
17461 : : else
17462 : 0 : output_indirect_thunk (regno);
17463 : : }
17464 : : else
17465 : : {
17466 : 17 : output_asm_insn ("%!jmp\t%A0", &ret_op);
17467 : 17 : if (ix86_harden_sls & harden_sls_indirect_jmp)
17468 : 1 : fputs ("\tint3\n", asm_out_file);
17469 : : }
17470 : 17 : return "";
17471 : : }
17472 : :
17473 : : /* Output the assembly for a call instruction. */
17474 : :
17475 : : const char *
17476 : 6042591 : ix86_output_call_insn (rtx_insn *insn, rtx call_op)
17477 : : {
17478 : 6042591 : bool direct_p = constant_call_address_operand (call_op, VOIDmode);
17479 : 6042591 : bool output_indirect_p
17480 : : = (!TARGET_SEH
17481 : 6042591 : && cfun->machine->indirect_branch_type != indirect_branch_keep);
17482 : 6042591 : bool seh_nop_p = false;
17483 : 6042591 : const char *xasm;
17484 : :
17485 : 6042591 : if (SIBLING_CALL_P (insn))
17486 : : {
17487 : 125464 : output_return_instrumentation ();
17488 : 125464 : if (direct_p)
17489 : : {
17490 : 116459 : if (ix86_nopic_noplt_attribute_p (call_op))
17491 : : {
17492 : 4 : direct_p = false;
17493 : 4 : if (TARGET_64BIT)
17494 : : {
17495 : 4 : if (output_indirect_p)
17496 : : xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17497 : : else
17498 : 4 : xasm = "%!jmp\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17499 : : }
17500 : : else
17501 : : {
17502 : 0 : if (output_indirect_p)
17503 : : xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}";
17504 : : else
17505 : 0 : xasm = "%!jmp\t{*%p0@GOT|[DWORD PTR %p0@GOT]}";
17506 : : }
17507 : : }
17508 : : else
17509 : : xasm = "%!jmp\t%P0";
17510 : : }
17511 : : /* SEH epilogue detection requires the indirect branch case
17512 : : to include REX.W. */
17513 : 9005 : else if (TARGET_SEH)
17514 : : xasm = "%!rex.W jmp\t%A0";
17515 : : else
17516 : : {
17517 : 9005 : if (output_indirect_p)
17518 : : xasm = "%0";
17519 : : else
17520 : 8982 : xasm = "%!jmp\t%A0";
17521 : : }
17522 : :
17523 : 125464 : if (output_indirect_p && !direct_p)
17524 : 23 : ix86_output_indirect_branch (call_op, xasm, true);
17525 : : else
17526 : : {
17527 : 125441 : output_asm_insn (xasm, &call_op);
17528 : 125441 : if (!direct_p
17529 : 8986 : && (ix86_harden_sls & harden_sls_indirect_jmp))
17530 : : return "int3";
17531 : : }
17532 : 125463 : return "";
17533 : : }
17534 : :
17535 : : /* SEH unwinding can require an extra nop to be emitted in several
17536 : : circumstances. Determine if we have one of those. */
17537 : 5917127 : if (TARGET_SEH)
17538 : : {
17539 : : rtx_insn *i;
17540 : :
17541 : : for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
17542 : : {
17543 : : /* Prevent a catch region from being adjacent to a jump that would
17544 : : be interpreted as an epilogue sequence by the unwinder. */
17545 : : if (JUMP_P(i) && CROSSING_JUMP_P (i))
17546 : : {
17547 : : seh_nop_p = true;
17548 : : break;
17549 : : }
17550 : :
17551 : : /* If we get to another real insn, we don't need the nop. */
17552 : : if (INSN_P (i))
17553 : : break;
17554 : :
17555 : : /* If we get to the epilogue note, prevent a catch region from
17556 : : being adjacent to the standard epilogue sequence. Note that,
17557 : : if non-call exceptions are enabled, we already did it during
17558 : : epilogue expansion, or else, if the insn can throw internally,
17559 : : we already did it during the reorg pass. */
17560 : : if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG
17561 : : && !flag_non_call_exceptions
17562 : : && !can_throw_internal (insn))
17563 : : {
17564 : : seh_nop_p = true;
17565 : : break;
17566 : : }
17567 : : }
17568 : :
17569 : : /* If we didn't find a real insn following the call, prevent the
17570 : : unwinder from looking into the next function. */
17571 : : if (i == NULL)
17572 : : seh_nop_p = true;
17573 : : }
17574 : :
17575 : 5917127 : if (direct_p)
17576 : : {
17577 : 5737963 : if (ix86_nopic_noplt_attribute_p (call_op))
17578 : : {
17579 : 6 : direct_p = false;
17580 : 6 : if (TARGET_64BIT)
17581 : : {
17582 : 6 : if (output_indirect_p)
17583 : : xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17584 : : else
17585 : 6 : xasm = "%!call\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
17586 : : }
17587 : : else
17588 : : {
17589 : 0 : if (output_indirect_p)
17590 : : xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}";
17591 : : else
17592 : 0 : xasm = "%!call\t{*%p0@GOT|[DWORD PTR %p0@GOT]}";
17593 : : }
17594 : : }
17595 : : else
17596 : : xasm = "%!call\t%P0";
17597 : : }
17598 : : else
17599 : : {
17600 : 179164 : if (output_indirect_p)
17601 : : xasm = "%0";
17602 : : else
17603 : 179141 : xasm = "%!call\t%A0";
17604 : : }
17605 : :
17606 : 5917127 : if (output_indirect_p && !direct_p)
17607 : 23 : ix86_output_indirect_branch (call_op, xasm, false);
17608 : : else
17609 : 5917104 : output_asm_insn (xasm, &call_op);
17610 : :
17611 : : if (seh_nop_p)
17612 : : return "nop";
17613 : :
17614 : : return "";
17615 : : }
17616 : :
17617 : : /* Return a MEM corresponding to a stack slot with mode MODE.
17618 : : Allocate a new slot if necessary.
17619 : :
17620 : : The RTL for a function can have several slots available: N is
17621 : : which slot to use. */
17622 : :
17623 : : rtx
17624 : 22160 : assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n)
17625 : : {
17626 : 22160 : struct stack_local_entry *s;
17627 : :
17628 : 22160 : gcc_assert (n < MAX_386_STACK_LOCALS);
17629 : :
17630 : 33418 : for (s = ix86_stack_locals; s; s = s->next)
17631 : 30897 : if (s->mode == mode && s->n == n)
17632 : 19639 : return validize_mem (copy_rtx (s->rtl));
17633 : :
17634 : 2521 : int align = 0;
17635 : : /* For DImode with SLOT_FLOATxFDI_387 use 32-bit
17636 : : alignment with -m32 -mpreferred-stack-boundary=2. */
17637 : 2521 : if (mode == DImode
17638 : 329 : && !TARGET_64BIT
17639 : 329 : && n == SLOT_FLOATxFDI_387
17640 : 2850 : && ix86_preferred_stack_boundary < GET_MODE_ALIGNMENT (DImode))
17641 : : align = 32;
17642 : 2521 : s = ggc_alloc<stack_local_entry> ();
17643 : 2521 : s->n = n;
17644 : 2521 : s->mode = mode;
17645 : 5042 : s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), align);
17646 : :
17647 : 2521 : s->next = ix86_stack_locals;
17648 : 2521 : ix86_stack_locals = s;
17649 : 2521 : return validize_mem (copy_rtx (s->rtl));
17650 : : }
17651 : :
17652 : : static void
17653 : 1455677 : ix86_instantiate_decls (void)
17654 : : {
17655 : 1455677 : struct stack_local_entry *s;
17656 : :
17657 : 1455677 : for (s = ix86_stack_locals; s; s = s->next)
17658 : 0 : if (s->rtl != NULL_RTX)
17659 : 0 : instantiate_decl_rtl (s->rtl);
17660 : 1455677 : }
17661 : :
17662 : : /* Check whether x86 address PARTS is a pc-relative address. */
17663 : :
17664 : : bool
17665 : 25335366 : ix86_rip_relative_addr_p (struct ix86_address *parts)
17666 : : {
17667 : 25335366 : rtx base, index, disp;
17668 : :
17669 : 25335366 : base = parts->base;
17670 : 25335366 : index = parts->index;
17671 : 25335366 : disp = parts->disp;
17672 : :
17673 : 25335366 : if (disp && !base && !index)
17674 : : {
17675 : 24729082 : if (TARGET_64BIT)
17676 : : {
17677 : 23247904 : rtx symbol = disp;
17678 : :
17679 : 23247904 : if (GET_CODE (disp) == CONST)
17680 : 7439336 : symbol = XEXP (disp, 0);
17681 : 23247904 : if (GET_CODE (symbol) == PLUS
17682 : 6947099 : && CONST_INT_P (XEXP (symbol, 1)))
17683 : 6947099 : symbol = XEXP (symbol, 0);
17684 : :
17685 : 23247904 : if (GET_CODE (symbol) == LABEL_REF
17686 : 23241041 : || (GET_CODE (symbol) == SYMBOL_REF
17687 : 22139361 : && SYMBOL_REF_TLS_MODEL (symbol) == 0)
17688 : 24349584 : || (GET_CODE (symbol) == UNSPEC
17689 : 510938 : && (XINT (symbol, 1) == UNSPEC_GOTPCREL
17690 : : || XINT (symbol, 1) == UNSPEC_PCREL
17691 : : || XINT (symbol, 1) == UNSPEC_GOTNTPOFF)))
17692 : 22630924 : return true;
17693 : : }
17694 : : }
17695 : : return false;
17696 : : }
17697 : :
17698 : : /* Calculate the length of the memory address in the instruction encoding.
17699 : : Includes addr32 prefix, does not include the one-byte modrm, opcode,
17700 : : or other prefixes. We never generate addr32 prefix for LEA insn. */
17701 : :
17702 : : int
17703 : 267664476 : memory_address_length (rtx addr, bool lea)
17704 : : {
17705 : 267664476 : struct ix86_address parts;
17706 : 267664476 : rtx base, index, disp;
17707 : 267664476 : int len;
17708 : 267664476 : int ok;
17709 : :
17710 : 267664476 : if (GET_CODE (addr) == PRE_DEC
17711 : 259169588 : || GET_CODE (addr) == POST_INC
17712 : 254560111 : || GET_CODE (addr) == PRE_MODIFY
17713 : 254560111 : || GET_CODE (addr) == POST_MODIFY)
17714 : : return 0;
17715 : :
17716 : 254560111 : ok = ix86_decompose_address (addr, &parts);
17717 : 254560111 : gcc_assert (ok);
17718 : :
17719 : 254560111 : len = (parts.seg == ADDR_SPACE_GENERIC) ? 0 : 1;
17720 : :
17721 : : /* If this is not LEA instruction, add the length of addr32 prefix. */
17722 : 215819873 : if (TARGET_64BIT && !lea
17723 : 445269536 : && (SImode_address_operand (addr, VOIDmode)
17724 : 190709272 : || (parts.base && GET_MODE (parts.base) == SImode)
17725 : 190698886 : || (parts.index && GET_MODE (parts.index) == SImode)))
17726 : 10539 : len++;
17727 : :
17728 : 254560111 : base = parts.base;
17729 : 254560111 : index = parts.index;
17730 : 254560111 : disp = parts.disp;
17731 : :
17732 : 254560111 : if (base && SUBREG_P (base))
17733 : 2 : base = SUBREG_REG (base);
17734 : 254560111 : if (index && SUBREG_P (index))
17735 : 0 : index = SUBREG_REG (index);
17736 : :
17737 : 254560111 : gcc_assert (base == NULL_RTX || REG_P (base));
17738 : 254560111 : gcc_assert (index == NULL_RTX || REG_P (index));
17739 : :
17740 : : /* Rule of thumb:
17741 : : - esp as the base always wants an index,
17742 : : - ebp as the base always wants a displacement,
17743 : : - r12 as the base always wants an index,
17744 : : - r13 as the base always wants a displacement. */
17745 : :
17746 : : /* Register Indirect. */
17747 : 254560111 : if (base && !index && !disp)
17748 : : {
17749 : : /* esp (for its index) and ebp (for its displacement) need
17750 : : the two-byte modrm form. Similarly for r12 and r13 in 64-bit
17751 : : code. */
17752 : 16176504 : if (base == arg_pointer_rtx
17753 : 16176504 : || base == frame_pointer_rtx
17754 : 16176504 : || REGNO (base) == SP_REG
17755 : 9650531 : || REGNO (base) == BP_REG
17756 : 9650531 : || REGNO (base) == R12_REG
17757 : 25376631 : || REGNO (base) == R13_REG)
17758 : 6976377 : len++;
17759 : : }
17760 : :
17761 : : /* Direct Addressing. In 64-bit mode mod 00 r/m 5
17762 : : is not disp32, but disp32(%rip), so for disp32
17763 : : SIB byte is needed, unless print_operand_address
17764 : : optimizes it into disp32(%rip) or (%rip) is implied
17765 : : by UNSPEC. */
17766 : 238383607 : else if (disp && !base && !index)
17767 : : {
17768 : 24417973 : len += 4;
17769 : 24417973 : if (!ix86_rip_relative_addr_p (&parts))
17770 : 1855124 : len++;
17771 : : }
17772 : : else
17773 : : {
17774 : : /* Find the length of the displacement constant. */
17775 : 213965634 : if (disp)
17776 : : {
17777 : 209846989 : if (base && satisfies_constraint_K (disp))
17778 : 120619243 : len += 1;
17779 : : else
17780 : 89227746 : len += 4;
17781 : : }
17782 : : /* ebp always wants a displacement. Similarly r13. */
17783 : 4118645 : else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
17784 : 6661 : len++;
17785 : :
17786 : : /* An index requires the two-byte modrm form.... */
17787 : 213965634 : if (index
17788 : : /* ...like esp (or r12), which always wants an index. */
17789 : 204226224 : || base == arg_pointer_rtx
17790 : 204226224 : || base == frame_pointer_rtx
17791 : 418191858 : || (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
17792 : 153943369 : len++;
17793 : : }
17794 : :
17795 : : return len;
17796 : : }
17797 : :
17798 : : /* Compute default value for "length_immediate" attribute. When SHORTFORM
17799 : : is set, expect that insn have 8bit immediate alternative. */
17800 : : int
17801 : 312920868 : ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform)
17802 : : {
17803 : 312920868 : int len = 0;
17804 : 312920868 : int i;
17805 : 312920868 : extract_insn_cached (insn);
17806 : 976293032 : for (i = recog_data.n_operands - 1; i >= 0; --i)
17807 : 663372164 : if (CONSTANT_P (recog_data.operand[i]))
17808 : : {
17809 : 136295074 : enum attr_mode mode = get_attr_mode (insn);
17810 : :
17811 : 136295074 : gcc_assert (!len);
17812 : 136295074 : if (shortform && CONST_INT_P (recog_data.operand[i]))
17813 : : {
17814 : 35174377 : HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
17815 : 35174377 : switch (mode)
17816 : : {
17817 : 1195621 : case MODE_QI:
17818 : 1195621 : len = 1;
17819 : 1195621 : continue;
17820 : 367765 : case MODE_HI:
17821 : 367765 : ival = trunc_int_for_mode (ival, HImode);
17822 : 367765 : break;
17823 : 15376618 : case MODE_SI:
17824 : 15376618 : ival = trunc_int_for_mode (ival, SImode);
17825 : 15376618 : break;
17826 : : default:
17827 : : break;
17828 : : }
17829 : 33978756 : if (IN_RANGE (ival, -128, 127))
17830 : : {
17831 : 30226333 : len = 1;
17832 : 30226333 : continue;
17833 : : }
17834 : : }
17835 : 104873120 : switch (mode)
17836 : : {
17837 : : case MODE_QI:
17838 : : len = 1;
17839 : : break;
17840 : : case MODE_HI:
17841 : 663372164 : len = 2;
17842 : : break;
17843 : : case MODE_SI:
17844 : 99364020 : len = 4;
17845 : : break;
17846 : : /* Immediates for DImode instructions are encoded
17847 : : as 32bit sign extended values. */
17848 : : case MODE_DI:
17849 : 99364020 : len = 4;
17850 : : break;
17851 : 0 : default:
17852 : 0 : fatal_insn ("unknown insn mode", insn);
17853 : : }
17854 : : }
17855 : 312920868 : return len;
17856 : : }
17857 : :
17858 : : /* Compute default value for "length_address" attribute. */
17859 : : int
17860 : 438631804 : ix86_attr_length_address_default (rtx_insn *insn)
17861 : : {
17862 : 438631804 : int i;
17863 : :
17864 : 438631804 : if (get_attr_type (insn) == TYPE_LEA)
17865 : : {
17866 : 27798782 : rtx set = PATTERN (insn), addr;
17867 : :
17868 : 27798782 : if (GET_CODE (set) == PARALLEL)
17869 : 87242 : set = XVECEXP (set, 0, 0);
17870 : :
17871 : 27798782 : gcc_assert (GET_CODE (set) == SET);
17872 : :
17873 : 27798782 : addr = SET_SRC (set);
17874 : :
17875 : 27798782 : return memory_address_length (addr, true);
17876 : : }
17877 : :
17878 : 410833022 : extract_insn_cached (insn);
17879 : 942852460 : for (i = recog_data.n_operands - 1; i >= 0; --i)
17880 : : {
17881 : 771605425 : rtx op = recog_data.operand[i];
17882 : 771605425 : if (MEM_P (op))
17883 : : {
17884 : 239857480 : constrain_operands_cached (insn, reload_completed);
17885 : 239857480 : if (which_alternative != -1)
17886 : : {
17887 : 239857480 : const char *constraints = recog_data.constraints[i];
17888 : 239857480 : int alt = which_alternative;
17889 : :
17890 : 379941888 : while (*constraints == '=' || *constraints == '+')
17891 : 140084408 : constraints++;
17892 : 1088371043 : while (alt-- > 0)
17893 : 2083885917 : while (*constraints++ != ',')
17894 : : ;
17895 : : /* Skip ignored operands. */
17896 : 239857480 : if (*constraints == 'X')
17897 : 271493 : continue;
17898 : : }
17899 : :
17900 : 239585987 : int len = memory_address_length (XEXP (op, 0), false);
17901 : :
17902 : : /* Account for segment prefix for non-default addr spaces. */
17903 : 249677120 : if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (op)))
17904 : 777719 : len++;
17905 : :
17906 : 239585987 : return len;
17907 : : }
17908 : : }
17909 : : return 0;
17910 : : }
17911 : :
17912 : : /* Compute default value for "length_vex" attribute. It includes
17913 : : 2 or 3 byte VEX prefix and 1 opcode byte. */
17914 : :
17915 : : int
17916 : 4892336 : ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode,
17917 : : bool has_vex_w)
17918 : : {
17919 : 4892336 : int i, reg_only = 2 + 1;
17920 : 4892336 : bool has_mem = false;
17921 : :
17922 : : /* Only 0f opcode can use 2 byte VEX prefix and VEX W bit uses 3
17923 : : byte VEX prefix. */
17924 : 4892336 : if (!has_0f_opcode || has_vex_w)
17925 : : return 3 + 1;
17926 : :
17927 : : /* We can always use 2 byte VEX prefix in 32bit. */
17928 : 4506401 : if (!TARGET_64BIT)
17929 : : return 2 + 1;
17930 : :
17931 : 3407204 : extract_insn_cached (insn);
17932 : :
17933 : 10599008 : for (i = recog_data.n_operands - 1; i >= 0; --i)
17934 : 7528473 : if (REG_P (recog_data.operand[i]))
17935 : : {
17936 : : /* REX.W bit uses 3 byte VEX prefix.
17937 : : REX2 with vex use extended EVEX prefix length is 4-byte. */
17938 : 4906196 : if (GET_MODE (recog_data.operand[i]) == DImode
17939 : 4906196 : && GENERAL_REG_P (recog_data.operand[i]))
17940 : : return 3 + 1;
17941 : :
17942 : : /* REX.B bit requires 3-byte VEX. Right here we don't know which
17943 : : operand will be encoded using VEX.B, so be conservative.
17944 : : REX2 with vex use extended EVEX prefix length is 4-byte. */
17945 : 4892161 : if (REX_INT_REGNO_P (recog_data.operand[i])
17946 : 4892161 : || REX2_INT_REGNO_P (recog_data.operand[i])
17947 : 4892161 : || REX_SSE_REGNO_P (recog_data.operand[i]))
17948 : 0 : reg_only = 3 + 1;
17949 : : }
17950 : 2622277 : else if (MEM_P (recog_data.operand[i]))
17951 : : {
17952 : : /* REX2.X or REX2.B bits use 3 byte VEX prefix. */
17953 : 2053898 : if (x86_extended_rex2reg_mentioned_p (recog_data.operand[i]))
17954 : : return 4;
17955 : :
17956 : : /* REX.X or REX.B bits use 3 byte VEX prefix. */
17957 : 2053644 : if (x86_extended_reg_mentioned_p (recog_data.operand[i]))
17958 : : return 3 + 1;
17959 : :
17960 : : has_mem = true;
17961 : : }
17962 : :
17963 : 3070535 : return has_mem ? 2 + 1 : reg_only;
17964 : : }
17965 : :
17966 : :
17967 : : static bool
17968 : : ix86_class_likely_spilled_p (reg_class_t);
17969 : :
17970 : : /* Returns true if lhs of insn is HW function argument register and set up
17971 : : is_spilled to true if it is likely spilled HW register. */
17972 : : static bool
17973 : 1132 : insn_is_function_arg (rtx insn, bool* is_spilled)
17974 : : {
17975 : 1132 : rtx dst;
17976 : :
17977 : 1132 : if (!NONDEBUG_INSN_P (insn))
17978 : : return false;
17979 : : /* Call instructions are not movable, ignore it. */
17980 : 1132 : if (CALL_P (insn))
17981 : : return false;
17982 : 1068 : insn = PATTERN (insn);
17983 : 1068 : if (GET_CODE (insn) == PARALLEL)
17984 : 75 : insn = XVECEXP (insn, 0, 0);
17985 : 1068 : if (GET_CODE (insn) != SET)
17986 : : return false;
17987 : 1068 : dst = SET_DEST (insn);
17988 : 964 : if (REG_P (dst) && HARD_REGISTER_P (dst)
17989 : 1924 : && ix86_function_arg_regno_p (REGNO (dst)))
17990 : : {
17991 : : /* Is it likely spilled HW register? */
17992 : 856 : if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst))
17993 : 856 : && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))))
17994 : 812 : *is_spilled = true;
17995 : 856 : return true;
17996 : : }
17997 : : return false;
17998 : : }
17999 : :
18000 : : /* Add output dependencies for chain of function adjacent arguments if only
18001 : : there is a move to likely spilled HW register. Return first argument
18002 : : if at least one dependence was added or NULL otherwise. */
18003 : : static rtx_insn *
18004 : 412 : add_parameter_dependencies (rtx_insn *call, rtx_insn *head)
18005 : : {
18006 : 412 : rtx_insn *insn;
18007 : 412 : rtx_insn *last = call;
18008 : 412 : rtx_insn *first_arg = NULL;
18009 : 412 : bool is_spilled = false;
18010 : :
18011 : 412 : head = PREV_INSN (head);
18012 : :
18013 : : /* Find nearest to call argument passing instruction. */
18014 : 412 : while (true)
18015 : : {
18016 : 412 : last = PREV_INSN (last);
18017 : 412 : if (last == head)
18018 : : return NULL;
18019 : 412 : if (!NONDEBUG_INSN_P (last))
18020 : 0 : continue;
18021 : 412 : if (insn_is_function_arg (last, &is_spilled))
18022 : : break;
18023 : : return NULL;
18024 : : }
18025 : :
18026 : : first_arg = last;
18027 : 1123 : while (true)
18028 : : {
18029 : 1123 : insn = PREV_INSN (last);
18030 : 1123 : if (!INSN_P (insn))
18031 : : break;
18032 : 1028 : if (insn == head)
18033 : : break;
18034 : 987 : if (!NONDEBUG_INSN_P (insn))
18035 : : {
18036 : 267 : last = insn;
18037 : 267 : continue;
18038 : : }
18039 : 720 : if (insn_is_function_arg (insn, &is_spilled))
18040 : : {
18041 : : /* Add output depdendence between two function arguments if chain
18042 : : of output arguments contains likely spilled HW registers. */
18043 : 451 : if (is_spilled)
18044 : 451 : add_dependence (first_arg, insn, REG_DEP_OUTPUT);
18045 : : first_arg = last = insn;
18046 : : }
18047 : : else
18048 : : break;
18049 : : }
18050 : 405 : if (!is_spilled)
18051 : : return NULL;
18052 : : return first_arg;
18053 : : }
18054 : :
18055 : : /* Add output or anti dependency from insn to first_arg to restrict its code
18056 : : motion. */
18057 : : static void
18058 : 2445 : avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn)
18059 : : {
18060 : 2445 : rtx set;
18061 : 2445 : rtx tmp;
18062 : :
18063 : 2445 : set = single_set (insn);
18064 : 2445 : if (!set)
18065 : : return;
18066 : 1470 : tmp = SET_DEST (set);
18067 : 1470 : if (REG_P (tmp))
18068 : : {
18069 : : /* Add output dependency to the first function argument. */
18070 : 1267 : add_dependence (first_arg, insn, REG_DEP_OUTPUT);
18071 : 1267 : return;
18072 : : }
18073 : : /* Add anti dependency. */
18074 : 203 : add_dependence (first_arg, insn, REG_DEP_ANTI);
18075 : : }
18076 : :
18077 : : /* Avoid cross block motion of function argument through adding dependency
18078 : : from the first non-jump instruction in bb. */
18079 : : static void
18080 : 68 : add_dependee_for_func_arg (rtx_insn *arg, basic_block bb)
18081 : : {
18082 : 68 : rtx_insn *insn = BB_END (bb);
18083 : :
18084 : 134 : while (insn)
18085 : : {
18086 : 134 : if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn))
18087 : : {
18088 : 67 : rtx set = single_set (insn);
18089 : 67 : if (set)
18090 : : {
18091 : 67 : avoid_func_arg_motion (arg, insn);
18092 : 67 : return;
18093 : : }
18094 : : }
18095 : 67 : if (insn == BB_HEAD (bb))
18096 : : return;
18097 : 66 : insn = PREV_INSN (insn);
18098 : : }
18099 : : }
18100 : :
18101 : : /* Hook for pre-reload schedule - avoid motion of function arguments
18102 : : passed in likely spilled HW registers. */
18103 : : static void
18104 : 10137501 : ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail)
18105 : : {
18106 : 10137501 : rtx_insn *insn;
18107 : 10137501 : rtx_insn *first_arg = NULL;
18108 : 10137501 : if (reload_completed)
18109 : : return;
18110 : 1563 : while (head != tail && DEBUG_INSN_P (head))
18111 : 365 : head = NEXT_INSN (head);
18112 : 9205 : for (insn = tail; insn != head; insn = PREV_INSN (insn))
18113 : 8140 : if (INSN_P (insn) && CALL_P (insn))
18114 : : {
18115 : 412 : first_arg = add_parameter_dependencies (insn, head);
18116 : 412 : if (first_arg)
18117 : : {
18118 : : /* Add dependee for first argument to predecessors if only
18119 : : region contains more than one block. */
18120 : 405 : basic_block bb = BLOCK_FOR_INSN (insn);
18121 : 405 : int rgn = CONTAINING_RGN (bb->index);
18122 : 405 : int nr_blks = RGN_NR_BLOCKS (rgn);
18123 : : /* Skip trivial regions and region head blocks that can have
18124 : : predecessors outside of region. */
18125 : 405 : if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0)
18126 : : {
18127 : 67 : edge e;
18128 : 67 : edge_iterator ei;
18129 : :
18130 : : /* Regions are SCCs with the exception of selective
18131 : : scheduling with pipelining of outer blocks enabled.
18132 : : So also check that immediate predecessors of a non-head
18133 : : block are in the same region. */
18134 : 137 : FOR_EACH_EDGE (e, ei, bb->preds)
18135 : : {
18136 : : /* Avoid creating of loop-carried dependencies through
18137 : : using topological ordering in the region. */
18138 : 70 : if (rgn == CONTAINING_RGN (e->src->index)
18139 : 69 : && BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index))
18140 : 68 : add_dependee_for_func_arg (first_arg, e->src);
18141 : : }
18142 : : }
18143 : 405 : insn = first_arg;
18144 : 405 : if (insn == head)
18145 : : break;
18146 : : }
18147 : : }
18148 : 7728 : else if (first_arg)
18149 : 2378 : avoid_func_arg_motion (first_arg, insn);
18150 : : }
18151 : :
18152 : : /* Hook for pre-reload schedule - set priority of moves from likely spilled
18153 : : HW registers to maximum, to schedule them at soon as possible. These are
18154 : : moves from function argument registers at the top of the function entry
18155 : : and moves from function return value registers after call. */
18156 : : static int
18157 : 105592517 : ix86_adjust_priority (rtx_insn *insn, int priority)
18158 : : {
18159 : 105592517 : rtx set;
18160 : :
18161 : 105592517 : if (reload_completed)
18162 : : return priority;
18163 : :
18164 : 12531 : if (!NONDEBUG_INSN_P (insn))
18165 : : return priority;
18166 : :
18167 : 10809 : set = single_set (insn);
18168 : 10809 : if (set)
18169 : : {
18170 : 10301 : rtx tmp = SET_SRC (set);
18171 : 10301 : if (REG_P (tmp)
18172 : 2298 : && HARD_REGISTER_P (tmp)
18173 : 496 : && !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp))
18174 : 10301 : && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp))))
18175 : 446 : return current_sched_info->sched_max_insns_priority;
18176 : : }
18177 : :
18178 : : return priority;
18179 : : }
18180 : :
18181 : : /* Prepare for scheduling pass. */
18182 : : static void
18183 : 948204 : ix86_sched_init_global (FILE *, int, int)
18184 : : {
18185 : : /* Install scheduling hooks for current CPU. Some of these hooks are used
18186 : : in time-critical parts of the scheduler, so we only set them up when
18187 : : they are actually used. */
18188 : 948204 : switch (ix86_tune)
18189 : : {
18190 : 901804 : case PROCESSOR_CORE2:
18191 : 901804 : case PROCESSOR_NEHALEM:
18192 : 901804 : case PROCESSOR_SANDYBRIDGE:
18193 : 901804 : case PROCESSOR_HASWELL:
18194 : 901804 : case PROCESSOR_TREMONT:
18195 : 901804 : case PROCESSOR_ALDERLAKE:
18196 : 901804 : case PROCESSOR_GENERIC:
18197 : : /* Do not perform multipass scheduling for pre-reload schedule
18198 : : to save compile time. */
18199 : 901804 : if (reload_completed)
18200 : : {
18201 : 901504 : ix86_core2i7_init_hooks ();
18202 : 901504 : break;
18203 : : }
18204 : : /* Fall through. */
18205 : 46700 : default:
18206 : 46700 : targetm.sched.dfa_post_advance_cycle = NULL;
18207 : 46700 : targetm.sched.first_cycle_multipass_init = NULL;
18208 : 46700 : targetm.sched.first_cycle_multipass_begin = NULL;
18209 : 46700 : targetm.sched.first_cycle_multipass_issue = NULL;
18210 : 46700 : targetm.sched.first_cycle_multipass_backtrack = NULL;
18211 : 46700 : targetm.sched.first_cycle_multipass_end = NULL;
18212 : 46700 : targetm.sched.first_cycle_multipass_fini = NULL;
18213 : 46700 : break;
18214 : : }
18215 : 948204 : }
18216 : :
18217 : :
18218 : : /* Implement TARGET_STATIC_RTX_ALIGNMENT. */
18219 : :
18220 : : static HOST_WIDE_INT
18221 : 709310 : ix86_static_rtx_alignment (machine_mode mode)
18222 : : {
18223 : 709310 : if (mode == DFmode)
18224 : : return 64;
18225 : : if (ALIGN_MODE_128 (mode))
18226 : 153298 : return MAX (128, GET_MODE_ALIGNMENT (mode));
18227 : 471962 : return GET_MODE_ALIGNMENT (mode);
18228 : : }
18229 : :
18230 : : /* Implement TARGET_CONSTANT_ALIGNMENT. */
18231 : :
18232 : : static HOST_WIDE_INT
18233 : 6788191 : ix86_constant_alignment (const_tree exp, HOST_WIDE_INT align)
18234 : : {
18235 : 6788191 : if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
18236 : : || TREE_CODE (exp) == INTEGER_CST)
18237 : : {
18238 : 360680 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
18239 : 360680 : HOST_WIDE_INT mode_align = ix86_static_rtx_alignment (mode);
18240 : 360680 : return MAX (mode_align, align);
18241 : : }
18242 : 6287723 : else if (!optimize_size && TREE_CODE (exp) == STRING_CST
18243 : 9477825 : && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
18244 : : return BITS_PER_WORD;
18245 : :
18246 : : return align;
18247 : : }
18248 : :
18249 : : /* Implement TARGET_EMPTY_RECORD_P. */
18250 : :
18251 : : static bool
18252 : 1278337552 : ix86_is_empty_record (const_tree type)
18253 : : {
18254 : 1278337552 : if (!TARGET_64BIT)
18255 : : return false;
18256 : 1248729833 : return default_is_empty_record (type);
18257 : : }
18258 : :
18259 : : /* Implement TARGET_WARN_PARAMETER_PASSING_ABI. */
18260 : :
18261 : : static void
18262 : 15233018 : ix86_warn_parameter_passing_abi (cumulative_args_t cum_v, tree type)
18263 : : {
18264 : 15233018 : CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
18265 : :
18266 : 15233018 : if (!cum->warn_empty)
18267 : : return;
18268 : :
18269 : 12946978 : if (!TYPE_EMPTY_P (type))
18270 : : return;
18271 : :
18272 : : /* Don't warn if the function isn't visible outside of the TU. */
18273 : 14179 : if (cum->decl && !TREE_PUBLIC (cum->decl))
18274 : : return;
18275 : :
18276 : 12721 : tree decl = cum->decl;
18277 : 12721 : if (!decl)
18278 : : /* If we don't know the target, look at the current TU. */
18279 : 39 : decl = current_function_decl;
18280 : :
18281 : 12721 : const_tree ctx = get_ultimate_context (decl);
18282 : 12721 : if (ctx == NULL_TREE
18283 : 25407 : || !TRANSLATION_UNIT_WARN_EMPTY_P (ctx))
18284 : : return;
18285 : :
18286 : : /* If the actual size of the type is zero, then there is no change
18287 : : in how objects of this size are passed. */
18288 : 72 : if (int_size_in_bytes (type) == 0)
18289 : : return;
18290 : :
18291 : 66 : warning (OPT_Wabi, "empty class %qT parameter passing ABI "
18292 : : "changes in %<-fabi-version=12%> (GCC 8)", type);
18293 : :
18294 : : /* Only warn once. */
18295 : 66 : cum->warn_empty = false;
18296 : : }
18297 : :
18298 : : /* This hook returns name of multilib ABI. */
18299 : :
18300 : : static const char *
18301 : 3303723 : ix86_get_multilib_abi_name (void)
18302 : : {
18303 : 3303723 : if (!(TARGET_64BIT_P (ix86_isa_flags)))
18304 : : return "i386";
18305 : 3259767 : else if (TARGET_X32_P (ix86_isa_flags))
18306 : : return "x32";
18307 : : else
18308 : 3259767 : return "x86_64";
18309 : : }
18310 : :
18311 : : /* Compute the alignment for a variable for Intel MCU psABI. TYPE is
18312 : : the data type, and ALIGN is the alignment that the object would
18313 : : ordinarily have. */
18314 : :
18315 : : static int
18316 : 0 : iamcu_alignment (tree type, int align)
18317 : : {
18318 : 0 : machine_mode mode;
18319 : :
18320 : 0 : if (align < 32 || TYPE_USER_ALIGN (type))
18321 : : return align;
18322 : :
18323 : : /* Intel MCU psABI specifies scalar types > 4 bytes aligned to 4
18324 : : bytes. */
18325 : 0 : type = strip_array_types (type);
18326 : 0 : if (TYPE_ATOMIC (type))
18327 : : return align;
18328 : :
18329 : 0 : mode = TYPE_MODE (type);
18330 : 0 : switch (GET_MODE_CLASS (mode))
18331 : : {
18332 : : case MODE_INT:
18333 : : case MODE_COMPLEX_INT:
18334 : : case MODE_COMPLEX_FLOAT:
18335 : : case MODE_FLOAT:
18336 : : case MODE_DECIMAL_FLOAT:
18337 : : return 32;
18338 : : default:
18339 : : return align;
18340 : : }
18341 : : }
18342 : :
18343 : : /* Compute the alignment for a static variable.
18344 : : TYPE is the data type, and ALIGN is the alignment that
18345 : : the object would ordinarily have. The value of this function is used
18346 : : instead of that alignment to align the object. */
18347 : :
18348 : : int
18349 : 11889154 : ix86_data_alignment (tree type, unsigned int align, bool opt)
18350 : : {
18351 : : /* GCC 4.8 and earlier used to incorrectly assume this alignment even
18352 : : for symbols from other compilation units or symbols that don't need
18353 : : to bind locally. In order to preserve some ABI compatibility with
18354 : : those compilers, ensure we don't decrease alignment from what we
18355 : : used to assume. */
18356 : :
18357 : 11889154 : unsigned int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT);
18358 : :
18359 : : /* A data structure, equal or greater than the size of a cache line
18360 : : (64 bytes in the Pentium 4 and other recent Intel processors, including
18361 : : processors based on Intel Core microarchitecture) should be aligned
18362 : : so that its base address is a multiple of a cache line size. */
18363 : :
18364 : 23778308 : unsigned int max_align
18365 : 11889154 : = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
18366 : :
18367 : 14469968 : if (max_align < BITS_PER_WORD)
18368 : 0 : max_align = BITS_PER_WORD;
18369 : :
18370 : 11889154 : switch (ix86_align_data_type)
18371 : : {
18372 : 11889154 : case ix86_align_data_type_abi: opt = false; break;
18373 : 11889134 : case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break;
18374 : : case ix86_align_data_type_cacheline: break;
18375 : : }
18376 : :
18377 : 11889154 : if (TARGET_IAMCU)
18378 : 0 : align = iamcu_alignment (type, align);
18379 : :
18380 : 11889154 : if (opt
18381 : 5742250 : && AGGREGATE_TYPE_P (type)
18382 : 3680635 : && TYPE_SIZE (type)
18383 : 15569757 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
18384 : : {
18385 : 6664336 : if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align_compat)
18386 : 3680603 : && align < max_align_compat)
18387 : 696870 : align = max_align_compat;
18388 : 7300193 : if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align)
18389 : 3680603 : && align < max_align)
18390 : 61013 : align = max_align;
18391 : : }
18392 : :
18393 : : /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18394 : : to 16byte boundary. */
18395 : 11889154 : if (TARGET_64BIT)
18396 : : {
18397 : 4855837 : if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
18398 : 3221332 : && TYPE_SIZE (type)
18399 : 3221290 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18400 : 10724368 : && wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128)
18401 : 11329842 : && align < 128)
18402 : 605474 : return 128;
18403 : : }
18404 : :
18405 : 11283680 : if (!opt)
18406 : 5955506 : return align;
18407 : :
18408 : 5328174 : if (TREE_CODE (type) == ARRAY_TYPE)
18409 : : {
18410 : 1089748 : if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18411 : : return 64;
18412 : 1089748 : if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18413 : : return 128;
18414 : : }
18415 : 4238426 : else if (TREE_CODE (type) == COMPLEX_TYPE)
18416 : : {
18417 : :
18418 : 12861 : if (TYPE_MODE (type) == DCmode && align < 64)
18419 : : return 64;
18420 : 12861 : if ((TYPE_MODE (type) == XCmode
18421 : 12861 : || TYPE_MODE (type) == TCmode) && align < 128)
18422 : : return 128;
18423 : : }
18424 : 4225565 : else if (RECORD_OR_UNION_TYPE_P (type)
18425 : 4225565 : && TYPE_FIELDS (type))
18426 : : {
18427 : 2175135 : if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18428 : : return 64;
18429 : 2175135 : if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18430 : : return 128;
18431 : : }
18432 : 2050430 : else if (SCALAR_FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type)
18433 : : || TREE_CODE (type) == INTEGER_TYPE)
18434 : : {
18435 : 1909681 : if (TYPE_MODE (type) == DFmode && align < 64)
18436 : : return 64;
18437 : 1909681 : if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18438 : : return 128;
18439 : : }
18440 : :
18441 : 5328061 : return align;
18442 : : }
18443 : :
18444 : : /* Implememnt TARGET_LOWER_LOCAL_DECL_ALIGNMENT. */
18445 : : static void
18446 : 30198652 : ix86_lower_local_decl_alignment (tree decl)
18447 : : {
18448 : 30198652 : unsigned int new_align = ix86_local_alignment (decl, VOIDmode,
18449 : 30198652 : DECL_ALIGN (decl), true);
18450 : 30198652 : if (new_align < DECL_ALIGN (decl))
18451 : 0 : SET_DECL_ALIGN (decl, new_align);
18452 : 30198652 : }
18453 : :
18454 : : /* Compute the alignment for a local variable or a stack slot. EXP is
18455 : : the data type or decl itself, MODE is the widest mode available and
18456 : : ALIGN is the alignment that the object would ordinarily have. The
18457 : : value of this macro is used instead of that alignment to align the
18458 : : object. */
18459 : :
18460 : : unsigned int
18461 : 47408513 : ix86_local_alignment (tree exp, machine_mode mode,
18462 : : unsigned int align, bool may_lower)
18463 : : {
18464 : 47408513 : tree type, decl;
18465 : :
18466 : 47408513 : if (exp && DECL_P (exp))
18467 : : {
18468 : 45303948 : type = TREE_TYPE (exp);
18469 : 45303948 : decl = exp;
18470 : : }
18471 : : else
18472 : : {
18473 : : type = exp;
18474 : : decl = NULL;
18475 : : }
18476 : :
18477 : : /* Don't do dynamic stack realignment for long long objects with
18478 : : -mpreferred-stack-boundary=2. */
18479 : 47408513 : if (may_lower
18480 : 30198652 : && !TARGET_64BIT
18481 : 236818 : && align == 64
18482 : 37814 : && ix86_preferred_stack_boundary < 64
18483 : 0 : && (mode == DImode || (type && TYPE_MODE (type) == DImode))
18484 : 0 : && (!type || (!TYPE_USER_ALIGN (type)
18485 : 0 : && !TYPE_ATOMIC (strip_array_types (type))))
18486 : 47408513 : && (!decl || !DECL_USER_ALIGN (decl)))
18487 : : align = 32;
18488 : :
18489 : : /* If TYPE is NULL, we are allocating a stack slot for caller-save
18490 : : register in MODE. We will return the largest alignment of XF
18491 : : and DF. */
18492 : 47408513 : if (!type)
18493 : : {
18494 : 1363308 : if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
18495 : 1468 : align = GET_MODE_ALIGNMENT (DFmode);
18496 : 1363308 : return align;
18497 : : }
18498 : :
18499 : : /* Don't increase alignment for Intel MCU psABI. */
18500 : 46045205 : if (TARGET_IAMCU)
18501 : : return align;
18502 : :
18503 : : /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
18504 : : to 16byte boundary. Exact wording is:
18505 : :
18506 : : An array uses the same alignment as its elements, except that a local or
18507 : : global array variable of length at least 16 bytes or
18508 : : a C99 variable-length array variable always has alignment of at least 16 bytes.
18509 : :
18510 : : This was added to allow use of aligned SSE instructions at arrays. This
18511 : : rule is meant for static storage (where compiler cannot do the analysis
18512 : : by itself). We follow it for automatic variables only when convenient.
18513 : : We fully control everything in the function compiled and functions from
18514 : : other unit cannot rely on the alignment.
18515 : :
18516 : : Exclude va_list type. It is the common case of local array where
18517 : : we cannot benefit from the alignment.
18518 : :
18519 : : TODO: Probably one should optimize for size only when var is not escaping. */
18520 : 43219056 : if (TARGET_64BIT && optimize_function_for_speed_p (cfun)
18521 : 88925711 : && TARGET_SSE)
18522 : : {
18523 : 42841906 : if (AGGREGATE_TYPE_P (type)
18524 : 8907712 : && (va_list_type_node == NULL_TREE
18525 : 8907712 : || (TYPE_MAIN_VARIANT (type)
18526 : 8907712 : != TYPE_MAIN_VARIANT (va_list_type_node)))
18527 : 8810643 : && TYPE_SIZE (type)
18528 : 8810643 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
18529 : 43859422 : && wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128)
18530 : 49401557 : && align < 128)
18531 : 5542135 : return 128;
18532 : : }
18533 : 40503070 : if (TREE_CODE (type) == ARRAY_TYPE)
18534 : : {
18535 : 786259 : if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
18536 : : return 64;
18537 : 786259 : if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
18538 : : return 128;
18539 : : }
18540 : 39716811 : else if (TREE_CODE (type) == COMPLEX_TYPE)
18541 : : {
18542 : 153057 : if (TYPE_MODE (type) == DCmode && align < 64)
18543 : : return 64;
18544 : 153057 : if ((TYPE_MODE (type) == XCmode
18545 : 153057 : || TYPE_MODE (type) == TCmode) && align < 128)
18546 : : return 128;
18547 : : }
18548 : 39563754 : else if (RECORD_OR_UNION_TYPE_P (type)
18549 : 39563754 : && TYPE_FIELDS (type))
18550 : : {
18551 : 4574130 : if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
18552 : : return 64;
18553 : 4570926 : if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
18554 : : return 128;
18555 : : }
18556 : 34989624 : else if (SCALAR_FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type)
18557 : : || TREE_CODE (type) == INTEGER_TYPE)
18558 : : {
18559 : :
18560 : 29008261 : if (TYPE_MODE (type) == DFmode && align < 64)
18561 : : return 64;
18562 : 29008261 : if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
18563 : : return 128;
18564 : : }
18565 : : return align;
18566 : : }
18567 : :
18568 : : /* Compute the minimum required alignment for dynamic stack realignment
18569 : : purposes for a local variable, parameter or a stack slot. EXP is
18570 : : the data type or decl itself, MODE is its mode and ALIGN is the
18571 : : alignment that the object would ordinarily have. */
18572 : :
18573 : : unsigned int
18574 : 47501335 : ix86_minimum_alignment (tree exp, machine_mode mode,
18575 : : unsigned int align)
18576 : : {
18577 : 47501335 : tree type, decl;
18578 : :
18579 : 47501335 : if (exp && DECL_P (exp))
18580 : : {
18581 : 15117273 : type = TREE_TYPE (exp);
18582 : 15117273 : decl = exp;
18583 : : }
18584 : : else
18585 : : {
18586 : : type = exp;
18587 : : decl = NULL;
18588 : : }
18589 : :
18590 : 47501335 : if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
18591 : : return align;
18592 : :
18593 : : /* Don't do dynamic stack realignment for long long objects with
18594 : : -mpreferred-stack-boundary=2. */
18595 : 0 : if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
18596 : 0 : && (!type || (!TYPE_USER_ALIGN (type)
18597 : 0 : && !TYPE_ATOMIC (strip_array_types (type))))
18598 : 0 : && (!decl || !DECL_USER_ALIGN (decl)))
18599 : : {
18600 : 0 : gcc_checking_assert (!TARGET_STV);
18601 : : return 32;
18602 : : }
18603 : :
18604 : : return align;
18605 : : }
18606 : :
18607 : : /* Find a location for the static chain incoming to a nested function.
18608 : : This is a register, unless all free registers are used by arguments. */
18609 : :
18610 : : static rtx
18611 : 267776 : ix86_static_chain (const_tree fndecl_or_type, bool incoming_p)
18612 : : {
18613 : 267776 : unsigned regno;
18614 : :
18615 : 267776 : if (TARGET_64BIT)
18616 : : {
18617 : : /* We always use R10 in 64-bit mode. */
18618 : : regno = R10_REG;
18619 : : }
18620 : : else
18621 : : {
18622 : 88480 : const_tree fntype, fndecl;
18623 : 88480 : unsigned int ccvt;
18624 : :
18625 : : /* By default in 32-bit mode we use ECX to pass the static chain. */
18626 : 88480 : regno = CX_REG;
18627 : :
18628 : 88480 : if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL)
18629 : : {
18630 : 78558 : fntype = TREE_TYPE (fndecl_or_type);
18631 : 78558 : fndecl = fndecl_or_type;
18632 : : }
18633 : : else
18634 : : {
18635 : : fntype = fndecl_or_type;
18636 : : fndecl = NULL;
18637 : : }
18638 : :
18639 : 88480 : ccvt = ix86_get_callcvt (fntype);
18640 : 88480 : if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
18641 : : {
18642 : : /* Fastcall functions use ecx/edx for arguments, which leaves
18643 : : us with EAX for the static chain.
18644 : : Thiscall functions use ecx for arguments, which also
18645 : : leaves us with EAX for the static chain. */
18646 : : regno = AX_REG;
18647 : : }
18648 : 88480 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
18649 : : {
18650 : : /* Thiscall functions use ecx for arguments, which leaves
18651 : : us with EAX and EDX for the static chain.
18652 : : We are using for abi-compatibility EAX. */
18653 : : regno = AX_REG;
18654 : : }
18655 : 88480 : else if (ix86_function_regparm (fntype, fndecl) == 3)
18656 : : {
18657 : : /* For regparm 3, we have no free call-clobbered registers in
18658 : : which to store the static chain. In order to implement this,
18659 : : we have the trampoline push the static chain to the stack.
18660 : : However, we can't push a value below the return address when
18661 : : we call the nested function directly, so we have to use an
18662 : : alternate entry point. For this we use ESI, and have the
18663 : : alternate entry point push ESI, so that things appear the
18664 : : same once we're executing the nested function. */
18665 : 0 : if (incoming_p)
18666 : : {
18667 : 0 : if (fndecl == current_function_decl
18668 : 0 : && !ix86_static_chain_on_stack)
18669 : : {
18670 : 0 : gcc_assert (!reload_completed);
18671 : 0 : ix86_static_chain_on_stack = true;
18672 : : }
18673 : 0 : return gen_frame_mem (SImode,
18674 : 0 : plus_constant (Pmode,
18675 : : arg_pointer_rtx, -8));
18676 : : }
18677 : : regno = SI_REG;
18678 : : }
18679 : : }
18680 : :
18681 : 356269 : return gen_rtx_REG (Pmode, regno);
18682 : : }
18683 : :
18684 : : /* Emit RTL insns to initialize the variable parts of a trampoline.
18685 : : FNDECL is the decl of the target address; M_TRAMP is a MEM for
18686 : : the trampoline, and CHAIN_VALUE is an RTX for the static chain
18687 : : to be passed to the target function. */
18688 : :
18689 : : static void
18690 : 290 : ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
18691 : : {
18692 : 290 : rtx mem, fnaddr;
18693 : 290 : int opcode;
18694 : 290 : int offset = 0;
18695 : 290 : bool need_endbr = (flag_cf_protection & CF_BRANCH);
18696 : :
18697 : 290 : fnaddr = XEXP (DECL_RTL (fndecl), 0);
18698 : :
18699 : 290 : if (TARGET_64BIT)
18700 : : {
18701 : 290 : int size;
18702 : :
18703 : 290 : if (need_endbr)
18704 : : {
18705 : : /* Insert ENDBR64. */
18706 : 1 : mem = adjust_address (m_tramp, SImode, offset);
18707 : 1 : emit_move_insn (mem, gen_int_mode (0xfa1e0ff3, SImode));
18708 : 1 : offset += 4;
18709 : : }
18710 : :
18711 : : /* Load the function address to r11. Try to load address using
18712 : : the shorter movl instead of movabs. We may want to support
18713 : : movq for kernel mode, but kernel does not use trampolines at
18714 : : the moment. FNADDR is a 32bit address and may not be in
18715 : : DImode when ptr_mode == SImode. Always use movl in this
18716 : : case. */
18717 : 290 : if (ptr_mode == SImode
18718 : 290 : || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
18719 : : {
18720 : 258 : fnaddr = copy_addr_to_reg (fnaddr);
18721 : :
18722 : 258 : mem = adjust_address (m_tramp, HImode, offset);
18723 : 258 : emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
18724 : :
18725 : 258 : mem = adjust_address (m_tramp, SImode, offset + 2);
18726 : 258 : emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
18727 : 258 : offset += 6;
18728 : : }
18729 : : else
18730 : : {
18731 : 32 : mem = adjust_address (m_tramp, HImode, offset);
18732 : 32 : emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
18733 : :
18734 : 32 : mem = adjust_address (m_tramp, DImode, offset + 2);
18735 : 32 : emit_move_insn (mem, fnaddr);
18736 : 32 : offset += 10;
18737 : : }
18738 : :
18739 : : /* Load static chain using movabs to r10. Use the shorter movl
18740 : : instead of movabs when ptr_mode == SImode. */
18741 : 290 : if (ptr_mode == SImode)
18742 : : {
18743 : : opcode = 0xba41;
18744 : : size = 6;
18745 : : }
18746 : : else
18747 : : {
18748 : 290 : opcode = 0xba49;
18749 : 290 : size = 10;
18750 : : }
18751 : :
18752 : 290 : mem = adjust_address (m_tramp, HImode, offset);
18753 : 290 : emit_move_insn (mem, gen_int_mode (opcode, HImode));
18754 : :
18755 : 290 : mem = adjust_address (m_tramp, ptr_mode, offset + 2);
18756 : 290 : emit_move_insn (mem, chain_value);
18757 : 290 : offset += size;
18758 : :
18759 : : /* Jump to r11; the last (unused) byte is a nop, only there to
18760 : : pad the write out to a single 32-bit store. */
18761 : 290 : mem = adjust_address (m_tramp, SImode, offset);
18762 : 290 : emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
18763 : 290 : offset += 4;
18764 : : }
18765 : : else
18766 : : {
18767 : 0 : rtx disp, chain;
18768 : :
18769 : : /* Depending on the static chain location, either load a register
18770 : : with a constant, or push the constant to the stack. All of the
18771 : : instructions are the same size. */
18772 : 0 : chain = ix86_static_chain (fndecl, true);
18773 : 0 : if (REG_P (chain))
18774 : : {
18775 : 0 : switch (REGNO (chain))
18776 : : {
18777 : : case AX_REG:
18778 : : opcode = 0xb8; break;
18779 : 0 : case CX_REG:
18780 : 0 : opcode = 0xb9; break;
18781 : 0 : default:
18782 : 0 : gcc_unreachable ();
18783 : : }
18784 : : }
18785 : : else
18786 : : opcode = 0x68;
18787 : :
18788 : 0 : if (need_endbr)
18789 : : {
18790 : : /* Insert ENDBR32. */
18791 : 0 : mem = adjust_address (m_tramp, SImode, offset);
18792 : 0 : emit_move_insn (mem, gen_int_mode (0xfb1e0ff3, SImode));
18793 : 0 : offset += 4;
18794 : : }
18795 : :
18796 : 0 : mem = adjust_address (m_tramp, QImode, offset);
18797 : 0 : emit_move_insn (mem, gen_int_mode (opcode, QImode));
18798 : :
18799 : 0 : mem = adjust_address (m_tramp, SImode, offset + 1);
18800 : 0 : emit_move_insn (mem, chain_value);
18801 : 0 : offset += 5;
18802 : :
18803 : 0 : mem = adjust_address (m_tramp, QImode, offset);
18804 : 0 : emit_move_insn (mem, gen_int_mode (0xe9, QImode));
18805 : :
18806 : 0 : mem = adjust_address (m_tramp, SImode, offset + 1);
18807 : :
18808 : : /* Compute offset from the end of the jmp to the target function.
18809 : : In the case in which the trampoline stores the static chain on
18810 : : the stack, we need to skip the first insn which pushes the
18811 : : (call-saved) register static chain; this push is 1 byte. */
18812 : 0 : offset += 5;
18813 : 0 : int skip = MEM_P (chain) ? 1 : 0;
18814 : : /* Skip ENDBR32 at the entry of the target function. */
18815 : 0 : if (need_endbr
18816 : 0 : && !cgraph_node::get (fndecl)->only_called_directly_p ())
18817 : 0 : skip += 4;
18818 : 0 : disp = expand_binop (SImode, sub_optab, fnaddr,
18819 : 0 : plus_constant (Pmode, XEXP (m_tramp, 0),
18820 : 0 : offset - skip),
18821 : : NULL_RTX, 1, OPTAB_DIRECT);
18822 : 0 : emit_move_insn (mem, disp);
18823 : : }
18824 : :
18825 : 290 : gcc_assert (offset <= TRAMPOLINE_SIZE);
18826 : :
18827 : : #ifdef HAVE_ENABLE_EXECUTE_STACK
18828 : : #ifdef CHECK_EXECUTE_STACK_ENABLED
18829 : : if (CHECK_EXECUTE_STACK_ENABLED)
18830 : : #endif
18831 : : emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
18832 : : LCT_NORMAL, VOIDmode, XEXP (m_tramp, 0), Pmode);
18833 : : #endif
18834 : 290 : }
18835 : :
18836 : : static bool
18837 : 53692148 : ix86_allocate_stack_slots_for_args (void)
18838 : : {
18839 : : /* Naked functions should not allocate stack slots for arguments. */
18840 : 53692148 : return !ix86_function_naked (current_function_decl);
18841 : : }
18842 : :
18843 : : static bool
18844 : 32595186 : ix86_warn_func_return (tree decl)
18845 : : {
18846 : : /* Naked functions are implemented entirely in assembly, including the
18847 : : return sequence, so suppress warnings about this. */
18848 : 32595186 : return !ix86_function_naked (decl);
18849 : : }
18850 : :
18851 : : /* Return the shift count of a vector by scalar shift builtin second argument
18852 : : ARG1. */
18853 : : static tree
18854 : 14142 : ix86_vector_shift_count (tree arg1)
18855 : : {
18856 : 14142 : if (tree_fits_uhwi_p (arg1))
18857 : : return arg1;
18858 : 8316 : else if (TREE_CODE (arg1) == VECTOR_CST && CHAR_BIT == 8)
18859 : : {
18860 : : /* The count argument is weird, passed in as various 128-bit
18861 : : (or 64-bit) vectors, the low 64 bits from it are the count. */
18862 : 162 : unsigned char buf[16];
18863 : 162 : int len = native_encode_expr (arg1, buf, 16);
18864 : 162 : if (len == 0)
18865 : 162 : return NULL_TREE;
18866 : 162 : tree t = native_interpret_expr (uint64_type_node, buf, len);
18867 : 162 : if (t && tree_fits_uhwi_p (t))
18868 : : return t;
18869 : : }
18870 : : return NULL_TREE;
18871 : : }
18872 : :
18873 : : /* Return true if arg_mask is all ones, ELEMS is elements number of
18874 : : corresponding vector. */
18875 : : static bool
18876 : 25032 : ix86_masked_all_ones (unsigned HOST_WIDE_INT elems, tree arg_mask)
18877 : : {
18878 : 25032 : if (TREE_CODE (arg_mask) != INTEGER_CST)
18879 : : return false;
18880 : :
18881 : 7452 : unsigned HOST_WIDE_INT mask = TREE_INT_CST_LOW (arg_mask);
18882 : 7452 : if (elems == HOST_BITS_PER_WIDE_INT)
18883 : 33 : return mask == HOST_WIDE_INT_M1U;
18884 : 7419 : if ((mask | (HOST_WIDE_INT_M1U << elems)) != HOST_WIDE_INT_M1U)
18885 : 2671 : return false;
18886 : :
18887 : : return true;
18888 : : }
18889 : :
18890 : : static tree
18891 : 65993613 : ix86_fold_builtin (tree fndecl, int n_args,
18892 : : tree *args, bool ignore ATTRIBUTE_UNUSED)
18893 : : {
18894 : 65993613 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
18895 : : {
18896 : 65993613 : enum ix86_builtins fn_code
18897 : 65993613 : = (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
18898 : 65993613 : enum rtx_code rcode;
18899 : 65993613 : bool is_vshift;
18900 : 65993613 : enum tree_code tcode;
18901 : 65993613 : bool is_scalar;
18902 : 65993613 : unsigned HOST_WIDE_INT mask;
18903 : :
18904 : 65993613 : switch (fn_code)
18905 : : {
18906 : 8362 : case IX86_BUILTIN_CPU_IS:
18907 : 8362 : case IX86_BUILTIN_CPU_SUPPORTS:
18908 : 8362 : gcc_assert (n_args == 1);
18909 : 8362 : return fold_builtin_cpu (fndecl, args);
18910 : :
18911 : 20841 : case IX86_BUILTIN_NANQ:
18912 : 20841 : case IX86_BUILTIN_NANSQ:
18913 : 20841 : {
18914 : 20841 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18915 : 20841 : const char *str = c_getstr (*args);
18916 : 20841 : int quiet = fn_code == IX86_BUILTIN_NANQ;
18917 : 20841 : REAL_VALUE_TYPE real;
18918 : :
18919 : 20841 : if (str && real_nan (&real, str, quiet, TYPE_MODE (type)))
18920 : 20841 : return build_real (type, real);
18921 : 0 : return NULL_TREE;
18922 : : }
18923 : :
18924 : 108 : case IX86_BUILTIN_INFQ:
18925 : 108 : case IX86_BUILTIN_HUGE_VALQ:
18926 : 108 : {
18927 : 108 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18928 : 108 : REAL_VALUE_TYPE inf;
18929 : 108 : real_inf (&inf);
18930 : 108 : return build_real (type, inf);
18931 : : }
18932 : :
18933 : 60485 : case IX86_BUILTIN_TZCNT16:
18934 : 60485 : case IX86_BUILTIN_CTZS:
18935 : 60485 : case IX86_BUILTIN_TZCNT32:
18936 : 60485 : case IX86_BUILTIN_TZCNT64:
18937 : 60485 : gcc_assert (n_args == 1);
18938 : 60485 : if (TREE_CODE (args[0]) == INTEGER_CST)
18939 : : {
18940 : 45 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18941 : 45 : tree arg = args[0];
18942 : 45 : if (fn_code == IX86_BUILTIN_TZCNT16
18943 : 45 : || fn_code == IX86_BUILTIN_CTZS)
18944 : 3 : arg = fold_convert (short_unsigned_type_node, arg);
18945 : 45 : if (integer_zerop (arg))
18946 : 6 : return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
18947 : : else
18948 : 39 : return fold_const_call (CFN_CTZ, type, arg);
18949 : : }
18950 : : break;
18951 : :
18952 : 50339 : case IX86_BUILTIN_LZCNT16:
18953 : 50339 : case IX86_BUILTIN_CLZS:
18954 : 50339 : case IX86_BUILTIN_LZCNT32:
18955 : 50339 : case IX86_BUILTIN_LZCNT64:
18956 : 50339 : gcc_assert (n_args == 1);
18957 : 50339 : if (TREE_CODE (args[0]) == INTEGER_CST)
18958 : : {
18959 : 54 : tree type = TREE_TYPE (TREE_TYPE (fndecl));
18960 : 54 : tree arg = args[0];
18961 : 54 : if (fn_code == IX86_BUILTIN_LZCNT16
18962 : 54 : || fn_code == IX86_BUILTIN_CLZS)
18963 : 18 : arg = fold_convert (short_unsigned_type_node, arg);
18964 : 54 : if (integer_zerop (arg))
18965 : 3 : return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
18966 : : else
18967 : 51 : return fold_const_call (CFN_CLZ, type, arg);
18968 : : }
18969 : : break;
18970 : :
18971 : 59421 : case IX86_BUILTIN_BEXTR32:
18972 : 59421 : case IX86_BUILTIN_BEXTR64:
18973 : 59421 : case IX86_BUILTIN_BEXTRI32:
18974 : 59421 : case IX86_BUILTIN_BEXTRI64:
18975 : 59421 : gcc_assert (n_args == 2);
18976 : 59421 : if (tree_fits_uhwi_p (args[1]))
18977 : : {
18978 : 152 : unsigned HOST_WIDE_INT res = 0;
18979 : 152 : unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0]));
18980 : 152 : unsigned int start = tree_to_uhwi (args[1]);
18981 : 152 : unsigned int len = (start & 0xff00) >> 8;
18982 : 152 : tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
18983 : 152 : start &= 0xff;
18984 : 152 : if (start >= prec || len == 0)
18985 : 111 : return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
18986 : : args[0]);
18987 : 41 : else if (!tree_fits_uhwi_p (args[0]))
18988 : : break;
18989 : : else
18990 : 24 : res = tree_to_uhwi (args[0]) >> start;
18991 : 24 : if (len > prec)
18992 : : len = prec;
18993 : 24 : if (len < HOST_BITS_PER_WIDE_INT)
18994 : 15 : res &= (HOST_WIDE_INT_1U << len) - 1;
18995 : 24 : return build_int_cstu (lhs_type, res);
18996 : : }
18997 : : break;
18998 : :
18999 : 20380 : case IX86_BUILTIN_BZHI32:
19000 : 20380 : case IX86_BUILTIN_BZHI64:
19001 : 20380 : gcc_assert (n_args == 2);
19002 : 20380 : if (tree_fits_uhwi_p (args[1]))
19003 : : {
19004 : 190 : unsigned int idx = tree_to_uhwi (args[1]) & 0xff;
19005 : 190 : tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
19006 : 190 : if (idx >= TYPE_PRECISION (TREE_TYPE (args[0])))
19007 : : return args[0];
19008 : 190 : if (idx == 0)
19009 : 52 : return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
19010 : : args[0]);
19011 : 138 : if (!tree_fits_uhwi_p (args[0]))
19012 : : break;
19013 : 12 : unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]);
19014 : 12 : res &= ~(HOST_WIDE_INT_M1U << idx);
19015 : 12 : return build_int_cstu (lhs_type, res);
19016 : : }
19017 : : break;
19018 : :
19019 : 20138 : case IX86_BUILTIN_PDEP32:
19020 : 20138 : case IX86_BUILTIN_PDEP64:
19021 : 20138 : gcc_assert (n_args == 2);
19022 : 20138 : if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1]))
19023 : : {
19024 : 46 : unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]);
19025 : 46 : unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]);
19026 : 46 : unsigned HOST_WIDE_INT res = 0;
19027 : 46 : unsigned HOST_WIDE_INT m, k = 1;
19028 : 2990 : for (m = 1; m; m <<= 1)
19029 : 2944 : if ((mask & m) != 0)
19030 : : {
19031 : 1440 : if ((src & k) != 0)
19032 : 789 : res |= m;
19033 : 1440 : k <<= 1;
19034 : : }
19035 : 46 : return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
19036 : : }
19037 : : break;
19038 : :
19039 : 20140 : case IX86_BUILTIN_PEXT32:
19040 : 20140 : case IX86_BUILTIN_PEXT64:
19041 : 20140 : gcc_assert (n_args == 2);
19042 : 20140 : if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1]))
19043 : : {
19044 : 46 : unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]);
19045 : 46 : unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]);
19046 : 46 : unsigned HOST_WIDE_INT res = 0;
19047 : 46 : unsigned HOST_WIDE_INT m, k = 1;
19048 : 2990 : for (m = 1; m; m <<= 1)
19049 : 2944 : if ((mask & m) != 0)
19050 : : {
19051 : 2016 : if ((src & m) != 0)
19052 : 1063 : res |= k;
19053 : 2016 : k <<= 1;
19054 : : }
19055 : 46 : return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
19056 : : }
19057 : : break;
19058 : :
19059 : 78956 : case IX86_BUILTIN_MOVMSKPS:
19060 : 78956 : case IX86_BUILTIN_PMOVMSKB:
19061 : 78956 : case IX86_BUILTIN_MOVMSKPD:
19062 : 78956 : case IX86_BUILTIN_PMOVMSKB128:
19063 : 78956 : case IX86_BUILTIN_MOVMSKPD256:
19064 : 78956 : case IX86_BUILTIN_MOVMSKPS256:
19065 : 78956 : case IX86_BUILTIN_PMOVMSKB256:
19066 : 78956 : gcc_assert (n_args == 1);
19067 : 78956 : if (TREE_CODE (args[0]) == VECTOR_CST)
19068 : : {
19069 : : HOST_WIDE_INT res = 0;
19070 : 139 : for (unsigned i = 0; i < VECTOR_CST_NELTS (args[0]); ++i)
19071 : : {
19072 : 124 : tree e = VECTOR_CST_ELT (args[0], i);
19073 : 124 : if (TREE_CODE (e) == INTEGER_CST && !TREE_OVERFLOW (e))
19074 : : {
19075 : 80 : if (wi::neg_p (wi::to_wide (e)))
19076 : 31 : res |= HOST_WIDE_INT_1 << i;
19077 : : }
19078 : 44 : else if (TREE_CODE (e) == REAL_CST && !TREE_OVERFLOW (e))
19079 : : {
19080 : 44 : if (TREE_REAL_CST (e).sign)
19081 : 19 : res |= HOST_WIDE_INT_1 << i;
19082 : : }
19083 : : else
19084 : : return NULL_TREE;
19085 : : }
19086 : 15 : return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), res);
19087 : : }
19088 : : break;
19089 : :
19090 : 640930 : case IX86_BUILTIN_PSLLD:
19091 : 640930 : case IX86_BUILTIN_PSLLD128:
19092 : 640930 : case IX86_BUILTIN_PSLLD128_MASK:
19093 : 640930 : case IX86_BUILTIN_PSLLD256:
19094 : 640930 : case IX86_BUILTIN_PSLLD256_MASK:
19095 : 640930 : case IX86_BUILTIN_PSLLD512:
19096 : 640930 : case IX86_BUILTIN_PSLLDI:
19097 : 640930 : case IX86_BUILTIN_PSLLDI128:
19098 : 640930 : case IX86_BUILTIN_PSLLDI128_MASK:
19099 : 640930 : case IX86_BUILTIN_PSLLDI256:
19100 : 640930 : case IX86_BUILTIN_PSLLDI256_MASK:
19101 : 640930 : case IX86_BUILTIN_PSLLDI512:
19102 : 640930 : case IX86_BUILTIN_PSLLQ:
19103 : 640930 : case IX86_BUILTIN_PSLLQ128:
19104 : 640930 : case IX86_BUILTIN_PSLLQ128_MASK:
19105 : 640930 : case IX86_BUILTIN_PSLLQ256:
19106 : 640930 : case IX86_BUILTIN_PSLLQ256_MASK:
19107 : 640930 : case IX86_BUILTIN_PSLLQ512:
19108 : 640930 : case IX86_BUILTIN_PSLLQI:
19109 : 640930 : case IX86_BUILTIN_PSLLQI128:
19110 : 640930 : case IX86_BUILTIN_PSLLQI128_MASK:
19111 : 640930 : case IX86_BUILTIN_PSLLQI256:
19112 : 640930 : case IX86_BUILTIN_PSLLQI256_MASK:
19113 : 640930 : case IX86_BUILTIN_PSLLQI512:
19114 : 640930 : case IX86_BUILTIN_PSLLW:
19115 : 640930 : case IX86_BUILTIN_PSLLW128:
19116 : 640930 : case IX86_BUILTIN_PSLLW128_MASK:
19117 : 640930 : case IX86_BUILTIN_PSLLW256:
19118 : 640930 : case IX86_BUILTIN_PSLLW256_MASK:
19119 : 640930 : case IX86_BUILTIN_PSLLW512_MASK:
19120 : 640930 : case IX86_BUILTIN_PSLLWI:
19121 : 640930 : case IX86_BUILTIN_PSLLWI128:
19122 : 640930 : case IX86_BUILTIN_PSLLWI128_MASK:
19123 : 640930 : case IX86_BUILTIN_PSLLWI256:
19124 : 640930 : case IX86_BUILTIN_PSLLWI256_MASK:
19125 : 640930 : case IX86_BUILTIN_PSLLWI512_MASK:
19126 : 640930 : rcode = ASHIFT;
19127 : 640930 : is_vshift = false;
19128 : 640930 : goto do_shift;
19129 : 584733 : case IX86_BUILTIN_PSRAD:
19130 : 584733 : case IX86_BUILTIN_PSRAD128:
19131 : 584733 : case IX86_BUILTIN_PSRAD128_MASK:
19132 : 584733 : case IX86_BUILTIN_PSRAD256:
19133 : 584733 : case IX86_BUILTIN_PSRAD256_MASK:
19134 : 584733 : case IX86_BUILTIN_PSRAD512:
19135 : 584733 : case IX86_BUILTIN_PSRADI:
19136 : 584733 : case IX86_BUILTIN_PSRADI128:
19137 : 584733 : case IX86_BUILTIN_PSRADI128_MASK:
19138 : 584733 : case IX86_BUILTIN_PSRADI256:
19139 : 584733 : case IX86_BUILTIN_PSRADI256_MASK:
19140 : 584733 : case IX86_BUILTIN_PSRADI512:
19141 : 584733 : case IX86_BUILTIN_PSRAQ128_MASK:
19142 : 584733 : case IX86_BUILTIN_PSRAQ256_MASK:
19143 : 584733 : case IX86_BUILTIN_PSRAQ512:
19144 : 584733 : case IX86_BUILTIN_PSRAQI128_MASK:
19145 : 584733 : case IX86_BUILTIN_PSRAQI256_MASK:
19146 : 584733 : case IX86_BUILTIN_PSRAQI512:
19147 : 584733 : case IX86_BUILTIN_PSRAW:
19148 : 584733 : case IX86_BUILTIN_PSRAW128:
19149 : 584733 : case IX86_BUILTIN_PSRAW128_MASK:
19150 : 584733 : case IX86_BUILTIN_PSRAW256:
19151 : 584733 : case IX86_BUILTIN_PSRAW256_MASK:
19152 : 584733 : case IX86_BUILTIN_PSRAW512:
19153 : 584733 : case IX86_BUILTIN_PSRAWI:
19154 : 584733 : case IX86_BUILTIN_PSRAWI128:
19155 : 584733 : case IX86_BUILTIN_PSRAWI128_MASK:
19156 : 584733 : case IX86_BUILTIN_PSRAWI256:
19157 : 584733 : case IX86_BUILTIN_PSRAWI256_MASK:
19158 : 584733 : case IX86_BUILTIN_PSRAWI512:
19159 : 584733 : rcode = ASHIFTRT;
19160 : 584733 : is_vshift = false;
19161 : 584733 : goto do_shift;
19162 : 616123 : case IX86_BUILTIN_PSRLD:
19163 : 616123 : case IX86_BUILTIN_PSRLD128:
19164 : 616123 : case IX86_BUILTIN_PSRLD128_MASK:
19165 : 616123 : case IX86_BUILTIN_PSRLD256:
19166 : 616123 : case IX86_BUILTIN_PSRLD256_MASK:
19167 : 616123 : case IX86_BUILTIN_PSRLD512:
19168 : 616123 : case IX86_BUILTIN_PSRLDI:
19169 : 616123 : case IX86_BUILTIN_PSRLDI128:
19170 : 616123 : case IX86_BUILTIN_PSRLDI128_MASK:
19171 : 616123 : case IX86_BUILTIN_PSRLDI256:
19172 : 616123 : case IX86_BUILTIN_PSRLDI256_MASK:
19173 : 616123 : case IX86_BUILTIN_PSRLDI512:
19174 : 616123 : case IX86_BUILTIN_PSRLQ:
19175 : 616123 : case IX86_BUILTIN_PSRLQ128:
19176 : 616123 : case IX86_BUILTIN_PSRLQ128_MASK:
19177 : 616123 : case IX86_BUILTIN_PSRLQ256:
19178 : 616123 : case IX86_BUILTIN_PSRLQ256_MASK:
19179 : 616123 : case IX86_BUILTIN_PSRLQ512:
19180 : 616123 : case IX86_BUILTIN_PSRLQI:
19181 : 616123 : case IX86_BUILTIN_PSRLQI128:
19182 : 616123 : case IX86_BUILTIN_PSRLQI128_MASK:
19183 : 616123 : case IX86_BUILTIN_PSRLQI256:
19184 : 616123 : case IX86_BUILTIN_PSRLQI256_MASK:
19185 : 616123 : case IX86_BUILTIN_PSRLQI512:
19186 : 616123 : case IX86_BUILTIN_PSRLW:
19187 : 616123 : case IX86_BUILTIN_PSRLW128:
19188 : 616123 : case IX86_BUILTIN_PSRLW128_MASK:
19189 : 616123 : case IX86_BUILTIN_PSRLW256:
19190 : 616123 : case IX86_BUILTIN_PSRLW256_MASK:
19191 : 616123 : case IX86_BUILTIN_PSRLW512:
19192 : 616123 : case IX86_BUILTIN_PSRLWI:
19193 : 616123 : case IX86_BUILTIN_PSRLWI128:
19194 : 616123 : case IX86_BUILTIN_PSRLWI128_MASK:
19195 : 616123 : case IX86_BUILTIN_PSRLWI256:
19196 : 616123 : case IX86_BUILTIN_PSRLWI256_MASK:
19197 : 616123 : case IX86_BUILTIN_PSRLWI512:
19198 : 616123 : rcode = LSHIFTRT;
19199 : 616123 : is_vshift = false;
19200 : 616123 : goto do_shift;
19201 : 267528 : case IX86_BUILTIN_PSLLVV16HI:
19202 : 267528 : case IX86_BUILTIN_PSLLVV16SI:
19203 : 267528 : case IX86_BUILTIN_PSLLVV2DI:
19204 : 267528 : case IX86_BUILTIN_PSLLVV2DI_MASK:
19205 : 267528 : case IX86_BUILTIN_PSLLVV32HI:
19206 : 267528 : case IX86_BUILTIN_PSLLVV4DI:
19207 : 267528 : case IX86_BUILTIN_PSLLVV4DI_MASK:
19208 : 267528 : case IX86_BUILTIN_PSLLVV4SI:
19209 : 267528 : case IX86_BUILTIN_PSLLVV4SI_MASK:
19210 : 267528 : case IX86_BUILTIN_PSLLVV8DI:
19211 : 267528 : case IX86_BUILTIN_PSLLVV8HI:
19212 : 267528 : case IX86_BUILTIN_PSLLVV8SI:
19213 : 267528 : case IX86_BUILTIN_PSLLVV8SI_MASK:
19214 : 267528 : rcode = ASHIFT;
19215 : 267528 : is_vshift = true;
19216 : 267528 : goto do_shift;
19217 : 267149 : case IX86_BUILTIN_PSRAVQ128:
19218 : 267149 : case IX86_BUILTIN_PSRAVQ256:
19219 : 267149 : case IX86_BUILTIN_PSRAVV16HI:
19220 : 267149 : case IX86_BUILTIN_PSRAVV16SI:
19221 : 267149 : case IX86_BUILTIN_PSRAVV32HI:
19222 : 267149 : case IX86_BUILTIN_PSRAVV4SI:
19223 : 267149 : case IX86_BUILTIN_PSRAVV4SI_MASK:
19224 : 267149 : case IX86_BUILTIN_PSRAVV8DI:
19225 : 267149 : case IX86_BUILTIN_PSRAVV8HI:
19226 : 267149 : case IX86_BUILTIN_PSRAVV8SI:
19227 : 267149 : case IX86_BUILTIN_PSRAVV8SI_MASK:
19228 : 267149 : rcode = ASHIFTRT;
19229 : 267149 : is_vshift = true;
19230 : 267149 : goto do_shift;
19231 : 267519 : case IX86_BUILTIN_PSRLVV16HI:
19232 : 267519 : case IX86_BUILTIN_PSRLVV16SI:
19233 : 267519 : case IX86_BUILTIN_PSRLVV2DI:
19234 : 267519 : case IX86_BUILTIN_PSRLVV2DI_MASK:
19235 : 267519 : case IX86_BUILTIN_PSRLVV32HI:
19236 : 267519 : case IX86_BUILTIN_PSRLVV4DI:
19237 : 267519 : case IX86_BUILTIN_PSRLVV4DI_MASK:
19238 : 267519 : case IX86_BUILTIN_PSRLVV4SI:
19239 : 267519 : case IX86_BUILTIN_PSRLVV4SI_MASK:
19240 : 267519 : case IX86_BUILTIN_PSRLVV8DI:
19241 : 267519 : case IX86_BUILTIN_PSRLVV8HI:
19242 : 267519 : case IX86_BUILTIN_PSRLVV8SI:
19243 : 267519 : case IX86_BUILTIN_PSRLVV8SI_MASK:
19244 : 267519 : rcode = LSHIFTRT;
19245 : 267519 : is_vshift = true;
19246 : 267519 : goto do_shift;
19247 : :
19248 : 2643982 : do_shift:
19249 : 2643982 : gcc_assert (n_args >= 2);
19250 : 2643982 : if (TREE_CODE (args[0]) != VECTOR_CST)
19251 : : break;
19252 : 916 : mask = HOST_WIDE_INT_M1U;
19253 : 916 : if (n_args > 2)
19254 : : {
19255 : : /* This is masked shift. */
19256 : 667 : if (!tree_fits_uhwi_p (args[n_args - 1])
19257 : 667 : || TREE_SIDE_EFFECTS (args[n_args - 2]))
19258 : : break;
19259 : 667 : mask = tree_to_uhwi (args[n_args - 1]);
19260 : 667 : unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19261 : 667 : mask |= HOST_WIDE_INT_M1U << elems;
19262 : 667 : if (mask != HOST_WIDE_INT_M1U
19263 : 556 : && TREE_CODE (args[n_args - 2]) != VECTOR_CST)
19264 : : break;
19265 : 633 : if (mask == (HOST_WIDE_INT_M1U << elems))
19266 : : return args[n_args - 2];
19267 : : }
19268 : 879 : if (is_vshift && TREE_CODE (args[1]) != VECTOR_CST)
19269 : : break;
19270 : 879 : if (tree tem = (is_vshift ? integer_one_node
19271 : 879 : : ix86_vector_shift_count (args[1])))
19272 : : {
19273 : 558 : unsigned HOST_WIDE_INT count = tree_to_uhwi (tem);
19274 : 558 : unsigned HOST_WIDE_INT prec
19275 : 558 : = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0])));
19276 : 558 : if (count == 0 && mask == HOST_WIDE_INT_M1U)
19277 : : return args[0];
19278 : 558 : if (count >= prec)
19279 : : {
19280 : 72 : if (rcode == ASHIFTRT)
19281 : 27 : count = prec - 1;
19282 : 45 : else if (mask == HOST_WIDE_INT_M1U)
19283 : 3 : return build_zero_cst (TREE_TYPE (args[0]));
19284 : : }
19285 : 555 : tree countt = NULL_TREE;
19286 : 555 : if (!is_vshift)
19287 : : {
19288 : 377 : if (count >= prec)
19289 : 42 : countt = integer_zero_node;
19290 : : else
19291 : 335 : countt = build_int_cst (integer_type_node, count);
19292 : : }
19293 : 555 : tree_vector_builder builder;
19294 : 555 : if (mask != HOST_WIDE_INT_M1U || is_vshift)
19295 : 392 : builder.new_vector (TREE_TYPE (args[0]),
19296 : 784 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])),
19297 : : 1);
19298 : : else
19299 : 163 : builder.new_unary_operation (TREE_TYPE (args[0]), args[0],
19300 : : false);
19301 : 555 : unsigned int cnt = builder.encoded_nelts ();
19302 : 5967 : for (unsigned int i = 0; i < cnt; ++i)
19303 : : {
19304 : 5412 : tree elt = VECTOR_CST_ELT (args[0], i);
19305 : 5412 : if (TREE_CODE (elt) != INTEGER_CST || TREE_OVERFLOW (elt))
19306 : 0 : return NULL_TREE;
19307 : 5412 : tree type = TREE_TYPE (elt);
19308 : 5412 : if (rcode == LSHIFTRT)
19309 : 2040 : elt = fold_convert (unsigned_type_for (type), elt);
19310 : 5412 : if (is_vshift)
19311 : : {
19312 : 1846 : countt = VECTOR_CST_ELT (args[1], i);
19313 : 1846 : if (TREE_CODE (countt) != INTEGER_CST
19314 : 1846 : || TREE_OVERFLOW (countt))
19315 : : return NULL_TREE;
19316 : 1846 : if (wi::neg_p (wi::to_wide (countt))
19317 : 3610 : || wi::to_widest (countt) >= prec)
19318 : : {
19319 : 325 : if (rcode == ASHIFTRT)
19320 : 108 : countt = build_int_cst (TREE_TYPE (countt),
19321 : 108 : prec - 1);
19322 : : else
19323 : : {
19324 : 217 : elt = build_zero_cst (TREE_TYPE (elt));
19325 : 217 : countt = build_zero_cst (TREE_TYPE (countt));
19326 : : }
19327 : : }
19328 : : }
19329 : 3566 : else if (count >= prec)
19330 : 504 : elt = build_zero_cst (TREE_TYPE (elt));
19331 : 8950 : elt = const_binop (rcode == ASHIFT
19332 : : ? LSHIFT_EXPR : RSHIFT_EXPR,
19333 : 5412 : TREE_TYPE (elt), elt, countt);
19334 : 5412 : if (!elt || TREE_CODE (elt) != INTEGER_CST)
19335 : : return NULL_TREE;
19336 : 5412 : if (rcode == LSHIFTRT)
19337 : 2040 : elt = fold_convert (type, elt);
19338 : 5412 : if ((mask & (HOST_WIDE_INT_1U << i)) == 0)
19339 : : {
19340 : 1566 : elt = VECTOR_CST_ELT (args[n_args - 2], i);
19341 : 1566 : if (TREE_CODE (elt) != INTEGER_CST
19342 : 1566 : || TREE_OVERFLOW (elt))
19343 : : return NULL_TREE;
19344 : : }
19345 : 5412 : builder.quick_push (elt);
19346 : : }
19347 : 555 : return builder.build ();
19348 : 555 : }
19349 : : break;
19350 : :
19351 : 31764 : case IX86_BUILTIN_MINSS:
19352 : 31764 : case IX86_BUILTIN_MINSH_MASK:
19353 : 31764 : tcode = LT_EXPR;
19354 : 31764 : is_scalar = true;
19355 : 31764 : goto do_minmax;
19356 : :
19357 : 31764 : case IX86_BUILTIN_MAXSS:
19358 : 31764 : case IX86_BUILTIN_MAXSH_MASK:
19359 : 31764 : tcode = GT_EXPR;
19360 : 31764 : is_scalar = true;
19361 : 31764 : goto do_minmax;
19362 : :
19363 : 339687 : case IX86_BUILTIN_MINPS:
19364 : 339687 : case IX86_BUILTIN_MINPD:
19365 : 339687 : case IX86_BUILTIN_MINPS256:
19366 : 339687 : case IX86_BUILTIN_MINPD256:
19367 : 339687 : case IX86_BUILTIN_MINPS512:
19368 : 339687 : case IX86_BUILTIN_MINPD512:
19369 : 339687 : case IX86_BUILTIN_MINPS128_MASK:
19370 : 339687 : case IX86_BUILTIN_MINPD128_MASK:
19371 : 339687 : case IX86_BUILTIN_MINPS256_MASK:
19372 : 339687 : case IX86_BUILTIN_MINPD256_MASK:
19373 : 339687 : case IX86_BUILTIN_MINPH128_MASK:
19374 : 339687 : case IX86_BUILTIN_MINPH256_MASK:
19375 : 339687 : case IX86_BUILTIN_MINPH512_MASK:
19376 : 339687 : tcode = LT_EXPR;
19377 : 339687 : is_scalar = false;
19378 : 339687 : goto do_minmax;
19379 : :
19380 : : case IX86_BUILTIN_MAXPS:
19381 : : case IX86_BUILTIN_MAXPD:
19382 : : case IX86_BUILTIN_MAXPS256:
19383 : : case IX86_BUILTIN_MAXPD256:
19384 : : case IX86_BUILTIN_MAXPS512:
19385 : : case IX86_BUILTIN_MAXPD512:
19386 : : case IX86_BUILTIN_MAXPS128_MASK:
19387 : : case IX86_BUILTIN_MAXPD128_MASK:
19388 : : case IX86_BUILTIN_MAXPS256_MASK:
19389 : : case IX86_BUILTIN_MAXPD256_MASK:
19390 : : case IX86_BUILTIN_MAXPH128_MASK:
19391 : : case IX86_BUILTIN_MAXPH256_MASK:
19392 : : case IX86_BUILTIN_MAXPH512_MASK:
19393 : : tcode = GT_EXPR;
19394 : : is_scalar = false;
19395 : 742922 : do_minmax:
19396 : 742922 : gcc_assert (n_args >= 2);
19397 : 742922 : if (TREE_CODE (args[0]) != VECTOR_CST
19398 : 76 : || TREE_CODE (args[1]) != VECTOR_CST)
19399 : : break;
19400 : 76 : mask = HOST_WIDE_INT_M1U;
19401 : 76 : if (n_args > 2)
19402 : : {
19403 : 36 : gcc_assert (n_args >= 4);
19404 : : /* This is masked minmax. */
19405 : 36 : if (TREE_CODE (args[3]) != INTEGER_CST
19406 : 36 : || TREE_SIDE_EFFECTS (args[2]))
19407 : : break;
19408 : 36 : mask = TREE_INT_CST_LOW (args[3]);
19409 : 36 : unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19410 : 36 : mask |= HOST_WIDE_INT_M1U << elems;
19411 : 36 : if (mask != HOST_WIDE_INT_M1U
19412 : 32 : && TREE_CODE (args[2]) != VECTOR_CST)
19413 : : break;
19414 : 36 : if (n_args >= 5)
19415 : : {
19416 : 20 : if (!tree_fits_uhwi_p (args[4]))
19417 : : break;
19418 : 20 : if (tree_to_uhwi (args[4]) != 4
19419 : 0 : && tree_to_uhwi (args[4]) != 8)
19420 : : break;
19421 : : }
19422 : 36 : if (mask == (HOST_WIDE_INT_M1U << elems))
19423 : : return args[2];
19424 : : }
19425 : : /* Punt on NaNs, unless exceptions are disabled. */
19426 : 76 : if (HONOR_NANS (args[0])
19427 : 76 : && (n_args < 5 || tree_to_uhwi (args[4]) != 8))
19428 : 184 : for (int i = 0; i < 2; ++i)
19429 : : {
19430 : 134 : unsigned count = vector_cst_encoded_nelts (args[i]);
19431 : 957 : for (unsigned j = 0; j < count; ++j)
19432 : 849 : if (tree_expr_nan_p (VECTOR_CST_ENCODED_ELT (args[i], j)))
19433 : : return NULL_TREE;
19434 : : }
19435 : 50 : {
19436 : 50 : tree res = const_binop (tcode,
19437 : 50 : truth_type_for (TREE_TYPE (args[0])),
19438 : : args[0], args[1]);
19439 : 50 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19440 : : break;
19441 : 50 : res = fold_ternary (VEC_COND_EXPR, TREE_TYPE (args[0]), res,
19442 : : args[0], args[1]);
19443 : 50 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19444 : : break;
19445 : 50 : if (mask != HOST_WIDE_INT_M1U)
19446 : : {
19447 : 32 : unsigned nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19448 : 32 : vec_perm_builder sel (nelts, nelts, 1);
19449 : 328 : for (unsigned int i = 0; i < nelts; i++)
19450 : 296 : if (mask & (HOST_WIDE_INT_1U << i))
19451 : 160 : sel.quick_push (i);
19452 : : else
19453 : 136 : sel.quick_push (nelts + i);
19454 : 32 : vec_perm_indices indices (sel, 2, nelts);
19455 : 32 : res = fold_vec_perm (TREE_TYPE (args[0]), res, args[2],
19456 : : indices);
19457 : 32 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19458 : : break;
19459 : 32 : }
19460 : 50 : if (is_scalar)
19461 : : {
19462 : 10 : unsigned nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
19463 : 10 : vec_perm_builder sel (nelts, nelts, 1);
19464 : 10 : sel.quick_push (0);
19465 : 40 : for (unsigned int i = 1; i < nelts; i++)
19466 : 30 : sel.quick_push (nelts + i);
19467 : 10 : vec_perm_indices indices (sel, 2, nelts);
19468 : 10 : res = fold_vec_perm (TREE_TYPE (args[0]), res, args[0],
19469 : : indices);
19470 : 10 : if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST)
19471 : : break;
19472 : 10 : }
19473 : 50 : return res;
19474 : : }
19475 : :
19476 : : default:
19477 : : break;
19478 : : }
19479 : : }
19480 : :
19481 : : #ifdef SUBTARGET_FOLD_BUILTIN
19482 : : return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore);
19483 : : #endif
19484 : :
19485 : : return NULL_TREE;
19486 : : }
19487 : :
19488 : : /* Fold a MD builtin (use ix86_fold_builtin for folding into
19489 : : constant) in GIMPLE. */
19490 : :
19491 : : bool
19492 : 1078455 : ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
19493 : : {
19494 : 1078455 : gimple *stmt = gsi_stmt (*gsi), *g;
19495 : 1078455 : gimple_seq stmts = NULL;
19496 : 1078455 : tree fndecl = gimple_call_fndecl (stmt);
19497 : 1078455 : gcc_checking_assert (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_MD));
19498 : 1078455 : int n_args = gimple_call_num_args (stmt);
19499 : 1078455 : enum ix86_builtins fn_code
19500 : 1078455 : = (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
19501 : 1078455 : tree decl = NULL_TREE;
19502 : 1078455 : tree arg0, arg1, arg2;
19503 : 1078455 : enum rtx_code rcode;
19504 : 1078455 : enum tree_code tcode;
19505 : 1078455 : unsigned HOST_WIDE_INT count;
19506 : 1078455 : bool is_vshift;
19507 : 1078455 : unsigned HOST_WIDE_INT elems;
19508 : 1078455 : location_t loc;
19509 : :
19510 : : /* Don't fold when there's isa mismatch. */
19511 : 1078455 : if (!ix86_check_builtin_isa_match (fn_code, NULL, NULL))
19512 : : return false;
19513 : :
19514 : 1078328 : switch (fn_code)
19515 : : {
19516 : 288 : case IX86_BUILTIN_TZCNT32:
19517 : 288 : decl = builtin_decl_implicit (BUILT_IN_CTZ);
19518 : 288 : goto fold_tzcnt_lzcnt;
19519 : :
19520 : 237 : case IX86_BUILTIN_TZCNT64:
19521 : 237 : decl = builtin_decl_implicit (BUILT_IN_CTZLL);
19522 : 237 : goto fold_tzcnt_lzcnt;
19523 : :
19524 : 215 : case IX86_BUILTIN_LZCNT32:
19525 : 215 : decl = builtin_decl_implicit (BUILT_IN_CLZ);
19526 : 215 : goto fold_tzcnt_lzcnt;
19527 : :
19528 : 224 : case IX86_BUILTIN_LZCNT64:
19529 : 224 : decl = builtin_decl_implicit (BUILT_IN_CLZLL);
19530 : 224 : goto fold_tzcnt_lzcnt;
19531 : :
19532 : 964 : fold_tzcnt_lzcnt:
19533 : 964 : gcc_assert (n_args == 1);
19534 : 964 : arg0 = gimple_call_arg (stmt, 0);
19535 : 964 : if (TREE_CODE (arg0) == SSA_NAME && decl && gimple_call_lhs (stmt))
19536 : : {
19537 : 799 : int prec = TYPE_PRECISION (TREE_TYPE (arg0));
19538 : : /* If arg0 is provably non-zero, optimize into generic
19539 : : __builtin_c[tl]z{,ll} function the middle-end handles
19540 : : better. */
19541 : 799 : if (!expr_not_equal_to (arg0, wi::zero (prec)))
19542 : : return false;
19543 : :
19544 : 9 : loc = gimple_location (stmt);
19545 : 9 : g = gimple_build_call (decl, 1, arg0);
19546 : 9 : gimple_set_location (g, loc);
19547 : 9 : tree lhs = make_ssa_name (integer_type_node);
19548 : 9 : gimple_call_set_lhs (g, lhs);
19549 : 9 : gsi_insert_before (gsi, g, GSI_SAME_STMT);
19550 : 9 : g = gimple_build_assign (gimple_call_lhs (stmt), NOP_EXPR, lhs);
19551 : 9 : gimple_set_location (g, loc);
19552 : 9 : gsi_replace (gsi, g, false);
19553 : 9 : return true;
19554 : : }
19555 : : break;
19556 : :
19557 : 491 : case IX86_BUILTIN_BZHI32:
19558 : 491 : case IX86_BUILTIN_BZHI64:
19559 : 491 : gcc_assert (n_args == 2);
19560 : 491 : arg1 = gimple_call_arg (stmt, 1);
19561 : 491 : if (tree_fits_uhwi_p (arg1) && gimple_call_lhs (stmt))
19562 : : {
19563 : 195 : unsigned int idx = tree_to_uhwi (arg1) & 0xff;
19564 : 195 : arg0 = gimple_call_arg (stmt, 0);
19565 : 195 : if (idx < TYPE_PRECISION (TREE_TYPE (arg0)))
19566 : : break;
19567 : 31 : loc = gimple_location (stmt);
19568 : 31 : g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
19569 : 31 : gimple_set_location (g, loc);
19570 : 31 : gsi_replace (gsi, g, false);
19571 : 31 : return true;
19572 : : }
19573 : : break;
19574 : :
19575 : 502 : case IX86_BUILTIN_PDEP32:
19576 : 502 : case IX86_BUILTIN_PDEP64:
19577 : 502 : case IX86_BUILTIN_PEXT32:
19578 : 502 : case IX86_BUILTIN_PEXT64:
19579 : 502 : gcc_assert (n_args == 2);
19580 : 502 : arg1 = gimple_call_arg (stmt, 1);
19581 : 502 : if (integer_all_onesp (arg1) && gimple_call_lhs (stmt))
19582 : : {
19583 : 4 : loc = gimple_location (stmt);
19584 : 4 : arg0 = gimple_call_arg (stmt, 0);
19585 : 4 : g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
19586 : 4 : gimple_set_location (g, loc);
19587 : 4 : gsi_replace (gsi, g, false);
19588 : 4 : return true;
19589 : : }
19590 : : break;
19591 : :
19592 : 145 : case IX86_BUILTIN_PBLENDVB256:
19593 : 145 : case IX86_BUILTIN_BLENDVPS256:
19594 : 145 : case IX86_BUILTIN_BLENDVPD256:
19595 : : /* pcmpeqb/d/q is under avx2, w/o avx2, it's veclower
19596 : : to scalar operations and not combined back. */
19597 : 145 : if (!TARGET_AVX2)
19598 : : break;
19599 : :
19600 : : /* FALLTHRU. */
19601 : 112 : case IX86_BUILTIN_BLENDVPD:
19602 : : /* blendvpd is under sse4.1 but pcmpgtq is under sse4.2,
19603 : : w/o sse4.2, it's veclowered to scalar operations and
19604 : : not combined back. */
19605 : 112 : if (!TARGET_SSE4_2)
19606 : : break;
19607 : : /* FALLTHRU. */
19608 : 151 : case IX86_BUILTIN_PBLENDVB128:
19609 : 151 : case IX86_BUILTIN_BLENDVPS:
19610 : 151 : gcc_assert (n_args == 3);
19611 : 151 : arg0 = gimple_call_arg (stmt, 0);
19612 : 151 : arg1 = gimple_call_arg (stmt, 1);
19613 : 151 : arg2 = gimple_call_arg (stmt, 2);
19614 : 151 : if (gimple_call_lhs (stmt))
19615 : : {
19616 : 151 : loc = gimple_location (stmt);
19617 : 151 : tree type = TREE_TYPE (arg2);
19618 : 151 : if (VECTOR_FLOAT_TYPE_P (type))
19619 : : {
19620 : 73 : tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode
19621 : 73 : ? intSI_type_node : intDI_type_node;
19622 : 73 : type = get_same_sized_vectype (itype, type);
19623 : : }
19624 : : else
19625 : 78 : type = signed_type_for (type);
19626 : 151 : arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2);
19627 : 151 : tree zero_vec = build_zero_cst (type);
19628 : 151 : tree cmp_type = truth_type_for (type);
19629 : 151 : tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec);
19630 : 151 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
19631 : 151 : g = gimple_build_assign (gimple_call_lhs (stmt),
19632 : : VEC_COND_EXPR, cmp,
19633 : : arg1, arg0);
19634 : 151 : gimple_set_location (g, loc);
19635 : 151 : gsi_replace (gsi, g, false);
19636 : : }
19637 : : else
19638 : 0 : gsi_replace (gsi, gimple_build_nop (), false);
19639 : : return true;
19640 : :
19641 : :
19642 : 16 : case IX86_BUILTIN_PCMPEQB128:
19643 : 16 : case IX86_BUILTIN_PCMPEQW128:
19644 : 16 : case IX86_BUILTIN_PCMPEQD128:
19645 : 16 : case IX86_BUILTIN_PCMPEQQ:
19646 : 16 : case IX86_BUILTIN_PCMPEQB256:
19647 : 16 : case IX86_BUILTIN_PCMPEQW256:
19648 : 16 : case IX86_BUILTIN_PCMPEQD256:
19649 : 16 : case IX86_BUILTIN_PCMPEQQ256:
19650 : 16 : tcode = EQ_EXPR;
19651 : 16 : goto do_cmp;
19652 : :
19653 : : case IX86_BUILTIN_PCMPGTB128:
19654 : : case IX86_BUILTIN_PCMPGTW128:
19655 : : case IX86_BUILTIN_PCMPGTD128:
19656 : : case IX86_BUILTIN_PCMPGTQ:
19657 : : case IX86_BUILTIN_PCMPGTB256:
19658 : : case IX86_BUILTIN_PCMPGTW256:
19659 : : case IX86_BUILTIN_PCMPGTD256:
19660 : : case IX86_BUILTIN_PCMPGTQ256:
19661 : : tcode = GT_EXPR;
19662 : :
19663 : 33 : do_cmp:
19664 : 33 : gcc_assert (n_args == 2);
19665 : 33 : arg0 = gimple_call_arg (stmt, 0);
19666 : 33 : arg1 = gimple_call_arg (stmt, 1);
19667 : 33 : if (gimple_call_lhs (stmt))
19668 : : {
19669 : 32 : loc = gimple_location (stmt);
19670 : 32 : tree type = TREE_TYPE (arg0);
19671 : 32 : tree zero_vec = build_zero_cst (type);
19672 : 32 : tree minus_one_vec = build_minus_one_cst (type);
19673 : 32 : tree cmp_type = truth_type_for (type);
19674 : 32 : tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1);
19675 : 32 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
19676 : 32 : g = gimple_build_assign (gimple_call_lhs (stmt),
19677 : : VEC_COND_EXPR, cmp,
19678 : : minus_one_vec, zero_vec);
19679 : 32 : gimple_set_location (g, loc);
19680 : 32 : gsi_replace (gsi, g, false);
19681 : : }
19682 : : else
19683 : 1 : gsi_replace (gsi, gimple_build_nop (), false);
19684 : : return true;
19685 : :
19686 : 9297 : case IX86_BUILTIN_PSLLD:
19687 : 9297 : case IX86_BUILTIN_PSLLD128:
19688 : 9297 : case IX86_BUILTIN_PSLLD128_MASK:
19689 : 9297 : case IX86_BUILTIN_PSLLD256:
19690 : 9297 : case IX86_BUILTIN_PSLLD256_MASK:
19691 : 9297 : case IX86_BUILTIN_PSLLD512:
19692 : 9297 : case IX86_BUILTIN_PSLLDI:
19693 : 9297 : case IX86_BUILTIN_PSLLDI128:
19694 : 9297 : case IX86_BUILTIN_PSLLDI128_MASK:
19695 : 9297 : case IX86_BUILTIN_PSLLDI256:
19696 : 9297 : case IX86_BUILTIN_PSLLDI256_MASK:
19697 : 9297 : case IX86_BUILTIN_PSLLDI512:
19698 : 9297 : case IX86_BUILTIN_PSLLQ:
19699 : 9297 : case IX86_BUILTIN_PSLLQ128:
19700 : 9297 : case IX86_BUILTIN_PSLLQ128_MASK:
19701 : 9297 : case IX86_BUILTIN_PSLLQ256:
19702 : 9297 : case IX86_BUILTIN_PSLLQ256_MASK:
19703 : 9297 : case IX86_BUILTIN_PSLLQ512:
19704 : 9297 : case IX86_BUILTIN_PSLLQI:
19705 : 9297 : case IX86_BUILTIN_PSLLQI128:
19706 : 9297 : case IX86_BUILTIN_PSLLQI128_MASK:
19707 : 9297 : case IX86_BUILTIN_PSLLQI256:
19708 : 9297 : case IX86_BUILTIN_PSLLQI256_MASK:
19709 : 9297 : case IX86_BUILTIN_PSLLQI512:
19710 : 9297 : case IX86_BUILTIN_PSLLW:
19711 : 9297 : case IX86_BUILTIN_PSLLW128:
19712 : 9297 : case IX86_BUILTIN_PSLLW128_MASK:
19713 : 9297 : case IX86_BUILTIN_PSLLW256:
19714 : 9297 : case IX86_BUILTIN_PSLLW256_MASK:
19715 : 9297 : case IX86_BUILTIN_PSLLW512_MASK:
19716 : 9297 : case IX86_BUILTIN_PSLLWI:
19717 : 9297 : case IX86_BUILTIN_PSLLWI128:
19718 : 9297 : case IX86_BUILTIN_PSLLWI128_MASK:
19719 : 9297 : case IX86_BUILTIN_PSLLWI256:
19720 : 9297 : case IX86_BUILTIN_PSLLWI256_MASK:
19721 : 9297 : case IX86_BUILTIN_PSLLWI512_MASK:
19722 : 9297 : rcode = ASHIFT;
19723 : 9297 : is_vshift = false;
19724 : 9297 : goto do_shift;
19725 : 6495 : case IX86_BUILTIN_PSRAD:
19726 : 6495 : case IX86_BUILTIN_PSRAD128:
19727 : 6495 : case IX86_BUILTIN_PSRAD128_MASK:
19728 : 6495 : case IX86_BUILTIN_PSRAD256:
19729 : 6495 : case IX86_BUILTIN_PSRAD256_MASK:
19730 : 6495 : case IX86_BUILTIN_PSRAD512:
19731 : 6495 : case IX86_BUILTIN_PSRADI:
19732 : 6495 : case IX86_BUILTIN_PSRADI128:
19733 : 6495 : case IX86_BUILTIN_PSRADI128_MASK:
19734 : 6495 : case IX86_BUILTIN_PSRADI256:
19735 : 6495 : case IX86_BUILTIN_PSRADI256_MASK:
19736 : 6495 : case IX86_BUILTIN_PSRADI512:
19737 : 6495 : case IX86_BUILTIN_PSRAQ128_MASK:
19738 : 6495 : case IX86_BUILTIN_PSRAQ256_MASK:
19739 : 6495 : case IX86_BUILTIN_PSRAQ512:
19740 : 6495 : case IX86_BUILTIN_PSRAQI128_MASK:
19741 : 6495 : case IX86_BUILTIN_PSRAQI256_MASK:
19742 : 6495 : case IX86_BUILTIN_PSRAQI512:
19743 : 6495 : case IX86_BUILTIN_PSRAW:
19744 : 6495 : case IX86_BUILTIN_PSRAW128:
19745 : 6495 : case IX86_BUILTIN_PSRAW128_MASK:
19746 : 6495 : case IX86_BUILTIN_PSRAW256:
19747 : 6495 : case IX86_BUILTIN_PSRAW256_MASK:
19748 : 6495 : case IX86_BUILTIN_PSRAW512:
19749 : 6495 : case IX86_BUILTIN_PSRAWI:
19750 : 6495 : case IX86_BUILTIN_PSRAWI128:
19751 : 6495 : case IX86_BUILTIN_PSRAWI128_MASK:
19752 : 6495 : case IX86_BUILTIN_PSRAWI256:
19753 : 6495 : case IX86_BUILTIN_PSRAWI256_MASK:
19754 : 6495 : case IX86_BUILTIN_PSRAWI512:
19755 : 6495 : rcode = ASHIFTRT;
19756 : 6495 : is_vshift = false;
19757 : 6495 : goto do_shift;
19758 : 7950 : case IX86_BUILTIN_PSRLD:
19759 : 7950 : case IX86_BUILTIN_PSRLD128:
19760 : 7950 : case IX86_BUILTIN_PSRLD128_MASK:
19761 : 7950 : case IX86_BUILTIN_PSRLD256:
19762 : 7950 : case IX86_BUILTIN_PSRLD256_MASK:
19763 : 7950 : case IX86_BUILTIN_PSRLD512:
19764 : 7950 : case IX86_BUILTIN_PSRLDI:
19765 : 7950 : case IX86_BUILTIN_PSRLDI128:
19766 : 7950 : case IX86_BUILTIN_PSRLDI128_MASK:
19767 : 7950 : case IX86_BUILTIN_PSRLDI256:
19768 : 7950 : case IX86_BUILTIN_PSRLDI256_MASK:
19769 : 7950 : case IX86_BUILTIN_PSRLDI512:
19770 : 7950 : case IX86_BUILTIN_PSRLQ:
19771 : 7950 : case IX86_BUILTIN_PSRLQ128:
19772 : 7950 : case IX86_BUILTIN_PSRLQ128_MASK:
19773 : 7950 : case IX86_BUILTIN_PSRLQ256:
19774 : 7950 : case IX86_BUILTIN_PSRLQ256_MASK:
19775 : 7950 : case IX86_BUILTIN_PSRLQ512:
19776 : 7950 : case IX86_BUILTIN_PSRLQI:
19777 : 7950 : case IX86_BUILTIN_PSRLQI128:
19778 : 7950 : case IX86_BUILTIN_PSRLQI128_MASK:
19779 : 7950 : case IX86_BUILTIN_PSRLQI256:
19780 : 7950 : case IX86_BUILTIN_PSRLQI256_MASK:
19781 : 7950 : case IX86_BUILTIN_PSRLQI512:
19782 : 7950 : case IX86_BUILTIN_PSRLW:
19783 : 7950 : case IX86_BUILTIN_PSRLW128:
19784 : 7950 : case IX86_BUILTIN_PSRLW128_MASK:
19785 : 7950 : case IX86_BUILTIN_PSRLW256:
19786 : 7950 : case IX86_BUILTIN_PSRLW256_MASK:
19787 : 7950 : case IX86_BUILTIN_PSRLW512:
19788 : 7950 : case IX86_BUILTIN_PSRLWI:
19789 : 7950 : case IX86_BUILTIN_PSRLWI128:
19790 : 7950 : case IX86_BUILTIN_PSRLWI128_MASK:
19791 : 7950 : case IX86_BUILTIN_PSRLWI256:
19792 : 7950 : case IX86_BUILTIN_PSRLWI256_MASK:
19793 : 7950 : case IX86_BUILTIN_PSRLWI512:
19794 : 7950 : rcode = LSHIFTRT;
19795 : 7950 : is_vshift = false;
19796 : 7950 : goto do_shift;
19797 : 2384 : case IX86_BUILTIN_PSLLVV16HI:
19798 : 2384 : case IX86_BUILTIN_PSLLVV16SI:
19799 : 2384 : case IX86_BUILTIN_PSLLVV2DI:
19800 : 2384 : case IX86_BUILTIN_PSLLVV2DI_MASK:
19801 : 2384 : case IX86_BUILTIN_PSLLVV32HI:
19802 : 2384 : case IX86_BUILTIN_PSLLVV4DI:
19803 : 2384 : case IX86_BUILTIN_PSLLVV4DI_MASK:
19804 : 2384 : case IX86_BUILTIN_PSLLVV4SI:
19805 : 2384 : case IX86_BUILTIN_PSLLVV4SI_MASK:
19806 : 2384 : case IX86_BUILTIN_PSLLVV8DI:
19807 : 2384 : case IX86_BUILTIN_PSLLVV8HI:
19808 : 2384 : case IX86_BUILTIN_PSLLVV8SI:
19809 : 2384 : case IX86_BUILTIN_PSLLVV8SI_MASK:
19810 : 2384 : rcode = ASHIFT;
19811 : 2384 : is_vshift = true;
19812 : 2384 : goto do_shift;
19813 : 2341 : case IX86_BUILTIN_PSRAVQ128:
19814 : 2341 : case IX86_BUILTIN_PSRAVQ256:
19815 : 2341 : case IX86_BUILTIN_PSRAVV16HI:
19816 : 2341 : case IX86_BUILTIN_PSRAVV16SI:
19817 : 2341 : case IX86_BUILTIN_PSRAVV32HI:
19818 : 2341 : case IX86_BUILTIN_PSRAVV4SI:
19819 : 2341 : case IX86_BUILTIN_PSRAVV4SI_MASK:
19820 : 2341 : case IX86_BUILTIN_PSRAVV8DI:
19821 : 2341 : case IX86_BUILTIN_PSRAVV8HI:
19822 : 2341 : case IX86_BUILTIN_PSRAVV8SI:
19823 : 2341 : case IX86_BUILTIN_PSRAVV8SI_MASK:
19824 : 2341 : rcode = ASHIFTRT;
19825 : 2341 : is_vshift = true;
19826 : 2341 : goto do_shift;
19827 : 2380 : case IX86_BUILTIN_PSRLVV16HI:
19828 : 2380 : case IX86_BUILTIN_PSRLVV16SI:
19829 : 2380 : case IX86_BUILTIN_PSRLVV2DI:
19830 : 2380 : case IX86_BUILTIN_PSRLVV2DI_MASK:
19831 : 2380 : case IX86_BUILTIN_PSRLVV32HI:
19832 : 2380 : case IX86_BUILTIN_PSRLVV4DI:
19833 : 2380 : case IX86_BUILTIN_PSRLVV4DI_MASK:
19834 : 2380 : case IX86_BUILTIN_PSRLVV4SI:
19835 : 2380 : case IX86_BUILTIN_PSRLVV4SI_MASK:
19836 : 2380 : case IX86_BUILTIN_PSRLVV8DI:
19837 : 2380 : case IX86_BUILTIN_PSRLVV8HI:
19838 : 2380 : case IX86_BUILTIN_PSRLVV8SI:
19839 : 2380 : case IX86_BUILTIN_PSRLVV8SI_MASK:
19840 : 2380 : rcode = LSHIFTRT;
19841 : 2380 : is_vshift = true;
19842 : 2380 : goto do_shift;
19843 : :
19844 : 30847 : do_shift:
19845 : 30847 : gcc_assert (n_args >= 2);
19846 : 30847 : if (!gimple_call_lhs (stmt))
19847 : : {
19848 : 1 : gsi_replace (gsi, gimple_build_nop (), false);
19849 : 1 : return true;
19850 : : }
19851 : 30846 : arg0 = gimple_call_arg (stmt, 0);
19852 : 30846 : arg1 = gimple_call_arg (stmt, 1);
19853 : 30846 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
19854 : : /* For masked shift, only optimize if the mask is all ones. */
19855 : 30846 : if (n_args > 2
19856 : 30846 : && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1)))
19857 : : break;
19858 : 16081 : if (is_vshift)
19859 : : {
19860 : 2640 : if (TREE_CODE (arg1) != VECTOR_CST)
19861 : : break;
19862 : 69 : count = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0)));
19863 : 69 : if (integer_zerop (arg1))
19864 : 27 : count = 0;
19865 : 42 : else if (rcode == ASHIFTRT)
19866 : : break;
19867 : : else
19868 : 230 : for (unsigned int i = 0; i < VECTOR_CST_NELTS (arg1); ++i)
19869 : : {
19870 : 212 : tree elt = VECTOR_CST_ELT (arg1, i);
19871 : 212 : if (!wi::neg_p (wi::to_wide (elt))
19872 : 375 : && wi::to_widest (elt) < count)
19873 : 16 : return false;
19874 : : }
19875 : : }
19876 : : else
19877 : : {
19878 : 13441 : arg1 = ix86_vector_shift_count (arg1);
19879 : 13441 : if (!arg1)
19880 : : break;
19881 : 5608 : count = tree_to_uhwi (arg1);
19882 : : }
19883 : 5653 : if (count == 0)
19884 : : {
19885 : : /* Just return the first argument for shift by 0. */
19886 : 93 : loc = gimple_location (stmt);
19887 : 93 : g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
19888 : 93 : gimple_set_location (g, loc);
19889 : 93 : gsi_replace (gsi, g, false);
19890 : 93 : return true;
19891 : : }
19892 : 5560 : if (rcode != ASHIFTRT
19893 : 5560 : && count >= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0))))
19894 : : {
19895 : : /* For shift counts equal or greater than precision, except for
19896 : : arithmetic right shift the result is zero. */
19897 : 78 : loc = gimple_location (stmt);
19898 : 78 : g = gimple_build_assign (gimple_call_lhs (stmt),
19899 : 78 : build_zero_cst (TREE_TYPE (arg0)));
19900 : 78 : gimple_set_location (g, loc);
19901 : 78 : gsi_replace (gsi, g, false);
19902 : 78 : return true;
19903 : : }
19904 : : break;
19905 : :
19906 : 531 : case IX86_BUILTIN_SHUFPD512:
19907 : 531 : case IX86_BUILTIN_SHUFPS512:
19908 : 531 : case IX86_BUILTIN_SHUFPD:
19909 : 531 : case IX86_BUILTIN_SHUFPD256:
19910 : 531 : case IX86_BUILTIN_SHUFPS:
19911 : 531 : case IX86_BUILTIN_SHUFPS256:
19912 : 531 : arg0 = gimple_call_arg (stmt, 0);
19913 : 531 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
19914 : : /* This is masked shuffle. Only optimize if the mask is all ones. */
19915 : 531 : if (n_args > 3
19916 : 895 : && !ix86_masked_all_ones (elems,
19917 : 364 : gimple_call_arg (stmt, n_args - 1)))
19918 : : break;
19919 : 203 : arg2 = gimple_call_arg (stmt, 2);
19920 : 203 : if (TREE_CODE (arg2) == INTEGER_CST && gimple_call_lhs (stmt))
19921 : : {
19922 : 146 : unsigned HOST_WIDE_INT shuffle_mask = TREE_INT_CST_LOW (arg2);
19923 : : /* Check valid imm, refer to gcc.target/i386/testimm-10.c. */
19924 : 146 : if (shuffle_mask > 255)
19925 : : return false;
19926 : :
19927 : 144 : machine_mode imode = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (arg0)));
19928 : 144 : loc = gimple_location (stmt);
19929 : 144 : tree itype = (imode == E_DFmode
19930 : 144 : ? long_long_integer_type_node : integer_type_node);
19931 : 144 : tree vtype = build_vector_type (itype, elems);
19932 : 144 : tree_vector_builder elts (vtype, elems, 1);
19933 : :
19934 : :
19935 : : /* Transform integer shuffle_mask to vector perm_mask which
19936 : : is used by vec_perm_expr, refer to shuflp[sd]256/512 in sse.md. */
19937 : 840 : for (unsigned i = 0; i != elems; i++)
19938 : : {
19939 : 696 : unsigned sel_idx;
19940 : : /* Imm[1:0](if VL > 128, then use Imm[3:2],Imm[5:4],Imm[7:6])
19941 : : provide 2 select constrols for each element of the
19942 : : destination. */
19943 : 696 : if (imode == E_DFmode)
19944 : 240 : sel_idx = (i & 1) * elems + (i & ~1)
19945 : 240 : + ((shuffle_mask >> i) & 1);
19946 : : else
19947 : : {
19948 : : /* Imm[7:0](if VL > 128, also use Imm[7:0]) provide 4 select
19949 : : controls for each element of the destination. */
19950 : 456 : unsigned j = i % 4;
19951 : 456 : sel_idx = ((i >> 1) & 1) * elems + (i & ~3)
19952 : 456 : + ((shuffle_mask >> 2 * j) & 3);
19953 : : }
19954 : 696 : elts.quick_push (build_int_cst (itype, sel_idx));
19955 : : }
19956 : :
19957 : 144 : tree perm_mask = elts.build ();
19958 : 144 : arg1 = gimple_call_arg (stmt, 1);
19959 : 144 : g = gimple_build_assign (gimple_call_lhs (stmt),
19960 : : VEC_PERM_EXPR,
19961 : : arg0, arg1, perm_mask);
19962 : 144 : gimple_set_location (g, loc);
19963 : 144 : gsi_replace (gsi, g, false);
19964 : 144 : return true;
19965 : 144 : }
19966 : : // Do not error yet, the constant could be propagated later?
19967 : : break;
19968 : :
19969 : 48 : case IX86_BUILTIN_PABSB:
19970 : 48 : case IX86_BUILTIN_PABSW:
19971 : 48 : case IX86_BUILTIN_PABSD:
19972 : : /* 64-bit vector abs<mode>2 is only supported under TARGET_MMX_WITH_SSE. */
19973 : 48 : if (!TARGET_MMX_WITH_SSE)
19974 : : break;
19975 : : /* FALLTHRU. */
19976 : 2190 : case IX86_BUILTIN_PABSB128:
19977 : 2190 : case IX86_BUILTIN_PABSB256:
19978 : 2190 : case IX86_BUILTIN_PABSB512:
19979 : 2190 : case IX86_BUILTIN_PABSW128:
19980 : 2190 : case IX86_BUILTIN_PABSW256:
19981 : 2190 : case IX86_BUILTIN_PABSW512:
19982 : 2190 : case IX86_BUILTIN_PABSD128:
19983 : 2190 : case IX86_BUILTIN_PABSD256:
19984 : 2190 : case IX86_BUILTIN_PABSD512:
19985 : 2190 : case IX86_BUILTIN_PABSQ128:
19986 : 2190 : case IX86_BUILTIN_PABSQ256:
19987 : 2190 : case IX86_BUILTIN_PABSQ512:
19988 : 2190 : case IX86_BUILTIN_PABSB128_MASK:
19989 : 2190 : case IX86_BUILTIN_PABSB256_MASK:
19990 : 2190 : case IX86_BUILTIN_PABSW128_MASK:
19991 : 2190 : case IX86_BUILTIN_PABSW256_MASK:
19992 : 2190 : case IX86_BUILTIN_PABSD128_MASK:
19993 : 2190 : case IX86_BUILTIN_PABSD256_MASK:
19994 : 2190 : gcc_assert (n_args >= 1);
19995 : 2190 : if (!gimple_call_lhs (stmt))
19996 : : {
19997 : 1 : gsi_replace (gsi, gimple_build_nop (), false);
19998 : 1 : return true;
19999 : : }
20000 : 2189 : arg0 = gimple_call_arg (stmt, 0);
20001 : 2189 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
20002 : : /* For masked ABS, only optimize if the mask is all ones. */
20003 : 2189 : if (n_args > 1
20004 : 2189 : && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1)))
20005 : : break;
20006 : 229 : {
20007 : 229 : tree utype, ures, vce;
20008 : 229 : utype = unsigned_type_for (TREE_TYPE (arg0));
20009 : : /* PABSB/W/D/Q store the unsigned result in dst, use ABSU_EXPR
20010 : : instead of ABS_EXPR to hanlde overflow case(TYPE_MIN). */
20011 : 229 : ures = gimple_build (&stmts, ABSU_EXPR, utype, arg0);
20012 : 229 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
20013 : 229 : loc = gimple_location (stmt);
20014 : 229 : vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg0), ures);
20015 : 229 : g = gimple_build_assign (gimple_call_lhs (stmt),
20016 : : VIEW_CONVERT_EXPR, vce);
20017 : 229 : gsi_replace (gsi, g, false);
20018 : : }
20019 : 229 : return true;
20020 : :
20021 : 2225 : case IX86_BUILTIN_MINPS:
20022 : 2225 : case IX86_BUILTIN_MINPD:
20023 : 2225 : case IX86_BUILTIN_MINPS256:
20024 : 2225 : case IX86_BUILTIN_MINPD256:
20025 : 2225 : case IX86_BUILTIN_MINPS512:
20026 : 2225 : case IX86_BUILTIN_MINPD512:
20027 : 2225 : case IX86_BUILTIN_MINPS128_MASK:
20028 : 2225 : case IX86_BUILTIN_MINPD128_MASK:
20029 : 2225 : case IX86_BUILTIN_MINPS256_MASK:
20030 : 2225 : case IX86_BUILTIN_MINPD256_MASK:
20031 : 2225 : case IX86_BUILTIN_MINPH128_MASK:
20032 : 2225 : case IX86_BUILTIN_MINPH256_MASK:
20033 : 2225 : case IX86_BUILTIN_MINPH512_MASK:
20034 : 2225 : tcode = LT_EXPR;
20035 : 2225 : goto do_minmax;
20036 : :
20037 : : case IX86_BUILTIN_MAXPS:
20038 : : case IX86_BUILTIN_MAXPD:
20039 : : case IX86_BUILTIN_MAXPS256:
20040 : : case IX86_BUILTIN_MAXPD256:
20041 : : case IX86_BUILTIN_MAXPS512:
20042 : : case IX86_BUILTIN_MAXPD512:
20043 : : case IX86_BUILTIN_MAXPS128_MASK:
20044 : : case IX86_BUILTIN_MAXPD128_MASK:
20045 : : case IX86_BUILTIN_MAXPS256_MASK:
20046 : : case IX86_BUILTIN_MAXPD256_MASK:
20047 : : case IX86_BUILTIN_MAXPH128_MASK:
20048 : : case IX86_BUILTIN_MAXPH256_MASK:
20049 : : case IX86_BUILTIN_MAXPH512_MASK:
20050 : : tcode = GT_EXPR;
20051 : 4435 : do_minmax:
20052 : 4435 : gcc_assert (n_args >= 2);
20053 : : /* Without SSE4.1 we often aren't able to pattern match it back to the
20054 : : desired instruction. */
20055 : 4435 : if (!gimple_call_lhs (stmt) || !optimize || !TARGET_SSE4_1)
20056 : : break;
20057 : 3865 : arg0 = gimple_call_arg (stmt, 0);
20058 : 3865 : arg1 = gimple_call_arg (stmt, 1);
20059 : 3865 : elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
20060 : : /* For masked minmax, only optimize if the mask is all ones. */
20061 : 3865 : if (n_args > 2
20062 : 3865 : && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, 3)))
20063 : : break;
20064 : 647 : if (n_args >= 5)
20065 : : {
20066 : 436 : tree arg4 = gimple_call_arg (stmt, 4);
20067 : 436 : if (!tree_fits_uhwi_p (arg4))
20068 : : break;
20069 : 424 : if (tree_to_uhwi (arg4) == 4)
20070 : : /* Ok. */;
20071 : 416 : else if (tree_to_uhwi (arg4) != 8)
20072 : : /* Invalid round argument. */
20073 : : break;
20074 : 416 : else if (HONOR_NANS (arg0))
20075 : : /* Lowering to comparison would raise exceptions which
20076 : : shouldn't be raised. */
20077 : : break;
20078 : : }
20079 : 219 : {
20080 : 219 : tree type = truth_type_for (TREE_TYPE (arg0));
20081 : 219 : tree cmpres = gimple_build (&stmts, tcode, type, arg0, arg1);
20082 : 219 : gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
20083 : 219 : g = gimple_build_assign (gimple_call_lhs (stmt),
20084 : : VEC_COND_EXPR, cmpres, arg0, arg1);
20085 : 219 : gsi_replace (gsi, g, false);
20086 : : }
20087 : 219 : return true;
20088 : :
20089 : : default:
20090 : : break;
20091 : : }
20092 : :
20093 : : return false;
20094 : : }
20095 : :
20096 : : /* Handler for an SVML-style interface to
20097 : : a library with vectorized intrinsics. */
20098 : :
20099 : : tree
20100 : 10 : ix86_veclibabi_svml (combined_fn fn, tree type_out, tree type_in)
20101 : : {
20102 : 10 : char name[20];
20103 : 10 : tree fntype, new_fndecl, args;
20104 : 10 : unsigned arity;
20105 : 10 : const char *bname;
20106 : 10 : machine_mode el_mode, in_mode;
20107 : 10 : int n, in_n;
20108 : :
20109 : : /* The SVML is suitable for unsafe math only. */
20110 : 10 : if (!flag_unsafe_math_optimizations)
20111 : : return NULL_TREE;
20112 : :
20113 : 10 : el_mode = TYPE_MODE (TREE_TYPE (type_out));
20114 : 10 : n = TYPE_VECTOR_SUBPARTS (type_out);
20115 : 10 : in_mode = TYPE_MODE (TREE_TYPE (type_in));
20116 : 10 : in_n = TYPE_VECTOR_SUBPARTS (type_in);
20117 : 10 : if (el_mode != in_mode
20118 : 10 : || n != in_n)
20119 : : return NULL_TREE;
20120 : :
20121 : 10 : switch (fn)
20122 : : {
20123 : 10 : CASE_CFN_EXP:
20124 : 10 : CASE_CFN_LOG:
20125 : 10 : CASE_CFN_LOG10:
20126 : 10 : CASE_CFN_POW:
20127 : 10 : CASE_CFN_TANH:
20128 : 10 : CASE_CFN_TAN:
20129 : 10 : CASE_CFN_ATAN:
20130 : 10 : CASE_CFN_ATAN2:
20131 : 10 : CASE_CFN_ATANH:
20132 : 10 : CASE_CFN_CBRT:
20133 : 10 : CASE_CFN_SINH:
20134 : 10 : CASE_CFN_SIN:
20135 : 10 : CASE_CFN_ASINH:
20136 : 10 : CASE_CFN_ASIN:
20137 : 10 : CASE_CFN_COSH:
20138 : 10 : CASE_CFN_COS:
20139 : 10 : CASE_CFN_ACOSH:
20140 : 10 : CASE_CFN_ACOS:
20141 : 10 : if ((el_mode != DFmode || n != 2)
20142 : 8 : && (el_mode != SFmode || n != 4))
20143 : : return NULL_TREE;
20144 : 6 : break;
20145 : :
20146 : : default:
20147 : : return NULL_TREE;
20148 : : }
20149 : :
20150 : 6 : tree fndecl = mathfn_built_in (el_mode == DFmode
20151 : : ? double_type_node : float_type_node, fn);
20152 : 6 : bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
20153 : :
20154 : 6 : if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOGF)
20155 : 2 : strcpy (name, "vmlsLn4");
20156 : 4 : else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOG)
20157 : 0 : strcpy (name, "vmldLn2");
20158 : 4 : else if (n == 4)
20159 : : {
20160 : 2 : sprintf (name, "vmls%s", bname+10);
20161 : 2 : name[strlen (name)-1] = '4';
20162 : : }
20163 : : else
20164 : 2 : sprintf (name, "vmld%s2", bname+10);
20165 : :
20166 : : /* Convert to uppercase. */
20167 : 6 : name[4] &= ~0x20;
20168 : :
20169 : 6 : arity = 0;
20170 : 6 : for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
20171 : 0 : arity++;
20172 : :
20173 : 6 : if (arity == 1)
20174 : 0 : fntype = build_function_type_list (type_out, type_in, NULL);
20175 : : else
20176 : 6 : fntype = build_function_type_list (type_out, type_in, type_in, NULL);
20177 : :
20178 : : /* Build a function declaration for the vectorized function. */
20179 : 6 : new_fndecl = build_decl (BUILTINS_LOCATION,
20180 : : FUNCTION_DECL, get_identifier (name), fntype);
20181 : 6 : TREE_PUBLIC (new_fndecl) = 1;
20182 : 6 : DECL_EXTERNAL (new_fndecl) = 1;
20183 : 6 : DECL_IS_NOVOPS (new_fndecl) = 1;
20184 : 6 : TREE_READONLY (new_fndecl) = 1;
20185 : :
20186 : 6 : return new_fndecl;
20187 : : }
20188 : :
20189 : : /* Handler for an ACML-style interface to
20190 : : a library with vectorized intrinsics. */
20191 : :
20192 : : tree
20193 : 3 : ix86_veclibabi_acml (combined_fn fn, tree type_out, tree type_in)
20194 : : {
20195 : 3 : char name[20] = "__vr.._";
20196 : 3 : tree fntype, new_fndecl, args;
20197 : 3 : unsigned arity;
20198 : 3 : const char *bname;
20199 : 3 : machine_mode el_mode, in_mode;
20200 : 3 : int n, in_n;
20201 : :
20202 : : /* The ACML is 64bits only and suitable for unsafe math only as
20203 : : it does not correctly support parts of IEEE with the required
20204 : : precision such as denormals. */
20205 : 3 : if (!TARGET_64BIT
20206 : 3 : || !flag_unsafe_math_optimizations)
20207 : : return NULL_TREE;
20208 : :
20209 : 3 : el_mode = TYPE_MODE (TREE_TYPE (type_out));
20210 : 3 : n = TYPE_VECTOR_SUBPARTS (type_out);
20211 : 3 : in_mode = TYPE_MODE (TREE_TYPE (type_in));
20212 : 3 : in_n = TYPE_VECTOR_SUBPARTS (type_in);
20213 : 3 : if (el_mode != in_mode
20214 : 3 : || n != in_n)
20215 : : return NULL_TREE;
20216 : :
20217 : 3 : switch (fn)
20218 : : {
20219 : 3 : CASE_CFN_SIN:
20220 : 3 : CASE_CFN_COS:
20221 : 3 : CASE_CFN_EXP:
20222 : 3 : CASE_CFN_LOG:
20223 : 3 : CASE_CFN_LOG2:
20224 : 3 : CASE_CFN_LOG10:
20225 : 3 : if (el_mode == DFmode && n == 2)
20226 : : {
20227 : 3 : name[4] = 'd';
20228 : 3 : name[5] = '2';
20229 : : }
20230 : 0 : else if (el_mode == SFmode && n == 4)
20231 : : {
20232 : 0 : name[4] = 's';
20233 : 0 : name[5] = '4';
20234 : : }
20235 : : else
20236 : : return NULL_TREE;
20237 : 3 : break;
20238 : :
20239 : : default:
20240 : : return NULL_TREE;
20241 : : }
20242 : :
20243 : 3 : tree fndecl = mathfn_built_in (el_mode == DFmode
20244 : : ? double_type_node : float_type_node, fn);
20245 : 3 : bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
20246 : 3 : sprintf (name + 7, "%s", bname+10);
20247 : :
20248 : 3 : arity = 0;
20249 : 3 : for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
20250 : 0 : arity++;
20251 : :
20252 : 3 : if (arity == 1)
20253 : 0 : fntype = build_function_type_list (type_out, type_in, NULL);
20254 : : else
20255 : 3 : fntype = build_function_type_list (type_out, type_in, type_in, NULL);
20256 : :
20257 : : /* Build a function declaration for the vectorized function. */
20258 : 3 : new_fndecl = build_decl (BUILTINS_LOCATION,
20259 : : FUNCTION_DECL, get_identifier (name), fntype);
20260 : 3 : TREE_PUBLIC (new_fndecl) = 1;
20261 : 3 : DECL_EXTERNAL (new_fndecl) = 1;
20262 : 3 : DECL_IS_NOVOPS (new_fndecl) = 1;
20263 : 3 : TREE_READONLY (new_fndecl) = 1;
20264 : :
20265 : 3 : return new_fndecl;
20266 : : }
20267 : :
20268 : : /* Handler for an AOCL-LibM-style interface to
20269 : : a library with vectorized intrinsics. */
20270 : :
20271 : : tree
20272 : 220 : ix86_veclibabi_aocl (combined_fn fn, tree type_out, tree type_in)
20273 : : {
20274 : 220 : char name[20] = "amd_vr";
20275 : 220 : int name_len = 6;
20276 : 220 : tree fntype, new_fndecl, args;
20277 : 220 : unsigned arity;
20278 : 220 : const char *bname;
20279 : 220 : machine_mode el_mode, in_mode;
20280 : 220 : int n, in_n;
20281 : :
20282 : : /* AOCL-LibM is 64bits only. It is also only suitable for unsafe math only
20283 : : as it trades off some accuracy for increased performance. */
20284 : 220 : if (!TARGET_64BIT
20285 : 220 : || !flag_unsafe_math_optimizations)
20286 : : return NULL_TREE;
20287 : :
20288 : 220 : el_mode = TYPE_MODE (TREE_TYPE (type_out));
20289 : 220 : n = TYPE_VECTOR_SUBPARTS (type_out);
20290 : 220 : in_mode = TYPE_MODE (TREE_TYPE (type_in));
20291 : 220 : in_n = TYPE_VECTOR_SUBPARTS (type_in);
20292 : 220 : if (el_mode != in_mode
20293 : 220 : || n != in_n)
20294 : : return NULL_TREE;
20295 : :
20296 : 220 : gcc_checking_assert (n > 0);
20297 : :
20298 : : /* Decide whether there exists a function for the combination of FN, the mode
20299 : : and the vector width. Return early if it doesn't. */
20300 : :
20301 : 220 : if (el_mode != DFmode && el_mode != SFmode)
20302 : : return NULL_TREE;
20303 : :
20304 : : /* Supported vector widths for given FN and single/double precision. Zeros
20305 : : are used to fill out unused positions in the arrays. */
20306 : 220 : static const int supported_n[][2][3] = {
20307 : : /* Single prec. , Double prec. */
20308 : : { { 16, 0, 0 }, { 2, 4, 8 } }, /* TAN. */
20309 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* EXP. */
20310 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* EXP2. */
20311 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* LOG. */
20312 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* LOG2. */
20313 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* COS. */
20314 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* SIN. */
20315 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* POW. */
20316 : : { { 4, 8, 16 }, { 2, 4, 8 } }, /* ERF. */
20317 : : { { 4, 8, 16 }, { 2, 8, 0 } }, /* ATAN. */
20318 : : { { 4, 8, 16 }, { 2, 0, 0 } }, /* LOG10. */
20319 : : { { 4, 0, 0 }, { 2, 0, 0 } }, /* EXP10. */
20320 : : { { 4, 0, 0 }, { 2, 0, 0 } }, /* LOG1P. */
20321 : : { { 4, 8, 16 }, { 8, 0, 0 } }, /* ASIN. */
20322 : : { { 4, 16, 0 }, { 0, 0, 0 } }, /* ACOS. */
20323 : : { { 4, 8, 16 }, { 0, 0, 0 } }, /* TANH. */
20324 : : { { 4, 0, 0 }, { 0, 0, 0 } }, /* EXPM1. */
20325 : : { { 4, 8, 0 }, { 0, 0, 0 } }, /* COSH. */
20326 : : };
20327 : :
20328 : : /* We cannot simply index the supported_n array with FN since multiple FNs
20329 : : may correspond to a single operation (see the definitions of these
20330 : : CASE_CFN_* macros). */
20331 : 220 : int i;
20332 : 220 : switch (fn)
20333 : : {
20334 : : CASE_CFN_TAN : i = 0; break;
20335 : 16 : CASE_CFN_EXP : i = 1; break;
20336 : 16 : CASE_CFN_EXP2 : i = 2; break;
20337 : 16 : CASE_CFN_LOG : i = 3; break;
20338 : 16 : CASE_CFN_LOG2 : i = 4; break;
20339 : 16 : CASE_CFN_COS : i = 5; break;
20340 : 16 : CASE_CFN_SIN : i = 6; break;
20341 : 16 : CASE_CFN_POW : i = 7; break;
20342 : 16 : CASE_CFN_ERF : i = 8; break;
20343 : 13 : CASE_CFN_ATAN : i = 9; break;
20344 : 11 : CASE_CFN_LOG10 : i = 10; break;
20345 : 8 : CASE_CFN_EXP10 : i = 11; break;
20346 : 8 : CASE_CFN_LOG1P : i = 12; break;
20347 : 11 : CASE_CFN_ASIN : i = 13; break;
20348 : 7 : CASE_CFN_ACOS : i = 14; break;
20349 : 9 : CASE_CFN_TANH : i = 15; break;
20350 : 7 : CASE_CFN_EXPM1 : i = 16; break;
20351 : 9 : CASE_CFN_COSH : i = 17; break;
20352 : : default: return NULL_TREE;
20353 : : }
20354 : :
20355 : 220 : int j = el_mode == DFmode;
20356 : 220 : bool n_is_supported = false;
20357 : 489 : for (unsigned k = 0; k < 3; k++)
20358 : 470 : if (supported_n[i][j][k] == n)
20359 : : {
20360 : : n_is_supported = true;
20361 : : break;
20362 : : }
20363 : 220 : if (!n_is_supported)
20364 : : return NULL_TREE;
20365 : :
20366 : : /* Append the precision and the vector width to the function name we are
20367 : : constructing. */
20368 : 201 : name[name_len++] = el_mode == DFmode ? 'd' : 's';
20369 : 201 : switch (n)
20370 : : {
20371 : 148 : case 2:
20372 : 148 : case 4:
20373 : 148 : case 8:
20374 : 148 : name[name_len++] = '0' + n;
20375 : 148 : break;
20376 : 53 : case 16:
20377 : 53 : name[name_len++] = '1';
20378 : 53 : name[name_len++] = '6';
20379 : 53 : break;
20380 : 0 : default:
20381 : 0 : gcc_unreachable ();
20382 : : }
20383 : 201 : name[name_len++] = '_';
20384 : :
20385 : : /* Append the operation name (steal it from the name of a builtin). */
20386 : 201 : tree fndecl = mathfn_built_in (el_mode == DFmode
20387 : : ? double_type_node : float_type_node, fn);
20388 : 201 : bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
20389 : 201 : sprintf (name + name_len, "%s", bname + 10);
20390 : :
20391 : 201 : arity = 0;
20392 : 201 : for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
20393 : 0 : arity++;
20394 : :
20395 : 201 : if (arity == 1)
20396 : 0 : fntype = build_function_type_list (type_out, type_in, NULL);
20397 : : else
20398 : 201 : fntype = build_function_type_list (type_out, type_in, type_in, NULL);
20399 : :
20400 : : /* Build a function declaration for the vectorized function. */
20401 : 201 : new_fndecl = build_decl (BUILTINS_LOCATION,
20402 : : FUNCTION_DECL, get_identifier (name), fntype);
20403 : 201 : TREE_PUBLIC (new_fndecl) = 1;
20404 : 201 : DECL_EXTERNAL (new_fndecl) = 1;
20405 : 201 : TREE_READONLY (new_fndecl) = 1;
20406 : :
20407 : 201 : return new_fndecl;
20408 : : }
20409 : :
20410 : : /* Returns a decl of a function that implements scatter store with
20411 : : register type VECTYPE and index type INDEX_TYPE and SCALE.
20412 : : Return NULL_TREE if it is not available. */
20413 : :
20414 : : static tree
20415 : 95232 : ix86_vectorize_builtin_scatter (const_tree vectype,
20416 : : const_tree index_type, int scale)
20417 : : {
20418 : 95232 : bool si;
20419 : 95232 : enum ix86_builtins code;
20420 : :
20421 : 95232 : if (!TARGET_AVX512F)
20422 : : return NULL_TREE;
20423 : :
20424 : 3477 : if (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 2u)
20425 : 6264 : ? !TARGET_USE_SCATTER_2PARTS
20426 : 6264 : : (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 4u)
20427 : 2787 : ? !TARGET_USE_SCATTER_4PARTS
20428 : 1937 : : !TARGET_USE_SCATTER_8PARTS))
20429 : : return NULL_TREE;
20430 : :
20431 : 3477 : if ((TREE_CODE (index_type) != INTEGER_TYPE
20432 : 472 : && !POINTER_TYPE_P (index_type))
20433 : 3949 : || (TYPE_MODE (index_type) != SImode
20434 : 1439 : && TYPE_MODE (index_type) != DImode))
20435 : 0 : return NULL_TREE;
20436 : :
20437 : 3689 : if (TYPE_PRECISION (index_type) > POINTER_SIZE)
20438 : : return NULL_TREE;
20439 : :
20440 : : /* v*scatter* insn sign extends index to pointer mode. */
20441 : 3477 : if (TYPE_PRECISION (index_type) < POINTER_SIZE
20442 : 3477 : && TYPE_UNSIGNED (index_type))
20443 : : return NULL_TREE;
20444 : :
20445 : : /* Scale can be 1, 2, 4 or 8. */
20446 : 3477 : if (scale <= 0
20447 : 3477 : || scale > 8
20448 : 3451 : || (scale & (scale - 1)) != 0)
20449 : : return NULL_TREE;
20450 : :
20451 : 3451 : si = TYPE_MODE (index_type) == SImode;
20452 : 3451 : switch (TYPE_MODE (vectype))
20453 : : {
20454 : 197 : case E_V8DFmode:
20455 : 197 : code = si ? IX86_BUILTIN_SCATTERALTSIV8DF : IX86_BUILTIN_SCATTERDIV8DF;
20456 : : break;
20457 : 125 : case E_V8DImode:
20458 : 125 : code = si ? IX86_BUILTIN_SCATTERALTSIV8DI : IX86_BUILTIN_SCATTERDIV8DI;
20459 : : break;
20460 : 214 : case E_V16SFmode:
20461 : 214 : code = si ? IX86_BUILTIN_SCATTERSIV16SF : IX86_BUILTIN_SCATTERALTDIV16SF;
20462 : : break;
20463 : 244 : case E_V16SImode:
20464 : 244 : code = si ? IX86_BUILTIN_SCATTERSIV16SI : IX86_BUILTIN_SCATTERALTDIV16SI;
20465 : : break;
20466 : 141 : case E_V4DFmode:
20467 : 141 : if (TARGET_AVX512VL)
20468 : 42 : code = si ? IX86_BUILTIN_SCATTERALTSIV4DF : IX86_BUILTIN_SCATTERDIV4DF;
20469 : : else
20470 : : return NULL_TREE;
20471 : : break;
20472 : 127 : case E_V4DImode:
20473 : 127 : if (TARGET_AVX512VL)
20474 : 42 : code = si ? IX86_BUILTIN_SCATTERALTSIV4DI : IX86_BUILTIN_SCATTERDIV4DI;
20475 : : else
20476 : : return NULL_TREE;
20477 : : break;
20478 : 148 : case E_V8SFmode:
20479 : 148 : if (TARGET_AVX512VL)
20480 : 48 : code = si ? IX86_BUILTIN_SCATTERSIV8SF : IX86_BUILTIN_SCATTERALTDIV8SF;
20481 : : else
20482 : : return NULL_TREE;
20483 : : break;
20484 : 228 : case E_V8SImode:
20485 : 228 : if (TARGET_AVX512VL)
20486 : 100 : code = si ? IX86_BUILTIN_SCATTERSIV8SI : IX86_BUILTIN_SCATTERALTDIV8SI;
20487 : : else
20488 : : return NULL_TREE;
20489 : : break;
20490 : 173 : case E_V2DFmode:
20491 : 173 : if (TARGET_AVX512VL)
20492 : 80 : code = si ? IX86_BUILTIN_SCATTERALTSIV2DF : IX86_BUILTIN_SCATTERDIV2DF;
20493 : : else
20494 : : return NULL_TREE;
20495 : : break;
20496 : 159 : case E_V2DImode:
20497 : 159 : if (TARGET_AVX512VL)
20498 : 80 : code = si ? IX86_BUILTIN_SCATTERALTSIV2DI : IX86_BUILTIN_SCATTERDIV2DI;
20499 : : else
20500 : : return NULL_TREE;
20501 : : break;
20502 : 176 : case E_V4SFmode:
20503 : 176 : if (TARGET_AVX512VL)
20504 : 84 : code = si ? IX86_BUILTIN_SCATTERSIV4SF : IX86_BUILTIN_SCATTERALTDIV4SF;
20505 : : else
20506 : : return NULL_TREE;
20507 : : break;
20508 : 260 : case E_V4SImode:
20509 : 260 : if (TARGET_AVX512VL)
20510 : 136 : code = si ? IX86_BUILTIN_SCATTERSIV4SI : IX86_BUILTIN_SCATTERALTDIV4SI;
20511 : : else
20512 : : return NULL_TREE;
20513 : : break;
20514 : : default:
20515 : : return NULL_TREE;
20516 : : }
20517 : :
20518 : 1392 : return get_ix86_builtin (code);
20519 : : }
20520 : :
20521 : : /* Return true if it is safe to use the rsqrt optabs to optimize
20522 : : 1.0/sqrt. */
20523 : :
20524 : : static bool
20525 : 84 : use_rsqrt_p (machine_mode mode)
20526 : : {
20527 : 84 : return ((mode == HFmode
20528 : 36 : || (TARGET_SSE && TARGET_SSE_MATH))
20529 : 84 : && flag_finite_math_only
20530 : 83 : && !flag_trapping_math
20531 : 149 : && flag_unsafe_math_optimizations);
20532 : : }
20533 : :
20534 : : /* Helper for avx_vpermilps256_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 : 29666 : avx_vpermilp_parallel (rtx par, machine_mode mode)
20540 : : {
20541 : 29666 : unsigned i, nelt = GET_MODE_NUNITS (mode);
20542 : 29666 : unsigned mask = 0;
20543 : 29666 : unsigned char ipar[16] = {}; /* Silence -Wuninitialized warning. */
20544 : :
20545 : 29666 : 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 : 175304 : for (i = 0; i < nelt; ++i)
20552 : : {
20553 : 145638 : rtx er = XVECEXP (par, 0, i);
20554 : 145638 : unsigned HOST_WIDE_INT ei;
20555 : :
20556 : 145638 : if (!CONST_INT_P (er))
20557 : : return 0;
20558 : 145638 : ei = INTVAL (er);
20559 : 145638 : if (ei >= nelt)
20560 : : return 0;
20561 : 145638 : ipar[i] = ei;
20562 : : }
20563 : :
20564 : 29666 : switch (mode)
20565 : : {
20566 : : case E_V8DFmode:
20567 : : /* In the 512-bit DFmode case, we can only move elements within
20568 : : a 128-bit lane. First fill the second part of the mask,
20569 : : then fallthru. */
20570 : 2070 : for (i = 4; i < 6; ++i)
20571 : : {
20572 : 1438 : if (ipar[i] < 4 || ipar[i] >= 6)
20573 : : return 0;
20574 : 1332 : mask |= (ipar[i] - 4) << i;
20575 : : }
20576 : 1470 : for (i = 6; i < 8; ++i)
20577 : : {
20578 : 1051 : if (ipar[i] < 6)
20579 : : return 0;
20580 : 838 : mask |= (ipar[i] - 6) << i;
20581 : : }
20582 : : /* FALLTHRU */
20583 : :
20584 : : case E_V4DFmode:
20585 : : /* In the 256-bit DFmode case, we can only move elements within
20586 : : a 128-bit lane. */
20587 : 22025 : for (i = 0; i < 2; ++i)
20588 : : {
20589 : 19095 : if (ipar[i] >= 2)
20590 : : return 0;
20591 : 12306 : mask |= ipar[i] << i;
20592 : : }
20593 : 7412 : for (i = 2; i < 4; ++i)
20594 : : {
20595 : 5171 : if (ipar[i] < 2)
20596 : : return 0;
20597 : 4482 : mask |= (ipar[i] - 2) << i;
20598 : : }
20599 : : break;
20600 : :
20601 : : case E_V16SFmode:
20602 : : /* In 512 bit SFmode case, permutation in the upper 256 bits
20603 : : must mirror the permutation in the lower 256-bits. */
20604 : 3705 : for (i = 0; i < 8; ++i)
20605 : 3295 : if (ipar[i] + 8 != ipar[i + 8])
20606 : : return 0;
20607 : : /* FALLTHRU */
20608 : :
20609 : : case E_V8SFmode:
20610 : : /* In 256 bit SFmode case, we have full freedom of
20611 : : movement within the low 128-bit lane, but the high 128-bit
20612 : : lane must mirror the exact same pattern. */
20613 : 27211 : for (i = 0; i < 4; ++i)
20614 : 23745 : if (ipar[i] + 4 != ipar[i + 4])
20615 : : return 0;
20616 : : nelt = 4;
20617 : : /* FALLTHRU */
20618 : :
20619 : 14361 : case E_V2DFmode:
20620 : 14361 : case E_V4SFmode:
20621 : : /* In the 128-bit case, we've full freedom in the placement of
20622 : : the elements from the source operand. */
20623 : 57495 : for (i = 0; i < nelt; ++i)
20624 : 43134 : mask |= ipar[i] << (i * (nelt / 2));
20625 : : break;
20626 : :
20627 : 0 : default:
20628 : 0 : gcc_unreachable ();
20629 : : }
20630 : :
20631 : : /* Make sure success has a non-zero value by adding one. */
20632 : 16602 : return mask + 1;
20633 : : }
20634 : :
20635 : : /* Helper for avx_vperm2f128_v4df_operand et al. This is also used by
20636 : : the expansion functions to turn the parallel back into a mask.
20637 : : The return value is 0 for no match and the imm8+1 for a match. */
20638 : :
20639 : : int
20640 : 52057 : avx_vperm2f128_parallel (rtx par, machine_mode mode)
20641 : : {
20642 : 52057 : unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2;
20643 : 52057 : unsigned mask = 0;
20644 : 52057 : unsigned char ipar[8] = {}; /* Silence -Wuninitialized warning. */
20645 : :
20646 : 52057 : if (XVECLEN (par, 0) != (int) nelt)
20647 : : return 0;
20648 : :
20649 : : /* Validate that all of the elements are constants, and not totally
20650 : : out of range. Copy the data into an integral array to make the
20651 : : subsequent checks easier. */
20652 : 418705 : for (i = 0; i < nelt; ++i)
20653 : : {
20654 : 366648 : rtx er = XVECEXP (par, 0, i);
20655 : 366648 : unsigned HOST_WIDE_INT ei;
20656 : :
20657 : 366648 : if (!CONST_INT_P (er))
20658 : : return 0;
20659 : 366648 : ei = INTVAL (er);
20660 : 366648 : if (ei >= 2 * nelt)
20661 : : return 0;
20662 : 366648 : ipar[i] = ei;
20663 : : }
20664 : :
20665 : : /* Validate that the halves of the permute are halves. */
20666 : 99292 : for (i = 0; i < nelt2 - 1; ++i)
20667 : 80695 : if (ipar[i] + 1 != ipar[i + 1])
20668 : : return 0;
20669 : 55450 : for (i = nelt2; i < nelt - 1; ++i)
20670 : 38355 : if (ipar[i] + 1 != ipar[i + 1])
20671 : : return 0;
20672 : :
20673 : : /* Reconstruct the mask. */
20674 : 51247 : for (i = 0; i < 2; ++i)
20675 : : {
20676 : 34173 : unsigned e = ipar[i * nelt2];
20677 : 34173 : if (e % nelt2)
20678 : : return 0;
20679 : 34152 : e /= nelt2;
20680 : 34152 : mask |= e << (i * 4);
20681 : : }
20682 : :
20683 : : /* Make sure success has a non-zero value by adding one. */
20684 : 17074 : return mask + 1;
20685 : : }
20686 : :
20687 : : /* Return a mask of VPTERNLOG operands that do not affect output. */
20688 : :
20689 : : int
20690 : 2420 : vpternlog_redundant_operand_mask (rtx pternlog_imm)
20691 : : {
20692 : 2420 : int mask = 0;
20693 : 2420 : int imm8 = INTVAL (pternlog_imm);
20694 : :
20695 : 2420 : if (((imm8 >> 4) & 0x0F) == (imm8 & 0x0F))
20696 : 6 : mask |= 1;
20697 : 2420 : if (((imm8 >> 2) & 0x33) == (imm8 & 0x33))
20698 : 6 : mask |= 2;
20699 : 2420 : if (((imm8 >> 1) & 0x55) == (imm8 & 0x55))
20700 : 147 : mask |= 4;
20701 : :
20702 : 2420 : return mask;
20703 : : }
20704 : :
20705 : : /* Eliminate false dependencies on operands that do not affect output
20706 : : by substituting other operands of a VPTERNLOG. */
20707 : :
20708 : : void
20709 : 77 : substitute_vpternlog_operands (rtx *operands)
20710 : : {
20711 : 77 : int mask = vpternlog_redundant_operand_mask (operands[4]);
20712 : :
20713 : 77 : if (mask & 1) /* The first operand is redundant. */
20714 : 2 : operands[1] = operands[2];
20715 : :
20716 : 77 : if (mask & 2) /* The second operand is redundant. */
20717 : 2 : operands[2] = operands[1];
20718 : :
20719 : 77 : if (mask & 4) /* The third operand is redundant. */
20720 : 73 : operands[3] = operands[1];
20721 : 4 : else if (REG_P (operands[3]))
20722 : : {
20723 : 0 : if (mask & 1)
20724 : 0 : operands[1] = operands[3];
20725 : 0 : if (mask & 2)
20726 : 0 : operands[2] = operands[3];
20727 : : }
20728 : 77 : }
20729 : :
20730 : : /* Return a register priority for hard reg REGNO. */
20731 : : static int
20732 : 57571629 : ix86_register_priority (int hard_regno)
20733 : : {
20734 : : /* ebp and r13 as the base always wants a displacement, r12 as the
20735 : : base always wants an index. So discourage their usage in an
20736 : : address. */
20737 : 57571629 : if (hard_regno == R12_REG || hard_regno == R13_REG)
20738 : : return 0;
20739 : 53082887 : if (hard_regno == BP_REG)
20740 : : return 1;
20741 : : /* New x86-64 int registers result in bigger code size. Discourage them. */
20742 : 51209892 : if (REX_INT_REGNO_P (hard_regno))
20743 : : return 2;
20744 : 34764412 : if (REX2_INT_REGNO_P (hard_regno))
20745 : : return 2;
20746 : : /* New x86-64 SSE registers result in bigger code size. Discourage them. */
20747 : 34762032 : if (REX_SSE_REGNO_P (hard_regno))
20748 : : return 2;
20749 : 28881640 : if (EXT_REX_SSE_REGNO_P (hard_regno))
20750 : : return 1;
20751 : : /* Usage of AX register results in smaller code. Prefer it. */
20752 : 28634221 : if (hard_regno == AX_REG)
20753 : 3781376 : return 4;
20754 : : return 3;
20755 : : }
20756 : :
20757 : : /* Implement TARGET_PREFERRED_RELOAD_CLASS.
20758 : :
20759 : : Put float CONST_DOUBLE in the constant pool instead of fp regs.
20760 : : QImode must go into class Q_REGS.
20761 : : Narrow ALL_REGS to GENERAL_REGS. This supports allowing movsf and
20762 : : movdf to do mem-to-mem moves through integer regs. */
20763 : :
20764 : : static reg_class_t
20765 : 541899275 : ix86_preferred_reload_class (rtx x, reg_class_t regclass)
20766 : : {
20767 : 541899275 : machine_mode mode = GET_MODE (x);
20768 : :
20769 : : /* We're only allowed to return a subclass of CLASS. Many of the
20770 : : following checks fail for NO_REGS, so eliminate that early. */
20771 : 541899275 : if (regclass == NO_REGS)
20772 : : return NO_REGS;
20773 : :
20774 : : /* All classes can load zeros. */
20775 : 541060404 : if (x == CONST0_RTX (mode))
20776 : : return regclass;
20777 : :
20778 : : /* Force constants into memory if we are loading a (nonzero) constant into
20779 : : an MMX, SSE or MASK register. This is because there are no MMX/SSE/MASK
20780 : : instructions to load from a constant. */
20781 : 516240840 : if (CONSTANT_P (x)
20782 : 516240840 : && (MAYBE_MMX_CLASS_P (regclass)
20783 : 151176623 : || MAYBE_SSE_CLASS_P (regclass)
20784 : 121362756 : || MAYBE_MASK_CLASS_P (regclass)))
20785 : 29939396 : return NO_REGS;
20786 : :
20787 : : /* Floating-point constants need more complex checks. */
20788 : 486301444 : if (CONST_DOUBLE_P (x))
20789 : : {
20790 : : /* General regs can load everything. */
20791 : 290184 : if (INTEGER_CLASS_P (regclass))
20792 : : return regclass;
20793 : :
20794 : : /* Floats can load 0 and 1 plus some others. Note that we eliminated
20795 : : zero above. We only want to wind up preferring 80387 registers if
20796 : : we plan on doing computation with them. */
20797 : 177241 : if (IS_STACK_MODE (mode)
20798 : 235973 : && standard_80387_constant_p (x) > 0)
20799 : : {
20800 : : /* Limit class to FP regs. */
20801 : 40470 : if (FLOAT_CLASS_P (regclass))
20802 : : return FLOAT_REGS;
20803 : : }
20804 : :
20805 : 136771 : return NO_REGS;
20806 : : }
20807 : :
20808 : : /* Prefer SSE if we can use them for math. Also allow integer regs
20809 : : when moves between register units are cheap. */
20810 : 486011260 : if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
20811 : : {
20812 : 31488892 : if (TARGET_INTER_UNIT_MOVES_FROM_VEC
20813 : 31473979 : && TARGET_INTER_UNIT_MOVES_TO_VEC
20814 : 94425762 : && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (word_mode))
20815 : 31248282 : return INT_SSE_CLASS_P (regclass) ? regclass : NO_REGS;
20816 : : else
20817 : 240610 : return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
20818 : : }
20819 : :
20820 : : /* Generally when we see PLUS here, it's the function invariant
20821 : : (plus soft-fp const_int). Which can only be computed into general
20822 : : regs. */
20823 : 454522368 : if (GET_CODE (x) == PLUS)
20824 : 1897767 : return INTEGER_CLASS_P (regclass) ? regclass : NO_REGS;
20825 : :
20826 : : /* QImode constants are easy to load, but non-constant QImode data
20827 : : must go into Q_REGS or ALL_MASK_REGS. */
20828 : 452624601 : if (GET_MODE (x) == QImode && !CONSTANT_P (x))
20829 : : {
20830 : 24970161 : if (Q_CLASS_P (regclass))
20831 : : return regclass;
20832 : 20170801 : else if (reg_class_subset_p (Q_REGS, regclass))
20833 : : return Q_REGS;
20834 : 53686 : else if (MASK_CLASS_P (regclass))
20835 : : return regclass;
20836 : : else
20837 : : return NO_REGS;
20838 : : }
20839 : :
20840 : : return regclass;
20841 : : }
20842 : :
20843 : : /* Discourage putting floating-point values in SSE registers unless
20844 : : SSE math is being used, and likewise for the 387 registers. */
20845 : : static reg_class_t
20846 : 73144666 : ix86_preferred_output_reload_class (rtx x, reg_class_t regclass)
20847 : : {
20848 : : /* Restrict the output reload class to the register bank that we are doing
20849 : : math on. If we would like not to return a subset of CLASS, reject this
20850 : : alternative: if reload cannot do this, it will still use its choice. */
20851 : 73144666 : machine_mode mode = GET_MODE (x);
20852 : 73144666 : if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
20853 : 7202781 : return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS;
20854 : :
20855 : 65941885 : if (IS_STACK_MODE (mode))
20856 : 205043 : return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
20857 : :
20858 : : return regclass;
20859 : : }
20860 : :
20861 : : static reg_class_t
20862 : 382268855 : ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
20863 : : machine_mode mode, secondary_reload_info *sri)
20864 : : {
20865 : : /* Double-word spills from general registers to non-offsettable memory
20866 : : references (zero-extended addresses) require special handling. */
20867 : 382268855 : if (TARGET_64BIT
20868 : 329678382 : && MEM_P (x)
20869 : 178006056 : && GET_MODE_SIZE (mode) > UNITS_PER_WORD
20870 : 17670213 : && INTEGER_CLASS_P (rclass)
20871 : 384967391 : && !offsettable_memref_p (x))
20872 : : {
20873 : 2455844 : sri->icode = (in_p
20874 : 1227922 : ? CODE_FOR_reload_noff_load
20875 : : : CODE_FOR_reload_noff_store);
20876 : : /* Add the cost of moving address to a temporary. */
20877 : 1227922 : sri->extra_cost = 1;
20878 : :
20879 : 1227922 : return NO_REGS;
20880 : : }
20881 : :
20882 : : /* QImode spills from non-QI registers require
20883 : : intermediate register on 32bit targets. */
20884 : 381040933 : if (mode == QImode
20885 : 381040933 : && ((!TARGET_64BIT && !in_p
20886 : 573928 : && INTEGER_CLASS_P (rclass)
20887 : 573884 : && MAYBE_NON_Q_CLASS_P (rclass))
20888 : 22675442 : || (!TARGET_AVX512DQ
20889 : 22483031 : && MAYBE_MASK_CLASS_P (rclass))))
20890 : : {
20891 : 6205 : int regno = true_regnum (x);
20892 : :
20893 : : /* Return Q_REGS if the operand is in memory. */
20894 : 6205 : if (regno == -1)
20895 : : return Q_REGS;
20896 : :
20897 : : return NO_REGS;
20898 : : }
20899 : :
20900 : : /* Require movement to gpr, and then store to memory. */
20901 : 381034728 : if ((mode == HFmode || mode == HImode || mode == V2QImode
20902 : : || mode == BFmode)
20903 : 3528658 : && !TARGET_SSE4_1
20904 : 2946243 : && SSE_CLASS_P (rclass)
20905 : 187370 : && !in_p && MEM_P (x))
20906 : : {
20907 : 88456 : sri->extra_cost = 1;
20908 : 88456 : return GENERAL_REGS;
20909 : : }
20910 : :
20911 : : /* This condition handles corner case where an expression involving
20912 : : pointers gets vectorized. We're trying to use the address of a
20913 : : stack slot as a vector initializer.
20914 : :
20915 : : (set (reg:V2DI 74 [ vect_cst_.2 ])
20916 : : (vec_duplicate:V2DI (reg/f:DI 20 frame)))
20917 : :
20918 : : Eventually frame gets turned into sp+offset like this:
20919 : :
20920 : : (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20921 : : (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
20922 : : (const_int 392 [0x188]))))
20923 : :
20924 : : That later gets turned into:
20925 : :
20926 : : (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20927 : : (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
20928 : : (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))))
20929 : :
20930 : : We'll have the following reload recorded:
20931 : :
20932 : : Reload 0: reload_in (DI) =
20933 : : (plus:DI (reg/f:DI 7 sp)
20934 : : (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))
20935 : : reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20936 : : SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine
20937 : : reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188]))
20938 : : reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
20939 : : reload_reg_rtx: (reg:V2DI 22 xmm1)
20940 : :
20941 : : Which isn't going to work since SSE instructions can't handle scalar
20942 : : additions. Returning GENERAL_REGS forces the addition into integer
20943 : : register and reload can handle subsequent reloads without problems. */
20944 : :
20945 : 220691888 : if (in_p && GET_CODE (x) == PLUS
20946 : 2 : && SSE_CLASS_P (rclass)
20947 : 380946272 : && SCALAR_INT_MODE_P (mode))
20948 : : return GENERAL_REGS;
20949 : :
20950 : : return NO_REGS;
20951 : : }
20952 : :
20953 : : /* Implement TARGET_CLASS_LIKELY_SPILLED_P. */
20954 : :
20955 : : static bool
20956 : 707516860 : ix86_class_likely_spilled_p (reg_class_t rclass)
20957 : : {
20958 : 697642785 : switch (rclass)
20959 : : {
20960 : : case AREG:
20961 : : case DREG:
20962 : : case CREG:
20963 : : case BREG:
20964 : : case AD_REGS:
20965 : : case SIREG:
20966 : : case DIREG:
20967 : : case SSE_FIRST_REG:
20968 : : case FP_TOP_REG:
20969 : : case FP_SECOND_REG:
20970 : : return true;
20971 : :
20972 : 676040836 : default:
20973 : 676040836 : break;
20974 : : }
20975 : :
20976 : 676040836 : return false;
20977 : : }
20978 : :
20979 : : /* Implement TARGET_CALLEE_SAVE_COST. */
20980 : :
20981 : : static int
20982 : 83261442 : ix86_callee_save_cost (spill_cost_type, unsigned int hard_regno, machine_mode,
20983 : : unsigned int, int mem_cost, const HARD_REG_SET &, bool)
20984 : : {
20985 : : /* Account for the fact that push and pop are shorter and do their
20986 : : own allocation and deallocation. */
20987 : 83261442 : if (GENERAL_REGNO_P (hard_regno))
20988 : : {
20989 : : /* push is 1 byte while typical spill is 4-5 bytes.
20990 : : ??? We probably should adjust size costs accordingly.
20991 : : Costs are relative to reg-reg move that has 2 bytes for 32bit
20992 : : and 3 bytes otherwise. Be sure that no cost table sets cost
20993 : : to 2, so we end up with 0. */
20994 : 83252124 : if (mem_cost <= 2 || optimize_function_for_size_p (cfun))
20995 : 3574126 : return 1;
20996 : 79677998 : return mem_cost - 2;
20997 : : }
20998 : : return mem_cost;
20999 : : }
21000 : :
21001 : : /* Return true if a set of DST by the expression SRC should be allowed.
21002 : : This prevents complex sets of likely_spilled hard regs before split1. */
21003 : :
21004 : : bool
21005 : 613692403 : ix86_hardreg_mov_ok (rtx dst, rtx src)
21006 : : {
21007 : : /* Avoid complex sets of likely_spilled hard registers before reload. */
21008 : 500652768 : if (REG_P (dst) && HARD_REGISTER_P (dst)
21009 : 294045266 : && !REG_P (src) && !MEM_P (src)
21010 : 96290671 : && !(VECTOR_MODE_P (GET_MODE (dst))
21011 : 96290671 : ? standard_sse_constant_p (src, GET_MODE (dst))
21012 : 47912949 : : x86_64_immediate_operand (src, GET_MODE (dst)))
21013 : 9874075 : && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst)))
21014 : 622331515 : && ix86_pre_reload_split ())
21015 : : return false;
21016 : : return true;
21017 : : }
21018 : :
21019 : : /* If we are copying between registers from different register sets
21020 : : (e.g. FP and integer), we may need a memory location.
21021 : :
21022 : : The function can't work reliably when one of the CLASSES is a class
21023 : : containing registers from multiple sets. We avoid this by never combining
21024 : : different sets in a single alternative in the machine description.
21025 : : Ensure that this constraint holds to avoid unexpected surprises.
21026 : :
21027 : : When STRICT is false, we are being called from REGISTER_MOVE_COST,
21028 : : so do not enforce these sanity checks.
21029 : :
21030 : : To optimize register_move_cost performance, define inline variant. */
21031 : :
21032 : : static inline bool
21033 : 5606468264 : inline_secondary_memory_needed (machine_mode mode, reg_class_t class1,
21034 : : reg_class_t class2, int strict)
21035 : : {
21036 : 5606468264 : if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
21037 : : return false;
21038 : :
21039 : 5574700181 : if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
21040 : 4750678407 : || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
21041 : 4056898264 : || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
21042 : 3870727062 : || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
21043 : 3694542453 : || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
21044 : 3694542453 : || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2)
21045 : 3694542453 : || MAYBE_MASK_CLASS_P (class1) != MASK_CLASS_P (class1)
21046 : 9101355010 : || MAYBE_MASK_CLASS_P (class2) != MASK_CLASS_P (class2))
21047 : : {
21048 : 2208023463 : gcc_assert (!strict || lra_in_progress);
21049 : : return true;
21050 : : }
21051 : :
21052 : 3366676718 : if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
21053 : : return true;
21054 : :
21055 : : /* ??? This is a lie. We do have moves between mmx/general, and for
21056 : : mmx/sse2. But by saying we need secondary memory we discourage the
21057 : : register allocator from using the mmx registers unless needed. */
21058 : 3219414738 : if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
21059 : : return true;
21060 : :
21061 : : /* Between mask and general, we have moves no larger than word size. */
21062 : 3124291687 : if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2))
21063 : : {
21064 : 2528230 : if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2))
21065 : 3311345 : || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
21066 : 184514 : return true;
21067 : : }
21068 : :
21069 : 3124107173 : if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
21070 : : {
21071 : : /* SSE1 doesn't have any direct moves from other classes. */
21072 : 678781329 : if (!TARGET_SSE2)
21073 : : return true;
21074 : :
21075 : 676220837 : if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2)))
21076 : : return true;
21077 : :
21078 : : /* If the target says that inter-unit moves are more expensive
21079 : : than moving through memory, then don't generate them. */
21080 : 1013906094 : if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC)
21081 : 1013439081 : || (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC))
21082 : 1283489 : return true;
21083 : :
21084 : : /* With SSE4.1, *mov{ti,di}_internal supports moves between
21085 : : SSE_REGS and GENERAL_REGS using pinsr{q,d} or pextr{q,d}. */
21086 : 674937348 : if (TARGET_SSE4_1
21087 : 36136384 : && (TARGET_64BIT ? mode == TImode : mode == DImode))
21088 : : return false;
21089 : :
21090 : 673369046 : int msize = GET_MODE_SIZE (mode);
21091 : :
21092 : : /* Between SSE and general, we have moves no larger than word size. */
21093 : 689606262 : if (msize > UNITS_PER_WORD)
21094 : : return true;
21095 : :
21096 : : /* In addition to SImode moves, HImode moves are supported for SSE2 and above,
21097 : : Use vmovw with AVX512FP16, or pinsrw/pextrw without AVX512FP16. */
21098 : 582429766 : int minsize = GET_MODE_SIZE (TARGET_SSE2 ? HImode : SImode);
21099 : :
21100 : 582429766 : if (msize < minsize)
21101 : : return true;
21102 : : }
21103 : :
21104 : : return false;
21105 : : }
21106 : :
21107 : : /* Implement TARGET_SECONDARY_MEMORY_NEEDED. */
21108 : :
21109 : : static bool
21110 : 70432258 : ix86_secondary_memory_needed (machine_mode mode, reg_class_t class1,
21111 : : reg_class_t class2)
21112 : : {
21113 : 70432258 : return inline_secondary_memory_needed (mode, class1, class2, true);
21114 : : }
21115 : :
21116 : : /* Implement TARGET_SECONDARY_MEMORY_NEEDED_MODE.
21117 : :
21118 : : get_secondary_mem widens integral modes to BITS_PER_WORD.
21119 : : There is no need to emit full 64 bit move on 64 bit targets
21120 : : for integral modes that can be moved using 32 bit move. */
21121 : :
21122 : : static machine_mode
21123 : 13798 : ix86_secondary_memory_needed_mode (machine_mode mode)
21124 : : {
21125 : 27596 : if (GET_MODE_BITSIZE (mode) < 32 && INTEGRAL_MODE_P (mode))
21126 : 16 : return mode_for_size (32, GET_MODE_CLASS (mode), 0).require ();
21127 : : return mode;
21128 : : }
21129 : :
21130 : : /* Implement the TARGET_CLASS_MAX_NREGS hook.
21131 : :
21132 : : On the 80386, this is the size of MODE in words,
21133 : : except in the FP regs, where a single reg is always enough. */
21134 : :
21135 : : static unsigned char
21136 : 6146687600 : ix86_class_max_nregs (reg_class_t rclass, machine_mode mode)
21137 : : {
21138 : 6146687600 : if (MAYBE_INTEGER_CLASS_P (rclass))
21139 : : {
21140 : 4127984999 : if (mode == XFmode)
21141 : 144268081 : return (TARGET_64BIT ? 2 : 3);
21142 : 3983716918 : else if (mode == XCmode)
21143 : 144267712 : return (TARGET_64BIT ? 4 : 6);
21144 : : else
21145 : 7786484711 : return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
21146 : : }
21147 : : else
21148 : : {
21149 : 2018702601 : if (COMPLEX_MODE_P (mode))
21150 : : return 2;
21151 : : else
21152 : 1735460382 : return 1;
21153 : : }
21154 : : }
21155 : :
21156 : : /* Implement TARGET_CAN_CHANGE_MODE_CLASS. */
21157 : :
21158 : : static bool
21159 : 39404616 : ix86_can_change_mode_class (machine_mode from, machine_mode to,
21160 : : reg_class_t regclass)
21161 : : {
21162 : 39404616 : if (from == to)
21163 : : return true;
21164 : :
21165 : : /* x87 registers can't do subreg at all, as all values are reformatted
21166 : : to extended precision.
21167 : :
21168 : : ??? middle-end queries mode changes for ALL_REGS and this makes
21169 : : vec_series_lowpart_p to always return false. We probably should
21170 : : restrict this to modes supported by i387 and check if it is enabled. */
21171 : 38124424 : if (MAYBE_FLOAT_CLASS_P (regclass))
21172 : : return false;
21173 : :
21174 : 33723382 : if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
21175 : : {
21176 : : /* Vector registers do not support QI or HImode loads. If we don't
21177 : : disallow a change to these modes, reload will assume it's ok to
21178 : : drop the subreg from (subreg:SI (reg:HI 100) 0). This affects
21179 : : the vec_dupv4hi pattern.
21180 : : NB: SSE2 can load 16bit data to sse register via pinsrw. */
21181 : 16493434 : int mov_size = MAYBE_SSE_CLASS_P (regclass) && TARGET_SSE2 ? 2 : 4;
21182 : 16493434 : if (GET_MODE_SIZE (from) < mov_size
21183 : 32986596 : || GET_MODE_SIZE (to) < mov_size)
21184 : : return false;
21185 : : }
21186 : :
21187 : : return true;
21188 : : }
21189 : :
21190 : : /* Return index of MODE in the sse load/store tables. */
21191 : :
21192 : : static inline int
21193 : 773576178 : sse_store_index (machine_mode mode)
21194 : : {
21195 : : /* NB: Use SFmode cost for HFmode instead of adding HFmode load/store
21196 : : costs to processor_costs, which requires changes to all entries in
21197 : : processor cost table. */
21198 : 773576178 : if (mode == E_HFmode)
21199 : 135293382 : mode = E_SFmode;
21200 : :
21201 : 1547152356 : switch (GET_MODE_SIZE (mode))
21202 : : {
21203 : : case 4:
21204 : : return 0;
21205 : : case 8:
21206 : : return 1;
21207 : : case 16:
21208 : : return 2;
21209 : : case 32:
21210 : : return 3;
21211 : : case 64:
21212 : : return 4;
21213 : : default:
21214 : : return -1;
21215 : : }
21216 : : }
21217 : :
21218 : : /* Return the cost of moving data of mode M between a
21219 : : register and memory. A value of 2 is the default; this cost is
21220 : : relative to those in `REGISTER_MOVE_COST'.
21221 : :
21222 : : This function is used extensively by register_move_cost that is used to
21223 : : build tables at startup. Make it inline in this case.
21224 : : When IN is 2, return maximum of in and out move cost.
21225 : :
21226 : : If moving between registers and memory is more expensive than
21227 : : between two registers, you should define this macro to express the
21228 : : relative cost.
21229 : :
21230 : : Model also increased moving costs of QImode registers in non
21231 : : Q_REGS classes.
21232 : : */
21233 : : static inline int
21234 : 6907769200 : inline_memory_move_cost (machine_mode mode, enum reg_class regclass, int in)
21235 : : {
21236 : 6907769200 : int cost;
21237 : :
21238 : 6907769200 : if (FLOAT_CLASS_P (regclass))
21239 : : {
21240 : 356161877 : int index;
21241 : 356161877 : switch (mode)
21242 : : {
21243 : : case E_SFmode:
21244 : : index = 0;
21245 : : break;
21246 : : case E_DFmode:
21247 : : index = 1;
21248 : : break;
21249 : : case E_XFmode:
21250 : : index = 2;
21251 : : break;
21252 : : default:
21253 : : return 100;
21254 : : }
21255 : 104157443 : if (in == 2)
21256 : 100269583 : return MAX (ix86_cost->hard_register.fp_load [index],
21257 : : ix86_cost->hard_register.fp_store [index]);
21258 : 3887860 : return in ? ix86_cost->hard_register.fp_load [index]
21259 : 3887860 : : ix86_cost->hard_register.fp_store [index];
21260 : : }
21261 : 6551607323 : if (SSE_CLASS_P (regclass))
21262 : : {
21263 : 646496917 : int index = sse_store_index (mode);
21264 : 646496917 : if (index == -1)
21265 : : return 100;
21266 : 553295635 : if (in == 2)
21267 : 392093529 : return MAX (ix86_cost->hard_register.sse_load [index],
21268 : : ix86_cost->hard_register.sse_store [index]);
21269 : 161202106 : return in ? ix86_cost->hard_register.sse_load [index]
21270 : 161202106 : : ix86_cost->hard_register.sse_store [index];
21271 : : }
21272 : 5905110406 : if (MASK_CLASS_P (regclass))
21273 : : {
21274 : 111980838 : int index;
21275 : 223961676 : switch (GET_MODE_SIZE (mode))
21276 : : {
21277 : : case 1:
21278 : : index = 0;
21279 : : break;
21280 : 8816633 : case 2:
21281 : 8816633 : index = 1;
21282 : 8816633 : break;
21283 : : /* DImode loads and stores assumed to cost the same as SImode. */
21284 : 39644569 : case 4:
21285 : 39644569 : case 8:
21286 : 39644569 : index = 2;
21287 : 39644569 : break;
21288 : : default:
21289 : : return 100;
21290 : : }
21291 : :
21292 : 51991958 : if (in == 2)
21293 : 572879 : return MAX (ix86_cost->hard_register.mask_load[index],
21294 : : ix86_cost->hard_register.mask_store[index]);
21295 : 51419079 : return in ? ix86_cost->hard_register.mask_load[2]
21296 : 51419079 : : ix86_cost->hard_register.mask_store[2];
21297 : : }
21298 : 5793129568 : if (MMX_CLASS_P (regclass))
21299 : : {
21300 : 172698995 : int index;
21301 : 345397990 : switch (GET_MODE_SIZE (mode))
21302 : : {
21303 : : case 4:
21304 : : index = 0;
21305 : : break;
21306 : 99847075 : case 8:
21307 : 99847075 : index = 1;
21308 : 99847075 : break;
21309 : : default:
21310 : : return 100;
21311 : : }
21312 : 136705667 : if (in == 2)
21313 : 116995013 : return MAX (ix86_cost->hard_register.mmx_load [index],
21314 : : ix86_cost->hard_register.mmx_store [index]);
21315 : 19710654 : return in ? ix86_cost->hard_register.mmx_load [index]
21316 : 19710654 : : ix86_cost->hard_register.mmx_store [index];
21317 : : }
21318 : 11240861146 : switch (GET_MODE_SIZE (mode))
21319 : : {
21320 : 123114850 : case 1:
21321 : 123114850 : if (Q_CLASS_P (regclass) || TARGET_64BIT)
21322 : : {
21323 : 120512552 : if (!in)
21324 : 19330988 : return ix86_cost->hard_register.int_store[0];
21325 : 101181564 : if (TARGET_PARTIAL_REG_DEPENDENCY
21326 : 101181564 : && optimize_function_for_speed_p (cfun))
21327 : 94467750 : cost = ix86_cost->hard_register.movzbl_load;
21328 : : else
21329 : 6713814 : cost = ix86_cost->hard_register.int_load[0];
21330 : 101181564 : if (in == 2)
21331 : 81815870 : return MAX (cost, ix86_cost->hard_register.int_store[0]);
21332 : : return cost;
21333 : : }
21334 : : else
21335 : : {
21336 : 2602298 : if (in == 2)
21337 : 1842890 : return MAX (ix86_cost->hard_register.movzbl_load,
21338 : : ix86_cost->hard_register.int_store[0] + 4);
21339 : 759408 : if (in)
21340 : 379764 : return ix86_cost->hard_register.movzbl_load;
21341 : : else
21342 : 379644 : return ix86_cost->hard_register.int_store[0] + 4;
21343 : : }
21344 : 635456629 : break;
21345 : 635456629 : case 2:
21346 : 635456629 : {
21347 : 635456629 : int cost;
21348 : 635456629 : if (in == 2)
21349 : 536881820 : cost = MAX (ix86_cost->hard_register.int_load[1],
21350 : : ix86_cost->hard_register.int_store[1]);
21351 : : else
21352 : 98574809 : cost = in ? ix86_cost->hard_register.int_load[1]
21353 : : : ix86_cost->hard_register.int_store[1];
21354 : :
21355 : 635456629 : if (mode == E_HFmode)
21356 : : {
21357 : : /* Prefer SSE over GPR for HFmode. */
21358 : 123135434 : int sse_cost;
21359 : 123135434 : int index = sse_store_index (mode);
21360 : 123135434 : if (in == 2)
21361 : 113280056 : sse_cost = MAX (ix86_cost->hard_register.sse_load[index],
21362 : : ix86_cost->hard_register.sse_store[index]);
21363 : : else
21364 : 19710756 : sse_cost = (in
21365 : 9855378 : ? ix86_cost->hard_register.sse_load [index]
21366 : : : ix86_cost->hard_register.sse_store [index]);
21367 : 123135434 : if (sse_cost >= cost)
21368 : 123135434 : cost = sse_cost + 1;
21369 : : }
21370 : : return cost;
21371 : : }
21372 : 4861859094 : default:
21373 : 4861859094 : if (in == 2)
21374 : 3718245346 : cost = MAX (ix86_cost->hard_register.int_load[2],
21375 : : ix86_cost->hard_register.int_store[2]);
21376 : 1143613748 : else if (in)
21377 : 572005420 : cost = ix86_cost->hard_register.int_load[2];
21378 : : else
21379 : 571608328 : cost = ix86_cost->hard_register.int_store[2];
21380 : : /* Multiply with the number of GPR moves needed. */
21381 : 9843029147 : return cost * CEIL ((int) GET_MODE_SIZE (mode), UNITS_PER_WORD);
21382 : : }
21383 : : }
21384 : :
21385 : : static int
21386 : 1838895088 : ix86_memory_move_cost (machine_mode mode, reg_class_t regclass, bool in)
21387 : : {
21388 : 2758010428 : return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0);
21389 : : }
21390 : :
21391 : :
21392 : : /* Return the cost of moving data from a register in class CLASS1 to
21393 : : one in class CLASS2.
21394 : :
21395 : : It is not required that the cost always equal 2 when FROM is the same as TO;
21396 : : on some machines it is expensive to move between registers if they are not
21397 : : general registers. */
21398 : :
21399 : : static int
21400 : 5536036006 : ix86_register_move_cost (machine_mode mode, reg_class_t class1_i,
21401 : : reg_class_t class2_i)
21402 : : {
21403 : 5536036006 : enum reg_class class1 = (enum reg_class) class1_i;
21404 : 5536036006 : enum reg_class class2 = (enum reg_class) class2_i;
21405 : :
21406 : : /* In case we require secondary memory, compute cost of the store followed
21407 : : by load. In order to avoid bad register allocation choices, we need
21408 : : for this to be *at least* as high as the symmetric MEMORY_MOVE_COST. */
21409 : :
21410 : 5536036006 : if (inline_secondary_memory_needed (mode, class1, class2, false))
21411 : : {
21412 : 2534437056 : int cost = 1;
21413 : :
21414 : 2534437056 : cost += inline_memory_move_cost (mode, class1, 2);
21415 : 2534437056 : cost += inline_memory_move_cost (mode, class2, 2);
21416 : :
21417 : : /* In case of copying from general_purpose_register we may emit multiple
21418 : : stores followed by single load causing memory size mismatch stall.
21419 : : Count this as arbitrarily high cost of 20. */
21420 : 5068874112 : if (GET_MODE_BITSIZE (mode) > BITS_PER_WORD
21421 : 758829338 : && TARGET_MEMORY_MISMATCH_STALL
21422 : 4052095732 : && targetm.class_max_nregs (class1, mode)
21423 : 758829338 : > targetm.class_max_nregs (class2, mode))
21424 : 144396780 : cost += 20;
21425 : :
21426 : : /* In the case of FP/MMX moves, the registers actually overlap, and we
21427 : : have to switch modes in order to treat them differently. */
21428 : 58497543 : if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
21429 : 2583722021 : || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
21430 : 18425156 : cost += 20;
21431 : :
21432 : 2534437056 : return cost;
21433 : : }
21434 : :
21435 : : /* Moves between MMX and non-MMX units require secondary memory. */
21436 : 3001598950 : if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
21437 : 0 : gcc_unreachable ();
21438 : :
21439 : 3001598950 : if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
21440 : 574571285 : return (SSE_CLASS_P (class1)
21441 : 574571285 : ? ix86_cost->hard_register.sse_to_integer
21442 : 574571285 : : ix86_cost->hard_register.integer_to_sse);
21443 : :
21444 : : /* Moves between mask register and GPR. */
21445 : 2427027665 : if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2))
21446 : : {
21447 : 1035531 : return (MASK_CLASS_P (class1)
21448 : 1035531 : ? ix86_cost->hard_register.mask_to_integer
21449 : 1035531 : : ix86_cost->hard_register.integer_to_mask);
21450 : : }
21451 : : /* Moving between mask registers. */
21452 : 2425992134 : if (MASK_CLASS_P (class1) && MASK_CLASS_P (class2))
21453 : 99972 : return ix86_cost->hard_register.mask_move;
21454 : :
21455 : 2425892162 : if (MAYBE_FLOAT_CLASS_P (class1))
21456 : 11645162 : return ix86_cost->hard_register.fp_move;
21457 : 2414247000 : if (MAYBE_SSE_CLASS_P (class1))
21458 : : {
21459 : 226609218 : if (GET_MODE_BITSIZE (mode) <= 128)
21460 : 110853794 : return ix86_cost->hard_register.xmm_move;
21461 : 4901630 : if (GET_MODE_BITSIZE (mode) <= 256)
21462 : 1555404 : return ix86_cost->hard_register.ymm_move;
21463 : 895411 : return ix86_cost->hard_register.zmm_move;
21464 : : }
21465 : 2300942391 : if (MAYBE_MMX_CLASS_P (class1))
21466 : 2142514 : return ix86_cost->hard_register.mmx_move;
21467 : : return 2;
21468 : : }
21469 : :
21470 : : /* Implement TARGET_HARD_REGNO_NREGS. This is ordinarily the length in
21471 : : words of a value of mode MODE but can be less for certain modes in
21472 : : special long registers.
21473 : :
21474 : : Actually there are no two word move instructions for consecutive
21475 : : registers. And only registers 0-3 may have mov byte instructions
21476 : : applied to them. */
21477 : :
21478 : : static unsigned int
21479 : 9390597320 : ix86_hard_regno_nregs (unsigned int regno, machine_mode mode)
21480 : : {
21481 : 9390597320 : if (GENERAL_REGNO_P (regno))
21482 : : {
21483 : 3266294720 : if (mode == XFmode)
21484 : 25599168 : return TARGET_64BIT ? 2 : 3;
21485 : 3241169376 : if (mode == XCmode)
21486 : 25599168 : return TARGET_64BIT ? 4 : 6;
21487 : 6492737536 : return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
21488 : : }
21489 : 6124302600 : if (COMPLEX_MODE_P (mode))
21490 : : return 2;
21491 : : /* Register pair for mask registers. */
21492 : 5370542280 : if (mode == P2QImode || mode == P2HImode)
21493 : : return 2;
21494 : 5276322240 : if (mode == V64SFmode || mode == V64SImode)
21495 : 94220040 : return 4;
21496 : : return 1;
21497 : : }
21498 : :
21499 : : /* Implement REGMODE_NATURAL_SIZE(MODE). */
21500 : : unsigned int
21501 : 105436497 : ix86_regmode_natural_size (machine_mode mode)
21502 : : {
21503 : 105436497 : if (mode == P2HImode || mode == P2QImode)
21504 : 2450 : return GET_MODE_SIZE (mode) / 2;
21505 : 105435272 : return UNITS_PER_WORD;
21506 : : }
21507 : :
21508 : : /* Implement TARGET_HARD_REGNO_MODE_OK. */
21509 : :
21510 : : static bool
21511 : 56729573972 : ix86_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
21512 : : {
21513 : : /* Flags and only flags can only hold CCmode values. */
21514 : 56729573972 : if (CC_REGNO_P (regno))
21515 : 452595769 : return GET_MODE_CLASS (mode) == MODE_CC;
21516 : 56276978203 : if (GET_MODE_CLASS (mode) == MODE_CC
21517 : : || GET_MODE_CLASS (mode) == MODE_RANDOM)
21518 : : return false;
21519 : 50753577834 : if (STACK_REGNO_P (regno))
21520 : 4947805869 : return VALID_FP_MODE_P (mode);
21521 : 45805771965 : if (MASK_REGNO_P (regno))
21522 : : {
21523 : : /* Register pair only starts at even register number. */
21524 : 3873186926 : if ((mode == P2QImode || mode == P2HImode))
21525 : 51229210 : return MASK_PAIR_REGNO_P(regno);
21526 : :
21527 : 1070372364 : return ((TARGET_AVX512F && VALID_MASK_REG_MODE (mode))
21528 : 4871741012 : || (TARGET_AVX512BW && VALID_MASK_AVX512BW_MODE (mode)));
21529 : : }
21530 : :
21531 : 41932585039 : if (GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
21532 : : return false;
21533 : :
21534 : 40955971053 : if (SSE_REGNO_P (regno))
21535 : : {
21536 : : /* We implement the move patterns for all vector modes into and
21537 : : out of SSE registers, even when no operation instructions
21538 : : are available. */
21539 : :
21540 : : /* For AVX-512 we allow, regardless of regno:
21541 : : - XI mode
21542 : : - any of 512-bit wide vector mode
21543 : : - any scalar mode. */
21544 : 17753521459 : if (TARGET_AVX512F
21545 : : && ((VALID_AVX512F_REG_OR_XI_MODE (mode))
21546 : : || VALID_AVX512F_SCALAR_MODE (mode)))
21547 : : return true;
21548 : :
21549 : : /* TODO check for QI/HI scalars. */
21550 : : /* AVX512VL allows sse regs16+ for 128/256 bit modes. */
21551 : 17054116160 : if (TARGET_AVX512VL
21552 : 1887319843 : && (VALID_AVX256_REG_OR_OI_MODE (mode)
21553 : 1673057589 : || VALID_AVX512VL_128_REG_MODE (mode)))
21554 : : return true;
21555 : :
21556 : : /* xmm16-xmm31 are only available for AVX-512. */
21557 : 16603417779 : if (EXT_REX_SSE_REGNO_P (regno))
21558 : : return false;
21559 : :
21560 : : /* OImode and AVX modes are available only when AVX is enabled. */
21561 : 9585304125 : return ((TARGET_AVX
21562 : 2137754239 : && VALID_AVX256_REG_OR_OI_MODE (mode))
21563 : : || VALID_SSE_REG_MODE (mode)
21564 : : || VALID_SSE2_REG_MODE (mode)
21565 : : || VALID_MMX_REG_MODE (mode)
21566 : 9585304125 : || VALID_MMX_REG_MODE_3DNOW (mode));
21567 : : }
21568 : 23202449594 : if (MMX_REGNO_P (regno))
21569 : : {
21570 : : /* We implement the move patterns for 3DNOW modes even in MMX mode,
21571 : : so if the register is available at all, then we can move data of
21572 : : the given mode into or out of it. */
21573 : 4159153372 : return (VALID_MMX_REG_MODE (mode)
21574 : : || VALID_MMX_REG_MODE_3DNOW (mode));
21575 : : }
21576 : :
21577 : 19043296222 : if (mode == QImode)
21578 : : {
21579 : : /* Take care for QImode values - they can be in non-QI regs,
21580 : : but then they do cause partial register stalls. */
21581 : 205965601 : if (ANY_QI_REGNO_P (regno))
21582 : : return true;
21583 : 14292418 : if (!TARGET_PARTIAL_REG_STALL)
21584 : : return true;
21585 : : /* LRA checks if the hard register is OK for the given mode.
21586 : : QImode values can live in non-QI regs, so we allow all
21587 : : registers here. */
21588 : 0 : if (lra_in_progress)
21589 : : return true;
21590 : 0 : return !can_create_pseudo_p ();
21591 : : }
21592 : : /* We handle both integer and floats in the general purpose registers. */
21593 : 18837330621 : else if (VALID_INT_MODE_P (mode)
21594 : 14040582260 : || VALID_FP_MODE_P (mode))
21595 : : return true;
21596 : : /* Lots of MMX code casts 8 byte vector modes to DImode. If we then go
21597 : : on to use that value in smaller contexts, this can easily force a
21598 : : pseudo to be allocated to GENERAL_REGS. Since this is no worse than
21599 : : supporting DImode, allow it. */
21600 : 12985795165 : else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
21601 : : return true;
21602 : :
21603 : : return false;
21604 : : }
21605 : :
21606 : : /* Implement TARGET_INSN_CALLEE_ABI. */
21607 : :
21608 : : const predefined_function_abi &
21609 : 248038337 : ix86_insn_callee_abi (const rtx_insn *insn)
21610 : : {
21611 : 248038337 : unsigned int abi_id = 0;
21612 : 248038337 : rtx pat = PATTERN (insn);
21613 : 248038337 : if (vzeroupper_pattern (pat, VOIDmode))
21614 : 315789 : abi_id = ABI_VZEROUPPER;
21615 : :
21616 : 248038337 : return function_abis[abi_id];
21617 : : }
21618 : :
21619 : : /* Initialize function_abis with corresponding abi_id,
21620 : : currently only handle vzeroupper. */
21621 : : void
21622 : 18100 : ix86_initialize_callee_abi (unsigned int abi_id)
21623 : : {
21624 : 18100 : gcc_assert (abi_id == ABI_VZEROUPPER);
21625 : 18100 : predefined_function_abi &vzeroupper_abi = function_abis[abi_id];
21626 : 18100 : if (!vzeroupper_abi.initialized_p ())
21627 : : {
21628 : : HARD_REG_SET full_reg_clobbers;
21629 : 4055 : CLEAR_HARD_REG_SET (full_reg_clobbers);
21630 : 4055 : vzeroupper_abi.initialize (ABI_VZEROUPPER, full_reg_clobbers);
21631 : : }
21632 : 18100 : }
21633 : :
21634 : : void
21635 : 18100 : ix86_expand_avx_vzeroupper (void)
21636 : : {
21637 : : /* Initialize vzeroupper_abi here. */
21638 : 18100 : ix86_initialize_callee_abi (ABI_VZEROUPPER);
21639 : 18100 : rtx_insn *insn = emit_call_insn (gen_avx_vzeroupper_callee_abi ());
21640 : : /* Return false for non-local goto in can_nonlocal_goto. */
21641 : 18100 : make_reg_eh_region_note (insn, 0, INT_MIN);
21642 : : /* Flag used for call_insn indicates it's a fake call. */
21643 : 18100 : RTX_FLAG (insn, used) = 1;
21644 : 18100 : }
21645 : :
21646 : :
21647 : : /* Implement TARGET_HARD_REGNO_CALL_PART_CLOBBERED. The only ABI that
21648 : : saves SSE registers across calls is Win64 (thus no need to check the
21649 : : current ABI here), and with AVX enabled Win64 only guarantees that
21650 : : the low 16 bytes are saved. */
21651 : :
21652 : : static bool
21653 : 2046750811 : ix86_hard_regno_call_part_clobbered (unsigned int abi_id, unsigned int regno,
21654 : : machine_mode mode)
21655 : : {
21656 : : /* Special ABI for vzeroupper which only clobber higher part of sse regs. */
21657 : 2046750811 : if (abi_id == ABI_VZEROUPPER)
21658 : 29239319 : return (GET_MODE_SIZE (mode) > 16
21659 : 29239319 : && ((TARGET_64BIT && REX_SSE_REGNO_P (regno))
21660 : 4451750 : || LEGACY_SSE_REGNO_P (regno)));
21661 : :
21662 : 2656738452 : return SSE_REGNO_P (regno) && GET_MODE_SIZE (mode) > 16;
21663 : : }
21664 : :
21665 : : /* A subroutine of ix86_modes_tieable_p. Return true if MODE is a
21666 : : tieable integer mode. */
21667 : :
21668 : : static bool
21669 : 50261599 : ix86_tieable_integer_mode_p (machine_mode mode)
21670 : : {
21671 : 50261599 : switch (mode)
21672 : : {
21673 : : case E_HImode:
21674 : : case E_SImode:
21675 : : return true;
21676 : :
21677 : 5251753 : case E_QImode:
21678 : 5251753 : return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
21679 : :
21680 : 9614524 : case E_DImode:
21681 : 9614524 : return TARGET_64BIT;
21682 : :
21683 : : default:
21684 : : return false;
21685 : : }
21686 : : }
21687 : :
21688 : : /* Implement TARGET_MODES_TIEABLE_P.
21689 : :
21690 : : Return true if MODE1 is accessible in a register that can hold MODE2
21691 : : without copying. That is, all register classes that can hold MODE2
21692 : : can also hold MODE1. */
21693 : :
21694 : : static bool
21695 : 32591639 : ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2)
21696 : : {
21697 : 32591639 : if (mode1 == mode2)
21698 : : return true;
21699 : :
21700 : 32500384 : if (ix86_tieable_integer_mode_p (mode1)
21701 : 32500384 : && ix86_tieable_integer_mode_p (mode2))
21702 : : return true;
21703 : :
21704 : : /* MODE2 being XFmode implies fp stack or general regs, which means we
21705 : : can tie any smaller floating point modes to it. Note that we do not
21706 : : tie this with TFmode. */
21707 : 24249068 : if (mode2 == XFmode)
21708 : 4373 : return mode1 == SFmode || mode1 == DFmode;
21709 : :
21710 : : /* MODE2 being DFmode implies fp stack, general or sse regs, which means
21711 : : that we can tie it with SFmode. */
21712 : 24244695 : if (mode2 == DFmode)
21713 : 257647 : return mode1 == SFmode;
21714 : :
21715 : : /* If MODE2 is only appropriate for an SSE register, then tie with
21716 : : any vector modes or scalar floating point modes acceptable to SSE
21717 : : registers, excluding scalar integer modes with SUBREG:
21718 : : (subreg:QI (reg:TI 99) 0))
21719 : : (subreg:HI (reg:TI 99) 0))
21720 : : (subreg:SI (reg:TI 99) 0))
21721 : : (subreg:DI (reg:TI 99) 0))
21722 : : to avoid unnecessary move from SSE register to integer register.
21723 : : */
21724 : 23987048 : if (GET_MODE_SIZE (mode2) >= 16
21725 : 37540832 : && (GET_MODE_SIZE (mode1) == GET_MODE_SIZE (mode2)
21726 : 13496361 : || ((VECTOR_MODE_P (mode1) || SCALAR_FLOAT_MODE_P (mode1))
21727 : 446464 : && GET_MODE_SIZE (mode1) <= GET_MODE_SIZE (mode2)))
21728 : 29483746 : && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
21729 : 5069372 : return ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1);
21730 : :
21731 : : /* If MODE2 is appropriate for an MMX register, then tie
21732 : : with any other mode acceptable to MMX registers. */
21733 : 18917676 : if (GET_MODE_SIZE (mode2) == 8
21734 : 18917676 : && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
21735 : 3237067 : return (GET_MODE_SIZE (mode1) == 8
21736 : 3237067 : && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
21737 : :
21738 : : /* SCmode and DImode can be tied. */
21739 : 15680609 : if ((mode1 == E_SCmode && mode2 == E_DImode)
21740 : 15680609 : || (mode1 == E_DImode && mode2 == E_SCmode))
21741 : 108 : return TARGET_64BIT;
21742 : :
21743 : : /* [SD]Cmode and V2[SD]Fmode modes can be tied. */
21744 : 15680501 : if ((mode1 == E_SCmode && mode2 == E_V2SFmode)
21745 : 15680501 : || (mode1 == E_V2SFmode && mode2 == E_SCmode)
21746 : 15680501 : || (mode1 == E_DCmode && mode2 == E_V2DFmode)
21747 : 15680501 : || (mode1 == E_V2DFmode && mode2 == E_DCmode))
21748 : 0 : return true;
21749 : :
21750 : : return false;
21751 : : }
21752 : :
21753 : : /* Return the cost of moving between two registers of mode MODE. */
21754 : :
21755 : : static int
21756 : 31475816 : ix86_set_reg_reg_cost (machine_mode mode)
21757 : : {
21758 : 31475816 : unsigned int units = UNITS_PER_WORD;
21759 : :
21760 : 31475816 : switch (GET_MODE_CLASS (mode))
21761 : : {
21762 : : default:
21763 : : break;
21764 : :
21765 : : case MODE_CC:
21766 : 31475816 : units = GET_MODE_SIZE (CCmode);
21767 : : break;
21768 : :
21769 : 1154836 : case MODE_FLOAT:
21770 : 1154836 : if ((TARGET_SSE && mode == TFmode)
21771 : 676413 : || (TARGET_80387 && mode == XFmode)
21772 : 209348 : || ((TARGET_80387 || TARGET_SSE2) && mode == DFmode)
21773 : 141681 : || ((TARGET_80387 || TARGET_SSE) && mode == SFmode))
21774 : 2280144 : units = GET_MODE_SIZE (mode);
21775 : : break;
21776 : :
21777 : 1290156 : case MODE_COMPLEX_FLOAT:
21778 : 1290156 : if ((TARGET_SSE && mode == TCmode)
21779 : 864964 : || (TARGET_80387 && mode == XCmode)
21780 : 439654 : || ((TARGET_80387 || TARGET_SSE2) && mode == DCmode)
21781 : 14330 : || ((TARGET_80387 || TARGET_SSE) && mode == SCmode))
21782 : 2573984 : units = GET_MODE_SIZE (mode);
21783 : : break;
21784 : :
21785 : 21024010 : case MODE_VECTOR_INT:
21786 : 21024010 : case MODE_VECTOR_FLOAT:
21787 : 21024010 : if ((TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
21788 : 20928585 : || (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
21789 : 20757371 : || (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
21790 : 18162818 : || (TARGET_SSE && VALID_SSE_REG_MODE (mode))
21791 : 16872073 : || ((TARGET_MMX || TARGET_MMX_WITH_SSE)
21792 : 16821195 : && VALID_MMX_REG_MODE (mode)))
21793 : 8409556 : units = GET_MODE_SIZE (mode);
21794 : : }
21795 : :
21796 : : /* Return the cost of moving between two registers of mode MODE,
21797 : : assuming that the move will be in pieces of at most UNITS bytes. */
21798 : 31475816 : return COSTS_N_INSNS (CEIL (GET_MODE_SIZE (mode), units));
21799 : : }
21800 : :
21801 : : /* Return cost of vector operation in MODE given that scalar version has
21802 : : COST. */
21803 : :
21804 : : static int
21805 : 2887922393 : ix86_vec_cost (machine_mode mode, int cost)
21806 : : {
21807 : 2887922393 : if (!VECTOR_MODE_P (mode))
21808 : : return cost;
21809 : :
21810 : 2887495596 : if (GET_MODE_BITSIZE (mode) == 128
21811 : 2887495596 : && TARGET_SSE_SPLIT_REGS)
21812 : 2801674 : return cost * GET_MODE_BITSIZE (mode) / 64;
21813 : 2886094759 : else if (GET_MODE_BITSIZE (mode) > 128
21814 : 2886094759 : && TARGET_AVX256_SPLIT_REGS)
21815 : 1724294 : return cost * GET_MODE_BITSIZE (mode) / 128;
21816 : 2885232612 : else if (GET_MODE_BITSIZE (mode) > 256
21817 : 2885232612 : && TARGET_AVX512_SPLIT_REGS)
21818 : 199142 : return cost * GET_MODE_BITSIZE (mode) / 256;
21819 : : return cost;
21820 : : }
21821 : :
21822 : : /* Return cost of vec_widen_<s>mult_hi/lo_<mode>,
21823 : : vec_widen_<s>mul_hi/lo_<mode> is only available for VI124_AVX2. */
21824 : : static int
21825 : 1714 : ix86_widen_mult_cost (const struct processor_costs *cost,
21826 : : enum machine_mode mode, bool uns_p)
21827 : : {
21828 : 1714 : gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT);
21829 : 1714 : int extra_cost = 0;
21830 : 1714 : int basic_cost = 0;
21831 : 1714 : switch (mode)
21832 : : {
21833 : 135 : case V8HImode:
21834 : 135 : case V16HImode:
21835 : 135 : if (!uns_p || mode == V16HImode)
21836 : 31 : extra_cost = cost->sse_op * 2;
21837 : 135 : basic_cost = cost->mulss * 2 + cost->sse_op * 4;
21838 : 135 : break;
21839 : 234 : case V4SImode:
21840 : 234 : case V8SImode:
21841 : : /* pmulhw/pmullw can be used. */
21842 : 234 : basic_cost = cost->mulss * 2 + cost->sse_op * 2;
21843 : 234 : break;
21844 : 1251 : case V2DImode:
21845 : : /* pmuludq under sse2, pmuldq under sse4.1, for sign_extend,
21846 : : require extra 4 mul, 4 add, 4 cmp and 2 shift. */
21847 : 1251 : if (!TARGET_SSE4_1 && !uns_p)
21848 : 784 : extra_cost = (cost->mulss + cost->sse_op + cost->sse_op) * 4
21849 : 784 : + cost->sse_op * 2;
21850 : : /* Fallthru. */
21851 : 1333 : case V4DImode:
21852 : 1333 : basic_cost = cost->mulss * 2 + cost->sse_op * 4;
21853 : 1333 : break;
21854 : : default:
21855 : : /* Not implemented. */
21856 : : return 100;
21857 : : }
21858 : 1702 : return ix86_vec_cost (mode, basic_cost + extra_cost);
21859 : : }
21860 : :
21861 : : /* Return cost of multiplication in MODE. */
21862 : :
21863 : : static int
21864 : 1232634690 : ix86_multiplication_cost (const struct processor_costs *cost,
21865 : : enum machine_mode mode)
21866 : : {
21867 : 1232634690 : machine_mode inner_mode = mode;
21868 : 1232634690 : if (VECTOR_MODE_P (mode))
21869 : 1231670752 : inner_mode = GET_MODE_INNER (mode);
21870 : :
21871 : 1232634690 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
21872 : 725560 : return inner_mode == DFmode ? cost->mulsd : cost->mulss;
21873 : 1231909130 : else if (X87_FLOAT_MODE_P (mode))
21874 : 163068 : return cost->fmul;
21875 : 1231746062 : else if (FLOAT_MODE_P (mode))
21876 : 188261 : return ix86_vec_cost (mode,
21877 : 188261 : inner_mode == DFmode ? cost->mulsd : cost->mulss);
21878 : 1231557801 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
21879 : : {
21880 : 1231506741 : int nmults, nops;
21881 : : /* Cost of reading the memory. */
21882 : 1231506741 : int extra;
21883 : :
21884 : 1231506741 : switch (mode)
21885 : : {
21886 : 18760749 : case V4QImode:
21887 : 18760749 : case V8QImode:
21888 : : /* Partial V*QImode is emulated with 4-6 insns. */
21889 : 18760749 : nmults = 1;
21890 : 18760749 : nops = 3;
21891 : 18760749 : extra = 0;
21892 : :
21893 : 18760749 : if (TARGET_AVX512BW && TARGET_AVX512VL)
21894 : : ;
21895 : 18667352 : else if (TARGET_AVX2)
21896 : : nops += 2;
21897 : 18154379 : else if (TARGET_XOP)
21898 : 9504 : extra += COSTS_N_INSNS (cost->sse_load[2]) / 2;
21899 : : else
21900 : : {
21901 : 18144875 : nops += 1;
21902 : 18144875 : extra += COSTS_N_INSNS (cost->sse_load[2]) / 2;
21903 : : }
21904 : 18760749 : goto do_qimode;
21905 : :
21906 : 9381568 : case V16QImode:
21907 : : /* V*QImode is emulated with 4-11 insns. */
21908 : 9381568 : nmults = 1;
21909 : 9381568 : nops = 3;
21910 : 9381568 : extra = 0;
21911 : :
21912 : 9381568 : if (TARGET_AVX2 && !TARGET_PREFER_AVX128)
21913 : : {
21914 : 301457 : if (!(TARGET_AVX512BW && TARGET_AVX512VL))
21915 : 255073 : nops += 3;
21916 : : }
21917 : 9080111 : else if (TARGET_XOP)
21918 : : {
21919 : 5200 : nmults += 1;
21920 : 5200 : nops += 2;
21921 : 5200 : extra += COSTS_N_INSNS (cost->sse_load[2]) / 2;
21922 : : }
21923 : : else
21924 : : {
21925 : 9074911 : nmults += 1;
21926 : 9074911 : nops += 4;
21927 : 9074911 : extra += COSTS_N_INSNS (cost->sse_load[2]) / 2;
21928 : : }
21929 : 9381568 : goto do_qimode;
21930 : :
21931 : 9380251 : case V32QImode:
21932 : 9380251 : nmults = 1;
21933 : 9380251 : nops = 3;
21934 : 9380251 : extra = 0;
21935 : :
21936 : 9380251 : if (!TARGET_AVX512BW || TARGET_PREFER_AVX256)
21937 : : {
21938 : 9301998 : nmults += 1;
21939 : 9301998 : nops += 4;
21940 : : /* 2 loads, so no division by 2. */
21941 : 9301998 : extra += COSTS_N_INSNS (cost->sse_load[3]);
21942 : : }
21943 : 9380251 : goto do_qimode;
21944 : :
21945 : 9379628 : case V64QImode:
21946 : 9379628 : nmults = 2;
21947 : 9379628 : nops = 9;
21948 : : /* 2 loads of each size, so no division by 2. */
21949 : 9379628 : extra = COSTS_N_INSNS (cost->sse_load[3] + cost->sse_load[4]);
21950 : :
21951 : 46902196 : do_qimode:
21952 : 46902196 : return ix86_vec_cost (mode, cost->mulss * nmults
21953 : 46902196 : + cost->sse_op * nops) + extra;
21954 : :
21955 : 40110089 : case V4SImode:
21956 : : /* pmulld is used in this case. No emulation is needed. */
21957 : 40110089 : if (TARGET_SSE4_1)
21958 : 2206336 : goto do_native;
21959 : : /* V4SImode is emulated with 7 insns. */
21960 : : else
21961 : 37903753 : return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5);
21962 : :
21963 : 162127226 : case V2DImode:
21964 : 162127226 : case V4DImode:
21965 : : /* vpmullq is used in this case. No emulation is needed. */
21966 : 162127226 : if (TARGET_AVX512DQ && TARGET_AVX512VL)
21967 : 473594 : goto do_native;
21968 : : /* V*DImode is emulated with 6-8 insns. */
21969 : 161653632 : else if (TARGET_XOP && mode == V2DImode)
21970 : 52530 : return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 4);
21971 : : /* FALLTHRU */
21972 : 242608490 : case V8DImode:
21973 : : /* vpmullq is used in this case. No emulation is needed. */
21974 : 242608490 : if (TARGET_AVX512DQ && mode == V8DImode)
21975 : 332574 : goto do_native;
21976 : : else
21977 : 242275916 : return ix86_vec_cost (mode, cost->mulss * 3 + cost->sse_op * 5);
21978 : :
21979 : 904372346 : default:
21980 : 904372346 : do_native:
21981 : 904372346 : return ix86_vec_cost (mode, cost->mulss);
21982 : : }
21983 : : }
21984 : : else
21985 : 102119 : return (cost->mult_init[MODE_INDEX (mode)] + cost->mult_bit * 7);
21986 : : }
21987 : :
21988 : : /* Return cost of multiplication in MODE. */
21989 : :
21990 : : static int
21991 : 73303379 : ix86_division_cost (const struct processor_costs *cost,
21992 : : enum machine_mode mode)
21993 : : {
21994 : 73303379 : machine_mode inner_mode = mode;
21995 : 73303379 : if (VECTOR_MODE_P (mode))
21996 : 54585290 : inner_mode = GET_MODE_INNER (mode);
21997 : :
21998 : 73303379 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
21999 : 250902 : return inner_mode == DFmode ? cost->divsd : cost->divss;
22000 : 73052477 : else if (X87_FLOAT_MODE_P (mode))
22001 : 44936 : return cost->fdiv;
22002 : 73007541 : else if (FLOAT_MODE_P (mode))
22003 : 16660 : return ix86_vec_cost (mode,
22004 : 16660 : inner_mode == DFmode ? cost->divsd : cost->divss);
22005 : : else
22006 : 81179316 : return cost->divide[MODE_INDEX (mode)];
22007 : : }
22008 : :
22009 : : /* Return cost of shift in MODE.
22010 : : If CONSTANT_OP1 is true, the op1 value is known and set in OP1_VAL.
22011 : : AND_IN_OP1 specify in op1 is result of AND and SHIFT_AND_TRUNCATE
22012 : : if op1 is a result of subreg.
22013 : :
22014 : : SKIP_OP0/1 is set to true if cost of OP0/1 should be ignored. */
22015 : :
22016 : : static int
22017 : 778674445 : ix86_shift_rotate_cost (const struct processor_costs *cost,
22018 : : enum rtx_code code,
22019 : : enum machine_mode mode, bool constant_op1,
22020 : : HOST_WIDE_INT op1_val,
22021 : : bool and_in_op1,
22022 : : bool shift_and_truncate,
22023 : : bool *skip_op0, bool *skip_op1)
22024 : : {
22025 : 778674445 : if (skip_op0)
22026 : 778634108 : *skip_op0 = *skip_op1 = false;
22027 : :
22028 : 778674445 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22029 : : {
22030 : 406496348 : int count;
22031 : : /* Cost of reading the memory. */
22032 : 406496348 : int extra;
22033 : :
22034 : 406496348 : switch (mode)
22035 : : {
22036 : 5968804 : case V4QImode:
22037 : 5968804 : case V8QImode:
22038 : 5968804 : if (TARGET_AVX2)
22039 : : /* Use vpbroadcast. */
22040 : 192760 : extra = cost->sse_op;
22041 : : else
22042 : 5776044 : extra = COSTS_N_INSNS (cost->sse_load[2]) / 2;
22043 : :
22044 : 5968804 : if (constant_op1)
22045 : : {
22046 : 5968776 : if (code == ASHIFTRT)
22047 : : {
22048 : 20 : count = 4;
22049 : 20 : extra *= 2;
22050 : : }
22051 : : else
22052 : : count = 2;
22053 : : }
22054 : 28 : else if (TARGET_AVX512BW && TARGET_AVX512VL)
22055 : 28 : return ix86_vec_cost (mode, cost->sse_op * 4);
22056 : 0 : else if (TARGET_SSE4_1)
22057 : : count = 5;
22058 : 0 : else if (code == ASHIFTRT)
22059 : : count = 6;
22060 : : else
22061 : 0 : count = 5;
22062 : 5968776 : return ix86_vec_cost (mode, cost->sse_op * count) + extra;
22063 : :
22064 : 2986545 : case V16QImode:
22065 : 2986545 : if (TARGET_XOP)
22066 : : {
22067 : : /* For XOP we use vpshab, which requires a broadcast of the
22068 : : value to the variable shift insn. For constants this
22069 : : means a V16Q const in mem; even when we can perform the
22070 : : shift with one insn set the cost to prefer paddb. */
22071 : 3360 : if (constant_op1)
22072 : : {
22073 : 2428 : extra = COSTS_N_INSNS (cost->sse_load[2]) / 2;
22074 : 2428 : return ix86_vec_cost (mode, cost->sse_op) + extra;
22075 : : }
22076 : : else
22077 : : {
22078 : 932 : count = (code == ASHIFT) ? 3 : 4;
22079 : 932 : return ix86_vec_cost (mode, cost->sse_op * count);
22080 : : }
22081 : : }
22082 : : /* FALLTHRU */
22083 : 5967593 : case V32QImode:
22084 : 5967593 : if (TARGET_AVX2)
22085 : : /* Use vpbroadcast. */
22086 : 192244 : extra = cost->sse_op;
22087 : : else
22088 : 5775349 : extra = COSTS_N_INSNS (mode == V16QImode
22089 : : ? cost->sse_load[2]
22090 : 5775349 : : cost->sse_load[3]) / 2;
22091 : :
22092 : 5967593 : if (constant_op1)
22093 : : {
22094 : 5967490 : if (code == ASHIFTRT)
22095 : : {
22096 : 104 : count = 4;
22097 : 104 : extra *= 2;
22098 : : }
22099 : : else
22100 : : count = 2;
22101 : : }
22102 : 103 : else if (TARGET_AVX512BW
22103 : 75 : && ((mode == V32QImode && !TARGET_PREFER_AVX256)
22104 : 37 : || (mode == V16QImode && TARGET_AVX512VL
22105 : 37 : && !TARGET_PREFER_AVX128)))
22106 : 75 : return ix86_vec_cost (mode, cost->sse_op * 4);
22107 : 28 : else if (TARGET_AVX2
22108 : 0 : && mode == V16QImode && !TARGET_PREFER_AVX128)
22109 : : count = 6;
22110 : 28 : else if (TARGET_SSE4_1)
22111 : : count = 9;
22112 : 28 : else if (code == ASHIFTRT)
22113 : : count = 10;
22114 : : else
22115 : 28 : count = 9;
22116 : 5967518 : return ix86_vec_cost (mode, cost->sse_op * count) + extra;
22117 : :
22118 : 53802996 : case V2DImode:
22119 : 53802996 : case V4DImode:
22120 : : /* V*DImode arithmetic right shift is emulated. */
22121 : 53802996 : if (code == ASHIFTRT && !TARGET_AVX512VL)
22122 : : {
22123 : 1169 : if (constant_op1)
22124 : : {
22125 : 478 : if (op1_val == 63)
22126 : 401 : count = TARGET_SSE4_2 ? 1 : 2;
22127 : 376 : else if (TARGET_XOP)
22128 : : count = 2;
22129 : 77 : else if (TARGET_SSE4_1)
22130 : : count = 3;
22131 : : else
22132 : 75 : count = 4;
22133 : : }
22134 : 691 : else if (TARGET_XOP)
22135 : : count = 3;
22136 : 10 : else if (TARGET_SSE4_2)
22137 : : count = 4;
22138 : : else
22139 : 1169 : count = 5;
22140 : :
22141 : 1169 : return ix86_vec_cost (mode, cost->sse_op * count);
22142 : : }
22143 : : /* FALLTHRU */
22144 : 394555422 : default:
22145 : 394555422 : return ix86_vec_cost (mode, cost->sse_op);
22146 : : }
22147 : : }
22148 : :
22149 : 752969395 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22150 : : {
22151 : 190561922 : if (constant_op1)
22152 : : {
22153 : 190527173 : if (op1_val > 32)
22154 : 135353096 : return cost->shift_const + COSTS_N_INSNS (2);
22155 : : else
22156 : 55174077 : return cost->shift_const * 2;
22157 : : }
22158 : : else
22159 : : {
22160 : 34749 : if (and_in_op1)
22161 : 63 : return cost->shift_var * 2;
22162 : : else
22163 : 34686 : return cost->shift_var * 6 + COSTS_N_INSNS (2);
22164 : : }
22165 : : }
22166 : : else
22167 : : {
22168 : 181616175 : if (constant_op1)
22169 : 180885724 : return cost->shift_const;
22170 : 730451 : else if (shift_and_truncate)
22171 : : {
22172 : 22712 : if (skip_op0)
22173 : 22712 : *skip_op0 = *skip_op1 = true;
22174 : : /* Return the cost after shift-and truncation. */
22175 : 22712 : return cost->shift_var;
22176 : : }
22177 : : else
22178 : 707739 : return cost->shift_var;
22179 : : }
22180 : : }
22181 : :
22182 : : static int
22183 : 142769518 : ix86_insn_cost (rtx_insn *insn, bool speed)
22184 : : {
22185 : 142769518 : int insn_cost = 0;
22186 : : /* Add extra cost to avoid post_reload late_combine revert
22187 : : the optimization did in pass_rpad. */
22188 : 142769518 : if (reload_completed
22189 : 4403860 : && ix86_rpad_gate ()
22190 : 268830 : && recog_memoized (insn) >= 0
22191 : 143038200 : && get_attr_avx_partial_xmm_update (insn)
22192 : : == AVX_PARTIAL_XMM_UPDATE_TRUE)
22193 : : insn_cost += COSTS_N_INSNS (3);
22194 : :
22195 : 142769518 : return insn_cost + pattern_cost (PATTERN (insn), speed);
22196 : : }
22197 : :
22198 : : /* Return cost of SSE/AVX FP->FP conversion (extensions and truncates). */
22199 : :
22200 : : static int
22201 : 736479 : vec_fp_conversion_cost (const struct processor_costs *cost, int size)
22202 : : {
22203 : 736479 : if (size < 128)
22204 : 733303 : return cost->cvtss2sd;
22205 : 3176 : else if (size < 256)
22206 : : {
22207 : 1379 : if (TARGET_SSE_SPLIT_REGS)
22208 : 0 : return cost->cvtss2sd * size / 64;
22209 : 1379 : return cost->cvtss2sd;
22210 : : }
22211 : 1797 : if (size < 512)
22212 : 658 : return cost->vcvtps2pd256;
22213 : : else
22214 : 1139 : return cost->vcvtps2pd512;
22215 : : }
22216 : :
22217 : : /* Return true of X is UNSPEC with UNSPEC_PCMP or UNSPEC_UNSIGNED_PCMP. */
22218 : :
22219 : : static bool
22220 : 231676 : unspec_pcmp_p (rtx x)
22221 : : {
22222 : 231676 : return GET_CODE (x) == UNSPEC
22223 : 231676 : && (XINT (x, 1) == UNSPEC_PCMP || XINT (x, 1) == UNSPEC_UNSIGNED_PCMP);
22224 : : }
22225 : :
22226 : : /* Compute a (partial) cost for rtx X. Return true if the complete
22227 : : cost has been computed, and false if subexpressions should be
22228 : : scanned. In either case, *TOTAL contains the cost result. */
22229 : :
22230 : : static bool
22231 : 7746268486 : ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno,
22232 : : int *total, bool speed)
22233 : : {
22234 : 7746268486 : rtx mask;
22235 : 7746268486 : enum rtx_code code = GET_CODE (x);
22236 : 7746268486 : enum rtx_code outer_code = (enum rtx_code) outer_code_i;
22237 : 4137356701 : const struct processor_costs *cost
22238 : 7746268486 : = speed ? ix86_tune_cost : &ix86_size_cost;
22239 : 7746268486 : int src_cost;
22240 : :
22241 : : /* Handling different vternlog variants. */
22242 : 7746268486 : if ((GET_MODE_SIZE (mode) == 64
22243 : 7746268486 : ? TARGET_AVX512F
22244 : 6577035522 : : (TARGET_AVX512VL
22245 : 6519362446 : || (TARGET_AVX512F && !TARGET_PREFER_AVX256)))
22246 : 179419376 : && GET_MODE_SIZE (mode) >= 16
22247 : 123493719 : && outer_code_i == SET
22248 : 7793815151 : && ternlog_operand (x, mode))
22249 : : {
22250 : 32714 : rtx args[3];
22251 : :
22252 : 32714 : args[0] = NULL_RTX;
22253 : 32714 : args[1] = NULL_RTX;
22254 : 32714 : args[2] = NULL_RTX;
22255 : 32714 : int idx = ix86_ternlog_idx (x, args);
22256 : 32714 : gcc_assert (idx >= 0);
22257 : :
22258 : 32714 : *total = cost->sse_op;
22259 : 130856 : for (int i = 0; i != 3; i++)
22260 : 98142 : if (args[i])
22261 : 69660 : *total += rtx_cost (args[i], GET_MODE (args[i]), UNSPEC, i, speed);
22262 : 32714 : return true;
22263 : : }
22264 : :
22265 : :
22266 : 7746235772 : switch (code)
22267 : : {
22268 : 50143331 : case SET:
22269 : 50143331 : if (register_operand (SET_DEST (x), VOIDmode)
22270 : 50143331 : && register_operand (SET_SRC (x), VOIDmode))
22271 : : {
22272 : 31475816 : *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
22273 : 31475816 : return true;
22274 : : }
22275 : :
22276 : 18667515 : if (register_operand (SET_SRC (x), VOIDmode))
22277 : : /* Avoid potentially incorrect high cost from rtx_costs
22278 : : for non-tieable SUBREGs. */
22279 : : src_cost = 0;
22280 : : else
22281 : : {
22282 : 16023457 : src_cost = rtx_cost (SET_SRC (x), mode, SET, 1, speed);
22283 : :
22284 : 16023457 : if (CONSTANT_P (SET_SRC (x)))
22285 : : /* Constant costs assume a base value of COSTS_N_INSNS (1) and add
22286 : : a small value, possibly zero for cheap constants. */
22287 : 7066396 : src_cost += COSTS_N_INSNS (1);
22288 : : }
22289 : :
22290 : 18667515 : *total = src_cost + rtx_cost (SET_DEST (x), mode, SET, 0, speed);
22291 : 18667515 : return true;
22292 : :
22293 : 2851439428 : case CONST_INT:
22294 : 2851439428 : case CONST:
22295 : 2851439428 : case LABEL_REF:
22296 : 2851439428 : case SYMBOL_REF:
22297 : 2851439428 : if (x86_64_immediate_operand (x, VOIDmode))
22298 : 2253180724 : *total = 0;
22299 : 598258704 : else if (TARGET_64BIT && x86_64_zext_immediate_operand (x, VOIDmode))
22300 : : /* Consider the zext constants slightly more expensive, as they
22301 : : can't appear in most instructions. */
22302 : 28962403 : *total = 1;
22303 : : else
22304 : : /* movabsq is slightly more expensive than a simple instruction. */
22305 : 569296301 : *total = COSTS_N_INSNS (1) + 1;
22306 : : return true;
22307 : :
22308 : 7540789 : case CONST_DOUBLE:
22309 : 7540789 : if (IS_STACK_MODE (mode))
22310 : 1311365 : switch (standard_80387_constant_p (x))
22311 : : {
22312 : : case -1:
22313 : : case 0:
22314 : : break;
22315 : 280316 : case 1: /* 0.0 */
22316 : 280316 : *total = 1;
22317 : 280316 : return true;
22318 : 485534 : default: /* Other constants */
22319 : 485534 : *total = 2;
22320 : 485534 : return true;
22321 : : }
22322 : : /* FALLTHRU */
22323 : :
22324 : 14005506 : case CONST_VECTOR:
22325 : 14005506 : switch (standard_sse_constant_p (x, mode))
22326 : : {
22327 : : case 0:
22328 : : break;
22329 : 3948792 : case 1: /* 0: xor eliminates false dependency */
22330 : 3948792 : *total = 0;
22331 : 3948792 : return true;
22332 : 154359 : default: /* -1: cmp contains false dependency */
22333 : 154359 : *total = 1;
22334 : 154359 : return true;
22335 : : }
22336 : : /* FALLTHRU */
22337 : :
22338 : 10901840 : case CONST_WIDE_INT:
22339 : : /* Fall back to (MEM (SYMBOL_REF)), since that's where
22340 : : it'll probably end up. Add a penalty for size. */
22341 : 21803680 : *total = (COSTS_N_INSNS (1)
22342 : 21578667 : + (!TARGET_64BIT && flag_pic)
22343 : 21803680 : + (GET_MODE_SIZE (mode) <= 4
22344 : 19046955 : ? 0 : GET_MODE_SIZE (mode) <= 8 ? 1 : 2));
22345 : 10901840 : return true;
22346 : :
22347 : 22131545 : case ZERO_EXTEND:
22348 : : /* The zero extensions is often completely free on x86_64, so make
22349 : : it as cheap as possible. */
22350 : 22131545 : if (TARGET_64BIT && mode == DImode
22351 : 4695643 : && GET_MODE (XEXP (x, 0)) == SImode)
22352 : 2716073 : *total = 1;
22353 : 19415472 : else if (TARGET_ZERO_EXTEND_WITH_AND)
22354 : 0 : *total = cost->add;
22355 : : else
22356 : 19415472 : *total = cost->movzx;
22357 : : return false;
22358 : :
22359 : 3099047 : case SIGN_EXTEND:
22360 : 3099047 : *total = cost->movsx;
22361 : 3099047 : return false;
22362 : :
22363 : 642951245 : case ASHIFT:
22364 : 642951245 : if (SCALAR_INT_MODE_P (mode)
22365 : 243314099 : && GET_MODE_SIZE (mode) < UNITS_PER_WORD
22366 : 685615284 : && CONST_INT_P (XEXP (x, 1)))
22367 : : {
22368 : 42500788 : HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
22369 : 42500788 : if (value == 1)
22370 : : {
22371 : 2479184 : *total = cost->add;
22372 : 2479184 : return false;
22373 : : }
22374 : 40021604 : if ((value == 2 || value == 3)
22375 : 4527000 : && cost->lea <= cost->shift_const)
22376 : : {
22377 : 2120716 : *total = cost->lea;
22378 : 2120716 : return false;
22379 : : }
22380 : : }
22381 : : /* FALLTHRU */
22382 : :
22383 : 778634108 : case ROTATE:
22384 : 778634108 : case ASHIFTRT:
22385 : 778634108 : case LSHIFTRT:
22386 : 778634108 : case ROTATERT:
22387 : 778634108 : bool skip_op0, skip_op1;
22388 : 778634108 : *total = ix86_shift_rotate_cost (cost, code, mode,
22389 : 778634108 : CONSTANT_P (XEXP (x, 1)),
22390 : : CONST_INT_P (XEXP (x, 1))
22391 : : ? INTVAL (XEXP (x, 1)) : -1,
22392 : : GET_CODE (XEXP (x, 1)) == AND,
22393 : 778634108 : SUBREG_P (XEXP (x, 1))
22394 : 778634108 : && GET_CODE (XEXP (XEXP (x, 1),
22395 : : 0)) == AND,
22396 : : &skip_op0, &skip_op1);
22397 : 778634108 : if (skip_op0 || skip_op1)
22398 : : {
22399 : 22712 : if (!skip_op0)
22400 : 0 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
22401 : 22712 : if (!skip_op1)
22402 : 0 : *total += rtx_cost (XEXP (x, 1), mode, code, 0, speed);
22403 : 22712 : return true;
22404 : : }
22405 : : return false;
22406 : :
22407 : 219795 : case FMA:
22408 : 219795 : {
22409 : 219795 : rtx sub;
22410 : :
22411 : 219795 : gcc_assert (FLOAT_MODE_P (mode));
22412 : 219795 : gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F);
22413 : :
22414 : 439590 : *total = ix86_vec_cost (mode,
22415 : 219795 : GET_MODE_INNER (mode) == SFmode
22416 : : ? cost->fmass : cost->fmasd);
22417 : 219795 : *total += rtx_cost (XEXP (x, 1), mode, FMA, 1, speed);
22418 : :
22419 : : /* Negate in op0 or op2 is free: FMS, FNMA, FNMS. */
22420 : 219795 : sub = XEXP (x, 0);
22421 : 219795 : if (GET_CODE (sub) == NEG)
22422 : 53324 : sub = XEXP (sub, 0);
22423 : 219795 : *total += rtx_cost (sub, mode, FMA, 0, speed);
22424 : :
22425 : 219795 : sub = XEXP (x, 2);
22426 : 219795 : if (GET_CODE (sub) == NEG)
22427 : 40050 : sub = XEXP (sub, 0);
22428 : 219795 : *total += rtx_cost (sub, mode, FMA, 2, speed);
22429 : 219795 : return true;
22430 : : }
22431 : :
22432 : 1777115369 : case MULT:
22433 : 1777115369 : if (!FLOAT_MODE_P (mode) && !VECTOR_MODE_P (mode))
22434 : : {
22435 : 544637366 : rtx op0 = XEXP (x, 0);
22436 : 544637366 : rtx op1 = XEXP (x, 1);
22437 : 544637366 : int nbits;
22438 : 544637366 : if (CONST_INT_P (XEXP (x, 1)))
22439 : : {
22440 : 526785510 : unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
22441 : 1069647897 : for (nbits = 0; value != 0; value &= value - 1)
22442 : 542862387 : nbits++;
22443 : : }
22444 : : else
22445 : : /* This is arbitrary. */
22446 : : nbits = 7;
22447 : :
22448 : : /* Compute costs correctly for widening multiplication. */
22449 : 544637366 : if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
22450 : 550090533 : && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
22451 : 5453167 : == GET_MODE_SIZE (mode))
22452 : : {
22453 : 5449076 : int is_mulwiden = 0;
22454 : 5449076 : machine_mode inner_mode = GET_MODE (op0);
22455 : :
22456 : 5449076 : if (GET_CODE (op0) == GET_CODE (op1))
22457 : 5363002 : is_mulwiden = 1, op1 = XEXP (op1, 0);
22458 : 86074 : else if (CONST_INT_P (op1))
22459 : : {
22460 : 75976 : if (GET_CODE (op0) == SIGN_EXTEND)
22461 : 22305 : is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
22462 : 22305 : == INTVAL (op1);
22463 : : else
22464 : 53671 : is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
22465 : : }
22466 : :
22467 : 5438978 : if (is_mulwiden)
22468 : 5438978 : op0 = XEXP (op0, 0), mode = GET_MODE (op0);
22469 : : }
22470 : :
22471 : 544637366 : int mult_init;
22472 : : // Double word multiplication requires 3 mults and 2 adds.
22473 : 1104804448 : if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22474 : : {
22475 : 327898518 : mult_init = 3 * cost->mult_init[MODE_INDEX (word_mode)]
22476 : 327898518 : + 2 * cost->add;
22477 : 327898518 : nbits *= 3;
22478 : : }
22479 : 373791496 : else mult_init = cost->mult_init[MODE_INDEX (mode)];
22480 : :
22481 : 1089274732 : *total = (mult_init
22482 : 544637366 : + nbits * cost->mult_bit
22483 : 544637366 : + rtx_cost (op0, mode, outer_code, opno, speed)
22484 : 544637366 : + rtx_cost (op1, mode, outer_code, opno, speed));
22485 : :
22486 : 544637366 : return true;
22487 : : }
22488 : 1232478003 : *total = ix86_multiplication_cost (cost, mode);
22489 : 1232478003 : return false;
22490 : :
22491 : 73294758 : case DIV:
22492 : 73294758 : case UDIV:
22493 : 73294758 : case MOD:
22494 : 73294758 : case UMOD:
22495 : 73294758 : *total = ix86_division_cost (cost, mode);
22496 : 73294758 : return false;
22497 : :
22498 : 692445842 : case PLUS:
22499 : 692445842 : if (GET_MODE_CLASS (mode) == MODE_INT
22500 : 943542019 : && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
22501 : : {
22502 : 138650759 : if (GET_CODE (XEXP (x, 0)) == PLUS
22503 : 3108497 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
22504 : 832457 : && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
22505 : 832448 : && CONSTANT_P (XEXP (x, 1)))
22506 : : {
22507 : 832375 : HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
22508 : 832375 : if (val == 2 || val == 4 || val == 8)
22509 : : {
22510 : 832271 : *total = cost->lea;
22511 : 832271 : *total += rtx_cost (XEXP (XEXP (x, 0), 1), mode,
22512 : : outer_code, opno, speed);
22513 : 832271 : *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), mode,
22514 : : outer_code, opno, speed);
22515 : 832271 : *total += rtx_cost (XEXP (x, 1), mode,
22516 : : outer_code, opno, speed);
22517 : 832271 : return true;
22518 : : }
22519 : : }
22520 : 137818384 : else if (GET_CODE (XEXP (x, 0)) == MULT
22521 : 51714074 : && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
22522 : : {
22523 : 51660572 : HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
22524 : 51660572 : if (val == 2 || val == 4 || val == 8)
22525 : : {
22526 : 7893176 : *total = cost->lea;
22527 : 7893176 : *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22528 : : outer_code, opno, speed);
22529 : 7893176 : *total += rtx_cost (XEXP (x, 1), mode,
22530 : : outer_code, opno, speed);
22531 : 7893176 : return true;
22532 : : }
22533 : : }
22534 : 86157812 : else if (GET_CODE (XEXP (x, 0)) == PLUS)
22535 : : {
22536 : 2276122 : rtx op = XEXP (XEXP (x, 0), 0);
22537 : :
22538 : : /* Add with carry, ignore the cost of adding a carry flag. */
22539 : 2276122 : if (ix86_carry_flag_operator (op, mode)
22540 : 2276122 : || ix86_carry_flag_unset_operator (op, mode))
22541 : 78493 : *total = cost->add;
22542 : : else
22543 : : {
22544 : 2197629 : *total = cost->lea;
22545 : 2197629 : *total += rtx_cost (op, mode,
22546 : : outer_code, opno, speed);
22547 : : }
22548 : :
22549 : 2276122 : *total += rtx_cost (XEXP (XEXP (x, 0), 1), mode,
22550 : : outer_code, opno, speed);
22551 : 2276122 : *total += rtx_cost (XEXP (x, 1), mode,
22552 : : outer_code, opno, speed);
22553 : 2276122 : return true;
22554 : : }
22555 : : }
22556 : : /* FALLTHRU */
22557 : :
22558 : 1852411144 : case MINUS:
22559 : : /* Subtract with borrow, ignore the cost of subtracting a carry flag. */
22560 : 1852411144 : if (GET_MODE_CLASS (mode) == MODE_INT
22561 : 511991350 : && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
22562 : 230560058 : && GET_CODE (XEXP (x, 0)) == MINUS
22563 : 1852452897 : && (ix86_carry_flag_operator (XEXP (XEXP (x, 0), 1), mode)
22564 : 12750 : || ix86_carry_flag_unset_operator (XEXP (XEXP (x, 0), 1), mode)))
22565 : : {
22566 : 29003 : *total = cost->add;
22567 : 29003 : *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22568 : : outer_code, opno, speed);
22569 : 29003 : *total += rtx_cost (XEXP (x, 1), mode,
22570 : : outer_code, opno, speed);
22571 : 29003 : return true;
22572 : : }
22573 : :
22574 : 1852382141 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22575 : 2413440 : *total = cost->addss;
22576 : 1849968701 : else if (X87_FLOAT_MODE_P (mode))
22577 : 218598 : *total = cost->fadd;
22578 : 1849750103 : else if (FLOAT_MODE_P (mode))
22579 : 398276 : *total = ix86_vec_cost (mode, cost->addss);
22580 : 1849351827 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22581 : 1232095317 : *total = ix86_vec_cost (mode, cost->sse_op);
22582 : 1273610331 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22583 : 327039255 : *total = cost->add * 2;
22584 : : else
22585 : 290217255 : *total = cost->add;
22586 : : return false;
22587 : :
22588 : 4341725 : case IOR:
22589 : 4341725 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
22590 : 4107299 : || SSE_FLOAT_MODE_P (mode))
22591 : : {
22592 : : /* (ior (not ...) ...) can be a single insn in AVX512. */
22593 : 0 : if (GET_CODE (XEXP (x, 0)) == NOT && TARGET_AVX512F
22594 : 244263 : && (GET_MODE_SIZE (mode) == 64
22595 : 0 : || (TARGET_AVX512VL
22596 : 0 : && (GET_MODE_SIZE (mode) == 32
22597 : 0 : || GET_MODE_SIZE (mode) == 16))))
22598 : : {
22599 : 0 : rtx right = GET_CODE (XEXP (x, 1)) != NOT
22600 : 0 : ? XEXP (x, 1) : XEXP (XEXP (x, 1), 0);
22601 : :
22602 : 0 : *total = ix86_vec_cost (mode, cost->sse_op)
22603 : 0 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22604 : : outer_code, opno, speed)
22605 : 0 : + rtx_cost (right, mode, outer_code, opno, speed);
22606 : 0 : return true;
22607 : : }
22608 : 244263 : *total = ix86_vec_cost (mode, cost->sse_op);
22609 : 244263 : }
22610 : 4097462 : else if (TARGET_64BIT
22611 : 3807759 : && mode == TImode
22612 : 1732866 : && GET_CODE (XEXP (x, 0)) == ASHIFT
22613 : 267565 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND
22614 : 265569 : && GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == DImode
22615 : 265568 : && CONST_INT_P (XEXP (XEXP (x, 0), 1))
22616 : 265568 : && INTVAL (XEXP (XEXP (x, 0), 1)) == 64
22617 : 265568 : && GET_CODE (XEXP (x, 1)) == ZERO_EXTEND
22618 : 240319 : && GET_MODE (XEXP (XEXP (x, 1), 0)) == DImode)
22619 : : {
22620 : : /* *concatditi3 is cheap. */
22621 : 240319 : rtx op0 = XEXP (XEXP (XEXP (x, 0), 0), 0);
22622 : 240319 : rtx op1 = XEXP (XEXP (x, 1), 0);
22623 : 1380 : *total = (SUBREG_P (op0) && GET_MODE (SUBREG_REG (op0)) == DFmode)
22624 : 240319 : ? COSTS_N_INSNS (1) /* movq. */
22625 : 238939 : : set_src_cost (op0, DImode, speed);
22626 : 2282 : *total += (SUBREG_P (op1) && GET_MODE (SUBREG_REG (op1)) == DFmode)
22627 : 240319 : ? COSTS_N_INSNS (1) /* movq. */
22628 : 238050 : : set_src_cost (op1, DImode, speed);
22629 : 240319 : return true;
22630 : : }
22631 : 3857143 : else if (TARGET_64BIT
22632 : 3567440 : && mode == TImode
22633 : 1492547 : && GET_CODE (XEXP (x, 0)) == AND
22634 : 1444170 : && REG_P (XEXP (XEXP (x, 0), 0))
22635 : 1438399 : && CONST_WIDE_INT_P (XEXP (XEXP (x, 0), 1))
22636 : 1438399 : && CONST_WIDE_INT_NUNITS (XEXP (XEXP (x, 0), 1)) == 2
22637 : 1438399 : && CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 0) == -1
22638 : 942283 : && CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 1) == 0
22639 : 942283 : && GET_CODE (XEXP (x, 1)) == ASHIFT
22640 : 940938 : && GET_CODE (XEXP (XEXP (x, 1), 0)) == ZERO_EXTEND
22641 : 940938 : && GET_MODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == DImode
22642 : 940930 : && CONST_INT_P (XEXP (XEXP (x, 1), 1))
22643 : 4798073 : && INTVAL (XEXP (XEXP (x, 1), 1)) == 64)
22644 : : {
22645 : : /* *insvti_highpart is cheap. */
22646 : 940930 : rtx op = XEXP (XEXP (XEXP (x, 1), 0), 0);
22647 : 940930 : *total = COSTS_N_INSNS (1) + 1;
22648 : 1302 : *total += (SUBREG_P (op) && GET_MODE (SUBREG_REG (op)) == DFmode)
22649 : 940930 : ? COSTS_N_INSNS (1) /* movq. */
22650 : 940068 : : set_src_cost (op, DImode, speed);
22651 : 940930 : return true;
22652 : : }
22653 : 6122129 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22654 : 875695 : *total = cost->add * 2;
22655 : : else
22656 : 2040518 : *total = cost->add;
22657 : : return false;
22658 : :
22659 : 558531 : case XOR:
22660 : 558531 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
22661 : 480092 : || SSE_FLOAT_MODE_P (mode))
22662 : 78439 : *total = ix86_vec_cost (mode, cost->sse_op);
22663 : 1024734 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22664 : 16447 : *total = cost->add * 2;
22665 : : else
22666 : 463645 : *total = cost->add;
22667 : : return false;
22668 : :
22669 : 6696074 : case AND:
22670 : 6696074 : if (address_no_seg_operand (x, mode))
22671 : : {
22672 : 14680 : *total = cost->lea;
22673 : 14680 : return true;
22674 : : }
22675 : 6681394 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
22676 : 6332463 : || SSE_FLOAT_MODE_P (mode))
22677 : : {
22678 : : /* pandn is a single instruction. */
22679 : 383230 : if (GET_CODE (XEXP (x, 0)) == NOT)
22680 : : {
22681 : 48206 : rtx right = XEXP (x, 1);
22682 : :
22683 : : /* (and (not ...) (not ...)) can be a single insn in AVX512. */
22684 : 376 : if (GET_CODE (right) == NOT && TARGET_AVX512F
22685 : 48206 : && (GET_MODE_SIZE (mode) == 64
22686 : 0 : || (TARGET_AVX512VL
22687 : 0 : && (GET_MODE_SIZE (mode) == 32
22688 : 0 : || GET_MODE_SIZE (mode) == 16))))
22689 : 0 : right = XEXP (right, 0);
22690 : :
22691 : 48206 : *total = ix86_vec_cost (mode, cost->sse_op)
22692 : 48206 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22693 : : outer_code, opno, speed)
22694 : 48206 : + rtx_cost (right, mode, outer_code, opno, speed);
22695 : 48206 : return true;
22696 : : }
22697 : 335024 : else if (GET_CODE (XEXP (x, 1)) == NOT)
22698 : : {
22699 : 754 : *total = ix86_vec_cost (mode, cost->sse_op)
22700 : 754 : + rtx_cost (XEXP (x, 0), mode,
22701 : : outer_code, opno, speed)
22702 : 754 : + rtx_cost (XEXP (XEXP (x, 1), 0), mode,
22703 : : outer_code, opno, speed);
22704 : 754 : return true;
22705 : : }
22706 : 334270 : *total = ix86_vec_cost (mode, cost->sse_op);
22707 : 334270 : }
22708 : 13230429 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22709 : : {
22710 : 1020232 : if (TARGET_BMI && GET_CODE (XEXP (x,0)) == NOT)
22711 : : {
22712 : 1556 : *total = cost->add * 2
22713 : 778 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22714 : : outer_code, opno, speed)
22715 : 778 : + rtx_cost (XEXP (x, 1), mode,
22716 : : outer_code, opno, speed);
22717 : 778 : return true;
22718 : : }
22719 : 1019454 : else if (TARGET_BMI && GET_CODE (XEXP (x, 1)) == NOT)
22720 : : {
22721 : 0 : *total = cost->add * 2
22722 : 0 : + rtx_cost (XEXP (x, 0), mode,
22723 : : outer_code, opno, speed)
22724 : 0 : + rtx_cost (XEXP (XEXP (x, 1), 0), mode,
22725 : : outer_code, opno, speed);
22726 : 0 : return true;
22727 : : }
22728 : 1019454 : *total = cost->add * 2;
22729 : : }
22730 : 5277932 : else if (TARGET_BMI && GET_CODE (XEXP (x,0)) == NOT)
22731 : : {
22732 : 746 : *total = cost->add
22733 : 373 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22734 : : outer_code, opno, speed)
22735 : 373 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
22736 : 373 : return true;
22737 : : }
22738 : 5277559 : else if (TARGET_BMI && GET_CODE (XEXP (x,1)) == NOT)
22739 : : {
22740 : 112 : *total = cost->add
22741 : 56 : + rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
22742 : 56 : + rtx_cost (XEXP (XEXP (x, 1), 0), mode,
22743 : : outer_code, opno, speed);
22744 : 56 : return true;
22745 : : }
22746 : : else
22747 : 5277503 : *total = cost->add;
22748 : : return false;
22749 : :
22750 : 519595 : case NOT:
22751 : 519595 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22752 : : {
22753 : : /* (not (xor ...)) can be a single insn in AVX512. */
22754 : 0 : if (GET_CODE (XEXP (x, 0)) == XOR && TARGET_AVX512F
22755 : 5551 : && (GET_MODE_SIZE (mode) == 64
22756 : 0 : || (TARGET_AVX512VL
22757 : 0 : && (GET_MODE_SIZE (mode) == 32
22758 : 0 : || GET_MODE_SIZE (mode) == 16))))
22759 : : {
22760 : 0 : *total = ix86_vec_cost (mode, cost->sse_op)
22761 : 0 : + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
22762 : : outer_code, opno, speed)
22763 : 0 : + rtx_cost (XEXP (XEXP (x, 0), 1), mode,
22764 : : outer_code, opno, speed);
22765 : 0 : return true;
22766 : : }
22767 : :
22768 : : // vnot is pxor -1.
22769 : 5551 : *total = ix86_vec_cost (mode, cost->sse_op) + 1;
22770 : : }
22771 : 1173753 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22772 : 68668 : *total = cost->add * 2;
22773 : : else
22774 : 445376 : *total = cost->add;
22775 : : return false;
22776 : :
22777 : 18377040 : case NEG:
22778 : 18377040 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22779 : 53657 : *total = cost->sse_op;
22780 : 18323383 : else if (X87_FLOAT_MODE_P (mode))
22781 : 15233 : *total = cost->fchs;
22782 : 18308150 : else if (FLOAT_MODE_P (mode))
22783 : 26783 : *total = ix86_vec_cost (mode, cost->sse_op);
22784 : 18281367 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22785 : 13654279 : *total = ix86_vec_cost (mode, cost->sse_op);
22786 : 9400580 : else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
22787 : 1742023 : *total = cost->add * 3;
22788 : : else
22789 : 2885065 : *total = cost->add;
22790 : : return false;
22791 : :
22792 : 53323994 : case COMPARE:
22793 : 53323994 : rtx op0, op1;
22794 : 53323994 : op0 = XEXP (x, 0);
22795 : 53323994 : op1 = XEXP (x, 1);
22796 : 53323994 : if (GET_CODE (op0) == ZERO_EXTRACT
22797 : 153418 : && XEXP (op0, 1) == const1_rtx
22798 : 135251 : && CONST_INT_P (XEXP (op0, 2))
22799 : 135149 : && op1 == const0_rtx)
22800 : : {
22801 : : /* This kind of construct is implemented using test[bwl].
22802 : : Treat it as if we had an AND. */
22803 : 135149 : mode = GET_MODE (XEXP (op0, 0));
22804 : 270298 : *total = (cost->add
22805 : 135149 : + rtx_cost (XEXP (op0, 0), mode, outer_code,
22806 : : opno, speed)
22807 : 135149 : + rtx_cost (const1_rtx, mode, outer_code, opno, speed));
22808 : 135149 : return true;
22809 : : }
22810 : :
22811 : 53188845 : if (GET_CODE (op0) == PLUS && rtx_equal_p (XEXP (op0, 0), op1))
22812 : : {
22813 : : /* This is an overflow detection, count it as a normal compare. */
22814 : 141468 : *total = rtx_cost (op0, GET_MODE (op0), COMPARE, 0, speed);
22815 : 141468 : return true;
22816 : : }
22817 : :
22818 : 53047377 : rtx geu;
22819 : : /* Match x
22820 : : (compare:CCC (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))
22821 : : (ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))) */
22822 : 53047377 : if (mode == CCCmode
22823 : 410386 : && GET_CODE (op0) == NEG
22824 : 7992 : && GET_CODE (geu = XEXP (op0, 0)) == GEU
22825 : 7989 : && REG_P (XEXP (geu, 0))
22826 : 7989 : && (GET_MODE (XEXP (geu, 0)) == CCCmode
22827 : 755 : || GET_MODE (XEXP (geu, 0)) == CCmode)
22828 : 7989 : && REGNO (XEXP (geu, 0)) == FLAGS_REG
22829 : 7989 : && XEXP (geu, 1) == const0_rtx
22830 : 7989 : && GET_CODE (op1) == LTU
22831 : 7989 : && REG_P (XEXP (op1, 0))
22832 : 7989 : && GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0))
22833 : 7989 : && REGNO (XEXP (op1, 0)) == FLAGS_REG
22834 : 53055366 : && XEXP (op1, 1) == const0_rtx)
22835 : : {
22836 : : /* This is *setcc_qi_addqi3_cconly_overflow_1_* patterns, a nop. */
22837 : 7989 : *total = 0;
22838 : 7989 : return true;
22839 : : }
22840 : : /* Match x
22841 : : (compare:CCC (neg:QI (ltu:QI (reg:CCC FLAGS_REG) (const_int 0)))
22842 : : (geu:QI (reg:CCC FLAGS_REG) (const_int 0))) */
22843 : 53039388 : if (mode == CCCmode
22844 : 402397 : && GET_CODE (op0) == NEG
22845 : 3 : && GET_CODE (XEXP (op0, 0)) == LTU
22846 : 3 : && REG_P (XEXP (XEXP (op0, 0), 0))
22847 : 3 : && GET_MODE (XEXP (XEXP (op0, 0), 0)) == CCCmode
22848 : 3 : && REGNO (XEXP (XEXP (op0, 0), 0)) == FLAGS_REG
22849 : 3 : && XEXP (XEXP (op0, 0), 1) == const0_rtx
22850 : 3 : && GET_CODE (op1) == GEU
22851 : 3 : && REG_P (XEXP (op1, 0))
22852 : 3 : && GET_MODE (XEXP (op1, 0)) == CCCmode
22853 : 3 : && REGNO (XEXP (op1, 0)) == FLAGS_REG
22854 : 53039391 : && XEXP (op1, 1) == const0_rtx)
22855 : : {
22856 : : /* This is *x86_cmc. */
22857 : 3 : if (!speed)
22858 : 0 : *total = COSTS_N_BYTES (1);
22859 : 3 : else if (TARGET_SLOW_STC)
22860 : 0 : *total = COSTS_N_INSNS (2);
22861 : : else
22862 : 3 : *total = COSTS_N_INSNS (1);
22863 : 3 : return true;
22864 : : }
22865 : :
22866 : 53039385 : if (SCALAR_INT_MODE_P (GET_MODE (op0))
22867 : 110438667 : && GET_MODE_SIZE (GET_MODE (op0)) > UNITS_PER_WORD)
22868 : : {
22869 : 793303 : if (op1 == const0_rtx)
22870 : 253082 : *total = cost->add
22871 : 126541 : + rtx_cost (op0, GET_MODE (op0), outer_code, opno, speed);
22872 : : else
22873 : 1333524 : *total = 3*cost->add
22874 : 666762 : + rtx_cost (op0, GET_MODE (op0), outer_code, opno, speed)
22875 : 666762 : + rtx_cost (op1, GET_MODE (op0), outer_code, opno, speed);
22876 : 793303 : return true;
22877 : : }
22878 : :
22879 : : /* The embedded comparison operand is completely free. */
22880 : 52246082 : if (!general_operand (op0, GET_MODE (op0)) && op1 == const0_rtx)
22881 : 348740 : *total = 0;
22882 : :
22883 : : return false;
22884 : :
22885 : 1358527 : case FLOAT_EXTEND:
22886 : : /* x87 represents all values extended to 80bit. */
22887 : 1358527 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22888 : 663726 : *total = 0;
22889 : : else
22890 : 1389602 : *total = vec_fp_conversion_cost (cost, GET_MODE_BITSIZE (mode));
22891 : : return false;
22892 : :
22893 : 82696 : case FLOAT_TRUNCATE:
22894 : 82696 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22895 : 58527 : *total = cost->fadd;
22896 : : else
22897 : 48338 : *total = vec_fp_conversion_cost (cost, GET_MODE_BITSIZE (mode));
22898 : : return false;
22899 : 680813 : case FLOAT:
22900 : 680813 : case UNSIGNED_FLOAT:
22901 : 680813 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22902 : : /* TODO: We do not have cost tables for x87. */
22903 : 92454 : *total = cost->fadd;
22904 : 588359 : else if (VECTOR_MODE_P (mode))
22905 : 0 : *total = ix86_vec_cost (mode, cost->cvtpi2ps);
22906 : : else
22907 : 588359 : *total = cost->cvtsi2ss;
22908 : : return false;
22909 : :
22910 : 274676 : case FIX:
22911 : 274676 : case UNSIGNED_FIX:
22912 : 274676 : if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22913 : : /* TODO: We do not have cost tables for x87. */
22914 : 274676 : *total = cost->fadd;
22915 : 0 : else if (VECTOR_MODE_P (mode))
22916 : 0 : *total = ix86_vec_cost (mode, cost->cvtps2pi);
22917 : : else
22918 : 0 : *total = cost->cvtss2si;
22919 : : return false;
22920 : :
22921 : 378559 : case ABS:
22922 : : /* SSE requires memory load for the constant operand. It may make
22923 : : sense to account for this. Of course the constant operand may or
22924 : : may not be reused. */
22925 : 378559 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22926 : 266007 : *total = cost->sse_op;
22927 : 112552 : else if (X87_FLOAT_MODE_P (mode))
22928 : 36886 : *total = cost->fabs;
22929 : 75666 : else if (FLOAT_MODE_P (mode))
22930 : 33572 : *total = ix86_vec_cost (mode, cost->sse_op);
22931 : 42094 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
22932 : 5405 : *total = cost->sse_op;
22933 : : return false;
22934 : :
22935 : 28200 : case SQRT:
22936 : 28200 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
22937 : 18076 : *total = mode == SFmode ? cost->sqrtss : cost->sqrtsd;
22938 : 10124 : else if (X87_FLOAT_MODE_P (mode))
22939 : 4269 : *total = cost->fsqrt;
22940 : 5855 : else if (FLOAT_MODE_P (mode))
22941 : 5855 : *total = ix86_vec_cost (mode,
22942 : : mode == SFmode ? cost->sqrtss : cost->sqrtsd);
22943 : : return false;
22944 : :
22945 : 3771903 : case UNSPEC:
22946 : 3771903 : if (XINT (x, 1) == UNSPEC_TP)
22947 : 116291 : *total = 0;
22948 : 3655612 : else if (XINT (x, 1) == UNSPEC_VTERNLOG)
22949 : : {
22950 : 5228 : *total = cost->sse_op;
22951 : 5228 : *total += rtx_cost (XVECEXP (x, 0, 0), mode, code, 0, speed);
22952 : 5228 : *total += rtx_cost (XVECEXP (x, 0, 1), mode, code, 1, speed);
22953 : 5228 : *total += rtx_cost (XVECEXP (x, 0, 2), mode, code, 2, speed);
22954 : 5228 : return true;
22955 : : }
22956 : 3650384 : else if (XINT (x, 1) == UNSPEC_PTEST)
22957 : : {
22958 : 42462 : *total = cost->sse_op;
22959 : 42462 : rtx test_op0 = XVECEXP (x, 0, 0);
22960 : 42462 : if (!rtx_equal_p (test_op0, XVECEXP (x, 0, 1)))
22961 : : return false;
22962 : 41785 : if (GET_CODE (test_op0) == AND)
22963 : : {
22964 : 23 : rtx and_op0 = XEXP (test_op0, 0);
22965 : 23 : if (GET_CODE (and_op0) == NOT)
22966 : 0 : and_op0 = XEXP (and_op0, 0);
22967 : 23 : *total += rtx_cost (and_op0, GET_MODE (and_op0),
22968 : : AND, 0, speed)
22969 : 23 : + rtx_cost (XEXP (test_op0, 1), GET_MODE (and_op0),
22970 : : AND, 1, speed);
22971 : : }
22972 : : else
22973 : 41762 : *total = rtx_cost (test_op0, GET_MODE (test_op0),
22974 : : UNSPEC, 0, speed);
22975 : 41785 : return true;
22976 : : }
22977 : : return false;
22978 : :
22979 : 2055455 : case VEC_CONCAT:
22980 : : /* ??? Assume all of these vector manipulation patterns are
22981 : : recognizable. In which case they all pretty much have the
22982 : : same cost.
22983 : : ??? We should still recruse when computing cost. */
22984 : 2055455 : *total = cost->sse_op;
22985 : 2055455 : return true;
22986 : :
22987 : 2298140 : case VEC_SELECT:
22988 : : /* Special case extracting lower part from the vector.
22989 : : This by itself needs to code and most of SSE/AVX instructions have
22990 : : packed and single forms where the single form may be represented
22991 : : by such VEC_SELECT.
22992 : :
22993 : : Use cost 1 (despite the fact that functionally equivalent SUBREG has
22994 : : cost 0). Making VEC_SELECT completely free, for example instructs CSE
22995 : : to forward propagate VEC_SELECT into
22996 : :
22997 : : (set (reg eax) (reg src))
22998 : :
22999 : : which then prevents fwprop and combining. See i.e.
23000 : : gcc.target/i386/pr91103-1.c.
23001 : :
23002 : : ??? rtvec_series_p test should be, for valid patterns, equivalent to
23003 : : vec_series_lowpart_p but is not, since the latter calls
23004 : : can_cange_mode_class on ALL_REGS and this return false since x87 does
23005 : : not support subregs at all. */
23006 : 2298140 : if (rtvec_series_p (XVEC (XEXP (x, 1), 0), 0))
23007 : 739983 : *total = rtx_cost (XEXP (x, 0), GET_MODE (XEXP (x, 0)),
23008 : 739983 : outer_code, opno, speed) + 1;
23009 : : else
23010 : : /* ??? We should still recruse when computing cost. */
23011 : 1558157 : *total = cost->sse_op;
23012 : : return true;
23013 : :
23014 : 1166547 : case VEC_DUPLICATE:
23015 : 2333094 : *total = rtx_cost (XEXP (x, 0),
23016 : 1166547 : GET_MODE (XEXP (x, 0)),
23017 : : VEC_DUPLICATE, 0, speed);
23018 : : /* It's broadcast instruction, not embedded broadcasting. */
23019 : 1166547 : if (outer_code == SET)
23020 : 1121720 : *total += cost->sse_op;
23021 : :
23022 : : return true;
23023 : :
23024 : 649142 : case VEC_MERGE:
23025 : 649142 : mask = XEXP (x, 2);
23026 : : /* Scalar versions of SSE instructions may be represented as:
23027 : :
23028 : : (vec_merge (vec_duplicate (operation ....))
23029 : : (register or memory)
23030 : : (const_int 1))
23031 : :
23032 : : In this case vec_merge and vec_duplicate is for free.
23033 : : Just recurse into operation and second operand. */
23034 : 649142 : if (mask == const1_rtx
23035 : 185463 : && GET_CODE (XEXP (x, 0)) == VEC_DUPLICATE)
23036 : : {
23037 : 69260 : *total = rtx_cost (XEXP (XEXP (x, 0), 0), mode,
23038 : : outer_code, opno, speed)
23039 : 69260 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
23040 : 69260 : return true;
23041 : : }
23042 : : /* This is masked instruction, assume the same cost,
23043 : : as nonmasked variant. */
23044 : 579882 : else if (TARGET_AVX512F
23045 : 579882 : && (register_operand (mask, GET_MODE (mask))
23046 : : /* Redunduant clean up of high bits for kmask with VL=2/4
23047 : : .i.e (vec_merge op0, op1, (and op3 15)). */
23048 : 108342 : || (GET_CODE (mask) == AND
23049 : 328 : && register_operand (XEXP (mask, 0), GET_MODE (mask))
23050 : 328 : && CONST_INT_P (XEXP (mask, 1))
23051 : 328 : && ((INTVAL (XEXP (mask, 1)) == 3
23052 : 131 : && GET_MODE_NUNITS (mode) == 2)
23053 : 197 : || (INTVAL (XEXP (mask, 1)) == 15
23054 : 197 : && GET_MODE_NUNITS (mode) == 4)))))
23055 : : {
23056 : 345992 : *total = rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
23057 : 345992 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
23058 : 345992 : return true;
23059 : : }
23060 : : /* Combination of the two above:
23061 : :
23062 : : (vec_merge (vec_merge (vec_duplicate (operation ...))
23063 : : (register or memory)
23064 : : (reg:QI mask))
23065 : : (register or memory)
23066 : : (const_int 1))
23067 : :
23068 : : i.e. avx512fp16_vcvtss2sh_mask. */
23069 : 233890 : else if (TARGET_AVX512F
23070 : 108014 : && mask == const1_rtx
23071 : 45291 : && GET_CODE (XEXP (x, 0)) == VEC_MERGE
23072 : 26723 : && GET_CODE (XEXP (XEXP (x, 0), 0)) == VEC_DUPLICATE
23073 : 236116 : && register_operand (XEXP (XEXP (x, 0), 2),
23074 : 2226 : GET_MODE (XEXP (XEXP (x, 0), 2))))
23075 : : {
23076 : 2214 : *total = rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
23077 : : mode, outer_code, opno, speed)
23078 : 2214 : + rtx_cost (XEXP (XEXP (x, 0), 1),
23079 : : mode, outer_code, opno, speed)
23080 : 2214 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
23081 : 2214 : return true;
23082 : : }
23083 : : /* vcmp. */
23084 : 231676 : else if (unspec_pcmp_p (mask)
23085 : 231676 : || (GET_CODE (mask) == NOT
23086 : 0 : && unspec_pcmp_p (XEXP (mask, 0))))
23087 : : {
23088 : 1905 : rtx uns = GET_CODE (mask) == NOT ? XEXP (mask, 0) : mask;
23089 : 1905 : rtx unsop0 = XVECEXP (uns, 0, 0);
23090 : : /* Make (subreg:V4SI (not:V16QI (reg:V16QI ..)) 0)
23091 : : cost the same as register.
23092 : : This is used by avx_cmp<mode>3_ltint_not. */
23093 : 1905 : if (GET_CODE (unsop0) == SUBREG)
23094 : 417 : unsop0 = XEXP (unsop0, 0);
23095 : 1905 : if (GET_CODE (unsop0) == NOT)
23096 : 18 : unsop0 = XEXP (unsop0, 0);
23097 : 1905 : *total = rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
23098 : 1905 : + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed)
23099 : 1905 : + rtx_cost (unsop0, mode, UNSPEC, opno, speed)
23100 : 1905 : + rtx_cost (XVECEXP (uns, 0, 1), mode, UNSPEC, opno, speed)
23101 : 1905 : + cost->sse_op;
23102 : 1905 : return true;
23103 : : }
23104 : : else
23105 : 229771 : *total = cost->sse_op;
23106 : 229771 : return false;
23107 : :
23108 : 104673720 : case MEM:
23109 : : /* CONST_VECTOR_DUPLICATE_P in constant_pool is just broadcast.
23110 : : or variants in ix86_vector_duplicate_simode_const. */
23111 : :
23112 : 104673720 : if (GET_MODE_SIZE (mode) >= 16
23113 : 16465535 : && VECTOR_MODE_P (mode)
23114 : 10410591 : && SYMBOL_REF_P (XEXP (x, 0))
23115 : 2132440 : && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))
23116 : 106613724 : && ix86_broadcast_from_constant (mode, x))
23117 : : {
23118 : 400494 : *total = COSTS_N_INSNS (2) + speed;
23119 : 400494 : return true;
23120 : : }
23121 : :
23122 : : /* An insn that accesses memory is slightly more expensive
23123 : : than one that does not. */
23124 : 104273226 : if (speed)
23125 : : {
23126 : 93249820 : *total += 1;
23127 : 93249820 : rtx addr = XEXP (x, 0);
23128 : : /* For MEM, rtx_cost iterates each subrtx, and adds up the costs,
23129 : : so for MEM (reg) and MEM (reg + 4), the former costs 5,
23130 : : the latter costs 9, it is not accurate for x86. Ideally
23131 : : address_cost should be used, but it reduce cost too much.
23132 : : So current solution is make constant disp as cheap as possible. */
23133 : 93249820 : if (GET_CODE (addr) == PLUS
23134 : 76866271 : && x86_64_immediate_operand (XEXP (addr, 1), Pmode)
23135 : : /* Only hanlde (reg + disp) since other forms of addr are mostly LEA,
23136 : : there's no additional cost for the plus of disp. */
23137 : 164544141 : && register_operand (XEXP (addr, 0), Pmode))
23138 : : {
23139 : 55752553 : *total += 1;
23140 : 68577189 : *total += rtx_cost (XEXP (addr, 0), Pmode, PLUS, 0, speed);
23141 : 55752553 : return true;
23142 : : }
23143 : : }
23144 : :
23145 : : return false;
23146 : :
23147 : 55502 : case ZERO_EXTRACT:
23148 : 55502 : if (XEXP (x, 1) == const1_rtx
23149 : 13116 : && GET_CODE (XEXP (x, 2)) == ZERO_EXTEND
23150 : 0 : && GET_MODE (XEXP (x, 2)) == SImode
23151 : 0 : && GET_MODE (XEXP (XEXP (x, 2), 0)) == QImode)
23152 : : {
23153 : : /* Ignore cost of zero extension and masking of last argument. */
23154 : 0 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
23155 : 0 : *total += rtx_cost (XEXP (x, 1), mode, code, 1, speed);
23156 : 0 : *total += rtx_cost (XEXP (XEXP (x, 2), 0), mode, code, 2, speed);
23157 : 0 : return true;
23158 : : }
23159 : : return false;
23160 : :
23161 : 26904205 : case IF_THEN_ELSE:
23162 : 26904205 : if (TARGET_XOP
23163 : 17129 : && VECTOR_MODE_P (mode)
23164 : 26909899 : && (GET_MODE_SIZE (mode) == 16 || GET_MODE_SIZE (mode) == 32))
23165 : : {
23166 : : /* vpcmov. */
23167 : 5018 : *total = speed ? COSTS_N_INSNS (2) : COSTS_N_BYTES (6);
23168 : 5018 : if (!REG_P (XEXP (x, 0)))
23169 : 4840 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
23170 : 5018 : if (!REG_P (XEXP (x, 1)))
23171 : 4804 : *total += rtx_cost (XEXP (x, 1), mode, code, 1, speed);
23172 : 5018 : if (!REG_P (XEXP (x, 2)))
23173 : 4806 : *total += rtx_cost (XEXP (x, 2), mode, code, 2, speed);
23174 : 5018 : return true;
23175 : : }
23176 : 0 : else if (TARGET_CMOVE
23177 : 26899187 : && SCALAR_INT_MODE_P (mode)
23178 : 29320918 : && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
23179 : : {
23180 : : /* cmov. */
23181 : 2243780 : *total = COSTS_N_INSNS (1);
23182 : 2243780 : if (!COMPARISON_P (XEXP (x, 0)) && !REG_P (XEXP (x, 0)))
23183 : 0 : *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
23184 : 2243780 : if (!REG_P (XEXP (x, 1)))
23185 : 125482 : *total += rtx_cost (XEXP (x, 1), mode, code, 1, speed);
23186 : 2243780 : if (!REG_P (XEXP (x, 2)))
23187 : 674155 : *total += rtx_cost (XEXP (x, 2), mode, code, 2, speed);
23188 : 2243780 : return true;
23189 : : }
23190 : : return false;
23191 : :
23192 : : default:
23193 : : return false;
23194 : : }
23195 : : }
23196 : :
23197 : : #if TARGET_MACHO
23198 : :
23199 : : static int current_machopic_label_num;
23200 : :
23201 : : /* Given a symbol name and its associated stub, write out the
23202 : : definition of the stub. */
23203 : :
23204 : : void
23205 : : machopic_output_stub (FILE *file, const char *symb, const char *stub)
23206 : : {
23207 : : unsigned int length;
23208 : : char *binder_name, *symbol_name, lazy_ptr_name[32];
23209 : : int label = ++current_machopic_label_num;
23210 : :
23211 : : /* For 64-bit we shouldn't get here. */
23212 : : gcc_assert (!TARGET_64BIT);
23213 : :
23214 : : /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
23215 : : symb = targetm.strip_name_encoding (symb);
23216 : :
23217 : : length = strlen (stub);
23218 : : binder_name = XALLOCAVEC (char, length + 32);
23219 : : GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
23220 : :
23221 : : length = strlen (symb);
23222 : : symbol_name = XALLOCAVEC (char, length + 32);
23223 : : GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
23224 : :
23225 : : sprintf (lazy_ptr_name, "L%d$lz", label);
23226 : :
23227 : : if (MACHOPIC_ATT_STUB)
23228 : : switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]);
23229 : : else if (MACHOPIC_PURE)
23230 : : switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]);
23231 : : else
23232 : : switch_to_section (darwin_sections[machopic_symbol_stub_section]);
23233 : :
23234 : : fprintf (file, "%s:\n", stub);
23235 : : fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
23236 : :
23237 : : if (MACHOPIC_ATT_STUB)
23238 : : {
23239 : : fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n");
23240 : : }
23241 : : else if (MACHOPIC_PURE)
23242 : : {
23243 : : /* PIC stub. */
23244 : : /* 25-byte PIC stub using "CALL get_pc_thunk". */
23245 : : rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */);
23246 : : output_set_got (tmp, NULL_RTX); /* "CALL ___<cpu>.get_pc_thunk.cx". */
23247 : : fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n",
23248 : : label, lazy_ptr_name, label);
23249 : : fprintf (file, "\tjmp\t*%%ecx\n");
23250 : : }
23251 : : else
23252 : : fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
23253 : :
23254 : : /* The AT&T-style ("self-modifying") stub is not lazily bound, thus
23255 : : it needs no stub-binding-helper. */
23256 : : if (MACHOPIC_ATT_STUB)
23257 : : return;
23258 : :
23259 : : fprintf (file, "%s:\n", binder_name);
23260 : :
23261 : : if (MACHOPIC_PURE)
23262 : : {
23263 : : fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name);
23264 : : fprintf (file, "\tpushl\t%%ecx\n");
23265 : : }
23266 : : else
23267 : : fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
23268 : :
23269 : : fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
23270 : :
23271 : : /* N.B. Keep the correspondence of these
23272 : : 'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the
23273 : : old-pic/new-pic/non-pic stubs; altering this will break
23274 : : compatibility with existing dylibs. */
23275 : : if (MACHOPIC_PURE)
23276 : : {
23277 : : /* 25-byte PIC stub using "CALL get_pc_thunk". */
23278 : : switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]);
23279 : : }
23280 : : else
23281 : : /* 16-byte -mdynamic-no-pic stub. */
23282 : : switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]);
23283 : :
23284 : : fprintf (file, "%s:\n", lazy_ptr_name);
23285 : : fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
23286 : : fprintf (file, ASM_LONG "%s\n", binder_name);
23287 : : }
23288 : : #endif /* TARGET_MACHO */
23289 : :
23290 : : /* Order the registers for register allocator. */
23291 : :
23292 : : void
23293 : 214246 : x86_order_regs_for_local_alloc (void)
23294 : : {
23295 : 214246 : int pos = 0;
23296 : 214246 : int i;
23297 : :
23298 : : /* First allocate the local general purpose registers. */
23299 : 19924878 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
23300 : 26566504 : if (GENERAL_REGNO_P (i) && call_used_or_fixed_reg_p (i))
23301 : 5579777 : reg_alloc_order [pos++] = i;
23302 : :
23303 : : /* Global general purpose registers. */
23304 : 19924878 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
23305 : 22880694 : if (GENERAL_REGNO_P (i) && !call_used_or_fixed_reg_p (i))
23306 : 1276095 : reg_alloc_order [pos++] = i;
23307 : :
23308 : : /* x87 registers come first in case we are doing FP math
23309 : : using them. */
23310 : 214246 : if (!TARGET_SSE_MATH)
23311 : 56889 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
23312 : 50568 : reg_alloc_order [pos++] = i;
23313 : :
23314 : : /* SSE registers. */
23315 : 1928214 : for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
23316 : 1713968 : reg_alloc_order [pos++] = i;
23317 : 1928214 : for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
23318 : 1713968 : reg_alloc_order [pos++] = i;
23319 : :
23320 : : /* Extended REX SSE registers. */
23321 : 3642182 : for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
23322 : 3427936 : reg_alloc_order [pos++] = i;
23323 : :
23324 : : /* Mask register. */
23325 : 1928214 : for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
23326 : 1713968 : reg_alloc_order [pos++] = i;
23327 : :
23328 : : /* x87 registers. */
23329 : 214246 : if (TARGET_SSE_MATH)
23330 : 1871325 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
23331 : 1663400 : reg_alloc_order [pos++] = i;
23332 : :
23333 : 1928214 : for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
23334 : 1713968 : reg_alloc_order [pos++] = i;
23335 : :
23336 : : /* Initialize the rest of array as we do not allocate some registers
23337 : : at all. */
23338 : 1071230 : while (pos < FIRST_PSEUDO_REGISTER)
23339 : 856984 : reg_alloc_order [pos++] = 0;
23340 : 214246 : }
23341 : :
23342 : : static bool
23343 : 206081418 : ix86_ms_bitfield_layout_p (const_tree record_type)
23344 : : {
23345 : 206081418 : return ((TARGET_MS_BITFIELD_LAYOUT
23346 : 215 : && !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
23347 : 206081418 : || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type)));
23348 : : }
23349 : :
23350 : : /* Returns an expression indicating where the this parameter is
23351 : : located on entry to the FUNCTION. */
23352 : :
23353 : : static rtx
23354 : 1761 : x86_this_parameter (tree function)
23355 : : {
23356 : 1761 : tree type = TREE_TYPE (function);
23357 : 1761 : bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
23358 : 1761 : int nregs;
23359 : :
23360 : 1761 : if (TARGET_64BIT)
23361 : : {
23362 : 1759 : const int *parm_regs;
23363 : :
23364 : 1759 : if (lookup_attribute ("preserve_none", TYPE_ATTRIBUTES (type)))
23365 : : parm_regs = x86_64_preserve_none_int_parameter_registers;
23366 : 1759 : else if (ix86_function_type_abi (type) == MS_ABI)
23367 : : parm_regs = x86_64_ms_abi_int_parameter_registers;
23368 : : else
23369 : 1759 : parm_regs = x86_64_int_parameter_registers;
23370 : 1759 : return gen_rtx_REG (Pmode, parm_regs[aggr]);
23371 : : }
23372 : :
23373 : 2 : nregs = ix86_function_regparm (type, function);
23374 : :
23375 : 2 : if (nregs > 0 && !stdarg_p (type))
23376 : : {
23377 : 0 : int regno;
23378 : 0 : unsigned int ccvt = ix86_get_callcvt (type);
23379 : :
23380 : 0 : if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
23381 : 0 : regno = aggr ? DX_REG : CX_REG;
23382 : 0 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
23383 : : {
23384 : 0 : regno = CX_REG;
23385 : 0 : if (aggr)
23386 : 0 : return gen_rtx_MEM (SImode,
23387 : 0 : plus_constant (Pmode, stack_pointer_rtx, 4));
23388 : : }
23389 : : else
23390 : : {
23391 : 0 : regno = AX_REG;
23392 : 0 : if (aggr)
23393 : : {
23394 : 0 : regno = DX_REG;
23395 : 0 : if (nregs == 1)
23396 : 0 : return gen_rtx_MEM (SImode,
23397 : 0 : plus_constant (Pmode,
23398 : : stack_pointer_rtx, 4));
23399 : : }
23400 : : }
23401 : 0 : return gen_rtx_REG (SImode, regno);
23402 : : }
23403 : :
23404 : 4 : return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx,
23405 : 4 : aggr ? 8 : 4));
23406 : : }
23407 : :
23408 : : /* Determine whether x86_output_mi_thunk can succeed. */
23409 : :
23410 : : static bool
23411 : 4929 : x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset,
23412 : : const_tree function)
23413 : : {
23414 : : /* 64-bit can handle anything. */
23415 : 4929 : if (TARGET_64BIT)
23416 : : return true;
23417 : :
23418 : : /* For 32-bit, everything's fine if we have one free register. */
23419 : 76 : if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
23420 : : return true;
23421 : :
23422 : : /* Need a free register for vcall_offset. */
23423 : 0 : if (vcall_offset)
23424 : : return false;
23425 : :
23426 : : /* Need a free register for GOT references. */
23427 : 0 : if (flag_pic && !targetm.binds_local_p (function))
23428 : : return false;
23429 : :
23430 : : /* Otherwise ok. */
23431 : : return true;
23432 : : }
23433 : :
23434 : : /* Output the assembler code for a thunk function. THUNK_DECL is the
23435 : : declaration for the thunk function itself, FUNCTION is the decl for
23436 : : the target function. DELTA is an immediate constant offset to be
23437 : : added to THIS. If VCALL_OFFSET is nonzero, the word at
23438 : : *(*this + vcall_offset) should be added to THIS. */
23439 : :
23440 : : static void
23441 : 1761 : x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
23442 : : HOST_WIDE_INT vcall_offset, tree function)
23443 : : {
23444 : 1761 : const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
23445 : 1761 : rtx this_param = x86_this_parameter (function);
23446 : 1761 : rtx this_reg, tmp, fnaddr;
23447 : 1761 : unsigned int tmp_regno;
23448 : 1761 : rtx_insn *insn;
23449 : 1761 : int saved_flag_force_indirect_call = flag_force_indirect_call;
23450 : :
23451 : 1761 : if (TARGET_64BIT)
23452 : : tmp_regno = R10_REG;
23453 : : else
23454 : : {
23455 : 2 : unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
23456 : 2 : if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
23457 : : tmp_regno = AX_REG;
23458 : 2 : else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
23459 : : tmp_regno = DX_REG;
23460 : : else
23461 : 2 : tmp_regno = CX_REG;
23462 : :
23463 : 2 : if (flag_pic)
23464 : 2 : flag_force_indirect_call = 0;
23465 : : }
23466 : :
23467 : 1761 : emit_note (NOTE_INSN_PROLOGUE_END);
23468 : :
23469 : : /* CET is enabled, insert EB instruction. */
23470 : 1761 : if ((flag_cf_protection & CF_BRANCH))
23471 : 20 : emit_insn (gen_nop_endbr ());
23472 : :
23473 : : /* If VCALL_OFFSET, we'll need THIS in a register. Might as well
23474 : : pull it in now and let DELTA benefit. */
23475 : 1761 : if (REG_P (this_param))
23476 : : this_reg = this_param;
23477 : 2 : else if (vcall_offset)
23478 : : {
23479 : : /* Put the this parameter into %eax. */
23480 : 2 : this_reg = gen_rtx_REG (Pmode, AX_REG);
23481 : 1 : emit_move_insn (this_reg, this_param);
23482 : : }
23483 : : else
23484 : : this_reg = NULL_RTX;
23485 : :
23486 : : /* Adjust the this parameter by a fixed constant. */
23487 : 1761 : if (delta)
23488 : : {
23489 : 826 : rtx delta_rtx = GEN_INT (delta);
23490 : 826 : rtx delta_dst = this_reg ? this_reg : this_param;
23491 : :
23492 : 826 : if (TARGET_64BIT)
23493 : : {
23494 : 825 : if (!x86_64_general_operand (delta_rtx, Pmode))
23495 : : {
23496 : 0 : tmp = gen_rtx_REG (Pmode, tmp_regno);
23497 : 0 : emit_move_insn (tmp, delta_rtx);
23498 : 0 : delta_rtx = tmp;
23499 : : }
23500 : : }
23501 : :
23502 : 827 : ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx);
23503 : : }
23504 : :
23505 : : /* Adjust the this parameter by a value stored in the vtable. */
23506 : 1761 : if (vcall_offset)
23507 : : {
23508 : 986 : rtx vcall_addr, vcall_mem, this_mem;
23509 : :
23510 : 987 : tmp = gen_rtx_REG (Pmode, tmp_regno);
23511 : :
23512 : 986 : this_mem = gen_rtx_MEM (ptr_mode, this_reg);
23513 : 987 : if (Pmode != ptr_mode)
23514 : 0 : this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem);
23515 : 986 : emit_move_insn (tmp, this_mem);
23516 : :
23517 : : /* Adjust the this parameter. */
23518 : 987 : vcall_addr = plus_constant (Pmode, tmp, vcall_offset);
23519 : 986 : if (TARGET_64BIT
23520 : 986 : && !ix86_legitimate_address_p (ptr_mode, vcall_addr, true))
23521 : : {
23522 : 0 : rtx tmp2 = gen_rtx_REG (Pmode, R11_REG);
23523 : 0 : emit_move_insn (tmp2, GEN_INT (vcall_offset));
23524 : 0 : vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2);
23525 : : }
23526 : :
23527 : 986 : vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr);
23528 : 987 : if (Pmode != ptr_mode)
23529 : 0 : emit_insn (gen_addsi_1_zext (this_reg,
23530 : : gen_rtx_REG (ptr_mode,
23531 : : REGNO (this_reg)),
23532 : : vcall_mem));
23533 : : else
23534 : 986 : ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem);
23535 : : }
23536 : :
23537 : : /* If necessary, drop THIS back to its stack slot. */
23538 : 1761 : if (this_reg && this_reg != this_param)
23539 : 1 : emit_move_insn (this_param, this_reg);
23540 : :
23541 : 1761 : fnaddr = XEXP (DECL_RTL (function), 0);
23542 : 1761 : if (TARGET_64BIT)
23543 : : {
23544 : 25 : if (!flag_pic || targetm.binds_local_p (function)
23545 : 1784 : || TARGET_PECOFF)
23546 : : ;
23547 : : else
23548 : : {
23549 : 0 : tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL);
23550 : 0 : tmp = gen_rtx_CONST (Pmode, tmp);
23551 : 0 : fnaddr = gen_const_mem (Pmode, tmp);
23552 : : }
23553 : : }
23554 : : else
23555 : : {
23556 : 2 : if (!flag_pic || targetm.binds_local_p (function))
23557 : : ;
23558 : : #if TARGET_MACHO
23559 : : else if (TARGET_MACHO)
23560 : : {
23561 : : fnaddr = machopic_indirect_call_target (DECL_RTL (function));
23562 : : fnaddr = XEXP (fnaddr, 0);
23563 : : }
23564 : : #endif /* TARGET_MACHO */
23565 : : else
23566 : : {
23567 : 0 : tmp = gen_rtx_REG (Pmode, CX_REG);
23568 : 0 : output_set_got (tmp, NULL_RTX);
23569 : :
23570 : 0 : fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT);
23571 : 0 : fnaddr = gen_rtx_CONST (Pmode, fnaddr);
23572 : 0 : fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr);
23573 : 0 : fnaddr = gen_const_mem (Pmode, fnaddr);
23574 : : }
23575 : : }
23576 : :
23577 : : /* Our sibling call patterns do not allow memories, because we have no
23578 : : predicate that can distinguish between frame and non-frame memory.
23579 : : For our purposes here, we can get away with (ab)using a jump pattern,
23580 : : because we're going to do no optimization. */
23581 : 1761 : if (MEM_P (fnaddr))
23582 : : {
23583 : 0 : if (sibcall_insn_operand (fnaddr, word_mode))
23584 : : {
23585 : 0 : fnaddr = XEXP (DECL_RTL (function), 0);
23586 : 0 : tmp = gen_rtx_MEM (QImode, fnaddr);
23587 : 0 : tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
23588 : 0 : tmp = emit_call_insn (tmp);
23589 : 0 : SIBLING_CALL_P (tmp) = 1;
23590 : : }
23591 : : else
23592 : 0 : emit_jump_insn (gen_indirect_jump (fnaddr));
23593 : : }
23594 : : else
23595 : : {
23596 : 1761 : if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr))
23597 : : {
23598 : : // CM_LARGE_PIC always uses pseudo PIC register which is
23599 : : // uninitialized. Since FUNCTION is local and calling it
23600 : : // doesn't go through PLT, we use scratch register %r11 as
23601 : : // PIC register and initialize it here.
23602 : 3 : pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG);
23603 : 3 : ix86_init_large_pic_reg (tmp_regno);
23604 : 3 : fnaddr = legitimize_pic_address (fnaddr,
23605 : 3 : gen_rtx_REG (Pmode, tmp_regno));
23606 : : }
23607 : :
23608 : 1761 : if (!sibcall_insn_operand (fnaddr, word_mode))
23609 : : {
23610 : 9 : tmp = gen_rtx_REG (word_mode, tmp_regno);
23611 : 9 : if (GET_MODE (fnaddr) != word_mode)
23612 : 0 : fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr);
23613 : 9 : emit_move_insn (tmp, fnaddr);
23614 : 9 : fnaddr = tmp;
23615 : : }
23616 : :
23617 : 1761 : tmp = gen_rtx_MEM (QImode, fnaddr);
23618 : 1761 : tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
23619 : 1761 : tmp = emit_call_insn (tmp);
23620 : 1761 : SIBLING_CALL_P (tmp) = 1;
23621 : : }
23622 : 1761 : emit_barrier ();
23623 : :
23624 : : /* Emit just enough of rest_of_compilation to get the insns emitted. */
23625 : 1761 : insn = get_insns ();
23626 : 1761 : shorten_branches (insn);
23627 : 1761 : assemble_start_function (thunk_fndecl, fnname);
23628 : 1761 : final_start_function (insn, file, 1);
23629 : 1761 : final (insn, file, 1);
23630 : 1761 : final_end_function ();
23631 : 1761 : assemble_end_function (thunk_fndecl, fnname);
23632 : :
23633 : 1761 : flag_force_indirect_call = saved_flag_force_indirect_call;
23634 : 1761 : }
23635 : :
23636 : : static void
23637 : 271784 : x86_file_start (void)
23638 : : {
23639 : 271784 : default_file_start ();
23640 : 271784 : if (TARGET_16BIT)
23641 : 5 : fputs ("\t.code16gcc\n", asm_out_file);
23642 : : #if TARGET_MACHO
23643 : : darwin_file_start ();
23644 : : #endif
23645 : 271784 : if (X86_FILE_START_VERSION_DIRECTIVE)
23646 : : fputs ("\t.version\t\"01.01\"\n", asm_out_file);
23647 : 271784 : if (X86_FILE_START_FLTUSED)
23648 : : fputs ("\t.global\t__fltused\n", asm_out_file);
23649 : 271784 : if (ix86_asm_dialect == ASM_INTEL)
23650 : 60 : fputs ("\t.intel_syntax noprefix\n", asm_out_file);
23651 : 271784 : }
23652 : :
23653 : : int
23654 : 90744423 : x86_field_alignment (tree type, int computed)
23655 : : {
23656 : 90744423 : machine_mode mode;
23657 : :
23658 : 90744423 : if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
23659 : : return computed;
23660 : 8965181 : if (TARGET_IAMCU)
23661 : 0 : return iamcu_alignment (type, computed);
23662 : 8965181 : type = strip_array_types (type);
23663 : 8965181 : mode = TYPE_MODE (type);
23664 : 8965181 : if (mode == DFmode || mode == DCmode
23665 : 8861499 : || GET_MODE_CLASS (mode) == MODE_INT
23666 : 3059440 : || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
23667 : : {
23668 : 5905741 : if (TYPE_ATOMIC (type) && computed > 32)
23669 : : {
23670 : 0 : static bool warned;
23671 : :
23672 : 0 : if (!warned && warn_psabi)
23673 : : {
23674 : 0 : const char *url
23675 : : = CHANGES_ROOT_URL "gcc-11/changes.html#ia32_atomic";
23676 : :
23677 : 0 : warned = true;
23678 : 0 : inform (input_location, "the alignment of %<_Atomic %T%> "
23679 : : "fields changed in %{GCC 11.1%}",
23680 : 0 : TYPE_MAIN_VARIANT (type), url);
23681 : : }
23682 : : }
23683 : : else
23684 : 5905741 : return MIN (32, computed);
23685 : : }
23686 : : return computed;
23687 : : }
23688 : :
23689 : : /* Print call to TARGET to FILE. */
23690 : :
23691 : : static void
23692 : 372 : x86_print_call_or_nop (FILE *file, const char *target)
23693 : : {
23694 : 372 : if (flag_nop_mcount || !strcmp (target, "nop"))
23695 : : /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
23696 : 6 : fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
23697 : 366 : else if (!TARGET_PECOFF && flag_pic)
23698 : : {
23699 : 6 : gcc_assert (flag_plt);
23700 : :
23701 : 6 : fprintf (file, "1:\tcall\t%s@PLT\n", target);
23702 : : }
23703 : : else
23704 : 360 : fprintf (file, "1:\tcall\t%s\n", target);
23705 : 372 : }
23706 : :
23707 : : static bool
23708 : 386 : current_fentry_name (const char **name)
23709 : : {
23710 : 386 : tree attr = lookup_attribute ("fentry_name",
23711 : 386 : DECL_ATTRIBUTES (current_function_decl));
23712 : 386 : if (!attr)
23713 : : return false;
23714 : 2 : *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
23715 : 2 : return true;
23716 : : }
23717 : :
23718 : : static bool
23719 : 10 : current_fentry_section (const char **name)
23720 : : {
23721 : 10 : tree attr = lookup_attribute ("fentry_section",
23722 : 10 : DECL_ATTRIBUTES (current_function_decl));
23723 : 10 : if (!attr)
23724 : : return false;
23725 : 2 : *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
23726 : 2 : return true;
23727 : : }
23728 : :
23729 : : /* Return a caller-saved register which isn't live or a callee-saved
23730 : : register which has been saved on stack in the prologue at entry for
23731 : : profile. */
23732 : :
23733 : : static int
23734 : 13 : x86_64_select_profile_regnum (bool r11_ok ATTRIBUTE_UNUSED)
23735 : : {
23736 : : /* Use %r10 if the profiler is emitted before the prologue or it isn't
23737 : : used by DRAP. */
23738 : 13 : if (ix86_profile_before_prologue ()
23739 : 9 : || !crtl->drap_reg
23740 : 16 : || REGNO (crtl->drap_reg) != R10_REG)
23741 : : return R10_REG;
23742 : :
23743 : : /* The profiler is emitted after the prologue. If there is a
23744 : : caller-saved register which isn't live or a callee-saved
23745 : : register saved on stack in the prologue, use it. */
23746 : :
23747 : 3 : bitmap reg_live = df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun));
23748 : :
23749 : 3 : int i;
23750 : 88 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
23751 : 56 : if (GENERAL_REGNO_P (i)
23752 : 29 : && i != R10_REG
23753 : : #ifdef NO_PROFILE_COUNTERS
23754 : 27 : && (r11_ok || i != R11_REG)
23755 : : #else
23756 : : && i != R11_REG
23757 : : #endif
23758 : 26 : && TEST_HARD_REG_BIT (accessible_reg_set, i)
23759 : 111 : && (ix86_save_reg (i, true, true)
23760 : 25 : || (call_used_regs[i]
23761 : 18 : && !fixed_regs[i]
23762 : 16 : && !REGNO_REG_SET_P (reg_live, i))))
23763 : 3 : return i;
23764 : :
23765 : 0 : sorry ("no register available for profiling %<-mcmodel=large%s%>",
23766 : 0 : ix86_cmodel == CM_LARGE_PIC ? " -fPIC" : "");
23767 : :
23768 : 0 : return R10_REG;
23769 : : }
23770 : :
23771 : : /* Output assembler code to FILE to increment profiler label # LABELNO
23772 : : for profiling a function entry. */
23773 : : void
23774 : 386 : x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
23775 : : {
23776 : 386 : if (cfun->machine->insn_queued_at_entrance)
23777 : : {
23778 : 5 : if (cfun->machine->insn_queued_at_entrance == TYPE_ENDBR)
23779 : 4 : fprintf (file, "\t%s\n", TARGET_64BIT ? "endbr64" : "endbr32");
23780 : 5 : unsigned int patch_area_size
23781 : 5 : = crtl->patch_area_size - crtl->patch_area_entry;
23782 : 5 : if (patch_area_size)
23783 : 2 : ix86_output_patchable_area (patch_area_size,
23784 : : crtl->patch_area_entry == 0);
23785 : : }
23786 : :
23787 : 386 : const char *mcount_name = MCOUNT_NAME;
23788 : :
23789 : 386 : if (current_fentry_name (&mcount_name))
23790 : : ;
23791 : 384 : else if (fentry_name)
23792 : 1 : mcount_name = fentry_name;
23793 : 383 : else if (flag_fentry)
23794 : 21 : mcount_name = MCOUNT_NAME_BEFORE_PROLOGUE;
23795 : :
23796 : 386 : if (TARGET_64BIT)
23797 : : {
23798 : : #ifndef NO_PROFILE_COUNTERS
23799 : : if (ASSEMBLER_DIALECT == ASM_INTEL)
23800 : : fprintf (file, "\tlea\tr11, %sP%d[rip]\n", LPREFIX, labelno);
23801 : : else
23802 : : fprintf (file, "\tleaq\t%sP%d(%%rip), %%r11\n", LPREFIX, labelno);
23803 : : #endif
23804 : :
23805 : 386 : int scratch;
23806 : 386 : const char *reg;
23807 : 386 : char legacy_reg[4] = { 0 };
23808 : :
23809 : 386 : if (!TARGET_PECOFF)
23810 : : {
23811 : 386 : switch (ix86_cmodel)
23812 : : {
23813 : 5 : case CM_LARGE:
23814 : 5 : scratch = x86_64_select_profile_regnum (true);
23815 : 5 : reg = hi_reg_name[scratch];
23816 : 5 : if (LEGACY_INT_REGNO_P (scratch))
23817 : : {
23818 : 0 : legacy_reg[0] = 'r';
23819 : 0 : legacy_reg[1] = reg[0];
23820 : 0 : legacy_reg[2] = reg[1];
23821 : 0 : reg = legacy_reg;
23822 : : }
23823 : 5 : if (ASSEMBLER_DIALECT == ASM_INTEL)
23824 : 1 : fprintf (file, "1:\tmovabs\t%s, OFFSET FLAT:%s\n"
23825 : : "\tcall\t%s\n", reg, mcount_name, reg);
23826 : : else
23827 : 4 : fprintf (file, "1:\tmovabsq\t$%s, %%%s\n\tcall\t*%%%s\n",
23828 : : mcount_name, reg, reg);
23829 : : break;
23830 : 8 : case CM_LARGE_PIC:
23831 : : #ifdef NO_PROFILE_COUNTERS
23832 : 8 : scratch = x86_64_select_profile_regnum (false);
23833 : 8 : reg = hi_reg_name[scratch];
23834 : 8 : if (LEGACY_INT_REGNO_P (scratch))
23835 : : {
23836 : 1 : legacy_reg[0] = 'r';
23837 : 1 : legacy_reg[1] = reg[0];
23838 : 1 : legacy_reg[2] = reg[1];
23839 : 1 : reg = legacy_reg;
23840 : : }
23841 : 8 : if (ASSEMBLER_DIALECT == ASM_INTEL)
23842 : : {
23843 : 1 : fprintf (file, "1:movabs\tr11, "
23844 : : "OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-1b\n");
23845 : 1 : fprintf (file, "\tlea\t%s, 1b[rip]\n", reg);
23846 : 1 : fprintf (file, "\tadd\t%s, r11\n", reg);
23847 : 1 : fprintf (file, "\tmovabs\tr11, OFFSET FLAT:%s@PLTOFF\n",
23848 : : mcount_name);
23849 : 1 : fprintf (file, "\tadd\t%s, r11\n", reg);
23850 : 1 : fprintf (file, "\tcall\t%s\n", reg);
23851 : 1 : break;
23852 : : }
23853 : 7 : fprintf (file,
23854 : : "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
23855 : 7 : fprintf (file, "\tleaq\t1b(%%rip), %%%s\n", reg);
23856 : 7 : fprintf (file, "\taddq\t%%r11, %%%s\n", reg);
23857 : 7 : fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n", mcount_name);
23858 : 7 : fprintf (file, "\taddq\t%%r11, %%%s\n", reg);
23859 : 7 : fprintf (file, "\tcall\t*%%%s\n", reg);
23860 : : #else
23861 : : sorry ("profiling %<-mcmodel=large%> with PIC is not supported");
23862 : : #endif
23863 : 7 : break;
23864 : 8 : case CM_SMALL_PIC:
23865 : 8 : case CM_MEDIUM_PIC:
23866 : 8 : if (!flag_plt)
23867 : : {
23868 : 1 : if (ASSEMBLER_DIALECT == ASM_INTEL)
23869 : 0 : fprintf (file, "1:\tcall\t[QWORD PTR %s@GOTPCREL[rip]]\n",
23870 : : mcount_name);
23871 : : else
23872 : 1 : fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n",
23873 : : mcount_name);
23874 : : break;
23875 : : }
23876 : : /* fall through */
23877 : 372 : default:
23878 : 372 : x86_print_call_or_nop (file, mcount_name);
23879 : 372 : break;
23880 : : }
23881 : : }
23882 : : else
23883 : : x86_print_call_or_nop (file, mcount_name);
23884 : : }
23885 : 0 : else if (flag_pic)
23886 : : {
23887 : : #ifndef NO_PROFILE_COUNTERS
23888 : : if (ASSEMBLER_DIALECT == ASM_INTEL)
23889 : : fprintf (file,
23890 : : "\tlea\t" PROFILE_COUNT_REGISTER ", %sP%d@GOTOFF[ebx]\n",
23891 : : LPREFIX, labelno);
23892 : : else
23893 : : fprintf (file,
23894 : : "\tleal\t%sP%d@GOTOFF(%%ebx), %%" PROFILE_COUNT_REGISTER "\n",
23895 : : LPREFIX, labelno);
23896 : : #endif
23897 : 0 : if (flag_plt)
23898 : 0 : x86_print_call_or_nop (file, mcount_name);
23899 : 0 : else if (ASSEMBLER_DIALECT == ASM_INTEL)
23900 : 0 : fprintf (file, "1:\tcall\t[DWORD PTR %s@GOT[ebx]]\n", mcount_name);
23901 : : else
23902 : 0 : fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
23903 : : }
23904 : : else
23905 : : {
23906 : : #ifndef NO_PROFILE_COUNTERS
23907 : : if (ASSEMBLER_DIALECT == ASM_INTEL)
23908 : : fprintf (file,
23909 : : "\tmov\t" PROFILE_COUNT_REGISTER ", OFFSET FLAT:%sP%d\n",
23910 : : LPREFIX, labelno);
23911 : : else
23912 : : fprintf (file, "\tmovl\t$%sP%d, %%" PROFILE_COUNT_REGISTER "\n",
23913 : : LPREFIX, labelno);
23914 : : #endif
23915 : 0 : x86_print_call_or_nop (file, mcount_name);
23916 : : }
23917 : :
23918 : 386 : if (flag_record_mcount
23919 : 763 : || lookup_attribute ("fentry_section",
23920 : 377 : DECL_ATTRIBUTES (current_function_decl)))
23921 : : {
23922 : 10 : const char *sname = "__mcount_loc";
23923 : :
23924 : 10 : if (current_fentry_section (&sname))
23925 : : ;
23926 : 8 : else if (fentry_section)
23927 : 1 : sname = fentry_section;
23928 : :
23929 : 10 : fprintf (file, "\t.section %s, \"a\",@progbits\n", sname);
23930 : 10 : fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
23931 : 10 : fprintf (file, "\t.previous\n");
23932 : : }
23933 : 386 : }
23934 : :
23935 : : /* We don't have exact information about the insn sizes, but we may assume
23936 : : quite safely that we are informed about all 1 byte insns and memory
23937 : : address sizes. This is enough to eliminate unnecessary padding in
23938 : : 99% of cases. */
23939 : :
23940 : : int
23941 : 378378460 : ix86_min_insn_size (rtx_insn *insn)
23942 : : {
23943 : 378378460 : int l = 0, len;
23944 : :
23945 : 378378460 : if (!INSN_P (insn) || !active_insn_p (insn))
23946 : 499088 : return 0;
23947 : :
23948 : : /* Discard alignments we've emit and jump instructions. */
23949 : 377879372 : if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
23950 : 377879372 : && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
23951 : : return 0;
23952 : :
23953 : : /* Important case - calls are always 5 bytes.
23954 : : It is common to have many calls in the row. */
23955 : 377879367 : if (CALL_P (insn)
23956 : 9014926 : && symbolic_reference_mentioned_p (PATTERN (insn))
23957 : 386546662 : && !SIBLING_CALL_P (insn))
23958 : : return 5;
23959 : 369443025 : len = get_attr_length (insn);
23960 : 369443025 : if (len <= 1)
23961 : : return 1;
23962 : :
23963 : : /* For normal instructions we rely on get_attr_length being exact,
23964 : : with a few exceptions. */
23965 : 360790497 : if (!JUMP_P (insn))
23966 : : {
23967 : 355567504 : enum attr_type type = get_attr_type (insn);
23968 : :
23969 : 355567504 : switch (type)
23970 : : {
23971 : 93419 : case TYPE_MULTI:
23972 : 93419 : if (GET_CODE (PATTERN (insn)) == ASM_INPUT
23973 : 93419 : || asm_noperands (PATTERN (insn)) >= 0)
23974 : 502 : return 0;
23975 : : break;
23976 : : case TYPE_OTHER:
23977 : : case TYPE_FCMP:
23978 : : break;
23979 : : default:
23980 : : /* Otherwise trust get_attr_length. */
23981 : : return len;
23982 : : }
23983 : :
23984 : 467853 : l = get_attr_length_address (insn);
23985 : 467853 : if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
23986 : : l = 4;
23987 : : }
23988 : 377793 : if (l)
23989 : 90060 : return 1+l;
23990 : : else
23991 : 5600786 : return 2;
23992 : : }
23993 : :
23994 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
23995 : :
23996 : : /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
23997 : : window. */
23998 : :
23999 : : static void
24000 : 45346 : ix86_avoid_jump_mispredicts (void)
24001 : : {
24002 : 45346 : rtx_insn *insn, *start = get_insns ();
24003 : 45346 : int nbytes = 0, njumps = 0;
24004 : 45346 : bool isjump = false;
24005 : :
24006 : : /* Look for all minimal intervals of instructions containing 4 jumps.
24007 : : The intervals are bounded by START and INSN. NBYTES is the total
24008 : : size of instructions in the interval including INSN and not including
24009 : : START. When the NBYTES is smaller than 16 bytes, it is possible
24010 : : that the end of START and INSN ends up in the same 16byte page.
24011 : :
24012 : : The smallest offset in the page INSN can start is the case where START
24013 : : ends on the offset 0. Offset of INSN is then NBYTES - sizeof (INSN).
24014 : : We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
24015 : :
24016 : : Don't consider asm goto as jump, while it can contain a jump, it doesn't
24017 : : have to, control transfer to label(s) can be performed through other
24018 : : means, and also we estimate minimum length of all asm stmts as 0. */
24019 : 699354 : for (insn = start; insn; insn = NEXT_INSN (insn))
24020 : : {
24021 : 654008 : int min_size;
24022 : :
24023 : 654008 : if (LABEL_P (insn))
24024 : : {
24025 : 941 : align_flags alignment = label_to_alignment (insn);
24026 : 941 : int align = alignment.levels[0].log;
24027 : 941 : int max_skip = alignment.levels[0].maxskip;
24028 : :
24029 : 941 : if (max_skip > 15)
24030 : : max_skip = 15;
24031 : : /* If align > 3, only up to 16 - max_skip - 1 bytes can be
24032 : : already in the current 16 byte page, because otherwise
24033 : : ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
24034 : : bytes to reach 16 byte boundary. */
24035 : 941 : if (align <= 0
24036 : 313 : || (align <= 3 && max_skip != (1 << align) - 1))
24037 : 941 : max_skip = 0;
24038 : 941 : if (dump_file)
24039 : 0 : fprintf (dump_file, "Label %i with max_skip %i\n",
24040 : 0 : INSN_UID (insn), max_skip);
24041 : 941 : if (max_skip)
24042 : : {
24043 : 5975 : while (nbytes + max_skip >= 16)
24044 : : {
24045 : 5662 : start = NEXT_INSN (start);
24046 : 298 : if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
24047 : 5677 : || CALL_P (start))
24048 : 331 : njumps--, isjump = true;
24049 : : else
24050 : : isjump = false;
24051 : 5662 : nbytes -= ix86_min_insn_size (start);
24052 : : }
24053 : : }
24054 : 941 : continue;
24055 : 941 : }
24056 : :
24057 : 653067 : min_size = ix86_min_insn_size (insn);
24058 : 653067 : nbytes += min_size;
24059 : 653067 : if (dump_file)
24060 : 0 : fprintf (dump_file, "Insn %i estimated to %i bytes\n",
24061 : 0 : INSN_UID (insn), min_size);
24062 : 46488 : if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0)
24063 : 653087 : || CALL_P (insn))
24064 : 47505 : njumps++;
24065 : : else
24066 : 605562 : continue;
24067 : :
24068 : 55953 : while (njumps > 3)
24069 : : {
24070 : 8448 : start = NEXT_INSN (start);
24071 : 542 : if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
24072 : 8448 : || CALL_P (start))
24073 : 1247 : njumps--, isjump = true;
24074 : : else
24075 : : isjump = false;
24076 : 8448 : nbytes -= ix86_min_insn_size (start);
24077 : : }
24078 : 47505 : gcc_assert (njumps >= 0);
24079 : 47505 : if (dump_file)
24080 : 0 : fprintf (dump_file, "Interval %i to %i has %i bytes\n",
24081 : 0 : INSN_UID (start), INSN_UID (insn), nbytes);
24082 : :
24083 : 47505 : if (njumps == 3 && isjump && nbytes < 16)
24084 : : {
24085 : 40 : int padsize = 15 - nbytes + ix86_min_insn_size (insn);
24086 : :
24087 : 40 : if (dump_file)
24088 : 0 : fprintf (dump_file, "Padding insn %i by %i bytes!\n",
24089 : 0 : INSN_UID (insn), padsize);
24090 : 40 : emit_insn_before (gen_max_skip_align (GEN_INT (4), GEN_INT (padsize)), insn);
24091 : : }
24092 : : }
24093 : 45346 : }
24094 : : #endif
24095 : :
24096 : : /* AMD Athlon works faster
24097 : : when RET is not destination of conditional jump or directly preceded
24098 : : by other jump instruction. We avoid the penalty by inserting NOP just
24099 : : before the RET instructions in such cases. */
24100 : : static void
24101 : 45066 : ix86_pad_returns (void)
24102 : : {
24103 : 45066 : edge e;
24104 : 45066 : edge_iterator ei;
24105 : :
24106 : 90156 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
24107 : : {
24108 : 45090 : basic_block bb = e->src;
24109 : 45090 : rtx_insn *ret = BB_END (bb);
24110 : 45090 : rtx_insn *prev;
24111 : 45090 : bool replace = false;
24112 : :
24113 : 45080 : if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret))
24114 : 90170 : || optimize_bb_for_size_p (bb))
24115 : 23 : continue;
24116 : 179362 : for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
24117 : 133883 : if (active_insn_p (prev) || LABEL_P (prev))
24118 : : break;
24119 : 45067 : if (prev && LABEL_P (prev))
24120 : : {
24121 : 43 : edge e;
24122 : 43 : edge_iterator ei;
24123 : :
24124 : 56 : FOR_EACH_EDGE (e, ei, bb->preds)
24125 : 146 : if (EDGE_FREQUENCY (e) && e->src->index >= 0
24126 : 97 : && !(e->flags & EDGE_FALLTHRU))
24127 : : {
24128 : : replace = true;
24129 : : break;
24130 : : }
24131 : : }
24132 : 43 : if (!replace)
24133 : : {
24134 : 45031 : prev = prev_active_insn (ret);
24135 : 45031 : if (prev
24136 : 45031 : && ((JUMP_P (prev) && any_condjump_p (prev))
24137 : 44601 : || CALL_P (prev)))
24138 : : replace = true;
24139 : : /* Empty functions get branch mispredict even when
24140 : : the jump destination is not visible to us. */
24141 : 45031 : if (!prev && !optimize_function_for_size_p (cfun))
24142 : : replace = true;
24143 : : }
24144 : 44619 : if (replace)
24145 : : {
24146 : 483 : emit_jump_insn_before (gen_simple_return_internal_long (), ret);
24147 : 483 : delete_insn (ret);
24148 : : }
24149 : : }
24150 : 45066 : }
24151 : :
24152 : : /* Count the minimum number of instructions in BB. Return 4 if the
24153 : : number of instructions >= 4. */
24154 : :
24155 : : static int
24156 : 42 : ix86_count_insn_bb (basic_block bb)
24157 : : {
24158 : 42 : rtx_insn *insn;
24159 : 42 : int insn_count = 0;
24160 : :
24161 : : /* Count number of instructions in this block. Return 4 if the number
24162 : : of instructions >= 4. */
24163 : 308 : FOR_BB_INSNS (bb, insn)
24164 : : {
24165 : : /* Only happen in exit blocks. */
24166 : 302 : if (JUMP_P (insn)
24167 : 302 : && ANY_RETURN_P (PATTERN (insn)))
24168 : : break;
24169 : :
24170 : 278 : if (NONDEBUG_INSN_P (insn)
24171 : 102 : && GET_CODE (PATTERN (insn)) != USE
24172 : 362 : && GET_CODE (PATTERN (insn)) != CLOBBER)
24173 : : {
24174 : 84 : insn_count++;
24175 : 84 : if (insn_count >= 4)
24176 : : return insn_count;
24177 : : }
24178 : : }
24179 : :
24180 : : return insn_count;
24181 : : }
24182 : :
24183 : :
24184 : : /* Count the minimum number of instructions in code path in BB.
24185 : : Return 4 if the number of instructions >= 4. */
24186 : :
24187 : : static int
24188 : 62 : ix86_count_insn (basic_block bb)
24189 : : {
24190 : 62 : edge e;
24191 : 62 : edge_iterator ei;
24192 : 62 : int min_prev_count;
24193 : :
24194 : : /* Only bother counting instructions along paths with no
24195 : : more than 2 basic blocks between entry and exit. Given
24196 : : that BB has an edge to exit, determine if a predecessor
24197 : : of BB has an edge from entry. If so, compute the number
24198 : : of instructions in the predecessor block. If there
24199 : : happen to be multiple such blocks, compute the minimum. */
24200 : 62 : min_prev_count = 4;
24201 : 143 : FOR_EACH_EDGE (e, ei, bb->preds)
24202 : : {
24203 : 107 : edge prev_e;
24204 : 107 : edge_iterator prev_ei;
24205 : :
24206 : 107 : if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
24207 : : {
24208 : 26 : min_prev_count = 0;
24209 : 26 : break;
24210 : : }
24211 : 178 : FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds)
24212 : : {
24213 : 107 : if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
24214 : : {
24215 : 10 : int count = ix86_count_insn_bb (e->src);
24216 : 10 : if (count < min_prev_count)
24217 : 81 : min_prev_count = count;
24218 : : break;
24219 : : }
24220 : : }
24221 : : }
24222 : :
24223 : 62 : if (min_prev_count < 4)
24224 : 32 : min_prev_count += ix86_count_insn_bb (bb);
24225 : :
24226 : 62 : return min_prev_count;
24227 : : }
24228 : :
24229 : : /* Pad short function to 4 instructions. */
24230 : :
24231 : : static void
24232 : 63 : ix86_pad_short_function (void)
24233 : : {
24234 : 63 : edge e;
24235 : 63 : edge_iterator ei;
24236 : :
24237 : 128 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
24238 : : {
24239 : 65 : rtx_insn *ret = BB_END (e->src);
24240 : 65 : if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret)))
24241 : : {
24242 : 62 : int insn_count = ix86_count_insn (e->src);
24243 : :
24244 : : /* Pad short function. */
24245 : 62 : if (insn_count < 4)
24246 : : {
24247 : : rtx_insn *insn = ret;
24248 : :
24249 : : /* Find epilogue. */
24250 : : while (insn
24251 : 54 : && (!NOTE_P (insn)
24252 : 25 : || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG))
24253 : 31 : insn = PREV_INSN (insn);
24254 : :
24255 : 23 : if (!insn)
24256 : 0 : insn = ret;
24257 : :
24258 : : /* Two NOPs count as one instruction. */
24259 : 23 : insn_count = 2 * (4 - insn_count);
24260 : 23 : emit_insn_before (gen_nops (GEN_INT (insn_count)), insn);
24261 : : }
24262 : : }
24263 : : }
24264 : 63 : }
24265 : :
24266 : : /* Fix up a Windows system unwinder issue. If an EH region falls through into
24267 : : the epilogue, the Windows system unwinder will apply epilogue logic and
24268 : : produce incorrect offsets. This can be avoided by adding a nop between
24269 : : the last insn that can throw and the first insn of the epilogue. */
24270 : :
24271 : : static void
24272 : 0 : ix86_seh_fixup_eh_fallthru (void)
24273 : : {
24274 : 0 : edge e;
24275 : 0 : edge_iterator ei;
24276 : :
24277 : 0 : FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
24278 : : {
24279 : 0 : rtx_insn *insn, *next;
24280 : :
24281 : : /* Find the beginning of the epilogue. */
24282 : 0 : for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn))
24283 : 0 : if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
24284 : : break;
24285 : 0 : if (insn == NULL)
24286 : 0 : continue;
24287 : :
24288 : : /* We only care about preceding insns that can throw. */
24289 : 0 : insn = prev_active_insn (insn);
24290 : 0 : if (insn == NULL || !can_throw_internal (insn))
24291 : 0 : continue;
24292 : :
24293 : : /* Do not separate calls from their debug information. */
24294 : 0 : for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next))
24295 : 0 : if (NOTE_P (next) && NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION)
24296 : 0 : insn = next;
24297 : : else
24298 : : break;
24299 : :
24300 : 0 : emit_insn_after (gen_nops (const1_rtx), insn);
24301 : : }
24302 : 0 : }
24303 : : /* Split vector load from parm_decl to elemental loads to avoid STLF
24304 : : stalls. */
24305 : : static void
24306 : 959048 : ix86_split_stlf_stall_load ()
24307 : : {
24308 : 959048 : rtx_insn* insn, *start = get_insns ();
24309 : 959048 : unsigned window = 0;
24310 : :
24311 : 26873666 : for (insn = start; insn; insn = NEXT_INSN (insn))
24312 : : {
24313 : 26872833 : if (!NONDEBUG_INSN_P (insn))
24314 : 15242781 : continue;
24315 : 11630052 : window++;
24316 : : /* Insert 64 vaddps %xmm18, %xmm19, %xmm20(no dependence between each
24317 : : other, just emulate for pipeline) before stalled load, stlf stall
24318 : : case is as fast as no stall cases on CLX.
24319 : : Since CFG is freed before machine_reorg, just do a rough
24320 : : calculation of the window according to the layout. */
24321 : 11630052 : if (window > (unsigned) x86_stlf_window_ninsns)
24322 : : return;
24323 : :
24324 : 11612375 : if (any_uncondjump_p (insn)
24325 : 11576708 : || ANY_RETURN_P (PATTERN (insn))
24326 : 22824105 : || CALL_P (insn))
24327 : : return;
24328 : :
24329 : 10671837 : rtx set = single_set (insn);
24330 : 10671837 : if (!set)
24331 : 388314 : continue;
24332 : 10283523 : rtx src = SET_SRC (set);
24333 : 20566884 : if (!MEM_P (src)
24334 : : /* Only handle V2DFmode load since it doesn't need any scratch
24335 : : register. */
24336 : 1491493 : || GET_MODE (src) != E_V2DFmode
24337 : 5368 : || !MEM_EXPR (src)
24338 : 10287436 : || TREE_CODE (get_base_address (MEM_EXPR (src))) != PARM_DECL)
24339 : 10283361 : continue;
24340 : :
24341 : 162 : rtx zero = CONST0_RTX (V2DFmode);
24342 : 162 : rtx dest = SET_DEST (set);
24343 : 162 : rtx m = adjust_address (src, DFmode, 0);
24344 : 162 : rtx loadlpd = gen_sse2_loadlpd (dest, zero, m);
24345 : 162 : emit_insn_before (loadlpd, insn);
24346 : 162 : m = adjust_address (src, DFmode, 8);
24347 : 162 : rtx loadhpd = gen_sse2_loadhpd (dest, dest, m);
24348 : 162 : if (dump_file && (dump_flags & TDF_DETAILS))
24349 : : {
24350 : 0 : fputs ("Due to potential STLF stall, split instruction:\n",
24351 : : dump_file);
24352 : 0 : print_rtl_single (dump_file, insn);
24353 : 0 : fputs ("To:\n", dump_file);
24354 : 0 : print_rtl_single (dump_file, loadlpd);
24355 : 0 : print_rtl_single (dump_file, loadhpd);
24356 : : }
24357 : 162 : PATTERN (insn) = loadhpd;
24358 : 162 : INSN_CODE (insn) = -1;
24359 : 162 : gcc_assert (recog_memoized (insn) != -1);
24360 : : }
24361 : : }
24362 : :
24363 : : /* Implement machine specific optimizations. We implement padding of returns
24364 : : for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window. */
24365 : : static void
24366 : 1455683 : ix86_reorg (void)
24367 : : {
24368 : : /* We are freeing block_for_insn in the toplev to keep compatibility
24369 : : with old MDEP_REORGS that are not CFG based. Recompute it now. */
24370 : 1455683 : compute_bb_for_insn ();
24371 : :
24372 : 1455683 : if (TARGET_SEH && current_function_has_exception_handlers ())
24373 : : ix86_seh_fixup_eh_fallthru ();
24374 : :
24375 : 1455683 : if (optimize && optimize_function_for_speed_p (cfun))
24376 : : {
24377 : 961331 : if (TARGET_SSE2)
24378 : 959048 : ix86_split_stlf_stall_load ();
24379 : 961331 : if (TARGET_PAD_SHORT_FUNCTION)
24380 : 63 : ix86_pad_short_function ();
24381 : 961268 : else if (TARGET_PAD_RETURNS)
24382 : 45066 : ix86_pad_returns ();
24383 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
24384 : 961331 : if (TARGET_FOUR_JUMP_LIMIT)
24385 : 45346 : ix86_avoid_jump_mispredicts ();
24386 : : #endif
24387 : : }
24388 : 1455683 : }
24389 : :
24390 : : /* Return nonzero when QImode register that must be represented via REX prefix
24391 : : is used. */
24392 : : bool
24393 : 9316454 : x86_extended_QIreg_mentioned_p (rtx_insn *insn)
24394 : : {
24395 : 9316454 : int i;
24396 : 9316454 : extract_insn_cached (insn);
24397 : 35272558 : for (i = 0; i < recog_data.n_operands; i++)
24398 : 4933638 : if (GENERAL_REG_P (recog_data.operand[i])
24399 : 23261640 : && !QI_REGNO_P (REGNO (recog_data.operand[i])))
24400 : : return true;
24401 : : return false;
24402 : : }
24403 : :
24404 : : /* Return true when INSN mentions register that must be encoded using REX
24405 : : prefix. */
24406 : : bool
24407 : 193670666 : x86_extended_reg_mentioned_p (rtx insn)
24408 : : {
24409 : 193670666 : subrtx_iterator::array_type array;
24410 : 1010373119 : FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
24411 : : {
24412 : 864401639 : const_rtx x = *iter;
24413 : 864401639 : if (REG_P (x)
24414 : 864401639 : && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x))
24415 : 248076426 : || REX2_INT_REGNO_P (REGNO (x))))
24416 : 47699186 : return true;
24417 : : }
24418 : 145971480 : return false;
24419 : 193670666 : }
24420 : :
24421 : : /* Return true when INSN mentions register that must be encoded using REX2
24422 : : prefix. */
24423 : : bool
24424 : 2056627 : x86_extended_rex2reg_mentioned_p (rtx insn)
24425 : : {
24426 : 2056627 : subrtx_iterator::array_type array;
24427 : 9557310 : FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
24428 : : {
24429 : 7501350 : const_rtx x = *iter;
24430 : 7501350 : if (REG_P (x) && REX2_INT_REGNO_P (REGNO (x)))
24431 : 667 : return true;
24432 : : }
24433 : 2055960 : return false;
24434 : 2056627 : }
24435 : :
24436 : : /* Return true when rtx operands mentions register that must be encoded using
24437 : : evex prefix. */
24438 : : bool
24439 : 8 : x86_evex_reg_mentioned_p (rtx operands[], int nops)
24440 : : {
24441 : 8 : int i;
24442 : 20 : for (i = 0; i < nops; i++)
24443 : 16 : if (EXT_REX_SSE_REG_P (operands[i])
24444 : 28 : || x86_extended_rex2reg_mentioned_p (operands[i]))
24445 : 4 : return true;
24446 : : return false;
24447 : : }
24448 : :
24449 : : /* If profitable, negate (without causing overflow) integer constant
24450 : : of mode MODE at location LOC. Return true in this case. */
24451 : : bool
24452 : 5791518 : x86_maybe_negate_const_int (rtx *loc, machine_mode mode)
24453 : : {
24454 : 5791518 : HOST_WIDE_INT val;
24455 : :
24456 : 5791518 : if (!CONST_INT_P (*loc))
24457 : : return false;
24458 : :
24459 : 4916469 : switch (mode)
24460 : : {
24461 : 2775059 : case E_DImode:
24462 : : /* DImode x86_64 constants must fit in 32 bits. */
24463 : 2775059 : gcc_assert (x86_64_immediate_operand (*loc, mode));
24464 : :
24465 : : mode = SImode;
24466 : : break;
24467 : :
24468 : : case E_SImode:
24469 : : case E_HImode:
24470 : : case E_QImode:
24471 : : break;
24472 : :
24473 : 0 : default:
24474 : 0 : gcc_unreachable ();
24475 : : }
24476 : :
24477 : : /* Avoid overflows. */
24478 : 4916469 : if (mode_signbit_p (mode, *loc))
24479 : : return false;
24480 : :
24481 : 4916048 : val = INTVAL (*loc);
24482 : :
24483 : : /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
24484 : : Exceptions: -128 encodes smaller than 128, so swap sign and op. */
24485 : 4916048 : if ((val < 0 && val != -128)
24486 : 3232227 : || val == 128)
24487 : : {
24488 : 1694767 : *loc = GEN_INT (-val);
24489 : 1694767 : return true;
24490 : : }
24491 : :
24492 : : return false;
24493 : : }
24494 : :
24495 : : /* Generate an unsigned DImode/SImode to FP conversion. This is the same code
24496 : : optabs would emit if we didn't have TFmode patterns. */
24497 : :
24498 : : void
24499 : 4654 : x86_emit_floatuns (rtx operands[2])
24500 : : {
24501 : 4654 : rtx_code_label *neglab, *donelab;
24502 : 4654 : rtx i0, i1, f0, in, out;
24503 : 4654 : machine_mode mode, inmode;
24504 : :
24505 : 4654 : inmode = GET_MODE (operands[1]);
24506 : 4654 : gcc_assert (inmode == SImode || inmode == DImode);
24507 : :
24508 : 4654 : out = operands[0];
24509 : 4654 : in = force_reg (inmode, operands[1]);
24510 : 4654 : mode = GET_MODE (out);
24511 : 4654 : neglab = gen_label_rtx ();
24512 : 4654 : donelab = gen_label_rtx ();
24513 : 4654 : f0 = gen_reg_rtx (mode);
24514 : :
24515 : 4654 : emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
24516 : :
24517 : 4654 : expand_float (out, in, 0);
24518 : :
24519 : 4654 : emit_jump_insn (gen_jump (donelab));
24520 : 4654 : emit_barrier ();
24521 : :
24522 : 4654 : emit_label (neglab);
24523 : :
24524 : 4654 : i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
24525 : : 1, OPTAB_DIRECT);
24526 : 4654 : i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
24527 : : 1, OPTAB_DIRECT);
24528 : 4654 : i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
24529 : :
24530 : 4654 : expand_float (f0, i0, 0);
24531 : :
24532 : 4654 : emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0)));
24533 : :
24534 : 4654 : emit_label (donelab);
24535 : 4654 : }
24536 : :
24537 : : /* Return the diagnostic message string if conversion from FROMTYPE to
24538 : : TOTYPE is not allowed, NULL otherwise. */
24539 : :
24540 : : static const char *
24541 : 940933981 : ix86_invalid_conversion (const_tree fromtype, const_tree totype)
24542 : : {
24543 : 940933981 : machine_mode from_mode = element_mode (fromtype);
24544 : 940933981 : machine_mode to_mode = element_mode (totype);
24545 : :
24546 : 940933981 : if (!TARGET_SSE2 && from_mode != to_mode)
24547 : : {
24548 : : /* Do no allow conversions to/from BFmode/HFmode scalar types
24549 : : when TARGET_SSE2 is not available. */
24550 : 453378 : if (from_mode == BFmode)
24551 : : return N_("invalid conversion from type %<__bf16%> "
24552 : : "without option %<-msse2%>");
24553 : 453377 : if (from_mode == HFmode)
24554 : : return N_("invalid conversion from type %<_Float16%> "
24555 : : "without option %<-msse2%>");
24556 : 453377 : if (to_mode == BFmode)
24557 : : return N_("invalid conversion to type %<__bf16%> "
24558 : : "without option %<-msse2%>");
24559 : 453377 : if (to_mode == HFmode)
24560 : : return N_("invalid conversion to type %<_Float16%> "
24561 : : "without option %<-msse2%>");
24562 : : }
24563 : :
24564 : : /* Warn for silent implicit conversion between __bf16 and short,
24565 : : since __bfloat16 is refined as real __bf16 instead of short
24566 : : since GCC13. */
24567 : 940933979 : if (element_mode (fromtype) != element_mode (totype)
24568 : 940933979 : && (TARGET_AVX512BF16 || TARGET_AVXNECONVERT))
24569 : : {
24570 : : /* Warn for silent implicit conversion where user may expect
24571 : : a bitcast. */
24572 : 6732663 : if ((TYPE_MODE (fromtype) == BFmode
24573 : 13 : && TYPE_MODE (totype) == HImode)
24574 : 6732675 : || (TYPE_MODE (totype) == BFmode
24575 : 39 : && TYPE_MODE (fromtype) == HImode))
24576 : 1 : warning (0, "%<__bfloat16%> is redefined from typedef %<short%> "
24577 : : "to real %<__bf16%> since GCC 13.1, be careful of "
24578 : : "implicit conversion between %<__bf16%> and %<short%>; "
24579 : : "an explicit bitcast may be needed here");
24580 : : }
24581 : :
24582 : : /* Conversion allowed. */
24583 : : return NULL;
24584 : : }
24585 : :
24586 : : /* Return the diagnostic message string if the unary operation OP is
24587 : : not permitted on TYPE, NULL otherwise. */
24588 : :
24589 : : static const char *
24590 : 85104182 : ix86_invalid_unary_op (int op, const_tree type)
24591 : : {
24592 : 85104182 : machine_mode mmode = element_mode (type);
24593 : : /* Reject all single-operand operations on BFmode/HFmode except for &
24594 : : when TARGET_SSE2 is not available. */
24595 : 85104182 : if (!TARGET_SSE2 && op != ADDR_EXPR)
24596 : : {
24597 : 107730 : if (mmode == BFmode)
24598 : : return N_("operation not permitted on type %<__bf16%> "
24599 : : "without option %<-msse2%>");
24600 : 107730 : if (mmode == HFmode)
24601 : 0 : return N_("operation not permitted on type %<_Float16%> "
24602 : : "without option %<-msse2%>");
24603 : : }
24604 : :
24605 : : /* Operation allowed. */
24606 : : return NULL;
24607 : : }
24608 : :
24609 : : /* Return the diagnostic message string if the binary operation OP is
24610 : : not permitted on TYPE1 and TYPE2, NULL otherwise. */
24611 : :
24612 : : static const char *
24613 : 137418365 : ix86_invalid_binary_op (int op ATTRIBUTE_UNUSED, const_tree type1,
24614 : : const_tree type2)
24615 : : {
24616 : 137418365 : machine_mode type1_mode = element_mode (type1);
24617 : 137418365 : machine_mode type2_mode = element_mode (type2);
24618 : : /* Reject all 2-operand operations on BFmode or HFmode
24619 : : when TARGET_SSE2 is not available. */
24620 : 137418365 : if (!TARGET_SSE2)
24621 : : {
24622 : 979557 : if (type1_mode == BFmode || type2_mode == BFmode)
24623 : : return N_("operation not permitted on type %<__bf16%> "
24624 : : "without option %<-msse2%>");
24625 : :
24626 : 979557 : if (type1_mode == HFmode || type2_mode == HFmode)
24627 : 0 : return N_("operation not permitted on type %<_Float16%> "
24628 : : "without option %<-msse2%>");
24629 : : }
24630 : :
24631 : : /* Operation allowed. */
24632 : : return NULL;
24633 : : }
24634 : :
24635 : :
24636 : : /* Target hook for scalar_mode_supported_p. */
24637 : : static bool
24638 : 4322581 : ix86_scalar_mode_supported_p (scalar_mode mode)
24639 : : {
24640 : 4322581 : if (DECIMAL_FLOAT_MODE_P (mode))
24641 : 622223 : return default_decimal_float_supported_p ();
24642 : 3700358 : else if (mode == TFmode)
24643 : : return true;
24644 : 3380283 : else if (mode == HFmode || mode == BFmode)
24645 : : return true;
24646 : : else
24647 : 2742116 : return default_scalar_mode_supported_p (mode);
24648 : : }
24649 : :
24650 : : /* Implement TARGET_LIBGCC_FLOATING_POINT_MODE_SUPPORTED_P - return TRUE
24651 : : if MODE is HFmode, and punt to the generic implementation otherwise. */
24652 : :
24653 : : static bool
24654 : 2198659 : ix86_libgcc_floating_mode_supported_p (scalar_float_mode mode)
24655 : : {
24656 : : /* NB: Always return TRUE for HFmode so that the _Float16 type will
24657 : : be defined by the C front-end for AVX512FP16 intrinsics. We will
24658 : : issue an error in ix86_expand_move for HFmode if AVX512FP16 isn't
24659 : : enabled. */
24660 : 1880051 : return ((mode == HFmode || mode == BFmode)
24661 : 3760102 : ? true
24662 : 1561443 : : default_libgcc_floating_mode_supported_p (mode));
24663 : : }
24664 : :
24665 : : /* Implements target hook vector_mode_supported_p. */
24666 : : static bool
24667 : 1302142746 : ix86_vector_mode_supported_p (machine_mode mode)
24668 : : {
24669 : : /* For ia32, scalar TImode isn't supported and so V1TImode shouldn't be
24670 : : either. */
24671 : 1438508026 : if (!TARGET_64BIT && GET_MODE_INNER (mode) == TImode)
24672 : : return false;
24673 : 1302142620 : if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
24674 : : return true;
24675 : 1099116345 : if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
24676 : : return true;
24677 : 478550298 : if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
24678 : : return true;
24679 : 344764785 : if (TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
24680 : : return true;
24681 : 218698764 : if ((TARGET_MMX || TARGET_MMX_WITH_SSE)
24682 : 218642590 : && VALID_MMX_REG_MODE (mode))
24683 : : return true;
24684 : 27352161 : if ((TARGET_3DNOW || TARGET_MMX_WITH_SSE)
24685 : 26743056 : && VALID_MMX_REG_MODE_3DNOW (mode))
24686 : : return true;
24687 : 18412858 : if (mode == V2QImode)
24688 : 22878 : return true;
24689 : : return false;
24690 : : }
24691 : :
24692 : : /* Target hook for c_mode_for_suffix. */
24693 : : static machine_mode
24694 : 81253 : ix86_c_mode_for_suffix (char suffix)
24695 : : {
24696 : 81253 : if (suffix == 'q')
24697 : : return TFmode;
24698 : 37 : if (suffix == 'w')
24699 : : return XFmode;
24700 : :
24701 : 0 : return VOIDmode;
24702 : : }
24703 : :
24704 : : /* Helper function to map common constraints to non-EGPR ones.
24705 : : All related constraints have h prefix, and h plus Upper letter
24706 : : means the constraint is strictly EGPR enabled, while h plus
24707 : : lower letter indicates the constraint is strictly gpr16 only.
24708 : :
24709 : : Specially for "g" constraint, split it to rmi as there is
24710 : : no corresponding general constraint define for backend.
24711 : :
24712 : : Here is the full list to map constraints that may involve
24713 : : gpr to h prefixed.
24714 : :
24715 : : "g" -> "jrjmi"
24716 : : "r" -> "jr"
24717 : : "m" -> "jm"
24718 : : "<" -> "j<"
24719 : : ">" -> "j>"
24720 : : "o" -> "jo"
24721 : : "V" -> "jV"
24722 : : "p" -> "jp"
24723 : : "Bm" -> "ja"
24724 : : */
24725 : :
24726 : 49 : static void map_egpr_constraints (vec<const char *> &constraints)
24727 : : {
24728 : 59 : for (size_t i = 0; i < constraints.length(); i++)
24729 : : {
24730 : 10 : const char *cur = constraints[i];
24731 : :
24732 : 10 : if (startswith (cur, "=@cc"))
24733 : 0 : continue;
24734 : :
24735 : 10 : int len = strlen (cur);
24736 : 10 : auto_vec<char> buf;
24737 : :
24738 : 24 : for (int j = 0; j < len; j++)
24739 : : {
24740 : 14 : switch (cur[j])
24741 : : {
24742 : 2 : case 'g':
24743 : 2 : buf.safe_push ('j');
24744 : 2 : buf.safe_push ('r');
24745 : 2 : buf.safe_push ('j');
24746 : 2 : buf.safe_push ('m');
24747 : 2 : buf.safe_push ('i');
24748 : 2 : break;
24749 : 8 : case 'r':
24750 : 8 : case 'm':
24751 : 8 : case '<':
24752 : 8 : case '>':
24753 : 8 : case 'o':
24754 : 8 : case 'V':
24755 : 8 : case 'p':
24756 : 8 : buf.safe_push ('j');
24757 : 8 : buf.safe_push (cur[j]);
24758 : 8 : break;
24759 : 0 : case 'B':
24760 : 0 : if (cur[j + 1] == 'm')
24761 : : {
24762 : 0 : buf.safe_push ('j');
24763 : 0 : buf.safe_push ('a');
24764 : 0 : j++;
24765 : : }
24766 : : else
24767 : : {
24768 : 0 : buf.safe_push (cur[j]);
24769 : 0 : buf.safe_push (cur[j + 1]);
24770 : 0 : j++;
24771 : : }
24772 : : break;
24773 : 0 : case 'T':
24774 : 0 : case 'Y':
24775 : 0 : case 'W':
24776 : 0 : case 'j':
24777 : 0 : buf.safe_push (cur[j]);
24778 : 0 : buf.safe_push (cur[j + 1]);
24779 : 0 : j++;
24780 : 0 : break;
24781 : 4 : default:
24782 : 4 : buf.safe_push (cur[j]);
24783 : 4 : break;
24784 : : }
24785 : : }
24786 : 10 : buf.safe_push ('\0');
24787 : 20 : constraints[i] = xstrdup (buf.address ());
24788 : 10 : }
24789 : 49 : }
24790 : :
24791 : : /* Worker function for TARGET_MD_ASM_ADJUST.
24792 : :
24793 : : We implement asm flag outputs, and maintain source compatibility
24794 : : with the old cc0-based compiler. */
24795 : :
24796 : : static rtx_insn *
24797 : 104828 : ix86_md_asm_adjust (vec<rtx> &outputs, vec<rtx> & /*inputs*/,
24798 : : vec<machine_mode> & /*input_modes*/,
24799 : : vec<const char *> &constraints, vec<rtx> &/*uses*/,
24800 : : vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs,
24801 : : location_t loc)
24802 : : {
24803 : 104828 : bool saw_asm_flag = false;
24804 : :
24805 : 104828 : start_sequence ();
24806 : :
24807 : 104828 : if (TARGET_APX_EGPR && !ix86_apx_inline_asm_use_gpr32)
24808 : 49 : map_egpr_constraints (constraints);
24809 : :
24810 : 280519 : for (unsigned i = 0, n = outputs.length (); i < n; ++i)
24811 : : {
24812 : 71821 : const char *con = constraints[i];
24813 : 71821 : if (!startswith (con, "=@cc"))
24814 : 71734 : continue;
24815 : 87 : con += 4;
24816 : 87 : if (strchr (con, ',') != NULL)
24817 : : {
24818 : 1 : error_at (loc, "alternatives not allowed in %<asm%> flag output");
24819 : 1 : continue;
24820 : : }
24821 : :
24822 : 86 : bool invert = false;
24823 : 86 : if (con[0] == 'n')
24824 : 19 : invert = true, con++;
24825 : :
24826 : 86 : machine_mode mode = CCmode;
24827 : 86 : rtx_code code = UNKNOWN;
24828 : :
24829 : 86 : switch (con[0])
24830 : : {
24831 : 15 : case 'a':
24832 : 15 : if (con[1] == 0)
24833 : : mode = CCAmode, code = EQ;
24834 : 4 : else if (con[1] == 'e' && con[2] == 0)
24835 : : mode = CCCmode, code = NE;
24836 : : break;
24837 : 11 : case 'b':
24838 : 11 : if (con[1] == 0)
24839 : : mode = CCCmode, code = EQ;
24840 : 6 : else if (con[1] == 'e' && con[2] == 0)
24841 : : mode = CCAmode, code = NE;
24842 : : break;
24843 : 14 : case 'c':
24844 : 14 : if (con[1] == 0)
24845 : : mode = CCCmode, code = EQ;
24846 : : break;
24847 : 8 : case 'e':
24848 : 8 : if (con[1] == 0)
24849 : : mode = CCZmode, code = EQ;
24850 : : break;
24851 : 11 : case 'g':
24852 : 11 : if (con[1] == 0)
24853 : : mode = CCGCmode, code = GT;
24854 : 5 : else if (con[1] == 'e' && con[2] == 0)
24855 : : mode = CCGCmode, code = GE;
24856 : : break;
24857 : 10 : case 'l':
24858 : 10 : if (con[1] == 0)
24859 : : mode = CCGCmode, code = LT;
24860 : 5 : else if (con[1] == 'e' && con[2] == 0)
24861 : : mode = CCGCmode, code = LE;
24862 : : break;
24863 : 4 : case 'o':
24864 : 4 : if (con[1] == 0)
24865 : : mode = CCOmode, code = EQ;
24866 : : break;
24867 : 4 : case 'p':
24868 : 4 : if (con[1] == 0)
24869 : : mode = CCPmode, code = EQ;
24870 : : break;
24871 : 4 : case 's':
24872 : 4 : if (con[1] == 0)
24873 : : mode = CCSmode, code = EQ;
24874 : : break;
24875 : 5 : case 'z':
24876 : 5 : if (con[1] == 0)
24877 : : mode = CCZmode, code = EQ;
24878 : : break;
24879 : : }
24880 : 1 : if (code == UNKNOWN)
24881 : : {
24882 : 1 : error_at (loc, "unknown %<asm%> flag output %qs", constraints[i]);
24883 : 1 : continue;
24884 : : }
24885 : 85 : if (invert)
24886 : 19 : code = reverse_condition (code);
24887 : :
24888 : 85 : rtx dest = outputs[i];
24889 : 85 : if (!saw_asm_flag)
24890 : : {
24891 : : /* This is the first asm flag output. Here we put the flags
24892 : : register in as the real output and adjust the condition to
24893 : : allow it. */
24894 : 74 : constraints[i] = "=Bf";
24895 : 74 : outputs[i] = gen_rtx_REG (CCmode, FLAGS_REG);
24896 : 74 : saw_asm_flag = true;
24897 : : }
24898 : : else
24899 : : {
24900 : : /* We don't need the flags register as output twice. */
24901 : 11 : constraints[i] = "=X";
24902 : 11 : outputs[i] = gen_rtx_SCRATCH (SImode);
24903 : : }
24904 : :
24905 : 85 : rtx x = gen_rtx_REG (mode, FLAGS_REG);
24906 : 85 : x = gen_rtx_fmt_ee (code, QImode, x, const0_rtx);
24907 : :
24908 : 85 : machine_mode dest_mode = GET_MODE (dest);
24909 : 85 : if (!SCALAR_INT_MODE_P (dest_mode))
24910 : : {
24911 : 3 : error_at (loc, "invalid type for %<asm%> flag output");
24912 : 3 : continue;
24913 : : }
24914 : :
24915 : 82 : if (dest_mode == QImode)
24916 : 72 : emit_insn (gen_rtx_SET (dest, x));
24917 : : else
24918 : : {
24919 : 10 : rtx reg = gen_reg_rtx (QImode);
24920 : 10 : emit_insn (gen_rtx_SET (reg, x));
24921 : :
24922 : 10 : reg = convert_to_mode (dest_mode, reg, 1);
24923 : 10 : emit_move_insn (dest, reg);
24924 : : }
24925 : : }
24926 : :
24927 : 104828 : rtx_insn *seq = end_sequence ();
24928 : :
24929 : 104828 : if (saw_asm_flag)
24930 : : return seq;
24931 : : else
24932 : : {
24933 : : /* If we had no asm flag outputs, clobber the flags. */
24934 : 104754 : clobbers.safe_push (gen_rtx_REG (CCmode, FLAGS_REG));
24935 : 104754 : SET_HARD_REG_BIT (clobbered_regs, FLAGS_REG);
24936 : 104754 : return NULL;
24937 : : }
24938 : : }
24939 : :
24940 : : /* Implements target vector targetm.asm.encode_section_info. */
24941 : :
24942 : : static void ATTRIBUTE_UNUSED
24943 : 9827065 : ix86_encode_section_info (tree decl, rtx rtl, int first)
24944 : : {
24945 : 9827065 : default_encode_section_info (decl, rtl, first);
24946 : :
24947 : 9827065 : if (ix86_in_large_data_p (decl))
24948 : 32 : SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
24949 : 9827065 : }
24950 : :
24951 : : /* Worker function for REVERSE_CONDITION. */
24952 : :
24953 : : enum rtx_code
24954 : 30755749 : ix86_reverse_condition (enum rtx_code code, machine_mode mode)
24955 : : {
24956 : 30755749 : return (mode == CCFPmode
24957 : 30755749 : ? reverse_condition_maybe_unordered (code)
24958 : 26499427 : : reverse_condition (code));
24959 : : }
24960 : :
24961 : : /* Output code to perform an x87 FP register move, from OPERANDS[1]
24962 : : to OPERANDS[0]. */
24963 : :
24964 : : const char *
24965 : 662742 : output_387_reg_move (rtx_insn *insn, rtx *operands)
24966 : : {
24967 : 662742 : if (REG_P (operands[0]))
24968 : : {
24969 : 553544 : if (REG_P (operands[1])
24970 : 553544 : && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
24971 : : {
24972 : 303292 : if (REGNO (operands[0]) == FIRST_STACK_REG)
24973 : 282646 : return output_387_ffreep (operands, 0);
24974 : : return "fstp\t%y0";
24975 : : }
24976 : 250252 : if (STACK_TOP_P (operands[0]))
24977 : 250252 : return "fld%Z1\t%y1";
24978 : : return "fst\t%y0";
24979 : : }
24980 : 109198 : else if (MEM_P (operands[0]))
24981 : : {
24982 : 109198 : gcc_assert (REG_P (operands[1]));
24983 : 109198 : if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
24984 : : return "fstp%Z0\t%y0";
24985 : : else
24986 : : {
24987 : : /* There is no non-popping store to memory for XFmode.
24988 : : So if we need one, follow the store with a load. */
24989 : 8006 : if (GET_MODE (operands[0]) == XFmode)
24990 : : return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
24991 : : else
24992 : 1845 : return "fst%Z0\t%y0";
24993 : : }
24994 : : }
24995 : : else
24996 : 0 : gcc_unreachable();
24997 : : }
24998 : : #ifdef TARGET_SOLARIS
24999 : : /* Solaris implementation of TARGET_ASM_NAMED_SECTION. */
25000 : :
25001 : : static void
25002 : : i386_solaris_elf_named_section (const char *name, unsigned int flags,
25003 : : tree decl)
25004 : : {
25005 : : /* With Binutils 2.15, the "@unwind" marker must be specified on
25006 : : every occurrence of the ".eh_frame" section, not just the first
25007 : : one. */
25008 : : if (TARGET_64BIT
25009 : : && strcmp (name, ".eh_frame") == 0)
25010 : : {
25011 : : fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
25012 : : flags & SECTION_WRITE ? "aw" : "a");
25013 : : return;
25014 : : }
25015 : :
25016 : : #ifndef USE_GAS
25017 : : if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
25018 : : {
25019 : : solaris_elf_asm_comdat_section (name, flags, decl);
25020 : : return;
25021 : : }
25022 : :
25023 : : /* Solaris/x86 as uses the same syntax for the SHF_EXCLUDE flags as the
25024 : : SPARC assembler. One cannot mix single-letter flags and #exclude, so
25025 : : only emit the latter here. */
25026 : : if (flags & SECTION_EXCLUDE)
25027 : : {
25028 : : fprintf (asm_out_file, "\t.section\t%s,#exclude\n", name);
25029 : : return;
25030 : : }
25031 : : #endif
25032 : :
25033 : : default_elf_asm_named_section (name, flags, decl);
25034 : : }
25035 : : #endif /* TARGET_SOLARIS */
25036 : :
25037 : : /* Return the mangling of TYPE if it is an extended fundamental type. */
25038 : :
25039 : : static const char *
25040 : 893185807 : ix86_mangle_type (const_tree type)
25041 : : {
25042 : 893185807 : type = TYPE_MAIN_VARIANT (type);
25043 : :
25044 : 893185807 : if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
25045 : : && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
25046 : : return NULL;
25047 : :
25048 : 487764763 : if (type == float128_type_node || type == float64x_type_node)
25049 : : return NULL;
25050 : :
25051 : 486871491 : switch (TYPE_MODE (type))
25052 : : {
25053 : : case E_BFmode:
25054 : : return "DF16b";
25055 : 496903 : case E_HFmode:
25056 : : /* _Float16 is "DF16_".
25057 : : Align with clang's decision in https://reviews.llvm.org/D33719. */
25058 : 496903 : return "DF16_";
25059 : 476857 : case E_TFmode:
25060 : : /* __float128 is "g". */
25061 : 476857 : return "g";
25062 : 7022085 : case E_XFmode:
25063 : : /* "long double" or __float80 is "e". */
25064 : 7022085 : return "e";
25065 : : default:
25066 : : return NULL;
25067 : : }
25068 : : }
25069 : :
25070 : : /* Create C++ tinfo symbols for only conditionally available fundamental
25071 : : types. */
25072 : :
25073 : : static void
25074 : 5 : ix86_emit_support_tinfos (emit_support_tinfos_callback callback)
25075 : : {
25076 : 5 : extern tree ix86_float16_type_node;
25077 : 5 : extern tree ix86_bf16_type_node;
25078 : :
25079 : 5 : if (!TARGET_SSE2)
25080 : : {
25081 : 0 : if (!float16_type_node)
25082 : 0 : float16_type_node = ix86_float16_type_node;
25083 : 0 : if (!bfloat16_type_node)
25084 : 0 : bfloat16_type_node = ix86_bf16_type_node;
25085 : 0 : callback (float16_type_node);
25086 : 0 : callback (bfloat16_type_node);
25087 : 0 : float16_type_node = NULL_TREE;
25088 : 0 : bfloat16_type_node = NULL_TREE;
25089 : : }
25090 : 5 : }
25091 : :
25092 : : static GTY(()) tree ix86_tls_stack_chk_guard_decl;
25093 : :
25094 : : static tree
25095 : 236 : ix86_stack_protect_guard (void)
25096 : : {
25097 : 236 : if (TARGET_SSP_TLS_GUARD)
25098 : : {
25099 : 233 : tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1);
25100 : 233 : int qual = ENCODE_QUAL_ADDR_SPACE (ix86_stack_protector_guard_reg);
25101 : 233 : tree type = build_qualified_type (type_node, qual);
25102 : 233 : tree t;
25103 : :
25104 : 233 : if (OPTION_SET_P (ix86_stack_protector_guard_symbol_str))
25105 : : {
25106 : 1 : t = ix86_tls_stack_chk_guard_decl;
25107 : :
25108 : 1 : if (t == NULL)
25109 : : {
25110 : 1 : rtx x;
25111 : :
25112 : 1 : t = build_decl
25113 : 1 : (UNKNOWN_LOCATION, VAR_DECL,
25114 : : get_identifier (ix86_stack_protector_guard_symbol_str),
25115 : : type);
25116 : 1 : TREE_STATIC (t) = 1;
25117 : 1 : TREE_PUBLIC (t) = 1;
25118 : 1 : DECL_EXTERNAL (t) = 1;
25119 : 1 : TREE_USED (t) = 1;
25120 : 1 : TREE_THIS_VOLATILE (t) = 1;
25121 : 1 : DECL_ARTIFICIAL (t) = 1;
25122 : 1 : DECL_IGNORED_P (t) = 1;
25123 : :
25124 : : /* Do not share RTL as the declaration is visible outside of
25125 : : current function. */
25126 : 1 : x = DECL_RTL (t);
25127 : 1 : RTX_FLAG (x, used) = 1;
25128 : :
25129 : 1 : ix86_tls_stack_chk_guard_decl = t;
25130 : : }
25131 : : }
25132 : : else
25133 : : {
25134 : 232 : tree asptrtype = build_pointer_type (type);
25135 : :
25136 : 232 : t = build_int_cst (asptrtype, ix86_stack_protector_guard_offset);
25137 : 232 : t = build2 (MEM_REF, asptrtype, t,
25138 : : build_int_cst (asptrtype, 0));
25139 : 232 : TREE_THIS_VOLATILE (t) = 1;
25140 : : }
25141 : :
25142 : 233 : return t;
25143 : : }
25144 : :
25145 : 3 : return default_stack_protect_guard ();
25146 : : }
25147 : :
25148 : : static bool
25149 : 737 : ix86_stack_protect_runtime_enabled_p (void)
25150 : : {
25151 : : /* Naked functions should not enable stack protector. */
25152 : 737 : return !ix86_function_naked (current_function_decl);
25153 : : }
25154 : :
25155 : : /* For 32-bit code we can save PIC register setup by using
25156 : : __stack_chk_fail_local hidden function instead of calling
25157 : : __stack_chk_fail directly. 64-bit code doesn't need to setup any PIC
25158 : : register, so it is better to call __stack_chk_fail directly. */
25159 : :
25160 : : static tree ATTRIBUTE_UNUSED
25161 : 262 : ix86_stack_protect_fail (void)
25162 : : {
25163 : 262 : return TARGET_64BIT
25164 : 262 : ? default_external_stack_protect_fail ()
25165 : 1 : : default_hidden_stack_protect_fail ();
25166 : : }
25167 : :
25168 : : /* Select a format to encode pointers in exception handling data. CODE
25169 : : is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
25170 : : true if the symbol may be affected by dynamic relocations.
25171 : :
25172 : : ??? All x86 object file formats are capable of representing this.
25173 : : After all, the relocation needed is the same as for the call insn.
25174 : : Whether or not a particular assembler allows us to enter such, I
25175 : : guess we'll have to see. */
25176 : :
25177 : : int
25178 : 786288 : asm_preferred_eh_data_format (int code, int global)
25179 : : {
25180 : : /* PE-COFF is effectively always -fPIC because of the .reloc section. */
25181 : 786288 : if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access)
25182 : : {
25183 : 37224 : int type = DW_EH_PE_sdata8;
25184 : 37224 : if (ptr_mode == SImode
25185 : 23472 : || ix86_cmodel == CM_SMALL_PIC
25186 : 37290 : || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
25187 : : type = DW_EH_PE_sdata4;
25188 : 52205 : return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
25189 : : }
25190 : :
25191 : 749064 : if (ix86_cmodel == CM_SMALL
25192 : 18727 : || (ix86_cmodel == CM_MEDIUM && code))
25193 : 730348 : return DW_EH_PE_udata4;
25194 : :
25195 : : return DW_EH_PE_absptr;
25196 : : }
25197 : :
25198 : : /* Implement targetm.vectorize.builtin_vectorization_cost. */
25199 : : static int
25200 : 15567344 : ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
25201 : : tree vectype, int)
25202 : : {
25203 : 15567344 : bool fp = false;
25204 : 15567344 : machine_mode mode = TImode;
25205 : 15567344 : int index;
25206 : 15567344 : if (vectype != NULL)
25207 : : {
25208 : 14584924 : fp = FLOAT_TYPE_P (vectype);
25209 : 14584924 : mode = TYPE_MODE (vectype);
25210 : : }
25211 : :
25212 : 15567344 : switch (type_of_cost)
25213 : : {
25214 : 2554601 : case scalar_stmt:
25215 : 2554601 : return fp ? ix86_cost->addss : COSTS_N_INSNS (1);
25216 : :
25217 : 1821597 : case scalar_load:
25218 : : /* load/store costs are relative to register move which is 2. Recompute
25219 : : it to COSTS_N_INSNS so everything have same base. */
25220 : 3643194 : return COSTS_N_INSNS (fp ? ix86_cost->sse_load[0]
25221 : 1821597 : : ix86_cost->int_load [2]) / 2;
25222 : :
25223 : 3995318 : case scalar_store:
25224 : 7990636 : return COSTS_N_INSNS (fp ? ix86_cost->sse_store[0]
25225 : 3995318 : : ix86_cost->int_store [2]) / 2;
25226 : :
25227 : 954141 : case vector_stmt:
25228 : 1908282 : return ix86_vec_cost (mode,
25229 : 1908282 : fp ? ix86_cost->addss : ix86_cost->sse_op);
25230 : :
25231 : 1750079 : case vector_load:
25232 : 1750079 : index = sse_store_index (mode);
25233 : : /* See PR82713 - we may end up being called on non-vector type. */
25234 : 1750079 : if (index < 0)
25235 : 94764 : index = 2;
25236 : 1750079 : return COSTS_N_INSNS (ix86_cost->sse_load[index]) / 2;
25237 : :
25238 : 1040013 : case vector_store:
25239 : 1040013 : index = sse_store_index (mode);
25240 : : /* See PR82713 - we may end up being called on non-vector type. */
25241 : 1040013 : if (index < 0)
25242 : 90259 : index = 2;
25243 : 1040013 : return COSTS_N_INSNS (ix86_cost->sse_store[index]) / 2;
25244 : :
25245 : 1011492 : case vec_to_scalar:
25246 : 1011492 : case scalar_to_vec:
25247 : 1011492 : return ix86_vec_cost (mode, ix86_cost->sse_op);
25248 : :
25249 : : /* We should have separate costs for unaligned loads and gather/scatter.
25250 : : Do that incrementally. */
25251 : 371925 : case unaligned_load:
25252 : 371925 : index = sse_store_index (mode);
25253 : : /* See PR82713 - we may end up being called on non-vector type. */
25254 : 371925 : if (index < 0)
25255 : 2606 : index = 2;
25256 : 371925 : return COSTS_N_INSNS (ix86_cost->sse_unaligned_load[index]) / 2;
25257 : :
25258 : 781810 : case unaligned_store:
25259 : 781810 : index = sse_store_index (mode);
25260 : : /* See PR82713 - we may end up being called on non-vector type. */
25261 : 781810 : if (index < 0)
25262 : 15292 : index = 2;
25263 : 781810 : return COSTS_N_INSNS (ix86_cost->sse_unaligned_store[index]) / 2;
25264 : :
25265 : 0 : case vector_gather_load:
25266 : 0 : return ix86_vec_cost (mode,
25267 : 0 : COSTS_N_INSNS
25268 : : (ix86_cost->gather_static
25269 : : + ix86_cost->gather_per_elt
25270 : 0 : * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
25271 : :
25272 : 0 : case vector_scatter_store:
25273 : 0 : return ix86_vec_cost (mode,
25274 : 0 : COSTS_N_INSNS
25275 : : (ix86_cost->scatter_static
25276 : : + ix86_cost->scatter_per_elt
25277 : 0 : * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
25278 : :
25279 : 242092 : case cond_branch_taken:
25280 : 242092 : return ix86_cost->cond_taken_branch_cost;
25281 : :
25282 : 4919 : case cond_branch_not_taken:
25283 : 4919 : return ix86_cost->cond_not_taken_branch_cost;
25284 : :
25285 : 250436 : case vec_perm:
25286 : 250436 : return ix86_vec_cost (mode, ix86_cost->sse_op);
25287 : :
25288 : 68891 : case vec_promote_demote:
25289 : 68891 : if (fp)
25290 : 7754 : return vec_fp_conversion_cost (ix86_tune_cost, mode);
25291 : 61137 : return ix86_vec_cost (mode, ix86_cost->sse_op);
25292 : :
25293 : 720030 : case vec_construct:
25294 : 720030 : {
25295 : 720030 : int n = TYPE_VECTOR_SUBPARTS (vectype);
25296 : : /* N - 1 element inserts into an SSE vector, the possible
25297 : : GPR -> XMM move is accounted for in add_stmt_cost. */
25298 : 1440060 : if (GET_MODE_BITSIZE (mode) <= 128)
25299 : 712888 : return (n - 1) * ix86_cost->sse_op;
25300 : : /* One vinserti128 for combining two SSE vectors for AVX256. */
25301 : 14284 : else if (GET_MODE_BITSIZE (mode) == 256)
25302 : 5570 : return ((n - 2) * ix86_cost->sse_op
25303 : 5570 : + ix86_vec_cost (mode, ix86_cost->sse_op));
25304 : : /* One vinserti64x4 and two vinserti128 for combining SSE
25305 : : and AVX256 vectors to AVX512. */
25306 : 3144 : else if (GET_MODE_BITSIZE (mode) == 512)
25307 : : {
25308 : 1572 : machine_mode half_mode
25309 : 1572 : = mode_for_vector (GET_MODE_INNER (mode),
25310 : 3144 : GET_MODE_NUNITS (mode) / 2).require ();
25311 : 1572 : return ((n - 4) * ix86_cost->sse_op
25312 : 1572 : + 2 * ix86_vec_cost (half_mode, ix86_cost->sse_op)
25313 : 1572 : + ix86_vec_cost (mode, ix86_cost->sse_op));
25314 : : }
25315 : 0 : gcc_unreachable ();
25316 : : }
25317 : :
25318 : 0 : default:
25319 : 0 : gcc_unreachable ();
25320 : : }
25321 : : }
25322 : :
25323 : :
25324 : : /* This function returns the calling abi specific va_list type node.
25325 : : It returns the FNDECL specific va_list type. */
25326 : :
25327 : : static tree
25328 : 47087 : ix86_fn_abi_va_list (tree fndecl)
25329 : : {
25330 : 47087 : if (!TARGET_64BIT)
25331 : 698 : return va_list_type_node;
25332 : 46389 : gcc_assert (fndecl != NULL_TREE);
25333 : :
25334 : 46389 : if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
25335 : 12868 : return ms_va_list_type_node;
25336 : : else
25337 : 33521 : return sysv_va_list_type_node;
25338 : : }
25339 : :
25340 : : /* Returns the canonical va_list type specified by TYPE. If there
25341 : : is no valid TYPE provided, it return NULL_TREE. */
25342 : :
25343 : : static tree
25344 : 245581 : ix86_canonical_va_list_type (tree type)
25345 : : {
25346 : 245581 : if (TARGET_64BIT)
25347 : : {
25348 : 245079 : if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type)))
25349 : 5944 : return ms_va_list_type_node;
25350 : :
25351 : 239135 : if ((TREE_CODE (type) == ARRAY_TYPE
25352 : 49767 : && integer_zerop (array_type_nelts_minus_one (type)))
25353 : 239135 : || POINTER_TYPE_P (type))
25354 : : {
25355 : 187463 : tree elem_type = TREE_TYPE (type);
25356 : 187463 : if (TREE_CODE (elem_type) == RECORD_TYPE
25357 : 338384 : && lookup_attribute ("sysv_abi va_list",
25358 : 150921 : TYPE_ATTRIBUTES (elem_type)))
25359 : 150921 : return sysv_va_list_type_node;
25360 : : }
25361 : :
25362 : 88214 : return NULL_TREE;
25363 : : }
25364 : :
25365 : 502 : return std_canonical_va_list_type (type);
25366 : : }
25367 : :
25368 : : /* Iterate through the target-specific builtin types for va_list.
25369 : : IDX denotes the iterator, *PTREE is set to the result type of
25370 : : the va_list builtin, and *PNAME to its internal type.
25371 : : Returns zero if there is no element for this index, otherwise
25372 : : IDX should be increased upon the next call.
25373 : : Note, do not iterate a base builtin's name like __builtin_va_list.
25374 : : Used from c_common_nodes_and_builtins. */
25375 : :
25376 : : static int
25377 : 610368 : ix86_enum_va_list (int idx, const char **pname, tree *ptree)
25378 : : {
25379 : 610368 : if (TARGET_64BIT)
25380 : : {
25381 : 605061 : switch (idx)
25382 : : {
25383 : : default:
25384 : : break;
25385 : :
25386 : 201687 : case 0:
25387 : 201687 : *ptree = ms_va_list_type_node;
25388 : 201687 : *pname = "__builtin_ms_va_list";
25389 : 201687 : return 1;
25390 : :
25391 : 201687 : case 1:
25392 : 201687 : *ptree = sysv_va_list_type_node;
25393 : 201687 : *pname = "__builtin_sysv_va_list";
25394 : 201687 : return 1;
25395 : : }
25396 : : }
25397 : :
25398 : : return 0;
25399 : : }
25400 : :
25401 : : #undef TARGET_SCHED_DISPATCH
25402 : : #define TARGET_SCHED_DISPATCH ix86_bd_has_dispatch
25403 : : #undef TARGET_SCHED_DISPATCH_DO
25404 : : #define TARGET_SCHED_DISPATCH_DO ix86_bd_do_dispatch
25405 : : #undef TARGET_SCHED_REASSOCIATION_WIDTH
25406 : : #define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width
25407 : : #undef TARGET_SCHED_REORDER
25408 : : #define TARGET_SCHED_REORDER ix86_atom_sched_reorder
25409 : : #undef TARGET_SCHED_ADJUST_PRIORITY
25410 : : #define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority
25411 : : #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
25412 : : #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
25413 : : ix86_dependencies_evaluation_hook
25414 : :
25415 : :
25416 : : /* Implementation of reassociation_width target hook used by
25417 : : reassoc phase to identify parallelism level in reassociated
25418 : : tree. Statements tree_code is passed in OPC. Arguments type
25419 : : is passed in MODE. */
25420 : :
25421 : : static int
25422 : 31950 : ix86_reassociation_width (unsigned int op, machine_mode mode)
25423 : : {
25424 : 31950 : int width = 1;
25425 : : /* Vector part. */
25426 : 31950 : if (VECTOR_MODE_P (mode))
25427 : : {
25428 : 7497 : int div = 1;
25429 : 7497 : if (INTEGRAL_MODE_P (mode))
25430 : 2300 : width = ix86_cost->reassoc_vec_int;
25431 : 5197 : else if (FLOAT_MODE_P (mode))
25432 : 5197 : width = ix86_cost->reassoc_vec_fp;
25433 : :
25434 : 7497 : if (width == 1)
25435 : : return 1;
25436 : :
25437 : : /* Znver1-4 Integer vector instructions execute in FP unit
25438 : : and can execute 3 additions and one multiplication per cycle. */
25439 : 7492 : if ((ix86_tune == PROCESSOR_ZNVER1 || ix86_tune == PROCESSOR_ZNVER2
25440 : 7492 : || ix86_tune == PROCESSOR_ZNVER3 || ix86_tune == PROCESSOR_ZNVER4)
25441 : 0 : && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
25442 : : return 1;
25443 : : /* Znver5 can do 2 integer multiplications per cycle with latency
25444 : : of 3. */
25445 : 7492 : if (ix86_tune == PROCESSOR_ZNVER5
25446 : 0 : && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
25447 : 7492 : width = 6;
25448 : :
25449 : : /* Account for targets that splits wide vectors into multiple parts. */
25450 : 7492 : if (TARGET_AVX512_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 256)
25451 : 0 : div = GET_MODE_BITSIZE (mode) / 256;
25452 : 7492 : else if (TARGET_AVX256_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 128)
25453 : 0 : div = GET_MODE_BITSIZE (mode) / 128;
25454 : 7492 : else if (TARGET_SSE_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 64)
25455 : 0 : div = GET_MODE_BITSIZE (mode) / 64;
25456 : 7492 : width = (width + div - 1) / div;
25457 : 7492 : }
25458 : : /* Scalar part. */
25459 : : else if (INTEGRAL_MODE_P (mode))
25460 : 14808 : width = ix86_cost->reassoc_int;
25461 : : else if (FLOAT_MODE_P (mode))
25462 : 9645 : width = ix86_cost->reassoc_fp;
25463 : :
25464 : : /* Avoid using too many registers in 32bit mode. */
25465 : 31945 : if (!TARGET_64BIT && width > 2)
25466 : 31950 : width = 2;
25467 : : return width;
25468 : : }
25469 : :
25470 : : /* ??? No autovectorization into MMX or 3DNOW until we can reliably
25471 : : place emms and femms instructions. */
25472 : :
25473 : : static machine_mode
25474 : 4970707 : ix86_preferred_simd_mode (scalar_mode mode)
25475 : : {
25476 : 4970707 : if (!TARGET_SSE)
25477 : 852 : return word_mode;
25478 : :
25479 : 4969855 : switch (mode)
25480 : : {
25481 : 388156 : case E_QImode:
25482 : 388156 : if (TARGET_AVX512BW && !TARGET_PREFER_AVX256)
25483 : : return V64QImode;
25484 : 380962 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25485 : : return V32QImode;
25486 : : else
25487 : 361405 : return V16QImode;
25488 : :
25489 : 180603 : case E_HImode:
25490 : 180603 : if (TARGET_AVX512BW && !TARGET_PREFER_AVX256)
25491 : : return V32HImode;
25492 : 171494 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25493 : : return V16HImode;
25494 : : else
25495 : 155282 : return V8HImode;
25496 : :
25497 : 1464218 : case E_SImode:
25498 : 1464218 : if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
25499 : : return V16SImode;
25500 : 1398792 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25501 : : return V8SImode;
25502 : : else
25503 : 1248091 : return V4SImode;
25504 : :
25505 : 1867762 : case E_DImode:
25506 : 1867762 : if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
25507 : : return V8DImode;
25508 : 1474590 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25509 : : return V4DImode;
25510 : : else
25511 : 1411950 : return V2DImode;
25512 : :
25513 : 138018 : case E_HFmode:
25514 : 138018 : if (TARGET_AVX512FP16)
25515 : : {
25516 : 137475 : if (TARGET_AVX512VL)
25517 : : {
25518 : 64695 : if (TARGET_PREFER_AVX128)
25519 : : return V8HFmode;
25520 : 64465 : else if (TARGET_PREFER_AVX256)
25521 : : return V16HFmode;
25522 : : }
25523 : 135089 : return V32HFmode;
25524 : : }
25525 : 543 : return word_mode;
25526 : :
25527 : 57044 : case E_BFmode:
25528 : 57044 : if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
25529 : : return V32BFmode;
25530 : 26552 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25531 : : return V16BFmode;
25532 : : else
25533 : 13489 : return V8BFmode;
25534 : :
25535 : 588311 : case E_SFmode:
25536 : 588311 : if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
25537 : : return V16SFmode;
25538 : 399109 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25539 : : return V8SFmode;
25540 : : else
25541 : 336906 : return V4SFmode;
25542 : :
25543 : 262521 : case E_DFmode:
25544 : 262521 : if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
25545 : : return V8DFmode;
25546 : 144456 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25547 : : return V4DFmode;
25548 : 93982 : else if (TARGET_SSE2)
25549 : : return V2DFmode;
25550 : : /* FALLTHRU */
25551 : :
25552 : 23278 : default:
25553 : 23278 : return word_mode;
25554 : : }
25555 : : }
25556 : :
25557 : : /* If AVX is enabled then try vectorizing with both 256bit and 128bit
25558 : : vectors. If AVX512F is enabled then try vectorizing with 512bit,
25559 : : 256bit and 128bit vectors. */
25560 : :
25561 : : static unsigned int
25562 : 2320973 : ix86_autovectorize_vector_modes (vector_modes *modes, bool all)
25563 : : {
25564 : 2320973 : if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
25565 : : {
25566 : 72355 : modes->safe_push (V64QImode);
25567 : 72355 : modes->safe_push (V32QImode);
25568 : 72355 : modes->safe_push (V16QImode);
25569 : : }
25570 : 2248618 : else if (TARGET_AVX512F && all)
25571 : : {
25572 : 555 : modes->safe_push (V32QImode);
25573 : 555 : modes->safe_push (V16QImode);
25574 : 555 : modes->safe_push (V64QImode);
25575 : : }
25576 : 2248063 : else if (TARGET_AVX && !TARGET_PREFER_AVX128)
25577 : : {
25578 : 28084 : modes->safe_push (V32QImode);
25579 : 28084 : modes->safe_push (V16QImode);
25580 : : }
25581 : 2219979 : else if (TARGET_AVX && all)
25582 : : {
25583 : 24 : modes->safe_push (V16QImode);
25584 : 24 : modes->safe_push (V32QImode);
25585 : : }
25586 : 2219955 : else if (TARGET_SSE2)
25587 : 2217708 : modes->safe_push (V16QImode);
25588 : :
25589 : 2320973 : if (TARGET_MMX_WITH_SSE)
25590 : 1854251 : modes->safe_push (V8QImode);
25591 : :
25592 : 2320973 : if (TARGET_SSE2)
25593 : 2318726 : modes->safe_push (V4QImode);
25594 : :
25595 : 2320973 : return 0;
25596 : : }
25597 : :
25598 : : /* Implemenation of targetm.vectorize.get_mask_mode. */
25599 : :
25600 : : static opt_machine_mode
25601 : 1933294 : ix86_get_mask_mode (machine_mode data_mode)
25602 : : {
25603 : 1933294 : unsigned vector_size = GET_MODE_SIZE (data_mode);
25604 : 1933294 : unsigned nunits = GET_MODE_NUNITS (data_mode);
25605 : 1933294 : unsigned elem_size = vector_size / nunits;
25606 : :
25607 : : /* Scalar mask case. */
25608 : 131388 : if ((TARGET_AVX512F && vector_size == 64)
25609 : 1908836 : || (TARGET_AVX512VL && (vector_size == 32 || vector_size == 16))
25610 : : /* AVX512FP16 only supports vector comparison
25611 : : to kmask for _Float16. */
25612 : 1863705 : || (TARGET_AVX512VL && TARGET_AVX512FP16
25613 : 367 : && GET_MODE_INNER (data_mode) == E_HFmode)
25614 : 3796989 : || (TARGET_AVX10_2 && GET_MODE_INNER (data_mode) == E_BFmode))
25615 : : {
25616 : 69688 : if (elem_size == 4
25617 : 69688 : || elem_size == 8
25618 : 24174 : || (TARGET_AVX512BW && (elem_size == 1 || elem_size == 2)))
25619 : 61469 : return smallest_int_mode_for_size (nunits).require ();
25620 : : }
25621 : :
25622 : 1871825 : scalar_int_mode elem_mode
25623 : 1871825 : = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT).require ();
25624 : :
25625 : 1871825 : gcc_assert (elem_size * nunits == vector_size);
25626 : :
25627 : 1871825 : return mode_for_vector (elem_mode, nunits);
25628 : : }
25629 : :
25630 : :
25631 : :
25632 : : /* Return class of registers which could be used for pseudo of MODE
25633 : : and of class RCLASS for spilling instead of memory. Return NO_REGS
25634 : : if it is not possible or non-profitable. */
25635 : :
25636 : : /* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657. */
25637 : :
25638 : : static reg_class_t
25639 : 6434536479 : ix86_spill_class (reg_class_t rclass, machine_mode mode)
25640 : : {
25641 : 6434536479 : if (0 && TARGET_GENERAL_REGS_SSE_SPILL
25642 : : && TARGET_SSE2
25643 : : && TARGET_INTER_UNIT_MOVES_TO_VEC
25644 : : && TARGET_INTER_UNIT_MOVES_FROM_VEC
25645 : : && (mode == SImode || (TARGET_64BIT && mode == DImode))
25646 : : && INTEGER_CLASS_P (rclass))
25647 : : return ALL_SSE_REGS;
25648 : 6434536479 : return NO_REGS;
25649 : : }
25650 : :
25651 : : /* Implement TARGET_MAX_NOCE_IFCVT_SEQ_COST. Like the default implementation,
25652 : : but returns a lower bound. */
25653 : :
25654 : : static unsigned int
25655 : 1849040 : ix86_max_noce_ifcvt_seq_cost (edge e)
25656 : : {
25657 : 1849040 : bool predictable_p = predictable_edge_p (e);
25658 : 1849040 : if (predictable_p)
25659 : : {
25660 : 139528 : if (OPTION_SET_P (param_max_rtl_if_conversion_predictable_cost))
25661 : 0 : return param_max_rtl_if_conversion_predictable_cost;
25662 : : }
25663 : : else
25664 : : {
25665 : 1709512 : if (OPTION_SET_P (param_max_rtl_if_conversion_unpredictable_cost))
25666 : 83 : return param_max_rtl_if_conversion_unpredictable_cost;
25667 : : }
25668 : :
25669 : : /* For modern machines with deeper pipeline, the penalty for branch
25670 : : misprediction could be higher than before to reset the pipeline
25671 : : slots. Add parameter br_mispredict_scale as a factor to describe
25672 : : the impact of reseting the pipeline. */
25673 : :
25674 : 1848957 : return BRANCH_COST (true, predictable_p)
25675 : 1848957 : * ix86_tune_cost->br_mispredict_scale;
25676 : : }
25677 : :
25678 : : /* Return true if SEQ is a good candidate as a replacement for the
25679 : : if-convertible sequence described in IF_INFO. */
25680 : :
25681 : : static bool
25682 : 229806 : ix86_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info)
25683 : : {
25684 : 229806 : if (TARGET_ONE_IF_CONV_INSN && if_info->speed_p)
25685 : : {
25686 : : int cmov_cnt = 0;
25687 : : /* Punt if SEQ contains more than one CMOV or FCMOV instruction.
25688 : : Maybe we should allow even more conditional moves as long as they
25689 : : are used far enough not to stall the CPU, or also consider
25690 : : IF_INFO->TEST_BB succ edge probabilities. */
25691 : 307 : for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn))
25692 : : {
25693 : 253 : rtx set = single_set (insn);
25694 : 253 : if (!set)
25695 : 0 : continue;
25696 : 253 : if (GET_CODE (SET_SRC (set)) != IF_THEN_ELSE)
25697 : 205 : continue;
25698 : 48 : rtx src = SET_SRC (set);
25699 : 48 : machine_mode mode = GET_MODE (src);
25700 : 48 : if (GET_MODE_CLASS (mode) != MODE_INT
25701 : 0 : && GET_MODE_CLASS (mode) != MODE_FLOAT)
25702 : 0 : continue;
25703 : 48 : if ((!REG_P (XEXP (src, 1)) && !MEM_P (XEXP (src, 1)))
25704 : 47 : || (!REG_P (XEXP (src, 2)) && !MEM_P (XEXP (src, 2))))
25705 : 1 : continue;
25706 : : /* insn is CMOV or FCMOV. */
25707 : 47 : if (++cmov_cnt > 1)
25708 : : return false;
25709 : : }
25710 : : }
25711 : :
25712 : : /* W/o TARGET_SSE4_1, it takes 3 instructions (pand, pandn and por)
25713 : : for movdfcc/movsfcc, and could possibly fail cost comparison.
25714 : : Increase branch cost will hurt performance for other modes, so
25715 : : specially add some preference for floating point ifcvt. */
25716 : 229798 : if (!TARGET_SSE4_1 && if_info->x
25717 : 174773 : && GET_MODE_CLASS (GET_MODE (if_info->x)) == MODE_FLOAT
25718 : 34271 : && if_info->speed_p)
25719 : : {
25720 : 27171 : unsigned cost = seq_cost (seq, true);
25721 : :
25722 : 27171 : if (cost <= if_info->original_cost)
25723 : : return true;
25724 : :
25725 : 26041 : return cost <= (if_info->max_seq_cost + COSTS_N_INSNS (2));
25726 : : }
25727 : :
25728 : 202627 : return default_noce_conversion_profitable_p (seq, if_info);
25729 : : }
25730 : :
25731 : : /* x86-specific vector costs. */
25732 : : class ix86_vector_costs : public vector_costs
25733 : : {
25734 : : public:
25735 : : ix86_vector_costs (vec_info *, bool);
25736 : :
25737 : : unsigned int add_stmt_cost (int count, vect_cost_for_stmt kind,
25738 : : stmt_vec_info stmt_info, slp_tree node,
25739 : : tree vectype, int misalign,
25740 : : vect_cost_model_location where) override;
25741 : : void finish_cost (const vector_costs *) override;
25742 : :
25743 : : private:
25744 : :
25745 : : /* Estimate register pressure of the vectorized code. */
25746 : : void ix86_vect_estimate_reg_pressure ();
25747 : : /* Number of GENERAL_REGS/SSE_REGS used in the vectorizer, it's used for
25748 : : estimation of register pressure.
25749 : : ??? Currently it's only used by vec_construct/scalar_to_vec
25750 : : where we know it's not loaded from memory. */
25751 : : unsigned m_num_gpr_needed[3];
25752 : : unsigned m_num_sse_needed[3];
25753 : : /* Number of 256-bit vector permutation. */
25754 : : unsigned m_num_avx256_vec_perm[3];
25755 : : };
25756 : :
25757 : 2033814 : ix86_vector_costs::ix86_vector_costs (vec_info* vinfo, bool costing_for_scalar)
25758 : : : vector_costs (vinfo, costing_for_scalar),
25759 : 2033814 : m_num_gpr_needed (),
25760 : 2033814 : m_num_sse_needed (),
25761 : 2033814 : m_num_avx256_vec_perm ()
25762 : : {
25763 : 2033814 : }
25764 : :
25765 : : /* Implement targetm.vectorize.create_costs. */
25766 : :
25767 : : static vector_costs *
25768 : 2033814 : ix86_vectorize_create_costs (vec_info *vinfo, bool costing_for_scalar)
25769 : : {
25770 : 2033814 : return new ix86_vector_costs (vinfo, costing_for_scalar);
25771 : : }
25772 : :
25773 : : unsigned
25774 : 6773151 : ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
25775 : : stmt_vec_info stmt_info, slp_tree node,
25776 : : tree vectype, int misalign,
25777 : : vect_cost_model_location where)
25778 : : {
25779 : 6773151 : unsigned retval = 0;
25780 : 6773151 : bool scalar_p
25781 : : = (kind == scalar_stmt || kind == scalar_load || kind == scalar_store);
25782 : 6773151 : int stmt_cost = - 1;
25783 : :
25784 : 6773151 : bool fp = false;
25785 : 6773151 : machine_mode mode = scalar_p ? SImode : TImode;
25786 : :
25787 : 6773151 : if (vectype != NULL)
25788 : : {
25789 : 6438519 : fp = FLOAT_TYPE_P (vectype);
25790 : 6438519 : mode = TYPE_MODE (vectype);
25791 : 6438519 : if (scalar_p)
25792 : 3674000 : mode = TYPE_MODE (TREE_TYPE (vectype));
25793 : : }
25794 : :
25795 : 6773151 : if ((kind == vector_stmt || kind == scalar_stmt)
25796 : 1621160 : && stmt_info
25797 : 8388506 : && stmt_info->stmt && gimple_code (stmt_info->stmt) == GIMPLE_ASSIGN)
25798 : : {
25799 : 1317015 : tree_code subcode = gimple_assign_rhs_code (stmt_info->stmt);
25800 : : /*machine_mode inner_mode = mode;
25801 : : if (VECTOR_MODE_P (mode))
25802 : : inner_mode = GET_MODE_INNER (mode);*/
25803 : :
25804 : 1317015 : switch (subcode)
25805 : : {
25806 : 573903 : case PLUS_EXPR:
25807 : 573903 : case POINTER_PLUS_EXPR:
25808 : 573903 : case MINUS_EXPR:
25809 : 573903 : if (kind == scalar_stmt)
25810 : : {
25811 : 410602 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25812 : 66782 : stmt_cost = ix86_cost->addss;
25813 : 343820 : else if (X87_FLOAT_MODE_P (mode))
25814 : 80 : stmt_cost = ix86_cost->fadd;
25815 : : else
25816 : 343740 : stmt_cost = ix86_cost->add;
25817 : : }
25818 : : else
25819 : 163301 : stmt_cost = ix86_vec_cost (mode, fp ? ix86_cost->addss
25820 : : : ix86_cost->sse_op);
25821 : : break;
25822 : :
25823 : 156663 : case MULT_EXPR:
25824 : : /* For MULT_HIGHPART_EXPR, x86 only supports pmulhw,
25825 : : take it as MULT_EXPR. */
25826 : 156663 : case MULT_HIGHPART_EXPR:
25827 : 156663 : stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
25828 : 156663 : break;
25829 : : /* There's no direct instruction for WIDEN_MULT_EXPR,
25830 : : take emulation into account. */
25831 : 1714 : case WIDEN_MULT_EXPR:
25832 : 3428 : stmt_cost = ix86_widen_mult_cost (ix86_cost, mode,
25833 : 1714 : TYPE_UNSIGNED (vectype));
25834 : 1714 : break;
25835 : :
25836 : 5925 : case NEGATE_EXPR:
25837 : 5925 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25838 : 1699 : stmt_cost = ix86_cost->sse_op;
25839 : 4226 : else if (X87_FLOAT_MODE_P (mode))
25840 : 0 : stmt_cost = ix86_cost->fchs;
25841 : 4226 : else if (VECTOR_MODE_P (mode))
25842 : 1738 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25843 : : else
25844 : 2488 : stmt_cost = ix86_cost->add;
25845 : : break;
25846 : 8621 : case TRUNC_DIV_EXPR:
25847 : 8621 : case CEIL_DIV_EXPR:
25848 : 8621 : case FLOOR_DIV_EXPR:
25849 : 8621 : case ROUND_DIV_EXPR:
25850 : 8621 : case TRUNC_MOD_EXPR:
25851 : 8621 : case CEIL_MOD_EXPR:
25852 : 8621 : case FLOOR_MOD_EXPR:
25853 : 8621 : case RDIV_EXPR:
25854 : 8621 : case ROUND_MOD_EXPR:
25855 : 8621 : case EXACT_DIV_EXPR:
25856 : 8621 : stmt_cost = ix86_division_cost (ix86_cost, mode);
25857 : 8621 : break;
25858 : :
25859 : 40337 : case RSHIFT_EXPR:
25860 : 40337 : case LSHIFT_EXPR:
25861 : 40337 : case LROTATE_EXPR:
25862 : 40337 : case RROTATE_EXPR:
25863 : 40337 : {
25864 : 40337 : tree op1 = gimple_assign_rhs1 (stmt_info->stmt);
25865 : 40337 : tree op2 = gimple_assign_rhs2 (stmt_info->stmt);
25866 : 40337 : stmt_cost = ix86_shift_rotate_cost
25867 : 40337 : (ix86_cost,
25868 : : (subcode == RSHIFT_EXPR
25869 : 25091 : && !TYPE_UNSIGNED (TREE_TYPE (op1)))
25870 : : ? ASHIFTRT : LSHIFTRT, mode,
25871 : 40337 : TREE_CODE (op2) == INTEGER_CST,
25872 : 40337 : cst_and_fits_in_hwi (op2)
25873 : 25555 : ? int_cst_value (op2) : -1,
25874 : : false, false, NULL, NULL);
25875 : : }
25876 : 40337 : break;
25877 : 81068 : case NOP_EXPR:
25878 : : /* Only sign-conversions are free. */
25879 : 81068 : if (tree_nop_conversion_p
25880 : 81068 : (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt)),
25881 : 81068 : TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt))))
25882 : : stmt_cost = 0;
25883 : 81068 : else if (fp)
25884 : 6649 : stmt_cost = vec_fp_conversion_cost
25885 : 6649 : (ix86_tune_cost, GET_MODE_BITSIZE (mode));
25886 : : break;
25887 : :
25888 : 14209 : case FLOAT_EXPR:
25889 : 14209 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25890 : 10798 : stmt_cost = ix86_cost->cvtsi2ss;
25891 : 3411 : else if (X87_FLOAT_MODE_P (mode))
25892 : : /* TODO: We do not have cost tables for x87. */
25893 : 1 : stmt_cost = ix86_cost->fadd;
25894 : : else
25895 : 3410 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtpi2ps);
25896 : : break;
25897 : :
25898 : 1908 : case FIX_TRUNC_EXPR:
25899 : 1908 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25900 : 0 : stmt_cost = ix86_cost->cvtss2si;
25901 : 1908 : else if (X87_FLOAT_MODE_P (mode))
25902 : : /* TODO: We do not have cost tables for x87. */
25903 : 0 : stmt_cost = ix86_cost->fadd;
25904 : : else
25905 : 1908 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtps2pi);
25906 : : break;
25907 : :
25908 : 35661 : case COND_EXPR:
25909 : 35661 : {
25910 : : /* SSE2 conditinal move sequence is:
25911 : : pcmpgtd %xmm5, %xmm0 (accounted separately)
25912 : : pand %xmm0, %xmm2
25913 : : pandn %xmm1, %xmm0
25914 : : por %xmm2, %xmm0
25915 : : while SSE4 uses cmp + blend
25916 : : and AVX512 masked moves.
25917 : :
25918 : : The condition is accounted separately since we usually have
25919 : : p = a < b
25920 : : c = p ? x : y
25921 : : and we will account first statement as setcc. Exception is when
25922 : : p is loaded from memory as bool and then we will not acocunt
25923 : : the compare, but there is no way to check for this. */
25924 : :
25925 : 35661 : int ninsns = TARGET_SSE4_1 ? 1 : 3;
25926 : :
25927 : : /* If one of parameters is 0 or -1 the sequence will be simplified:
25928 : : (if_true & mask) | (if_false & ~mask) -> if_true & mask */
25929 : 18999 : if (ninsns > 1
25930 : 18999 : && (zerop (gimple_assign_rhs2 (stmt_info->stmt))
25931 : 18693 : || zerop (gimple_assign_rhs3 (stmt_info->stmt))
25932 : 10155 : || integer_minus_onep
25933 : 10155 : (gimple_assign_rhs2 (stmt_info->stmt))
25934 : 9750 : || integer_minus_onep
25935 : 9750 : (gimple_assign_rhs3 (stmt_info->stmt))))
25936 : : ninsns = 1;
25937 : :
25938 : 35661 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25939 : 2418 : stmt_cost = ninsns * ix86_cost->sse_op;
25940 : 33243 : else if (X87_FLOAT_MODE_P (mode))
25941 : : /* x87 requires conditional branch. We don't have cost for
25942 : : that. */
25943 : : ;
25944 : 33243 : else if (VECTOR_MODE_P (mode))
25945 : 11556 : stmt_cost = ix86_vec_cost (mode, ninsns * ix86_cost->sse_op);
25946 : : else
25947 : : /* compare (accounted separately) + cmov. */
25948 : 21687 : stmt_cost = ix86_cost->add;
25949 : : }
25950 : : break;
25951 : :
25952 : 18318 : case MIN_EXPR:
25953 : 18318 : case MAX_EXPR:
25954 : 18318 : if (fp)
25955 : : {
25956 : 991 : if (X87_FLOAT_MODE_P (mode)
25957 : 377 : && !SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25958 : : /* x87 requires conditional branch. We don't have cost for
25959 : : that. */
25960 : : ;
25961 : : else
25962 : : /* minss */
25963 : 991 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25964 : : }
25965 : : else
25966 : : {
25967 : 17327 : if (VECTOR_MODE_P (mode))
25968 : : {
25969 : 4098 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
25970 : : /* vpmin was introduced in SSE3.
25971 : : SSE2 needs pcmpgtd + pand + pandn + pxor.
25972 : : If one of parameters is 0 or -1 the sequence is simplified
25973 : : to pcmpgtd + pand. */
25974 : 4098 : if (!TARGET_SSSE3)
25975 : : {
25976 : 3057 : if (zerop (gimple_assign_rhs2 (stmt_info->stmt))
25977 : 4350 : || integer_minus_onep
25978 : 1293 : (gimple_assign_rhs2 (stmt_info->stmt)))
25979 : 1764 : stmt_cost *= 2;
25980 : : else
25981 : 1293 : stmt_cost *= 4;
25982 : : }
25983 : : }
25984 : : else
25985 : : /* cmp + cmov. */
25986 : 13229 : stmt_cost = ix86_cost->add * 2;
25987 : : }
25988 : : break;
25989 : :
25990 : 2307 : case ABS_EXPR:
25991 : 2307 : case ABSU_EXPR:
25992 : 2307 : if (fp)
25993 : : {
25994 : 1937 : if (X87_FLOAT_MODE_P (mode)
25995 : 1801 : && !SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
25996 : : /* fabs. */
25997 : 0 : stmt_cost = ix86_cost->fabs;
25998 : : else
25999 : : /* andss of sign bit. */
26000 : 1937 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
26001 : : }
26002 : : else
26003 : : {
26004 : 370 : if (VECTOR_MODE_P (mode))
26005 : : {
26006 : 62 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
26007 : : /* vabs was introduced in SSE3.
26008 : : SSE3 uses psrat + pxor + psub. */
26009 : 62 : if (!TARGET_SSSE3)
26010 : 53 : stmt_cost *= 3;
26011 : : }
26012 : : else
26013 : : /* neg + cmov. */
26014 : 308 : stmt_cost = ix86_cost->add * 2;
26015 : : }
26016 : : break;
26017 : :
26018 : 93320 : case BIT_IOR_EXPR:
26019 : 93320 : case BIT_XOR_EXPR:
26020 : 93320 : case BIT_AND_EXPR:
26021 : 93320 : case BIT_NOT_EXPR:
26022 : 93320 : gcc_assert (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)
26023 : : && !X87_FLOAT_MODE_P (mode));
26024 : 93320 : if (VECTOR_MODE_P (mode))
26025 : 28851 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
26026 : : else
26027 : 64469 : stmt_cost = ix86_cost->add;
26028 : : break;
26029 : :
26030 : 283061 : default:
26031 : 283061 : if (truth_value_p (subcode))
26032 : : {
26033 : 63269 : if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
26034 : : /* CMPccS? insructions are cheap, so use sse_op. While they
26035 : : produce a mask which may need to be turned to 0/1 by and,
26036 : : expect that this will be optimized away in a common case. */
26037 : 0 : stmt_cost = ix86_cost->sse_op;
26038 : 63269 : else if (X87_FLOAT_MODE_P (mode))
26039 : : /* fcmp + setcc. */
26040 : 0 : stmt_cost = ix86_cost->fadd + ix86_cost->add;
26041 : 63269 : else if (VECTOR_MODE_P (mode))
26042 : 13059 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
26043 : : else
26044 : : /* setcc. */
26045 : 50210 : stmt_cost = ix86_cost->add;
26046 : : break;
26047 : : }
26048 : : break;
26049 : : }
26050 : : }
26051 : :
26052 : 6773151 : combined_fn cfn;
26053 : 6773151 : if ((kind == vector_stmt || kind == scalar_stmt)
26054 : 1621160 : && stmt_info
26055 : 1615355 : && stmt_info->stmt
26056 : 8388506 : && (cfn = gimple_call_combined_fn (stmt_info->stmt)) != CFN_LAST)
26057 : 16377 : switch (cfn)
26058 : : {
26059 : 40 : case CFN_FMA:
26060 : 40 : stmt_cost = ix86_vec_cost (mode,
26061 : 40 : mode == SFmode ? ix86_cost->fmass
26062 : : : ix86_cost->fmasd);
26063 : 40 : break;
26064 : 24 : case CFN_MULH:
26065 : 24 : stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
26066 : 24 : break;
26067 : : default:
26068 : : break;
26069 : : }
26070 : :
26071 : 6773151 : if (kind == vec_promote_demote)
26072 : : {
26073 : 35787 : int outer_size
26074 : : = tree_to_uhwi
26075 : 35787 : (TYPE_SIZE
26076 : 35787 : (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt))));
26077 : 35787 : int inner_size
26078 : : = tree_to_uhwi
26079 : 35787 : (TYPE_SIZE
26080 : 35787 : (TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt))));
26081 : 35787 : bool inner_fp = FLOAT_TYPE_P
26082 : : (TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt)));
26083 : :
26084 : 3478 : if (fp && inner_fp)
26085 : 3106 : stmt_cost = vec_fp_conversion_cost
26086 : 3106 : (ix86_tune_cost, GET_MODE_BITSIZE (mode));
26087 : 32681 : else if (fp && !inner_fp)
26088 : 3739 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtpi2ps);
26089 : 28942 : else if (!fp && inner_fp)
26090 : 372 : stmt_cost = ix86_vec_cost (mode, ix86_cost->cvtps2pi);
26091 : : else
26092 : 28570 : stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
26093 : : /* VEC_PACK_TRUNC_EXPR and similar demote operations: If outer size is
26094 : : greater than inner size we will end up doing two conversions and
26095 : : packing them. We always pack pairs; if the size difference is greater
26096 : : it is split into multiple demote operations. */
26097 : 35787 : if (inner_size > outer_size)
26098 : 17769 : stmt_cost = stmt_cost * 2
26099 : 17769 : + ix86_vec_cost (mode, ix86_cost->sse_op);
26100 : : }
26101 : :
26102 : : /* If we do elementwise loads into a vector then we are bound by
26103 : : latency and execution resources for the many scalar loads
26104 : : (AGU and load ports). Try to account for this by scaling the
26105 : : construction cost by the number of elements involved. */
26106 : 6773151 : if ((kind == vec_construct || kind == vec_to_scalar)
26107 : 482378 : && ((stmt_info
26108 : 196718 : && (STMT_VINFO_TYPE (stmt_info) == load_vec_info_type
26109 : 196718 : || STMT_VINFO_TYPE (stmt_info) == store_vec_info_type)
26110 : 76075 : && ((STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) == VMAT_ELEMENTWISE
26111 : 0 : && (TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF (stmt_info)))
26112 : : != INTEGER_CST))
26113 : 76075 : || (STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info)
26114 : : == VMAT_GATHER_SCATTER)))
26115 : 478042 : || (node
26116 : 305357 : && (((SLP_TREE_MEMORY_ACCESS_TYPE (node) == VMAT_ELEMENTWISE
26117 : 299341 : || (SLP_TREE_MEMORY_ACCESS_TYPE (node) == VMAT_STRIDED_SLP
26118 : 36842 : && SLP_TREE_LANES (node) == 1))
26119 : 40975 : && (TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF
26120 : : (SLP_TREE_REPRESENTATIVE (node))))
26121 : : != INTEGER_CST))
26122 : 280323 : || (SLP_TREE_MEMORY_ACCESS_TYPE (node)
26123 : : == VMAT_GATHER_SCATTER)))))
26124 : : {
26125 : 33300 : stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
26126 : 33300 : stmt_cost *= (TYPE_VECTOR_SUBPARTS (vectype) + 1);
26127 : : }
26128 : 6739851 : else if ((kind == vec_construct || kind == scalar_to_vec)
26129 : 568543 : && node
26130 : 381676 : && SLP_TREE_DEF_TYPE (node) == vect_external_def)
26131 : : {
26132 : 373144 : stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
26133 : 373144 : unsigned i;
26134 : 373144 : tree op;
26135 : 1592557 : FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
26136 : 846269 : if (TREE_CODE (op) == SSA_NAME)
26137 : 581007 : TREE_VISITED (op) = 0;
26138 : 1219413 : FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
26139 : : {
26140 : 846269 : if (TREE_CODE (op) != SSA_NAME
26141 : 581007 : || TREE_VISITED (op))
26142 : 308070 : continue;
26143 : 538199 : TREE_VISITED (op) = 1;
26144 : 538199 : gimple *def = SSA_NAME_DEF_STMT (op);
26145 : 538199 : tree tem;
26146 : 538199 : if (is_gimple_assign (def)
26147 : 282589 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
26148 : 34447 : && ((tem = gimple_assign_rhs1 (def)), true)
26149 : 34447 : && TREE_CODE (tem) == SSA_NAME
26150 : : /* A sign-change expands to nothing. */
26151 : 572457 : && tree_nop_conversion_p (TREE_TYPE (gimple_assign_lhs (def)),
26152 : 34258 : TREE_TYPE (tem)))
26153 : 9867 : def = SSA_NAME_DEF_STMT (tem);
26154 : : /* When the component is loaded from memory we can directly
26155 : : move it to a vector register, otherwise we have to go
26156 : : via a GPR or via vpinsr which involves similar cost.
26157 : : Likewise with a BIT_FIELD_REF extracting from a vector
26158 : : register we can hope to avoid using a GPR. */
26159 : 538199 : if (!is_gimple_assign (def)
26160 : 538199 : || ((!gimple_assign_load_p (def)
26161 : 143435 : || (!TARGET_SSE4_1
26162 : 278758 : && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op))) == 1))
26163 : 142318 : && (gimple_assign_rhs_code (def) != BIT_FIELD_REF
26164 : 3521 : || !VECTOR_TYPE_P (TREE_TYPE
26165 : : (TREE_OPERAND (gimple_assign_rhs1 (def), 0))))))
26166 : : {
26167 : 396237 : if (fp)
26168 : 15719 : m_num_sse_needed[where]++;
26169 : : else
26170 : : {
26171 : 380518 : m_num_gpr_needed[where]++;
26172 : :
26173 : 380518 : int cost = COSTS_N_INSNS (ix86_cost->integer_to_sse) / 2;
26174 : :
26175 : : /* For integer construction, the number of actual GPR -> XMM
26176 : : moves will be somewhere between 0 and n.
26177 : : We do not have very good idea about actual number, since
26178 : : the source may be a constant, memory or a chain of
26179 : : instructions that will be later converted by
26180 : : scalar-to-vector pass. */
26181 : 380518 : if (kind == vec_construct
26182 : 643655 : && GET_MODE_BITSIZE (mode) == 256)
26183 : 744 : cost *= 2;
26184 : 379774 : else if (kind == vec_construct
26185 : 642167 : && GET_MODE_BITSIZE (mode) == 512)
26186 : 48 : cost *= 3;
26187 : 380518 : stmt_cost += cost;
26188 : : }
26189 : : }
26190 : : }
26191 : 1219413 : FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
26192 : 846269 : if (TREE_CODE (op) == SSA_NAME)
26193 : 581007 : TREE_VISITED (op) = 0;
26194 : : }
26195 : 6773151 : if (stmt_cost == -1)
26196 : 5308052 : stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
26197 : :
26198 : 6773151 : if (kind == vec_perm && vectype
26199 : 6857183 : && GET_MODE_SIZE (TYPE_MODE (vectype)) == 32)
26200 : 2931 : m_num_avx256_vec_perm[where]++;
26201 : :
26202 : : /* Penalize DFmode vector operations for Bonnell. */
26203 : 6773151 : if (TARGET_CPU_P (BONNELL) && kind == vector_stmt
26204 : 6773213 : && vectype && GET_MODE_INNER (TYPE_MODE (vectype)) == DFmode)
26205 : 12 : stmt_cost *= 5; /* FIXME: The value here is arbitrary. */
26206 : :
26207 : : /* Statements in an inner loop relative to the loop being
26208 : : vectorized are weighted more heavily. The value here is
26209 : : arbitrary and could potentially be improved with analysis. */
26210 : 6773151 : retval = adjust_cost_for_freq (stmt_info, where, count * stmt_cost);
26211 : :
26212 : : /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
26213 : : for Silvermont as it has out of order integer pipeline and can execute
26214 : : 2 scalar instruction per tick, but has in order SIMD pipeline. */
26215 : 6773151 : if ((TARGET_CPU_P (SILVERMONT) || TARGET_CPU_P (GOLDMONT)
26216 : 6773151 : || TARGET_CPU_P (GOLDMONT_PLUS) || TARGET_CPU_P (INTEL))
26217 : 1800 : && stmt_info && stmt_info->stmt)
26218 : : {
26219 : 1580 : tree lhs_op = gimple_get_lhs (stmt_info->stmt);
26220 : 1580 : if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE)
26221 : 1186 : retval = (retval * 17) / 10;
26222 : : }
26223 : :
26224 : 6773151 : m_costs[where] += retval;
26225 : :
26226 : 6773151 : return retval;
26227 : : }
26228 : :
26229 : : void
26230 : 1762662 : ix86_vector_costs::ix86_vect_estimate_reg_pressure ()
26231 : : {
26232 : 1762662 : unsigned gpr_spill_cost = COSTS_N_INSNS (ix86_cost->int_store [2]) / 2;
26233 : 1762662 : unsigned sse_spill_cost = COSTS_N_INSNS (ix86_cost->sse_store[0]) / 2;
26234 : :
26235 : : /* Any better way to have target available fp registers, currently use SSE_REGS. */
26236 : 1762662 : unsigned target_avail_sse = TARGET_64BIT ? (TARGET_AVX512F ? 32 : 16) : 8;
26237 : 7050648 : for (unsigned i = 0; i != 3; i++)
26238 : : {
26239 : 5287986 : if (m_num_gpr_needed[i] > target_avail_regs)
26240 : 753 : m_costs[i] += gpr_spill_cost * (m_num_gpr_needed[i] - target_avail_regs);
26241 : : /* Only measure sse registers pressure. */
26242 : 5287986 : if (TARGET_SSE && (m_num_sse_needed[i] > target_avail_sse))
26243 : 138 : m_costs[i] += sse_spill_cost * (m_num_sse_needed[i] - target_avail_sse);
26244 : : }
26245 : 1762662 : }
26246 : :
26247 : : void
26248 : 1762662 : ix86_vector_costs::finish_cost (const vector_costs *scalar_costs)
26249 : : {
26250 : 1762662 : loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo);
26251 : 299440 : if (loop_vinfo && !m_costing_for_scalar)
26252 : : {
26253 : : /* We are currently not asking the vectorizer to compare costs
26254 : : between different vector mode sizes. When using predication
26255 : : that will end up always choosing the prefered mode size even
26256 : : if there's a smaller mode covering all lanes. Test for this
26257 : : situation and artificially reject the larger mode attempt.
26258 : : ??? We currently lack masked ops for sub-SSE sized modes,
26259 : : so we could restrict this rejection to AVX and AVX512 modes
26260 : : but error on the safe side for now. */
26261 : 78502 : if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)
26262 : 15 : && !LOOP_VINFO_EPILOGUE_P (loop_vinfo)
26263 : 13 : && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
26264 : 78510 : && (exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant ())
26265 : 16 : > ceil_log2 (LOOP_VINFO_INT_NITERS (loop_vinfo))))
26266 : 6 : m_costs[vect_body] = INT_MAX;
26267 : : }
26268 : :
26269 : 1762662 : ix86_vect_estimate_reg_pressure ();
26270 : :
26271 : 7050648 : for (int i = 0; i != 3; i++)
26272 : 5287986 : if (m_num_avx256_vec_perm[i]
26273 : 472 : && TARGET_AVX256_AVOID_VEC_PERM)
26274 : 2 : m_costs[i] = INT_MAX;
26275 : :
26276 : : /* When X86_TUNE_AVX512_TWO_EPILOGUES is enabled arrange for both
26277 : : a AVX2 and a SSE epilogue for AVX512 vectorized loops. */
26278 : 1762662 : if (loop_vinfo
26279 : 299440 : && LOOP_VINFO_EPILOGUE_P (loop_vinfo)
26280 : 37588 : && GET_MODE_SIZE (loop_vinfo->vector_mode) == 32
26281 : 1763254 : && ix86_tune_features[X86_TUNE_AVX512_TWO_EPILOGUES])
26282 : 8 : m_suggested_epilogue_mode = V16QImode;
26283 : : /* When a 128bit SSE vectorized epilogue still has a VF of 16 or larger
26284 : : enable a 64bit SSE epilogue. */
26285 : 1762662 : if (loop_vinfo
26286 : 299440 : && LOOP_VINFO_EPILOGUE_P (loop_vinfo)
26287 : 37588 : && GET_MODE_SIZE (loop_vinfo->vector_mode) == 16
26288 : 1764943 : && LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant () >= 16)
26289 : 213 : m_suggested_epilogue_mode = V8QImode;
26290 : :
26291 : 1762662 : vector_costs::finish_cost (scalar_costs);
26292 : 1762662 : }
26293 : :
26294 : : /* Validate target specific memory model bits in VAL. */
26295 : :
26296 : : static unsigned HOST_WIDE_INT
26297 : 516458 : ix86_memmodel_check (unsigned HOST_WIDE_INT val)
26298 : : {
26299 : 516458 : enum memmodel model = memmodel_from_int (val);
26300 : 516458 : bool strong;
26301 : :
26302 : 516458 : if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE
26303 : : |MEMMODEL_MASK)
26304 : 516454 : || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE)))
26305 : : {
26306 : 4 : warning (OPT_Winvalid_memory_model,
26307 : : "unknown architecture specific memory model");
26308 : 4 : return MEMMODEL_SEQ_CST;
26309 : : }
26310 : 516454 : strong = (is_mm_acq_rel (model) || is_mm_seq_cst (model));
26311 : 516454 : if (val & IX86_HLE_ACQUIRE && !(is_mm_acquire (model) || strong))
26312 : : {
26313 : 0 : warning (OPT_Winvalid_memory_model,
26314 : : "%<HLE_ACQUIRE%> not used with %<ACQUIRE%> or stronger "
26315 : : "memory model");
26316 : 0 : return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE;
26317 : : }
26318 : 516454 : if (val & IX86_HLE_RELEASE && !(is_mm_release (model) || strong))
26319 : : {
26320 : 0 : warning (OPT_Winvalid_memory_model,
26321 : : "%<HLE_RELEASE%> not used with %<RELEASE%> or stronger "
26322 : : "memory model");
26323 : 0 : return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE;
26324 : : }
26325 : : return val;
26326 : : }
26327 : :
26328 : : /* Set CLONEI->vecsize_mangle, CLONEI->mask_mode, CLONEI->vecsize_int,
26329 : : CLONEI->vecsize_float and if CLONEI->simdlen is 0, also
26330 : : CLONEI->simdlen. Return 0 if SIMD clones shouldn't be emitted,
26331 : : or number of vecsize_mangle variants that should be emitted. */
26332 : :
26333 : : static int
26334 : 7477 : ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node,
26335 : : struct cgraph_simd_clone *clonei,
26336 : : tree base_type, int num,
26337 : : bool explicit_p)
26338 : : {
26339 : 7477 : int ret = 1;
26340 : :
26341 : 7477 : if (clonei->simdlen
26342 : 7477 : && (clonei->simdlen < 2
26343 : 1289 : || clonei->simdlen > 1024
26344 : 1289 : || (clonei->simdlen & (clonei->simdlen - 1)) != 0))
26345 : : {
26346 : 0 : if (explicit_p)
26347 : 0 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26348 : : "unsupported simdlen %wd", clonei->simdlen.to_constant ());
26349 : 0 : return 0;
26350 : : }
26351 : :
26352 : 7477 : tree ret_type = TREE_TYPE (TREE_TYPE (node->decl));
26353 : 7477 : if (TREE_CODE (ret_type) != VOID_TYPE)
26354 : 6685 : switch (TYPE_MODE (ret_type))
26355 : : {
26356 : 6685 : case E_QImode:
26357 : 6685 : case E_HImode:
26358 : 6685 : case E_SImode:
26359 : 6685 : case E_DImode:
26360 : 6685 : case E_SFmode:
26361 : 6685 : case E_DFmode:
26362 : : /* case E_SCmode: */
26363 : : /* case E_DCmode: */
26364 : 6685 : if (!AGGREGATE_TYPE_P (ret_type))
26365 : : break;
26366 : : /* FALLTHRU */
26367 : 2 : default:
26368 : 2 : if (explicit_p)
26369 : 2 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26370 : : "unsupported return type %qT for simd", ret_type);
26371 : 2 : return 0;
26372 : : }
26373 : :
26374 : 7475 : tree t;
26375 : 7475 : int i;
26376 : 7475 : tree type_arg_types = TYPE_ARG_TYPES (TREE_TYPE (node->decl));
26377 : 7475 : bool decl_arg_p = (node->definition || type_arg_types == NULL_TREE);
26378 : :
26379 : 7475 : for (t = (decl_arg_p ? DECL_ARGUMENTS (node->decl) : type_arg_types), i = 0;
26380 : 20178 : t && t != void_list_node; t = TREE_CHAIN (t), i++)
26381 : : {
26382 : 16422 : tree arg_type = decl_arg_p ? TREE_TYPE (t) : TREE_VALUE (t);
26383 : 12708 : switch (TYPE_MODE (arg_type))
26384 : : {
26385 : 12689 : case E_QImode:
26386 : 12689 : case E_HImode:
26387 : 12689 : case E_SImode:
26388 : 12689 : case E_DImode:
26389 : 12689 : case E_SFmode:
26390 : 12689 : case E_DFmode:
26391 : : /* case E_SCmode: */
26392 : : /* case E_DCmode: */
26393 : 12689 : if (!AGGREGATE_TYPE_P (arg_type))
26394 : : break;
26395 : : /* FALLTHRU */
26396 : 41 : default:
26397 : 41 : if (clonei->args[i].arg_type == SIMD_CLONE_ARG_TYPE_UNIFORM)
26398 : : break;
26399 : 5 : if (explicit_p)
26400 : 5 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26401 : : "unsupported argument type %qT for simd", arg_type);
26402 : : return 0;
26403 : : }
26404 : : }
26405 : :
26406 : 7470 : if (!TREE_PUBLIC (node->decl) || !explicit_p)
26407 : : {
26408 : : /* If the function isn't exported, we can pick up just one ISA
26409 : : for the clones. */
26410 : 114 : if (TARGET_AVX512F)
26411 : 0 : clonei->vecsize_mangle = 'e';
26412 : 114 : else if (TARGET_AVX2)
26413 : 1 : clonei->vecsize_mangle = 'd';
26414 : 113 : else if (TARGET_AVX)
26415 : 88 : clonei->vecsize_mangle = 'c';
26416 : : else
26417 : 25 : clonei->vecsize_mangle = 'b';
26418 : : ret = 1;
26419 : : }
26420 : : else
26421 : : {
26422 : 7356 : clonei->vecsize_mangle = "bcde"[num];
26423 : 7356 : ret = 4;
26424 : : }
26425 : 7470 : clonei->mask_mode = VOIDmode;
26426 : 7470 : switch (clonei->vecsize_mangle)
26427 : : {
26428 : 1864 : case 'b':
26429 : 1864 : clonei->vecsize_int = 128;
26430 : 1864 : clonei->vecsize_float = 128;
26431 : 1864 : break;
26432 : 1927 : case 'c':
26433 : 1927 : clonei->vecsize_int = 128;
26434 : 1927 : clonei->vecsize_float = 256;
26435 : 1927 : break;
26436 : 1840 : case 'd':
26437 : 1840 : clonei->vecsize_int = 256;
26438 : 1840 : clonei->vecsize_float = 256;
26439 : 1840 : break;
26440 : 1839 : case 'e':
26441 : 1839 : clonei->vecsize_int = 512;
26442 : 1839 : clonei->vecsize_float = 512;
26443 : 1839 : if (TYPE_MODE (base_type) == QImode)
26444 : 15 : clonei->mask_mode = DImode;
26445 : : else
26446 : 1824 : clonei->mask_mode = SImode;
26447 : : break;
26448 : : }
26449 : 7470 : if (clonei->simdlen == 0)
26450 : : {
26451 : 6181 : if (SCALAR_INT_MODE_P (TYPE_MODE (base_type)))
26452 : 3265 : clonei->simdlen = clonei->vecsize_int;
26453 : : else
26454 : 2916 : clonei->simdlen = clonei->vecsize_float;
26455 : 6181 : clonei->simdlen = clonei->simdlen
26456 : 12362 : / GET_MODE_BITSIZE (TYPE_MODE (base_type));
26457 : : }
26458 : 1289 : else if (clonei->simdlen > 16)
26459 : : {
26460 : : /* For compatibility with ICC, use the same upper bounds
26461 : : for simdlen. In particular, for CTYPE below, use the return type,
26462 : : unless the function returns void, in that case use the characteristic
26463 : : type. If it is possible for given SIMDLEN to pass CTYPE value
26464 : : in registers (8 [XYZ]MM* regs for 32-bit code, 16 [XYZ]MM* regs
26465 : : for 64-bit code), accept that SIMDLEN, otherwise warn and don't
26466 : : emit corresponding clone. */
26467 : 4 : tree ctype = ret_type;
26468 : 4 : if (VOID_TYPE_P (ret_type))
26469 : 0 : ctype = base_type;
26470 : 8 : int cnt = GET_MODE_BITSIZE (TYPE_MODE (ctype)) * clonei->simdlen;
26471 : 4 : if (SCALAR_INT_MODE_P (TYPE_MODE (ctype)))
26472 : 0 : cnt /= clonei->vecsize_int;
26473 : : else
26474 : 4 : cnt /= clonei->vecsize_float;
26475 : 4 : if (cnt > (TARGET_64BIT ? 16 : 8))
26476 : : {
26477 : 0 : if (explicit_p)
26478 : 0 : warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
26479 : : "unsupported simdlen %wd",
26480 : : clonei->simdlen.to_constant ());
26481 : 0 : return 0;
26482 : : }
26483 : : }
26484 : : return ret;
26485 : : }
26486 : :
26487 : : /* If SIMD clone NODE can't be used in a vectorized loop
26488 : : in current function, return -1, otherwise return a badness of using it
26489 : : (0 if it is most desirable from vecsize_mangle point of view, 1
26490 : : slightly less desirable, etc.). */
26491 : :
26492 : : static int
26493 : 1708 : ix86_simd_clone_usable (struct cgraph_node *node, machine_mode)
26494 : : {
26495 : 1708 : switch (node->simdclone->vecsize_mangle)
26496 : : {
26497 : 589 : case 'b':
26498 : 589 : if (!TARGET_SSE2)
26499 : : return -1;
26500 : 589 : if (!TARGET_AVX)
26501 : : return 0;
26502 : 504 : return TARGET_AVX512F ? 3 : TARGET_AVX2 ? 2 : 1;
26503 : 609 : case 'c':
26504 : 609 : if (!TARGET_AVX)
26505 : : return -1;
26506 : 578 : return TARGET_AVX512F ? 2 : TARGET_AVX2 ? 1 : 0;
26507 : 324 : case 'd':
26508 : 324 : if (!TARGET_AVX2)
26509 : : return -1;
26510 : 119 : return TARGET_AVX512F ? 1 : 0;
26511 : 186 : case 'e':
26512 : 186 : if (!TARGET_AVX512F)
26513 : 148 : return -1;
26514 : : return 0;
26515 : 0 : default:
26516 : 0 : gcc_unreachable ();
26517 : : }
26518 : : }
26519 : :
26520 : : /* This function adjusts the unroll factor based on
26521 : : the hardware capabilities. For ex, bdver3 has
26522 : : a loop buffer which makes unrolling of smaller
26523 : : loops less important. This function decides the
26524 : : unroll factor using number of memory references
26525 : : (value 32 is used) as a heuristic. */
26526 : :
26527 : : static unsigned
26528 : 797308 : ix86_loop_unroll_adjust (unsigned nunroll, class loop *loop)
26529 : : {
26530 : 797308 : basic_block *bbs;
26531 : 797308 : rtx_insn *insn;
26532 : 797308 : unsigned i;
26533 : 797308 : unsigned mem_count = 0;
26534 : :
26535 : : /* Unroll small size loop when unroll factor is not explicitly
26536 : : specified. */
26537 : 797308 : if (ix86_unroll_only_small_loops && !loop->unroll)
26538 : : {
26539 : 755248 : if (loop->ninsns <= ix86_cost->small_unroll_ninsns)
26540 : 69936 : return MIN (nunroll, ix86_cost->small_unroll_factor);
26541 : : else
26542 : : return 1;
26543 : : }
26544 : :
26545 : 42060 : if (!TARGET_ADJUST_UNROLL)
26546 : : return nunroll;
26547 : :
26548 : : /* Count the number of memory references within the loop body.
26549 : : This value determines the unrolling factor for bdver3 and bdver4
26550 : : architectures. */
26551 : 7 : subrtx_iterator::array_type array;
26552 : 7 : bbs = get_loop_body (loop);
26553 : 21 : for (i = 0; i < loop->num_nodes; i++)
26554 : 102 : FOR_BB_INSNS (bbs[i], insn)
26555 : 88 : if (NONDEBUG_INSN_P (insn))
26556 : 464 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
26557 : 404 : if (const_rtx x = *iter)
26558 : 404 : if (MEM_P (x))
26559 : : {
26560 : 25 : machine_mode mode = GET_MODE (x);
26561 : 50 : unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
26562 : 25 : if (n_words > 4)
26563 : 0 : mem_count += 2;
26564 : : else
26565 : 25 : mem_count += 1;
26566 : : }
26567 : 7 : free (bbs);
26568 : :
26569 : 7 : if (mem_count && mem_count <=32)
26570 : 7 : return MIN (nunroll, 32 / mem_count);
26571 : :
26572 : : return nunroll;
26573 : 7 : }
26574 : :
26575 : :
26576 : : /* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P. */
26577 : :
26578 : : static bool
26579 : 412944 : ix86_float_exceptions_rounding_supported_p (void)
26580 : : {
26581 : : /* For x87 floating point with standard excess precision handling,
26582 : : there is no adddf3 pattern (since x87 floating point only has
26583 : : XFmode operations) so the default hook implementation gets this
26584 : : wrong. */
26585 : 412944 : return TARGET_80387 || (TARGET_SSE && TARGET_SSE_MATH);
26586 : : }
26587 : :
26588 : : /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */
26589 : :
26590 : : static void
26591 : 7054 : ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
26592 : : {
26593 : 7054 : if (!TARGET_80387 && !(TARGET_SSE && TARGET_SSE_MATH))
26594 : : return;
26595 : 7054 : tree exceptions_var = create_tmp_var_raw (integer_type_node);
26596 : 7054 : if (TARGET_80387)
26597 : : {
26598 : 7054 : tree fenv_index_type = build_index_type (size_int (6));
26599 : 7054 : tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
26600 : 7054 : tree fenv_var = create_tmp_var_raw (fenv_type);
26601 : 7054 : TREE_ADDRESSABLE (fenv_var) = 1;
26602 : 7054 : tree fenv_ptr = build_pointer_type (fenv_type);
26603 : 7054 : tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
26604 : 7054 : fenv_addr = fold_convert (ptr_type_node, fenv_addr);
26605 : 7054 : tree fnstenv = get_ix86_builtin (IX86_BUILTIN_FNSTENV);
26606 : 7054 : tree fldenv = get_ix86_builtin (IX86_BUILTIN_FLDENV);
26607 : 7054 : tree fnstsw = get_ix86_builtin (IX86_BUILTIN_FNSTSW);
26608 : 7054 : tree fnclex = get_ix86_builtin (IX86_BUILTIN_FNCLEX);
26609 : 7054 : tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
26610 : 7054 : tree hold_fnclex = build_call_expr (fnclex, 0);
26611 : 7054 : fenv_var = build4 (TARGET_EXPR, fenv_type, fenv_var, hold_fnstenv,
26612 : : NULL_TREE, NULL_TREE);
26613 : 7054 : *hold = build2 (COMPOUND_EXPR, void_type_node, fenv_var,
26614 : : hold_fnclex);
26615 : 7054 : *clear = build_call_expr (fnclex, 0);
26616 : 7054 : tree sw_var = create_tmp_var_raw (short_unsigned_type_node);
26617 : 7054 : tree fnstsw_call = build_call_expr (fnstsw, 0);
26618 : 7054 : tree sw_mod = build4 (TARGET_EXPR, short_unsigned_type_node, sw_var,
26619 : : fnstsw_call, NULL_TREE, NULL_TREE);
26620 : 7054 : tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
26621 : 7054 : tree update_mod = build4 (TARGET_EXPR, integer_type_node,
26622 : : exceptions_var, exceptions_x87,
26623 : : NULL_TREE, NULL_TREE);
26624 : 7054 : *update = build2 (COMPOUND_EXPR, integer_type_node,
26625 : : sw_mod, update_mod);
26626 : 7054 : tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
26627 : 7054 : *update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv);
26628 : : }
26629 : 7054 : if (TARGET_SSE && TARGET_SSE_MATH)
26630 : : {
26631 : 7054 : tree mxcsr_orig_var = create_tmp_var_raw (unsigned_type_node);
26632 : 7054 : tree mxcsr_mod_var = create_tmp_var_raw (unsigned_type_node);
26633 : 7054 : tree stmxcsr = get_ix86_builtin (IX86_BUILTIN_STMXCSR);
26634 : 7054 : tree ldmxcsr = get_ix86_builtin (IX86_BUILTIN_LDMXCSR);
26635 : 7054 : tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
26636 : 7054 : tree hold_assign_orig = build4 (TARGET_EXPR, unsigned_type_node,
26637 : : mxcsr_orig_var, stmxcsr_hold_call,
26638 : : NULL_TREE, NULL_TREE);
26639 : 7054 : tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
26640 : : mxcsr_orig_var,
26641 : : build_int_cst (unsigned_type_node, 0x1f80));
26642 : 7054 : hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
26643 : : build_int_cst (unsigned_type_node, 0xffffffc0));
26644 : 7054 : tree hold_assign_mod = build4 (TARGET_EXPR, unsigned_type_node,
26645 : : mxcsr_mod_var, hold_mod_val,
26646 : : NULL_TREE, NULL_TREE);
26647 : 7054 : tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
26648 : 7054 : tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
26649 : : hold_assign_orig, hold_assign_mod);
26650 : 7054 : hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all,
26651 : : ldmxcsr_hold_call);
26652 : 7054 : if (*hold)
26653 : 7054 : *hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all);
26654 : : else
26655 : 0 : *hold = hold_all;
26656 : 7054 : tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
26657 : 7054 : if (*clear)
26658 : 7054 : *clear = build2 (COMPOUND_EXPR, void_type_node, *clear,
26659 : : ldmxcsr_clear_call);
26660 : : else
26661 : 0 : *clear = ldmxcsr_clear_call;
26662 : 7054 : tree stxmcsr_update_call = build_call_expr (stmxcsr, 0);
26663 : 7054 : tree exceptions_sse = fold_convert (integer_type_node,
26664 : : stxmcsr_update_call);
26665 : 7054 : if (*update)
26666 : : {
26667 : 7054 : tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node,
26668 : : exceptions_var, exceptions_sse);
26669 : 7054 : tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node,
26670 : : exceptions_var, exceptions_mod);
26671 : 7054 : *update = build2 (COMPOUND_EXPR, integer_type_node, *update,
26672 : : exceptions_assign);
26673 : : }
26674 : : else
26675 : 0 : *update = build4 (TARGET_EXPR, integer_type_node, exceptions_var,
26676 : : exceptions_sse, NULL_TREE, NULL_TREE);
26677 : 7054 : tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
26678 : 7054 : *update = build2 (COMPOUND_EXPR, void_type_node, *update,
26679 : : ldmxcsr_update_call);
26680 : : }
26681 : 7054 : tree atomic_feraiseexcept
26682 : 7054 : = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
26683 : 7054 : tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
26684 : : 1, exceptions_var);
26685 : 7054 : *update = build2 (COMPOUND_EXPR, void_type_node, *update,
26686 : : atomic_feraiseexcept_call);
26687 : : }
26688 : :
26689 : : #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
26690 : : /* For i386, common symbol is local only for non-PIE binaries. For
26691 : : x86-64, common symbol is local only for non-PIE binaries or linker
26692 : : supports copy reloc in PIE binaries. */
26693 : :
26694 : : static bool
26695 : 750490359 : ix86_binds_local_p (const_tree exp)
26696 : : {
26697 : 750490359 : bool direct_extern_access
26698 : 750490359 : = (ix86_direct_extern_access
26699 : 1497487539 : && !(VAR_OR_FUNCTION_DECL_P (exp)
26700 : 746997180 : && lookup_attribute ("nodirect_extern_access",
26701 : 746997180 : DECL_ATTRIBUTES (exp))));
26702 : 750490359 : if (!direct_extern_access)
26703 : 1039 : ix86_has_no_direct_extern_access = true;
26704 : 750490359 : return default_binds_local_p_3 (exp, flag_shlib != 0, true,
26705 : : direct_extern_access,
26706 : : (direct_extern_access
26707 : 750489320 : && (!flag_pic
26708 : 130218452 : || (TARGET_64BIT
26709 : 750490359 : && HAVE_LD_PIE_COPYRELOC != 0))));
26710 : : }
26711 : :
26712 : : /* If flag_pic or ix86_direct_extern_access is false, then neither
26713 : : local nor global relocs should be placed in readonly memory. */
26714 : :
26715 : : static int
26716 : 5137799 : ix86_reloc_rw_mask (void)
26717 : : {
26718 : 5137799 : return (flag_pic || !ix86_direct_extern_access) ? 3 : 0;
26719 : : }
26720 : : #endif
26721 : :
26722 : : /* Return true iff ADDR can be used as a symbolic base address. */
26723 : :
26724 : : static bool
26725 : 3702 : symbolic_base_address_p (rtx addr)
26726 : : {
26727 : 0 : if (GET_CODE (addr) == SYMBOL_REF)
26728 : : return true;
26729 : :
26730 : 3627 : if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_GOTOFF)
26731 : 0 : return true;
26732 : :
26733 : : return false;
26734 : : }
26735 : :
26736 : : /* Return true iff ADDR can be used as a base address. */
26737 : :
26738 : : static bool
26739 : 5676 : base_address_p (rtx addr)
26740 : : {
26741 : 0 : if (REG_P (addr))
26742 : : return true;
26743 : :
26744 : 3448 : if (symbolic_base_address_p (addr))
26745 : 0 : return true;
26746 : :
26747 : : return false;
26748 : : }
26749 : :
26750 : : /* If MEM is in the form of [(base+symbase)+offset], extract the three
26751 : : parts of address and set to BASE, SYMBASE and OFFSET, otherwise
26752 : : return false. */
26753 : :
26754 : : static bool
26755 : 3508 : extract_base_offset_in_addr (rtx mem, rtx *base, rtx *symbase, rtx *offset)
26756 : : {
26757 : 3508 : rtx addr;
26758 : :
26759 : 3508 : gcc_assert (MEM_P (mem));
26760 : :
26761 : 3508 : addr = XEXP (mem, 0);
26762 : :
26763 : 3508 : if (GET_CODE (addr) == CONST)
26764 : 56 : addr = XEXP (addr, 0);
26765 : :
26766 : 3508 : if (base_address_p (addr))
26767 : : {
26768 : 1340 : *base = addr;
26769 : 1340 : *symbase = const0_rtx;
26770 : 1340 : *offset = const0_rtx;
26771 : 1340 : return true;
26772 : : }
26773 : :
26774 : 2168 : if (GET_CODE (addr) == PLUS
26775 : 2168 : && base_address_p (XEXP (addr, 0)))
26776 : : {
26777 : 963 : rtx addend = XEXP (addr, 1);
26778 : :
26779 : 963 : if (GET_CODE (addend) == CONST)
26780 : 0 : addend = XEXP (addend, 0);
26781 : :
26782 : 963 : if (CONST_INT_P (addend))
26783 : : {
26784 : 709 : *base = XEXP (addr, 0);
26785 : 709 : *symbase = const0_rtx;
26786 : 709 : *offset = addend;
26787 : 709 : return true;
26788 : : }
26789 : :
26790 : : /* Also accept REG + symbolic ref, with or without a CONST_INT
26791 : : offset. */
26792 : 254 : if (REG_P (XEXP (addr, 0)))
26793 : : {
26794 : 254 : if (symbolic_base_address_p (addend))
26795 : : {
26796 : 0 : *base = XEXP (addr, 0);
26797 : 0 : *symbase = addend;
26798 : 0 : *offset = const0_rtx;
26799 : 0 : return true;
26800 : : }
26801 : :
26802 : 254 : if (GET_CODE (addend) == PLUS
26803 : 0 : && symbolic_base_address_p (XEXP (addend, 0))
26804 : 254 : && CONST_INT_P (XEXP (addend, 1)))
26805 : : {
26806 : 0 : *base = XEXP (addr, 0);
26807 : 0 : *symbase = XEXP (addend, 0);
26808 : 0 : *offset = XEXP (addend, 1);
26809 : 0 : return true;
26810 : : }
26811 : : }
26812 : : }
26813 : :
26814 : : return false;
26815 : : }
26816 : :
26817 : : /* Given OPERANDS of consecutive load/store, check if we can merge
26818 : : them into move multiple. LOAD is true if they are load instructions.
26819 : : MODE is the mode of memory operands. */
26820 : :
26821 : : bool
26822 : 1950 : ix86_operands_ok_for_move_multiple (rtx *operands, bool load,
26823 : : machine_mode mode)
26824 : : {
26825 : 1950 : HOST_WIDE_INT offval_1, offval_2, msize;
26826 : 1950 : rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2,
26827 : : symbase_1, symbase_2, offset_1, offset_2;
26828 : :
26829 : 1950 : if (load)
26830 : : {
26831 : 1615 : mem_1 = operands[1];
26832 : 1615 : mem_2 = operands[3];
26833 : 1615 : reg_1 = operands[0];
26834 : 1615 : reg_2 = operands[2];
26835 : : }
26836 : : else
26837 : : {
26838 : 335 : mem_1 = operands[0];
26839 : 335 : mem_2 = operands[2];
26840 : 335 : reg_1 = operands[1];
26841 : 335 : reg_2 = operands[3];
26842 : : }
26843 : :
26844 : 1950 : gcc_assert (REG_P (reg_1) && REG_P (reg_2));
26845 : :
26846 : 1950 : if (REGNO (reg_1) != REGNO (reg_2))
26847 : : return false;
26848 : :
26849 : : /* Check if the addresses are in the form of [base+offset]. */
26850 : 1950 : if (!extract_base_offset_in_addr (mem_1, &base_1, &symbase_1, &offset_1))
26851 : : return false;
26852 : 1558 : if (!extract_base_offset_in_addr (mem_2, &base_2, &symbase_2, &offset_2))
26853 : : return false;
26854 : :
26855 : : /* Check if the bases are the same. */
26856 : 491 : if (!rtx_equal_p (base_1, base_2) || !rtx_equal_p (symbase_1, symbase_2))
26857 : 106 : return false;
26858 : :
26859 : 385 : offval_1 = INTVAL (offset_1);
26860 : 385 : offval_2 = INTVAL (offset_2);
26861 : 385 : msize = GET_MODE_SIZE (mode);
26862 : : /* Check if mem_1 is adjacent to mem_2 and mem_1 has lower address. */
26863 : 385 : if (offval_1 + msize != offval_2)
26864 : : return false;
26865 : :
26866 : : return true;
26867 : : }
26868 : :
26869 : : /* Implement the TARGET_OPTAB_SUPPORTED_P hook. */
26870 : :
26871 : : static bool
26872 : 324325 : ix86_optab_supported_p (int op, machine_mode mode1, machine_mode,
26873 : : optimization_type opt_type)
26874 : : {
26875 : 324325 : switch (op)
26876 : : {
26877 : 220 : case asin_optab:
26878 : 220 : case acos_optab:
26879 : 220 : case log1p_optab:
26880 : 220 : case exp_optab:
26881 : 220 : case exp10_optab:
26882 : 220 : case exp2_optab:
26883 : 220 : case expm1_optab:
26884 : 220 : case ldexp_optab:
26885 : 220 : case scalb_optab:
26886 : 220 : case round_optab:
26887 : 220 : case lround_optab:
26888 : 220 : return opt_type == OPTIMIZE_FOR_SPEED;
26889 : :
26890 : 267 : case rint_optab:
26891 : 267 : if (SSE_FLOAT_MODE_P (mode1)
26892 : 144 : && TARGET_SSE_MATH
26893 : 128 : && !flag_trapping_math
26894 : 21 : && !TARGET_SSE4_1
26895 : : && mode1 != HFmode)
26896 : 21 : return opt_type == OPTIMIZE_FOR_SPEED;
26897 : : return true;
26898 : :
26899 : 1816 : case floor_optab:
26900 : 1816 : case ceil_optab:
26901 : 1816 : case btrunc_optab:
26902 : 1816 : if (((SSE_FLOAT_MODE_P (mode1)
26903 : 1510 : && TARGET_SSE_MATH
26904 : 1431 : && TARGET_SSE4_1)
26905 : 1767 : || mode1 == HFmode)
26906 : 118 : && !flag_trapping_math)
26907 : : return true;
26908 : 1756 : return opt_type == OPTIMIZE_FOR_SPEED;
26909 : :
26910 : 84 : case rsqrt_optab:
26911 : 84 : return opt_type == OPTIMIZE_FOR_SPEED && use_rsqrt_p (mode1);
26912 : :
26913 : : default:
26914 : : return true;
26915 : : }
26916 : : }
26917 : :
26918 : : /* Address space support.
26919 : :
26920 : : This is not "far pointers" in the 16-bit sense, but an easy way
26921 : : to use %fs and %gs segment prefixes. Therefore:
26922 : :
26923 : : (a) All address spaces have the same modes,
26924 : : (b) All address spaces have the same addresss forms,
26925 : : (c) While %fs and %gs are technically subsets of the generic
26926 : : address space, they are probably not subsets of each other.
26927 : : (d) Since we have no access to the segment base register values
26928 : : without resorting to a system call, we cannot convert a
26929 : : non-default address space to a default address space.
26930 : : Therefore we do not claim %fs or %gs are subsets of generic.
26931 : :
26932 : : Therefore we can (mostly) use the default hooks. */
26933 : :
26934 : : /* All use of segmentation is assumed to make address 0 valid. */
26935 : :
26936 : : static bool
26937 : 67604128 : ix86_addr_space_zero_address_valid (addr_space_t as)
26938 : : {
26939 : 67604128 : return as != ADDR_SPACE_GENERIC;
26940 : : }
26941 : :
26942 : : static void
26943 : 785164 : ix86_init_libfuncs (void)
26944 : : {
26945 : 785164 : if (TARGET_64BIT)
26946 : : {
26947 : 770357 : set_optab_libfunc (sdivmod_optab, TImode, "__divmodti4");
26948 : 770357 : set_optab_libfunc (udivmod_optab, TImode, "__udivmodti4");
26949 : : }
26950 : : else
26951 : : {
26952 : 14807 : set_optab_libfunc (sdivmod_optab, DImode, "__divmoddi4");
26953 : 14807 : set_optab_libfunc (udivmod_optab, DImode, "__udivmoddi4");
26954 : : }
26955 : :
26956 : : #if TARGET_MACHO
26957 : : darwin_rename_builtins ();
26958 : : #endif
26959 : 785164 : }
26960 : :
26961 : : /* Set the value of FLT_EVAL_METHOD in float.h. When using only the
26962 : : FPU, assume that the fpcw is set to extended precision; when using
26963 : : only SSE, rounding is correct; when using both SSE and the FPU,
26964 : : the rounding precision is indeterminate, since either may be chosen
26965 : : apparently at random. */
26966 : :
26967 : : static enum flt_eval_method
26968 : 90973269 : ix86_get_excess_precision (enum excess_precision_type type)
26969 : : {
26970 : 90973269 : switch (type)
26971 : : {
26972 : 87151682 : case EXCESS_PRECISION_TYPE_FAST:
26973 : : /* The fastest type to promote to will always be the native type,
26974 : : whether that occurs with implicit excess precision or
26975 : : otherwise. */
26976 : 87151682 : return TARGET_AVX512FP16
26977 : 87151682 : ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
26978 : 87151682 : : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
26979 : 3821506 : case EXCESS_PRECISION_TYPE_STANDARD:
26980 : 3821506 : case EXCESS_PRECISION_TYPE_IMPLICIT:
26981 : : /* Otherwise, the excess precision we want when we are
26982 : : in a standards compliant mode, and the implicit precision we
26983 : : provide would be identical were it not for the unpredictable
26984 : : cases. */
26985 : 3821506 : if (TARGET_AVX512FP16 && TARGET_SSE_MATH)
26986 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16;
26987 : 3815752 : else if (!TARGET_80387)
26988 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
26989 : 3809652 : else if (!TARGET_MIX_SSE_I387)
26990 : : {
26991 : 3809480 : if (!(TARGET_SSE && TARGET_SSE_MATH))
26992 : : return FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE;
26993 : 2822830 : else if (TARGET_SSE2)
26994 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
26995 : : }
26996 : :
26997 : : /* If we are in standards compliant mode, but we know we will
26998 : : calculate in unpredictable precision, return
26999 : : FLT_EVAL_METHOD_FLOAT. There is no reason to introduce explicit
27000 : : excess precision if the target can't guarantee it will honor
27001 : : it. */
27002 : 318 : return (type == EXCESS_PRECISION_TYPE_STANDARD
27003 : 318 : ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
27004 : : : FLT_EVAL_METHOD_UNPREDICTABLE);
27005 : 81 : case EXCESS_PRECISION_TYPE_FLOAT16:
27006 : 81 : if (TARGET_80387
27007 : 75 : && !(TARGET_SSE_MATH && TARGET_SSE))
27008 : 4 : error ("%<-fexcess-precision=16%> is not compatible with %<-mfpmath=387%>");
27009 : : return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16;
27010 : 0 : default:
27011 : 0 : gcc_unreachable ();
27012 : : }
27013 : :
27014 : : return FLT_EVAL_METHOD_UNPREDICTABLE;
27015 : : }
27016 : :
27017 : : /* Return true if _BitInt(N) is supported and fill its details into *INFO. */
27018 : : bool
27019 : 1715710 : ix86_bitint_type_info (int n, struct bitint_info *info)
27020 : : {
27021 : 1715710 : if (n <= 8)
27022 : 3871 : info->limb_mode = QImode;
27023 : 1711839 : else if (n <= 16)
27024 : 918 : info->limb_mode = HImode;
27025 : 1710921 : else if (n <= 32 || (!TARGET_64BIT && n > 64))
27026 : 18773 : info->limb_mode = SImode;
27027 : : else
27028 : 1692148 : info->limb_mode = DImode;
27029 : 1715710 : info->abi_limb_mode = info->limb_mode;
27030 : 1715710 : info->big_endian = false;
27031 : 1715710 : info->extended = false;
27032 : 1715710 : return true;
27033 : : }
27034 : :
27035 : : /* Implement TARGET_C_MODE_FOR_FLOATING_TYPE. Return DFmode, TFmode
27036 : : or XFmode for TI_LONG_DOUBLE_TYPE which is for long double type,
27037 : : based on long double bits, go with the default one for the others. */
27038 : :
27039 : : static machine_mode
27040 : 3634329 : ix86_c_mode_for_floating_type (enum tree_index ti)
27041 : : {
27042 : 3634329 : if (ti == TI_LONG_DOUBLE_TYPE)
27043 : 606508 : return (TARGET_LONG_DOUBLE_64 ? DFmode
27044 : 606476 : : (TARGET_LONG_DOUBLE_128 ? TFmode : XFmode));
27045 : 3027821 : return default_mode_for_floating_type (ti);
27046 : : }
27047 : :
27048 : : /* Returns modified FUNCTION_TYPE for cdtor callabi. */
27049 : : tree
27050 : 13612 : ix86_cxx_adjust_cdtor_callabi_fntype (tree fntype)
27051 : : {
27052 : 13612 : if (TARGET_64BIT
27053 : 65 : || TARGET_RTD
27054 : 13677 : || ix86_function_type_abi (fntype) != MS_ABI)
27055 : 13612 : return fntype;
27056 : : /* For 32-bit MS ABI add thiscall attribute. */
27057 : 0 : tree attribs = tree_cons (get_identifier ("thiscall"), NULL_TREE,
27058 : 0 : TYPE_ATTRIBUTES (fntype));
27059 : 0 : return build_type_attribute_variant (fntype, attribs);
27060 : : }
27061 : :
27062 : : /* Implement PUSH_ROUNDING. On 386, we have pushw instruction that
27063 : : decrements by exactly 2 no matter what the position was, there is no pushb.
27064 : :
27065 : : But as CIE data alignment factor on this arch is -4 for 32bit targets
27066 : : and -8 for 64bit targets, we need to make sure all stack pointer adjustments
27067 : : are in multiple of 4 for 32bit targets and 8 for 64bit targets. */
27068 : :
27069 : : poly_int64
27070 : 268449926 : ix86_push_rounding (poly_int64 bytes)
27071 : : {
27072 : 347910561 : return ROUND_UP (bytes, UNITS_PER_WORD);
27073 : : }
27074 : :
27075 : : /* Use 8 bits metadata start from bit48 for LAM_U48,
27076 : : 6 bits metadat start from bit57 for LAM_U57. */
27077 : : #define IX86_HWASAN_SHIFT (ix86_lam_type == lam_u48 \
27078 : : ? 48 \
27079 : : : (ix86_lam_type == lam_u57 ? 57 : 0))
27080 : : #define IX86_HWASAN_TAG_SIZE (ix86_lam_type == lam_u48 \
27081 : : ? 8 \
27082 : : : (ix86_lam_type == lam_u57 ? 6 : 0))
27083 : :
27084 : : /* Implement TARGET_MEMTAG_CAN_TAG_ADDRESSES. */
27085 : : bool
27086 : 6185211 : ix86_memtag_can_tag_addresses ()
27087 : : {
27088 : 6185211 : return ix86_lam_type != lam_none && TARGET_LP64;
27089 : : }
27090 : :
27091 : : /* Implement TARGET_MEMTAG_TAG_SIZE. */
27092 : : unsigned char
27093 : 435 : ix86_memtag_tag_size ()
27094 : : {
27095 : 435 : return IX86_HWASAN_TAG_SIZE;
27096 : : }
27097 : :
27098 : : /* Implement TARGET_MEMTAG_SET_TAG. */
27099 : : rtx
27100 : 103 : ix86_memtag_set_tag (rtx untagged, rtx tag, rtx target)
27101 : : {
27102 : : /* default_memtag_insert_random_tag may
27103 : : generate tag with value more than 6 bits. */
27104 : 103 : if (ix86_lam_type == lam_u57)
27105 : : {
27106 : 103 : unsigned HOST_WIDE_INT and_imm
27107 : : = (HOST_WIDE_INT_1U << IX86_HWASAN_TAG_SIZE) - 1;
27108 : :
27109 : 103 : emit_insn (gen_andqi3 (tag, tag, GEN_INT (and_imm)));
27110 : : }
27111 : 103 : tag = expand_simple_binop (Pmode, ASHIFT, tag,
27112 : 103 : GEN_INT (IX86_HWASAN_SHIFT), NULL_RTX,
27113 : : /* unsignedp = */1, OPTAB_WIDEN);
27114 : 103 : rtx ret = expand_simple_binop (Pmode, IOR, untagged, tag, target,
27115 : : /* unsignedp = */1, OPTAB_DIRECT);
27116 : 103 : return ret;
27117 : : }
27118 : :
27119 : : /* Implement TARGET_MEMTAG_EXTRACT_TAG. */
27120 : : rtx
27121 : 174 : ix86_memtag_extract_tag (rtx tagged_pointer, rtx target)
27122 : : {
27123 : 174 : rtx tag = expand_simple_binop (Pmode, LSHIFTRT, tagged_pointer,
27124 : 174 : GEN_INT (IX86_HWASAN_SHIFT), target,
27125 : : /* unsignedp = */0,
27126 : : OPTAB_DIRECT);
27127 : 174 : rtx ret = gen_reg_rtx (QImode);
27128 : : /* Mask off bit63 when LAM_U57. */
27129 : 174 : if (ix86_lam_type == lam_u57)
27130 : : {
27131 : 174 : unsigned HOST_WIDE_INT and_imm
27132 : : = (HOST_WIDE_INT_1U << IX86_HWASAN_TAG_SIZE) - 1;
27133 : 174 : emit_insn (gen_andqi3 (ret, gen_lowpart (QImode, tag),
27134 : 174 : gen_int_mode (and_imm, QImode)));
27135 : : }
27136 : : else
27137 : 0 : emit_move_insn (ret, gen_lowpart (QImode, tag));
27138 : 174 : return ret;
27139 : : }
27140 : :
27141 : : /* The default implementation of TARGET_MEMTAG_UNTAGGED_POINTER. */
27142 : : rtx
27143 : 111 : ix86_memtag_untagged_pointer (rtx tagged_pointer, rtx target)
27144 : : {
27145 : : /* Leave bit63 alone. */
27146 : 111 : rtx tag_mask = gen_int_mode (((HOST_WIDE_INT_1U << IX86_HWASAN_SHIFT)
27147 : 111 : + (HOST_WIDE_INT_1U << 63) - 1),
27148 : 111 : Pmode);
27149 : 111 : rtx untagged_base = expand_simple_binop (Pmode, AND, tagged_pointer,
27150 : : tag_mask, target, true,
27151 : : OPTAB_DIRECT);
27152 : 111 : gcc_assert (untagged_base);
27153 : 111 : return untagged_base;
27154 : : }
27155 : :
27156 : : /* Implement TARGET_MEMTAG_ADD_TAG. */
27157 : : rtx
27158 : 87 : ix86_memtag_add_tag (rtx base, poly_int64 offset, unsigned char tag_offset)
27159 : : {
27160 : 87 : rtx base_tag = gen_reg_rtx (QImode);
27161 : 87 : rtx base_addr = gen_reg_rtx (Pmode);
27162 : 87 : rtx tagged_addr = gen_reg_rtx (Pmode);
27163 : 87 : rtx new_tag = gen_reg_rtx (QImode);
27164 : 174 : unsigned HOST_WIDE_INT and_imm
27165 : 87 : = (HOST_WIDE_INT_1U << IX86_HWASAN_SHIFT) - 1;
27166 : :
27167 : : /* When there's "overflow" in tag adding,
27168 : : need to mask the most significant bit off. */
27169 : 87 : emit_move_insn (base_tag, ix86_memtag_extract_tag (base, NULL_RTX));
27170 : 87 : emit_move_insn (base_addr,
27171 : : ix86_memtag_untagged_pointer (base, NULL_RTX));
27172 : 87 : emit_insn (gen_add2_insn (base_tag, gen_int_mode (tag_offset, QImode)));
27173 : 87 : emit_move_insn (new_tag, base_tag);
27174 : 87 : emit_insn (gen_andqi3 (new_tag, new_tag, gen_int_mode (and_imm, QImode)));
27175 : 87 : emit_move_insn (tagged_addr,
27176 : : ix86_memtag_set_tag (base_addr, new_tag, NULL_RTX));
27177 : 87 : return plus_constant (Pmode, tagged_addr, offset);
27178 : : }
27179 : :
27180 : : /* Implement TARGET_HAVE_CCMP. */
27181 : : static bool
27182 : 7858037 : ix86_have_ccmp ()
27183 : : {
27184 : 7858037 : return (bool) TARGET_APX_CCMP;
27185 : : }
27186 : :
27187 : : /* Implement TARGET_MODE_CAN_TRANSFER_BITS. */
27188 : : static bool
27189 : 4779345 : ix86_mode_can_transfer_bits (machine_mode mode)
27190 : : {
27191 : 4779345 : if (GET_MODE_CLASS (mode) == MODE_FLOAT
27192 : 4731619 : || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
27193 : 115462 : switch (GET_MODE_INNER (mode))
27194 : : {
27195 : 55628 : case E_SFmode:
27196 : 55628 : case E_DFmode:
27197 : : /* These suffer from normalization upon load when not using SSE. */
27198 : 55628 : return !(ix86_fpmath & FPMATH_387);
27199 : : default:
27200 : : return true;
27201 : : }
27202 : :
27203 : : return true;
27204 : : }
27205 : :
27206 : : /* Implement TARGET_REDZONE_CLOBBER. */
27207 : : static rtx
27208 : 2 : ix86_redzone_clobber ()
27209 : : {
27210 : 2 : cfun->machine->asm_redzone_clobber_seen = true;
27211 : 2 : if (ix86_using_red_zone ())
27212 : : {
27213 : 2 : rtx base = plus_constant (Pmode, stack_pointer_rtx, -RED_ZONE_SIZE);
27214 : 2 : rtx mem = gen_rtx_MEM (BLKmode, base);
27215 : 2 : set_mem_size (mem, RED_ZONE_SIZE);
27216 : 2 : return mem;
27217 : : }
27218 : : return NULL_RTX;
27219 : : }
27220 : :
27221 : : /* Target-specific selftests. */
27222 : :
27223 : : #if CHECKING_P
27224 : :
27225 : : namespace selftest {
27226 : :
27227 : : /* Verify that hard regs are dumped as expected (in compact mode). */
27228 : :
27229 : : static void
27230 : 4 : ix86_test_dumping_hard_regs ()
27231 : : {
27232 : 4 : ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
27233 : 4 : ASSERT_RTL_DUMP_EQ ("(reg:SI dx)", gen_raw_REG (SImode, 1));
27234 : 4 : }
27235 : :
27236 : : /* Test dumping an insn with repeated references to the same SCRATCH,
27237 : : to verify the rtx_reuse code. */
27238 : :
27239 : : static void
27240 : 4 : ix86_test_dumping_memory_blockage ()
27241 : : {
27242 : 4 : set_new_first_and_last_insn (NULL, NULL);
27243 : :
27244 : 4 : rtx pat = gen_memory_blockage ();
27245 : 4 : rtx_reuse_manager r;
27246 : 4 : r.preprocess (pat);
27247 : :
27248 : : /* Verify that the repeated references to the SCRATCH show use
27249 : : reuse IDS. The first should be prefixed with a reuse ID,
27250 : : and the second should be dumped as a "reuse_rtx" of that ID.
27251 : : The expected string assumes Pmode == DImode. */
27252 : 4 : if (Pmode == DImode)
27253 : 4 : ASSERT_RTL_DUMP_EQ_WITH_REUSE
27254 : : ("(cinsn 1 (set (mem/v:BLK (0|scratch:DI) [0 A8])\n"
27255 : : " (unspec:BLK [\n"
27256 : : " (mem/v:BLK (reuse_rtx 0) [0 A8])\n"
27257 : : " ] UNSPEC_MEMORY_BLOCKAGE)))\n", pat, &r);
27258 : 4 : }
27259 : :
27260 : : /* Verify loading an RTL dump; specifically a dump of copying
27261 : : a param on x86_64 from a hard reg into the frame.
27262 : : This test is target-specific since the dump contains target-specific
27263 : : hard reg names. */
27264 : :
27265 : : static void
27266 : 4 : ix86_test_loading_dump_fragment_1 ()
27267 : : {
27268 : 4 : rtl_dump_test t (SELFTEST_LOCATION,
27269 : 4 : locate_file ("x86_64/copy-hard-reg-into-frame.rtl"));
27270 : :
27271 : 4 : rtx_insn *insn = get_insn_by_uid (1);
27272 : :
27273 : : /* The block structure and indentation here is purely for
27274 : : readability; it mirrors the structure of the rtx. */
27275 : 4 : tree mem_expr;
27276 : 4 : {
27277 : 4 : rtx pat = PATTERN (insn);
27278 : 4 : ASSERT_EQ (SET, GET_CODE (pat));
27279 : 4 : {
27280 : 4 : rtx dest = SET_DEST (pat);
27281 : 4 : ASSERT_EQ (MEM, GET_CODE (dest));
27282 : : /* Verify the "/c" was parsed. */
27283 : 4 : ASSERT_TRUE (RTX_FLAG (dest, call));
27284 : 4 : ASSERT_EQ (SImode, GET_MODE (dest));
27285 : 4 : {
27286 : 4 : rtx addr = XEXP (dest, 0);
27287 : 4 : ASSERT_EQ (PLUS, GET_CODE (addr));
27288 : 4 : ASSERT_EQ (DImode, GET_MODE (addr));
27289 : 4 : {
27290 : 4 : rtx lhs = XEXP (addr, 0);
27291 : : /* Verify that the "frame" REG was consolidated. */
27292 : 4 : ASSERT_RTX_PTR_EQ (frame_pointer_rtx, lhs);
27293 : : }
27294 : 4 : {
27295 : 4 : rtx rhs = XEXP (addr, 1);
27296 : 4 : ASSERT_EQ (CONST_INT, GET_CODE (rhs));
27297 : 4 : ASSERT_EQ (-4, INTVAL (rhs));
27298 : : }
27299 : : }
27300 : : /* Verify the "[1 i+0 S4 A32]" was parsed. */
27301 : 4 : ASSERT_EQ (1, MEM_ALIAS_SET (dest));
27302 : : /* "i" should have been handled by synthesizing a global int
27303 : : variable named "i". */
27304 : 4 : mem_expr = MEM_EXPR (dest);
27305 : 4 : ASSERT_NE (mem_expr, NULL);
27306 : 4 : ASSERT_EQ (VAR_DECL, TREE_CODE (mem_expr));
27307 : 4 : ASSERT_EQ (integer_type_node, TREE_TYPE (mem_expr));
27308 : 4 : ASSERT_EQ (IDENTIFIER_NODE, TREE_CODE (DECL_NAME (mem_expr)));
27309 : 4 : ASSERT_STREQ ("i", IDENTIFIER_POINTER (DECL_NAME (mem_expr)));
27310 : : /* "+0". */
27311 : 4 : ASSERT_TRUE (MEM_OFFSET_KNOWN_P (dest));
27312 : 4 : ASSERT_EQ (0, MEM_OFFSET (dest));
27313 : : /* "S4". */
27314 : 4 : ASSERT_EQ (4, MEM_SIZE (dest));
27315 : : /* "A32. */
27316 : 4 : ASSERT_EQ (32, MEM_ALIGN (dest));
27317 : : }
27318 : 4 : {
27319 : 4 : rtx src = SET_SRC (pat);
27320 : 4 : ASSERT_EQ (REG, GET_CODE (src));
27321 : 4 : ASSERT_EQ (SImode, GET_MODE (src));
27322 : 4 : ASSERT_EQ (5, REGNO (src));
27323 : 4 : tree reg_expr = REG_EXPR (src);
27324 : : /* "i" here should point to the same var as for the MEM_EXPR. */
27325 : 4 : ASSERT_EQ (reg_expr, mem_expr);
27326 : : }
27327 : : }
27328 : 4 : }
27329 : :
27330 : : /* Verify that the RTL loader copes with a call_insn dump.
27331 : : This test is target-specific since the dump contains a target-specific
27332 : : hard reg name. */
27333 : :
27334 : : static void
27335 : 4 : ix86_test_loading_call_insn ()
27336 : : {
27337 : : /* The test dump includes register "xmm0", where requires TARGET_SSE
27338 : : to exist. */
27339 : 4 : if (!TARGET_SSE)
27340 : 0 : return;
27341 : :
27342 : 4 : rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/call-insn.rtl"));
27343 : :
27344 : 4 : rtx_insn *insn = get_insns ();
27345 : 4 : ASSERT_EQ (CALL_INSN, GET_CODE (insn));
27346 : :
27347 : : /* "/j". */
27348 : 4 : ASSERT_TRUE (RTX_FLAG (insn, jump));
27349 : :
27350 : 4 : rtx pat = PATTERN (insn);
27351 : 4 : ASSERT_EQ (CALL, GET_CODE (SET_SRC (pat)));
27352 : :
27353 : : /* Verify REG_NOTES. */
27354 : 4 : {
27355 : : /* "(expr_list:REG_CALL_DECL". */
27356 : 4 : ASSERT_EQ (EXPR_LIST, GET_CODE (REG_NOTES (insn)));
27357 : 4 : rtx_expr_list *note0 = as_a <rtx_expr_list *> (REG_NOTES (insn));
27358 : 4 : ASSERT_EQ (REG_CALL_DECL, REG_NOTE_KIND (note0));
27359 : :
27360 : : /* "(expr_list:REG_EH_REGION (const_int 0 [0])". */
27361 : 4 : rtx_expr_list *note1 = note0->next ();
27362 : 4 : ASSERT_EQ (REG_EH_REGION, REG_NOTE_KIND (note1));
27363 : :
27364 : 4 : ASSERT_EQ (NULL, note1->next ());
27365 : : }
27366 : :
27367 : : /* Verify CALL_INSN_FUNCTION_USAGE. */
27368 : 4 : {
27369 : : /* "(expr_list:DF (use (reg:DF 21 xmm0))". */
27370 : 4 : rtx_expr_list *usage
27371 : 4 : = as_a <rtx_expr_list *> (CALL_INSN_FUNCTION_USAGE (insn));
27372 : 4 : ASSERT_EQ (EXPR_LIST, GET_CODE (usage));
27373 : 4 : ASSERT_EQ (DFmode, GET_MODE (usage));
27374 : 4 : ASSERT_EQ (USE, GET_CODE (usage->element ()));
27375 : 4 : ASSERT_EQ (NULL, usage->next ());
27376 : : }
27377 : 4 : }
27378 : :
27379 : : /* Verify that the RTL loader copes a dump from print_rtx_function.
27380 : : This test is target-specific since the dump contains target-specific
27381 : : hard reg names. */
27382 : :
27383 : : static void
27384 : 4 : ix86_test_loading_full_dump ()
27385 : : {
27386 : 4 : rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/times-two.rtl"));
27387 : :
27388 : 4 : ASSERT_STREQ ("times_two", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
27389 : :
27390 : 4 : rtx_insn *insn_1 = get_insn_by_uid (1);
27391 : 4 : ASSERT_EQ (NOTE, GET_CODE (insn_1));
27392 : :
27393 : 4 : rtx_insn *insn_7 = get_insn_by_uid (7);
27394 : 4 : ASSERT_EQ (INSN, GET_CODE (insn_7));
27395 : 4 : ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_7)));
27396 : :
27397 : 4 : rtx_insn *insn_15 = get_insn_by_uid (15);
27398 : 4 : ASSERT_EQ (INSN, GET_CODE (insn_15));
27399 : 4 : ASSERT_EQ (USE, GET_CODE (PATTERN (insn_15)));
27400 : :
27401 : : /* Verify crtl->return_rtx. */
27402 : 4 : ASSERT_EQ (REG, GET_CODE (crtl->return_rtx));
27403 : 4 : ASSERT_EQ (0, REGNO (crtl->return_rtx));
27404 : 4 : ASSERT_EQ (SImode, GET_MODE (crtl->return_rtx));
27405 : 4 : }
27406 : :
27407 : : /* Verify that the RTL loader copes with UNSPEC and UNSPEC_VOLATILE insns.
27408 : : In particular, verify that it correctly loads the 2nd operand.
27409 : : This test is target-specific since these are machine-specific
27410 : : operands (and enums). */
27411 : :
27412 : : static void
27413 : 4 : ix86_test_loading_unspec ()
27414 : : {
27415 : 4 : rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/unspec.rtl"));
27416 : :
27417 : 4 : ASSERT_STREQ ("test_unspec", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
27418 : :
27419 : 4 : ASSERT_TRUE (cfun);
27420 : :
27421 : : /* Test of an UNSPEC. */
27422 : 4 : rtx_insn *insn = get_insns ();
27423 : 4 : ASSERT_EQ (INSN, GET_CODE (insn));
27424 : 4 : rtx set = single_set (insn);
27425 : 4 : ASSERT_NE (NULL, set);
27426 : 4 : rtx dst = SET_DEST (set);
27427 : 4 : ASSERT_EQ (MEM, GET_CODE (dst));
27428 : 4 : rtx src = SET_SRC (set);
27429 : 4 : ASSERT_EQ (UNSPEC, GET_CODE (src));
27430 : 4 : ASSERT_EQ (BLKmode, GET_MODE (src));
27431 : 4 : ASSERT_EQ (UNSPEC_MEMORY_BLOCKAGE, XINT (src, 1));
27432 : :
27433 : 4 : rtx v0 = XVECEXP (src, 0, 0);
27434 : :
27435 : : /* Verify that the two uses of the first SCRATCH have pointer
27436 : : equality. */
27437 : 4 : rtx scratch_a = XEXP (dst, 0);
27438 : 4 : ASSERT_EQ (SCRATCH, GET_CODE (scratch_a));
27439 : :
27440 : 4 : rtx scratch_b = XEXP (v0, 0);
27441 : 4 : ASSERT_EQ (SCRATCH, GET_CODE (scratch_b));
27442 : :
27443 : 4 : ASSERT_EQ (scratch_a, scratch_b);
27444 : :
27445 : : /* Verify that the two mems are thus treated as equal. */
27446 : 4 : ASSERT_TRUE (rtx_equal_p (dst, v0));
27447 : :
27448 : : /* Verify that the insn is recognized. */
27449 : 4 : ASSERT_NE(-1, recog_memoized (insn));
27450 : :
27451 : : /* Test of an UNSPEC_VOLATILE, which has its own enum values. */
27452 : 4 : insn = NEXT_INSN (insn);
27453 : 4 : ASSERT_EQ (INSN, GET_CODE (insn));
27454 : :
27455 : 4 : set = single_set (insn);
27456 : 4 : ASSERT_NE (NULL, set);
27457 : :
27458 : 4 : src = SET_SRC (set);
27459 : 4 : ASSERT_EQ (UNSPEC_VOLATILE, GET_CODE (src));
27460 : 4 : ASSERT_EQ (UNSPECV_RDTSCP, XINT (src, 1));
27461 : 4 : }
27462 : :
27463 : : /* Run all target-specific selftests. */
27464 : :
27465 : : static void
27466 : 4 : ix86_run_selftests (void)
27467 : : {
27468 : 4 : ix86_test_dumping_hard_regs ();
27469 : 4 : ix86_test_dumping_memory_blockage ();
27470 : :
27471 : : /* Various tests of loading RTL dumps, here because they contain
27472 : : ix86-isms (e.g. names of hard regs). */
27473 : 4 : ix86_test_loading_dump_fragment_1 ();
27474 : 4 : ix86_test_loading_call_insn ();
27475 : 4 : ix86_test_loading_full_dump ();
27476 : 4 : ix86_test_loading_unspec ();
27477 : 4 : }
27478 : :
27479 : : } // namespace selftest
27480 : :
27481 : : #endif /* CHECKING_P */
27482 : :
27483 : : static const scoped_attribute_specs *const ix86_attribute_table[] =
27484 : : {
27485 : : &ix86_gnu_attribute_table
27486 : : };
27487 : :
27488 : : /* Initialize the GCC target structure. */
27489 : : #undef TARGET_RETURN_IN_MEMORY
27490 : : #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
27491 : :
27492 : : #undef TARGET_LEGITIMIZE_ADDRESS
27493 : : #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
27494 : :
27495 : : #undef TARGET_ATTRIBUTE_TABLE
27496 : : #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
27497 : : #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
27498 : : #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
27499 : : #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27500 : : # undef TARGET_MERGE_DECL_ATTRIBUTES
27501 : : # define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
27502 : : #endif
27503 : :
27504 : : #undef TARGET_INVALID_CONVERSION
27505 : : #define TARGET_INVALID_CONVERSION ix86_invalid_conversion
27506 : :
27507 : : #undef TARGET_INVALID_UNARY_OP
27508 : : #define TARGET_INVALID_UNARY_OP ix86_invalid_unary_op
27509 : :
27510 : : #undef TARGET_INVALID_BINARY_OP
27511 : : #define TARGET_INVALID_BINARY_OP ix86_invalid_binary_op
27512 : :
27513 : : #undef TARGET_COMP_TYPE_ATTRIBUTES
27514 : : #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
27515 : :
27516 : : #undef TARGET_INIT_BUILTINS
27517 : : #define TARGET_INIT_BUILTINS ix86_init_builtins
27518 : : #undef TARGET_BUILTIN_DECL
27519 : : #define TARGET_BUILTIN_DECL ix86_builtin_decl
27520 : : #undef TARGET_EXPAND_BUILTIN
27521 : : #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
27522 : :
27523 : : #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
27524 : : #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
27525 : : ix86_builtin_vectorized_function
27526 : :
27527 : : #undef TARGET_VECTORIZE_BUILTIN_GATHER
27528 : : #define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather
27529 : :
27530 : : #undef TARGET_VECTORIZE_BUILTIN_SCATTER
27531 : : #define TARGET_VECTORIZE_BUILTIN_SCATTER ix86_vectorize_builtin_scatter
27532 : :
27533 : : #undef TARGET_BUILTIN_RECIPROCAL
27534 : : #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
27535 : :
27536 : : #undef TARGET_ASM_FUNCTION_EPILOGUE
27537 : : #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
27538 : :
27539 : : #undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
27540 : : #define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY \
27541 : : ix86_print_patchable_function_entry
27542 : :
27543 : : #undef TARGET_ENCODE_SECTION_INFO
27544 : : #ifndef SUBTARGET_ENCODE_SECTION_INFO
27545 : : #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
27546 : : #else
27547 : : #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
27548 : : #endif
27549 : :
27550 : : #undef TARGET_ASM_OPEN_PAREN
27551 : : #define TARGET_ASM_OPEN_PAREN ""
27552 : : #undef TARGET_ASM_CLOSE_PAREN
27553 : : #define TARGET_ASM_CLOSE_PAREN ""
27554 : :
27555 : : #undef TARGET_ASM_BYTE_OP
27556 : : #define TARGET_ASM_BYTE_OP ASM_BYTE
27557 : :
27558 : : #undef TARGET_ASM_ALIGNED_HI_OP
27559 : : #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
27560 : : #undef TARGET_ASM_ALIGNED_SI_OP
27561 : : #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
27562 : : #ifdef ASM_QUAD
27563 : : #undef TARGET_ASM_ALIGNED_DI_OP
27564 : : #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
27565 : : #endif
27566 : :
27567 : : #undef TARGET_PROFILE_BEFORE_PROLOGUE
27568 : : #define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
27569 : :
27570 : : #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
27571 : : #define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name
27572 : :
27573 : : #undef TARGET_ASM_UNALIGNED_HI_OP
27574 : : #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
27575 : : #undef TARGET_ASM_UNALIGNED_SI_OP
27576 : : #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
27577 : : #undef TARGET_ASM_UNALIGNED_DI_OP
27578 : : #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
27579 : :
27580 : : #undef TARGET_PRINT_OPERAND
27581 : : #define TARGET_PRINT_OPERAND ix86_print_operand
27582 : : #undef TARGET_PRINT_OPERAND_ADDRESS
27583 : : #define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address
27584 : : #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
27585 : : #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p
27586 : : #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
27587 : : #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra
27588 : :
27589 : : #undef TARGET_SCHED_INIT_GLOBAL
27590 : : #define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global
27591 : : #undef TARGET_SCHED_ADJUST_COST
27592 : : #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
27593 : : #undef TARGET_SCHED_ISSUE_RATE
27594 : : #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
27595 : : #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
27596 : : #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
27597 : : ia32_multipass_dfa_lookahead
27598 : : #undef TARGET_SCHED_MACRO_FUSION_P
27599 : : #define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p
27600 : : #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
27601 : : #define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p
27602 : :
27603 : : #undef TARGET_FUNCTION_OK_FOR_SIBCALL
27604 : : #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
27605 : :
27606 : : #undef TARGET_MEMMODEL_CHECK
27607 : : #define TARGET_MEMMODEL_CHECK ix86_memmodel_check
27608 : :
27609 : : #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
27610 : : #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv
27611 : :
27612 : : #ifdef HAVE_AS_TLS
27613 : : #undef TARGET_HAVE_TLS
27614 : : #define TARGET_HAVE_TLS true
27615 : : #endif
27616 : : #undef TARGET_CANNOT_FORCE_CONST_MEM
27617 : : #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
27618 : : #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
27619 : : #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
27620 : :
27621 : : #undef TARGET_DELEGITIMIZE_ADDRESS
27622 : : #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
27623 : :
27624 : : #undef TARGET_CONST_NOT_OK_FOR_DEBUG_P
27625 : : #define TARGET_CONST_NOT_OK_FOR_DEBUG_P ix86_const_not_ok_for_debug_p
27626 : :
27627 : : #undef TARGET_MS_BITFIELD_LAYOUT_P
27628 : : #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
27629 : :
27630 : : #if TARGET_MACHO
27631 : : #undef TARGET_BINDS_LOCAL_P
27632 : : #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
27633 : : #else
27634 : : #undef TARGET_BINDS_LOCAL_P
27635 : : #define TARGET_BINDS_LOCAL_P ix86_binds_local_p
27636 : : #endif
27637 : : #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
27638 : : #undef TARGET_BINDS_LOCAL_P
27639 : : #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
27640 : : #endif
27641 : :
27642 : : #undef TARGET_ASM_OUTPUT_MI_THUNK
27643 : : #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
27644 : : #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
27645 : : #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
27646 : :
27647 : : #undef TARGET_ASM_FILE_START
27648 : : #define TARGET_ASM_FILE_START x86_file_start
27649 : :
27650 : : #undef TARGET_OPTION_OVERRIDE
27651 : : #define TARGET_OPTION_OVERRIDE ix86_option_override
27652 : :
27653 : : #undef TARGET_REGISTER_MOVE_COST
27654 : : #define TARGET_REGISTER_MOVE_COST ix86_register_move_cost
27655 : : #undef TARGET_MEMORY_MOVE_COST
27656 : : #define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost
27657 : : #undef TARGET_RTX_COSTS
27658 : : #define TARGET_RTX_COSTS ix86_rtx_costs
27659 : : #undef TARGET_INSN_COST
27660 : : #define TARGET_INSN_COST ix86_insn_cost
27661 : : #undef TARGET_ADDRESS_COST
27662 : : #define TARGET_ADDRESS_COST ix86_address_cost
27663 : :
27664 : : #undef TARGET_OVERLAP_OP_BY_PIECES_P
27665 : : #define TARGET_OVERLAP_OP_BY_PIECES_P hook_bool_void_true
27666 : :
27667 : : #undef TARGET_FLAGS_REGNUM
27668 : : #define TARGET_FLAGS_REGNUM FLAGS_REG
27669 : : #undef TARGET_FIXED_CONDITION_CODE_REGS
27670 : : #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
27671 : : #undef TARGET_CC_MODES_COMPATIBLE
27672 : : #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
27673 : :
27674 : : #undef TARGET_MACHINE_DEPENDENT_REORG
27675 : : #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
27676 : :
27677 : : #undef TARGET_BUILD_BUILTIN_VA_LIST
27678 : : #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
27679 : :
27680 : : #undef TARGET_FOLD_BUILTIN
27681 : : #define TARGET_FOLD_BUILTIN ix86_fold_builtin
27682 : :
27683 : : #undef TARGET_GIMPLE_FOLD_BUILTIN
27684 : : #define TARGET_GIMPLE_FOLD_BUILTIN ix86_gimple_fold_builtin
27685 : :
27686 : : #undef TARGET_COMPARE_VERSION_PRIORITY
27687 : : #define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority
27688 : :
27689 : : #undef TARGET_GENERATE_VERSION_DISPATCHER_BODY
27690 : : #define TARGET_GENERATE_VERSION_DISPATCHER_BODY \
27691 : : ix86_generate_version_dispatcher_body
27692 : :
27693 : : #undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
27694 : : #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
27695 : : ix86_get_function_versions_dispatcher
27696 : :
27697 : : #undef TARGET_ENUM_VA_LIST_P
27698 : : #define TARGET_ENUM_VA_LIST_P ix86_enum_va_list
27699 : :
27700 : : #undef TARGET_FN_ABI_VA_LIST
27701 : : #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
27702 : :
27703 : : #undef TARGET_CANONICAL_VA_LIST_TYPE
27704 : : #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
27705 : :
27706 : : #undef TARGET_EXPAND_BUILTIN_VA_START
27707 : : #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
27708 : :
27709 : : #undef TARGET_MD_ASM_ADJUST
27710 : : #define TARGET_MD_ASM_ADJUST ix86_md_asm_adjust
27711 : :
27712 : : #undef TARGET_C_EXCESS_PRECISION
27713 : : #define TARGET_C_EXCESS_PRECISION ix86_get_excess_precision
27714 : : #undef TARGET_C_BITINT_TYPE_INFO
27715 : : #define TARGET_C_BITINT_TYPE_INFO ix86_bitint_type_info
27716 : : #undef TARGET_C_MODE_FOR_FLOATING_TYPE
27717 : : #define TARGET_C_MODE_FOR_FLOATING_TYPE ix86_c_mode_for_floating_type
27718 : : #undef TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE
27719 : : #define TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE ix86_cxx_adjust_cdtor_callabi_fntype
27720 : : #undef TARGET_PROMOTE_PROTOTYPES
27721 : : #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
27722 : : #undef TARGET_PUSH_ARGUMENT
27723 : : #define TARGET_PUSH_ARGUMENT ix86_push_argument
27724 : : #undef TARGET_SETUP_INCOMING_VARARGS
27725 : : #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
27726 : : #undef TARGET_MUST_PASS_IN_STACK
27727 : : #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
27728 : : #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
27729 : : #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS ix86_allocate_stack_slots_for_args
27730 : : #undef TARGET_FUNCTION_ARG_ADVANCE
27731 : : #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance
27732 : : #undef TARGET_FUNCTION_ARG
27733 : : #define TARGET_FUNCTION_ARG ix86_function_arg
27734 : : #undef TARGET_INIT_PIC_REG
27735 : : #define TARGET_INIT_PIC_REG ix86_init_pic_reg
27736 : : #undef TARGET_USE_PSEUDO_PIC_REG
27737 : : #define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg
27738 : : #undef TARGET_FUNCTION_ARG_BOUNDARY
27739 : : #define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary
27740 : : #undef TARGET_PASS_BY_REFERENCE
27741 : : #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
27742 : : #undef TARGET_INTERNAL_ARG_POINTER
27743 : : #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
27744 : : #undef TARGET_UPDATE_STACK_BOUNDARY
27745 : : #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
27746 : : #undef TARGET_GET_DRAP_RTX
27747 : : #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
27748 : : #undef TARGET_STRICT_ARGUMENT_NAMING
27749 : : #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
27750 : : #undef TARGET_STATIC_CHAIN
27751 : : #define TARGET_STATIC_CHAIN ix86_static_chain
27752 : : #undef TARGET_TRAMPOLINE_INIT
27753 : : #define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
27754 : : #undef TARGET_RETURN_POPS_ARGS
27755 : : #define TARGET_RETURN_POPS_ARGS ix86_return_pops_args
27756 : :
27757 : : #undef TARGET_WARN_FUNC_RETURN
27758 : : #define TARGET_WARN_FUNC_RETURN ix86_warn_func_return
27759 : :
27760 : : #undef TARGET_LEGITIMATE_COMBINED_INSN
27761 : : #define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn
27762 : :
27763 : : #undef TARGET_ASAN_SHADOW_OFFSET
27764 : : #define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset
27765 : :
27766 : : #undef TARGET_GIMPLIFY_VA_ARG_EXPR
27767 : : #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
27768 : :
27769 : : #undef TARGET_SCALAR_MODE_SUPPORTED_P
27770 : : #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
27771 : :
27772 : : #undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
27773 : : #define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \
27774 : : ix86_libgcc_floating_mode_supported_p
27775 : :
27776 : : #undef TARGET_VECTOR_MODE_SUPPORTED_P
27777 : : #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
27778 : :
27779 : : #undef TARGET_C_MODE_FOR_SUFFIX
27780 : : #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
27781 : :
27782 : : #ifdef HAVE_AS_TLS
27783 : : #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
27784 : : #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
27785 : : #endif
27786 : :
27787 : : #ifdef SUBTARGET_INSERT_ATTRIBUTES
27788 : : #undef TARGET_INSERT_ATTRIBUTES
27789 : : #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
27790 : : #endif
27791 : :
27792 : : #undef TARGET_MANGLE_TYPE
27793 : : #define TARGET_MANGLE_TYPE ix86_mangle_type
27794 : :
27795 : : #undef TARGET_EMIT_SUPPORT_TINFOS
27796 : : #define TARGET_EMIT_SUPPORT_TINFOS ix86_emit_support_tinfos
27797 : :
27798 : : #undef TARGET_STACK_PROTECT_GUARD
27799 : : #define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
27800 : :
27801 : : #undef TARGET_STACK_PROTECT_RUNTIME_ENABLED_P
27802 : : #define TARGET_STACK_PROTECT_RUNTIME_ENABLED_P \
27803 : : ix86_stack_protect_runtime_enabled_p
27804 : :
27805 : : #if !TARGET_MACHO
27806 : : #undef TARGET_STACK_PROTECT_FAIL
27807 : : #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
27808 : : #endif
27809 : :
27810 : : #undef TARGET_FUNCTION_VALUE
27811 : : #define TARGET_FUNCTION_VALUE ix86_function_value
27812 : :
27813 : : #undef TARGET_FUNCTION_VALUE_REGNO_P
27814 : : #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
27815 : :
27816 : : #undef TARGET_ZERO_CALL_USED_REGS
27817 : : #define TARGET_ZERO_CALL_USED_REGS ix86_zero_call_used_regs
27818 : :
27819 : : #undef TARGET_PROMOTE_FUNCTION_MODE
27820 : : #define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
27821 : :
27822 : : #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
27823 : : #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE ix86_override_options_after_change
27824 : :
27825 : : #undef TARGET_MEMBER_TYPE_FORCES_BLK
27826 : : #define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk
27827 : :
27828 : : #undef TARGET_INSTANTIATE_DECLS
27829 : : #define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls
27830 : :
27831 : : #undef TARGET_SECONDARY_RELOAD
27832 : : #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
27833 : : #undef TARGET_SECONDARY_MEMORY_NEEDED
27834 : : #define TARGET_SECONDARY_MEMORY_NEEDED ix86_secondary_memory_needed
27835 : : #undef TARGET_SECONDARY_MEMORY_NEEDED_MODE
27836 : : #define TARGET_SECONDARY_MEMORY_NEEDED_MODE ix86_secondary_memory_needed_mode
27837 : :
27838 : : #undef TARGET_CLASS_MAX_NREGS
27839 : : #define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs
27840 : :
27841 : : #undef TARGET_PREFERRED_RELOAD_CLASS
27842 : : #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
27843 : : #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
27844 : : #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
27845 : : /* When this hook returns true for MODE, the compiler allows
27846 : : registers explicitly used in the rtl to be used as spill registers
27847 : : but prevents the compiler from extending the lifetime of these
27848 : : registers. */
27849 : : #undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P
27850 : : #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true
27851 : : #undef TARGET_CLASS_LIKELY_SPILLED_P
27852 : : #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
27853 : : #undef TARGET_CALLEE_SAVE_COST
27854 : : #define TARGET_CALLEE_SAVE_COST ix86_callee_save_cost
27855 : :
27856 : : #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
27857 : : #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
27858 : : ix86_builtin_vectorization_cost
27859 : : #undef TARGET_VECTORIZE_VEC_PERM_CONST
27860 : : #define TARGET_VECTORIZE_VEC_PERM_CONST ix86_vectorize_vec_perm_const
27861 : : #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
27862 : : #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
27863 : : ix86_preferred_simd_mode
27864 : : #undef TARGET_VECTORIZE_SPLIT_REDUCTION
27865 : : #define TARGET_VECTORIZE_SPLIT_REDUCTION \
27866 : : ix86_split_reduction
27867 : : #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES
27868 : : #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES \
27869 : : ix86_autovectorize_vector_modes
27870 : : #undef TARGET_VECTORIZE_GET_MASK_MODE
27871 : : #define TARGET_VECTORIZE_GET_MASK_MODE ix86_get_mask_mode
27872 : : #undef TARGET_VECTORIZE_CREATE_COSTS
27873 : : #define TARGET_VECTORIZE_CREATE_COSTS ix86_vectorize_create_costs
27874 : :
27875 : : #undef TARGET_SET_CURRENT_FUNCTION
27876 : : #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
27877 : :
27878 : : #undef TARGET_OPTION_VALID_ATTRIBUTE_P
27879 : : #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
27880 : :
27881 : : #undef TARGET_OPTION_SAVE
27882 : : #define TARGET_OPTION_SAVE ix86_function_specific_save
27883 : :
27884 : : #undef TARGET_OPTION_RESTORE
27885 : : #define TARGET_OPTION_RESTORE ix86_function_specific_restore
27886 : :
27887 : : #undef TARGET_OPTION_POST_STREAM_IN
27888 : : #define TARGET_OPTION_POST_STREAM_IN ix86_function_specific_post_stream_in
27889 : :
27890 : : #undef TARGET_OPTION_PRINT
27891 : : #define TARGET_OPTION_PRINT ix86_function_specific_print
27892 : :
27893 : : #undef TARGET_OPTION_FUNCTION_VERSIONS
27894 : : #define TARGET_OPTION_FUNCTION_VERSIONS common_function_versions
27895 : :
27896 : : #undef TARGET_CAN_INLINE_P
27897 : : #define TARGET_CAN_INLINE_P ix86_can_inline_p
27898 : :
27899 : : #undef TARGET_LEGITIMATE_ADDRESS_P
27900 : : #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
27901 : :
27902 : : #undef TARGET_REGISTER_PRIORITY
27903 : : #define TARGET_REGISTER_PRIORITY ix86_register_priority
27904 : :
27905 : : #undef TARGET_REGISTER_USAGE_LEVELING_P
27906 : : #define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true
27907 : :
27908 : : #undef TARGET_LEGITIMATE_CONSTANT_P
27909 : : #define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p
27910 : :
27911 : : #undef TARGET_COMPUTE_FRAME_LAYOUT
27912 : : #define TARGET_COMPUTE_FRAME_LAYOUT ix86_compute_frame_layout
27913 : :
27914 : : #undef TARGET_FRAME_POINTER_REQUIRED
27915 : : #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
27916 : :
27917 : : #undef TARGET_CAN_ELIMINATE
27918 : : #define TARGET_CAN_ELIMINATE ix86_can_eliminate
27919 : :
27920 : : #undef TARGET_EXTRA_LIVE_ON_ENTRY
27921 : : #define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry
27922 : :
27923 : : #undef TARGET_ASM_CODE_END
27924 : : #define TARGET_ASM_CODE_END ix86_code_end
27925 : :
27926 : : #undef TARGET_CONDITIONAL_REGISTER_USAGE
27927 : : #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
27928 : :
27929 : : #undef TARGET_CANONICALIZE_COMPARISON
27930 : : #define TARGET_CANONICALIZE_COMPARISON ix86_canonicalize_comparison
27931 : :
27932 : : #undef TARGET_LOOP_UNROLL_ADJUST
27933 : : #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust
27934 : :
27935 : : /* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657. */
27936 : : #undef TARGET_SPILL_CLASS
27937 : : #define TARGET_SPILL_CLASS ix86_spill_class
27938 : :
27939 : : #undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
27940 : : #define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
27941 : : ix86_simd_clone_compute_vecsize_and_simdlen
27942 : :
27943 : : #undef TARGET_SIMD_CLONE_ADJUST
27944 : : #define TARGET_SIMD_CLONE_ADJUST ix86_simd_clone_adjust
27945 : :
27946 : : #undef TARGET_SIMD_CLONE_USABLE
27947 : : #define TARGET_SIMD_CLONE_USABLE ix86_simd_clone_usable
27948 : :
27949 : : #undef TARGET_OMP_DEVICE_KIND_ARCH_ISA
27950 : : #define TARGET_OMP_DEVICE_KIND_ARCH_ISA ix86_omp_device_kind_arch_isa
27951 : :
27952 : : #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
27953 : : #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
27954 : : ix86_float_exceptions_rounding_supported_p
27955 : :
27956 : : #undef TARGET_MODE_EMIT
27957 : : #define TARGET_MODE_EMIT ix86_emit_mode_set
27958 : :
27959 : : #undef TARGET_MODE_NEEDED
27960 : : #define TARGET_MODE_NEEDED ix86_mode_needed
27961 : :
27962 : : #undef TARGET_MODE_AFTER
27963 : : #define TARGET_MODE_AFTER ix86_mode_after
27964 : :
27965 : : #undef TARGET_MODE_ENTRY
27966 : : #define TARGET_MODE_ENTRY ix86_mode_entry
27967 : :
27968 : : #undef TARGET_MODE_EXIT
27969 : : #define TARGET_MODE_EXIT ix86_mode_exit
27970 : :
27971 : : #undef TARGET_MODE_PRIORITY
27972 : : #define TARGET_MODE_PRIORITY ix86_mode_priority
27973 : :
27974 : : #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
27975 : : #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
27976 : :
27977 : : #undef TARGET_OFFLOAD_OPTIONS
27978 : : #define TARGET_OFFLOAD_OPTIONS \
27979 : : ix86_offload_options
27980 : :
27981 : : #undef TARGET_ABSOLUTE_BIGGEST_ALIGNMENT
27982 : : #define TARGET_ABSOLUTE_BIGGEST_ALIGNMENT 512
27983 : :
27984 : : #undef TARGET_OPTAB_SUPPORTED_P
27985 : : #define TARGET_OPTAB_SUPPORTED_P ix86_optab_supported_p
27986 : :
27987 : : #undef TARGET_HARD_REGNO_SCRATCH_OK
27988 : : #define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok
27989 : :
27990 : : #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
27991 : : #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS X86_CUSTOM_FUNCTION_TEST
27992 : :
27993 : : #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
27994 : : #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid
27995 : :
27996 : : #undef TARGET_INIT_LIBFUNCS
27997 : : #define TARGET_INIT_LIBFUNCS ix86_init_libfuncs
27998 : :
27999 : : #undef TARGET_EXPAND_DIVMOD_LIBFUNC
28000 : : #define TARGET_EXPAND_DIVMOD_LIBFUNC ix86_expand_divmod_libfunc
28001 : :
28002 : : #undef TARGET_MAX_NOCE_IFCVT_SEQ_COST
28003 : : #define TARGET_MAX_NOCE_IFCVT_SEQ_COST ix86_max_noce_ifcvt_seq_cost
28004 : :
28005 : : #undef TARGET_NOCE_CONVERSION_PROFITABLE_P
28006 : : #define TARGET_NOCE_CONVERSION_PROFITABLE_P ix86_noce_conversion_profitable_p
28007 : :
28008 : : #undef TARGET_HARD_REGNO_NREGS
28009 : : #define TARGET_HARD_REGNO_NREGS ix86_hard_regno_nregs
28010 : : #undef TARGET_HARD_REGNO_MODE_OK
28011 : : #define TARGET_HARD_REGNO_MODE_OK ix86_hard_regno_mode_ok
28012 : :
28013 : : #undef TARGET_MODES_TIEABLE_P
28014 : : #define TARGET_MODES_TIEABLE_P ix86_modes_tieable_p
28015 : :
28016 : : #undef TARGET_HARD_REGNO_CALL_PART_CLOBBERED
28017 : : #define TARGET_HARD_REGNO_CALL_PART_CLOBBERED \
28018 : : ix86_hard_regno_call_part_clobbered
28019 : :
28020 : : #undef TARGET_INSN_CALLEE_ABI
28021 : : #define TARGET_INSN_CALLEE_ABI ix86_insn_callee_abi
28022 : :
28023 : : #undef TARGET_CAN_CHANGE_MODE_CLASS
28024 : : #define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class
28025 : :
28026 : : #undef TARGET_LOWER_LOCAL_DECL_ALIGNMENT
28027 : : #define TARGET_LOWER_LOCAL_DECL_ALIGNMENT ix86_lower_local_decl_alignment
28028 : :
28029 : : #undef TARGET_STATIC_RTX_ALIGNMENT
28030 : : #define TARGET_STATIC_RTX_ALIGNMENT ix86_static_rtx_alignment
28031 : : #undef TARGET_CONSTANT_ALIGNMENT
28032 : : #define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment
28033 : :
28034 : : #undef TARGET_EMPTY_RECORD_P
28035 : : #define TARGET_EMPTY_RECORD_P ix86_is_empty_record
28036 : :
28037 : : #undef TARGET_WARN_PARAMETER_PASSING_ABI
28038 : : #define TARGET_WARN_PARAMETER_PASSING_ABI ix86_warn_parameter_passing_abi
28039 : :
28040 : : #undef TARGET_GET_MULTILIB_ABI_NAME
28041 : : #define TARGET_GET_MULTILIB_ABI_NAME \
28042 : : ix86_get_multilib_abi_name
28043 : :
28044 : : #undef TARGET_IFUNC_REF_LOCAL_OK
28045 : : #define TARGET_IFUNC_REF_LOCAL_OK ix86_ifunc_ref_local_ok
28046 : :
28047 : : #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
28048 : : # undef TARGET_ASM_RELOC_RW_MASK
28049 : : # define TARGET_ASM_RELOC_RW_MASK ix86_reloc_rw_mask
28050 : : #endif
28051 : :
28052 : : #undef TARGET_MEMTAG_CAN_TAG_ADDRESSES
28053 : : #define TARGET_MEMTAG_CAN_TAG_ADDRESSES ix86_memtag_can_tag_addresses
28054 : :
28055 : : #undef TARGET_MEMTAG_ADD_TAG
28056 : : #define TARGET_MEMTAG_ADD_TAG ix86_memtag_add_tag
28057 : :
28058 : : #undef TARGET_MEMTAG_SET_TAG
28059 : : #define TARGET_MEMTAG_SET_TAG ix86_memtag_set_tag
28060 : :
28061 : : #undef TARGET_MEMTAG_EXTRACT_TAG
28062 : : #define TARGET_MEMTAG_EXTRACT_TAG ix86_memtag_extract_tag
28063 : :
28064 : : #undef TARGET_MEMTAG_UNTAGGED_POINTER
28065 : : #define TARGET_MEMTAG_UNTAGGED_POINTER ix86_memtag_untagged_pointer
28066 : :
28067 : : #undef TARGET_MEMTAG_TAG_SIZE
28068 : : #define TARGET_MEMTAG_TAG_SIZE ix86_memtag_tag_size
28069 : :
28070 : : #undef TARGET_GEN_CCMP_FIRST
28071 : : #define TARGET_GEN_CCMP_FIRST ix86_gen_ccmp_first
28072 : :
28073 : : #undef TARGET_GEN_CCMP_NEXT
28074 : : #define TARGET_GEN_CCMP_NEXT ix86_gen_ccmp_next
28075 : :
28076 : : #undef TARGET_HAVE_CCMP
28077 : : #define TARGET_HAVE_CCMP ix86_have_ccmp
28078 : :
28079 : : #undef TARGET_MODE_CAN_TRANSFER_BITS
28080 : : #define TARGET_MODE_CAN_TRANSFER_BITS ix86_mode_can_transfer_bits
28081 : :
28082 : : #undef TARGET_REDZONE_CLOBBER
28083 : : #define TARGET_REDZONE_CLOBBER ix86_redzone_clobber
28084 : :
28085 : : static bool
28086 : 79989 : ix86_libc_has_fast_function (int fcode ATTRIBUTE_UNUSED)
28087 : : {
28088 : : #ifdef OPTION_GLIBC
28089 : 79989 : if (OPTION_GLIBC)
28090 : 79989 : return (built_in_function)fcode == BUILT_IN_MEMPCPY;
28091 : : else
28092 : : return false;
28093 : : #else
28094 : : return false;
28095 : : #endif
28096 : : }
28097 : :
28098 : : #undef TARGET_LIBC_HAS_FAST_FUNCTION
28099 : : #define TARGET_LIBC_HAS_FAST_FUNCTION ix86_libc_has_fast_function
28100 : :
28101 : : static unsigned
28102 : 76967 : ix86_libm_function_max_error (unsigned cfn, machine_mode mode,
28103 : : bool boundary_p)
28104 : : {
28105 : : #ifdef OPTION_GLIBC
28106 : 76967 : bool glibc_p = OPTION_GLIBC;
28107 : : #else
28108 : : bool glibc_p = false;
28109 : : #endif
28110 : 76967 : if (glibc_p)
28111 : : {
28112 : : /* If __FAST_MATH__ is defined, glibc provides libmvec. */
28113 : 76967 : unsigned int libmvec_ret = 0;
28114 : 76967 : if (!flag_trapping_math
28115 : 8244 : && flag_unsafe_math_optimizations
28116 : 3362 : && flag_finite_math_only
28117 : 3336 : && !flag_signed_zeros
28118 : 3336 : && !flag_errno_math)
28119 : 3336 : switch (cfn)
28120 : : {
28121 : 1388 : CASE_CFN_COS:
28122 : 1388 : CASE_CFN_COS_FN:
28123 : 1388 : CASE_CFN_SIN:
28124 : 1388 : CASE_CFN_SIN_FN:
28125 : 1388 : if (!boundary_p)
28126 : : {
28127 : : /* With non-default rounding modes, libmvec provides
28128 : : complete garbage in results. E.g.
28129 : : _ZGVcN8v_sinf for 1.40129846e-45f in FE_UPWARD
28130 : : returns 0.00333309174f rather than 1.40129846e-45f. */
28131 : 583 : if (flag_rounding_math)
28132 : : return ~0U;
28133 : : /* https://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html
28134 : : claims libmvec maximum error is 4ulps.
28135 : : My own random testing indicates 2ulps for SFmode and
28136 : : 0.5ulps for DFmode, but let's go with the 4ulps. */
28137 : : libmvec_ret = 4;
28138 : : }
28139 : : break;
28140 : : default:
28141 : : break;
28142 : : }
28143 : 76967 : unsigned int ret = glibc_linux_libm_function_max_error (cfn, mode,
28144 : : boundary_p);
28145 : 76967 : return MAX (ret, libmvec_ret);
28146 : : }
28147 : 0 : return default_libm_function_max_error (cfn, mode, boundary_p);
28148 : : }
28149 : :
28150 : : #undef TARGET_LIBM_FUNCTION_MAX_ERROR
28151 : : #define TARGET_LIBM_FUNCTION_MAX_ERROR ix86_libm_function_max_error
28152 : :
28153 : : #if TARGET_MACHO
28154 : : static bool
28155 : : ix86_cannot_copy_insn_p (rtx_insn *insn)
28156 : : {
28157 : : if (TARGET_64BIT)
28158 : : return false;
28159 : :
28160 : : rtx set = single_set (insn);
28161 : : if (set)
28162 : : {
28163 : : rtx src = SET_SRC (set);
28164 : : if (GET_CODE (src) == UNSPEC
28165 : : && XINT (src, 1) == UNSPEC_SET_GOT)
28166 : : return true;
28167 : : }
28168 : : return false;
28169 : : }
28170 : :
28171 : : #undef TARGET_CANNOT_COPY_INSN_P
28172 : : #define TARGET_CANNOT_COPY_INSN_P ix86_cannot_copy_insn_p
28173 : :
28174 : : #endif
28175 : :
28176 : : #if CHECKING_P
28177 : : #undef TARGET_RUN_TARGET_SELFTESTS
28178 : : #define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
28179 : : #endif /* #if CHECKING_P */
28180 : :
28181 : : #undef TARGET_DOCUMENTATION_NAME
28182 : : #define TARGET_DOCUMENTATION_NAME "x86"
28183 : :
28184 : : /* Implement TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS. */
28185 : : sbitmap
28186 : 718646 : ix86_get_separate_components (void)
28187 : : {
28188 : 718646 : HOST_WIDE_INT offset, to_allocate;
28189 : 718646 : sbitmap components = sbitmap_alloc (FIRST_PSEUDO_REGISTER);
28190 : 718646 : bitmap_clear (components);
28191 : 718646 : struct machine_function *m = cfun->machine;
28192 : :
28193 : 718646 : offset = m->frame.stack_pointer_offset;
28194 : 718646 : to_allocate = offset - m->frame.sse_reg_save_offset;
28195 : :
28196 : : /* Shrink wrap separate uses MOV, which means APX PPX cannot be used.
28197 : : Experiments show that APX PPX can speed up the prologue. If the function
28198 : : does not exit early during actual execution, then using APX PPX is faster.
28199 : : If the function always exits early during actual execution, then shrink
28200 : : wrap separate reduces the number of MOV (PUSH/POP) instructions actually
28201 : : executed, thus speeding up execution.
28202 : : foo:
28203 : : movl $1, %eax
28204 : : testq %rdi, %rdi
28205 : : jne.L60
28206 : : ret ---> early return.
28207 : : .L60:
28208 : : subq $88, %rsp ---> belong to prologue.
28209 : : xorl %eax, %eax
28210 : : movq %rbx, 40 (%rsp) ---> belong to prologue.
28211 : : movq 8 (%rdi), %rbx
28212 : : movq %rbp, 48 (%rsp) ---> belong to prologue.
28213 : : movq %rdi, %rbp
28214 : : testq %rbx, %rbx
28215 : : jne.L61
28216 : : movq 40 (%rsp), %rbx
28217 : : movq 48 (%rsp), %rbp
28218 : : addq $88, %rsp
28219 : : ret
28220 : : .L61:
28221 : : movq %r12, 56 (%rsp) ---> belong to prologue.
28222 : : movq %r13, 64 (%rsp) ---> belong to prologue.
28223 : : movq %r14, 72 (%rsp) ---> belong to prologue.
28224 : : ... ...
28225 : :
28226 : : Disable shrink wrap separate when PPX is enabled. */
28227 : 718646 : if ((TARGET_APX_PPX && !crtl->calls_eh_return)
28228 : 718192 : || cfun->machine->func_type != TYPE_NORMAL
28229 : : || TARGET_SEH
28230 : 718096 : || crtl->stack_realign_needed
28231 : 708798 : || m->call_ms2sysv)
28232 : : return components;
28233 : :
28234 : : /* Since shrink wrapping separate uses MOV instead of PUSH/POP.
28235 : : Disable shrink wrap separate when MOV is prohibited. */
28236 : 706876 : if (save_regs_using_push_pop (to_allocate))
28237 : : return components;
28238 : :
28239 : 32330985 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
28240 : 31983340 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
28241 : : {
28242 : : /* Skip registers with large offsets, where a pseudo may be needed. */
28243 : 611380 : if (IN_RANGE (offset, -0x8000, 0x7fff))
28244 : 610304 : bitmap_set_bit (components, regno);
28245 : 655633 : offset += UNITS_PER_WORD;
28246 : : }
28247 : :
28248 : : /* Don't mess with the following registers. */
28249 : 347645 : if (frame_pointer_needed)
28250 : 6301 : bitmap_clear_bit (components, HARD_FRAME_POINTER_REGNUM);
28251 : :
28252 : 347645 : if (crtl->drap_reg)
28253 : 131 : bitmap_clear_bit (components, REGNO (crtl->drap_reg));
28254 : :
28255 : 347645 : if (pic_offset_table_rtx)
28256 : 28982 : bitmap_clear_bit (components, REAL_PIC_OFFSET_TABLE_REGNUM);
28257 : :
28258 : : return components;
28259 : : }
28260 : :
28261 : : /* Implement TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB. */
28262 : : sbitmap
28263 : 9249197 : ix86_components_for_bb (basic_block bb)
28264 : : {
28265 : 9249197 : bitmap in = DF_LIVE_IN (bb);
28266 : 9249197 : bitmap gen = &DF_LIVE_BB_INFO (bb)->gen;
28267 : 9249197 : bitmap kill = &DF_LIVE_BB_INFO (bb)->kill;
28268 : :
28269 : 9249197 : sbitmap components = sbitmap_alloc (FIRST_PSEUDO_REGISTER);
28270 : 9249197 : bitmap_clear (components);
28271 : :
28272 : 9249197 : function_abi_aggregator callee_abis;
28273 : 9249197 : rtx_insn *insn;
28274 : 106925228 : FOR_BB_INSNS (bb, insn)
28275 : 97676031 : if (CALL_P (insn))
28276 : 3045954 : callee_abis.note_callee_abi (insn_callee_abi (insn));
28277 : 9249197 : HARD_REG_SET extra_caller_saves = callee_abis.caller_save_regs (*crtl->abi);
28278 : :
28279 : : /* GPRs are used in a bb if they are in the IN, GEN, or KILL sets. */
28280 : 860175321 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
28281 : 850926124 : if (!fixed_regs[regno]
28282 : 850926124 : && (TEST_HARD_REG_BIT (extra_caller_saves, regno)
28283 : 432382453 : || bitmap_bit_p (in, regno)
28284 : 407763658 : || bitmap_bit_p (gen, regno)
28285 : 395158167 : || bitmap_bit_p (kill, regno)))
28286 : 37488192 : bitmap_set_bit (components, regno);
28287 : :
28288 : 9249197 : return components;
28289 : : }
28290 : :
28291 : : /* Implement TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS. */
28292 : : void
28293 : 481831 : ix86_disqualify_components (sbitmap, edge, sbitmap, bool)
28294 : : {
28295 : : /* Nothing to do for x86. */
28296 : 481831 : }
28297 : :
28298 : : /* Implement TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS. */
28299 : : void
28300 : 164407 : ix86_emit_prologue_components (sbitmap components)
28301 : : {
28302 : 164407 : HOST_WIDE_INT cfa_offset;
28303 : 164407 : struct machine_function *m = cfun->machine;
28304 : :
28305 : 164407 : cfa_offset = m->frame.reg_save_offset + m->fs.sp_offset
28306 : 164407 : - m->frame.stack_pointer_offset;
28307 : 15289851 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
28308 : 15125444 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
28309 : : {
28310 : 723340 : if (bitmap_bit_p (components, regno))
28311 : 197339 : ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
28312 : 771573 : cfa_offset -= UNITS_PER_WORD;
28313 : : }
28314 : 164407 : }
28315 : :
28316 : : /* Implement TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS. */
28317 : : void
28318 : 151190 : ix86_emit_epilogue_components (sbitmap components)
28319 : : {
28320 : 151190 : HOST_WIDE_INT cfa_offset;
28321 : 151190 : struct machine_function *m = cfun->machine;
28322 : 151190 : cfa_offset = m->frame.reg_save_offset + m->fs.sp_offset
28323 : 151190 : - m->frame.stack_pointer_offset;
28324 : :
28325 : 14060670 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
28326 : 13909480 : if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
28327 : : {
28328 : 682084 : if (bitmap_bit_p (components, regno))
28329 : : {
28330 : 268919 : rtx reg = gen_rtx_REG (word_mode, regno);
28331 : 268919 : rtx mem;
28332 : 268919 : rtx_insn *insn;
28333 : :
28334 : 268919 : mem = choose_baseaddr (cfa_offset, NULL);
28335 : 268919 : mem = gen_frame_mem (word_mode, mem);
28336 : 268919 : insn = emit_move_insn (reg, mem);
28337 : :
28338 : 268919 : RTX_FRAME_RELATED_P (insn) = 1;
28339 : 268919 : add_reg_note (insn, REG_CFA_RESTORE, reg);
28340 : : }
28341 : 736308 : cfa_offset -= UNITS_PER_WORD;
28342 : : }
28343 : 151190 : }
28344 : :
28345 : : /* Implement TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS. */
28346 : : void
28347 : 45900 : ix86_set_handled_components (sbitmap components)
28348 : : {
28349 : 4268700 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
28350 : 4222800 : if (bitmap_bit_p (components, regno))
28351 : : {
28352 : 108251 : cfun->machine->reg_is_wrapped_separately[regno] = true;
28353 : 108251 : cfun->machine->use_fast_prologue_epilogue = true;
28354 : 108251 : cfun->machine->frame.save_regs_using_mov = true;
28355 : : }
28356 : 45900 : }
28357 : :
28358 : : #undef TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS
28359 : : #define TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS ix86_get_separate_components
28360 : : #undef TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB
28361 : : #define TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB ix86_components_for_bb
28362 : : #undef TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS
28363 : : #define TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS ix86_disqualify_components
28364 : : #undef TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS
28365 : : #define TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS \
28366 : : ix86_emit_prologue_components
28367 : : #undef TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS
28368 : : #define TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS \
28369 : : ix86_emit_epilogue_components
28370 : : #undef TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS
28371 : : #define TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS ix86_set_handled_components
28372 : :
28373 : : struct gcc_target targetm = TARGET_INITIALIZER;
28374 : :
28375 : : #include "gt-i386.h"
|