Branch data Line data Source code
1 : : /* Copyright (C) 1988-2025 Free Software Foundation, Inc.
2 : :
3 : : This file is part of GCC.
4 : :
5 : : GCC is free software; you can redistribute it and/or modify
6 : : it under the terms of the GNU General Public License as published by
7 : : the Free Software Foundation; either version 3, or (at your option)
8 : : any later version.
9 : :
10 : : GCC is distributed in the hope that it will be useful,
11 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : : GNU General Public License for more details.
14 : :
15 : : You should have received a copy of the GNU General Public License
16 : : along with GCC; see the file COPYING3. If not see
17 : : <http://www.gnu.org/licenses/>. */
18 : :
19 : : #define IN_TARGET_CODE 1
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "backend.h"
25 : : #include "rtl.h"
26 : : #include "tree.h"
27 : : #include "memmodel.h"
28 : : #include "gimple.h"
29 : : #include "cfghooks.h"
30 : : #include "cfgloop.h"
31 : : #include "df.h"
32 : : #include "tm_p.h"
33 : : #include "stringpool.h"
34 : : #include "expmed.h"
35 : : #include "optabs.h"
36 : : #include "regs.h"
37 : : #include "emit-rtl.h"
38 : : #include "recog.h"
39 : : #include "cgraph.h"
40 : : #include "diagnostic.h"
41 : : #include "cfgbuild.h"
42 : : #include "alias.h"
43 : : #include "fold-const.h"
44 : : #include "attribs.h"
45 : : #include "calls.h"
46 : : #include "stor-layout.h"
47 : : #include "varasm.h"
48 : : #include "output.h"
49 : : #include "insn-attr.h"
50 : : #include "flags.h"
51 : : #include "except.h"
52 : : #include "explow.h"
53 : : #include "expr.h"
54 : : #include "cfgrtl.h"
55 : : #include "common/common-target.h"
56 : : #include "langhooks.h"
57 : : #include "reload.h"
58 : : #include "gimplify.h"
59 : : #include "dwarf2.h"
60 : : #include "tm-constrs.h"
61 : : #include "cselib.h"
62 : : #include "sched-int.h"
63 : : #include "opts.h"
64 : : #include "tree-pass.h"
65 : : #include "context.h"
66 : : #include "pass_manager.h"
67 : : #include "target-globals.h"
68 : : #include "gimple-iterator.h"
69 : : #include "shrink-wrap.h"
70 : : #include "builtins.h"
71 : : #include "rtl-iter.h"
72 : : #include "tree-iterator.h"
73 : : #include "dbgcnt.h"
74 : : #include "case-cfn-macros.h"
75 : : #include "dojump.h"
76 : : #include "fold-const-call.h"
77 : : #include "tree-vrp.h"
78 : : #include "tree-ssanames.h"
79 : : #include "selftest.h"
80 : : #include "selftest-rtl.h"
81 : : #include "print-rtl.h"
82 : : #include "intl.h"
83 : : #include "ifcvt.h"
84 : : #include "symbol-summary.h"
85 : : #include "sreal.h"
86 : : #include "ipa-cp.h"
87 : : #include "ipa-prop.h"
88 : : #include "ipa-fnsummary.h"
89 : : #include "wide-int-bitmask.h"
90 : : #include "tree-vector-builder.h"
91 : : #include "debug.h"
92 : : #include "dwarf2out.h"
93 : : #include "i386-builtins.h"
94 : : #include "i386-features.h"
95 : : #include "i386-expand.h"
96 : :
97 : : const char * const xlogue_layout::STUB_BASE_NAMES[XLOGUE_STUB_COUNT] = {
98 : : "savms64",
99 : : "resms64",
100 : : "resms64x",
101 : : "savms64f",
102 : : "resms64f",
103 : : "resms64fx"
104 : : };
105 : :
106 : : const unsigned xlogue_layout::REG_ORDER[xlogue_layout::MAX_REGS] = {
107 : : /* The below offset values are where each register is stored for the layout
108 : : relative to incoming stack pointer. The value of each m_regs[].offset will
109 : : be relative to the incoming base pointer (rax or rsi) used by the stub.
110 : :
111 : : s_instances: 0 1 2 3
112 : : Offset: realigned or aligned + 8
113 : : Register aligned aligned + 8 aligned w/HFP w/HFP */
114 : : XMM15_REG, /* 0x10 0x18 0x10 0x18 */
115 : : XMM14_REG, /* 0x20 0x28 0x20 0x28 */
116 : : XMM13_REG, /* 0x30 0x38 0x30 0x38 */
117 : : XMM12_REG, /* 0x40 0x48 0x40 0x48 */
118 : : XMM11_REG, /* 0x50 0x58 0x50 0x58 */
119 : : XMM10_REG, /* 0x60 0x68 0x60 0x68 */
120 : : XMM9_REG, /* 0x70 0x78 0x70 0x78 */
121 : : XMM8_REG, /* 0x80 0x88 0x80 0x88 */
122 : : XMM7_REG, /* 0x90 0x98 0x90 0x98 */
123 : : XMM6_REG, /* 0xa0 0xa8 0xa0 0xa8 */
124 : : SI_REG, /* 0xa8 0xb0 0xa8 0xb0 */
125 : : DI_REG, /* 0xb0 0xb8 0xb0 0xb8 */
126 : : BX_REG, /* 0xb8 0xc0 0xb8 0xc0 */
127 : : BP_REG, /* 0xc0 0xc8 N/A N/A */
128 : : R12_REG, /* 0xc8 0xd0 0xc0 0xc8 */
129 : : R13_REG, /* 0xd0 0xd8 0xc8 0xd0 */
130 : : R14_REG, /* 0xd8 0xe0 0xd0 0xd8 */
131 : : R15_REG, /* 0xe0 0xe8 0xd8 0xe0 */
132 : : };
133 : :
134 : : /* Instantiate static const values. */
135 : : const HOST_WIDE_INT xlogue_layout::STUB_INDEX_OFFSET;
136 : : const unsigned xlogue_layout::MIN_REGS;
137 : : const unsigned xlogue_layout::MAX_REGS;
138 : : const unsigned xlogue_layout::MAX_EXTRA_REGS;
139 : : const unsigned xlogue_layout::VARIANT_COUNT;
140 : : const unsigned xlogue_layout::STUB_NAME_MAX_LEN;
141 : :
142 : : /* Initialize xlogue_layout::s_stub_names to zero. */
143 : : char xlogue_layout::s_stub_names[2][XLOGUE_STUB_COUNT][VARIANT_COUNT]
144 : : [STUB_NAME_MAX_LEN];
145 : :
146 : : /* Instantiates all xlogue_layout instances. */
147 : : const xlogue_layout xlogue_layout::s_instances[XLOGUE_SET_COUNT] = {
148 : : xlogue_layout (0, false),
149 : : xlogue_layout (8, false),
150 : : xlogue_layout (0, true),
151 : : xlogue_layout (8, true)
152 : : };
153 : :
154 : : /* Return an appropriate const instance of xlogue_layout based upon values
155 : : in cfun->machine and crtl. */
156 : : const class xlogue_layout &
157 : 49891 : xlogue_layout::get_instance ()
158 : : {
159 : 49891 : enum xlogue_stub_sets stub_set;
160 : 49891 : bool aligned_plus_8 = cfun->machine->call_ms2sysv_pad_in;
161 : :
162 : 49891 : if (stack_realign_fp)
163 : : stub_set = XLOGUE_SET_HFP_ALIGNED_OR_REALIGN;
164 : 40910 : else if (frame_pointer_needed)
165 : 25246 : stub_set = aligned_plus_8
166 : 31552 : ? XLOGUE_SET_HFP_ALIGNED_PLUS_8
167 : : : XLOGUE_SET_HFP_ALIGNED_OR_REALIGN;
168 : : else
169 : 9358 : stub_set = aligned_plus_8 ? XLOGUE_SET_ALIGNED_PLUS_8 : XLOGUE_SET_ALIGNED;
170 : :
171 : 49891 : return s_instances[stub_set];
172 : : }
173 : :
174 : : /* Determine how many clobbered registers can be saved by the stub.
175 : : Returns the count of registers the stub will save and restore. */
176 : : unsigned
177 : 35225 : xlogue_layout::count_stub_managed_regs ()
178 : : {
179 : 35225 : bool hfp = frame_pointer_needed || stack_realign_fp;
180 : 35225 : unsigned i, count;
181 : 35225 : unsigned regno;
182 : :
183 : 94890 : for (count = i = MIN_REGS; i < MAX_REGS; ++i)
184 : : {
185 : 93670 : regno = REG_ORDER[i];
186 : 93670 : if (regno == BP_REG && hfp)
187 : 18200 : continue;
188 : 75470 : if (!ix86_save_reg (regno, false, false))
189 : : break;
190 : 41465 : ++count;
191 : : }
192 : 35225 : return count;
193 : : }
194 : :
195 : : /* Determine if register REGNO is a stub managed register given the
196 : : total COUNT of stub managed registers. */
197 : : bool
198 : 2650688 : xlogue_layout::is_stub_managed_reg (unsigned regno, unsigned count)
199 : : {
200 : 2650688 : bool hfp = frame_pointer_needed || stack_realign_fp;
201 : 2650688 : unsigned i;
202 : :
203 : 34587805 : for (i = 0; i < count; ++i)
204 : : {
205 : 32436986 : gcc_assert (i < MAX_REGS);
206 : 32436986 : if (REG_ORDER[i] == BP_REG && hfp)
207 : 522627 : ++count;
208 : 31914359 : else if (REG_ORDER[i] == regno)
209 : : return true;
210 : : }
211 : : return false;
212 : : }
213 : :
214 : : /* Constructor for xlogue_layout. */
215 : 1134448 : xlogue_layout::xlogue_layout (HOST_WIDE_INT stack_align_off_in, bool hfp)
216 : 1134448 : : m_hfp (hfp) , m_nregs (hfp ? 17 : 18),
217 : 1134448 : m_stack_align_off_in (stack_align_off_in)
218 : : {
219 : 1134448 : HOST_WIDE_INT offset = stack_align_off_in;
220 : 1134448 : unsigned i, j;
221 : :
222 : 21554512 : for (i = j = 0; i < MAX_REGS; ++i)
223 : : {
224 : 20420064 : unsigned regno = REG_ORDER[i];
225 : :
226 : 20420064 : if (regno == BP_REG && hfp)
227 : 567224 : continue;
228 : 19852840 : if (SSE_REGNO_P (regno))
229 : : {
230 : 11344480 : offset += 16;
231 : : /* Verify that SSE regs are always aligned. */
232 : 11344480 : gcc_assert (!((stack_align_off_in + offset) & 15));
233 : : }
234 : : else
235 : 8508360 : offset += 8;
236 : :
237 : 19852840 : m_regs[j].regno = regno;
238 : 19852840 : m_regs[j++].offset = offset - STUB_INDEX_OFFSET;
239 : : }
240 : 1134448 : gcc_assert (j == m_nregs);
241 : 1134448 : }
242 : :
243 : : const char *
244 : 14666 : xlogue_layout::get_stub_name (enum xlogue_stub stub,
245 : : unsigned n_extra_regs)
246 : : {
247 : 14666 : const int have_avx = TARGET_AVX;
248 : 14666 : char *name = s_stub_names[!!have_avx][stub][n_extra_regs];
249 : :
250 : : /* Lazy init */
251 : 14666 : if (!*name)
252 : : {
253 : 362 : int res = snprintf (name, STUB_NAME_MAX_LEN, "__%s_%s_%u",
254 : : (have_avx ? "avx" : "sse"),
255 : 181 : STUB_BASE_NAMES[stub],
256 : : MIN_REGS + n_extra_regs);
257 : 181 : gcc_checking_assert (res < (int)STUB_NAME_MAX_LEN);
258 : : }
259 : :
260 : 14666 : return name;
261 : : }
262 : :
263 : : /* Return rtx of a symbol ref for the entry point (based upon
264 : : cfun->machine->call_ms2sysv_extra_regs) of the specified stub. */
265 : : rtx
266 : 14666 : xlogue_layout::get_stub_rtx (enum xlogue_stub stub)
267 : : {
268 : 14666 : const unsigned n_extra_regs = cfun->machine->call_ms2sysv_extra_regs;
269 : 14666 : gcc_checking_assert (n_extra_regs <= MAX_EXTRA_REGS);
270 : 14666 : gcc_assert (stub < XLOGUE_STUB_COUNT);
271 : 14666 : gcc_assert (crtl->stack_realign_finalized);
272 : :
273 : 14666 : return gen_rtx_SYMBOL_REF (Pmode, get_stub_name (stub, n_extra_regs));
274 : : }
275 : :
276 : : unsigned scalar_chain::max_id = 0;
277 : :
278 : : namespace {
279 : :
280 : : /* Initialize new chain. */
281 : :
282 : 6414443 : scalar_chain::scalar_chain (enum machine_mode smode_, enum machine_mode vmode_)
283 : : {
284 : 6414443 : smode = smode_;
285 : 6414443 : vmode = vmode_;
286 : :
287 : 6414443 : chain_id = ++max_id;
288 : :
289 : 6414443 : if (dump_file)
290 : 138 : fprintf (dump_file, "Created a new instruction chain #%d\n", chain_id);
291 : :
292 : 6414443 : bitmap_obstack_initialize (NULL);
293 : 6414443 : insns = BITMAP_ALLOC (NULL);
294 : 6414443 : defs = BITMAP_ALLOC (NULL);
295 : 6414443 : defs_conv = BITMAP_ALLOC (NULL);
296 : 6414443 : insns_conv = BITMAP_ALLOC (NULL);
297 : 6414443 : queue = NULL;
298 : :
299 : 6414443 : cost_sse_integer = 0;
300 : 6414443 : weighted_cost_sse_integer = 0 ;
301 : 6414443 : max_visits = x86_stv_max_visits;
302 : 6414443 : }
303 : :
304 : : /* Free chain's data. */
305 : :
306 : 6414443 : scalar_chain::~scalar_chain ()
307 : : {
308 : 6414443 : BITMAP_FREE (insns);
309 : 6414443 : BITMAP_FREE (defs);
310 : 6414443 : BITMAP_FREE (defs_conv);
311 : 6414443 : BITMAP_FREE (insns_conv);
312 : 6414443 : bitmap_obstack_release (NULL);
313 : 6414443 : }
314 : :
315 : : /* Add instruction into chains' queue. */
316 : :
317 : : void
318 : 7949710 : scalar_chain::add_to_queue (unsigned insn_uid)
319 : : {
320 : 7949710 : if (!bitmap_set_bit (queue, insn_uid))
321 : : return;
322 : :
323 : 6172644 : if (dump_file)
324 : 141 : fprintf (dump_file, " Adding insn %d into chain's #%d queue\n",
325 : : insn_uid, chain_id);
326 : : }
327 : :
328 : : /* For DImode conversion, mark register defined by DEF as requiring
329 : : conversion. */
330 : :
331 : : void
332 : 9398204 : scalar_chain::mark_dual_mode_def (df_ref def)
333 : : {
334 : 9398204 : gcc_assert (DF_REF_REG_DEF_P (def));
335 : :
336 : : /* Record the def/insn pair so we can later efficiently iterate over
337 : : the defs to convert on insns not in the chain. */
338 : 9398204 : bool reg_new = bitmap_set_bit (defs_conv, DF_REF_REGNO (def));
339 : 9398204 : basic_block bb = BLOCK_FOR_INSN (DF_REF_INSN (def));
340 : 9398204 : profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
341 : 9398204 : bool speed_p = optimize_bb_for_speed_p (bb);
342 : 9398204 : int cost = 0;
343 : :
344 : 9398204 : if (!bitmap_bit_p (insns, DF_REF_INSN_UID (def)))
345 : : {
346 : 2725522 : if (!bitmap_set_bit (insns_conv, DF_REF_INSN_UID (def))
347 : 2725522 : && !reg_new)
348 : 1373919 : return;
349 : :
350 : : /* Cost integer to sse moves. */
351 : 2482370 : if (speed_p)
352 : 2206859 : cost = COSTS_N_INSNS (ix86_cost->integer_to_sse) / 2;
353 : 275511 : else if (TARGET_64BIT || smode == SImode)
354 : : cost = COSTS_N_BYTES (4);
355 : : /* vmovd (4 bytes) + vpinsrd (6 bytes). */
356 : 18464 : else if (TARGET_SSE4_1)
357 : : cost = COSTS_N_BYTES (10);
358 : : /* movd (4 bytes) + movd (4 bytes) + unpckldq (4 bytes). */
359 : : else
360 : 8024285 : cost = COSTS_N_BYTES (12);
361 : : }
362 : : else
363 : : {
364 : 6672682 : if (!reg_new)
365 : : return;
366 : :
367 : : /* Cost sse to integer moves. */
368 : 5541915 : if (speed_p)
369 : 4991760 : cost = COSTS_N_INSNS (ix86_cost->sse_to_integer) / 2;
370 : 550155 : else if (TARGET_64BIT || smode == SImode)
371 : : cost = COSTS_N_BYTES (4);
372 : : /* vmovd (4 bytes) + vpextrd (6 bytes). */
373 : 2978 : else if (TARGET_SSE4_1)
374 : : cost = COSTS_N_BYTES (10);
375 : : /* movd (4 bytes) + psrlq (5 bytes) + movd (4 bytes). */
376 : : else
377 : 8024285 : cost = COSTS_N_BYTES (13);
378 : : }
379 : :
380 : 8024285 : if (speed_p)
381 : 7198619 : weighted_cost_sse_integer += bb->count.to_sreal_scale (entry_count) * cost;
382 : :
383 : 8024285 : cost_sse_integer += cost;
384 : :
385 : 8024285 : if (dump_file)
386 : 244 : fprintf (dump_file,
387 : : " Mark r%d def in insn %d as requiring both modes in chain #%d\n",
388 : 244 : DF_REF_REGNO (def), DF_REF_INSN_UID (def), chain_id);
389 : : }
390 : :
391 : : /* Check REF's chain to add new insns into a queue
392 : : and find registers requiring conversion. Return true if OK, false
393 : : if the analysis was aborted. */
394 : :
395 : : bool
396 : 17711227 : scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref,
397 : : bitmap disallowed)
398 : : {
399 : 17711227 : df_link *chain;
400 : 17711227 : bool mark_def = false;
401 : :
402 : 17711227 : gcc_checking_assert (bitmap_bit_p (insns, DF_REF_INSN_UID (ref)));
403 : :
404 : 60627762 : for (chain = DF_REF_CHAIN (ref); chain; chain = chain->next)
405 : : {
406 : 42917052 : unsigned uid = DF_REF_INSN_UID (chain->ref);
407 : :
408 : 42917052 : if (!NONDEBUG_INSN_P (DF_REF_INSN (chain->ref)))
409 : 7515726 : continue;
410 : :
411 : 35401326 : if (--max_visits == 0)
412 : : return false;
413 : :
414 : 35400809 : if (!DF_REF_REG_MEM_P (chain->ref))
415 : : {
416 : 29539748 : if (bitmap_bit_p (insns, uid))
417 : 9301164 : continue;
418 : :
419 : 20238584 : if (bitmap_bit_p (candidates, uid))
420 : : {
421 : 7949710 : add_to_queue (uid);
422 : 7949710 : continue;
423 : : }
424 : :
425 : : /* If we run into parts of an aborted chain discovery abort. */
426 : 12288874 : if (bitmap_bit_p (disallowed, uid))
427 : : return false;
428 : : }
429 : :
430 : 18149935 : if (DF_REF_REG_DEF_P (chain->ref))
431 : : {
432 : 2725522 : if (dump_file)
433 : 127 : fprintf (dump_file, " r%d def in insn %d isn't convertible\n",
434 : : DF_REF_REGNO (chain->ref), uid);
435 : 2725522 : mark_dual_mode_def (chain->ref);
436 : : }
437 : : else
438 : : {
439 : 15424413 : if (dump_file)
440 : 538 : fprintf (dump_file, " r%d use in insn %d isn't convertible\n",
441 : : DF_REF_REGNO (chain->ref), uid);
442 : : mark_def = true;
443 : : }
444 : : }
445 : :
446 : 17710710 : if (mark_def)
447 : 6672682 : mark_dual_mode_def (ref);
448 : :
449 : : return true;
450 : : }
451 : :
452 : : /* Add instruction into a chain. Return true if OK, false if the search
453 : : was aborted. */
454 : :
455 : : bool
456 : 12587087 : scalar_chain::add_insn (bitmap candidates, unsigned int insn_uid,
457 : : bitmap disallowed)
458 : : {
459 : 12587087 : if (!bitmap_set_bit (insns, insn_uid))
460 : : return true;
461 : :
462 : 12587087 : if (dump_file)
463 : 279 : fprintf (dump_file, " Adding insn %d to chain #%d\n", insn_uid, chain_id);
464 : :
465 : 12587087 : rtx_insn *insn = DF_INSN_UID_GET (insn_uid)->insn;
466 : 12587087 : rtx def_set = single_set (insn);
467 : 12587087 : if (def_set && REG_P (SET_DEST (def_set))
468 : 22314189 : && !HARD_REGISTER_P (SET_DEST (def_set)))
469 : 9727094 : bitmap_set_bit (defs, REGNO (SET_DEST (def_set)));
470 : :
471 : : /* ??? The following is quadratic since analyze_register_chain
472 : : iterates over all refs to look for dual-mode regs. Instead this
473 : : should be done separately for all regs mentioned in the chain once. */
474 : 12587087 : df_ref ref;
475 : 25685643 : for (ref = DF_INSN_UID_DEFS (insn_uid); ref; ref = DF_REF_NEXT_LOC (ref))
476 : 13099006 : if (!HARD_REGISTER_P (DF_REF_REG (ref)))
477 : 9727094 : if (!analyze_register_chain (candidates, ref, disallowed))
478 : : return false;
479 : :
480 : : /* The operand(s) of VEC_SELECT don't need to be converted/convertible. */
481 : 12586637 : if (def_set && GET_CODE (SET_SRC (def_set)) == VEC_SELECT)
482 : : return true;
483 : :
484 : 27481485 : for (ref = DF_INSN_UID_USES (insn_uid); ref; ref = DF_REF_NEXT_LOC (ref))
485 : 14929829 : if (!DF_REF_REG_MEM_P (ref))
486 : 7984133 : if (!analyze_register_chain (candidates, ref, disallowed))
487 : : return false;
488 : :
489 : : return true;
490 : : }
491 : :
492 : : /* Build new chain starting from insn INSN_UID recursively
493 : : adding all dependent uses and definitions. Return true if OK, false
494 : : if the chain discovery was aborted. */
495 : :
496 : : bool
497 : 6414443 : scalar_chain::build (bitmap candidates, unsigned insn_uid, bitmap disallowed)
498 : : {
499 : 6414443 : queue = BITMAP_ALLOC (NULL);
500 : 6414443 : bitmap_set_bit (queue, insn_uid);
501 : :
502 : 6414443 : if (dump_file)
503 : 138 : fprintf (dump_file, "Building chain #%d...\n", chain_id);
504 : :
505 : 19001013 : while (!bitmap_empty_p (queue))
506 : : {
507 : 12587087 : insn_uid = bitmap_first_set_bit (queue);
508 : 12587087 : bitmap_clear_bit (queue, insn_uid);
509 : 12587087 : bitmap_clear_bit (candidates, insn_uid);
510 : 12587087 : if (!add_insn (candidates, insn_uid, disallowed))
511 : : {
512 : : /* If we aborted the search put sofar found insn on the set of
513 : : disallowed insns so that further searches reaching them also
514 : : abort and thus we abort the whole but yet undiscovered chain. */
515 : 517 : bitmap_ior_into (disallowed, insns);
516 : 517 : if (dump_file)
517 : 0 : fprintf (dump_file, "Aborted chain #%d discovery\n", chain_id);
518 : 517 : BITMAP_FREE (queue);
519 : 517 : return false;
520 : : }
521 : : }
522 : :
523 : 6413926 : if (dump_file)
524 : : {
525 : 138 : fprintf (dump_file, "Collected chain #%d...\n", chain_id);
526 : 138 : fprintf (dump_file, " insns: ");
527 : 138 : dump_bitmap (dump_file, insns);
528 : 138 : if (!bitmap_empty_p (defs_conv))
529 : : {
530 : 138 : bitmap_iterator bi;
531 : 138 : unsigned id;
532 : 138 : const char *comma = "";
533 : 138 : fprintf (dump_file, " defs to convert: ");
534 : 372 : EXECUTE_IF_SET_IN_BITMAP (defs_conv, 0, id, bi)
535 : : {
536 : 234 : fprintf (dump_file, "%sr%d", comma, id);
537 : 234 : comma = ", ";
538 : : }
539 : 138 : fprintf (dump_file, "\n");
540 : : }
541 : : }
542 : :
543 : 6413926 : BITMAP_FREE (queue);
544 : :
545 : 6413926 : return true;
546 : : }
547 : :
548 : : /* Return a cost of building a vector costant
549 : : instead of using a scalar one. */
550 : :
551 : : int
552 : 2637930 : general_scalar_chain::vector_const_cost (rtx exp, basic_block bb)
553 : : {
554 : 2637930 : gcc_assert (CONST_INT_P (exp));
555 : :
556 : 2637930 : if (standard_sse_constant_p (exp, vmode))
557 : 614718 : return ix86_cost->sse_op;
558 : 2023212 : if (optimize_bb_for_size_p (bb))
559 : : return COSTS_N_BYTES (8);
560 : : /* We have separate costs for SImode and DImode, use SImode costs
561 : : for smaller modes. */
562 : 2433142 : return COSTS_N_INSNS (ix86_cost->sse_load[smode == DImode ? 1 : 0]) / 2;
563 : : }
564 : :
565 : : /* Return true if it's cost profitable for chain conversion. */
566 : :
567 : : bool
568 : 5958560 : general_scalar_chain::compute_convert_gain ()
569 : : {
570 : 5958560 : bitmap_iterator bi;
571 : 5958560 : unsigned insn_uid;
572 : 5958560 : int gain = 0;
573 : 5958560 : sreal weighted_gain = 0;
574 : :
575 : 5958560 : if (dump_file)
576 : 138 : fprintf (dump_file, "Computing gain for chain #%d...\n", chain_id);
577 : :
578 : : /* SSE costs distinguish between SImode and DImode loads/stores, for
579 : : int costs factor in the number of GPRs involved. When supporting
580 : : smaller modes than SImode the int load/store costs need to be
581 : : adjusted as well. */
582 : 5958560 : unsigned sse_cost_idx = smode == DImode ? 1 : 0;
583 : 5958560 : int m = smode == DImode ? (TARGET_64BIT ? 1 : 2) : 1;
584 : :
585 : 17643863 : EXECUTE_IF_SET_IN_BITMAP (insns, 0, insn_uid, bi)
586 : : {
587 : 11685303 : rtx_insn *insn = DF_INSN_UID_GET (insn_uid)->insn;
588 : 11685303 : rtx def_set = single_set (insn);
589 : 11685303 : rtx src = SET_SRC (def_set);
590 : 11685303 : rtx dst = SET_DEST (def_set);
591 : 11685303 : basic_block bb = BLOCK_FOR_INSN (insn);
592 : 11685303 : int igain = 0;
593 : 11685303 : profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
594 : 11685303 : bool speed_p = optimize_bb_for_speed_p (bb);
595 : 11685303 : sreal bb_freq = bb->count.to_sreal_scale (entry_count);
596 : :
597 : 11685303 : if (REG_P (src) && REG_P (dst))
598 : : {
599 : 949351 : if (!speed_p)
600 : : /* reg-reg move is 2 bytes, while SSE 3. */
601 : 200836 : igain += COSTS_N_BYTES (2 * m - 3);
602 : : else
603 : : /* Move costs are normalized to reg-reg move having cost 2. */
604 : 748515 : igain += COSTS_N_INSNS (2 * m - ix86_cost->xmm_move) / 2;
605 : : }
606 : 10735952 : else if (REG_P (src) && MEM_P (dst))
607 : : {
608 : 2301858 : if (!speed_p)
609 : : /* Integer load/store is 3+ bytes and SSE 4+. */
610 : 181222 : igain += COSTS_N_BYTES (3 * m - 4);
611 : : else
612 : 2120636 : igain
613 : 2120636 : += COSTS_N_INSNS (m * ix86_cost->int_store[2]
614 : : - ix86_cost->sse_store[sse_cost_idx]) / 2;
615 : : }
616 : 8434094 : else if (MEM_P (src) && REG_P (dst))
617 : : {
618 : 3845330 : if (!speed_p)
619 : 354460 : igain += COSTS_N_BYTES (3 * m - 4);
620 : : else
621 : 3490870 : igain += COSTS_N_INSNS (m * ix86_cost->int_load[2]
622 : : - ix86_cost->sse_load[sse_cost_idx]) / 2;
623 : : }
624 : : else
625 : : {
626 : : /* For operations on memory operands, include the overhead
627 : : of explicit load and store instructions. */
628 : 4588764 : if (MEM_P (dst))
629 : : {
630 : 63865 : if (!speed_p)
631 : : /* ??? This probably should account size difference
632 : : of SSE and integer load rather than full SSE load. */
633 : : igain -= COSTS_N_BYTES (8);
634 : : else
635 : : {
636 : 54769 : int cost = (m * (ix86_cost->int_load[2]
637 : 54769 : + ix86_cost->int_store[2])
638 : 54769 : - (ix86_cost->sse_load[sse_cost_idx] +
639 : 54769 : ix86_cost->sse_store[sse_cost_idx]));
640 : 54769 : igain += COSTS_N_INSNS (cost) / 2;
641 : : }
642 : : }
643 : :
644 : 4588764 : switch (GET_CODE (src))
645 : : {
646 : 477676 : case ASHIFT:
647 : 477676 : case ASHIFTRT:
648 : 477676 : case LSHIFTRT:
649 : 477676 : if (m == 2)
650 : : {
651 : 17087 : if (INTVAL (XEXP (src, 1)) >= 32)
652 : 11543 : igain += ix86_cost->add;
653 : : /* Gain for extend highpart case. */
654 : 5544 : else if (GET_CODE (XEXP (src, 0)) == ASHIFT)
655 : 0 : igain += ix86_cost->shift_const - ix86_cost->sse_op;
656 : : else
657 : 5544 : igain += ix86_cost->shift_const;
658 : : }
659 : :
660 : 477676 : igain += ix86_cost->shift_const - ix86_cost->sse_op;
661 : :
662 : 477676 : if (CONST_INT_P (XEXP (src, 0)))
663 : 0 : igain -= vector_const_cost (XEXP (src, 0), bb);
664 : : break;
665 : :
666 : 3755 : case ROTATE:
667 : 3755 : case ROTATERT:
668 : 3755 : igain += m * ix86_cost->shift_const;
669 : 3755 : if (TARGET_AVX512VL)
670 : 192 : igain -= ix86_cost->sse_op;
671 : 3563 : else if (smode == DImode)
672 : : {
673 : 569 : int bits = INTVAL (XEXP (src, 1));
674 : 569 : if ((bits & 0x0f) == 0)
675 : 105 : igain -= ix86_cost->sse_op;
676 : 464 : else if ((bits & 0x07) == 0)
677 : 27 : igain -= 2 * ix86_cost->sse_op;
678 : : else
679 : 437 : igain -= 3 * ix86_cost->sse_op;
680 : : }
681 : 2994 : else if (INTVAL (XEXP (src, 1)) == 16)
682 : 239 : igain -= ix86_cost->sse_op;
683 : : else
684 : 2755 : igain -= 2 * ix86_cost->sse_op;
685 : : break;
686 : :
687 : 2809705 : case AND:
688 : 2809705 : case IOR:
689 : 2809705 : case XOR:
690 : 2809705 : case PLUS:
691 : 2809705 : case MINUS:
692 : 2809705 : igain += m * ix86_cost->add - ix86_cost->sse_op;
693 : : /* Additional gain for andnot for targets without BMI. */
694 : 2809705 : if (GET_CODE (XEXP (src, 0)) == NOT
695 : 3599 : && !TARGET_BMI)
696 : 3590 : igain += m * ix86_cost->add;
697 : :
698 : 2809705 : if (CONST_INT_P (XEXP (src, 0)))
699 : 0 : igain -= vector_const_cost (XEXP (src, 0), bb);
700 : 2809705 : if (CONST_INT_P (XEXP (src, 1)))
701 : 1672738 : igain -= vector_const_cost (XEXP (src, 1), bb);
702 : 2809705 : if (MEM_P (XEXP (src, 1)))
703 : : {
704 : 100591 : if (!speed_p)
705 : 21037 : igain -= COSTS_N_BYTES (m == 2 ? 3 : 5);
706 : : else
707 : 90068 : igain += COSTS_N_INSNS
708 : : (m * ix86_cost->int_load[2]
709 : : - ix86_cost->sse_load[sse_cost_idx]) / 2;
710 : : }
711 : : break;
712 : :
713 : 51314 : case NEG:
714 : 51314 : case NOT:
715 : 51314 : igain -= ix86_cost->sse_op + COSTS_N_INSNS (1);
716 : :
717 : 51314 : if (GET_CODE (XEXP (src, 0)) != ABS)
718 : : {
719 : 51314 : igain += m * ix86_cost->add;
720 : 51314 : break;
721 : : }
722 : : /* FALLTHRU */
723 : :
724 : 992 : case ABS:
725 : 992 : case SMAX:
726 : 992 : case SMIN:
727 : 992 : case UMAX:
728 : 992 : case UMIN:
729 : : /* We do not have any conditional move cost, estimate it as a
730 : : reg-reg move. Comparisons are costed as adds. */
731 : 992 : igain += m * (COSTS_N_INSNS (2) + ix86_cost->add);
732 : : /* Integer SSE ops are all costed the same. */
733 : 992 : igain -= ix86_cost->sse_op;
734 : 992 : break;
735 : :
736 : 0 : case COMPARE:
737 : 0 : if (XEXP (src, 1) != const0_rtx)
738 : : {
739 : : /* cmp vs. pxor;pshufd;ptest. */
740 : 0 : igain += COSTS_N_INSNS (m - 3);
741 : : }
742 : 0 : else if (GET_CODE (XEXP (src, 0)) != AND)
743 : : {
744 : : /* test vs. pshufd;ptest. */
745 : 0 : igain += COSTS_N_INSNS (m - 2);
746 : : }
747 : 0 : else if (GET_CODE (XEXP (XEXP (src, 0), 0)) != NOT)
748 : : {
749 : : /* and;test vs. pshufd;ptest. */
750 : 0 : igain += COSTS_N_INSNS (2 * m - 2);
751 : : }
752 : 0 : else if (TARGET_BMI)
753 : : {
754 : : /* andn;test vs. pandn;pshufd;ptest. */
755 : 0 : igain += COSTS_N_INSNS (2 * m - 3);
756 : : }
757 : : else
758 : : {
759 : : /* not;and;test vs. pandn;pshufd;ptest. */
760 : 0 : igain += COSTS_N_INSNS (3 * m - 3);
761 : : }
762 : : break;
763 : :
764 : 1210408 : case CONST_INT:
765 : 1210408 : if (REG_P (dst))
766 : : {
767 : 1210408 : if (!speed_p)
768 : : {
769 : : /* xor (2 bytes) vs. xorps (3 bytes). */
770 : 245216 : if (src == const0_rtx)
771 : 140085 : igain -= COSTS_N_BYTES (1);
772 : : /* movdi_internal vs. movv2di_internal. */
773 : : /* => mov (5 bytes) vs. movaps (7 bytes). */
774 : 105131 : else if (x86_64_immediate_operand (src, SImode))
775 : 92844 : igain -= COSTS_N_BYTES (2);
776 : : else
777 : : /* ??? Larger immediate constants are placed in the
778 : : constant pool, where the size benefit/impact of
779 : : STV conversion is affected by whether and how
780 : : often each constant pool entry is shared/reused.
781 : : The value below is empirically derived from the
782 : : CSiBE benchmark (and the optimal value may drift
783 : : over time). */
784 : : igain += COSTS_N_BYTES (0);
785 : : }
786 : : else
787 : : {
788 : : /* DImode can be immediate for TARGET_64BIT
789 : : and SImode always. */
790 : 965192 : igain += m * COSTS_N_INSNS (1);
791 : 965192 : igain -= vector_const_cost (src, bb);
792 : : }
793 : : }
794 : 0 : else if (MEM_P (dst))
795 : : {
796 : 0 : igain += (m * ix86_cost->int_store[2]
797 : 0 : - ix86_cost->sse_store[sse_cost_idx]);
798 : 0 : igain -= vector_const_cost (src, bb);
799 : : }
800 : : break;
801 : :
802 : 34914 : case VEC_SELECT:
803 : 34914 : if (XVECEXP (XEXP (src, 1), 0, 0) == const0_rtx)
804 : : {
805 : : // movd (4 bytes) replaced with movdqa (4 bytes).
806 : 26746 : if (!!speed_p)
807 : 24043 : igain += COSTS_N_INSNS (ix86_cost->sse_to_integer
808 : : - ix86_cost->xmm_move) / 2;
809 : : }
810 : : else
811 : : {
812 : : // pshufd; movd replaced with pshufd.
813 : 8168 : if (!speed_p)
814 : 571 : igain += COSTS_N_BYTES (4);
815 : : else
816 : 7597 : igain += ix86_cost->sse_to_integer;
817 : : }
818 : : break;
819 : :
820 : 0 : default:
821 : 0 : gcc_unreachable ();
822 : : }
823 : : }
824 : :
825 : 11682600 : if (speed_p)
826 : 10424099 : weighted_gain += bb_freq * igain;
827 : 11685303 : gain += igain;
828 : :
829 : 11685303 : if (igain != 0 && dump_file)
830 : : {
831 : 95 : fprintf (dump_file, " Instruction gain %d with bb_freq %.2f for",
832 : : igain, bb_freq.to_double ());
833 : 95 : dump_insn_slim (dump_file, insn);
834 : : }
835 : : }
836 : :
837 : 5958560 : if (dump_file)
838 : : {
839 : 138 : fprintf (dump_file, " Instruction conversion gain: %d, \n",
840 : : gain);
841 : 138 : fprintf (dump_file, " Registers conversion cost: %d\n",
842 : : cost_sse_integer);
843 : 138 : fprintf (dump_file, " Weighted instruction conversion gain: %.2f, \n",
844 : : weighted_gain.to_double ());
845 : 138 : fprintf (dump_file, " Weighted registers conversion cost: %.2f\n",
846 : : weighted_cost_sse_integer.to_double ());
847 : : }
848 : :
849 : 5958560 : if (weighted_gain != weighted_cost_sse_integer)
850 : 4850708 : return weighted_gain > weighted_cost_sse_integer;
851 : : else
852 : 1107852 : return gain > cost_sse_integer;;
853 : : }
854 : :
855 : : /* Insert generated conversion instruction sequence INSNS
856 : : after instruction AFTER. New BB may be required in case
857 : : instruction has EH region attached. */
858 : :
859 : : void
860 : 29434 : scalar_chain::emit_conversion_insns (rtx insns, rtx_insn *after)
861 : : {
862 : 29434 : if (!control_flow_insn_p (after))
863 : : {
864 : 29266 : emit_insn_after (insns, after);
865 : 29266 : return;
866 : : }
867 : :
868 : 168 : basic_block bb = BLOCK_FOR_INSN (after);
869 : 168 : edge e = find_fallthru_edge (bb->succs);
870 : 168 : gcc_assert (e);
871 : :
872 : 168 : basic_block new_bb = split_edge (e);
873 : 168 : emit_insn_after (insns, BB_HEAD (new_bb));
874 : : }
875 : :
876 : : } // anon namespace
877 : :
878 : : /* Generate the canonical SET_SRC to move GPR to a VMODE vector register,
879 : : zeroing the upper parts. */
880 : :
881 : : static rtx
882 : 180016 : gen_gpr_to_xmm_move_src (enum machine_mode vmode, rtx gpr)
883 : : {
884 : 360032 : switch (GET_MODE_NUNITS (vmode))
885 : : {
886 : 12 : case 1:
887 : 12 : return gen_rtx_SUBREG (vmode, gpr, 0);
888 : 179533 : case 2:
889 : 359066 : return gen_rtx_VEC_CONCAT (vmode, gpr,
890 : : CONST0_RTX (GET_MODE_INNER (vmode)));
891 : 471 : default:
892 : 471 : return gen_rtx_VEC_MERGE (vmode, gen_rtx_VEC_DUPLICATE (vmode, gpr),
893 : : CONST0_RTX (vmode), GEN_INT (HOST_WIDE_INT_1U));
894 : : }
895 : : }
896 : :
897 : : /* Make vector copies for all register REGNO definitions
898 : : and replace its uses in a chain. */
899 : :
900 : : void
901 : 7889 : scalar_chain::make_vector_copies (rtx_insn *insn, rtx reg)
902 : : {
903 : 7889 : rtx vreg = *defs_map.get (reg);
904 : :
905 : 7889 : start_sequence ();
906 : 7889 : if (!TARGET_INTER_UNIT_MOVES_TO_VEC)
907 : : {
908 : 0 : rtx tmp = assign_386_stack_local (smode, SLOT_STV_TEMP);
909 : 0 : if (smode == DImode && !TARGET_64BIT)
910 : : {
911 : 0 : emit_move_insn (adjust_address (tmp, SImode, 0),
912 : : gen_rtx_SUBREG (SImode, reg, 0));
913 : 0 : emit_move_insn (adjust_address (tmp, SImode, 4),
914 : : gen_rtx_SUBREG (SImode, reg, 4));
915 : : }
916 : : else
917 : 0 : emit_move_insn (copy_rtx (tmp), reg);
918 : 0 : emit_insn (gen_rtx_SET (gen_rtx_SUBREG (vmode, vreg, 0),
919 : : gen_gpr_to_xmm_move_src (vmode, tmp)));
920 : : }
921 : 7889 : else if (!TARGET_64BIT && smode == DImode)
922 : : {
923 : 7841 : if (TARGET_SSE4_1)
924 : : {
925 : 356 : emit_insn (gen_sse2_loadld (gen_rtx_SUBREG (V4SImode, vreg, 0),
926 : : CONST0_RTX (V4SImode),
927 : : gen_rtx_SUBREG (SImode, reg, 0)));
928 : 356 : emit_insn (gen_sse4_1_pinsrd (gen_rtx_SUBREG (V4SImode, vreg, 0),
929 : : gen_rtx_SUBREG (V4SImode, vreg, 0),
930 : : gen_rtx_SUBREG (SImode, reg, 4),
931 : : GEN_INT (2)));
932 : : }
933 : : else
934 : : {
935 : 7485 : rtx tmp = gen_reg_rtx (DImode);
936 : 7485 : emit_insn (gen_sse2_loadld (gen_rtx_SUBREG (V4SImode, vreg, 0),
937 : : CONST0_RTX (V4SImode),
938 : : gen_rtx_SUBREG (SImode, reg, 0)));
939 : 7485 : emit_insn (gen_sse2_loadld (gen_rtx_SUBREG (V4SImode, tmp, 0),
940 : : CONST0_RTX (V4SImode),
941 : : gen_rtx_SUBREG (SImode, reg, 4)));
942 : 7485 : emit_insn (gen_vec_interleave_lowv4si
943 : : (gen_rtx_SUBREG (V4SImode, vreg, 0),
944 : : gen_rtx_SUBREG (V4SImode, vreg, 0),
945 : : gen_rtx_SUBREG (V4SImode, tmp, 0)));
946 : : }
947 : : }
948 : : else
949 : 48 : emit_insn (gen_rtx_SET (gen_rtx_SUBREG (vmode, vreg, 0),
950 : : gen_gpr_to_xmm_move_src (vmode, reg)));
951 : 7889 : rtx_insn *seq = end_sequence ();
952 : 7889 : emit_conversion_insns (seq, insn);
953 : :
954 : 7889 : if (dump_file)
955 : 0 : fprintf (dump_file,
956 : : " Copied r%d to a vector register r%d for insn %d\n",
957 : 0 : REGNO (reg), REGNO (vreg), INSN_UID (insn));
958 : 7889 : }
959 : :
960 : : /* Copy the definition SRC of INSN inside the chain to DST for
961 : : scalar uses outside of the chain. */
962 : :
963 : : void
964 : 20793 : scalar_chain::convert_reg (rtx_insn *insn, rtx dst, rtx src)
965 : : {
966 : 20793 : start_sequence ();
967 : 20793 : if (!TARGET_INTER_UNIT_MOVES_FROM_VEC)
968 : : {
969 : 0 : rtx tmp = assign_386_stack_local (smode, SLOT_STV_TEMP);
970 : 0 : emit_move_insn (tmp, src);
971 : 0 : if (!TARGET_64BIT && smode == DImode)
972 : : {
973 : 0 : emit_move_insn (gen_rtx_SUBREG (SImode, dst, 0),
974 : : adjust_address (tmp, SImode, 0));
975 : 0 : emit_move_insn (gen_rtx_SUBREG (SImode, dst, 4),
976 : : adjust_address (tmp, SImode, 4));
977 : : }
978 : : else
979 : 0 : emit_move_insn (dst, copy_rtx (tmp));
980 : : }
981 : 20793 : else if (!TARGET_64BIT && smode == DImode)
982 : : {
983 : 20421 : if (TARGET_SSE4_1)
984 : : {
985 : 0 : rtx tmp = gen_rtx_PARALLEL (VOIDmode,
986 : : gen_rtvec (1, const0_rtx));
987 : 0 : emit_insn
988 : 0 : (gen_rtx_SET
989 : : (gen_rtx_SUBREG (SImode, dst, 0),
990 : : gen_rtx_VEC_SELECT (SImode,
991 : : gen_rtx_SUBREG (V4SImode, src, 0),
992 : : tmp)));
993 : :
994 : 0 : tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const1_rtx));
995 : 0 : emit_insn
996 : 0 : (gen_rtx_SET
997 : : (gen_rtx_SUBREG (SImode, dst, 4),
998 : : gen_rtx_VEC_SELECT (SImode,
999 : : gen_rtx_SUBREG (V4SImode, src, 0),
1000 : : tmp)));
1001 : : }
1002 : : else
1003 : : {
1004 : 20421 : rtx vcopy = gen_reg_rtx (V2DImode);
1005 : 20421 : emit_move_insn (vcopy, gen_rtx_SUBREG (V2DImode, src, 0));
1006 : 20421 : emit_move_insn (gen_rtx_SUBREG (SImode, dst, 0),
1007 : : gen_rtx_SUBREG (SImode, vcopy, 0));
1008 : 20421 : emit_move_insn (vcopy,
1009 : : gen_rtx_LSHIFTRT (V2DImode,
1010 : : vcopy, GEN_INT (32)));
1011 : 20421 : emit_move_insn (gen_rtx_SUBREG (SImode, dst, 4),
1012 : : gen_rtx_SUBREG (SImode, vcopy, 0));
1013 : : }
1014 : : }
1015 : : else
1016 : 372 : emit_move_insn (dst, src);
1017 : :
1018 : 20793 : rtx_insn *seq = end_sequence ();
1019 : 20793 : emit_conversion_insns (seq, insn);
1020 : :
1021 : 20793 : if (dump_file)
1022 : 0 : fprintf (dump_file,
1023 : : " Copied r%d to a scalar register r%d for insn %d\n",
1024 : 0 : REGNO (src), REGNO (dst), INSN_UID (insn));
1025 : 20793 : }
1026 : :
1027 : : /* Helper function to convert immediate constant X to vmode. */
1028 : : static rtx
1029 : 44520 : smode_convert_cst (rtx x, enum machine_mode vmode)
1030 : : {
1031 : : /* Prefer all ones vector in case of -1. */
1032 : 44520 : if (constm1_operand (x, GET_MODE (x)))
1033 : 896 : return CONSTM1_RTX (vmode);
1034 : :
1035 : 43624 : unsigned n = GET_MODE_NUNITS (vmode);
1036 : 43624 : rtx *v = XALLOCAVEC (rtx, n);
1037 : 43624 : v[0] = x;
1038 : 49374 : for (unsigned i = 1; i < n; ++i)
1039 : 5750 : v[i] = const0_rtx;
1040 : 43624 : return gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (n, v));
1041 : : }
1042 : :
1043 : : /* Convert operand OP in INSN. We should handle
1044 : : memory operands and uninitialized registers.
1045 : : All other register uses are converted during
1046 : : registers conversion. */
1047 : :
1048 : : void
1049 : 252913 : scalar_chain::convert_op (rtx *op, rtx_insn *insn)
1050 : : {
1051 : 252913 : rtx tmp;
1052 : :
1053 : 252913 : if (GET_MODE (*op) == V1TImode)
1054 : : return;
1055 : :
1056 : 252886 : *op = copy_rtx_if_shared (*op);
1057 : :
1058 : 252886 : if (GET_CODE (*op) == NOT
1059 : 252886 : || GET_CODE (*op) == ASHIFT)
1060 : : {
1061 : 3490 : convert_op (&XEXP (*op, 0), insn);
1062 : 3490 : PUT_MODE (*op, vmode);
1063 : : }
1064 : : else if (MEM_P (*op))
1065 : : {
1066 : 179968 : rtx_insn *movabs = NULL;
1067 : :
1068 : : /* Emit MOVABS to load from a 64-bit absolute address to a GPR. */
1069 : 179968 : if (!memory_operand (*op, GET_MODE (*op)))
1070 : : {
1071 : 0 : tmp = gen_reg_rtx (GET_MODE (*op));
1072 : 0 : movabs = emit_insn_before (gen_rtx_SET (tmp, *op), insn);
1073 : :
1074 : 0 : *op = tmp;
1075 : : }
1076 : :
1077 : 179968 : tmp = gen_rtx_SUBREG (vmode, gen_reg_rtx (GET_MODE (*op)), 0);
1078 : :
1079 : 179968 : rtx_insn *eh_insn
1080 : 179968 : = emit_insn_before (gen_rtx_SET (copy_rtx (tmp),
1081 : : gen_gpr_to_xmm_move_src (vmode, *op)),
1082 : 179968 : insn);
1083 : :
1084 : 179968 : if (cfun->can_throw_non_call_exceptions)
1085 : : {
1086 : : /* Handle REG_EH_REGION note. */
1087 : 176027 : rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
1088 : 176027 : if (note)
1089 : : {
1090 : 4744 : if (movabs)
1091 : 0 : eh_insn = movabs;
1092 : 4744 : control_flow_insns.safe_push (eh_insn);
1093 : 4744 : add_reg_note (eh_insn, REG_EH_REGION, XEXP (note, 0));
1094 : : }
1095 : : }
1096 : :
1097 : 179968 : *op = tmp;
1098 : :
1099 : 179968 : if (dump_file)
1100 : 0 : fprintf (dump_file, " Preloading operand for insn %d into r%d\n",
1101 : 0 : INSN_UID (insn), reg_or_subregno (tmp));
1102 : : }
1103 : : else if (REG_P (*op))
1104 : 63005 : *op = gen_rtx_SUBREG (vmode, *op, 0);
1105 : : else if (CONST_SCALAR_INT_P (*op))
1106 : : {
1107 : 6423 : rtx vec_cst = smode_convert_cst (*op, vmode);
1108 : :
1109 : 6423 : if (!standard_sse_constant_p (vec_cst, vmode))
1110 : : {
1111 : 2715 : start_sequence ();
1112 : 2715 : vec_cst = validize_mem (force_const_mem (vmode, vec_cst));
1113 : 2715 : rtx_insn *seq = end_sequence ();
1114 : 2715 : emit_insn_before (seq, insn);
1115 : : }
1116 : :
1117 : 6423 : tmp = gen_rtx_SUBREG (vmode, gen_reg_rtx (smode), 0);
1118 : :
1119 : 6423 : emit_insn_before (gen_move_insn (copy_rtx (tmp), vec_cst), insn);
1120 : 6423 : *op = tmp;
1121 : : }
1122 : : else
1123 : : {
1124 : 0 : gcc_assert (SUBREG_P (*op));
1125 : 0 : gcc_assert (GET_MODE (*op) == vmode);
1126 : : }
1127 : : }
1128 : :
1129 : : /* Convert CCZmode COMPARE to vector mode. */
1130 : :
1131 : : rtx
1132 : 6 : scalar_chain::convert_compare (rtx op1, rtx op2, rtx_insn *insn)
1133 : : {
1134 : 6 : rtx src, tmp;
1135 : :
1136 : : /* Handle any REG_EQUAL notes. */
1137 : 6 : tmp = find_reg_equal_equiv_note (insn);
1138 : 6 : if (tmp)
1139 : : {
1140 : 1 : if (GET_CODE (XEXP (tmp, 0)) == COMPARE
1141 : 1 : && GET_MODE (XEXP (tmp, 0)) == CCZmode
1142 : 1 : && REG_P (XEXP (XEXP (tmp, 0), 0)))
1143 : : {
1144 : 1 : rtx *op = &XEXP (XEXP (tmp, 0), 1);
1145 : 1 : if (CONST_SCALAR_INT_P (*op))
1146 : : {
1147 : 1 : if (constm1_operand (*op, GET_MODE (*op)))
1148 : 0 : *op = CONSTM1_RTX (vmode);
1149 : : else
1150 : : {
1151 : 1 : unsigned n = GET_MODE_NUNITS (vmode);
1152 : 1 : rtx *v = XALLOCAVEC (rtx, n);
1153 : 1 : v[0] = *op;
1154 : 1 : for (unsigned i = 1; i < n; ++i)
1155 : 0 : v[i] = const0_rtx;
1156 : 1 : *op = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (n, v));
1157 : : }
1158 : : tmp = NULL_RTX;
1159 : : }
1160 : 0 : else if (REG_P (*op))
1161 : : tmp = NULL_RTX;
1162 : : }
1163 : :
1164 : : if (tmp)
1165 : 0 : remove_note (insn, tmp);
1166 : : }
1167 : :
1168 : : /* Comparison against anything other than zero, requires an XOR. */
1169 : 6 : if (op2 != const0_rtx)
1170 : : {
1171 : 4 : convert_op (&op1, insn);
1172 : 4 : convert_op (&op2, insn);
1173 : : /* If both operands are MEMs, explicitly load the OP1 into TMP. */
1174 : 4 : if (MEM_P (op1) && MEM_P (op2))
1175 : : {
1176 : 0 : tmp = gen_reg_rtx (vmode);
1177 : 0 : emit_insn_before (gen_rtx_SET (tmp, op1), insn);
1178 : 0 : src = tmp;
1179 : : }
1180 : : else
1181 : : src = op1;
1182 : 4 : src = gen_rtx_XOR (vmode, src, op2);
1183 : : }
1184 : 2 : else if (GET_CODE (op1) == AND
1185 : 0 : && GET_CODE (XEXP (op1, 0)) == NOT)
1186 : : {
1187 : 0 : rtx op11 = XEXP (XEXP (op1, 0), 0);
1188 : 0 : rtx op12 = XEXP (op1, 1);
1189 : 0 : convert_op (&op11, insn);
1190 : 0 : convert_op (&op12, insn);
1191 : 0 : if (!REG_P (op11))
1192 : : {
1193 : 0 : tmp = gen_reg_rtx (vmode);
1194 : 0 : emit_insn_before (gen_rtx_SET (tmp, op11), insn);
1195 : 0 : op11 = tmp;
1196 : : }
1197 : 0 : src = gen_rtx_AND (vmode, gen_rtx_NOT (vmode, op11), op12);
1198 : 0 : }
1199 : 2 : else if (GET_CODE (op1) == AND)
1200 : : {
1201 : 0 : rtx op11 = XEXP (op1, 0);
1202 : 0 : rtx op12 = XEXP (op1, 1);
1203 : 0 : convert_op (&op11, insn);
1204 : 0 : convert_op (&op12, insn);
1205 : 0 : if (!REG_P (op11))
1206 : : {
1207 : 0 : tmp = gen_reg_rtx (vmode);
1208 : 0 : emit_insn_before (gen_rtx_SET (tmp, op11), insn);
1209 : 0 : op11 = tmp;
1210 : : }
1211 : 0 : return gen_rtx_UNSPEC (CCZmode, gen_rtvec (2, op11, op12),
1212 : : UNSPEC_PTEST);
1213 : : }
1214 : : else
1215 : : {
1216 : 2 : convert_op (&op1, insn);
1217 : 2 : src = op1;
1218 : : }
1219 : :
1220 : 6 : if (!REG_P (src))
1221 : : {
1222 : 4 : tmp = gen_reg_rtx (vmode);
1223 : 4 : emit_insn_before (gen_rtx_SET (tmp, src), insn);
1224 : 4 : src = tmp;
1225 : : }
1226 : :
1227 : 6 : if (vmode == V2DImode)
1228 : : {
1229 : 0 : tmp = gen_reg_rtx (vmode);
1230 : 0 : emit_insn_before (gen_vec_interleave_lowv2di (tmp, src, src), insn);
1231 : 0 : src = tmp;
1232 : : }
1233 : 6 : else if (vmode == V4SImode)
1234 : : {
1235 : 0 : tmp = gen_reg_rtx (vmode);
1236 : 0 : emit_insn_before (gen_sse2_pshufd (tmp, src, const0_rtx), insn);
1237 : 0 : src = tmp;
1238 : : }
1239 : :
1240 : 6 : return gen_rtx_UNSPEC (CCZmode, gen_rtvec (2, src, src), UNSPEC_PTEST);
1241 : : }
1242 : :
1243 : : /* Helper function for converting INSN to vector mode. */
1244 : :
1245 : : void
1246 : 1324912 : scalar_chain::convert_insn_common (rtx_insn *insn)
1247 : : {
1248 : : /* Generate copies for out-of-chain uses of defs and adjust debug uses. */
1249 : 2016245 : for (df_ref ref = DF_INSN_DEFS (insn); ref; ref = DF_REF_NEXT_LOC (ref))
1250 : 691333 : if (bitmap_bit_p (defs_conv, DF_REF_REGNO (ref)))
1251 : : {
1252 : 22245 : df_link *use;
1253 : 42674 : for (use = DF_REF_CHAIN (ref); use; use = use->next)
1254 : 41222 : if (NONDEBUG_INSN_P (DF_REF_INSN (use->ref))
1255 : 41222 : && (DF_REF_REG_MEM_P (use->ref)
1256 : 36694 : || !bitmap_bit_p (insns, DF_REF_INSN_UID (use->ref))))
1257 : : break;
1258 : 22245 : if (use)
1259 : 20793 : convert_reg (insn, DF_REF_REG (ref),
1260 : 20793 : *defs_map.get (regno_reg_rtx [DF_REF_REGNO (ref)]));
1261 : 1452 : else if (MAY_HAVE_DEBUG_BIND_INSNS)
1262 : : {
1263 : : /* If we generated a scalar copy we can leave debug-insns
1264 : : as-is, if not, we have to adjust them. */
1265 : 1360 : auto_vec<rtx_insn *, 5> to_reset_debug_insns;
1266 : 4154 : for (use = DF_REF_CHAIN (ref); use; use = use->next)
1267 : 2794 : if (DEBUG_INSN_P (DF_REF_INSN (use->ref)))
1268 : : {
1269 : 895 : rtx_insn *debug_insn = DF_REF_INSN (use->ref);
1270 : : /* If there's a reaching definition outside of the
1271 : : chain we have to reset. */
1272 : 895 : df_link *def;
1273 : 3771 : for (def = DF_REF_CHAIN (use->ref); def; def = def->next)
1274 : 3087 : if (!bitmap_bit_p (insns, DF_REF_INSN_UID (def->ref)))
1275 : : break;
1276 : 895 : if (def)
1277 : 211 : to_reset_debug_insns.safe_push (debug_insn);
1278 : : else
1279 : : {
1280 : 684 : *DF_REF_REAL_LOC (use->ref)
1281 : 684 : = *defs_map.get (regno_reg_rtx [DF_REF_REGNO (ref)]);
1282 : 684 : df_insn_rescan (debug_insn);
1283 : : }
1284 : : }
1285 : : /* Have to do the reset outside of the DF_CHAIN walk to not
1286 : : disrupt it. */
1287 : 2931 : while (!to_reset_debug_insns.is_empty ())
1288 : : {
1289 : 211 : rtx_insn *debug_insn = to_reset_debug_insns.pop ();
1290 : 211 : INSN_VAR_LOCATION_LOC (debug_insn) = gen_rtx_UNKNOWN_VAR_LOC ();
1291 : 211 : df_insn_rescan_debug_internal (debug_insn);
1292 : : }
1293 : 1360 : }
1294 : : }
1295 : :
1296 : : /* Replace uses in this insn with the defs we use in the chain. */
1297 : 3306055 : for (df_ref ref = DF_INSN_USES (insn); ref; ref = DF_REF_NEXT_LOC (ref))
1298 : 1981143 : if (!DF_REF_REG_MEM_P (ref))
1299 : 712583 : if (rtx *vreg = defs_map.get (regno_reg_rtx[DF_REF_REGNO (ref)]))
1300 : : {
1301 : : /* Also update a corresponding REG_DEAD note. */
1302 : 33896 : rtx note = find_reg_note (insn, REG_DEAD, DF_REF_REG (ref));
1303 : 33896 : if (note)
1304 : 22453 : XEXP (note, 0) = *vreg;
1305 : 33896 : *DF_REF_REAL_LOC (ref) = *vreg;
1306 : : }
1307 : 1324912 : }
1308 : :
1309 : : /* Convert INSN which is an SImode or DImode rotation by a constant
1310 : : to vector mode. CODE is either ROTATE or ROTATERT with operands
1311 : : OP0 and OP1. Returns the SET_SRC of the last instruction in the
1312 : : resulting sequence, which is emitted before INSN. */
1313 : :
1314 : : rtx
1315 : 92 : general_scalar_chain::convert_rotate (enum rtx_code code, rtx op0, rtx op1,
1316 : : rtx_insn *insn)
1317 : : {
1318 : 92 : int bits = INTVAL (op1);
1319 : 92 : rtx pat, result;
1320 : :
1321 : 92 : convert_op (&op0, insn);
1322 : 92 : if (bits == 0)
1323 : 0 : return op0;
1324 : :
1325 : 92 : if (smode == DImode)
1326 : : {
1327 : 92 : if (code == ROTATE)
1328 : 45 : bits = 64 - bits;
1329 : 92 : if (bits == 32)
1330 : : {
1331 : 0 : rtx tmp1 = gen_reg_rtx (V4SImode);
1332 : 0 : pat = gen_sse2_pshufd (tmp1, gen_lowpart (V4SImode, op0),
1333 : : GEN_INT (225));
1334 : 0 : emit_insn_before (pat, insn);
1335 : 0 : result = gen_lowpart (V2DImode, tmp1);
1336 : : }
1337 : 92 : else if (TARGET_AVX512VL)
1338 : 0 : result = simplify_gen_binary (code, V2DImode, op0, op1);
1339 : 92 : else if (bits == 16 || bits == 48)
1340 : : {
1341 : 0 : rtx tmp1 = gen_reg_rtx (V8HImode);
1342 : 0 : pat = gen_sse2_pshuflw (tmp1, gen_lowpart (V8HImode, op0),
1343 : : GEN_INT (bits == 16 ? 57 : 147));
1344 : 0 : emit_insn_before (pat, insn);
1345 : 0 : result = gen_lowpart (V2DImode, tmp1);
1346 : : }
1347 : 92 : else if ((bits & 0x07) == 0)
1348 : : {
1349 : 0 : rtx tmp1 = gen_reg_rtx (V4SImode);
1350 : 0 : pat = gen_sse2_pshufd (tmp1, gen_lowpart (V4SImode, op0),
1351 : : GEN_INT (68));
1352 : 0 : emit_insn_before (pat, insn);
1353 : 0 : rtx tmp2 = gen_reg_rtx (V1TImode);
1354 : 0 : pat = gen_sse2_lshrv1ti3 (tmp2, gen_lowpart (V1TImode, tmp1),
1355 : : GEN_INT (bits));
1356 : 0 : emit_insn_before (pat, insn);
1357 : 0 : result = gen_lowpart (V2DImode, tmp2);
1358 : : }
1359 : : else
1360 : : {
1361 : 92 : rtx tmp1 = gen_reg_rtx (V4SImode);
1362 : 92 : pat = gen_sse2_pshufd (tmp1, gen_lowpart (V4SImode, op0),
1363 : : GEN_INT (20));
1364 : 92 : emit_insn_before (pat, insn);
1365 : 92 : rtx tmp2 = gen_reg_rtx (V2DImode);
1366 : 92 : pat = gen_lshrv2di3 (tmp2, gen_lowpart (V2DImode, tmp1),
1367 : : GEN_INT (bits & 31));
1368 : 92 : emit_insn_before (pat, insn);
1369 : 92 : rtx tmp3 = gen_reg_rtx (V4SImode);
1370 : 139 : pat = gen_sse2_pshufd (tmp3, gen_lowpart (V4SImode, tmp2),
1371 : : GEN_INT (bits > 32 ? 34 : 136));
1372 : 92 : emit_insn_before (pat, insn);
1373 : 92 : result = gen_lowpart (V2DImode, tmp3);
1374 : : }
1375 : : }
1376 : 0 : else if (bits == 16)
1377 : : {
1378 : 0 : rtx tmp1 = gen_reg_rtx (V8HImode);
1379 : 0 : pat = gen_sse2_pshuflw (tmp1, gen_lowpart (V8HImode, op0), GEN_INT (225));
1380 : 0 : emit_insn_before (pat, insn);
1381 : 0 : result = gen_lowpart (V4SImode, tmp1);
1382 : : }
1383 : 0 : else if (TARGET_AVX512VL)
1384 : 0 : result = simplify_gen_binary (code, V4SImode, op0, op1);
1385 : : else
1386 : : {
1387 : 0 : if (code == ROTATE)
1388 : 0 : bits = 32 - bits;
1389 : :
1390 : 0 : rtx tmp1 = gen_reg_rtx (V4SImode);
1391 : 0 : emit_insn_before (gen_sse2_pshufd (tmp1, op0, GEN_INT (224)), insn);
1392 : 0 : rtx tmp2 = gen_reg_rtx (V2DImode);
1393 : 0 : pat = gen_lshrv2di3 (tmp2, gen_lowpart (V2DImode, tmp1),
1394 : : GEN_INT (bits));
1395 : 0 : emit_insn_before (pat, insn);
1396 : 0 : result = gen_lowpart (V4SImode, tmp2);
1397 : : }
1398 : :
1399 : : return result;
1400 : : }
1401 : :
1402 : : /* Convert INSN to vector mode. */
1403 : :
1404 : : void
1405 : 423983 : general_scalar_chain::convert_insn (rtx_insn *insn)
1406 : : {
1407 : 423983 : rtx def_set = single_set (insn);
1408 : 423983 : rtx src = SET_SRC (def_set);
1409 : 423983 : rtx dst = SET_DEST (def_set);
1410 : 423983 : rtx subreg;
1411 : :
1412 : 423983 : if (MEM_P (dst) && !REG_P (src))
1413 : : {
1414 : : /* There are no scalar integer instructions and therefore
1415 : : temporary register usage is required. */
1416 : 752 : rtx tmp = gen_reg_rtx (smode);
1417 : 752 : emit_conversion_insns (gen_move_insn (dst, tmp), insn);
1418 : 752 : dst = gen_rtx_SUBREG (vmode, tmp, 0);
1419 : 752 : }
1420 : 423231 : else if (REG_P (dst) && GET_MODE (dst) == smode)
1421 : : {
1422 : : /* Replace the definition with a SUBREG to the definition we
1423 : : use inside the chain. */
1424 : 220814 : rtx *vdef = defs_map.get (dst);
1425 : 220814 : if (vdef)
1426 : 22245 : dst = *vdef;
1427 : 220814 : dst = gen_rtx_SUBREG (vmode, dst, 0);
1428 : : /* IRA doesn't like to have REG_EQUAL/EQUIV notes when the SET_DEST
1429 : : is a non-REG_P. So kill those off. */
1430 : 220814 : rtx note = find_reg_equal_equiv_note (insn);
1431 : 220814 : if (note)
1432 : 9306 : remove_note (insn, note);
1433 : : }
1434 : :
1435 : 423983 : switch (GET_CODE (src))
1436 : : {
1437 : 29345 : case PLUS:
1438 : 29345 : case MINUS:
1439 : 29345 : case IOR:
1440 : 29345 : case XOR:
1441 : 29345 : case AND:
1442 : 29345 : case SMAX:
1443 : 29345 : case SMIN:
1444 : 29345 : case UMAX:
1445 : 29345 : case UMIN:
1446 : 29345 : convert_op (&XEXP (src, 1), insn);
1447 : : /* FALLTHRU */
1448 : :
1449 : 36591 : case ABS:
1450 : 36591 : case ASHIFT:
1451 : 36591 : case ASHIFTRT:
1452 : 36591 : case LSHIFTRT:
1453 : 36591 : convert_op (&XEXP (src, 0), insn);
1454 : 36591 : PUT_MODE (src, vmode);
1455 : 36591 : break;
1456 : :
1457 : 92 : case ROTATE:
1458 : 92 : case ROTATERT:
1459 : 92 : src = convert_rotate (GET_CODE (src), XEXP (src, 0), XEXP (src, 1),
1460 : : insn);
1461 : 92 : break;
1462 : :
1463 : 399 : case NEG:
1464 : 399 : src = XEXP (src, 0);
1465 : :
1466 : 399 : if (GET_CODE (src) == ABS)
1467 : : {
1468 : 0 : src = XEXP (src, 0);
1469 : 0 : convert_op (&src, insn);
1470 : 0 : subreg = gen_reg_rtx (vmode);
1471 : 0 : emit_insn_before (gen_rtx_SET (subreg,
1472 : : gen_rtx_ABS (vmode, src)), insn);
1473 : 0 : src = subreg;
1474 : : }
1475 : : else
1476 : 399 : convert_op (&src, insn);
1477 : :
1478 : 399 : subreg = gen_reg_rtx (vmode);
1479 : 399 : emit_insn_before (gen_move_insn (subreg, CONST0_RTX (vmode)), insn);
1480 : 399 : src = gen_rtx_MINUS (vmode, subreg, src);
1481 : 399 : break;
1482 : :
1483 : 255 : case NOT:
1484 : 255 : src = XEXP (src, 0);
1485 : 255 : convert_op (&src, insn);
1486 : 255 : subreg = gen_reg_rtx (vmode);
1487 : 255 : emit_insn_before (gen_move_insn (subreg, CONSTM1_RTX (vmode)), insn);
1488 : 255 : src = gen_rtx_XOR (vmode, src, subreg);
1489 : 255 : break;
1490 : :
1491 : 177864 : case MEM:
1492 : 177864 : if (!REG_P (dst))
1493 : 177864 : convert_op (&src, insn);
1494 : : break;
1495 : :
1496 : 203826 : case REG:
1497 : 203826 : if (!MEM_P (dst))
1498 : 1409 : convert_op (&src, insn);
1499 : : break;
1500 : :
1501 : 0 : case SUBREG:
1502 : 0 : gcc_assert (GET_MODE (src) == vmode);
1503 : : break;
1504 : :
1505 : 0 : case COMPARE:
1506 : 0 : dst = gen_rtx_REG (CCZmode, FLAGS_REG);
1507 : 0 : src = convert_compare (XEXP (src, 0), XEXP (src, 1), insn);
1508 : 0 : break;
1509 : :
1510 : 3424 : case CONST_INT:
1511 : 3424 : convert_op (&src, insn);
1512 : 3424 : break;
1513 : :
1514 : 1532 : case VEC_SELECT:
1515 : 1532 : if (XVECEXP (XEXP (src, 1), 0, 0) == const0_rtx)
1516 : 1244 : src = XEXP (src, 0);
1517 : 288 : else if (smode == DImode)
1518 : : {
1519 : 144 : rtx tmp = gen_lowpart (V1TImode, XEXP (src, 0));
1520 : 144 : dst = gen_lowpart (V1TImode, dst);
1521 : 144 : src = gen_rtx_LSHIFTRT (V1TImode, tmp, GEN_INT (64));
1522 : : }
1523 : : else
1524 : : {
1525 : 144 : rtx tmp = XVECEXP (XEXP (src, 1), 0, 0);
1526 : 144 : rtvec vec = gen_rtvec (4, tmp, tmp, tmp, tmp);
1527 : 144 : rtx par = gen_rtx_PARALLEL (VOIDmode, vec);
1528 : 144 : src = gen_rtx_VEC_SELECT (vmode, XEXP (src, 0), par);
1529 : : }
1530 : : break;
1531 : :
1532 : 0 : default:
1533 : 0 : gcc_unreachable ();
1534 : : }
1535 : :
1536 : 423983 : SET_SRC (def_set) = src;
1537 : 423983 : SET_DEST (def_set) = dst;
1538 : :
1539 : : /* Drop possible dead definitions. */
1540 : 423983 : PATTERN (insn) = def_set;
1541 : :
1542 : 423983 : INSN_CODE (insn) = -1;
1543 : 423983 : int patt = recog_memoized (insn);
1544 : 423983 : if (patt == -1)
1545 : 0 : fatal_insn_not_found (insn);
1546 : 423983 : df_insn_rescan (insn);
1547 : 423983 : }
1548 : :
1549 : : /* Helper function to compute gain for loading an immediate constant.
1550 : : Typically, two movabsq for TImode vs. vmovdqa for V1TImode, but
1551 : : with numerous special cases. */
1552 : :
1553 : : static int
1554 : 5 : timode_immed_const_gain (rtx cst, basic_block bb)
1555 : : {
1556 : : /* movabsq vs. movabsq+vmovq+vunpacklqdq. */
1557 : 5 : if (CONST_WIDE_INT_P (cst)
1558 : 4 : && CONST_WIDE_INT_NUNITS (cst) == 2
1559 : 9 : && CONST_WIDE_INT_ELT (cst, 0) == CONST_WIDE_INT_ELT (cst, 1))
1560 : 0 : return optimize_bb_for_size_p (bb) ? -COSTS_N_BYTES (9)
1561 : : : -COSTS_N_INSNS (2);
1562 : : /* 2x movabsq ~ vmovdqa. */
1563 : : return 0;
1564 : : }
1565 : :
1566 : : /* Return true it's cost profitable for for chain conversion. */
1567 : :
1568 : : bool
1569 : 455366 : timode_scalar_chain::compute_convert_gain ()
1570 : : {
1571 : : /* Assume that if we have to move TImode values between units,
1572 : : then transforming this chain isn't worth it. */
1573 : 455366 : if (cost_sse_integer)
1574 : : return false;
1575 : :
1576 : 455366 : bitmap_iterator bi;
1577 : 455366 : unsigned insn_uid;
1578 : :
1579 : : /* Split ties to prefer V1TImode when not optimizing for size. */
1580 : 455366 : int gain = optimize_size ? 0 : 1;
1581 : 455366 : sreal weighted_gain = 0;
1582 : :
1583 : 455366 : if (dump_file)
1584 : 0 : fprintf (dump_file, "Computing gain for chain #%d...\n", chain_id);
1585 : :
1586 : 1356633 : EXECUTE_IF_SET_IN_BITMAP (insns, 0, insn_uid, bi)
1587 : : {
1588 : 901267 : rtx_insn *insn = DF_INSN_UID_GET (insn_uid)->insn;
1589 : 901267 : rtx def_set = single_set (insn);
1590 : 901267 : rtx src = SET_SRC (def_set);
1591 : 901267 : rtx dst = SET_DEST (def_set);
1592 : 901267 : HOST_WIDE_INT op1val;
1593 : 901267 : basic_block bb = BLOCK_FOR_INSN (insn);
1594 : 901267 : int scost, vcost;
1595 : 901267 : int igain = 0;
1596 : 901267 : profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
1597 : 901267 : bool speed_p = optimize_bb_for_speed_p (bb);
1598 : 901267 : sreal bb_freq = bb->count.to_sreal_scale (entry_count);
1599 : :
1600 : 901267 : switch (GET_CODE (src))
1601 : : {
1602 : 445648 : case REG:
1603 : 445648 : if (!speed_p)
1604 : 10719 : igain = MEM_P (dst) ? COSTS_N_BYTES (6) : COSTS_N_BYTES (3);
1605 : : else
1606 : : igain = COSTS_N_INSNS (1);
1607 : : break;
1608 : :
1609 : 405960 : case MEM:
1610 : 405960 : igain = !speed_p ? COSTS_N_BYTES (7) : COSTS_N_INSNS (1);
1611 : : break;
1612 : :
1613 : 11096 : case CONST_INT:
1614 : 11096 : if (MEM_P (dst)
1615 : 11096 : && standard_sse_constant_p (src, V1TImode))
1616 : 10543 : igain = !speed_p ? COSTS_N_BYTES (11) : 1;
1617 : : break;
1618 : :
1619 : 38292 : case CONST_WIDE_INT:
1620 : : /* 2 x mov vs. vmovdqa. */
1621 : 38292 : if (MEM_P (dst))
1622 : 38119 : igain = !speed_p ? COSTS_N_BYTES (3) : COSTS_N_INSNS (1);
1623 : : break;
1624 : :
1625 : 17 : case NOT:
1626 : 17 : if (MEM_P (dst))
1627 : 11712 : igain = -COSTS_N_INSNS (1);
1628 : : break;
1629 : :
1630 : 12 : case AND:
1631 : 12 : case XOR:
1632 : 12 : case IOR:
1633 : 12 : if (!MEM_P (dst))
1634 : 6 : igain = COSTS_N_INSNS (1);
1635 : 12 : if (CONST_SCALAR_INT_P (XEXP (src, 1)))
1636 : 5 : igain += timode_immed_const_gain (XEXP (src, 1), bb);
1637 : : break;
1638 : :
1639 : 126 : case ASHIFT:
1640 : 126 : case LSHIFTRT:
1641 : : /* See ix86_expand_v1ti_shift. */
1642 : 126 : op1val = INTVAL (XEXP (src, 1));
1643 : 126 : if (!speed_p)
1644 : : {
1645 : 10 : if (op1val == 64 || op1val == 65)
1646 : : scost = COSTS_N_BYTES (5);
1647 : 10 : else if (op1val >= 66)
1648 : : scost = COSTS_N_BYTES (6);
1649 : 10 : else if (op1val == 1)
1650 : : scost = COSTS_N_BYTES (8);
1651 : : else
1652 : : scost = COSTS_N_BYTES (9);
1653 : :
1654 : 9 : if ((op1val & 7) == 0)
1655 : : vcost = COSTS_N_BYTES (5);
1656 : 10 : else if (op1val > 64)
1657 : : vcost = COSTS_N_BYTES (10);
1658 : : else
1659 : 10 : vcost = TARGET_AVX ? COSTS_N_BYTES (19) : COSTS_N_BYTES (23);
1660 : : }
1661 : : else
1662 : : {
1663 : 116 : scost = COSTS_N_INSNS (2);
1664 : 116 : if ((op1val & 7) == 0)
1665 : : vcost = COSTS_N_INSNS (1);
1666 : 114 : else if (op1val > 64)
1667 : : vcost = COSTS_N_INSNS (2);
1668 : : else
1669 : 110 : vcost = TARGET_AVX ? COSTS_N_INSNS (4) : COSTS_N_INSNS (5);
1670 : : }
1671 : 126 : igain = scost - vcost;
1672 : 126 : break;
1673 : :
1674 : 103 : case ASHIFTRT:
1675 : : /* See ix86_expand_v1ti_ashiftrt. */
1676 : 103 : op1val = INTVAL (XEXP (src, 1));
1677 : 103 : if (!speed_p)
1678 : : {
1679 : 7 : if (op1val == 64 || op1val == 127)
1680 : : scost = COSTS_N_BYTES (7);
1681 : 7 : else if (op1val == 1)
1682 : : scost = COSTS_N_BYTES (8);
1683 : 7 : else if (op1val == 65)
1684 : : scost = COSTS_N_BYTES (10);
1685 : 7 : else if (op1val >= 66)
1686 : : scost = COSTS_N_BYTES (11);
1687 : : else
1688 : : scost = COSTS_N_BYTES (9);
1689 : :
1690 : 0 : if (op1val == 127)
1691 : : vcost = COSTS_N_BYTES (10);
1692 : 7 : else if (op1val == 64)
1693 : : vcost = COSTS_N_BYTES (14);
1694 : 7 : else if (op1val == 96)
1695 : : vcost = COSTS_N_BYTES (18);
1696 : 7 : else if (op1val >= 111)
1697 : : vcost = COSTS_N_BYTES (15);
1698 : 7 : else if (TARGET_AVX2 && op1val == 32)
1699 : : vcost = COSTS_N_BYTES (16);
1700 : 7 : else if (TARGET_SSE4_1 && op1val == 32)
1701 : : vcost = COSTS_N_BYTES (20);
1702 : 7 : else if (op1val >= 96)
1703 : : vcost = COSTS_N_BYTES (23);
1704 : 7 : else if ((op1val & 7) == 0)
1705 : : vcost = COSTS_N_BYTES (28);
1706 : 7 : else if (TARGET_AVX2 && op1val < 32)
1707 : : vcost = COSTS_N_BYTES (30);
1708 : 7 : else if (op1val == 1 || op1val >= 64)
1709 : : vcost = COSTS_N_BYTES (42);
1710 : : else
1711 : 7 : vcost = COSTS_N_BYTES (47);
1712 : : }
1713 : : else
1714 : : {
1715 : 96 : if (op1val >= 65 && op1val <= 126)
1716 : : scost = COSTS_N_INSNS (3);
1717 : : else
1718 : 96 : scost = COSTS_N_INSNS (2);
1719 : :
1720 : 96 : if (op1val == 127)
1721 : : vcost = COSTS_N_INSNS (2);
1722 : 96 : else if (op1val == 64)
1723 : : vcost = COSTS_N_INSNS (3);
1724 : 96 : else if (op1val == 96)
1725 : : vcost = COSTS_N_INSNS (3);
1726 : 96 : else if (op1val >= 111)
1727 : : vcost = COSTS_N_INSNS (3);
1728 : 96 : else if (TARGET_SSE4_1 && op1val == 32)
1729 : : vcost = COSTS_N_INSNS (3);
1730 : 96 : else if (TARGET_SSE4_1
1731 : 0 : && (op1val == 8 || op1val == 16 || op1val == 24))
1732 : : vcost = COSTS_N_INSNS (3);
1733 : 96 : else if (op1val >= 96)
1734 : : vcost = COSTS_N_INSNS (4);
1735 : 96 : else if (TARGET_SSE4_1 && (op1val == 28 || op1val == 80))
1736 : : vcost = COSTS_N_INSNS (4);
1737 : 96 : else if ((op1val & 7) == 0)
1738 : : vcost = COSTS_N_INSNS (5);
1739 : 96 : else if (TARGET_AVX2 && op1val < 32)
1740 : : vcost = COSTS_N_INSNS (6);
1741 : 96 : else if (TARGET_SSE4_1 && op1val < 15)
1742 : : vcost = COSTS_N_INSNS (6);
1743 : 96 : else if (op1val == 1 || op1val >= 64)
1744 : : vcost = COSTS_N_INSNS (8);
1745 : : else
1746 : 0 : vcost = COSTS_N_INSNS (9);
1747 : : }
1748 : 103 : igain = scost - vcost;
1749 : 103 : break;
1750 : :
1751 : 5 : case ROTATE:
1752 : 5 : case ROTATERT:
1753 : : /* See ix86_expand_v1ti_rotate. */
1754 : 5 : op1val = INTVAL (XEXP (src, 1));
1755 : 5 : if (!speed_p)
1756 : : {
1757 : 0 : scost = COSTS_N_BYTES (13);
1758 : 0 : if ((op1val & 31) == 0)
1759 : : vcost = COSTS_N_BYTES (5);
1760 : 0 : else if ((op1val & 7) == 0)
1761 : 0 : vcost = TARGET_AVX ? COSTS_N_BYTES (13) : COSTS_N_BYTES (18);
1762 : 0 : else if (op1val > 32 && op1val < 96)
1763 : : vcost = COSTS_N_BYTES (24);
1764 : : else
1765 : 0 : vcost = COSTS_N_BYTES (19);
1766 : : }
1767 : : else
1768 : : {
1769 : 5 : scost = COSTS_N_INSNS (3);
1770 : 5 : if ((op1val & 31) == 0)
1771 : : vcost = COSTS_N_INSNS (1);
1772 : 3 : else if ((op1val & 7) == 0)
1773 : 1 : vcost = TARGET_AVX ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4);
1774 : 2 : else if (op1val > 32 && op1val < 96)
1775 : : vcost = COSTS_N_INSNS (5);
1776 : : else
1777 : 2 : vcost = COSTS_N_INSNS (1);
1778 : : }
1779 : 5 : igain = scost - vcost;
1780 : 5 : break;
1781 : :
1782 : 8 : case COMPARE:
1783 : 8 : if (XEXP (src, 1) == const0_rtx)
1784 : : {
1785 : 4 : if (GET_CODE (XEXP (src, 0)) == AND)
1786 : : /* and;and;or (9 bytes) vs. ptest (5 bytes). */
1787 : : igain = !speed_p ? COSTS_N_BYTES (4) : COSTS_N_INSNS (2);
1788 : : /* or (3 bytes) vs. ptest (5 bytes). */
1789 : 4 : else if (!speed_p)
1790 : 0 : igain = -COSTS_N_BYTES (2);
1791 : : }
1792 : 4 : else if (XEXP (src, 1) == const1_rtx)
1793 : : /* and;cmp -1 (7 bytes) vs. pcmpeqd;pxor;ptest (13 bytes). */
1794 : 0 : igain = !speed_p ? -COSTS_N_BYTES (6) : -COSTS_N_INSNS (1);
1795 : : break;
1796 : :
1797 : : default:
1798 : : break;
1799 : : }
1800 : :
1801 : 1779499 : gain += igain;
1802 : 901263 : if (speed_p)
1803 : 878236 : weighted_gain += bb_freq * igain;
1804 : :
1805 : 901267 : if (igain != 0 && dump_file)
1806 : : {
1807 : 0 : fprintf (dump_file, " Instruction gain %d with bb_freq %.2f for ",
1808 : : igain, bb_freq.to_double ());
1809 : 0 : dump_insn_slim (dump_file, insn);
1810 : : }
1811 : : }
1812 : :
1813 : 455366 : if (dump_file)
1814 : 0 : fprintf (dump_file, " Total gain: %d, weighted gain %.2f\n",
1815 : : gain, weighted_gain.to_double ());
1816 : :
1817 : 455366 : if (weighted_gain > (sreal) 0)
1818 : : return true;
1819 : : else
1820 : 12888 : return gain > 0;
1821 : : }
1822 : :
1823 : : /* Fix uses of converted REG in debug insns. */
1824 : :
1825 : : void
1826 : 406791 : timode_scalar_chain::fix_debug_reg_uses (rtx reg)
1827 : : {
1828 : 406791 : if (!flag_var_tracking)
1829 : : return;
1830 : :
1831 : 359735 : df_ref ref, next;
1832 : 748651 : for (ref = DF_REG_USE_CHAIN (REGNO (reg)); ref; ref = next)
1833 : : {
1834 : 388916 : rtx_insn *insn = DF_REF_INSN (ref);
1835 : : /* Make sure the next ref is for a different instruction,
1836 : : so that we're not affected by the rescan. */
1837 : 388916 : next = DF_REF_NEXT_REG (ref);
1838 : 388916 : while (next && DF_REF_INSN (next) == insn)
1839 : 0 : next = DF_REF_NEXT_REG (next);
1840 : :
1841 : 388916 : if (DEBUG_INSN_P (insn))
1842 : : {
1843 : : /* It may be a debug insn with a TImode variable in
1844 : : register. */
1845 : : bool changed = false;
1846 : 30 : for (; ref != next; ref = DF_REF_NEXT_REG (ref))
1847 : : {
1848 : 15 : rtx *loc = DF_REF_LOC (ref);
1849 : 15 : if (REG_P (*loc) && GET_MODE (*loc) == V1TImode)
1850 : : {
1851 : 15 : *loc = gen_rtx_SUBREG (TImode, *loc, 0);
1852 : 15 : changed = true;
1853 : : }
1854 : : }
1855 : 15 : if (changed)
1856 : 15 : df_insn_rescan (insn);
1857 : : }
1858 : : }
1859 : : }
1860 : :
1861 : : /* Convert INSN from TImode to V1T1mode. */
1862 : :
1863 : : void
1864 : 900929 : timode_scalar_chain::convert_insn (rtx_insn *insn)
1865 : : {
1866 : 900929 : rtx def_set = single_set (insn);
1867 : 900929 : rtx src = SET_SRC (def_set);
1868 : 900929 : rtx dst = SET_DEST (def_set);
1869 : 900929 : rtx tmp;
1870 : :
1871 : 900929 : switch (GET_CODE (dst))
1872 : : {
1873 : 406797 : case REG:
1874 : 406797 : if (GET_MODE (dst) == TImode)
1875 : : {
1876 : 406229 : PUT_MODE (dst, V1TImode);
1877 : 406229 : fix_debug_reg_uses (dst);
1878 : : }
1879 : 406797 : if (GET_MODE (dst) == V1TImode)
1880 : : {
1881 : : /* It might potentially be helpful to convert REG_EQUAL notes,
1882 : : but for now we just remove them. */
1883 : 406791 : rtx note = find_reg_equal_equiv_note (insn);
1884 : 406791 : if (note)
1885 : 443 : remove_note (insn, note);
1886 : : }
1887 : : break;
1888 : 494132 : case MEM:
1889 : 494132 : PUT_MODE (dst, V1TImode);
1890 : 494132 : break;
1891 : :
1892 : 0 : default:
1893 : 0 : gcc_unreachable ();
1894 : : }
1895 : :
1896 : 900929 : switch (GET_CODE (src))
1897 : : {
1898 : 445602 : case REG:
1899 : 445602 : if (GET_MODE (src) == TImode)
1900 : : {
1901 : 562 : PUT_MODE (src, V1TImode);
1902 : 562 : fix_debug_reg_uses (src);
1903 : : }
1904 : : break;
1905 : :
1906 : 405912 : case MEM:
1907 : 405912 : PUT_MODE (src, V1TImode);
1908 : 405912 : break;
1909 : :
1910 : 38291 : case CONST_WIDE_INT:
1911 : 38291 : if (NONDEBUG_INSN_P (insn))
1912 : : {
1913 : : /* Since there are no instructions to store 128-bit constant,
1914 : : temporary register usage is required. */
1915 : 38291 : bool use_move;
1916 : 38291 : start_sequence ();
1917 : 38291 : tmp = ix86_convert_const_wide_int_to_broadcast (TImode, src);
1918 : 38291 : if (tmp)
1919 : : {
1920 : 194 : src = lowpart_subreg (V1TImode, tmp, TImode);
1921 : 194 : use_move = true;
1922 : : }
1923 : : else
1924 : : {
1925 : 38097 : src = smode_convert_cst (src, V1TImode);
1926 : 38097 : src = validize_mem (force_const_mem (V1TImode, src));
1927 : 38097 : use_move = MEM_P (dst);
1928 : : }
1929 : 38291 : rtx_insn *seq = end_sequence ();
1930 : 38291 : if (seq)
1931 : 195 : emit_insn_before (seq, insn);
1932 : 38291 : if (use_move)
1933 : : {
1934 : 38120 : tmp = gen_reg_rtx (V1TImode);
1935 : 38120 : emit_insn_before (gen_rtx_SET (tmp, src), insn);
1936 : 38120 : src = tmp;
1937 : : }
1938 : : }
1939 : : break;
1940 : :
1941 : 11095 : case CONST_INT:
1942 : 11095 : switch (standard_sse_constant_p (src, TImode))
1943 : : {
1944 : 10874 : case 1:
1945 : 10874 : src = CONST0_RTX (GET_MODE (dst));
1946 : 10874 : break;
1947 : 221 : case 2:
1948 : 221 : src = CONSTM1_RTX (GET_MODE (dst));
1949 : 221 : break;
1950 : 0 : default:
1951 : 0 : gcc_unreachable ();
1952 : : }
1953 : 11095 : if (MEM_P (dst))
1954 : : {
1955 : 10543 : tmp = gen_reg_rtx (V1TImode);
1956 : 10543 : emit_insn_before (gen_rtx_SET (tmp, src), insn);
1957 : 10543 : src = tmp;
1958 : : }
1959 : : break;
1960 : :
1961 : 8 : case AND:
1962 : 8 : if (GET_CODE (XEXP (src, 0)) == NOT)
1963 : : {
1964 : 0 : convert_op (&XEXP (XEXP (src, 0), 0), insn);
1965 : 0 : convert_op (&XEXP (src, 1), insn);
1966 : 0 : PUT_MODE (XEXP (src, 0), V1TImode);
1967 : 0 : PUT_MODE (src, V1TImode);
1968 : 0 : break;
1969 : : }
1970 : : /* FALLTHRU */
1971 : :
1972 : 11 : case XOR:
1973 : 11 : case IOR:
1974 : 11 : convert_op (&XEXP (src, 0), insn);
1975 : 11 : convert_op (&XEXP (src, 1), insn);
1976 : 11 : PUT_MODE (src, V1TImode);
1977 : 11 : if (MEM_P (dst))
1978 : : {
1979 : 5 : tmp = gen_reg_rtx (V1TImode);
1980 : 5 : emit_insn_before (gen_rtx_SET (tmp, src), insn);
1981 : 5 : src = tmp;
1982 : : }
1983 : : break;
1984 : :
1985 : 1 : case NOT:
1986 : 1 : src = XEXP (src, 0);
1987 : 1 : convert_op (&src, insn);
1988 : 1 : tmp = gen_reg_rtx (V1TImode);
1989 : 1 : emit_insn_before (gen_move_insn (tmp, CONSTM1_RTX (V1TImode)), insn);
1990 : 1 : src = gen_rtx_XOR (V1TImode, src, tmp);
1991 : 1 : if (MEM_P (dst))
1992 : : {
1993 : 0 : tmp = gen_reg_rtx (V1TImode);
1994 : 0 : emit_insn_before (gen_rtx_SET (tmp, src), insn);
1995 : 0 : src = tmp;
1996 : : }
1997 : : break;
1998 : :
1999 : 6 : case COMPARE:
2000 : 6 : dst = gen_rtx_REG (CCZmode, FLAGS_REG);
2001 : 6 : src = convert_compare (XEXP (src, 0), XEXP (src, 1), insn);
2002 : 6 : break;
2003 : :
2004 : 11 : case ASHIFT:
2005 : 11 : case LSHIFTRT:
2006 : 11 : case ASHIFTRT:
2007 : 11 : case ROTATERT:
2008 : 11 : case ROTATE:
2009 : 11 : convert_op (&XEXP (src, 0), insn);
2010 : 11 : PUT_MODE (src, V1TImode);
2011 : 11 : break;
2012 : :
2013 : 0 : default:
2014 : 0 : gcc_unreachable ();
2015 : : }
2016 : :
2017 : 900929 : SET_SRC (def_set) = src;
2018 : 900929 : SET_DEST (def_set) = dst;
2019 : :
2020 : : /* Drop possible dead definitions. */
2021 : 900929 : PATTERN (insn) = def_set;
2022 : :
2023 : 900929 : INSN_CODE (insn) = -1;
2024 : 900929 : recog_memoized (insn);
2025 : 900929 : df_insn_rescan (insn);
2026 : 900929 : }
2027 : :
2028 : : /* Generate copies from defs used by the chain but not defined therein.
2029 : : Also populates defs_map which is used later by convert_insn. */
2030 : :
2031 : : void
2032 : 634786 : scalar_chain::convert_registers ()
2033 : : {
2034 : 634786 : bitmap_iterator bi;
2035 : 634786 : unsigned id;
2036 : 659443 : EXECUTE_IF_SET_IN_BITMAP (defs_conv, 0, id, bi)
2037 : : {
2038 : 24657 : rtx chain_reg = gen_reg_rtx (smode);
2039 : 24657 : defs_map.put (regno_reg_rtx[id], chain_reg);
2040 : : }
2041 : 642675 : EXECUTE_IF_SET_IN_BITMAP (insns_conv, 0, id, bi)
2042 : 19846 : for (df_ref ref = DF_INSN_UID_DEFS (id); ref; ref = DF_REF_NEXT_LOC (ref))
2043 : 11957 : if (bitmap_bit_p (defs_conv, DF_REF_REGNO (ref)))
2044 : 7889 : make_vector_copies (DF_REF_INSN (ref), DF_REF_REAL_REG (ref));
2045 : 634786 : }
2046 : :
2047 : : /* Convert whole chain creating required register
2048 : : conversions and copies. */
2049 : :
2050 : : int
2051 : 634786 : scalar_chain::convert ()
2052 : : {
2053 : 634786 : bitmap_iterator bi;
2054 : 634786 : unsigned id;
2055 : 634786 : int converted_insns = 0;
2056 : :
2057 : 634786 : if (!dbg_cnt (stv_conversion))
2058 : : return 0;
2059 : :
2060 : 634786 : if (dump_file)
2061 : 0 : fprintf (dump_file, "Converting chain #%d...\n", chain_id);
2062 : :
2063 : 634786 : convert_registers ();
2064 : :
2065 : 1959698 : EXECUTE_IF_SET_IN_BITMAP (insns, 0, id, bi)
2066 : : {
2067 : 1324912 : rtx_insn *insn = DF_INSN_UID_GET (id)->insn;
2068 : 1324912 : convert_insn_common (insn);
2069 : 1324912 : convert_insn (insn);
2070 : 1324912 : converted_insns++;
2071 : : }
2072 : :
2073 : : return converted_insns;
2074 : : }
2075 : :
2076 : : /* Return the SET expression if INSN doesn't reference hard register.
2077 : : Return NULL if INSN uses or defines a hard register, excluding
2078 : : pseudo register pushes, hard register uses in a memory address,
2079 : : clobbers and flags definitions. */
2080 : :
2081 : : static rtx
2082 : 332409370 : pseudo_reg_set (rtx_insn *insn)
2083 : : {
2084 : 332409370 : rtx set = single_set (insn);
2085 : 332409370 : if (!set)
2086 : : return NULL;
2087 : :
2088 : : /* Check pseudo register push first. */
2089 : 135331571 : machine_mode mode = TARGET_64BIT ? TImode : DImode;
2090 : 135331571 : if (REG_P (SET_SRC (set))
2091 : 38264062 : && !HARD_REGISTER_P (SET_SRC (set))
2092 : 165190020 : && push_operand (SET_DEST (set), mode))
2093 : : return set;
2094 : :
2095 : 135078343 : df_ref ref;
2096 : 218975565 : FOR_EACH_INSN_DEF (ref, insn)
2097 : 120853544 : if (HARD_REGISTER_P (DF_REF_REAL_REG (ref))
2098 : 64709017 : && !DF_REF_FLAGS_IS_SET (ref, DF_REF_MUST_CLOBBER)
2099 : 171131067 : && DF_REF_REGNO (ref) != FLAGS_REG)
2100 : : return NULL;
2101 : :
2102 : 187482254 : FOR_EACH_INSN_USE (ref, insn)
2103 : 114685092 : if (!DF_REF_REG_MEM_P (ref) && HARD_REGISTER_P (DF_REF_REAL_REG (ref)))
2104 : : return NULL;
2105 : :
2106 : : return set;
2107 : : }
2108 : :
2109 : : /* Return true if the register REG is defined in a single DEF chain.
2110 : : If it is defined in more than one DEF chains, we may not be able
2111 : : to convert it in all chains. */
2112 : :
2113 : : static bool
2114 : 1145619 : single_def_chain_p (rtx reg)
2115 : : {
2116 : 1145619 : df_ref ref = DF_REG_DEF_CHAIN (REGNO (reg));
2117 : 1145619 : if (!ref)
2118 : : return false;
2119 : 1145604 : return DF_REF_NEXT_REG (ref) == nullptr;
2120 : : }
2121 : :
2122 : : /* Check if comparison INSN may be transformed into vector comparison.
2123 : : Currently we transform equality/inequality checks which look like:
2124 : : (set (reg:CCZ 17 flags) (compare:CCZ (reg:TI x) (reg:TI y))) */
2125 : :
2126 : : static bool
2127 : 12681511 : convertible_comparison_p (rtx_insn *insn, enum machine_mode mode)
2128 : : {
2129 : 14074413 : if (mode != (TARGET_64BIT ? TImode : DImode))
2130 : : return false;
2131 : :
2132 : 4639236 : if (!TARGET_SSE4_1)
2133 : : return false;
2134 : :
2135 : 156811 : rtx def_set = single_set (insn);
2136 : :
2137 : 156811 : gcc_assert (def_set);
2138 : :
2139 : 156811 : rtx src = SET_SRC (def_set);
2140 : 156811 : rtx dst = SET_DEST (def_set);
2141 : :
2142 : 156811 : gcc_assert (GET_CODE (src) == COMPARE);
2143 : :
2144 : 156811 : if (GET_CODE (dst) != REG
2145 : 156811 : || REGNO (dst) != FLAGS_REG
2146 : 313622 : || GET_MODE (dst) != CCZmode)
2147 : : return false;
2148 : :
2149 : 114671 : rtx op1 = XEXP (src, 0);
2150 : 114671 : rtx op2 = XEXP (src, 1);
2151 : :
2152 : : /* *cmp<dwi>_doubleword. */
2153 : 114671 : if ((CONST_SCALAR_INT_P (op1)
2154 : 114671 : || ((REG_P (op1) || MEM_P (op1))
2155 : 112944 : && GET_MODE (op1) == mode))
2156 : 49 : && (CONST_SCALAR_INT_P (op2)
2157 : 6 : || ((REG_P (op2) || MEM_P (op2))
2158 : 4 : && GET_MODE (op2) == mode)))
2159 : : return true;
2160 : :
2161 : : /* *testti_doubleword. */
2162 : 114624 : if (op2 == const0_rtx
2163 : 36520 : && GET_CODE (op1) == AND
2164 : 152 : && REG_P (XEXP (op1, 0)))
2165 : : {
2166 : 152 : rtx op12 = XEXP (op1, 1);
2167 : 152 : return GET_MODE (XEXP (op1, 0)) == TImode
2168 : 152 : && (CONST_SCALAR_INT_P (op12)
2169 : 0 : || ((REG_P (op12) || MEM_P (op12))
2170 : 0 : && GET_MODE (op12) == TImode));
2171 : : }
2172 : :
2173 : : /* *test<dwi>_not_doubleword. */
2174 : 114472 : if (op2 == const0_rtx
2175 : 36368 : && GET_CODE (op1) == AND
2176 : 0 : && GET_CODE (XEXP (op1, 0)) == NOT)
2177 : : {
2178 : 0 : rtx op11 = XEXP (XEXP (op1, 0), 0);
2179 : 0 : rtx op12 = XEXP (op1, 1);
2180 : 0 : return (REG_P (op11) || MEM_P (op11))
2181 : 0 : && (REG_P (op12) || MEM_P (op12))
2182 : 0 : && GET_MODE (op11) == mode
2183 : 0 : && GET_MODE (op12) == mode;
2184 : : }
2185 : :
2186 : : return false;
2187 : : }
2188 : :
2189 : : /* The general version of scalar_to_vector_candidate_p. */
2190 : :
2191 : : static bool
2192 : 232544520 : general_scalar_to_vector_candidate_p (rtx_insn *insn, enum machine_mode mode)
2193 : : {
2194 : 232544520 : rtx def_set = pseudo_reg_set (insn);
2195 : :
2196 : 232544520 : if (!def_set)
2197 : : return false;
2198 : :
2199 : 49470298 : rtx src = SET_SRC (def_set);
2200 : 49470298 : rtx dst = SET_DEST (def_set);
2201 : :
2202 : 49470298 : if (GET_CODE (src) == COMPARE)
2203 : 8738726 : return convertible_comparison_p (insn, mode);
2204 : :
2205 : : /* We are interested in "mode" only. */
2206 : 40731572 : if ((GET_MODE (src) != mode
2207 : 27839997 : && !CONST_INT_P (src))
2208 : 18096758 : || GET_MODE (dst) != mode)
2209 : : return false;
2210 : :
2211 : 15146877 : if (!REG_P (dst) && !MEM_P (dst))
2212 : : return false;
2213 : :
2214 : 14915583 : switch (GET_CODE (src))
2215 : : {
2216 : 526626 : case ASHIFT:
2217 : 526626 : case LSHIFTRT:
2218 : 526626 : case ASHIFTRT:
2219 : 526626 : case ROTATE:
2220 : 526626 : case ROTATERT:
2221 : 526626 : if (!CONST_INT_P (XEXP (src, 1))
2222 : 1017633 : || !IN_RANGE (INTVAL (XEXP (src, 1)), 0, GET_MODE_BITSIZE (mode)-1))
2223 : : return false;
2224 : :
2225 : : /* Check for extend highpart case. */
2226 : 491003 : if (mode != DImode
2227 : 345611 : || GET_CODE (src) != ASHIFTRT
2228 : 77839 : || GET_CODE (XEXP (src, 0)) != ASHIFT)
2229 : : break;
2230 : :
2231 : 3642848 : src = XEXP (src, 0);
2232 : : break;
2233 : :
2234 : 68552 : case SMAX:
2235 : 68552 : case SMIN:
2236 : 68552 : case UMAX:
2237 : 68552 : case UMIN:
2238 : 68552 : if ((mode == DImode && !TARGET_AVX512VL)
2239 : 17201 : || (mode == SImode && !TARGET_SSE4_1))
2240 : : return false;
2241 : : /* Fallthru. */
2242 : :
2243 : 3198453 : case AND:
2244 : 3198453 : case IOR:
2245 : 3198453 : case XOR:
2246 : 3198453 : case PLUS:
2247 : 3198453 : case MINUS:
2248 : 3198453 : if (!REG_P (XEXP (src, 1))
2249 : : && !MEM_P (XEXP (src, 1))
2250 : : && !CONST_INT_P (XEXP (src, 1)))
2251 : : return false;
2252 : :
2253 : 3098805 : if (GET_MODE (XEXP (src, 1)) != mode
2254 : 1810926 : && !CONST_INT_P (XEXP (src, 1)))
2255 : : return false;
2256 : :
2257 : : /* Check for andnot case. */
2258 : 3098805 : if (GET_CODE (src) != AND
2259 : 188391 : || GET_CODE (XEXP (src, 0)) != NOT)
2260 : : break;
2261 : :
2262 : 3642848 : src = XEXP (src, 0);
2263 : : /* FALLTHRU */
2264 : :
2265 : : case NOT:
2266 : : break;
2267 : :
2268 : 26048 : case NEG:
2269 : : /* Check for nabs case. */
2270 : 26048 : if (GET_CODE (XEXP (src, 0)) != ABS)
2271 : : break;
2272 : :
2273 : : src = XEXP (src, 0);
2274 : : /* FALLTHRU */
2275 : :
2276 : 2800 : case ABS:
2277 : 2800 : if ((mode == DImode && !TARGET_AVX512VL)
2278 : 1113 : || (mode == SImode && !TARGET_SSSE3))
2279 : : return false;
2280 : : break;
2281 : :
2282 : : case REG:
2283 : : return true;
2284 : :
2285 : 6053311 : case MEM:
2286 : 6053311 : case CONST_INT:
2287 : 6053311 : return REG_P (dst);
2288 : :
2289 : 54130 : case VEC_SELECT:
2290 : : /* Excluding MEM_P (dst) avoids intefering with vpextr[dq]. */
2291 : 54130 : return REG_P (dst)
2292 : 43818 : && REG_P (XEXP (src, 0))
2293 : 50781 : && GET_MODE (XEXP (src, 0)) == (mode == DImode ? V2DImode
2294 : : : V4SImode)
2295 : 34914 : && GET_CODE (XEXP (src, 1)) == PARALLEL
2296 : 34914 : && XVECLEN (XEXP (src, 1), 0) == 1
2297 : 89044 : && CONST_INT_P (XVECEXP (XEXP (src, 1), 0, 0));
2298 : :
2299 : : default:
2300 : : return false;
2301 : : }
2302 : :
2303 : 3642848 : if (!REG_P (XEXP (src, 0))
2304 : : && !MEM_P (XEXP (src, 0))
2305 : : && !CONST_INT_P (XEXP (src, 0)))
2306 : : return false;
2307 : :
2308 : 3343695 : if (GET_MODE (XEXP (src, 0)) != mode
2309 : 0 : && !CONST_INT_P (XEXP (src, 0)))
2310 : : return false;
2311 : :
2312 : : return true;
2313 : : }
2314 : :
2315 : : /* Check for a suitable TImode memory operand. */
2316 : :
2317 : : static bool
2318 : 13185 : timode_mem_p (rtx x)
2319 : : {
2320 : 13185 : return MEM_P (x)
2321 : 13185 : && (TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
2322 : 0 : || !misaligned_operand (x, TImode));
2323 : : }
2324 : :
2325 : : /* The TImode version of scalar_to_vector_candidate_p. */
2326 : :
2327 : : static bool
2328 : 99864850 : timode_scalar_to_vector_candidate_p (rtx_insn *insn)
2329 : : {
2330 : 99864850 : rtx def_set = pseudo_reg_set (insn);
2331 : :
2332 : 99864850 : if (!def_set)
2333 : : return false;
2334 : :
2335 : 23580092 : rtx src = SET_SRC (def_set);
2336 : 23580092 : rtx dst = SET_DEST (def_set);
2337 : :
2338 : 23580092 : if (GET_CODE (src) == COMPARE)
2339 : 3942785 : return convertible_comparison_p (insn, TImode);
2340 : :
2341 : 19637307 : if (GET_MODE (dst) != TImode
2342 : 1197330 : || (GET_MODE (src) != TImode
2343 : 66387 : && !CONST_SCALAR_INT_P (src)))
2344 : : return false;
2345 : :
2346 : 1197330 : if (!REG_P (dst) && !MEM_P (dst))
2347 : : return false;
2348 : :
2349 : 1195879 : if (MEM_P (dst)
2350 : 534904 : && misaligned_operand (dst, TImode)
2351 : 1469391 : && !TARGET_SSE_UNALIGNED_STORE_OPTIMAL)
2352 : : return false;
2353 : :
2354 : 1195874 : if (REG_P (dst) && !single_def_chain_p (dst))
2355 : : return false;
2356 : :
2357 : 1034287 : switch (GET_CODE (src))
2358 : : {
2359 : 484644 : case REG:
2360 : 484644 : return single_def_chain_p (src);
2361 : :
2362 : : case CONST_WIDE_INT:
2363 : : return true;
2364 : :
2365 : 13047 : case CONST_INT:
2366 : : /* ??? Verify performance impact before enabling CONST_INT for
2367 : : __int128 store. */
2368 : 13047 : return standard_sse_constant_p (src, TImode);
2369 : :
2370 : 428849 : case MEM:
2371 : : /* Memory must be aligned or unaligned load is optimal. */
2372 : 428849 : return (REG_P (dst)
2373 : 428849 : && (!misaligned_operand (src, TImode)
2374 : 122736 : || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL));
2375 : :
2376 : 4762 : case AND:
2377 : 4762 : if (!MEM_P (dst)
2378 : 4726 : && GET_CODE (XEXP (src, 0)) == NOT
2379 : 0 : && REG_P (XEXP (XEXP (src, 0), 0))
2380 : 4762 : && (REG_P (XEXP (src, 1))
2381 : 0 : || CONST_SCALAR_INT_P (XEXP (src, 1))
2382 : 0 : || timode_mem_p (XEXP (src, 1))))
2383 : 0 : return true;
2384 : 4762 : return (REG_P (XEXP (src, 0))
2385 : 41 : || timode_mem_p (XEXP (src, 0)))
2386 : 4803 : && (REG_P (XEXP (src, 1))
2387 : 2915 : || CONST_SCALAR_INT_P (XEXP (src, 1))
2388 : 35 : || timode_mem_p (XEXP (src, 1)));
2389 : :
2390 : 14337 : case IOR:
2391 : 14337 : case XOR:
2392 : 14337 : return (REG_P (XEXP (src, 0))
2393 : 13062 : || timode_mem_p (XEXP (src, 0)))
2394 : 14345 : && (REG_P (XEXP (src, 1))
2395 : 267 : || CONST_SCALAR_INT_P (XEXP (src, 1))
2396 : 31 : || timode_mem_p (XEXP (src, 1)));
2397 : :
2398 : 631 : case NOT:
2399 : 631 : return REG_P (XEXP (src, 0)) || timode_mem_p (XEXP (src, 0));
2400 : :
2401 : 13029 : case ASHIFT:
2402 : 13029 : case LSHIFTRT:
2403 : 13029 : case ASHIFTRT:
2404 : 13029 : case ROTATERT:
2405 : 13029 : case ROTATE:
2406 : : /* Handle shifts/rotates by integer constants between 0 and 127. */
2407 : 13029 : return REG_P (XEXP (src, 0))
2408 : 12993 : && CONST_INT_P (XEXP (src, 1))
2409 : 25675 : && (INTVAL (XEXP (src, 1)) & ~0x7f) == 0;
2410 : :
2411 : : default:
2412 : : return false;
2413 : : }
2414 : : }
2415 : :
2416 : : /* For a register REGNO, scan instructions for its defs and uses.
2417 : : Put REGNO in REGS if a def or use isn't in CANDIDATES. */
2418 : :
2419 : : static void
2420 : 1255988 : timode_check_non_convertible_regs (bitmap candidates, bitmap regs,
2421 : : unsigned int regno)
2422 : : {
2423 : : /* Do nothing if REGNO is already in REGS or is a hard reg. */
2424 : 1255988 : if (bitmap_bit_p (regs, regno)
2425 : 1255988 : || HARD_REGISTER_NUM_P (regno))
2426 : : return;
2427 : :
2428 : 1241641 : for (df_ref def = DF_REG_DEF_CHAIN (regno);
2429 : 2451741 : def;
2430 : 1210100 : def = DF_REF_NEXT_REG (def))
2431 : : {
2432 : 1241621 : if (!bitmap_bit_p (candidates, DF_REF_INSN_UID (def)))
2433 : : {
2434 : 31521 : if (dump_file)
2435 : 0 : fprintf (dump_file,
2436 : : "r%d has non convertible def in insn %d\n",
2437 : 0 : regno, DF_REF_INSN_UID (def));
2438 : :
2439 : 31521 : bitmap_set_bit (regs, regno);
2440 : 31521 : break;
2441 : : }
2442 : : }
2443 : :
2444 : 1241641 : for (df_ref ref = DF_REG_USE_CHAIN (regno);
2445 : 2811014 : ref;
2446 : 1569373 : ref = DF_REF_NEXT_REG (ref))
2447 : : {
2448 : : /* Debug instructions are skipped. */
2449 : 1626434 : if (NONDEBUG_INSN_P (DF_REF_INSN (ref))
2450 : 1626434 : && !bitmap_bit_p (candidates, DF_REF_INSN_UID (ref)))
2451 : : {
2452 : 57061 : if (dump_file)
2453 : 0 : fprintf (dump_file,
2454 : : "r%d has non convertible use in insn %d\n",
2455 : 0 : regno, DF_REF_INSN_UID (ref));
2456 : :
2457 : 57061 : bitmap_set_bit (regs, regno);
2458 : 57061 : break;
2459 : : }
2460 : : }
2461 : : }
2462 : :
2463 : : /* For a given bitmap of insn UIDs scans all instructions and
2464 : : remove insn from CANDIDATES in case it has both convertible
2465 : : and not convertible definitions.
2466 : :
2467 : : All insns in a bitmap are conversion candidates according to
2468 : : scalar_to_vector_candidate_p. Currently it implies all insns
2469 : : are single_set. */
2470 : :
2471 : : static void
2472 : 819387 : timode_remove_non_convertible_regs (bitmap candidates)
2473 : : {
2474 : 819387 : bitmap_iterator bi;
2475 : 819387 : unsigned id;
2476 : 819387 : bitmap regs = BITMAP_ALLOC (NULL);
2477 : 843891 : bool changed;
2478 : :
2479 : 843891 : do {
2480 : 843891 : changed = false;
2481 : 2132640 : EXECUTE_IF_SET_IN_BITMAP (candidates, 0, id, bi)
2482 : : {
2483 : 1288749 : rtx_insn *insn = DF_INSN_UID_GET (id)->insn;
2484 : 1288749 : df_ref ref;
2485 : :
2486 : 1916667 : FOR_EACH_INSN_DEF (ref, insn)
2487 : 627918 : if (!DF_REF_REG_MEM_P (ref)
2488 : 627918 : && GET_MODE (DF_REF_REG (ref)) == TImode)
2489 : 604597 : timode_check_non_convertible_regs (candidates, regs,
2490 : : DF_REF_REGNO (ref));
2491 : :
2492 : 3164133 : FOR_EACH_INSN_USE (ref, insn)
2493 : 1875384 : if (!DF_REF_REG_MEM_P (ref)
2494 : 651391 : && GET_MODE (DF_REF_REG (ref)) == TImode)
2495 : 651391 : timode_check_non_convertible_regs (candidates, regs,
2496 : : DF_REF_REGNO (ref));
2497 : : }
2498 : :
2499 : 1020091 : EXECUTE_IF_SET_IN_BITMAP (regs, 0, id, bi)
2500 : : {
2501 : 176200 : for (df_ref def = DF_REG_DEF_CHAIN (id);
2502 : 359596 : def;
2503 : 183396 : def = DF_REF_NEXT_REG (def))
2504 : 183396 : if (bitmap_bit_p (candidates, DF_REF_INSN_UID (def)))
2505 : : {
2506 : 37796 : if (dump_file)
2507 : 0 : fprintf (dump_file, "Removing insn %d from candidates list\n",
2508 : 0 : DF_REF_INSN_UID (def));
2509 : :
2510 : 37796 : bitmap_clear_bit (candidates, DF_REF_INSN_UID (def));
2511 : 37796 : changed = true;
2512 : : }
2513 : :
2514 : 176200 : for (df_ref ref = DF_REG_USE_CHAIN (id);
2515 : 492782 : ref;
2516 : 316582 : ref = DF_REF_NEXT_REG (ref))
2517 : 316582 : if (bitmap_bit_p (candidates, DF_REF_INSN_UID (ref)))
2518 : : {
2519 : 43733 : if (dump_file)
2520 : 0 : fprintf (dump_file, "Removing insn %d from candidates list\n",
2521 : 0 : DF_REF_INSN_UID (ref));
2522 : :
2523 : 43733 : bitmap_clear_bit (candidates, DF_REF_INSN_UID (ref));
2524 : 43733 : changed = true;
2525 : : }
2526 : : }
2527 : : } while (changed);
2528 : :
2529 : 819387 : BITMAP_FREE (regs);
2530 : 819387 : }
2531 : :
2532 : : /* Main STV pass function. Find and convert scalar
2533 : : instructions into vector mode when profitable. */
2534 : :
2535 : : static unsigned int
2536 : 1764015 : convert_scalars_to_vector (bool timode_p)
2537 : : {
2538 : 1764015 : basic_block bb;
2539 : 1764015 : int converted_insns = 0;
2540 : 1764015 : auto_vec<rtx_insn *> control_flow_insns;
2541 : :
2542 : 1764015 : bitmap_obstack_initialize (NULL);
2543 : 1764015 : const machine_mode cand_mode[3] = { SImode, DImode, TImode };
2544 : 1764015 : const machine_mode cand_vmode[3] = { V4SImode, V2DImode, V1TImode };
2545 : 5292045 : bitmap_head candidates[3]; /* { SImode, DImode, TImode } */
2546 : 7056060 : for (unsigned i = 0; i < 3; ++i)
2547 : 5292045 : bitmap_initialize (&candidates[i], &bitmap_default_obstack);
2548 : :
2549 : 1764015 : calculate_dominance_info (CDI_DOMINATORS);
2550 : 1764015 : df_set_flags (DF_DEFER_INSN_RESCAN | DF_RD_PRUNE_DEAD_DEFS);
2551 : 1764015 : df_chain_add_problem (DF_DU_CHAIN | DF_UD_CHAIN);
2552 : 1764015 : df_analyze ();
2553 : :
2554 : : /* Find all instructions we want to convert into vector mode. */
2555 : 1764015 : if (dump_file)
2556 : 44 : fprintf (dump_file, "Searching for mode conversion candidates...\n");
2557 : :
2558 : 19657009 : FOR_EACH_BB_FN (bb, cfun)
2559 : : {
2560 : 17892994 : rtx_insn *insn;
2561 : 235813670 : FOR_BB_INSNS (bb, insn)
2562 : 217920676 : if (timode_p
2563 : 217920676 : && timode_scalar_to_vector_candidate_p (insn))
2564 : : {
2565 : 982796 : if (dump_file)
2566 : 0 : fprintf (dump_file, " insn %d is marked as a TImode candidate\n",
2567 : 0 : INSN_UID (insn));
2568 : :
2569 : 982796 : bitmap_set_bit (&candidates[2], INSN_UID (insn));
2570 : : }
2571 : 216937880 : else if (!timode_p)
2572 : : {
2573 : : /* Check {SI,DI}mode. */
2574 : 338914526 : for (unsigned i = 0; i <= 1; ++i)
2575 : 232544520 : if (general_scalar_to_vector_candidate_p (insn, cand_mode[i]))
2576 : : {
2577 : 11685820 : if (dump_file)
2578 : 558 : fprintf (dump_file, " insn %d is marked as a %s candidate\n",
2579 : 279 : INSN_UID (insn), i == 0 ? "SImode" : "DImode");
2580 : :
2581 : 11685820 : bitmap_set_bit (&candidates[i], INSN_UID (insn));
2582 : 11685820 : break;
2583 : : }
2584 : : }
2585 : : }
2586 : :
2587 : 1764015 : if (timode_p)
2588 : 819387 : timode_remove_non_convertible_regs (&candidates[2]);
2589 : :
2590 : 5572716 : for (unsigned i = 0; i <= 2; ++i)
2591 : 4441722 : if (!bitmap_empty_p (&candidates[i]))
2592 : : break;
2593 : 3808701 : else if (i == 2 && dump_file)
2594 : 23 : fprintf (dump_file, "There are no candidates for optimization.\n");
2595 : :
2596 : 7056060 : for (unsigned i = 0; i <= 2; ++i)
2597 : : {
2598 : 5292045 : auto_bitmap disallowed;
2599 : 5292045 : bitmap_tree_view (&candidates[i]);
2600 : 16998533 : while (!bitmap_empty_p (&candidates[i]))
2601 : : {
2602 : 6414443 : unsigned uid = bitmap_first_set_bit (&candidates[i]);
2603 : 6414443 : scalar_chain *chain;
2604 : :
2605 : 6414443 : if (cand_mode[i] == TImode)
2606 : 455366 : chain = new timode_scalar_chain;
2607 : : else
2608 : 5959077 : chain = new general_scalar_chain (cand_mode[i], cand_vmode[i]);
2609 : :
2610 : : /* Find instructions chain we want to convert to vector mode.
2611 : : Check all uses and definitions to estimate all required
2612 : : conversions. */
2613 : 6414443 : if (chain->build (&candidates[i], uid, disallowed))
2614 : : {
2615 : 6413926 : if (chain->compute_convert_gain ())
2616 : 634786 : converted_insns += chain->convert ();
2617 : 5779140 : else if (dump_file)
2618 : 138 : fprintf (dump_file, "Chain #%d conversion is not profitable\n",
2619 : : chain->chain_id);
2620 : : }
2621 : :
2622 : 6414443 : rtx_insn* iter_insn;
2623 : 6414443 : unsigned int ii;
2624 : 6419187 : FOR_EACH_VEC_ELT (chain->control_flow_insns, ii, iter_insn)
2625 : 4744 : control_flow_insns.safe_push (iter_insn);
2626 : :
2627 : 6414443 : delete chain;
2628 : : }
2629 : 5292045 : }
2630 : :
2631 : 1764015 : if (dump_file)
2632 : 44 : fprintf (dump_file, "Total insns converted: %d\n", converted_insns);
2633 : :
2634 : 7056060 : for (unsigned i = 0; i <= 2; ++i)
2635 : 5292045 : bitmap_release (&candidates[i]);
2636 : 1764015 : bitmap_obstack_release (NULL);
2637 : 1764015 : df_process_deferred_rescans ();
2638 : :
2639 : : /* Conversion means we may have 128bit register spills/fills
2640 : : which require aligned stack. */
2641 : 1764015 : if (converted_insns)
2642 : : {
2643 : 109811 : if (crtl->stack_alignment_needed < 128)
2644 : 2175 : crtl->stack_alignment_needed = 128;
2645 : 109811 : if (crtl->stack_alignment_estimated < 128)
2646 : 188 : crtl->stack_alignment_estimated = 128;
2647 : :
2648 : 109811 : crtl->stack_realign_needed
2649 : 109811 : = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
2650 : 109811 : crtl->stack_realign_tried = crtl->stack_realign_needed;
2651 : :
2652 : 109811 : crtl->stack_realign_processed = true;
2653 : :
2654 : 109811 : if (!crtl->drap_reg)
2655 : : {
2656 : 109665 : rtx drap_rtx = targetm.calls.get_drap_rtx ();
2657 : :
2658 : : /* stack_realign_drap and drap_rtx must match. */
2659 : 109665 : gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
2660 : :
2661 : : /* Do nothing if NULL is returned,
2662 : : which means DRAP is not needed. */
2663 : 109665 : if (drap_rtx != NULL)
2664 : : {
2665 : 0 : crtl->args.internal_arg_pointer = drap_rtx;
2666 : :
2667 : : /* Call fixup_tail_calls to clean up
2668 : : REG_EQUIV note if DRAP is needed. */
2669 : 0 : fixup_tail_calls ();
2670 : : }
2671 : : }
2672 : :
2673 : : /* Fix up DECL_RTL/DECL_INCOMING_RTL of arguments. */
2674 : 109811 : if (TARGET_64BIT)
2675 : 70048 : for (tree parm = DECL_ARGUMENTS (current_function_decl);
2676 : 193724 : parm; parm = DECL_CHAIN (parm))
2677 : : {
2678 : 123676 : if (TYPE_MODE (TREE_TYPE (parm)) != TImode)
2679 : 107114 : continue;
2680 : 16562 : if (DECL_RTL_SET_P (parm)
2681 : 33124 : && GET_MODE (DECL_RTL (parm)) == V1TImode)
2682 : : {
2683 : 324 : rtx r = DECL_RTL (parm);
2684 : 324 : if (REG_P (r))
2685 : 324 : SET_DECL_RTL (parm, gen_rtx_SUBREG (TImode, r, 0));
2686 : : }
2687 : 16562 : if (DECL_INCOMING_RTL (parm)
2688 : 16562 : && GET_MODE (DECL_INCOMING_RTL (parm)) == V1TImode)
2689 : : {
2690 : 0 : rtx r = DECL_INCOMING_RTL (parm);
2691 : 0 : if (REG_P (r))
2692 : 0 : DECL_INCOMING_RTL (parm) = gen_rtx_SUBREG (TImode, r, 0);
2693 : : }
2694 : : }
2695 : :
2696 : 109811 : if (!control_flow_insns.is_empty ())
2697 : : {
2698 : 1347 : free_dominance_info (CDI_DOMINATORS);
2699 : :
2700 : 1347 : unsigned int i;
2701 : 1347 : rtx_insn* insn;
2702 : 7438 : FOR_EACH_VEC_ELT (control_flow_insns, i, insn)
2703 : 4744 : if (control_flow_insn_p (insn))
2704 : : {
2705 : : /* Split the block after insn. There will be a fallthru
2706 : : edge, which is OK so we keep it. We have to create
2707 : : the exception edges ourselves. */
2708 : 4744 : bb = BLOCK_FOR_INSN (insn);
2709 : 4744 : split_block (bb, insn);
2710 : 4744 : rtl_make_eh_edge (NULL, bb, BB_END (bb));
2711 : : }
2712 : : }
2713 : : }
2714 : :
2715 : 1764015 : return 0;
2716 : 1764015 : }
2717 : :
2718 : : static unsigned int
2719 : 72643 : rest_of_handle_insert_vzeroupper (void)
2720 : : {
2721 : : /* vzeroupper instructions are inserted immediately after reload and
2722 : : postreload_cse to clean up after it a little bit to account for possible
2723 : : spills from 256bit or 512bit registers. The pass reuses mode switching
2724 : : infrastructure by re-running mode insertion pass, so disable entities
2725 : : that have already been processed. */
2726 : 508501 : for (int i = 0; i < MAX_386_ENTITIES; i++)
2727 : 435858 : ix86_optimize_mode_switching[i] = 0;
2728 : :
2729 : 72643 : ix86_optimize_mode_switching[AVX_U128] = 1;
2730 : :
2731 : : /* Call optimize_mode_switching. */
2732 : 72643 : g->get_passes ()->execute_pass_mode_switching ();
2733 : :
2734 : : /* LRA removes all REG_DEAD/REG_UNUSED notes and normally they
2735 : : reappear in the IL only at the start of pass_rtl_dse2, which does
2736 : : df_note_add_problem (); df_analyze ();
2737 : : The vzeroupper is scheduled after postreload_cse pass and mode
2738 : : switching computes the notes as well, the problem is that e.g.
2739 : : pass_gcse2 doesn't maintain the notes, see PR113059 and
2740 : : PR112760. Remove the notes now to restore status quo ante
2741 : : until we figure out how to maintain the notes or what else
2742 : : to do. */
2743 : 72643 : basic_block bb;
2744 : 72643 : rtx_insn *insn;
2745 : 391626 : FOR_EACH_BB_FN (bb, cfun)
2746 : 4194636 : FOR_BB_INSNS (bb, insn)
2747 : 3875653 : if (NONDEBUG_INSN_P (insn))
2748 : : {
2749 : 2028162 : rtx *pnote = ®_NOTES (insn);
2750 : 3744546 : while (*pnote != 0)
2751 : : {
2752 : 1716384 : if (REG_NOTE_KIND (*pnote) == REG_DEAD
2753 : 782527 : || REG_NOTE_KIND (*pnote) == REG_UNUSED)
2754 : 1237631 : *pnote = XEXP (*pnote, 1);
2755 : : else
2756 : 478753 : pnote = &XEXP (*pnote, 1);
2757 : : }
2758 : : }
2759 : :
2760 : 72643 : df_remove_problem (df_note);
2761 : 72643 : df_analyze ();
2762 : 72643 : return 0;
2763 : : }
2764 : :
2765 : : namespace {
2766 : :
2767 : : const pass_data pass_data_insert_vzeroupper =
2768 : : {
2769 : : RTL_PASS, /* type */
2770 : : "vzeroupper", /* name */
2771 : : OPTGROUP_NONE, /* optinfo_flags */
2772 : : TV_MACH_DEP, /* tv_id */
2773 : : 0, /* properties_required */
2774 : : 0, /* properties_provided */
2775 : : 0, /* properties_destroyed */
2776 : : 0, /* todo_flags_start */
2777 : : TODO_df_finish, /* todo_flags_finish */
2778 : : };
2779 : :
2780 : : class pass_insert_vzeroupper : public rtl_opt_pass
2781 : : {
2782 : : public:
2783 : 284673 : pass_insert_vzeroupper(gcc::context *ctxt)
2784 : 569346 : : rtl_opt_pass(pass_data_insert_vzeroupper, ctxt)
2785 : : {}
2786 : :
2787 : : /* opt_pass methods: */
2788 : 1449068 : bool gate (function *) final override
2789 : : {
2790 : 1449068 : return TARGET_AVX && TARGET_VZEROUPPER;
2791 : : }
2792 : :
2793 : 72643 : unsigned int execute (function *) final override
2794 : : {
2795 : 72643 : return rest_of_handle_insert_vzeroupper ();
2796 : : }
2797 : :
2798 : : }; // class pass_insert_vzeroupper
2799 : :
2800 : : const pass_data pass_data_stv =
2801 : : {
2802 : : RTL_PASS, /* type */
2803 : : "stv", /* name */
2804 : : OPTGROUP_NONE, /* optinfo_flags */
2805 : : TV_MACH_DEP, /* tv_id */
2806 : : 0, /* properties_required */
2807 : : 0, /* properties_provided */
2808 : : 0, /* properties_destroyed */
2809 : : 0, /* todo_flags_start */
2810 : : TODO_df_finish, /* todo_flags_finish */
2811 : : };
2812 : :
2813 : : class pass_stv : public rtl_opt_pass
2814 : : {
2815 : : public:
2816 : 569346 : pass_stv (gcc::context *ctxt)
2817 : 569346 : : rtl_opt_pass (pass_data_stv, ctxt),
2818 : 1138692 : timode_p (false)
2819 : : {}
2820 : :
2821 : : /* opt_pass methods: */
2822 : 2898136 : bool gate (function *) final override
2823 : : {
2824 : 1449068 : return ((!timode_p || TARGET_64BIT)
2825 : 4221656 : && TARGET_STV && TARGET_SSE2 && optimize > 1);
2826 : : }
2827 : :
2828 : 1764015 : unsigned int execute (function *) final override
2829 : : {
2830 : 1764015 : return convert_scalars_to_vector (timode_p);
2831 : : }
2832 : :
2833 : 284673 : opt_pass *clone () final override
2834 : : {
2835 : 284673 : return new pass_stv (m_ctxt);
2836 : : }
2837 : :
2838 : 569346 : void set_pass_param (unsigned int n, bool param) final override
2839 : : {
2840 : 569346 : gcc_assert (n == 0);
2841 : 569346 : timode_p = param;
2842 : 569346 : }
2843 : :
2844 : : private:
2845 : : bool timode_p;
2846 : : }; // class pass_stv
2847 : :
2848 : : } // anon namespace
2849 : :
2850 : : rtl_opt_pass *
2851 : 284673 : make_pass_insert_vzeroupper (gcc::context *ctxt)
2852 : : {
2853 : 284673 : return new pass_insert_vzeroupper (ctxt);
2854 : : }
2855 : :
2856 : : rtl_opt_pass *
2857 : 284673 : make_pass_stv (gcc::context *ctxt)
2858 : : {
2859 : 284673 : return new pass_stv (ctxt);
2860 : : }
2861 : :
2862 : : /* Inserting ENDBR and pseudo patchable-area instructions. */
2863 : :
2864 : : static void
2865 : 201262 : rest_of_insert_endbr_and_patchable_area (bool need_endbr,
2866 : : unsigned int patchable_area_size)
2867 : : {
2868 : 201262 : rtx endbr;
2869 : 201262 : rtx_insn *insn;
2870 : 201262 : rtx_insn *endbr_insn = NULL;
2871 : 201262 : basic_block bb;
2872 : :
2873 : 201262 : if (need_endbr)
2874 : : {
2875 : : /* Currently emit EB if it's a tracking function, i.e. 'nocf_check'
2876 : : is absent among function attributes. Later an optimization will
2877 : : be introduced to make analysis if an address of a static function
2878 : : is taken. A static function whose address is not taken will get
2879 : : a nocf_check attribute. This will allow to reduce the number of
2880 : : EB. */
2881 : 201217 : if (!lookup_attribute ("nocf_check",
2882 : 201217 : TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
2883 : 201207 : && (!flag_manual_endbr
2884 : 8 : || lookup_attribute ("cf_check",
2885 : 8 : DECL_ATTRIBUTES (cfun->decl)))
2886 : 402423 : && (!cgraph_node::get (cfun->decl)->only_called_directly_p ()
2887 : 28033 : || ix86_cmodel == CM_LARGE
2888 : 28032 : || ix86_cmodel == CM_LARGE_PIC
2889 : 28031 : || flag_force_indirect_call
2890 : 28031 : || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2891 : : && DECL_DLLIMPORT_P (cfun->decl))))
2892 : : {
2893 : 173176 : if (crtl->profile && flag_fentry)
2894 : : {
2895 : : /* Queue ENDBR insertion to x86_function_profiler.
2896 : : NB: Any patchable-area insn will be inserted after
2897 : : ENDBR. */
2898 : 4 : cfun->machine->insn_queued_at_entrance = TYPE_ENDBR;
2899 : : }
2900 : : else
2901 : : {
2902 : 173172 : endbr = gen_nop_endbr ();
2903 : 173172 : bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
2904 : 173172 : rtx_insn *insn = BB_HEAD (bb);
2905 : 173172 : endbr_insn = emit_insn_before (endbr, insn);
2906 : : }
2907 : : }
2908 : : }
2909 : :
2910 : 201262 : if (patchable_area_size)
2911 : : {
2912 : 51 : if (crtl->profile && flag_fentry)
2913 : : {
2914 : : /* Queue patchable-area insertion to x86_function_profiler.
2915 : : NB: If there is a queued ENDBR, x86_function_profiler
2916 : : will also handle patchable-area. */
2917 : 2 : if (!cfun->machine->insn_queued_at_entrance)
2918 : 1 : cfun->machine->insn_queued_at_entrance = TYPE_PATCHABLE_AREA;
2919 : : }
2920 : : else
2921 : : {
2922 : 49 : rtx patchable_area
2923 : 49 : = gen_patchable_area (GEN_INT (patchable_area_size),
2924 : 49 : GEN_INT (crtl->patch_area_entry == 0));
2925 : 49 : if (endbr_insn)
2926 : 3 : emit_insn_after (patchable_area, endbr_insn);
2927 : : else
2928 : : {
2929 : 46 : bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
2930 : 46 : insn = BB_HEAD (bb);
2931 : 46 : emit_insn_before (patchable_area, insn);
2932 : : }
2933 : : }
2934 : : }
2935 : :
2936 : 201262 : if (!need_endbr)
2937 : : return;
2938 : :
2939 : 201217 : bb = 0;
2940 : 4146117 : FOR_EACH_BB_FN (bb, cfun)
2941 : : {
2942 : 73219268 : for (insn = BB_HEAD (bb); insn != NEXT_INSN (BB_END (bb));
2943 : 69274368 : insn = NEXT_INSN (insn))
2944 : : {
2945 : 69274368 : if (CALL_P (insn))
2946 : : {
2947 : 1406305 : need_endbr = find_reg_note (insn, REG_SETJMP, NULL) != NULL;
2948 : 1406305 : if (!need_endbr && !SIBLING_CALL_P (insn))
2949 : : {
2950 : 1355595 : rtx call = get_call_rtx_from (insn);
2951 : 1355595 : rtx fnaddr = XEXP (call, 0);
2952 : 1355595 : tree fndecl = NULL_TREE;
2953 : :
2954 : : /* Also generate ENDBRANCH for non-tail call which
2955 : : may return via indirect branch. */
2956 : 1355595 : if (GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
2957 : 1288316 : fndecl = SYMBOL_REF_DECL (XEXP (fnaddr, 0));
2958 : 1288316 : if (fndecl == NULL_TREE)
2959 : 68320 : fndecl = MEM_EXPR (fnaddr);
2960 : 68320 : if (fndecl
2961 : 1352666 : && TREE_CODE (TREE_TYPE (fndecl)) != FUNCTION_TYPE
2962 : 618957 : && TREE_CODE (TREE_TYPE (fndecl)) != METHOD_TYPE)
2963 : : fndecl = NULL_TREE;
2964 : 1355595 : if (fndecl && TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
2965 : : {
2966 : 1312017 : tree fntype = TREE_TYPE (fndecl);
2967 : 1312017 : if (lookup_attribute ("indirect_return",
2968 : 1312017 : TYPE_ATTRIBUTES (fntype)))
2969 : : need_endbr = true;
2970 : : }
2971 : : }
2972 : 1406293 : if (!need_endbr)
2973 : 1406287 : continue;
2974 : : /* Generate ENDBRANCH after CALL, which can return more than
2975 : : twice, setjmp-like functions. */
2976 : :
2977 : 18 : endbr = gen_nop_endbr ();
2978 : 18 : emit_insn_after_setloc (endbr, insn, INSN_LOCATION (insn));
2979 : 18 : continue;
2980 : 18 : }
2981 : :
2982 : 67868063 : if (JUMP_P (insn) && flag_cet_switch)
2983 : : {
2984 : 9 : rtx target = JUMP_LABEL (insn);
2985 : 9 : if (target == NULL_RTX || ANY_RETURN_P (target))
2986 : 5 : continue;
2987 : :
2988 : : /* Check the jump is a switch table. */
2989 : 4 : rtx_insn *label = as_a<rtx_insn *> (target);
2990 : 4 : rtx_insn *table = next_insn (label);
2991 : 4 : if (table == NULL_RTX || !JUMP_TABLE_DATA_P (table))
2992 : 2 : continue;
2993 : :
2994 : : /* For the indirect jump find out all places it jumps and insert
2995 : : ENDBRANCH there. It should be done under a special flag to
2996 : : control ENDBRANCH generation for switch stmts. */
2997 : 2 : edge_iterator ei;
2998 : 2 : edge e;
2999 : 2 : basic_block dest_blk;
3000 : :
3001 : 24 : FOR_EACH_EDGE (e, ei, bb->succs)
3002 : : {
3003 : 22 : rtx_insn *insn;
3004 : :
3005 : 22 : dest_blk = e->dest;
3006 : 22 : insn = BB_HEAD (dest_blk);
3007 : 22 : gcc_assert (LABEL_P (insn));
3008 : 22 : endbr = gen_nop_endbr ();
3009 : 22 : emit_insn_after (endbr, insn);
3010 : : }
3011 : 2 : continue;
3012 : 2 : }
3013 : :
3014 : 67868054 : if (LABEL_P (insn) && LABEL_PRESERVE_P (insn))
3015 : : {
3016 : 145997 : endbr = gen_nop_endbr ();
3017 : 145997 : emit_insn_after (endbr, insn);
3018 : 145997 : continue;
3019 : : }
3020 : : }
3021 : : }
3022 : :
3023 : : return;
3024 : : }
3025 : :
3026 : : namespace {
3027 : :
3028 : : const pass_data pass_data_insert_endbr_and_patchable_area =
3029 : : {
3030 : : RTL_PASS, /* type. */
3031 : : "endbr_and_patchable_area", /* name. */
3032 : : OPTGROUP_NONE, /* optinfo_flags. */
3033 : : TV_MACH_DEP, /* tv_id. */
3034 : : 0, /* properties_required. */
3035 : : 0, /* properties_provided. */
3036 : : 0, /* properties_destroyed. */
3037 : : 0, /* todo_flags_start. */
3038 : : 0, /* todo_flags_finish. */
3039 : : };
3040 : :
3041 : : class pass_insert_endbr_and_patchable_area : public rtl_opt_pass
3042 : : {
3043 : : public:
3044 : 284673 : pass_insert_endbr_and_patchable_area (gcc::context *ctxt)
3045 : 569346 : : rtl_opt_pass (pass_data_insert_endbr_and_patchable_area, ctxt)
3046 : : {}
3047 : :
3048 : : /* opt_pass methods: */
3049 : 1449068 : bool gate (function *) final override
3050 : : {
3051 : 1449068 : need_endbr = (flag_cf_protection & CF_BRANCH) != 0;
3052 : 1449068 : patchable_area_size = crtl->patch_area_size - crtl->patch_area_entry;
3053 : 1449068 : return need_endbr || patchable_area_size;
3054 : : }
3055 : :
3056 : 201262 : unsigned int execute (function *) final override
3057 : : {
3058 : 201262 : timevar_push (TV_MACH_DEP);
3059 : 201262 : rest_of_insert_endbr_and_patchable_area (need_endbr,
3060 : : patchable_area_size);
3061 : 201262 : timevar_pop (TV_MACH_DEP);
3062 : 201262 : return 0;
3063 : : }
3064 : :
3065 : : private:
3066 : : bool need_endbr;
3067 : : unsigned int patchable_area_size;
3068 : : }; // class pass_insert_endbr_and_patchable_area
3069 : :
3070 : : } // anon namespace
3071 : :
3072 : : rtl_opt_pass *
3073 : 284673 : make_pass_insert_endbr_and_patchable_area (gcc::context *ctxt)
3074 : : {
3075 : 284673 : return new pass_insert_endbr_and_patchable_area (ctxt);
3076 : : }
3077 : :
3078 : : bool
3079 : 5987645 : ix86_rpad_gate ()
3080 : : {
3081 : 5987645 : return (TARGET_AVX
3082 : 406503 : && TARGET_SSE_PARTIAL_REG_DEPENDENCY
3083 : 312017 : && TARGET_SSE_MATH
3084 : 311795 : && optimize
3085 : 6294394 : && optimize_function_for_speed_p (cfun));
3086 : : }
3087 : :
3088 : : /* Generate a vector set, DEST = SRC, at entry of the nearest dominator
3089 : : for basic block map BBS, which is in the fake loop that contains the
3090 : : whole function, so that there is only a single vector set in the
3091 : : whole function. If not nullptr, INNER_SCALAR is the inner scalar of
3092 : : SRC, as (reg:SI 99) in (vec_duplicate:V4SI (reg:SI 99)). */
3093 : :
3094 : : static void
3095 : 30256 : ix86_place_single_vector_set (rtx dest, rtx src, bitmap bbs,
3096 : : rtx inner_scalar = nullptr)
3097 : : {
3098 : 30256 : basic_block bb = nearest_common_dominator_for_set (CDI_DOMINATORS, bbs);
3099 : 30256 : while (bb->loop_father->latch
3100 : 32530 : != EXIT_BLOCK_PTR_FOR_FN (cfun))
3101 : 2274 : bb = get_immediate_dominator (CDI_DOMINATORS,
3102 : : bb->loop_father->header);
3103 : :
3104 : 30256 : rtx set = gen_rtx_SET (dest, src);
3105 : :
3106 : 30256 : rtx_insn *insn = BB_HEAD (bb);
3107 : 129085 : while (insn && !NONDEBUG_INSN_P (insn))
3108 : : {
3109 : 98833 : if (insn == BB_END (bb))
3110 : : {
3111 : : insn = NULL;
3112 : : break;
3113 : : }
3114 : 98829 : insn = NEXT_INSN (insn);
3115 : : }
3116 : :
3117 : 30256 : rtx_insn *set_insn;
3118 : 30256 : if (insn == BB_HEAD (bb))
3119 : : {
3120 : 0 : set_insn = emit_insn_before (set, insn);
3121 : 0 : if (dump_file)
3122 : : {
3123 : 0 : fprintf (dump_file, "\nPlace:\n\n");
3124 : 0 : print_rtl_single (dump_file, set_insn);
3125 : 0 : fprintf (dump_file, "\nbefore:\n\n");
3126 : 0 : print_rtl_single (dump_file, insn);
3127 : 0 : fprintf (dump_file, "\n");
3128 : : }
3129 : : }
3130 : : else
3131 : : {
3132 : 30256 : rtx_insn *after = insn ? PREV_INSN (insn) : BB_END (bb);
3133 : 30256 : set_insn = emit_insn_after (set, after);
3134 : 30256 : if (dump_file)
3135 : : {
3136 : 0 : fprintf (dump_file, "\nPlace:\n\n");
3137 : 0 : print_rtl_single (dump_file, set_insn);
3138 : 0 : fprintf (dump_file, "\nafter:\n\n");
3139 : 0 : print_rtl_single (dump_file, after);
3140 : 0 : fprintf (dump_file, "\n");
3141 : : }
3142 : : }
3143 : :
3144 : 30256 : if (inner_scalar)
3145 : : {
3146 : : /* Set the source in (vec_duplicate:V4SI (reg:SI 99)). */
3147 : 9907 : rtx reg = XEXP (src, 0);
3148 : 9907 : if ((REG_P (inner_scalar) || MEM_P (inner_scalar))
3149 : 250 : && GET_MODE (reg) != GET_MODE (inner_scalar))
3150 : 0 : inner_scalar = gen_rtx_SUBREG (GET_MODE (reg), inner_scalar, 0);
3151 : 9907 : rtx set = gen_rtx_SET (reg, inner_scalar);
3152 : 9907 : insn = emit_insn_before (set, set_insn);
3153 : 9907 : if (dump_file)
3154 : : {
3155 : 0 : fprintf (dump_file, "\nAdd:\n\n");
3156 : 0 : print_rtl_single (dump_file, insn);
3157 : 0 : fprintf (dump_file, "\nbefore:\n\n");
3158 : 0 : print_rtl_single (dump_file, set_insn);
3159 : 0 : fprintf (dump_file, "\n");
3160 : : }
3161 : : }
3162 : 30256 : }
3163 : :
3164 : : /* At entry of the nearest common dominator for basic blocks with
3165 : : conversions/rcp/sqrt/rsqrt/round, generate a single
3166 : : vxorps %xmmN, %xmmN, %xmmN
3167 : : for all
3168 : : vcvtss2sd op, %xmmN, %xmmX
3169 : : vcvtsd2ss op, %xmmN, %xmmX
3170 : : vcvtsi2ss op, %xmmN, %xmmX
3171 : : vcvtsi2sd op, %xmmN, %xmmX
3172 : :
3173 : : NB: We want to generate only a single vxorps to cover the whole
3174 : : function. The LCM algorithm isn't appropriate here since it may
3175 : : place a vxorps inside the loop. */
3176 : :
3177 : : static unsigned int
3178 : 31553 : remove_partial_avx_dependency (void)
3179 : : {
3180 : 31553 : timevar_push (TV_MACH_DEP);
3181 : :
3182 : 31553 : bitmap_obstack_initialize (NULL);
3183 : 31553 : bitmap convert_bbs = BITMAP_ALLOC (NULL);
3184 : :
3185 : 31553 : basic_block bb;
3186 : 31553 : rtx_insn *insn, *set_insn;
3187 : 31553 : rtx set;
3188 : 31553 : rtx v4sf_const0 = NULL_RTX;
3189 : :
3190 : 31553 : auto_vec<rtx_insn *> control_flow_insns;
3191 : :
3192 : : /* We create invalid RTL initially so defer rescans. */
3193 : 31553 : df_set_flags (DF_DEFER_INSN_RESCAN);
3194 : :
3195 : 292621 : FOR_EACH_BB_FN (bb, cfun)
3196 : : {
3197 : 3450475 : FOR_BB_INSNS (bb, insn)
3198 : : {
3199 : 3189407 : if (!NONDEBUG_INSN_P (insn))
3200 : 1445521 : continue;
3201 : :
3202 : 1743886 : set = single_set (insn);
3203 : 1743886 : if (!set)
3204 : 65199 : continue;
3205 : :
3206 : 1678687 : if (get_attr_avx_partial_xmm_update (insn)
3207 : : != AVX_PARTIAL_XMM_UPDATE_TRUE)
3208 : 1675709 : continue;
3209 : :
3210 : : /* Convert PARTIAL_XMM_UPDATE_TRUE insns, DF -> SF, SF -> DF,
3211 : : SI -> SF, SI -> DF, DI -> SF, DI -> DF, sqrt, rsqrt, rcp,
3212 : : round, to vec_dup and vec_merge with subreg. */
3213 : 2978 : rtx src = SET_SRC (set);
3214 : 2978 : rtx dest = SET_DEST (set);
3215 : 2978 : machine_mode dest_mode = GET_MODE (dest);
3216 : 2978 : bool convert_p = false;
3217 : 2978 : switch (GET_CODE (src))
3218 : : {
3219 : 2874 : case FLOAT:
3220 : 2874 : case FLOAT_EXTEND:
3221 : 2874 : case FLOAT_TRUNCATE:
3222 : 2874 : case UNSIGNED_FLOAT:
3223 : 2874 : convert_p = true;
3224 : 2874 : break;
3225 : : default:
3226 : : break;
3227 : : }
3228 : :
3229 : : /* Only hanlde conversion here. */
3230 : 2874 : machine_mode src_mode
3231 : 2874 : = convert_p ? GET_MODE (XEXP (src, 0)) : VOIDmode;
3232 : 2874 : switch (src_mode)
3233 : : {
3234 : 172 : case E_SFmode:
3235 : 172 : case E_DFmode:
3236 : 172 : if (TARGET_USE_VECTOR_FP_CONVERTS
3237 : 166 : || !TARGET_SSE_PARTIAL_REG_FP_CONVERTS_DEPENDENCY)
3238 : 8 : continue;
3239 : : break;
3240 : 2702 : case E_SImode:
3241 : 2702 : case E_DImode:
3242 : 2702 : if (TARGET_USE_VECTOR_CONVERTS
3243 : 2690 : || !TARGET_SSE_PARTIAL_REG_CONVERTS_DEPENDENCY)
3244 : 14 : continue;
3245 : : break;
3246 : 104 : case E_VOIDmode:
3247 : 104 : gcc_assert (!convert_p);
3248 : : break;
3249 : 0 : default:
3250 : 0 : gcc_unreachable ();
3251 : : }
3252 : :
3253 : 2956 : if (!v4sf_const0)
3254 : 960 : v4sf_const0 = gen_reg_rtx (V4SFmode);
3255 : :
3256 : 2956 : rtx zero;
3257 : 2956 : machine_mode dest_vecmode;
3258 : 2956 : switch (dest_mode)
3259 : : {
3260 : 90 : case E_HFmode:
3261 : 90 : dest_vecmode = V8HFmode;
3262 : 90 : zero = gen_rtx_SUBREG (V8HFmode, v4sf_const0, 0);
3263 : 90 : break;
3264 : : case E_SFmode:
3265 : : dest_vecmode = V4SFmode;
3266 : : zero = v4sf_const0;
3267 : : break;
3268 : 1007 : case E_DFmode:
3269 : 1007 : dest_vecmode = V2DFmode;
3270 : 1007 : zero = gen_rtx_SUBREG (V2DFmode, v4sf_const0, 0);
3271 : 1007 : break;
3272 : 0 : default:
3273 : 0 : gcc_unreachable ();
3274 : : }
3275 : :
3276 : : /* Change source to vector mode. */
3277 : 2956 : src = gen_rtx_VEC_DUPLICATE (dest_vecmode, src);
3278 : 2956 : src = gen_rtx_VEC_MERGE (dest_vecmode, src, zero,
3279 : : GEN_INT (HOST_WIDE_INT_1U));
3280 : : /* Change destination to vector mode. */
3281 : 2956 : rtx vec = gen_reg_rtx (dest_vecmode);
3282 : : /* Generate an XMM vector SET. */
3283 : 2956 : set = gen_rtx_SET (vec, src);
3284 : 2956 : set_insn = emit_insn_before (set, insn);
3285 : :
3286 : 2956 : if (cfun->can_throw_non_call_exceptions)
3287 : : {
3288 : : /* Handle REG_EH_REGION note. */
3289 : 0 : rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
3290 : 0 : if (note)
3291 : : {
3292 : 0 : control_flow_insns.safe_push (set_insn);
3293 : 0 : add_reg_note (set_insn, REG_EH_REGION, XEXP (note, 0));
3294 : : }
3295 : : }
3296 : :
3297 : 2956 : src = gen_rtx_SUBREG (dest_mode, vec, 0);
3298 : 2956 : set = gen_rtx_SET (dest, src);
3299 : :
3300 : : /* Drop possible dead definitions. */
3301 : 2956 : PATTERN (insn) = set;
3302 : :
3303 : 2956 : INSN_CODE (insn) = -1;
3304 : 2956 : recog_memoized (insn);
3305 : 2956 : df_insn_rescan (insn);
3306 : 2956 : bitmap_set_bit (convert_bbs, bb->index);
3307 : : }
3308 : : }
3309 : :
3310 : 31553 : if (v4sf_const0)
3311 : : {
3312 : : /* (Re-)discover loops so that bb->loop_father can be used in the
3313 : : analysis below. */
3314 : 960 : calculate_dominance_info (CDI_DOMINATORS);
3315 : 960 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
3316 : :
3317 : 960 : ix86_place_single_vector_set (v4sf_const0,
3318 : : CONST0_RTX (V4SFmode),
3319 : : convert_bbs);
3320 : :
3321 : 960 : loop_optimizer_finalize ();
3322 : :
3323 : 960 : if (!control_flow_insns.is_empty ())
3324 : : {
3325 : 0 : free_dominance_info (CDI_DOMINATORS);
3326 : :
3327 : 0 : unsigned int i;
3328 : 0 : FOR_EACH_VEC_ELT (control_flow_insns, i, insn)
3329 : 0 : if (control_flow_insn_p (insn))
3330 : : {
3331 : : /* Split the block after insn. There will be a fallthru
3332 : : edge, which is OK so we keep it. We have to create
3333 : : the exception edges ourselves. */
3334 : 0 : bb = BLOCK_FOR_INSN (insn);
3335 : 0 : split_block (bb, insn);
3336 : 0 : rtl_make_eh_edge (NULL, bb, BB_END (bb));
3337 : : }
3338 : : }
3339 : : }
3340 : :
3341 : 31553 : df_process_deferred_rescans ();
3342 : 31553 : df_clear_flags (DF_DEFER_INSN_RESCAN);
3343 : 31553 : bitmap_obstack_release (NULL);
3344 : 31553 : BITMAP_FREE (convert_bbs);
3345 : :
3346 : 31553 : timevar_pop (TV_MACH_DEP);
3347 : 31553 : return 0;
3348 : 31553 : }
3349 : :
3350 : : namespace {
3351 : :
3352 : : const pass_data pass_data_remove_partial_avx_dependency =
3353 : : {
3354 : : RTL_PASS, /* type */
3355 : : "rpad", /* name */
3356 : : OPTGROUP_NONE, /* optinfo_flags */
3357 : : TV_MACH_DEP, /* tv_id */
3358 : : 0, /* properties_required */
3359 : : 0, /* properties_provided */
3360 : : 0, /* properties_destroyed */
3361 : : 0, /* todo_flags_start */
3362 : : 0, /* todo_flags_finish */
3363 : : };
3364 : :
3365 : : class pass_remove_partial_avx_dependency : public rtl_opt_pass
3366 : : {
3367 : : public:
3368 : 284673 : pass_remove_partial_avx_dependency (gcc::context *ctxt)
3369 : 569346 : : rtl_opt_pass (pass_data_remove_partial_avx_dependency, ctxt)
3370 : : {}
3371 : :
3372 : : /* opt_pass methods: */
3373 : 1449068 : bool gate (function *) final override
3374 : : {
3375 : 1449068 : return ix86_rpad_gate ();
3376 : : }
3377 : :
3378 : 31553 : unsigned int execute (function *) final override
3379 : : {
3380 : 31553 : return remove_partial_avx_dependency ();
3381 : : }
3382 : : }; // class pass_rpad
3383 : :
3384 : : } // anon namespace
3385 : :
3386 : : rtl_opt_pass *
3387 : 284673 : make_pass_remove_partial_avx_dependency (gcc::context *ctxt)
3388 : : {
3389 : 284673 : return new pass_remove_partial_avx_dependency (ctxt);
3390 : : }
3391 : :
3392 : : /* Return a machine mode suitable for vector SIZE with SMODE inner
3393 : : mode. */
3394 : :
3395 : : static machine_mode
3396 : 30397 : ix86_get_vector_cse_mode (unsigned int size, machine_mode smode)
3397 : : {
3398 : : /* Use the inner scalar mode of vector broadcast source in:
3399 : :
3400 : : (set (reg:V8DF 394)
3401 : : (vec_duplicate:V8DF (reg:V2DF 190 [ alpha ])))
3402 : :
3403 : : to compute the vector mode for broadcast from vector source.
3404 : : */
3405 : 30397 : if (VECTOR_MODE_P (smode))
3406 : 1 : smode = GET_MODE_INNER (smode);
3407 : 30397 : scalar_mode s_mode = as_a <scalar_mode> (smode);
3408 : 60794 : poly_uint64 nunits = size / GET_MODE_SIZE (smode);
3409 : 30397 : machine_mode mode = mode_for_vector (s_mode, nunits).require ();
3410 : 30397 : return mode;
3411 : : }
3412 : :
3413 : : /* Replace the source operand of instructions in VECTOR_INSNS with
3414 : : VECTOR_CONST in VECTOR_MODE. */
3415 : :
3416 : : static void
3417 : 30007 : replace_vector_const (machine_mode vector_mode, rtx vector_const,
3418 : : auto_bitmap &vector_insns,
3419 : : machine_mode scalar_mode)
3420 : : {
3421 : 30007 : bitmap_iterator bi;
3422 : 30007 : unsigned int id;
3423 : :
3424 : 144381 : EXECUTE_IF_SET_IN_BITMAP (vector_insns, 0, id, bi)
3425 : : {
3426 : 114374 : rtx_insn *insn = DF_INSN_UID_GET (id)->insn;
3427 : :
3428 : : /* Get the single SET instruction. */
3429 : 114374 : rtx set = single_set (insn);
3430 : 114374 : rtx src = SET_SRC (set);
3431 : 114374 : rtx dest = SET_DEST (set);
3432 : 114374 : machine_mode mode = GET_MODE (dest);
3433 : :
3434 : 114374 : rtx replace;
3435 : : /* Replace the source operand with VECTOR_CONST. */
3436 : 114374 : if (SUBREG_P (src) || mode == vector_mode)
3437 : : replace = vector_const;
3438 : : else
3439 : : {
3440 : 58849 : unsigned int size = GET_MODE_SIZE (mode);
3441 : 58849 : if (size < ix86_regmode_natural_size (mode))
3442 : : {
3443 : : /* If the mode size is smaller than its natural size,
3444 : : first insert an extra move with a QI vector SUBREG
3445 : : of the same size to avoid validate_subreg failure. */
3446 : 390 : machine_mode vmode
3447 : 390 : = ix86_get_vector_cse_mode (size, scalar_mode);
3448 : 390 : rtx vreg;
3449 : 390 : if (mode == vmode)
3450 : : vreg = vector_const;
3451 : : else
3452 : : {
3453 : 37 : vreg = gen_reg_rtx (vmode);
3454 : 37 : rtx vsubreg = gen_rtx_SUBREG (vmode, vector_const, 0);
3455 : 37 : rtx pat = gen_rtx_SET (vreg, vsubreg);
3456 : 37 : rtx_insn *vinsn = emit_insn_before (pat, insn);
3457 : 37 : if (dump_file)
3458 : : {
3459 : 0 : fprintf (dump_file, "\nInsert an extra move:\n\n");
3460 : 0 : print_rtl_single (dump_file, vinsn);
3461 : 0 : fprintf (dump_file, "\nbefore:\n\n");
3462 : 0 : print_rtl_single (dump_file, insn);
3463 : 0 : fprintf (dump_file, "\n");
3464 : : }
3465 : : }
3466 : 390 : replace = gen_rtx_SUBREG (mode, vreg, 0);
3467 : : }
3468 : : else
3469 : 58459 : replace = gen_rtx_SUBREG (mode, vector_const, 0);
3470 : : }
3471 : :
3472 : 114374 : if (dump_file)
3473 : : {
3474 : 0 : fprintf (dump_file, "\nReplace:\n\n");
3475 : 0 : print_rtl_single (dump_file, insn);
3476 : : }
3477 : 114374 : SET_SRC (set) = replace;
3478 : : /* Drop possible dead definitions. */
3479 : 114374 : PATTERN (insn) = set;
3480 : 114374 : INSN_CODE (insn) = -1;
3481 : 114374 : recog_memoized (insn);
3482 : 114374 : if (dump_file)
3483 : : {
3484 : 0 : fprintf (dump_file, "\nwith:\n\n");
3485 : 0 : print_rtl_single (dump_file, insn);
3486 : 0 : fprintf (dump_file, "\n");
3487 : : }
3488 : 114374 : df_insn_rescan (insn);
3489 : : }
3490 : 30007 : }
3491 : :
3492 : : enum x86_cse_kind
3493 : : {
3494 : : X86_CSE_CONST0_VECTOR,
3495 : : X86_CSE_CONSTM1_VECTOR,
3496 : : X86_CSE_VEC_DUP
3497 : : };
3498 : :
3499 : 115722 : struct redundant_load
3500 : : {
3501 : : /* Bitmap of basic blocks with broadcast instructions. */
3502 : : auto_bitmap bbs;
3503 : : /* Bitmap of broadcast instructions. */
3504 : : auto_bitmap insns;
3505 : : /* The broadcast inner scalar. */
3506 : : rtx val;
3507 : : /* The inner scalar mode. */
3508 : : machine_mode mode;
3509 : : /* The instruction which sets the inner scalar. Nullptr if the inner
3510 : : scalar is applied to the whole function, instead of within the same
3511 : : block. */
3512 : : rtx_insn *def_insn;
3513 : : /* The widest broadcast source. */
3514 : : rtx broadcast_source;
3515 : : /* The widest broadcast register. */
3516 : : rtx broadcast_reg;
3517 : : /* The basic block of the broadcast instruction. */
3518 : : basic_block bb;
3519 : : /* The number of broadcast instructions with the same inner scalar. */
3520 : : unsigned HOST_WIDE_INT count;
3521 : : /* The threshold of broadcast instructions with the same inner
3522 : : scalar. */
3523 : : unsigned int threshold;
3524 : : /* The widest broadcast size in bytes. */
3525 : : unsigned int size;
3526 : : /* Load kind. */
3527 : : x86_cse_kind kind;
3528 : : };
3529 : :
3530 : : /* Return the inner scalar if OP is a broadcast, else return nullptr. */
3531 : :
3532 : : static rtx
3533 : 2085448 : ix86_broadcast_inner (rtx op, machine_mode mode,
3534 : : machine_mode *scalar_mode_p,
3535 : : x86_cse_kind *kind_p, rtx_insn **insn_p)
3536 : : {
3537 : 2085448 : if (op == const0_rtx || op == CONST0_RTX (mode))
3538 : : {
3539 : 104939 : *scalar_mode_p = QImode;
3540 : 104939 : *kind_p = X86_CSE_CONST0_VECTOR;
3541 : 104939 : *insn_p = nullptr;
3542 : 104939 : return const0_rtx;
3543 : : }
3544 : 1980509 : else if ((GET_MODE_CLASS (mode) == MODE_VECTOR_INT
3545 : 1586572 : && (op == constm1_rtx || op == CONSTM1_RTX (mode)))
3546 : 3556550 : || (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
3547 : 393937 : && float_vector_all_ones_operand (op, mode)))
3548 : : {
3549 : 10558 : *scalar_mode_p = QImode;
3550 : 10558 : *kind_p = X86_CSE_CONSTM1_VECTOR;
3551 : 10558 : *insn_p = nullptr;
3552 : 10558 : return constm1_rtx;
3553 : : }
3554 : :
3555 : 1969951 : mode = GET_MODE (op);
3556 : 1969951 : int nunits = GET_MODE_NUNITS (mode);
3557 : 1969951 : if (nunits < 2)
3558 : : return nullptr;
3559 : :
3560 : 1499637 : *kind_p = X86_CSE_VEC_DUP;
3561 : :
3562 : 1499637 : rtx reg;
3563 : 1499637 : if (GET_CODE (op) == VEC_DUPLICATE)
3564 : : {
3565 : : /* Only
3566 : : (vec_duplicate:V4SI (reg:SI 99))
3567 : : (vec_duplicate:V2DF (mem/u/c:DF (symbol_ref/u:DI ("*.LC1") [flags 0x2]) [0 S8 A64]))
3568 : : are supported. Set OP to the broadcast source by default. */
3569 : 92246 : op = XEXP (op, 0);
3570 : 92246 : reg = op;
3571 : 92246 : if (SUBREG_P (op)
3572 : 381 : && SUBREG_BYTE (op) == 0
3573 : 92627 : && !paradoxical_subreg_p (op))
3574 : 381 : reg = SUBREG_REG (op);
3575 : 92246 : if (!REG_P (reg))
3576 : : {
3577 : 7161 : if (MEM_P (op)
3578 : 6894 : && SYMBOL_REF_P (XEXP (op, 0))
3579 : 12333 : && CONSTANT_POOL_ADDRESS_P (XEXP (op, 0)))
3580 : : {
3581 : : /* Handle constant broadcast from memory. */
3582 : 4977 : *scalar_mode_p = GET_MODE_INNER (mode);
3583 : 4977 : *insn_p = nullptr;
3584 : 4977 : return op;
3585 : : }
3586 : : return nullptr;
3587 : : }
3588 : : }
3589 : 1407391 : else if (CONST_VECTOR_P (op))
3590 : : {
3591 : 20 : rtx first = XVECEXP (op, 0, 0);
3592 : 48 : for (int i = 1; i < nunits; ++i)
3593 : : {
3594 : 48 : rtx tmp = XVECEXP (op, 0, i);
3595 : : /* Vector duplicate value. */
3596 : 48 : if (!rtx_equal_p (tmp, first))
3597 : : return nullptr;
3598 : : }
3599 : 0 : *scalar_mode_p = GET_MODE (first);
3600 : 0 : *insn_p = nullptr;
3601 : 0 : return first;
3602 : : }
3603 : : else
3604 : : return nullptr;
3605 : :
3606 : 85085 : mode = GET_MODE (op);
3607 : :
3608 : : /* Only single def chain is supported. */
3609 : 85085 : df_ref ref = DF_REG_DEF_CHAIN (REGNO (reg));
3610 : 85085 : if (!ref
3611 : 85084 : || DF_REF_IS_ARTIFICIAL (ref)
3612 : 85084 : || DF_REF_NEXT_REG (ref) != nullptr)
3613 : : return nullptr;
3614 : :
3615 : 79659 : rtx_insn *insn = DF_REF_INSN (ref);
3616 : 79659 : rtx set = single_set (insn);
3617 : 79659 : if (!set)
3618 : : return nullptr;
3619 : :
3620 : 79615 : rtx src = SET_SRC (set);
3621 : :
3622 : 79615 : if (CONST_INT_P (src))
3623 : : {
3624 : : /* Handle sequences like
3625 : :
3626 : : (set (reg:SI 99)
3627 : : (const_int 34 [0x22]))
3628 : : (set (reg:V4SI 98)
3629 : : (vec_duplicate:V4SI (reg:SI 99)))
3630 : :
3631 : : Set *INSN_P to nullptr and return SET_SRC if SET_SRC is an
3632 : : integer constant. */
3633 : 65849 : op = src;
3634 : 65849 : *insn_p = nullptr;
3635 : : }
3636 : : else
3637 : : {
3638 : : /* Handle sequences like
3639 : :
3640 : : (set (reg:QI 105 [ c ])
3641 : : (reg:QI 5 di [ c ]))
3642 : : (set (reg:V64QI 102 [ _1 ])
3643 : : (vec_duplicate:V64QI (reg:QI 105 [ c ])))
3644 : :
3645 : : (set (reg/v:SI 116 [ argc ])
3646 : : (mem/c:SI (reg:SI 135) [2 argc+0 S4 A32]))
3647 : : (set (reg:V4SI 119 [ _45 ])
3648 : : (vec_duplicate:V4SI (reg/v:SI 116 [ argc ])))
3649 : :
3650 : : (set (reg:SI 98 [ _1 ])
3651 : : (sign_extend:SI (reg:QI 106 [ c ])))
3652 : : (set (reg:V16SI 103 [ _2 ])
3653 : : (vec_duplicate:V16SI (reg:SI 98 [ _1 ])))
3654 : :
3655 : : (set (reg:SI 102 [ cost ])
3656 : : (mem/c:SI (symbol_ref:DI ("cost") [flags 0x40])))
3657 : : (set (reg:V4HI 103 [ _16 ])
3658 : : (vec_duplicate:V4HI (subreg:HI (reg:SI 102 [ cost ]) 0)))
3659 : :
3660 : : (set (subreg:SI (reg/v:HI 107 [ cr_val ]) 0)
3661 : : (ashift:SI (reg:SI 158)
3662 : : (subreg:QI (reg:SI 156 [ _2 ]) 0)))
3663 : : (set (reg:V16HI 183 [ _61 ])
3664 : : (vec_duplicate:V16HI (reg/v:HI 107 [ cr_val ])))
3665 : :
3666 : : Set *INSN_P to INSN and return the broadcast source otherwise. */
3667 : 13766 : *insn_p = insn;
3668 : : }
3669 : :
3670 : 79615 : *scalar_mode_p = mode;
3671 : 79615 : return op;
3672 : : }
3673 : :
3674 : : /* At entry of the nearest common dominator for basic blocks with vector
3675 : : CONST0_RTX and integer CONSTM1_RTX uses, generate a single widest
3676 : : vector set instruction for all CONST0_RTX and integer CONSTM1_RTX
3677 : : uses.
3678 : :
3679 : : NB: We want to generate only a single widest vector set to cover the
3680 : : whole function. The LCM algorithm isn't appropriate here since it
3681 : : may place a vector set inside the loop. */
3682 : :
3683 : : static unsigned int
3684 : 961505 : remove_redundant_vector_load (void)
3685 : : {
3686 : 961505 : timevar_push (TV_MACH_DEP);
3687 : :
3688 : 961505 : auto_vec<redundant_load *> loads;
3689 : 961505 : redundant_load *load;
3690 : 961505 : basic_block bb;
3691 : 961505 : rtx_insn *insn;
3692 : 961505 : unsigned int i;
3693 : :
3694 : 961505 : df_set_flags (DF_DEFER_INSN_RESCAN);
3695 : :
3696 : 961505 : bool recursive_call_p = cfun->machine->recursive_function;
3697 : :
3698 : 10889953 : FOR_EACH_BB_FN (bb, cfun)
3699 : : {
3700 : 130041262 : FOR_BB_INSNS (bb, insn)
3701 : : {
3702 : 120112814 : if (!NONDEBUG_INSN_P (insn))
3703 : 119997092 : continue;
3704 : :
3705 : 53846401 : rtx set = single_set (insn);
3706 : 53846401 : if (!set)
3707 : 3616840 : continue;
3708 : :
3709 : : /* Record single set vector instruction with CONST0_RTX and
3710 : : CONSTM1_RTX source. Record basic blocks with CONST0_RTX and
3711 : : CONSTM1_RTX. Count CONST0_RTX and CONSTM1_RTX. Record the
3712 : : maximum size of CONST0_RTX and CONSTM1_RTX. */
3713 : :
3714 : 50229561 : rtx dest = SET_DEST (set);
3715 : 50229561 : machine_mode mode = GET_MODE (dest);
3716 : : /* Skip non-vector instruction. */
3717 : 50229561 : if (!VECTOR_MODE_P (mode))
3718 : 46677921 : continue;
3719 : :
3720 : 3551640 : rtx src = SET_SRC (set);
3721 : : /* Skip non-vector load instruction. */
3722 : 3551640 : if (!REG_P (dest) && !SUBREG_P (dest))
3723 : 1466192 : continue;
3724 : :
3725 : 2085448 : rtx_insn *def_insn;
3726 : 2085448 : machine_mode scalar_mode;
3727 : 2085448 : x86_cse_kind kind;
3728 : 2085448 : rtx val = ix86_broadcast_inner (src, mode, &scalar_mode,
3729 : : &kind, &def_insn);
3730 : 2085448 : if (!val)
3731 : 1885359 : continue;
3732 : :
3733 : : /* Remove redundant register loads if there are more than 2
3734 : : loads will be used. */
3735 : : unsigned int threshold = 2;
3736 : :
3737 : : /* Check if there is a matching redundant vector load. */
3738 : 351549 : bool matched = false;
3739 : 351549 : FOR_EACH_VEC_ELT (loads, i, load)
3740 : 235827 : if (load->val
3741 : 235827 : && load->kind == kind
3742 : 181260 : && load->mode == scalar_mode
3743 : 171358 : && (load->bb == bb
3744 : 148491 : || kind < X86_CSE_VEC_DUP
3745 : : /* Non all 0s/1s vector load must be in the same
3746 : : basic block if it is in a recursive call. */
3747 : 95935 : || !recursive_call_p)
3748 : 405215 : && rtx_equal_p (load->val, val))
3749 : : {
3750 : : /* Record vector instruction. */
3751 : 84367 : bitmap_set_bit (load->insns, INSN_UID (insn));
3752 : :
3753 : : /* Record the maximum vector size. */
3754 : 168734 : if (load->size < GET_MODE_SIZE (mode))
3755 : 874 : load->size = GET_MODE_SIZE (mode);
3756 : :
3757 : : /* Record the basic block. */
3758 : 84367 : bitmap_set_bit (load->bbs, bb->index);
3759 : 84367 : load->count++;
3760 : 84367 : matched = true;
3761 : 84367 : break;
3762 : : }
3763 : :
3764 : 200089 : if (matched)
3765 : 84367 : continue;
3766 : :
3767 : : /* We see this vector broadcast the first time. */
3768 : 115722 : load = new redundant_load;
3769 : :
3770 : 115722 : load->val = copy_rtx (val);
3771 : 115722 : load->mode = scalar_mode;
3772 : 115722 : load->size = GET_MODE_SIZE (mode);
3773 : 115722 : load->def_insn = def_insn;
3774 : 115722 : load->count = 1;
3775 : 115722 : load->threshold = threshold;
3776 : 115722 : load->bb = BLOCK_FOR_INSN (insn);
3777 : 115722 : load->kind = kind;
3778 : :
3779 : 115722 : bitmap_set_bit (load->insns, INSN_UID (insn));
3780 : 115722 : bitmap_set_bit (load->bbs, bb->index);
3781 : :
3782 : 115722 : loads.safe_push (load);
3783 : : }
3784 : : }
3785 : :
3786 : : bool replaced = false;
3787 : : rtx reg, broadcast_source, broadcast_reg;
3788 : 1077227 : FOR_EACH_VEC_ELT (loads, i, load)
3789 : 115722 : if (load->count >= load->threshold)
3790 : : {
3791 : 30007 : machine_mode mode = ix86_get_vector_cse_mode (load->size,
3792 : : load->mode);
3793 : 30007 : broadcast_reg = gen_reg_rtx (mode);
3794 : 30007 : if (load->def_insn)
3795 : : {
3796 : : /* Replace redundant vector loads with a single vector load
3797 : : in the same basic block. */
3798 : 711 : reg = load->val;
3799 : 711 : if (load->mode != GET_MODE (reg))
3800 : 0 : reg = gen_rtx_SUBREG (load->mode, reg, 0);
3801 : 711 : broadcast_source = gen_rtx_VEC_DUPLICATE (mode, reg);
3802 : 711 : replace_vector_const (mode, broadcast_reg, load->insns,
3803 : : load->mode);
3804 : : }
3805 : : else
3806 : : {
3807 : : /* This is a constant integer/double vector. If the
3808 : : inner scalar is 0 or -1, set vector to CONST0_RTX
3809 : : or CONSTM1_RTX directly. */
3810 : 29296 : rtx reg;
3811 : 29296 : switch (load->kind)
3812 : : {
3813 : 18228 : case X86_CSE_CONST0_VECTOR:
3814 : 18228 : broadcast_source = CONST0_RTX (mode);
3815 : 18228 : break;
3816 : 1161 : case X86_CSE_CONSTM1_VECTOR:
3817 : 1161 : broadcast_source = CONSTM1_RTX (mode);
3818 : 1161 : break;
3819 : 9907 : default:
3820 : 9907 : reg = gen_reg_rtx (load->mode);
3821 : 9907 : broadcast_source = gen_rtx_VEC_DUPLICATE (mode, reg);
3822 : 9907 : break;
3823 : : }
3824 : 29296 : replace_vector_const (mode, broadcast_reg, load->insns,
3825 : : load->mode);
3826 : : }
3827 : 30007 : load->broadcast_source = broadcast_source;
3828 : 30007 : load->broadcast_reg = broadcast_reg;
3829 : 30007 : replaced = true;
3830 : : }
3831 : :
3832 : 961505 : if (replaced)
3833 : : {
3834 : 24229 : auto_vec<rtx_insn *> control_flow_insns;
3835 : :
3836 : : /* (Re-)discover loops so that bb->loop_father can be used in the
3837 : : analysis below. */
3838 : 24229 : calculate_dominance_info (CDI_DOMINATORS);
3839 : 24229 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
3840 : :
3841 : 66538 : FOR_EACH_VEC_ELT (loads, i, load)
3842 : 42309 : if (load->count >= load->threshold)
3843 : : {
3844 : 30007 : if (load->def_insn)
3845 : : {
3846 : : /* Insert a broadcast after the original scalar
3847 : : definition. */
3848 : 711 : rtx set = gen_rtx_SET (load->broadcast_reg,
3849 : : load->broadcast_source);
3850 : 711 : insn = emit_insn_after (set, load->def_insn);
3851 : :
3852 : 711 : if (cfun->can_throw_non_call_exceptions)
3853 : : {
3854 : : /* Handle REG_EH_REGION note in DEF_INSN. */
3855 : 5 : rtx note = find_reg_note (load->def_insn,
3856 : : REG_EH_REGION, nullptr);
3857 : 5 : if (note)
3858 : : {
3859 : 1 : control_flow_insns.safe_push (load->def_insn);
3860 : 1 : add_reg_note (insn, REG_EH_REGION,
3861 : : XEXP (note, 0));
3862 : : }
3863 : : }
3864 : :
3865 : 711 : if (dump_file)
3866 : : {
3867 : 0 : fprintf (dump_file, "\nAdd:\n\n");
3868 : 0 : print_rtl_single (dump_file, insn);
3869 : 0 : fprintf (dump_file, "\nafter:\n\n");
3870 : 0 : print_rtl_single (dump_file, load->def_insn);
3871 : 0 : fprintf (dump_file, "\n");
3872 : : }
3873 : : }
3874 : : else
3875 : 29296 : ix86_place_single_vector_set (load->broadcast_reg,
3876 : : load->broadcast_source,
3877 : : load->bbs,
3878 : 29296 : (load->kind == X86_CSE_VEC_DUP
3879 : : ? load->val
3880 : : : nullptr));
3881 : : }
3882 : :
3883 : 24229 : loop_optimizer_finalize ();
3884 : :
3885 : 24229 : if (!control_flow_insns.is_empty ())
3886 : : {
3887 : 1 : free_dominance_info (CDI_DOMINATORS);
3888 : :
3889 : 3 : FOR_EACH_VEC_ELT (control_flow_insns, i, insn)
3890 : 1 : if (control_flow_insn_p (insn))
3891 : : {
3892 : : /* Split the block after insn. There will be a fallthru
3893 : : edge, which is OK so we keep it. We have to create
3894 : : the exception edges ourselves. */
3895 : 1 : bb = BLOCK_FOR_INSN (insn);
3896 : 1 : split_block (bb, insn);
3897 : 1 : rtl_make_eh_edge (NULL, bb, BB_END (bb));
3898 : : }
3899 : : }
3900 : :
3901 : 24229 : df_process_deferred_rescans ();
3902 : 24229 : }
3903 : :
3904 : 961505 : df_clear_flags (DF_DEFER_INSN_RESCAN);
3905 : :
3906 : 961505 : timevar_pop (TV_MACH_DEP);
3907 : 961505 : return 0;
3908 : 961505 : }
3909 : :
3910 : : namespace {
3911 : :
3912 : : const pass_data pass_data_remove_redundant_vector_load =
3913 : : {
3914 : : RTL_PASS, /* type */
3915 : : "rrvl", /* name */
3916 : : OPTGROUP_NONE, /* optinfo_flags */
3917 : : TV_MACH_DEP, /* tv_id */
3918 : : 0, /* properties_required */
3919 : : 0, /* properties_provided */
3920 : : 0, /* properties_destroyed */
3921 : : 0, /* todo_flags_start */
3922 : : 0, /* todo_flags_finish */
3923 : : };
3924 : :
3925 : : class pass_remove_redundant_vector_load : public rtl_opt_pass
3926 : : {
3927 : : public:
3928 : 284673 : pass_remove_redundant_vector_load (gcc::context *ctxt)
3929 : 569346 : : rtl_opt_pass (pass_data_remove_redundant_vector_load, ctxt)
3930 : : {}
3931 : :
3932 : : /* opt_pass methods: */
3933 : 1449068 : bool gate (function *fun) final override
3934 : : {
3935 : 1449068 : return (TARGET_SSE2
3936 : 1444862 : && optimize
3937 : 2473129 : && optimize_function_for_speed_p (fun));
3938 : : }
3939 : :
3940 : 961505 : unsigned int execute (function *) final override
3941 : : {
3942 : 961505 : return remove_redundant_vector_load ();
3943 : : }
3944 : : }; // class pass_remove_redundant_vector_load
3945 : :
3946 : : } // anon namespace
3947 : :
3948 : : rtl_opt_pass *
3949 : 284673 : make_pass_remove_redundant_vector_load (gcc::context *ctxt)
3950 : : {
3951 : 284673 : return new pass_remove_redundant_vector_load (ctxt);
3952 : : }
3953 : :
3954 : : /* Convert legacy instructions that clobbers EFLAGS to APX_NF
3955 : : instructions when there are no flag set between a flag
3956 : : producer and user. */
3957 : :
3958 : : static unsigned int
3959 : 357 : ix86_apx_nf_convert (void)
3960 : : {
3961 : 357 : timevar_push (TV_MACH_DEP);
3962 : :
3963 : 357 : basic_block bb;
3964 : 357 : rtx_insn *insn;
3965 : 357 : hash_map <rtx_insn *, rtx> converting_map;
3966 : 357 : auto_vec <rtx_insn *> current_convert_list;
3967 : :
3968 : 357 : bool converting_seq = false;
3969 : 357 : rtx cc = gen_rtx_REG (CCmode, FLAGS_REG);
3970 : :
3971 : 758 : FOR_EACH_BB_FN (bb, cfun)
3972 : : {
3973 : : /* Reset conversion for each bb. */
3974 : 401 : converting_seq = false;
3975 : 4538 : FOR_BB_INSNS (bb, insn)
3976 : : {
3977 : 4137 : if (!NONDEBUG_INSN_P (insn))
3978 : 4505 : continue;
3979 : :
3980 : 3350 : if (recog_memoized (insn) < 0)
3981 : 330 : continue;
3982 : :
3983 : : /* Convert candidate insns after cstore, which should
3984 : : satisify the two conditions:
3985 : : 1. Is not flag user or producer, only clobbers
3986 : : FLAGS_REG.
3987 : : 2. Have corresponding nf pattern. */
3988 : :
3989 : 3020 : rtx pat = PATTERN (insn);
3990 : :
3991 : : /* Starting convertion at first cstorecc. */
3992 : 3020 : rtx set = NULL_RTX;
3993 : 3020 : if (!converting_seq
3994 : 2617 : && (set = single_set (insn))
3995 : 2558 : && ix86_comparison_operator (SET_SRC (set), VOIDmode)
3996 : 63 : && reg_overlap_mentioned_p (cc, SET_SRC (set))
3997 : 3080 : && !reg_overlap_mentioned_p (cc, SET_DEST (set)))
3998 : : {
3999 : 60 : converting_seq = true;
4000 : 60 : current_convert_list.truncate (0);
4001 : : }
4002 : : /* Terminate at the next explicit flag set. */
4003 : 2960 : else if (reg_set_p (cc, pat)
4004 : 2960 : && GET_CODE (set_of (cc, pat)) != CLOBBER)
4005 : : converting_seq = false;
4006 : :
4007 : 2868 : if (!converting_seq)
4008 : 2601 : continue;
4009 : :
4010 : 419 : if (get_attr_has_nf (insn)
4011 : 419 : && GET_CODE (pat) == PARALLEL)
4012 : : {
4013 : : /* Record the insn to candidate map. */
4014 : 17 : current_convert_list.safe_push (insn);
4015 : 17 : converting_map.put (insn, pat);
4016 : : }
4017 : : /* If the insn clobbers flags but has no nf_attr,
4018 : : revoke all previous candidates. */
4019 : 402 : else if (!get_attr_has_nf (insn)
4020 : 401 : && reg_set_p (cc, pat)
4021 : 402 : && GET_CODE (set_of (cc, pat)) == CLOBBER)
4022 : : {
4023 : 0 : for (auto item : current_convert_list)
4024 : 0 : converting_map.remove (item);
4025 : 0 : converting_seq = false;
4026 : : }
4027 : : }
4028 : : }
4029 : :
4030 : 357 : if (!converting_map.is_empty ())
4031 : : {
4032 : 25 : for (auto iter = converting_map.begin ();
4033 : 50 : iter != converting_map.end (); ++iter)
4034 : : {
4035 : 17 : rtx_insn *replace = (*iter).first;
4036 : 17 : rtx pat = (*iter).second;
4037 : 17 : int i, n = 0, len = XVECLEN (pat, 0);
4038 : 17 : rtx *new_elems = XALLOCAVEC (rtx, len);
4039 : 17 : rtx new_pat;
4040 : 51 : for (i = 0; i < len; i++)
4041 : : {
4042 : 34 : rtx temp = XVECEXP (pat, 0, i);
4043 : 51 : if (! (GET_CODE (temp) == CLOBBER
4044 : 17 : && reg_overlap_mentioned_p (cc,
4045 : 17 : XEXP (temp, 0))))
4046 : : {
4047 : 17 : new_elems[n] = temp;
4048 : 17 : n++;
4049 : : }
4050 : : }
4051 : :
4052 : 17 : if (n == 1)
4053 : 17 : new_pat = new_elems[0];
4054 : : else
4055 : 0 : new_pat =
4056 : 0 : gen_rtx_PARALLEL (VOIDmode,
4057 : : gen_rtvec_v (n,
4058 : : new_elems));
4059 : :
4060 : 17 : PATTERN (replace) = new_pat;
4061 : 17 : INSN_CODE (replace) = -1;
4062 : 17 : recog_memoized (replace);
4063 : 17 : df_insn_rescan (replace);
4064 : : }
4065 : : }
4066 : :
4067 : 357 : timevar_pop (TV_MACH_DEP);
4068 : 357 : return 0;
4069 : 357 : }
4070 : :
4071 : :
4072 : : namespace {
4073 : :
4074 : : const pass_data pass_data_apx_nf_convert =
4075 : : {
4076 : : RTL_PASS, /* type */
4077 : : "apx_nfcvt", /* name */
4078 : : OPTGROUP_NONE, /* optinfo_flags */
4079 : : TV_MACH_DEP, /* tv_id */
4080 : : 0, /* properties_required */
4081 : : 0, /* properties_provided */
4082 : : 0, /* properties_destroyed */
4083 : : 0, /* todo_flags_start */
4084 : : 0, /* todo_flags_finish */
4085 : : };
4086 : :
4087 : : class pass_apx_nf_convert : public rtl_opt_pass
4088 : : {
4089 : : public:
4090 : 284673 : pass_apx_nf_convert (gcc::context *ctxt)
4091 : 569346 : : rtl_opt_pass (pass_data_apx_nf_convert, ctxt)
4092 : : {}
4093 : :
4094 : : /* opt_pass methods: */
4095 : 1449068 : bool gate (function *) final override
4096 : : {
4097 : 1449068 : return (TARGET_APX_NF
4098 : 448 : && optimize
4099 : 1449508 : && optimize_function_for_speed_p (cfun));
4100 : : }
4101 : :
4102 : 357 : unsigned int execute (function *) final override
4103 : : {
4104 : 357 : return ix86_apx_nf_convert ();
4105 : : }
4106 : : }; // class pass_apx_nf_convert
4107 : :
4108 : : } // anon namespace
4109 : :
4110 : : rtl_opt_pass *
4111 : 284673 : make_pass_apx_nf_convert (gcc::context *ctxt)
4112 : : {
4113 : 284673 : return new pass_apx_nf_convert (ctxt);
4114 : : }
4115 : :
4116 : : /* When a hot loop can be fit into one cacheline,
4117 : : force align the loop without considering the max skip. */
4118 : : static void
4119 : 963329 : ix86_align_loops ()
4120 : : {
4121 : 963329 : basic_block bb;
4122 : :
4123 : : /* Don't do this when we don't know cache line size. */
4124 : 963329 : if (ix86_cost->prefetch_block == 0)
4125 : 9 : return;
4126 : :
4127 : 963320 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
4128 : 963320 : profile_count count_threshold = cfun->cfg->count_max / param_align_threshold;
4129 : 11351677 : FOR_EACH_BB_FN (bb, cfun)
4130 : : {
4131 : 10388357 : rtx_insn *label = BB_HEAD (bb);
4132 : 10388357 : bool has_fallthru = 0;
4133 : 10388357 : edge e;
4134 : 10388357 : edge_iterator ei;
4135 : :
4136 : 10388357 : if (!LABEL_P (label))
4137 : 5253100 : continue;
4138 : :
4139 : 5140278 : profile_count fallthru_count = profile_count::zero ();
4140 : 5140278 : profile_count branch_count = profile_count::zero ();
4141 : :
4142 : 14904754 : FOR_EACH_EDGE (e, ei, bb->preds)
4143 : : {
4144 : 9764476 : if (e->flags & EDGE_FALLTHRU)
4145 : 2491333 : has_fallthru = 1, fallthru_count += e->count ();
4146 : : else
4147 : 7273143 : branch_count += e->count ();
4148 : : }
4149 : :
4150 : 5140278 : if (!fallthru_count.initialized_p () || !branch_count.initialized_p ())
4151 : 5021 : continue;
4152 : :
4153 : 5135257 : if (bb->loop_father
4154 : 5135257 : && bb->loop_father->latch != EXIT_BLOCK_PTR_FOR_FN (cfun)
4155 : 6440535 : && (has_fallthru
4156 : 1305278 : ? (!(single_succ_p (bb)
4157 : 138692 : && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun))
4158 : 912143 : && optimize_bb_for_speed_p (bb)
4159 : 827404 : && branch_count + fallthru_count > count_threshold
4160 : 717071 : && (branch_count > fallthru_count * param_align_loop_iterations))
4161 : : /* In case there'no fallthru for the loop.
4162 : : Nops inserted won't be executed. */
4163 : 393135 : : (branch_count > count_threshold
4164 : 130593 : || (bb->count > bb->prev_bb->count * 10
4165 : 12506 : && (bb->prev_bb->count
4166 : 4611565 : <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count / 2)))))
4167 : : {
4168 : 536198 : rtx_insn* insn, *end_insn;
4169 : 536198 : HOST_WIDE_INT size = 0;
4170 : 536198 : bool padding_p = true;
4171 : 536198 : basic_block tbb = bb;
4172 : 536198 : unsigned cond_branch_num = 0;
4173 : 536198 : bool detect_tight_loop_p = false;
4174 : :
4175 : 844924 : for (unsigned int i = 0; i != bb->loop_father->num_nodes;
4176 : 308726 : i++, tbb = tbb->next_bb)
4177 : : {
4178 : : /* Only handle continuous cfg layout. */
4179 : 844924 : if (bb->loop_father != tbb->loop_father)
4180 : : {
4181 : : padding_p = false;
4182 : : break;
4183 : : }
4184 : :
4185 : 9878526 : FOR_BB_INSNS (tbb, insn)
4186 : : {
4187 : 9233960 : if (!NONDEBUG_INSN_P (insn))
4188 : 5200019 : continue;
4189 : 4033941 : size += ix86_min_insn_size (insn);
4190 : :
4191 : : /* We don't know size of inline asm.
4192 : : Don't align loop for call. */
4193 : 4033941 : if (asm_noperands (PATTERN (insn)) >= 0
4194 : 4033941 : || CALL_P (insn))
4195 : : {
4196 : : size = -1;
4197 : : break;
4198 : : }
4199 : : }
4200 : :
4201 : 804544 : if (size == -1 || size > ix86_cost->prefetch_block)
4202 : : {
4203 : : padding_p = false;
4204 : : break;
4205 : : }
4206 : :
4207 : 1415316 : FOR_EACH_EDGE (e, ei, tbb->succs)
4208 : : {
4209 : : /* It could be part of the loop. */
4210 : 973870 : if (e->dest == bb)
4211 : : {
4212 : : detect_tight_loop_p = true;
4213 : : break;
4214 : : }
4215 : : }
4216 : :
4217 : 616518 : if (detect_tight_loop_p)
4218 : : break;
4219 : :
4220 : 441446 : end_insn = BB_END (tbb);
4221 : 441446 : if (JUMP_P (end_insn))
4222 : : {
4223 : : /* For decoded icache:
4224 : : 1. Up to two branches are allowed per Way.
4225 : : 2. A non-conditional branch is the last micro-op in a Way.
4226 : : */
4227 : 354395 : if (onlyjump_p (end_insn)
4228 : 354395 : && (any_uncondjump_p (end_insn)
4229 : 301581 : || single_succ_p (tbb)))
4230 : : {
4231 : : padding_p = false;
4232 : : break;
4233 : : }
4234 : 301581 : else if (++cond_branch_num >= 2)
4235 : : {
4236 : : padding_p = false;
4237 : : break;
4238 : : }
4239 : : }
4240 : :
4241 : : }
4242 : :
4243 : 536198 : if (padding_p && detect_tight_loop_p)
4244 : : {
4245 : 350144 : emit_insn_before (gen_max_skip_align (GEN_INT (ceil_log2 (size)),
4246 : : GEN_INT (0)), label);
4247 : : /* End of function. */
4248 : 175072 : if (!tbb || tbb == EXIT_BLOCK_PTR_FOR_FN (cfun))
4249 : : break;
4250 : : /* Skip bb which already fits into one cacheline. */
4251 : : bb = tbb;
4252 : : }
4253 : : }
4254 : : }
4255 : :
4256 : 963320 : loop_optimizer_finalize ();
4257 : 963320 : free_dominance_info (CDI_DOMINATORS);
4258 : : }
4259 : :
4260 : : namespace {
4261 : :
4262 : : const pass_data pass_data_align_tight_loops =
4263 : : {
4264 : : RTL_PASS, /* type */
4265 : : "align_tight_loops", /* name */
4266 : : OPTGROUP_NONE, /* optinfo_flags */
4267 : : TV_MACH_DEP, /* tv_id */
4268 : : 0, /* properties_required */
4269 : : 0, /* properties_provided */
4270 : : 0, /* properties_destroyed */
4271 : : 0, /* todo_flags_start */
4272 : : 0, /* todo_flags_finish */
4273 : : };
4274 : :
4275 : : class pass_align_tight_loops : public rtl_opt_pass
4276 : : {
4277 : : public:
4278 : 284673 : pass_align_tight_loops (gcc::context *ctxt)
4279 : 569346 : : rtl_opt_pass (pass_data_align_tight_loops, ctxt)
4280 : : {}
4281 : :
4282 : : /* opt_pass methods: */
4283 : 1449068 : bool gate (function *) final override
4284 : : {
4285 : 1449068 : return TARGET_ALIGN_TIGHT_LOOPS
4286 : 1448599 : && optimize
4287 : 2474997 : && optimize_function_for_speed_p (cfun);
4288 : : }
4289 : :
4290 : 963329 : unsigned int execute (function *) final override
4291 : : {
4292 : 963329 : timevar_push (TV_MACH_DEP);
4293 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
4294 : 963329 : ix86_align_loops ();
4295 : : #endif
4296 : 963329 : timevar_pop (TV_MACH_DEP);
4297 : 963329 : return 0;
4298 : : }
4299 : : }; // class pass_align_tight_loops
4300 : :
4301 : : } // anon namespace
4302 : :
4303 : : rtl_opt_pass *
4304 : 284673 : make_pass_align_tight_loops (gcc::context *ctxt)
4305 : : {
4306 : 284673 : return new pass_align_tight_loops (ctxt);
4307 : : }
4308 : :
4309 : : /* This compares the priority of target features in function DECL1
4310 : : and DECL2. It returns positive value if DECL1 is higher priority,
4311 : : negative value if DECL2 is higher priority and 0 if they are the
4312 : : same. */
4313 : :
4314 : : int
4315 : 5318 : ix86_compare_version_priority (tree decl1, tree decl2)
4316 : : {
4317 : 5318 : unsigned int priority1 = get_builtin_code_for_version (decl1, NULL);
4318 : 5318 : unsigned int priority2 = get_builtin_code_for_version (decl2, NULL);
4319 : :
4320 : 5318 : return (int)priority1 - (int)priority2;
4321 : : }
4322 : :
4323 : : /* V1 and V2 point to function versions with different priorities
4324 : : based on the target ISA. This function compares their priorities. */
4325 : :
4326 : : static int
4327 : 6647 : feature_compare (const void *v1, const void *v2)
4328 : : {
4329 : 6647 : typedef struct _function_version_info
4330 : : {
4331 : : tree version_decl;
4332 : : tree predicate_chain;
4333 : : unsigned int dispatch_priority;
4334 : : } function_version_info;
4335 : :
4336 : 6647 : const function_version_info c1 = *(const function_version_info *)v1;
4337 : 6647 : const function_version_info c2 = *(const function_version_info *)v2;
4338 : 6647 : return (c2.dispatch_priority - c1.dispatch_priority);
4339 : : }
4340 : :
4341 : : /* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL
4342 : : to return a pointer to VERSION_DECL if the outcome of the expression
4343 : : formed by PREDICATE_CHAIN is true. This function will be called during
4344 : : version dispatch to decide which function version to execute. It returns
4345 : : the basic block at the end, to which more conditions can be added. */
4346 : :
4347 : : static basic_block
4348 : 812 : add_condition_to_bb (tree function_decl, tree version_decl,
4349 : : tree predicate_chain, basic_block new_bb)
4350 : : {
4351 : 812 : gimple *return_stmt;
4352 : 812 : tree convert_expr, result_var;
4353 : 812 : gimple *convert_stmt;
4354 : 812 : gimple *call_cond_stmt;
4355 : 812 : gimple *if_else_stmt;
4356 : :
4357 : 812 : basic_block bb1, bb2, bb3;
4358 : 812 : edge e12, e23;
4359 : :
4360 : 812 : tree cond_var, and_expr_var = NULL_TREE;
4361 : 812 : gimple_seq gseq;
4362 : :
4363 : 812 : tree predicate_decl, predicate_arg;
4364 : :
4365 : 812 : push_cfun (DECL_STRUCT_FUNCTION (function_decl));
4366 : :
4367 : 812 : gcc_assert (new_bb != NULL);
4368 : 812 : gseq = bb_seq (new_bb);
4369 : :
4370 : :
4371 : 812 : convert_expr = build1 (CONVERT_EXPR, ptr_type_node,
4372 : : build_fold_addr_expr (version_decl));
4373 : 812 : result_var = create_tmp_var (ptr_type_node);
4374 : 812 : convert_stmt = gimple_build_assign (result_var, convert_expr);
4375 : 812 : return_stmt = gimple_build_return (result_var);
4376 : :
4377 : 812 : if (predicate_chain == NULL_TREE)
4378 : : {
4379 : 195 : gimple_seq_add_stmt (&gseq, convert_stmt);
4380 : 195 : gimple_seq_add_stmt (&gseq, return_stmt);
4381 : 195 : set_bb_seq (new_bb, gseq);
4382 : 195 : gimple_set_bb (convert_stmt, new_bb);
4383 : 195 : gimple_set_bb (return_stmt, new_bb);
4384 : 195 : pop_cfun ();
4385 : 195 : return new_bb;
4386 : : }
4387 : :
4388 : 1273 : while (predicate_chain != NULL)
4389 : : {
4390 : 656 : cond_var = create_tmp_var (integer_type_node);
4391 : 656 : predicate_decl = TREE_PURPOSE (predicate_chain);
4392 : 656 : predicate_arg = TREE_VALUE (predicate_chain);
4393 : 656 : call_cond_stmt = gimple_build_call (predicate_decl, 1, predicate_arg);
4394 : 656 : gimple_call_set_lhs (call_cond_stmt, cond_var);
4395 : :
4396 : 656 : gimple_set_block (call_cond_stmt, DECL_INITIAL (function_decl));
4397 : 656 : gimple_set_bb (call_cond_stmt, new_bb);
4398 : 656 : gimple_seq_add_stmt (&gseq, call_cond_stmt);
4399 : :
4400 : 656 : predicate_chain = TREE_CHAIN (predicate_chain);
4401 : :
4402 : 656 : if (and_expr_var == NULL)
4403 : : and_expr_var = cond_var;
4404 : : else
4405 : : {
4406 : 39 : gimple *assign_stmt;
4407 : : /* Use MIN_EXPR to check if any integer is zero?.
4408 : : and_expr_var = min_expr <cond_var, and_expr_var> */
4409 : 39 : assign_stmt = gimple_build_assign (and_expr_var,
4410 : : build2 (MIN_EXPR, integer_type_node,
4411 : : cond_var, and_expr_var));
4412 : :
4413 : 39 : gimple_set_block (assign_stmt, DECL_INITIAL (function_decl));
4414 : 39 : gimple_set_bb (assign_stmt, new_bb);
4415 : 39 : gimple_seq_add_stmt (&gseq, assign_stmt);
4416 : : }
4417 : : }
4418 : :
4419 : 617 : if_else_stmt = gimple_build_cond (GT_EXPR, and_expr_var,
4420 : : integer_zero_node,
4421 : : NULL_TREE, NULL_TREE);
4422 : 617 : gimple_set_block (if_else_stmt, DECL_INITIAL (function_decl));
4423 : 617 : gimple_set_bb (if_else_stmt, new_bb);
4424 : 617 : gimple_seq_add_stmt (&gseq, if_else_stmt);
4425 : :
4426 : 617 : gimple_seq_add_stmt (&gseq, convert_stmt);
4427 : 617 : gimple_seq_add_stmt (&gseq, return_stmt);
4428 : 617 : set_bb_seq (new_bb, gseq);
4429 : :
4430 : 617 : bb1 = new_bb;
4431 : 617 : e12 = split_block (bb1, if_else_stmt);
4432 : 617 : bb2 = e12->dest;
4433 : 617 : e12->flags &= ~EDGE_FALLTHRU;
4434 : 617 : e12->flags |= EDGE_TRUE_VALUE;
4435 : :
4436 : 617 : e23 = split_block (bb2, return_stmt);
4437 : :
4438 : 617 : gimple_set_bb (convert_stmt, bb2);
4439 : 617 : gimple_set_bb (return_stmt, bb2);
4440 : :
4441 : 617 : bb3 = e23->dest;
4442 : 617 : make_edge (bb1, bb3, EDGE_FALSE_VALUE);
4443 : :
4444 : 617 : remove_edge (e23);
4445 : 617 : make_edge (bb2, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
4446 : :
4447 : 617 : pop_cfun ();
4448 : :
4449 : 617 : return bb3;
4450 : : }
4451 : :
4452 : : /* This function generates the dispatch function for
4453 : : multi-versioned functions. DISPATCH_DECL is the function which will
4454 : : contain the dispatch logic. FNDECLS are the function choices for
4455 : : dispatch, and is a tree chain. EMPTY_BB is the basic block pointer
4456 : : in DISPATCH_DECL in which the dispatch code is generated. */
4457 : :
4458 : : static int
4459 : 195 : dispatch_function_versions (tree dispatch_decl,
4460 : : void *fndecls_p,
4461 : : basic_block *empty_bb)
4462 : : {
4463 : 195 : tree default_decl;
4464 : 195 : gimple *ifunc_cpu_init_stmt;
4465 : 195 : gimple_seq gseq;
4466 : 195 : int ix;
4467 : 195 : tree ele;
4468 : 195 : vec<tree> *fndecls;
4469 : 195 : unsigned int num_versions = 0;
4470 : 195 : unsigned int actual_versions = 0;
4471 : 195 : unsigned int i;
4472 : :
4473 : 195 : struct _function_version_info
4474 : : {
4475 : : tree version_decl;
4476 : : tree predicate_chain;
4477 : : unsigned int dispatch_priority;
4478 : : }*function_version_info;
4479 : :
4480 : 195 : gcc_assert (dispatch_decl != NULL
4481 : : && fndecls_p != NULL
4482 : : && empty_bb != NULL);
4483 : :
4484 : : /*fndecls_p is actually a vector. */
4485 : 195 : fndecls = static_cast<vec<tree> *> (fndecls_p);
4486 : :
4487 : : /* At least one more version other than the default. */
4488 : 195 : num_versions = fndecls->length ();
4489 : 195 : gcc_assert (num_versions >= 2);
4490 : :
4491 : 195 : function_version_info = (struct _function_version_info *)
4492 : 195 : XNEWVEC (struct _function_version_info, (num_versions - 1));
4493 : :
4494 : : /* The first version in the vector is the default decl. */
4495 : 195 : default_decl = (*fndecls)[0];
4496 : :
4497 : 195 : push_cfun (DECL_STRUCT_FUNCTION (dispatch_decl));
4498 : :
4499 : 195 : gseq = bb_seq (*empty_bb);
4500 : : /* Function version dispatch is via IFUNC. IFUNC resolvers fire before
4501 : : constructors, so explicity call __builtin_cpu_init here. */
4502 : 195 : ifunc_cpu_init_stmt
4503 : 195 : = gimple_build_call_vec (get_ix86_builtin (IX86_BUILTIN_CPU_INIT), vNULL);
4504 : 195 : gimple_seq_add_stmt (&gseq, ifunc_cpu_init_stmt);
4505 : 195 : gimple_set_bb (ifunc_cpu_init_stmt, *empty_bb);
4506 : 195 : set_bb_seq (*empty_bb, gseq);
4507 : :
4508 : 195 : pop_cfun ();
4509 : :
4510 : :
4511 : 966 : for (ix = 1; fndecls->iterate (ix, &ele); ++ix)
4512 : : {
4513 : 771 : tree version_decl = ele;
4514 : 771 : tree predicate_chain = NULL_TREE;
4515 : 771 : unsigned int priority;
4516 : : /* Get attribute string, parse it and find the right predicate decl.
4517 : : The predicate function could be a lengthy combination of many
4518 : : features, like arch-type and various isa-variants. */
4519 : 771 : priority = get_builtin_code_for_version (version_decl,
4520 : : &predicate_chain);
4521 : :
4522 : 771 : if (predicate_chain == NULL_TREE)
4523 : 154 : continue;
4524 : :
4525 : 617 : function_version_info [actual_versions].version_decl = version_decl;
4526 : 617 : function_version_info [actual_versions].predicate_chain
4527 : 617 : = predicate_chain;
4528 : 617 : function_version_info [actual_versions].dispatch_priority = priority;
4529 : 617 : actual_versions++;
4530 : : }
4531 : :
4532 : : /* Sort the versions according to descending order of dispatch priority. The
4533 : : priority is based on the ISA. This is not a perfect solution. There
4534 : : could still be ambiguity. If more than one function version is suitable
4535 : : to execute, which one should be dispatched? In future, allow the user
4536 : : to specify a dispatch priority next to the version. */
4537 : 195 : qsort (function_version_info, actual_versions,
4538 : : sizeof (struct _function_version_info), feature_compare);
4539 : :
4540 : 1007 : for (i = 0; i < actual_versions; ++i)
4541 : 617 : *empty_bb = add_condition_to_bb (dispatch_decl,
4542 : : function_version_info[i].version_decl,
4543 : 617 : function_version_info[i].predicate_chain,
4544 : : *empty_bb);
4545 : :
4546 : : /* dispatch default version at the end. */
4547 : 195 : *empty_bb = add_condition_to_bb (dispatch_decl, default_decl,
4548 : : NULL, *empty_bb);
4549 : :
4550 : 195 : free (function_version_info);
4551 : 195 : return 0;
4552 : : }
4553 : :
4554 : : /* This function changes the assembler name for functions that are
4555 : : versions. If DECL is a function version and has a "target"
4556 : : attribute, it appends the attribute string to its assembler name. */
4557 : :
4558 : : static tree
4559 : 825 : ix86_mangle_function_version_assembler_name (tree decl, tree id)
4560 : : {
4561 : 825 : tree version_attr;
4562 : 825 : const char *orig_name, *version_string;
4563 : 825 : char *attr_str, *assembler_name;
4564 : :
4565 : 825 : if (DECL_DECLARED_INLINE_P (decl)
4566 : 879 : && lookup_attribute ("gnu_inline",
4567 : 54 : DECL_ATTRIBUTES (decl)))
4568 : 0 : error_at (DECL_SOURCE_LOCATION (decl),
4569 : : "function versions cannot be marked as %<gnu_inline%>,"
4570 : : " bodies have to be generated");
4571 : :
4572 : 825 : if (DECL_VIRTUAL_P (decl)
4573 : 1650 : || DECL_VINDEX (decl))
4574 : 0 : sorry ("virtual function multiversioning not supported");
4575 : :
4576 : 825 : version_attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
4577 : :
4578 : : /* target attribute string cannot be NULL. */
4579 : 825 : gcc_assert (version_attr != NULL_TREE);
4580 : :
4581 : 825 : orig_name = IDENTIFIER_POINTER (id);
4582 : 825 : version_string
4583 : 825 : = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (version_attr)));
4584 : :
4585 : 825 : if (strcmp (version_string, "default") == 0)
4586 : : return id;
4587 : :
4588 : 678 : attr_str = sorted_attr_string (TREE_VALUE (version_attr));
4589 : 678 : assembler_name = XNEWVEC (char, strlen (orig_name) + strlen (attr_str) + 2);
4590 : :
4591 : 678 : sprintf (assembler_name, "%s.%s", orig_name, attr_str);
4592 : :
4593 : : /* Allow assembler name to be modified if already set. */
4594 : 678 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
4595 : 12 : SET_DECL_RTL (decl, NULL);
4596 : :
4597 : 678 : tree ret = get_identifier (assembler_name);
4598 : 678 : XDELETEVEC (attr_str);
4599 : 678 : XDELETEVEC (assembler_name);
4600 : 678 : return ret;
4601 : : }
4602 : :
4603 : : tree
4604 : 441723589 : ix86_mangle_decl_assembler_name (tree decl, tree id)
4605 : : {
4606 : : /* For function version, add the target suffix to the assembler name. */
4607 : 441723589 : if (TREE_CODE (decl) == FUNCTION_DECL
4608 : 441723589 : && DECL_FUNCTION_VERSIONED (decl))
4609 : 825 : id = ix86_mangle_function_version_assembler_name (decl, id);
4610 : : #ifdef SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME
4611 : : id = SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME (decl, id);
4612 : : #endif
4613 : :
4614 : 441723589 : return id;
4615 : : }
4616 : :
4617 : : /* Make a dispatcher declaration for the multi-versioned function DECL.
4618 : : Calls to DECL function will be replaced with calls to the dispatcher
4619 : : by the front-end. Returns the decl of the dispatcher function. */
4620 : :
4621 : : tree
4622 : 321 : ix86_get_function_versions_dispatcher (void *decl)
4623 : : {
4624 : 321 : tree fn = (tree) decl;
4625 : 321 : struct cgraph_node *node = NULL;
4626 : 321 : struct cgraph_node *default_node = NULL;
4627 : 321 : struct cgraph_function_version_info *node_v = NULL;
4628 : :
4629 : 321 : tree dispatch_decl = NULL;
4630 : :
4631 : 321 : struct cgraph_function_version_info *default_version_info = NULL;
4632 : :
4633 : 642 : gcc_assert (fn != NULL && DECL_FUNCTION_VERSIONED (fn));
4634 : :
4635 : 321 : node = cgraph_node::get (fn);
4636 : 321 : gcc_assert (node != NULL);
4637 : :
4638 : 321 : node_v = node->function_version ();
4639 : 321 : gcc_assert (node_v != NULL);
4640 : :
4641 : 321 : if (node_v->dispatcher_resolver != NULL)
4642 : : return node_v->dispatcher_resolver;
4643 : :
4644 : : /* The default node is always the beginning of the chain. */
4645 : : default_version_info = node_v;
4646 : 651 : while (default_version_info->prev != NULL)
4647 : : default_version_info = default_version_info->prev;
4648 : 207 : default_node = default_version_info->this_node;
4649 : :
4650 : : /* If there is no default node, just return NULL. */
4651 : 207 : if (!is_function_default_version (default_node->decl))
4652 : : return NULL;
4653 : :
4654 : : #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
4655 : 198 : if (targetm.has_ifunc_p ())
4656 : : {
4657 : 198 : struct cgraph_function_version_info *it_v = NULL;
4658 : 198 : struct cgraph_node *dispatcher_node = NULL;
4659 : 198 : struct cgraph_function_version_info *dispatcher_version_info = NULL;
4660 : :
4661 : : /* Right now, the dispatching is done via ifunc. */
4662 : 198 : dispatch_decl = make_dispatcher_decl (default_node->decl);
4663 : 198 : TREE_NOTHROW (dispatch_decl) = TREE_NOTHROW (fn);
4664 : :
4665 : 198 : dispatcher_node = cgraph_node::get_create (dispatch_decl);
4666 : 198 : gcc_assert (dispatcher_node != NULL);
4667 : 198 : dispatcher_node->dispatcher_function = 1;
4668 : 198 : dispatcher_version_info
4669 : 198 : = dispatcher_node->insert_new_function_version ();
4670 : 198 : dispatcher_version_info->next = default_version_info;
4671 : 198 : dispatcher_node->definition = 1;
4672 : :
4673 : : /* Set the dispatcher for all the versions. */
4674 : 198 : it_v = default_version_info;
4675 : 1170 : while (it_v != NULL)
4676 : : {
4677 : 972 : it_v->dispatcher_resolver = dispatch_decl;
4678 : 972 : it_v = it_v->next;
4679 : : }
4680 : : }
4681 : : else
4682 : : #endif
4683 : : {
4684 : 0 : error_at (DECL_SOURCE_LOCATION (default_node->decl),
4685 : : "multiversioning needs %<ifunc%> which is not supported "
4686 : : "on this target");
4687 : : }
4688 : :
4689 : : return dispatch_decl;
4690 : : }
4691 : :
4692 : : /* Make the resolver function decl to dispatch the versions of
4693 : : a multi-versioned function, DEFAULT_DECL. IFUNC_ALIAS_DECL is
4694 : : ifunc alias that will point to the created resolver. Create an
4695 : : empty basic block in the resolver and store the pointer in
4696 : : EMPTY_BB. Return the decl of the resolver function. */
4697 : :
4698 : : static tree
4699 : 195 : make_resolver_func (const tree default_decl,
4700 : : const tree ifunc_alias_decl,
4701 : : basic_block *empty_bb)
4702 : : {
4703 : 195 : tree decl, type, t;
4704 : :
4705 : : /* Create resolver function name based on default_decl. */
4706 : 195 : tree decl_name = clone_function_name (default_decl, "resolver");
4707 : 195 : const char *resolver_name = IDENTIFIER_POINTER (decl_name);
4708 : :
4709 : : /* The resolver function should return a (void *). */
4710 : 195 : type = build_function_type_list (ptr_type_node, NULL_TREE);
4711 : :
4712 : 195 : decl = build_fn_decl (resolver_name, type);
4713 : 195 : SET_DECL_ASSEMBLER_NAME (decl, decl_name);
4714 : :
4715 : 195 : DECL_NAME (decl) = decl_name;
4716 : 195 : TREE_USED (decl) = 1;
4717 : 195 : DECL_ARTIFICIAL (decl) = 1;
4718 : 195 : DECL_IGNORED_P (decl) = 1;
4719 : 195 : TREE_PUBLIC (decl) = 0;
4720 : 195 : DECL_UNINLINABLE (decl) = 1;
4721 : :
4722 : : /* Resolver is not external, body is generated. */
4723 : 195 : DECL_EXTERNAL (decl) = 0;
4724 : 195 : DECL_EXTERNAL (ifunc_alias_decl) = 0;
4725 : :
4726 : 195 : DECL_CONTEXT (decl) = NULL_TREE;
4727 : 195 : DECL_INITIAL (decl) = make_node (BLOCK);
4728 : 195 : DECL_STATIC_CONSTRUCTOR (decl) = 0;
4729 : :
4730 : 195 : if (DECL_COMDAT_GROUP (default_decl)
4731 : 195 : || TREE_PUBLIC (default_decl))
4732 : : {
4733 : : /* In this case, each translation unit with a call to this
4734 : : versioned function will put out a resolver. Ensure it
4735 : : is comdat to keep just one copy. */
4736 : 171 : DECL_COMDAT (decl) = 1;
4737 : 171 : make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
4738 : : }
4739 : : else
4740 : 24 : TREE_PUBLIC (ifunc_alias_decl) = 0;
4741 : :
4742 : : /* Build result decl and add to function_decl. */
4743 : 195 : t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node);
4744 : 195 : DECL_CONTEXT (t) = decl;
4745 : 195 : DECL_ARTIFICIAL (t) = 1;
4746 : 195 : DECL_IGNORED_P (t) = 1;
4747 : 195 : DECL_RESULT (decl) = t;
4748 : :
4749 : 195 : gimplify_function_tree (decl);
4750 : 195 : push_cfun (DECL_STRUCT_FUNCTION (decl));
4751 : 195 : *empty_bb = init_lowered_empty_function (decl, false,
4752 : : profile_count::uninitialized ());
4753 : :
4754 : 195 : cgraph_node::add_new_function (decl, true);
4755 : 195 : symtab->call_cgraph_insertion_hooks (cgraph_node::get_create (decl));
4756 : :
4757 : 195 : pop_cfun ();
4758 : :
4759 : 195 : gcc_assert (ifunc_alias_decl != NULL);
4760 : : /* Mark ifunc_alias_decl as "ifunc" with resolver as resolver_name. */
4761 : 195 : DECL_ATTRIBUTES (ifunc_alias_decl)
4762 : 195 : = make_attribute ("ifunc", resolver_name,
4763 : 195 : DECL_ATTRIBUTES (ifunc_alias_decl));
4764 : :
4765 : : /* Create the alias for dispatch to resolver here. */
4766 : 195 : cgraph_node::create_same_body_alias (ifunc_alias_decl, decl);
4767 : 195 : return decl;
4768 : : }
4769 : :
4770 : : /* Generate the dispatching code body to dispatch multi-versioned function
4771 : : DECL. The target hook is called to process the "target" attributes and
4772 : : provide the code to dispatch the right function at run-time. NODE points
4773 : : to the dispatcher decl whose body will be created. */
4774 : :
4775 : : tree
4776 : 195 : ix86_generate_version_dispatcher_body (void *node_p)
4777 : : {
4778 : 195 : tree resolver_decl;
4779 : 195 : basic_block empty_bb;
4780 : 195 : tree default_ver_decl;
4781 : 195 : struct cgraph_node *versn;
4782 : 195 : struct cgraph_node *node;
4783 : :
4784 : 195 : struct cgraph_function_version_info *node_version_info = NULL;
4785 : 195 : struct cgraph_function_version_info *versn_info = NULL;
4786 : :
4787 : 195 : node = (cgraph_node *)node_p;
4788 : :
4789 : 195 : node_version_info = node->function_version ();
4790 : 195 : gcc_assert (node->dispatcher_function
4791 : : && node_version_info != NULL);
4792 : :
4793 : 195 : if (node_version_info->dispatcher_resolver)
4794 : : return node_version_info->dispatcher_resolver;
4795 : :
4796 : : /* The first version in the chain corresponds to the default version. */
4797 : 195 : default_ver_decl = node_version_info->next->this_node->decl;
4798 : :
4799 : : /* node is going to be an alias, so remove the finalized bit. */
4800 : 195 : node->definition = false;
4801 : :
4802 : 195 : resolver_decl = make_resolver_func (default_ver_decl,
4803 : : node->decl, &empty_bb);
4804 : :
4805 : 195 : node_version_info->dispatcher_resolver = resolver_decl;
4806 : :
4807 : 195 : push_cfun (DECL_STRUCT_FUNCTION (resolver_decl));
4808 : :
4809 : 195 : auto_vec<tree, 2> fn_ver_vec;
4810 : :
4811 : 1161 : for (versn_info = node_version_info->next; versn_info;
4812 : 966 : versn_info = versn_info->next)
4813 : : {
4814 : 966 : versn = versn_info->this_node;
4815 : : /* Check for virtual functions here again, as by this time it should
4816 : : have been determined if this function needs a vtable index or
4817 : : not. This happens for methods in derived classes that override
4818 : : virtual methods in base classes but are not explicitly marked as
4819 : : virtual. */
4820 : 966 : if (DECL_VINDEX (versn->decl))
4821 : 0 : sorry ("virtual function multiversioning not supported");
4822 : :
4823 : 966 : fn_ver_vec.safe_push (versn->decl);
4824 : : }
4825 : :
4826 : 195 : dispatch_function_versions (resolver_decl, &fn_ver_vec, &empty_bb);
4827 : 195 : cgraph_edge::rebuild_edges ();
4828 : 195 : pop_cfun ();
4829 : 195 : return resolver_decl;
4830 : 195 : }
4831 : :
4832 : :
|