1 ;;- Machine description for Renesas / SuperH SH.
2 ;; Copyright (C) 1993-2024 Free Software Foundation, Inc.
3 ;; Contributed by Steve Chamberlain (sac@cygnus.com).
4 ;; Improved by Jim Wilson (wilson@cygnus.com).
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
23 ;; ??? Should prepend a * to all pattern names which are not used.
24 ;; This will make the compiler smaller, and rebuilds after changes faster.
26 ;; ??? Should be enhanced to include support for many more GNU superoptimizer
27 ;; sequences. Especially the sequences for arithmetic right shifts.
29 ;; ??? Should check all DImode patterns for consistency and usefulness.
31 ;; ??? The MAC.W and MAC.L instructions are not supported. There is no
32 ;; way to generate them.
34 ;; BSR is not generated by the compiler proper, but when relaxing, it
35 ;; generates .uses pseudo-ops that allow linker relaxation to create
36 ;; BSR. This is actually implemented in bfd/{coff,elf32}-sh.c
38 ;; Special constraints for SH machine description:
45 ;; Special formats used for outputting SH instructions:
47 ;; %. -- print a .s if insn needs delay slot
48 ;; %@ -- print rte/rts if is/isn't an interrupt function
49 ;; %# -- output a nop if there is nothing to put in the delay slot
50 ;; %O -- print a constant without the #
51 ;; %R -- print the lsw reg of a double
52 ;; %S -- print the msw reg of a double
53 ;; %T -- print next word of a double REG or MEM
55 ;; Special predicates:
57 ;; arith_operand -- operand is valid source for arithmetic op
58 ;; arith_reg_operand -- operand is valid register for arithmetic op
59 ;; general_movdst_operand -- operand is valid move destination
60 ;; general_movsrc_operand -- operand is valid move source
61 ;; logical_operand -- operand is valid source for logical op
63 ;; -------------------------------------------------------------------------
65 ;; -------------------------------------------------------------------------
79 ;; Virtual FPSCR - bits that are used by FP ops.
82 ;; Virtual FPSCR - bits that are updated by FP ops.
111 (FPSCR_PR 524288) ;; 1 << 19
112 (FPSCR_SZ 1048576) ;; 1 << 20
113 (FPSCR_FR 2097152) ;; 1 << 21
116 (define_c_enum "unspec" [
117 ;; These are used with unspec.
146 ;; (unspec [TARGET ANCHOR] UNSPEC_SYMOFF) == TARGET - ANCHOR.
148 ;; (unspec [OFFSET ANCHOR] UNSPEC_PCREL_SYMOFF) == OFFSET - (ANCHOR - .).
152 UNSPEC_GOTOFFFUNCDESC
154 UNSPEC_BUILTIN_STRLEN
157 (define_c_enum "unspecv" [
158 ;; These are used with unspec_volatile.
175 ;; -------------------------------------------------------------------------
177 ;; -------------------------------------------------------------------------
182 "sh1,sh2,sh2e,sh2a,sh3,sh3e,sh4,sh4a"
183 (const (symbol_ref "sh_cpu_attr")))
185 (define_attr "endian" "big,little"
186 (const (if_then_else (symbol_ref "TARGET_LITTLE_ENDIAN")
187 (const_string "little") (const_string "big"))))
189 ;; Indicate if the default fpu mode is single precision.
190 (define_attr "fpu_single" "yes,no"
191 (const (if_then_else (symbol_ref "TARGET_FPU_SINGLE")
192 (const_string "yes") (const_string "no"))))
194 (define_attr "fmovd" "yes,no"
195 (const (if_then_else (symbol_ref "TARGET_FMOVD")
196 (const_string "yes") (const_string "no"))))
198 (define_attr "pipe_model" "sh1,sh4"
200 (cond [(symbol_ref "TARGET_SUPERSCALAR") (const_string "sh4")]
201 (const_string "sh1"))))
203 ;; cbranch conditional branch instructions
204 ;; jump unconditional jumps
205 ;; arith ordinary arithmetic
206 ;; arith3 a compound insn that behaves similarly to a sequence of
207 ;; three insns of type arith
208 ;; arith3b like above, but might end with a redirected branch
210 ;; load_si Likewise, SImode variant for general register.
211 ;; fload Likewise, but load to fp register.
213 ;; fstore floating point register to memory
214 ;; move general purpose register to register
215 ;; movi8 8-bit immediate to general purpose register
216 ;; mt_group other sh4 mt instructions
217 ;; fmove register to register, floating point
218 ;; smpy word precision integer multiply
219 ;; dmpy longword or doublelongword precision integer multiply
221 ;; pload load of pr reg, which can't be put into delay slot of rts
222 ;; prset copy register to pr reg, ditto
223 ;; pstore store of pr reg, which can't be put into delay slot of jsr
224 ;; prget copy pr to register, ditto
225 ;; pcload pc relative load of constant value
226 ;; pcfload Likewise, but load to fp register.
227 ;; pcload_si Likewise, SImode variant for general register.
228 ;; rte return from exception
229 ;; sfunc special function call with known used registers
230 ;; call function call
232 ;; fpscr_toggle toggle a bit in the fpscr
233 ;; fdiv floating point divide (or square root)
234 ;; gp_fpul move from general purpose register to fpul
235 ;; fpul_gp move from fpul to general purpose register
236 ;; mac_gp move from mac[lh] to general purpose register
237 ;; gp_mac move from general purpose register to mac[lh]
238 ;; mac_mem move from mac[lh] to memory
239 ;; mem_mac move from memory to mac[lh]
240 ;; dfp_arith,dfp_mul, fp_cmp,dfp_cmp,dfp_conv
241 ;; ftrc_s fix_truncsfsi2_i4
242 ;; dfdiv double precision floating point divide (or square root)
243 ;; cwb ic_invalidate_line_i
244 ;; movua SH4a unaligned load
245 ;; fsrra square root reciprocal approximate
246 ;; fsca sine and cosine approximate
247 ;; tls_load load TLS related address
248 ;; nil no-op move, will be deleted.
251 "mt_group,cbranch,jump,jump_ind,arith,arith3,arith3b,dyn_shift,load,load_si,
252 fload,store,fstore,move,movi8,fmove,smpy,dmpy,return,pload,prset,pstore,
253 prget,pcload,pcload_si,pcfload,rte,sfunc,call,fp,fpscr_toggle,fdiv,ftrc_s,
254 dfp_arith,dfp_mul,fp_cmp,dfp_cmp,dfp_conv,dfdiv,gp_fpul,fpul_gp,mac_gp,
255 gp_mac,mac_mem,mem_mac,mem_fpscr,gp_fpscr,cwb,movua,fsrra,fsca,tls_load,
257 (const_string "other"))
259 ;; We define a new attribute namely "insn_class".We use
260 ;; this for the DFA based pipeline description.
262 ;; mt_group SH4 "mt" group instructions.
264 ;; ex_group SH4 "ex" group instructions.
266 ;; ls_group SH4 "ls" group instructions.
268 (define_attr "insn_class"
269 "mt_group,ex_group,ls_group,br_group,fe_group,co_group,none"
270 (cond [(eq_attr "type" "move,mt_group") (const_string "mt_group")
271 (eq_attr "type" "movi8,arith,dyn_shift") (const_string "ex_group")
272 (eq_attr "type" "fmove,load,pcload,load_si,pcload_si,fload,pcfload,
273 store,fstore,gp_fpul,fpul_gp") (const_string "ls_group")
274 (eq_attr "type" "cbranch,jump") (const_string "br_group")
275 (eq_attr "type" "fp,fp_cmp,fdiv,ftrc_s,dfp_arith,dfp_mul,dfp_conv,dfdiv")
276 (const_string "fe_group")
277 (eq_attr "type" "jump_ind,smpy,dmpy,mac_gp,return,pload,prset,pstore,
278 prget,rte,sfunc,call,dfp_cmp,mem_fpscr,gp_fpscr,cwb,
279 gp_mac,mac_mem,mem_mac") (const_string "co_group")]
280 (const_string "none")))
282 ;; nil are zero instructions, and arith3 / arith3b are multiple instructions,
283 ;; so these do not belong in an insn group, although they are modeled
284 ;; with their own define_insn_reservations.
286 ;; Indicate what precision must be selected in fpscr for this insn, if any.
287 (define_attr "fp_mode" "single,double,none" (const_string "none"))
289 ;; Indicate if the fpu mode is set by this instruction
290 ;; "unknown" must have the value as "none" in fp_mode, and means
291 ;; that the instruction/abi has left the processor in an unknown
293 ;; "none" means that nothing has changed and no mode is set.
294 ;; This attribute is only used for the Renesas ABI.
295 (define_attr "fp_set" "single,double,unknown,none" (const_string "none"))
297 ; If a conditional branch destination is within -252..258 bytes away
298 ; from the instruction it can be 2 bytes long. Something in the
299 ; range -4090..4100 bytes can be 6 bytes long. All other conditional
300 ; branches are initially assumed to be 16 bytes long.
301 ; In machine_dependent_reorg, we split all branches that are longer than
304 ;; The maximum range used for SImode constant pool entries is 1018. A final
305 ;; instruction can add 8 bytes while only being 4 bytes in size, thus we
306 ;; can have a total of 1022 bytes in the pool. Add 4 bytes for a branch
307 ;; instruction around the pool table, 2 bytes of alignment before the table,
308 ;; and 30 bytes of alignment after the table. That gives a maximum total
309 ;; pool size of 1058 bytes.
310 ;; Worst case code/pool content size ratio is 1:2 (using asms).
311 ;; Thus, in the worst case, there is one instruction in front of a maximum
312 ;; sized pool, and then there are 1052 bytes of pool for every 508 bytes of
313 ;; code. For the last n bytes of code, there are 2n + 36 bytes of pool.
314 ;; If we have a forward branch, the initial table will be put after the
315 ;; unconditional branch.
317 ;; ??? We could do much better by keeping track of the actual pcloads within
318 ;; the branch range and in the pcload range in front of the branch range.
320 ;; ??? This looks ugly because genattrtab won't allow if_then_else or cond
322 (define_attr "short_cbranch_p" "no,yes"
323 (cond [(match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
325 (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 506))
327 (match_test "NEXT_INSN (PREV_INSN (insn)) != insn")
329 (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 508))
331 ] (const_string "no")))
333 (define_attr "med_branch_p" "no,yes"
334 (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 990))
337 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
339 (leu (plus (minus (match_dup 0) (pc)) (const_int 4092))
342 ] (const_string "no")))
344 (define_attr "med_cbranch_p" "no,yes"
345 (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 988))
348 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
350 (leu (plus (minus (match_dup 0) (pc)) (const_int 4090))
353 ] (const_string "no")))
355 (define_attr "braf_branch_p" "no,yes"
356 (cond [(match_test "! TARGET_SH2")
358 (leu (plus (minus (match_dup 0) (pc)) (const_int 10330))
361 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
363 (leu (plus (minus (match_dup 0) (pc)) (const_int 32764))
366 ] (const_string "no")))
368 (define_attr "braf_cbranch_p" "no,yes"
369 (cond [(match_test "! TARGET_SH2")
371 (leu (plus (minus (match_dup 0) (pc)) (const_int 10328))
374 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
376 (leu (plus (minus (match_dup 0) (pc)) (const_int 32762))
379 ] (const_string "no")))
381 ;; An unconditional jump in the range -4092..4098 can be 2 bytes long.
382 ;; For wider ranges, we need a combination of a code and a data part.
383 ;; If we can get a scratch register for a long range jump, the code
384 ;; part can be 4 bytes long; otherwise, it must be 8 bytes long.
385 ;; If the jump is in the range -32764..32770, the data part can be 2 bytes
386 ;; long; otherwise, it must be 6 bytes long.
388 ;; All other instructions are two bytes long by default.
390 ;; ??? This should use something like *branch_p (minus (match_dup 0) (pc)),
391 ;; but getattrtab doesn't understand this.
392 (define_attr "length" ""
393 (cond [(eq_attr "type" "cbranch")
394 (cond [(eq_attr "short_cbranch_p" "yes")
396 (eq_attr "med_cbranch_p" "yes")
398 (eq_attr "braf_cbranch_p" "yes")
400 ;; ??? using pc is not computed transitively.
401 (ne (match_dup 0) (match_dup 0))
403 (match_test "flag_pic")
406 (eq_attr "type" "jump")
407 (cond [(eq_attr "med_branch_p" "yes")
409 (and (match_test "prev_nonnote_insn (insn)")
410 (and (eq (symbol_ref "GET_CODE (prev_nonnote_insn (insn))")
412 (eq (symbol_ref "INSN_CODE (prev_nonnote_insn (insn))")
413 (symbol_ref "code_for_indirect_jump_scratch"))))
414 (cond [(eq_attr "braf_branch_p" "yes")
416 (not (match_test "flag_pic"))
418 (match_test "TARGET_SH2")
419 (const_int 10)] (const_int 18))
420 (eq_attr "braf_branch_p" "yes")
422 ;; ??? using pc is not computed transitively.
423 (ne (match_dup 0) (match_dup 0))
425 (match_test "flag_pic")
430 ;; DFA descriptions for the pipelines
435 (include "iterators.md")
436 (include "predicates.md")
437 (include "constraints.md")
439 ;; Definitions for filling delay slots
441 (define_attr "needs_delay_slot" "yes,no" (const_string "no"))
443 (define_attr "banked" "yes,no"
444 (cond [(match_test "sh_loads_bankedreg_p (insn)")
445 (const_string "yes")]
446 (const_string "no")))
448 ;; ??? This should be (nil) instead of (const_int 0)
449 (define_attr "hit_stack" "yes,no"
450 (cond [(not (match_test "find_regno_note (insn, REG_INC, SP_REG)"))
452 (const_string "yes")))
454 (define_attr "interrupt_function" "no,yes"
455 (const (symbol_ref "current_function_interrupt")))
457 (define_attr "in_delay_slot" "yes,no"
458 (cond [(eq_attr "type" "cbranch") (const_string "no")
459 (eq_attr "type" "pcload,pcload_si") (const_string "no")
460 (eq_attr "type" "fpscr_toggle") (const_string "no")
461 (eq_attr "needs_delay_slot" "yes") (const_string "no")
462 (eq_attr "length" "2") (const_string "yes")
463 ] (const_string "no")))
465 (define_attr "cond_delay_slot" "yes,no"
466 (cond [(eq_attr "in_delay_slot" "yes") (const_string "yes")
467 ] (const_string "no")))
469 (define_attr "is_sfunc" ""
470 (if_then_else (eq_attr "type" "sfunc") (const_int 1) (const_int 0)))
472 ;; SH4 Double-precision computation with double-precision result -
473 ;; the two halves are ready at different times.
474 (define_attr "dfp_comp" "yes,no"
475 (cond [(eq_attr "type" "dfp_arith,dfp_mul,dfp_conv,dfdiv") (const_string "yes")]
476 (const_string "no")))
478 ;; Insns for which the latency of a preceding fp insn is decreased by one.
479 (define_attr "late_fp_use" "yes,no" (const_string "no"))
480 ;; And feeding insns for which this relevant.
481 (define_attr "any_fp_comp" "yes,no"
482 (cond [(eq_attr "type" "fp,fdiv,ftrc_s,dfp_arith,dfp_mul,dfp_conv,dfdiv")
483 (const_string "yes")]
484 (const_string "no")))
486 (define_attr "any_int_load" "yes,no"
487 (cond [(eq_attr "type" "load,load_si,pcload,pcload_si")
488 (const_string "yes")]
489 (const_string "no")))
491 (define_attr "highpart" "user, ignore, extend, depend, must_split"
492 (const_string "user"))
495 (eq_attr "needs_delay_slot" "yes")
496 [(eq_attr "in_delay_slot" "yes") (nil) (nil)])
498 ;; Since a normal return (rts) implicitly uses the PR register,
499 ;; we can't allow PR register loads in an rts delay slot.
500 ;; On the SH1* and SH2*, the rte instruction reads the return pc from the
501 ;; stack, and thus we can't put a pop instruction in its delay slot.
502 ;; On the SH3* and SH4*, the rte instruction does not use the stack, so a
503 ;; pop instruction can go in the delay slot, unless it references a banked
504 ;; register (the register bank is switched by rte).
506 (eq_attr "type" "return")
507 [(and (eq_attr "in_delay_slot" "yes")
508 (ior (and (eq_attr "interrupt_function" "no")
509 (eq_attr "type" "!pload,prset"))
510 (and (eq_attr "interrupt_function" "yes")
511 (ior (match_test "TARGET_SH3") (eq_attr "hit_stack" "no"))
512 (eq_attr "banked" "no"))))
515 ;; Since a call implicitly uses the PR register, we can't allow
516 ;; a PR register store in a jsr delay slot.
519 (ior (eq_attr "type" "call") (eq_attr "type" "sfunc"))
520 [(and (eq_attr "in_delay_slot" "yes")
521 (eq_attr "type" "!pstore,prget")) (nil) (nil)])
523 ;; Conditional branches with delay slots are available starting with SH2.
524 ;; If zero displacement conditional branches are fast, disable the delay
525 ;; slot if the branch jumps over only one 2-byte insn.
527 (and (eq_attr "type" "cbranch")
528 (match_test "TARGET_SH2")
529 (not (and (match_test "TARGET_ZDCBRANCH")
530 (match_test "sh_cbranch_distance (insn, 4) == 2"))))
531 [(eq_attr "cond_delay_slot" "yes") (nil) (nil)])
533 ;; -------------------------------------------------------------------------
534 ;; SImode signed integer comparisons
535 ;; -------------------------------------------------------------------------
537 ;; Patterns to generate the tst instruction which are usually formed by
539 ;; The canonical form here being used is (eq (and (op) (op)) 0).
540 ;; For some bit patterns, such as contiguous bits, we also must accept
541 ;; zero_extract forms. Single bit tests are also handled via zero_extract
542 ;; patterns in the 'bit field extract patterns' section. All variants
543 ;; are eventually converted to the 'tstsi_t' insn.
544 ;; As long as pseudos can be created (before RA), 'tstsi_t' will also accept
545 ;; constants that won't fit into 8 bits. After having captured the constant
546 ;; we can decide better whether/how to load it into a register and do other
547 ;; post-combine optimizations such as bypassing sign/zero extensions.
548 (define_insn_and_split "tstsi_t"
550 (eq:SI (and:SI (match_operand:SI 0 "arith_reg_operand" "%z,r")
551 (match_operand:SI 1 "arith_or_int_operand" "K08,?r"))
554 && (can_create_pseudo_p () || arith_reg_operand (operands[1], SImode)
555 || satisfies_constraint_K08 (operands[1]))"
557 "TARGET_SH1 && can_create_pseudo_p () && CONST_INT_P (operands[1])
558 && !sh_in_recog_treg_set_expr ()"
561 gcc_assert (CONST_INT_P (operands[1]));
563 HOST_WIDE_INT op1val = INTVAL (operands[1]);
564 rtx reg = operands[0];
566 reg = SUBREG_REG (reg);
567 gcc_assert (REG_P (reg));
568 bool op0_dead_after_this =
569 sh_reg_dead_or_unused_after_insn (curr_insn, REGNO (reg));
575 "tstsi_t: trying to optimize const_int 0x%08x\n",
578 /* See if we can convert a test with a reg and a constant into
579 something simpler, if the reg is known to be zero or sign
581 sh_extending_set_of_reg eop0 = sh_find_extending_set_of_reg (operands[0],
583 if (eop0.ext_code != UNKNOWN)
585 /* Adjust the constant, trying to eliminate bits that are not
586 contributing to the result. */
587 if (eop0.from_mode == QImode)
589 | (eop0.ext_code == SIGN_EXTEND && (op1val & 0xFFFFFF80)
591 else if (eop0.from_mode == HImode)
593 | (eop0.ext_code == SIGN_EXTEND && (op1val & 0xFFFF8000)
594 ? 0x8000 : 0)) & 0xFFFF;
597 fprintf (dump_file, "tstsi_t: using effective const_int: 0x%08x\n",
600 /* Try to bypass the sign/zero extension first if op0 dies after
602 if (op0_dead_after_this && eop0.can_use_as_unextended_reg ())
605 fprintf (dump_file, "tstsi_t: bypassing sign/zero extension\n");
607 operands[0] = eop0.use_as_unextended_reg (curr_insn);
609 else if ((eop0.from_mode == QImode && op1val == 0xFF)
610 || (eop0.from_mode == HImode && op1val == 0xFFFF))
613 fprintf (dump_file, "tstsi_t: converting to cmpeqsi_t\n");
614 emit_insn (gen_cmpeqsi_t (eop0.use_as_extended_reg (curr_insn),
618 else if (eop0.ext_code == SIGN_EXTEND
619 && ((eop0.from_mode == QImode && op1val == 0x80)
620 || (eop0.from_mode == HImode && op1val == 0x8000)))
623 fprintf (dump_file, "tstsi_t: converting to cmpgesi_t\n");
624 emit_insn (gen_cmpgesi_t (eop0.use_as_extended_reg (curr_insn),
628 else if (!CONST_OK_FOR_K08 (op1val))
631 fprintf (dump_file, "tstsi_t: converting const_int to signed "
634 /* If here we haven't done anything yet. Convert the constant
635 to a signed value to reduce the constant pool size. */
636 operands[0] = eop0.use_as_extended_reg (curr_insn);
638 if (eop0.from_mode == QImode)
639 op1val |= (op1val & 0x80) ? 0xFFFFFFFFFFFFFF00LL : 0;
640 else if (eop0.from_mode == HImode)
641 op1val |= (op1val & 0x8000) ? 0xFFFFFFFFFFFF0000LL : 0;
644 operands[0] = eop0.use_as_extended_reg (curr_insn);
649 fprintf (dump_file, "tstsi_t: using const_int 0x%08x\n",
652 /* Try to fit the constant into 8 bits by shuffling the value in the
654 Doing that usually results in smaller code as the constants in the
655 pools are avoided (32 bit constant = load + constant = 6 bytes).
656 However, if the constant load (LS insn) can be hoisted insn dependencies
657 can be avoided and chances for parallel execution increase. The common
663 FIXME: For now we do that only when optimizing for size until there is
666 FIXME: If there are multiple tst insns in the block with the same
667 constant, avoid the #imm variant to avoid R0 loads. Use the 'tst Rn,Rm'
668 variant instead and load the constant into a reg. For that we'd need
669 to do some analysis. */
671 if (CONST_OK_FOR_K08 (op1val))
675 else if ((op1val & 0xFFFF) == 0
676 && CONST_OK_FOR_K08 (op1val >> 16) && optimize_size)
678 /* Use a swap.w insn to do a shift + reg copy (to R0) in one insn. */
679 op1val = op1val >> 16;
680 rtx r = gen_reg_rtx (SImode);
681 emit_insn (gen_rotlsi3_16 (r, operands[0]));
684 else if ((op1val & 0xFF) == 0
685 && CONST_OK_FOR_K08 (op1val >> 8) && optimize_size)
687 /* Use a swap.b insn to do a shift + reg copy (to R0) in one insn. */
688 op1val = op1val >> 8;
689 rtx r = gen_reg_rtx (SImode);
690 emit_insn (gen_swapbsi2 (r, operands[0]));
693 else if ((op1val & 3) == 0
694 && CONST_OK_FOR_K08 (op1val >> 2) && optimize_size)
696 op1val = op1val >> 2;
697 rtx r = gen_reg_rtx (SImode);
698 emit_insn (gen_lshrsi3_k (r, operands[0], GEN_INT (2)));
701 else if ((op1val & 1) == 0
702 && CONST_OK_FOR_K08 (op1val >> 1) && optimize_size)
704 op1val = op1val >> 1;
705 rtx r = gen_reg_rtx (SImode);
706 emit_insn (gen_shlr (r, operands[0]));
710 operands[1] = GEN_INT (op1val);
712 if (!satisfies_constraint_K08 (operands[1]))
713 operands[1] = force_reg (SImode, operands[1]);
715 emit_insn (gen_tstsi_t (operands[0], operands[1]));
718 [(set_attr "type" "mt_group")])
720 ;; This pattern is used by combine when testing QI/HImode subregs with a
721 ;; negative constant. Ignore high bits by masking them out in the constant.
722 (define_insn_and_split "*tst<mode>_t"
725 (and:QIHI (match_operand:QIHI 0 "arith_reg_operand")
726 (match_operand 1 "const_int_operand")) 0)
728 "TARGET_SH1 && can_create_pseudo_p ()"
732 (eq:SI (and:SI (match_dup 0) (match_dup 1)) (const_int 0)))]
734 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
735 operands[1] = GEN_INT (INTVAL (operands[1])
736 & (<MODE>mode == HImode ? 0xFFFF : 0xFF));
739 ;; This pattern might be risky because it also tests the upper bits and not
740 ;; only the subreg. We have to check whether the operands have been sign
741 ;; or zero extended. In the worst case, a zero extension has to be inserted
742 ;; to mask out the unwanted bits.
743 (define_insn_and_split "*tst<mode>_t_subregs"
747 (and:SI (match_operand:SI 0 "arith_reg_operand")
748 (match_operand:SI 1 "arith_reg_operand")) <lowpart_le>)
750 "TARGET_SH1 && TARGET_LITTLE_ENDIAN && can_create_pseudo_p ()"
752 "&& !sh_in_recog_treg_set_expr ()"
755 sh_split_tst_subregs (curr_insn, <MODE>mode, <lowpart_le>, operands);
759 (define_insn_and_split "*tst<mode>_t_subregs"
763 (and:SI (match_operand:SI 0 "arith_reg_operand")
764 (match_operand:SI 1 "arith_reg_operand")) <lowpart_be>)
766 "TARGET_SH1 && TARGET_BIG_ENDIAN && can_create_pseudo_p ()"
768 "&& !sh_in_recog_treg_set_expr ()"
771 sh_split_tst_subregs (curr_insn, <MODE>mode, <lowpart_be>, operands);
775 ;; Extract contiguous bits and compare them against zero.
776 ;; Notice that this will not be used for single bits. Special single bit
777 ;; extraction patterns are in the 'bit field extract patterns' section.
778 (define_insn_and_split "*tst<mode>_t_zero_extract"
780 (eq:SI (zero_extract:SI (match_operand:QIHISI 0 "arith_reg_operand")
781 (match_operand 1 "const_int_operand")
782 (match_operand 2 "const_int_operand"))
784 "TARGET_SH1 && can_create_pseudo_p ()"
788 (eq:SI (and:SI (match_dup 0) (match_dup 1)) (const_int 0)))]
790 operands[1] = GEN_INT (ZERO_EXTRACT_ANDMASK (operands[1], operands[2]));
791 if (GET_MODE (operands[0]) != SImode)
792 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
795 ;; Convert '(reg << shift) & mask' into 'reg & (mask >> shift)'.
796 ;; The shifted-out bits in the mask will always be zero, since the
797 ;; shifted-in bits in the reg will also be always zero.
798 (define_insn_and_split "*tstsi_t_shift_mask"
800 (eq:SI (and:SI (ashift:SI (match_operand:SI 0 "arith_reg_operand")
801 (match_operand 1 "const_int_operand"))
802 (match_operand 2 "const_int_operand"))
804 "TARGET_SH1 && can_create_pseudo_p ()"
808 (eq:SI (and:SI (match_dup 0) (match_dup 2)) (const_int 0)))]
810 operands[2] = GEN_INT (INTVAL (operands[2]) >> INTVAL (operands[1]));
813 (define_insn "cmpeqsi_t"
815 (eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
816 (match_operand:SI 1 "arith_operand" "N,rI08,r")))]
822 [(set_attr "type" "mt_group")])
824 ;; Sometimes combine fails to form the (eq (and (op) (op)) 0) tst insn.
825 ;; Try to fix that in the split1 pass by looking for the previous set
826 ;; of the tested op. Also see if there is a preceeding sign/zero
827 ;; extension that can be avoided.
830 (eq:SI (match_operand:SI 0 "arith_reg_operand") (const_int 0)))]
831 "TARGET_SH1 && can_create_pseudo_p () && optimize
832 && !sh_in_recog_treg_set_expr ()"
833 [(set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))]
836 fprintf (dump_file, "cmpeqsi_t: trying to optimize const_int 0\n");
838 /* If the tested reg is not dead after this insn, it's probably used by
839 something else after the comparison. It's probably better to leave
841 rtx reg = operands[0];
843 reg = SUBREG_REG (reg);
844 gcc_assert (REG_P (reg));
845 if (find_regno_note (curr_insn, REG_DEAD, REGNO (reg)) == NULL_RTX)
848 /* FIXME: Maybe also search the predecessor basic blocks to catch
850 set_of_reg op = sh_find_set_of_reg (operands[0], curr_insn,
851 prev_nonnote_nondebug_insn_bb);
853 if (op.set_src != NULL && GET_CODE (op.set_src) == AND
854 && !sh_insn_operands_modified_between_p (op.insn, op.insn, curr_insn))
857 fprintf (dump_file, "cmpeqsi_t: found preceeding and in insn %d\n",
860 if (!(arith_reg_operand (XEXP (op.set_src, 0), SImode)
861 && (arith_reg_operand (XEXP (op.set_src, 1), SImode)
862 || CONST_INT_P (XEXP (op.set_src, 1)))))
865 /* Assume that the operands of the andsi insn are compatible with the
866 operands of the tstsi_t insn, which is generally the case. */
868 fprintf (dump_file, "cmpeqsi_t: replacing with tstsi_t\n");
869 emit_insn (gen_tstsi_t (copy_rtx (XEXP (op.set_src, 0)),
870 copy_rtx (XEXP (op.set_src, 1))));
874 /* Converting HImode into tests against 0xFFFF tends to increase the code
875 size, as it will create constant pool entries. Disable it for now. */
876 const bool enable_himode = false;
878 /* FIXME: try to keep the (eq (reg) (const_int 0)). Even if the zero
879 extended reg is used after this insn, if we know that _before_ the zero
880 extension the value was loaded via sign extending mem load, we can just
881 use the value of the mem load directly. */
882 sh_extending_set_of_reg eop = sh_find_extending_set_of_reg (operands[0],
885 if (eop.ext_code != UNKNOWN
886 && (eop.from_mode == QImode || (eop.from_mode == HImode && enable_himode))
887 && eop.can_use_as_unextended_reg ()
888 && !reg_used_between_p (operands[0], eop.insn, curr_insn))
890 /* Bypass the sign/zero extension and test against the bit mask, but
891 only if it's the only use of the sign/zero extracted value.
892 Otherwise we'd be introducing new constants in the pool. */
894 fprintf (dump_file, "cmpeqsi_t: bypassing sign/zero extension in "
895 "insn %d and using tstsi_t\n", INSN_UID (op.insn));
897 emit_insn (gen_tstsi_t (
898 eop.use_as_unextended_reg (curr_insn),
899 GEN_INT (eop.from_mode == QImode ? 0xFF : 0xFFFF)));
904 fprintf (dump_file, "cmpeqsi_t: nothing optimized\n");
908 (define_insn "cmpgtsi_t"
910 (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
911 (match_operand:SI 1 "arith_reg_or_0_operand" "N,r")))]
916 [(set_attr "type" "mt_group")])
918 (define_insn "cmpgesi_t"
920 (ge:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
921 (match_operand:SI 1 "arith_reg_or_0_operand" "N,r")))]
926 [(set_attr "type" "mt_group")])
928 ;; Recombine a cmp/pz followed by a nott into a shll.
929 ;; On non-SH2A recombine a cmp/pz followed by a movrt into shll-movt.
930 ;; On SH2A cmp/pz-movrt is slightly better, as it does not mutate the input.
933 (ge:SI (match_operand:SI 0 "arith_reg_operand") (const_int 0)))]
935 "TARGET_SH1 && can_create_pseudo_p () && optimize
936 && !sh_in_recog_treg_set_expr ()"
940 fprintf (dump_file, "cmpgesi_t: trying to optimize for const_int 0\n");
942 rtx_insn* i = next_nonnote_nondebug_insn_bb (curr_insn);
946 fprintf (dump_file, "cmpgesi_t: following insn is \n");
947 print_rtl_single (dump_file, i);
948 fprintf (dump_file, "\n");
951 if (sh_is_nott_insn (i))
955 "cmpgesi_t: replacing (cmp/pz, nott) with (shll)\n");
956 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
957 set_insn_deleted (i);
961 /* On non-SH2A negc is used as movrt replacement, which sets T = 1.
962 Thus we can remove it only if T is marked as dead afterwards. */
963 if (rtx dest_reg = !TARGET_SH2A
964 && sh_reg_dead_or_unused_after_insn (i, T_REG)
965 ? sh_movrt_set_dest (i) : NULL)
969 "cmpgesi_t: replacing (cmp/pz, movrt) with (shll, movt)\n");
970 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
971 add_reg_note (emit_insn (gen_movt (dest_reg, get_t_reg_rtx ())),
972 REG_DEAD, get_t_reg_rtx ());
973 set_insn_deleted (i);
978 fprintf (dump_file, "cmpgesi_t: nothing optimized\n");
983 ;; FIXME: This is actually wrong. There is no way to literally move a
984 ;; general reg to t reg. Luckily, it seems that this pattern will be only
985 ;; used when the general reg is known be either '0' or '1' during combine.
986 ;; What we actually need is reg != 0 -> T, but we have only reg == 0 -> T.
987 ;; Due to interactions with other patterns, combine fails to pick the latter
988 ;; and invert the dependent logic.
989 (define_insn "*negtstsi"
990 [(set (reg:SI T_REG) (match_operand:SI 0 "arith_reg_operand" "r"))]
991 "TARGET_SH1 && !sh_in_recog_treg_set_expr ()"
993 [(set_attr "type" "mt_group")])
995 ;; Some integer sign comparison patterns can be realized with the div0s insn.
996 ;; div0s Rm,Rn T = (Rm >> 31) ^ (Rn >> 31)
998 ;; The 'cmp_div0s' pattern is our canonical form, into which all the other
999 ;; variations are converted. The negative forms will split into a trailing
1000 ;; nott sequence, which will be eliminated either by the
1001 ;; 'any_treg_expr_to_reg' pattern, or by the 'sh_treg_combine' pass.
1002 (define_insn "cmp_div0s"
1003 [(set (reg:SI T_REG)
1004 (lshiftrt:SI (xor:SI (match_operand:SI 0 "arith_reg_operand" "%r")
1005 (match_operand:SI 1 "arith_reg_operand" "r"))
1009 [(set_attr "type" "arith")])
1011 (define_insn_and_split "*cmp_div0s_1"
1012 [(set (reg:SI T_REG)
1013 (xor:SI (ge:SI (match_operand:SI 0 "arith_reg_operand")
1015 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1017 "TARGET_SH1 && can_create_pseudo_p ()"
1020 [(set (reg:SI T_REG)
1021 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))])
1023 (define_insn_and_split "*cmp_div0s_2"
1024 [(set (reg:SI T_REG)
1025 (eq:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
1027 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1029 "TARGET_SH1 && can_create_pseudo_p ()"
1032 [(set (reg:SI T_REG)
1033 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))])
1035 (define_insn_and_split "*cmp_div0s_3"
1036 [(set (reg:SI T_REG)
1037 (eq:SI (ge:SI (match_operand:SI 0 "arith_reg_operand")
1039 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1041 "TARGET_SH1 && can_create_pseudo_p ()"
1044 [(set (reg:SI T_REG)
1045 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1046 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1048 (define_insn_and_split "*cmp_div0s_4"
1049 [(set (reg:SI T_REG)
1050 (ge:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
1051 (match_operand:SI 1 "arith_reg_operand"))
1053 "TARGET_SH1 && can_create_pseudo_p ()"
1056 [(set (reg:SI T_REG)
1057 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1058 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1060 (define_insn_and_split "*cmp_div0s_5"
1061 [(set (reg:SI T_REG)
1062 (xor:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
1064 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1066 "TARGET_SH1 && can_create_pseudo_p ()"
1069 [(set (reg:SI T_REG)
1070 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1071 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1073 (define_insn_and_split "*cmp_div0s_6"
1074 [(set (reg:SI T_REG)
1075 (eq:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
1077 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
1079 "TARGET_SH1 && can_create_pseudo_p ()"
1082 [(set (reg:SI T_REG)
1083 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1084 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1086 ;; In some cases, it might be shorter to get a tested bit into bit 31 and
1087 ;; use div0s. Otherwise it's usually better to just leave the xor and tst
1088 ;; sequence. The only thing we can try to do here is avoiding the large
1090 (define_insn_and_split "*cmp_div0s_7"
1091 [(set (reg:SI T_REG)
1092 (zero_extract:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
1093 (match_operand:SI 1 "arith_reg_operand"))
1095 (match_operand 2 "const_int_operand")))]
1096 "TARGET_SH1 && can_create_pseudo_p ()
1097 && (INTVAL (operands[2]) == 7 || INTVAL (operands[2]) == 15
1098 || INTVAL (operands[2]) == 23 || INTVAL (operands[2]) == 29
1099 || INTVAL (operands[2]) == 30 || INTVAL (operands[2]) == 31)"
1104 const int bitpos = INTVAL (operands[2]);
1106 rtx op0 = gen_reg_rtx (SImode);
1107 rtx op1 = gen_reg_rtx (SImode);
1109 if (bitpos == 23 || bitpos == 30 || bitpos == 29)
1111 emit_insn (gen_ashlsi3 (op0, operands[0], GEN_INT (31 - bitpos)));
1112 emit_insn (gen_ashlsi3 (op1, operands[1], GEN_INT (31 - bitpos)));
1114 else if (bitpos == 15)
1116 emit_insn (gen_extendhisi2 (op0, gen_lowpart (HImode, operands[0])));
1117 emit_insn (gen_extendhisi2 (op1, gen_lowpart (HImode, operands[1])));
1119 else if (bitpos == 7)
1121 emit_insn (gen_extendqisi2 (op0, gen_lowpart (QImode, operands[0])));
1122 emit_insn (gen_extendqisi2 (op1, gen_lowpart (QImode, operands[1])));
1124 else if (bitpos == 31)
1132 emit_insn (gen_cmp_div0s (op0, op1));
1136 ;; For bits 0..7 using a xor and tst #imm,r0 sequence seems to be better.
1137 ;; Thus allow the following patterns only for higher bit positions where
1138 ;; we it's more likely to save the large tst constant.
1139 (define_insn_and_split "*cmp_div0s_8"
1140 [(set (reg:SI T_REG)
1141 (eq:SI (zero_extract:SI (match_operand:SI 0 "arith_reg_operand")
1143 (match_operand 2 "const_int_operand"))
1144 (zero_extract:SI (match_operand:SI 1 "arith_reg_operand")
1147 "TARGET_SH1 && can_create_pseudo_p ()
1148 && (INTVAL (operands[2]) == 15
1149 || INTVAL (operands[2]) == 23 || INTVAL (operands[2]) == 29
1150 || INTVAL (operands[2]) == 30 || INTVAL (operands[2]) == 31)"
1153 [(set (reg:SI T_REG)
1154 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
1155 (const_int 1) (match_dup 2)))
1156 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1158 (define_insn_and_split "*cmp_div0s_9"
1159 [(set (reg:SI T_REG)
1160 (zero_extract:SI (xor:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
1161 (match_operand:SI 1 "arith_reg_operand"))
1162 (match_operand 2 "const_int_operand"))
1164 (match_operand 3 "const_int_operand")))]
1165 "TARGET_SH1 && can_create_pseudo_p ()
1166 && (INTVAL (operands[2]) & 0xFFFFFFFF) == (1U << INTVAL (operands[3]))
1167 && (INTVAL (operands[3]) == 15
1168 || INTVAL (operands[3]) == 23 || INTVAL (operands[3]) == 29
1169 || INTVAL (operands[3]) == 30 || INTVAL (operands[3]) == 31)"
1172 [(set (reg:SI T_REG)
1173 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
1174 (const_int 1) (match_dup 3)))
1175 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1177 ;; -------------------------------------------------------------------------
1178 ;; SImode compare and branch
1179 ;; -------------------------------------------------------------------------
1181 (define_expand "cbranchsi4"
1183 (if_then_else (match_operator 0 "comparison_operator"
1184 [(match_operand:SI 1 "arith_operand" "")
1185 (match_operand:SI 2 "arith_operand" "")])
1186 (label_ref (match_operand 3 "" ""))
1188 (clobber (reg:SI T_REG))]
1189 "can_create_pseudo_p ()"
1191 expand_cbranchsi4 (operands, LAST_AND_UNUSED_RTX_CODE);
1195 ;; Combine patterns to invert compare and branch operations for which we
1196 ;; don't have actual comparison insns. These patterns are used in cases
1197 ;; which appear after the initial cbranchsi expansion, which also does
1198 ;; some condition inversion.
1201 (if_then_else (ne (match_operand:SI 0 "arith_reg_operand" "")
1202 (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1203 (label_ref (match_operand 2))
1205 (clobber (reg:SI T_REG))]
1207 [(set (reg:SI T_REG) (eq:SI (match_dup 0) (match_dup 1)))
1208 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1209 (label_ref (match_dup 2))
1212 ;; FIXME: These don't seem to have any effect on the generated cbranch code
1213 ;; anymore, but only on some register allocation choices.
1216 (if_then_else (le (match_operand:SI 0 "arith_reg_operand" "")
1217 (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1218 (label_ref (match_operand 2))
1220 (clobber (reg:SI T_REG))]
1222 [(set (reg:SI T_REG) (gt:SI (match_dup 0) (match_dup 1)))
1223 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1224 (label_ref (match_dup 2))
1229 (if_then_else (lt (match_operand:SI 0 "arith_reg_operand" "")
1230 (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1231 (label_ref (match_operand 2))
1233 (clobber (reg:SI T_REG))]
1235 [(set (reg:SI T_REG) (ge:SI (match_dup 0) (match_dup 1)))
1236 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1237 (label_ref (match_dup 2))
1242 (if_then_else (leu (match_operand:SI 0 "arith_reg_operand" "")
1243 (match_operand:SI 1 "arith_reg_operand" ""))
1244 (label_ref (match_operand 2))
1246 (clobber (reg:SI T_REG))]
1248 [(set (reg:SI T_REG) (gtu:SI (match_dup 0) (match_dup 1)))
1249 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1250 (label_ref (match_dup 2))
1255 (if_then_else (ltu (match_operand:SI 0 "arith_reg_operand" "")
1256 (match_operand:SI 1 "arith_reg_operand" ""))
1257 (label_ref (match_operand 2))
1259 (clobber (reg:SI T_REG))]
1261 [(set (reg:SI T_REG) (geu:SI (match_dup 0) (match_dup 1)))
1262 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1263 (label_ref (match_dup 2))
1266 ;; -------------------------------------------------------------------------
1267 ;; SImode unsigned integer comparisons
1268 ;; -------------------------------------------------------------------------
1270 ;; Usually comparisons of 'unsigned int >= 0' are optimized away completely.
1271 ;; However, especially when optimizations are off (e.g. -O0) such comparisons
1272 ;; might remain and we have to handle them. If the '>= 0' case wasn't
1273 ;; handled here, something else would just load a '0' into the second operand
1274 ;; and do the comparison. We can do slightly better by just setting the
1276 (define_insn_and_split "cmpgeusi_t"
1277 [(set (reg:SI T_REG)
1278 (geu:SI (match_operand:SI 0 "arith_reg_operand" "r")
1279 (match_operand:SI 1 "arith_reg_or_0_operand" "r")))]
1282 "&& satisfies_constraint_Z (operands[1])"
1283 [(set (reg:SI T_REG) (const_int 1))]
1285 [(set_attr "type" "mt_group")])
1287 (define_insn "cmpgtusi_t"
1288 [(set (reg:SI T_REG)
1289 (gtu:SI (match_operand:SI 0 "arith_reg_operand" "r")
1290 (match_operand:SI 1 "arith_reg_operand" "r")))]
1293 [(set_attr "type" "mt_group")])
1295 ;; -------------------------------------------------------------------------
1296 ;; DImode compare and branch
1297 ;; -------------------------------------------------------------------------
1299 ;; arith3 patterns don't work well with the sh4-300 branch prediction mechanism.
1300 ;; Therefore, we aim to have a set of three branches that go straight to the
1301 ;; destination, i.e. only one of them is taken at any one time.
1302 ;; This mechanism should also be slightly better for the sh4-200.
1304 (define_expand "cbranchdi4"
1306 (if_then_else (match_operator 0 "comparison_operator"
1307 [(match_operand:DI 1 "arith_operand")
1308 (match_operand:DI 2 "arith_operand")])
1309 (label_ref (match_operand 3))
1311 (clobber (reg:SI T_REG))]
1312 "TARGET_SH2 && can_create_pseudo_p ()"
1314 if (!expand_cbranchdi4 (operands, GET_CODE (operands[0])))
1319 ;; -------------------------------------------------------------------------
1320 ;; DImode signed integer comparisons
1321 ;; -------------------------------------------------------------------------
1324 [(set (reg:SI T_REG)
1325 (eq:SI (and:DI (match_operand:DI 0 "arith_reg_operand" "r")
1326 (match_operand:DI 1 "arith_operand" "r"))
1330 return output_branchy_insn (EQ, "tst\t%S1,%S0;bf\t%l9;tst\t%R1,%R0",
1333 [(set_attr "length" "6")
1334 (set_attr "type" "arith3b")])
1336 (define_insn "cmpeqdi_t"
1337 [(set (reg:SI T_REG)
1338 (eq:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1339 (match_operand:DI 1 "arith_reg_or_0_operand" "N,r")))]
1342 static const char* alt[] =
1349 "cmp/eq %S1,%S0" "\n"
1351 " cmp/eq %R1,%R0" "\n"
1354 return alt[which_alternative];
1356 [(set_attr "length" "6")
1357 (set_attr "type" "arith3b")])
1360 [(set (reg:SI T_REG)
1361 (eq:SI (match_operand:DI 0 "arith_reg_operand" "")
1362 (match_operand:DI 1 "arith_reg_or_0_operand" "")))]
1363 ;; If we applied this split when not optimizing, it would only be
1364 ;; applied during the machine-dependent reorg, when no new basic blocks
1366 "TARGET_SH1 && reload_completed && optimize"
1367 [(set (reg:SI T_REG) (eq:SI (match_dup 2) (match_dup 3)))
1368 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1369 (label_ref (match_dup 6))
1371 (set (reg:SI T_REG) (eq:SI (match_dup 4) (match_dup 5)))
1374 operands[2] = gen_highpart (SImode, operands[0]);
1375 operands[3] = operands[1] == const0_rtx
1377 : gen_highpart (SImode, operands[1]);
1378 operands[4] = gen_lowpart (SImode, operands[0]);
1379 operands[5] = gen_lowpart (SImode, operands[1]);
1380 operands[6] = gen_label_rtx ();
1383 (define_insn "cmpgtdi_t"
1384 [(set (reg:SI T_REG)
1385 (gt:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1386 (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
1389 static const char* alt[] =
1391 "cmp/eq %S1,%S0" "\n"
1393 " cmp/gt %S1,%S0" "\n"
1394 " cmp/hi %R1,%R0" "\n"
1400 " cmp/hi %S0,%R0" "\n"
1403 return alt[which_alternative];
1405 [(set_attr "length" "8")
1406 (set_attr "type" "arith3")])
1408 (define_insn "cmpgedi_t"
1409 [(set (reg:SI T_REG)
1410 (ge:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1411 (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
1414 static const char* alt[] =
1416 "cmp/eq %S1,%S0" "\n"
1418 " cmp/ge %S1,%S0" "\n"
1419 " cmp/hs %R1,%R0" "\n"
1424 return alt[which_alternative];
1426 [(set_attr "length" "8,2")
1427 (set_attr "type" "arith3,mt_group")])
1429 ;; -------------------------------------------------------------------------
1430 ;; DImode unsigned integer comparisons
1431 ;; -------------------------------------------------------------------------
1433 (define_insn "cmpgeudi_t"
1434 [(set (reg:SI T_REG)
1435 (geu:SI (match_operand:DI 0 "arith_reg_operand" "r")
1436 (match_operand:DI 1 "arith_reg_operand" "r")))]
1439 return "cmp/eq %S1,%S0" "\n"
1441 " cmp/hs %S1,%S0" "\n"
1442 " cmp/hs %R1,%R0" "\n"
1445 [(set_attr "length" "8")
1446 (set_attr "type" "arith3")])
1448 (define_insn "cmpgtudi_t"
1449 [(set (reg:SI T_REG)
1450 (gtu:SI (match_operand:DI 0 "arith_reg_operand" "r")
1451 (match_operand:DI 1 "arith_reg_operand" "r")))]
1454 return "cmp/eq %S1,%S0" "\n"
1456 " cmp/hi %S1,%S0" "\n"
1457 " cmp/hi %R1,%R0" "\n"
1460 [(set_attr "length" "8")
1461 (set_attr "type" "arith3")])
1463 ;; -------------------------------------------------------------------------
1464 ;; Conditional move instructions
1465 ;; -------------------------------------------------------------------------
1467 (define_insn "*movsicc_t_false"
1468 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1469 (if_then_else (eq (reg:SI T_REG) (const_int 0))
1470 (match_operand:SI 1 "general_movsrc_operand" "r,I08")
1471 (match_operand:SI 2 "arith_reg_operand" "0,0")))]
1472 "TARGET_PRETEND_CMOVE
1473 && (arith_reg_operand (operands[1], SImode)
1474 || (immediate_operand (operands[1], SImode)
1475 && satisfies_constraint_I08 (operands[1])))"
1481 [(set_attr "type" "mt_group,arith") ;; poor approximation
1482 (set_attr "length" "4")])
1484 (define_insn "*movsicc_t_true"
1485 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1486 (if_then_else (ne (reg:SI T_REG) (const_int 0))
1487 (match_operand:SI 1 "general_movsrc_operand" "r,I08")
1488 (match_operand:SI 2 "arith_reg_operand" "0,0")))]
1489 "TARGET_PRETEND_CMOVE
1490 && (arith_reg_operand (operands[1], SImode)
1491 || (immediate_operand (operands[1], SImode)
1492 && satisfies_constraint_I08 (operands[1])))"
1498 [(set_attr "type" "mt_group,arith") ;; poor approximation
1499 (set_attr "length" "4")])
1501 (define_expand "movsicc"
1502 [(set (match_operand:SI 0 "arith_reg_dest" "")
1503 (if_then_else:SI (match_operand 1 "comparison_operator" "")
1504 (match_operand:SI 2 "arith_reg_or_0_operand" "")
1505 (match_operand:SI 3 "arith_reg_operand" "")))]
1506 "TARGET_PRETEND_CMOVE"
1508 rtx_code code = GET_CODE (operands[1]);
1509 rtx_code new_code = code;
1510 rtx op0 = XEXP (operands[1], 0);
1511 rtx op1 = XEXP (operands[1], 1);
1513 if (! currently_expanding_to_rtl)
1518 case LT: case LE: case LEU: case LTU:
1519 if (GET_MODE_CLASS (GET_MODE (op0)) != MODE_INT)
1523 new_code = reverse_condition (code);
1525 case EQ: case GT: case GE: case GEU: case GTU:
1531 sh_emit_scc_to_t (new_code, op0, op1);
1532 operands[1] = gen_rtx_fmt_ee (new_code == code ? NE : EQ, VOIDmode,
1533 gen_rtx_REG (SImode, T_REG), const0_rtx);
1536 ;; -------------------------------------------------------------------------
1537 ;; Addition instructions
1538 ;; -------------------------------------------------------------------------
1540 (define_insn_and_split "adddi3"
1541 [(set (match_operand:DI 0 "arith_reg_dest")
1542 (plus:DI (match_operand:DI 1 "arith_reg_operand")
1543 (match_operand:DI 2 "arith_reg_operand")))
1544 (clobber (reg:SI T_REG))]
1545 "TARGET_SH1 && can_create_pseudo_p ()"
1550 emit_insn (gen_clrt ());
1551 emit_insn (gen_addc (gen_lowpart (SImode, operands[0]),
1552 gen_lowpart (SImode, operands[1]),
1553 gen_lowpart (SImode, operands[2])));
1554 emit_insn (gen_addc (gen_highpart (SImode, operands[0]),
1555 gen_highpart (SImode, operands[1]),
1556 gen_highpart (SImode, operands[2])));
1561 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1562 (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0")
1563 (match_operand:SI 2 "arith_reg_operand" "r"))
1566 (ltu:SI (plus:SI (match_dup 1) (match_dup 2)) (match_dup 1)))]
1569 [(set_attr "type" "arith")])
1571 ;; A simplified version of the addc insn, where the exact value of the
1572 ;; T bit doesn't matter. This is easier for combine to pick up.
1573 ;; We allow a reg or 0 for one of the operands in order to be able to
1574 ;; do 'reg + T' sequences.
1575 (define_insn_and_split "*addc"
1576 [(set (match_operand:SI 0 "arith_reg_dest")
1577 (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand")
1578 (match_operand:SI 2 "arith_reg_or_0_operand"))
1579 (match_operand 3 "treg_set_expr")))
1580 (clobber (reg:SI T_REG))]
1581 "TARGET_SH1 && can_create_pseudo_p ()"
1586 sh_treg_insns ti = sh_split_treg_set_expr (operands[3], curr_insn);
1587 if (ti.has_trailing_nott ())
1589 if (operands[2] == const0_rtx)
1591 /* op1 + 0 + (1 - T) = op1 + 1 - T = op1 - (-1) - T */
1592 remove_insn (ti.trailing_nott ());
1593 emit_insn (gen_subc (operands[0], operands[1],
1594 force_reg (SImode, GEN_INT (-1))));
1597 else if (!TARGET_SH2A)
1599 /* op1 + op2 + (1 - T) = op1 - (0 - op2 - 1) - T = op1 - ~op2 - T
1600 On SH2A keep the nott insn, because nott-addc sequence doesn't
1601 mutate the inputs. */
1602 remove_insn (ti.trailing_nott ());
1603 rtx tmp = gen_reg_rtx (SImode);
1604 emit_insn (gen_one_cmplsi2 (tmp, operands[2]));
1605 emit_insn (gen_subc (operands[0], operands[1], tmp));
1610 emit_insn (gen_addc (operands[0], operands[1],
1611 force_reg (SImode, operands[2])));
1615 (define_insn_and_split "*addc"
1616 [(set (match_operand:SI 0 "arith_reg_dest")
1617 (plus:SI (plus:SI (match_operand 1 "treg_set_expr")
1618 (match_operand:SI 2 "arith_reg_operand"))
1619 (match_operand:SI 3 "arith_reg_operand")))
1620 (clobber (reg:SI T_REG))]
1621 "TARGET_SH1 && can_create_pseudo_p ()"
1624 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 3))
1626 (clobber (reg:SI T_REG))])])
1628 (define_insn_and_split "*addc"
1629 [(set (match_operand:SI 0 "arith_reg_dest")
1630 (plus:SI (match_operand 1 "treg_set_expr")
1631 (plus:SI (match_operand:SI 2 "arith_reg_operand")
1632 (match_operand:SI 3 "arith_reg_operand"))))
1633 (clobber (reg:SI T_REG))]
1634 "TARGET_SH1 && can_create_pseudo_p ()"
1637 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 3))
1639 (clobber (reg:SI T_REG))])])
1641 ;; Sometimes combine will try to do 'reg + (0-reg) + 1' if the *addc pattern
1642 ;; matched. Split this up into a simple sub add sequence, as this will save
1643 ;; us one sett insn.
1644 (define_insn_and_split "*minus_plus_one"
1645 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1646 (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
1647 (match_operand:SI 2 "arith_reg_operand" "r"))
1652 [(set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))
1653 (set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))])
1656 ;; The tree optimiziers canonicalize
1661 ;; On SH2A an add-bclr sequence will be used to handle this.
1662 ;; On non-SH2A re-emit the add-and sequence to improve register utilization.
1663 (define_insn_and_split "*round_int_even"
1664 [(set (match_operand:SI 0 "arith_reg_dest")
1665 (and:SI (plus:SI (match_operand:SI 1 "arith_reg_operand")
1668 "TARGET_SH1 && !TARGET_SH2A && can_create_pseudo_p ()
1669 && !reg_overlap_mentioned_p (operands[0], operands[1])"
1672 [(set (match_dup 0) (const_int -2))
1673 (set (match_dup 2) (plus:SI (match_dup 1) (const_int 1)))
1674 (set (match_dup 0) (and:SI (match_dup 0) (match_dup 2)))]
1676 operands[2] = gen_reg_rtx (SImode);
1679 ;; If the *round_int_even pattern is combined with another plus,
1680 ;; convert it into an addc pattern to emit an shlr-addc sequence.
1681 ;; This split is taken by combine on non-SH2A and SH2A.
1683 [(set (match_operand:SI 0 "arith_reg_dest")
1684 (plus:SI (and:SI (plus:SI (match_operand:SI 1 "arith_reg_operand")
1687 (match_operand:SI 2 "arith_reg_operand")))]
1688 "TARGET_SH1 && can_create_pseudo_p ()"
1689 [(parallel [(set (match_dup 0)
1690 (plus:SI (plus:SI (match_dup 1) (match_dup 2))
1691 (and:SI (match_dup 1) (const_int 1))))
1692 (clobber (reg:SI T_REG))])])
1694 ;; Split 'reg + T' into 'reg + 0 + T' to utilize the addc insn.
1695 ;; If the 0 constant can be CSE-ed, this becomes a one instruction
1696 ;; operation, as opposed to sequences such as
1700 ;; Even if the constant is not CSE-ed, a sequence such as
1703 ;; can be scheduled much better since the load of the constant can be
1704 ;; done earlier, before any comparison insns that store the result in
1706 ;; However, avoid things like 'reg + 1', which would expand into a
1707 ;; 3 insn sequence, instead of add #imm8.
1708 (define_insn_and_split "*addc_t_r"
1709 [(set (match_operand:SI 0 "arith_reg_dest")
1710 (plus:SI (match_operand 1 "treg_set_expr_not_const01")
1711 (match_operand:SI 2 "arith_reg_operand")))
1712 (clobber (reg:SI T_REG))]
1713 "TARGET_SH1 && can_create_pseudo_p ()"
1716 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (const_int 0))
1718 (clobber (reg:SI T_REG))])])
1720 (define_insn_and_split "*addc_r_t"
1721 [(set (match_operand:SI 0 "arith_reg_dest")
1722 (plus:SI (match_operand:SI 1 "arith_reg_operand")
1723 (match_operand 2 "treg_set_expr_not_const01")))
1724 (clobber (reg:SI T_REG))]
1725 "TARGET_SH1 && can_create_pseudo_p ()"
1728 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (const_int 0))
1730 (clobber (reg:SI T_REG))])])
1732 ;; Convert '2 * reg + T' into 'reg + reg + T'.
1733 (define_insn_and_split "*addc_2r_t"
1734 [(set (match_operand:SI 0 "arith_reg_dest")
1735 (plus:SI (match_operand 1 "treg_set_expr")
1736 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
1738 (clobber (reg:SI T_REG))]
1739 "TARGET_SH1 && can_create_pseudo_p ()"
1742 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 2))
1744 (clobber (reg:SI T_REG))])])
1746 (define_insn_and_split "*addc_2r_t"
1747 [(set (match_operand:SI 0 "arith_reg_dest")
1748 (plus:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
1750 (match_operand 2 "treg_set_expr")))
1751 (clobber (reg:SI T_REG))]
1752 "TARGET_SH1 && can_create_pseudo_p ()"
1755 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (match_dup 1))
1757 (clobber (reg:SI T_REG))])])
1759 ;; Convert '(op2 + T) - op3' into 'op2 + (-op3) + T'
1760 (define_insn_and_split "*addc_negreg_t"
1761 [(set (match_operand:SI 0 "arith_reg_dest")
1762 (minus:SI (plus:SI (match_operand 1 "treg_set_expr")
1763 (match_operand:SI 2 "arith_reg_operand"))
1764 (match_operand:SI 3 "arith_reg_operand")))
1765 (clobber (reg:SI T_REG))]
1766 "TARGET_SH1 && can_create_pseudo_p ()"
1769 [(set (match_dup 4) (neg:SI (match_dup 3)))
1770 (parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 4))
1772 (clobber (reg:SI T_REG))])]
1774 operands[4] = gen_reg_rtx (SImode);
1777 (define_expand "addsi3"
1778 [(set (match_operand:SI 0 "arith_reg_dest")
1779 (plus:SI (match_operand:SI 1 "arith_reg_operand")
1780 (match_operand:SI 2 "arith_or_int_operand")))]
1783 if (!arith_operand (operands[2], SImode))
1785 if (!sh_lra_p () || reg_overlap_mentioned_p (operands[0], operands[1]))
1787 emit_insn (gen_addsi3_scr (operands[0], operands[1], operands[2]));
1793 ;; The *addsi3_compact is made an insn_and_split and accepts actually
1794 ;; impossible constraints to make LRA's register elimination work well on SH.
1795 ;; The problem is that LRA expects something like
1796 ;; (set rA (plus rB (const_int N)))
1797 ;; to work. We can do that, but we have to split out an additional reg-reg
1798 ;; copy or constant load before the actual add insn.
1799 ;; Use u constraint for that case to avoid the invalid value in the stack
1801 ;; This also results in better code when LRA is not used. However, we have
1802 ;; to use different sets of patterns and the order of these patterns is
1804 ;; In some cases the constant zero might end up in operands[2] of the
1805 ;; patterns. We have to accept that and convert it into a reg-reg move.
1806 (define_insn_and_split "*addsi3_compact_lra"
1807 [(set (match_operand:SI 0 "arith_reg_dest" "=r,&u")
1808 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0,r")
1809 (match_operand:SI 2 "arith_or_int_operand" "rI08,rn")))]
1810 "TARGET_SH1 && sh_lra_p ()
1811 && (! reg_overlap_mentioned_p (operands[0], operands[1])
1812 || arith_operand (operands[2], SImode))"
1816 "&& reload_completed
1817 && ! reg_overlap_mentioned_p (operands[0], operands[1])"
1818 [(set (match_dup 0) (match_dup 2))
1819 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))]
1821 /* Prefer 'mov r0,r1; add #imm8,r1' over 'mov #imm8,r1; add r0,r1' */
1822 if (satisfies_constraint_I08 (operands[2]))
1823 std::swap (operands[1], operands[2]);
1825 [(set_attr "type" "arith")])
1827 (define_insn_and_split "addsi3_scr"
1828 [(set (match_operand:SI 0 "arith_reg_dest" "=r,&u,&u")
1829 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0,r,r")
1830 (match_operand:SI 2 "arith_or_int_operand" "rI08,r,n")))
1831 (clobber (match_scratch:SI 3 "=X,X,&u"))]
1837 "&& reload_completed"
1838 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1840 if (operands[2] == const0_rtx)
1842 emit_move_insn (operands[0], operands[1]);
1846 if (CONST_INT_P (operands[2]) && !satisfies_constraint_I08 (operands[2]))
1848 if (reg_overlap_mentioned_p (operands[0], operands[1]))
1850 emit_move_insn (operands[3], operands[2]);
1851 emit_move_insn (operands[0], operands[1]);
1852 operands[2] = operands[3];
1856 emit_move_insn (operands[0], operands[2]);
1857 operands[2] = operands[1];
1860 else if (!reg_overlap_mentioned_p (operands[0], operands[1]))
1862 if (!reg_overlap_mentioned_p (operands[0], operands[2]))
1863 emit_move_insn (operands[0], operands[1]);
1865 operands[2] = operands[1];
1868 [(set_attr "type" "arith")])
1870 ;; Old reload might generate add insns directly (not through the expander) for
1871 ;; address register calculations when reloading, in which case it won't try
1872 ;; the addsi_scr pattern. Because reload will sometimes try to validate
1873 ;; the generated insns and their constraints, this pattern must be
1874 ;; recognizable during and after reload. However, when reload generates
1875 ;; address register calculations for the stack pointer, we don't allow this
1876 ;; pattern. This will make reload prefer using indexed @(reg + reg) address
1877 ;; modes when the displacement of a @(disp + reg) doesn't fit.
1878 (define_insn_and_split "*addsi3"
1879 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1880 (plus:SI (match_operand:SI 1 "arith_reg_operand" "r")
1881 (match_operand:SI 2 "arith_or_int_operand" "rn")))]
1882 "TARGET_SH1 && !sh_lra_p ()
1883 && (reload_completed || reload_in_progress)
1884 && !reg_overlap_mentioned_p (operands[0], operands[1])
1885 && (!reload_in_progress
1886 || ((!REG_P (operands[1]) || REGNO (operands[1]) != SP_REG)
1887 && (!REG_P (operands[2]) || REGNO (operands[2]) != SP_REG)))"
1890 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1892 if (operands[2] == const0_rtx)
1894 emit_move_insn (operands[0], operands[1]);
1898 if (CONST_INT_P (operands[2]))
1900 if (satisfies_constraint_I08 (operands[2]))
1901 emit_move_insn (operands[0], operands[1]);
1904 emit_move_insn (operands[0], operands[2]);
1905 operands[2] = operands[1];
1908 else if (!reg_overlap_mentioned_p (operands[0], operands[2]))
1909 emit_move_insn (operands[0], operands[1]);
1911 operands[2] = operands[1];
1914 (define_insn_and_split "*addsi3"
1915 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1916 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0,r")
1917 (match_operand:SI 2 "arith_operand" "rI08,Z")))]
1918 "TARGET_SH1 && !sh_lra_p ()"
1922 "&& operands[2] == const0_rtx"
1923 [(set (match_dup 0) (match_dup 1))]
1926 [(set_attr "type" "arith")])
1928 ;; -------------------------------------------------------------------------
1929 ;; Subtraction instructions
1930 ;; -------------------------------------------------------------------------
1932 (define_insn_and_split "subdi3"
1933 [(set (match_operand:DI 0 "arith_reg_dest")
1934 (minus:DI (match_operand:DI 1 "arith_reg_operand")
1935 (match_operand:DI 2 "arith_reg_operand")))
1936 (clobber (reg:SI T_REG))]
1937 "TARGET_SH1 && can_create_pseudo_p ()"
1942 emit_insn (gen_clrt ());
1943 emit_insn (gen_subc (gen_lowpart (SImode, operands[0]),
1944 gen_lowpart (SImode, operands[1]),
1945 gen_lowpart (SImode, operands[2])));
1946 emit_insn (gen_subc (gen_highpart (SImode, operands[0]),
1947 gen_highpart (SImode, operands[1]),
1948 gen_highpart (SImode, operands[2])));
1953 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1954 (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
1955 (match_operand:SI 2 "arith_reg_operand" "r"))
1958 (gtu:SI (minus:SI (minus:SI (match_dup 1) (match_dup 2))
1963 [(set_attr "type" "arith")])
1965 ;; A simplified version of the subc insn, where the exact value of the
1966 ;; T bit doesn't matter. This is easier for combine to pick up.
1967 ;; We allow a reg or 0 for one of the operands in order to be able to
1968 ;; do 'reg - T' sequences. Reload will load the constant 0 into the reg
1970 (define_insn_and_split "*subc"
1971 [(set (match_operand:SI 0 "arith_reg_dest")
1972 (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand")
1973 (match_operand:SI 2 "arith_reg_or_0_operand"))
1974 (match_operand 3 "treg_set_expr")))
1975 (clobber (reg:SI T_REG))]
1976 "TARGET_SH1 && can_create_pseudo_p ()"
1981 sh_treg_insns ti = sh_split_treg_set_expr (operands[3], curr_insn);
1982 if (ti.has_trailing_nott ())
1984 if (operands[2] == const0_rtx)
1986 /* op1 - (1 - T) = op1 - 1 + T = op1 + (-1) + T */
1987 remove_insn (ti.trailing_nott ());
1988 emit_insn (gen_addc (operands[0], operands[1],
1989 force_reg (SImode, GEN_INT (-1))));
1992 else if (!TARGET_SH2A)
1994 /* op1 - op2 - (1 - T) = op1 + (0 - op2 - 1) + T = op1 + ~op2 + T
1995 On SH2A keep the nott insn, because nott-subc sequence doesn't
1996 mutate the inputs. */
1997 remove_insn (ti.trailing_nott ());
1998 rtx tmp = gen_reg_rtx (SImode);
1999 emit_insn (gen_one_cmplsi2 (tmp, operands[2]));
2000 emit_insn (gen_addc (operands[0], operands[1], tmp));
2005 emit_insn (gen_subc (operands[0], operands[1],
2006 force_reg (SImode, operands[2])));
2010 ;; Convert reg - T - reg = reg - reg - T
2011 (define_insn_and_split "*subc"
2012 [(set (match_operand:SI 0 "arith_reg_dest")
2013 (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand")
2014 (match_operand 2 "treg_set_expr"))
2015 (match_operand:SI 3 "arith_reg_operand")))
2016 (clobber (reg:SI T_REG))]
2017 "TARGET_SH1 && can_create_pseudo_p ()"
2020 [(parallel [(set (match_dup 0)
2021 (minus:SI (minus:SI (match_dup 1) (match_dup 3))
2023 (clobber (reg:SI T_REG))])])
2025 ;; Split reg - reg - 1 into a sett subc sequence, as it can be scheduled
2026 ;; better, if the sett insn can be done early.
2027 ;; Notice that combine turns 'a - b - 1' into 'a + (~b)'.
2028 (define_insn_and_split "*subc"
2029 [(set (match_operand:SI 0 "arith_reg_dest" "")
2030 (plus:SI (not:SI (match_operand:SI 1 "arith_reg_operand" ""))
2031 (match_operand:SI 2 "arith_reg_operand" "")))
2032 (clobber (reg:SI T_REG))]
2033 "TARGET_SH1 && can_create_pseudo_p ()"
2036 [(parallel [(set (match_dup 0)
2037 (minus:SI (minus:SI (match_dup 2) (match_dup 1))
2039 (clobber (reg:SI T_REG))])])
2041 ;; Split 'reg - T' into 'reg - 0 - T' to utilize the subc insn.
2042 ;; If the 0 constant can be CSE-ed, this becomes a one instruction
2043 ;; operation, as opposed to sequences such as
2047 ;; Even if the constant is not CSE-ed, a sequence such as
2050 ;; can be scheduled much better since the load of the constant can be
2051 ;; done earlier, before any comparison insns that store the result in
2053 ;; However, avoid things like 'reg - 1', which would expand into a
2054 ;; 3 insn sequence, instead of add #imm8.
2055 (define_insn_and_split "*subc"
2056 [(set (match_operand:SI 0 "arith_reg_dest" "")
2057 (minus:SI (match_operand:SI 1 "arith_reg_operand" "")
2058 (match_operand 2 "treg_set_expr_not_const01")))
2059 (clobber (reg:SI T_REG))]
2060 "TARGET_SH1 && can_create_pseudo_p ()"
2063 [(parallel [(set (match_dup 0)
2064 (minus:SI (minus:SI (match_dup 1) (const_int 0))
2066 (clobber (reg:SI T_REG))])])
2069 ;; (1 - T) - op2 = 1 - op2 - T
2070 (define_insn_and_split "*subc_negt_reg"
2071 [(set (match_operand:SI 0 "arith_reg_dest")
2072 (minus:SI (match_operand 1 "treg_set_expr_not_const01")
2073 (match_operand:SI 2 "arith_reg_operand")))
2074 (clobber (reg:SI T_REG))]
2075 "TARGET_SH1 && can_create_pseudo_p ()"
2080 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
2081 if (ti.remove_trailing_nott ())
2083 /* (1 - T) - op2 = 1 - op2 - T */
2084 emit_insn (gen_subc (operands[0],
2085 force_reg (SImode, GEN_INT (1)), operands[2]));
2089 /* T - op2: use movt,sub sequence. */
2090 rtx tmp = gen_reg_rtx (SImode);
2091 emit_insn (gen_movt (tmp, get_t_reg_rtx ()));
2092 emit_insn (gen_subsi3 (operands[0], tmp, operands[2]));
2098 ;; op1 - (1 - T) + op3 = op1 - 1 + T + op3
2099 ;; (op1 - T) + op3 = op1 - (-op3) - T
2100 (define_insn_and_split "*subc_negreg_t"
2101 [(set (match_operand:SI 0 "arith_reg_dest")
2102 (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand")
2103 (match_operand 2 "treg_set_expr"))
2104 (match_operand:SI 3 "arith_reg_operand")))
2105 (clobber (reg:SI T_REG))]
2106 "TARGET_SH1 && can_create_pseudo_p ()"
2111 sh_treg_insns ti = sh_split_treg_set_expr (operands[2], curr_insn);
2112 if (ti.remove_trailing_nott ())
2114 /* op1 - (1 - T) + op3 = (op1 - 1) + op3 + T */
2115 rtx tmp = gen_reg_rtx (SImode);
2116 emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (-1)));
2117 emit_insn (gen_addc (operands[0], tmp, operands[3]));
2121 /* (op1 - T) + op3' = 'op1 - (-op3) - T */
2122 rtx tmp = gen_reg_rtx (SImode);
2123 emit_insn (gen_negsi2 (tmp, operands[3]));
2124 emit_insn (gen_subc (operands[0], operands[1], tmp));
2129 (define_insn "*subsi3_internal"
2130 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2131 (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
2132 (match_operand:SI 2 "arith_reg_operand" "r")))]
2135 [(set_attr "type" "arith")])
2142 ;; since this will sometimes save one instruction.
2143 ;; Otherwise we might get a sequence like
2147 ;; if the source and dest regs are the same.
2148 (define_expand "subsi3"
2149 [(set (match_operand:SI 0 "arith_reg_operand" "")
2150 (minus:SI (match_operand:SI 1 "arith_operand" "")
2151 (match_operand:SI 2 "arith_reg_operand" "")))]
2154 if (CONST_INT_P (operands[1]))
2156 emit_insn (gen_negsi2 (operands[0], operands[2]));
2157 emit_insn (gen_addsi3 (operands[0], operands[0], operands[1]));
2162 ;; -------------------------------------------------------------------------
2163 ;; Division instructions
2164 ;; -------------------------------------------------------------------------
2166 ;; We take advantage of the library routines which don't clobber as many
2167 ;; registers as a normal function call would.
2169 ;; The INSN_REFERENCES_ARE_DELAYED in sh.h is problematic because it
2170 ;; also has an effect on the register that holds the address of the sfunc.
2171 ;; To make this work, we have an extra dummy insn that shows the use
2172 ;; of this register for reorg.
2174 (define_insn "use_sfunc_addr"
2175 [(set (reg:SI PR_REG)
2176 (unspec:SI [(match_operand:SI 0 "register_operand" "r")] UNSPEC_SFUNC))]
2177 "TARGET_SH1 && check_use_sfunc_addr (insn, operands[0])"
2179 [(set_attr "length" "0")])
2181 (define_insn "udivsi3_sh2a"
2182 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2183 (udiv:SI (match_operand:SI 1 "arith_reg_operand" "0")
2184 (match_operand:SI 2 "arith_reg_operand" "z")))]
2187 [(set_attr "type" "arith")
2188 (set_attr "in_delay_slot" "no")])
2190 ;; We must use a pseudo-reg forced to reg 0 in the SET_DEST rather than
2191 ;; hard register 0. If we used hard register 0, then the next instruction
2192 ;; would be a move from hard register 0 to a pseudo-reg. If the pseudo-reg
2193 ;; gets allocated to a stack slot that needs its address reloaded, then
2194 ;; there is nothing to prevent reload from using r0 to reload the address.
2195 ;; This reload would clobber the value in r0 we are trying to store.
2196 ;; If we let reload allocate r0, then this problem can never happen.
2197 (define_insn "udivsi3_i1"
2198 [(set (match_operand:SI 0 "register_operand" "=z,z")
2199 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2200 (clobber (reg:SI T_REG))
2201 (clobber (reg:SI PR_REG))
2202 (clobber (reg:SI R1_REG))
2203 (clobber (reg:SI R4_REG))
2204 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2205 (use (match_operand 2 "" "Z,Ccl"))]
2206 "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
2210 [(set_attr "type" "sfunc")
2211 (set_attr "needs_delay_slot" "yes")])
2213 (define_insn "udivsi3_i4"
2214 [(set (match_operand:SI 0 "register_operand" "=y,y")
2215 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2216 (clobber (reg:SI T_REG))
2217 (clobber (reg:SI PR_REG))
2218 (clobber (reg:DF DR0_REG))
2219 (clobber (reg:DF DR2_REG))
2220 (clobber (reg:DF DR4_REG))
2221 (clobber (reg:SI R0_REG))
2222 (clobber (reg:SI R1_REG))
2223 (clobber (reg:SI R4_REG))
2224 (clobber (reg:SI R5_REG))
2225 (clobber (reg:SI FPSCR_STAT_REG))
2226 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2227 (use (match_operand 2 "" "Z,Ccl"))
2228 (use (reg:SI FPSCR_MODES_REG))]
2229 "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
2233 [(set_attr "type" "sfunc")
2234 (set_attr "fp_mode" "double")
2235 (set_attr "needs_delay_slot" "yes")])
2237 (define_insn "udivsi3_i4_single"
2238 [(set (match_operand:SI 0 "register_operand" "=y,y")
2239 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2240 (clobber (reg:SI T_REG))
2241 (clobber (reg:SI PR_REG))
2242 (clobber (reg:DF DR0_REG))
2243 (clobber (reg:DF DR2_REG))
2244 (clobber (reg:DF DR4_REG))
2245 (clobber (reg:SI R0_REG))
2246 (clobber (reg:SI R1_REG))
2247 (clobber (reg:SI R4_REG))
2248 (clobber (reg:SI R5_REG))
2249 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2250 (use (match_operand 2 "" "Z,Ccl"))]
2251 "TARGET_FPU_ANY && TARGET_FPU_SINGLE"
2255 [(set_attr "type" "sfunc")
2256 (set_attr "needs_delay_slot" "yes")])
2258 (define_insn "udivsi3_i4_int"
2259 [(set (match_operand:SI 0 "register_operand" "=z")
2260 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2261 (clobber (reg:SI T_REG))
2262 (clobber (reg:SI R1_REG))
2263 (clobber (reg:SI PR_REG))
2264 (clobber (reg:SI MACH_REG))
2265 (clobber (reg:SI MACL_REG))
2266 (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2269 [(set_attr "type" "sfunc")
2270 (set_attr "needs_delay_slot" "yes")])
2273 (define_expand "udivsi3"
2274 [(set (match_operand:SI 0 "register_operand")
2275 (udiv:SI (match_operand:SI 1 "general_operand")
2276 (match_operand:SI 2 "general_operand")))]
2280 rtx func_ptr = gen_reg_rtx (Pmode);
2282 /* Emit the move of the address to a pseudo outside of the libcall. */
2283 if (TARGET_DIVIDE_CALL_TABLE)
2285 /* libgcc2:__udivmoddi4 is not supposed to use an actual division, since
2286 that causes problems when the divide code is supposed to come from a
2287 separate library. Division by zero is undefined, so dividing 1 can be
2288 implemented by comparing with the divisor. */
2289 if (operands[1] == const1_rtx && currently_expanding_to_rtl)
2291 rtx test = gen_rtx_GEU (VOIDmode, operands[1], operands[2]);
2292 emit_insn (gen_cstoresi4 (operands[0], test,
2293 operands[1], operands[2]));
2296 else if (operands[2] == const0_rtx)
2298 emit_move_insn (operands[0], operands[2]);
2301 function_symbol (func_ptr, "__udivsi3_i4i", SFUNC_GOT);
2302 last = gen_udivsi3_i4_int (operands[0], func_ptr);
2304 else if (TARGET_DIVIDE_CALL_FP)
2306 rtx lab = function_symbol (func_ptr, "__udivsi3_i4", SFUNC_STATIC).lab;
2307 if (TARGET_FPU_SINGLE)
2308 last = gen_udivsi3_i4_single (operands[0], func_ptr, lab);
2310 last = gen_udivsi3_i4 (operands[0], func_ptr, lab);
2312 else if (TARGET_SH2A)
2314 operands[1] = force_reg (SImode, operands[1]);
2315 operands[2] = force_reg (SImode, operands[2]);
2316 emit_insn (gen_udivsi3_sh2a (operands[0], operands[1], operands[2]));
2321 rtx lab = function_symbol (func_ptr, "__udivsi3", SFUNC_STATIC).lab;
2322 last = gen_udivsi3_i1 (operands[0], func_ptr, lab);
2324 emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
2325 emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
2330 (define_insn "divsi3_sh2a"
2331 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2332 (div:SI (match_operand:SI 1 "arith_reg_operand" "0")
2333 (match_operand:SI 2 "arith_reg_operand" "z")))]
2336 [(set_attr "type" "arith")
2337 (set_attr "in_delay_slot" "no")])
2339 (define_insn "divsi3_i1"
2340 [(set (match_operand:SI 0 "register_operand" "=z")
2341 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2342 (clobber (reg:SI T_REG))
2343 (clobber (reg:SI PR_REG))
2344 (clobber (reg:SI R1_REG))
2345 (clobber (reg:SI R2_REG))
2346 (clobber (reg:SI R3_REG))
2347 (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2348 "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
2350 [(set_attr "type" "sfunc")
2351 (set_attr "needs_delay_slot" "yes")])
2353 (define_insn "divsi3_i4"
2354 [(set (match_operand:SI 0 "register_operand" "=y,y")
2355 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2356 (clobber (reg:SI PR_REG))
2357 (clobber (reg:DF DR0_REG))
2358 (clobber (reg:DF DR2_REG))
2359 (clobber (reg:SI FPSCR_STAT_REG))
2360 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2361 (use (match_operand 2 "" "Z,Ccl"))
2362 (use (reg:SI FPSCR_MODES_REG))]
2363 "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
2367 [(set_attr "type" "sfunc")
2368 (set_attr "fp_mode" "double")
2369 (set_attr "needs_delay_slot" "yes")])
2371 (define_insn "divsi3_i4_single"
2372 [(set (match_operand:SI 0 "register_operand" "=y,y")
2373 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2374 (clobber (reg:SI PR_REG))
2375 (clobber (reg:DF DR0_REG))
2376 (clobber (reg:DF DR2_REG))
2377 (clobber (reg:SI R2_REG))
2378 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2379 (use (match_operand 2 "" "Z,Ccl"))]
2380 "TARGET_FPU_ANY && TARGET_FPU_SINGLE"
2384 [(set_attr "type" "sfunc")
2385 (set_attr "needs_delay_slot" "yes")])
2387 (define_insn "divsi3_i4_int"
2388 [(set (match_operand:SI 0 "register_operand" "=z")
2389 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2390 (clobber (reg:SI T_REG))
2391 (clobber (reg:SI PR_REG))
2392 (clobber (reg:SI R1_REG))
2393 (clobber (reg:SI MACH_REG))
2394 (clobber (reg:SI MACL_REG))
2395 (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2398 [(set_attr "type" "sfunc")
2399 (set_attr "needs_delay_slot" "yes")])
2401 (define_expand "divsi3"
2402 [(set (match_operand:SI 0 "register_operand")
2403 (div:SI (match_operand:SI 1 "general_operand")
2404 (match_operand:SI 2 "general_operand")))]
2408 rtx func_ptr = gen_reg_rtx (Pmode);
2410 /* Emit the move of the address to a pseudo outside of the libcall. */
2411 if (TARGET_DIVIDE_CALL_TABLE)
2413 function_symbol (func_ptr, sh_divsi3_libfunc, SFUNC_GOT);
2414 last = gen_divsi3_i4_int (operands[0], func_ptr);
2416 else if (TARGET_DIVIDE_CALL_FP)
2418 rtx lab = function_symbol (func_ptr, sh_divsi3_libfunc,
2420 if (TARGET_FPU_SINGLE)
2421 last = gen_divsi3_i4_single (operands[0], func_ptr, lab);
2423 last = gen_divsi3_i4 (operands[0], func_ptr, lab);
2425 else if (TARGET_SH2A)
2427 operands[1] = force_reg (SImode, operands[1]);
2428 operands[2] = force_reg (SImode, operands[2]);
2429 emit_insn (gen_divsi3_sh2a (operands[0], operands[1], operands[2]));
2434 function_symbol (func_ptr, sh_divsi3_libfunc, SFUNC_GOT);
2435 last = gen_divsi3_i1 (operands[0], func_ptr);
2437 emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
2438 emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
2444 ;; -------------------------------------------------------------------------
2445 ;; Multiplication instructions
2446 ;; -------------------------------------------------------------------------
2448 (define_insn_and_split "mulhisi3"
2449 [(set (match_operand:SI 0 "arith_reg_dest")
2450 (mult:SI (sign_extend:SI (match_operand:HI 1 "arith_reg_operand"))
2451 (sign_extend:SI (match_operand:HI 2 "arith_reg_operand"))))
2452 (clobber (reg:SI MACL_REG))]
2453 "TARGET_SH1 && can_create_pseudo_p ()"
2456 [(set (reg:SI MACL_REG) (mult:SI (sign_extend:SI (match_dup 1))
2457 (sign_extend:SI (match_dup 2))))
2458 (set (match_dup 0) (reg:SI MACL_REG))])
2460 (define_insn_and_split "umulhisi3"
2461 [(set (match_operand:SI 0 "arith_reg_dest")
2462 (mult:SI (zero_extend:SI (match_operand:HI 1 "arith_reg_operand"))
2463 (zero_extend:SI (match_operand:HI 2 "arith_reg_operand"))))
2464 (clobber (reg:SI MACL_REG))]
2465 "TARGET_SH1 && can_create_pseudo_p ()"
2468 [(set (reg:SI MACL_REG) (mult:SI (zero_extend:SI (match_dup 1))
2469 (zero_extend:SI (match_dup 2))))
2470 (set (match_dup 0) (reg:SI MACL_REG))])
2472 (define_insn "umulhisi3_i"
2473 [(set (reg:SI MACL_REG)
2474 (mult:SI (zero_extend:SI
2475 (match_operand:HI 0 "arith_reg_operand" "r"))
2477 (match_operand:HI 1 "arith_reg_operand" "r"))))]
2480 [(set_attr "type" "smpy")])
2482 (define_insn "mulhisi3_i"
2483 [(set (reg:SI MACL_REG)
2484 (mult:SI (sign_extend:SI
2485 (match_operand:HI 0 "arith_reg_operand" "r"))
2487 (match_operand:HI 1 "arith_reg_operand" "r"))))]
2490 [(set_attr "type" "smpy")])
2493 ;; mulsi3 on the SH2 can be done in one instruction, on the SH1 we generate
2494 ;; a call to a routine which clobbers known registers.
2495 (define_insn "mulsi3_call"
2496 [(set (match_operand:SI 1 "register_operand" "=z")
2497 (mult:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2498 (clobber (reg:SI MACL_REG))
2499 (clobber (reg:SI T_REG))
2500 (clobber (reg:SI PR_REG))
2501 (clobber (reg:SI R3_REG))
2502 (clobber (reg:SI R2_REG))
2503 (clobber (reg:SI R1_REG))
2504 (use (match_operand:SI 0 "arith_reg_operand" "r"))]
2507 [(set_attr "type" "sfunc")
2508 (set_attr "needs_delay_slot" "yes")])
2510 (define_insn "mul_r"
2511 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2512 (mult:SI (match_operand:SI 1 "arith_reg_operand" "0")
2513 (match_operand:SI 2 "arith_reg_operand" "z")))]
2516 [(set_attr "type" "dmpy")])
2518 (define_insn "mul_l"
2519 [(set (reg:SI MACL_REG)
2520 (mult:SI (match_operand:SI 0 "arith_reg_operand" "r")
2521 (match_operand:SI 1 "arith_reg_operand" "r")))]
2524 [(set_attr "type" "dmpy")])
2526 (define_insn_and_split "mulsi3_i"
2527 [(set (match_operand:SI 0 "arith_reg_dest")
2528 (mult:SI (match_operand:SI 1 "arith_reg_operand")
2529 (match_operand:SI 2 "arith_reg_operand")))
2530 (clobber (reg:SI MACL_REG))]
2531 "TARGET_SH2 && can_create_pseudo_p ()"
2534 [(set (reg:SI MACL_REG) (mult:SI (match_dup 1) (match_dup 2)))
2535 (set (match_dup 0) (reg:SI MACL_REG))])
2537 (define_expand "mulsi3"
2538 [(set (match_operand:SI 0 "arith_reg_dest")
2539 (mult:SI (match_operand:SI 1 "arith_reg_operand")
2540 (match_operand:SI 2 "arith_reg_operand")))]
2545 emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
2546 emit_move_insn (gen_rtx_REG (SImode, R5_REG), operands[2]);
2548 rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC).sym;
2550 emit_insn (gen_mulsi3_call (force_reg (SImode, sym), operands[0]));
2554 /* FIXME: For some reason, expanding the mul_l insn and the macl store
2555 insn early gives slightly better code. In particular it prevents
2556 the decrement-test loop type to be used in some cases which saves
2557 one multiplication in the loop setup code.
2559 emit_insn (gen_mulsi3_i (operands[0], operands[1], operands[2]));
2562 emit_insn (gen_mul_l (operands[1], operands[2]));
2563 emit_move_insn (operands[0], gen_rtx_REG (SImode, MACL_REG));
2568 (define_insn "mulsidi3_i"
2569 [(set (reg:SI MACH_REG)
2573 (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2574 (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2576 (set (reg:SI MACL_REG)
2577 (mult:SI (match_dup 0)
2581 [(set_attr "type" "dmpy")])
2583 (define_expand "mulsidi3"
2584 [(set (match_operand:DI 0 "arith_reg_dest")
2585 (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2586 (sign_extend:DI (match_operand:SI 2 "arith_reg_operand"))))]
2589 emit_insn (gen_mulsidi3_compact (operands[0], operands[1], operands[2]));
2593 (define_insn_and_split "mulsidi3_compact"
2594 [(set (match_operand:DI 0 "arith_reg_dest")
2595 (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2596 (sign_extend:DI (match_operand:SI 2 "arith_reg_operand"))))
2597 (clobber (reg:SI MACH_REG))
2598 (clobber (reg:SI MACL_REG))]
2599 "TARGET_SH2 && can_create_pseudo_p ()"
2604 rtx low_dst = gen_lowpart (SImode, operands[0]);
2605 rtx high_dst = gen_highpart (SImode, operands[0]);
2607 emit_insn (gen_mulsidi3_i (operands[1], operands[2]));
2609 emit_move_insn (low_dst, gen_rtx_REG (SImode, MACL_REG));
2610 emit_move_insn (high_dst, gen_rtx_REG (SImode, MACH_REG));
2611 /* We need something to tag the possible REG_EQUAL notes on to. */
2612 emit_move_insn (operands[0], operands[0]);
2616 (define_insn "umulsidi3_i"
2617 [(set (reg:SI MACH_REG)
2621 (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2622 (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2624 (set (reg:SI MACL_REG)
2625 (mult:SI (match_dup 0)
2629 [(set_attr "type" "dmpy")])
2631 (define_expand "umulsidi3"
2632 [(set (match_operand:DI 0 "arith_reg_dest")
2633 (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2634 (zero_extend:DI (match_operand:SI 2 "arith_reg_operand"))))]
2637 emit_insn (gen_umulsidi3_compact (operands[0], operands[1], operands[2]));
2641 (define_insn_and_split "umulsidi3_compact"
2642 [(set (match_operand:DI 0 "arith_reg_dest")
2643 (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2644 (zero_extend:DI (match_operand:SI 2 "arith_reg_operand"))))
2645 (clobber (reg:SI MACH_REG))
2646 (clobber (reg:SI MACL_REG))]
2647 "TARGET_SH2 && can_create_pseudo_p ()"
2652 rtx low_dst = gen_lowpart (SImode, operands[0]);
2653 rtx high_dst = gen_highpart (SImode, operands[0]);
2655 emit_insn (gen_umulsidi3_i (operands[1], operands[2]));
2657 emit_move_insn (low_dst, gen_rtx_REG (SImode, MACL_REG));
2658 emit_move_insn (high_dst, gen_rtx_REG (SImode, MACH_REG));
2659 /* We need something to tag the possible REG_EQUAL notes on to. */
2660 emit_move_insn (operands[0], operands[0]);
2664 (define_insn "smulsi3_highpart_i"
2665 [(set (reg:SI MACH_REG)
2669 (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2670 (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2672 (clobber (reg:SI MACL_REG))]
2675 [(set_attr "type" "dmpy")])
2677 (define_insn_and_split "smulsi3_highpart"
2678 [(set (match_operand:SI 0 "arith_reg_dest")
2682 (sign_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2683 (sign_extend:DI (match_operand:SI 2 "arith_reg_operand")))
2685 (clobber (reg:SI MACL_REG))
2686 (clobber (reg:SI MACH_REG))]
2687 "TARGET_SH2 && can_create_pseudo_p ()"
2692 emit_insn (gen_smulsi3_highpart_i (operands[1], operands[2]));
2693 emit_move_insn (operands[0], gen_rtx_REG (SImode, MACH_REG));
2696 (define_insn "umulsi3_highpart_i"
2697 [(set (reg:SI MACH_REG)
2701 (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2702 (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2704 (clobber (reg:SI MACL_REG))]
2707 [(set_attr "type" "dmpy")])
2709 (define_insn_and_split "umulsi3_highpart"
2710 [(set (match_operand:SI 0 "arith_reg_dest")
2714 (zero_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2715 (zero_extend:DI (match_operand:SI 2 "arith_reg_operand")))
2717 (clobber (reg:SI MACL_REG))]
2718 "TARGET_SH2 && can_create_pseudo_p ()"
2723 emit_insn (gen_umulsi3_highpart_i (operands[1], operands[2]));
2724 emit_move_insn (operands[0], gen_rtx_REG (SImode, MACH_REG));
2727 ;; -------------------------------------------------------------------------
2728 ;; Logical operations
2729 ;; -------------------------------------------------------------------------
2731 (define_expand "andsi3"
2732 [(set (match_operand:SI 0 "arith_reg_dest")
2733 (and:SI (match_operand:SI 1 "arith_reg_operand")
2734 (match_operand:SI 2 "logical_and_operand")))]
2737 /* If it is possible to turn the and insn into a zero extension
2738 already, redundant zero extensions will be folded, which results
2740 Ideally the splitter of *andsi_compact would be enough, if redundant
2741 zero extensions were detected after the combine pass, which does not
2742 happen at the moment. */
2744 if (satisfies_constraint_Jmb (operands[2]))
2746 emit_insn (gen_zero_extendqisi2 (operands[0],
2747 gen_lowpart (QImode, operands[1])));
2750 else if (satisfies_constraint_Jmw (operands[2]))
2752 emit_insn (gen_zero_extendhisi2 (operands[0],
2753 gen_lowpart (HImode, operands[1])));
2758 (define_insn_and_split "*andsi_compact"
2759 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r,z,r")
2760 (and:SI (match_operand:SI 1 "arith_reg_operand" "%r,r,0,0")
2761 (match_operand:SI 2 "logical_and_operand" "Jmb,Jmw,K08,r")))]
2769 [(set (match_dup 0) (zero_extend:SI (match_dup 1)))]
2771 if (satisfies_constraint_Jmb (operands[2]))
2772 operands[1] = gen_lowpart (QImode, operands[1]);
2773 else if (satisfies_constraint_Jmw (operands[2]))
2774 operands[1] = gen_lowpart (HImode, operands[1]);
2778 [(set_attr "type" "arith")])
2780 (define_insn "*andsi3_bclr"
2781 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2782 (and:SI (match_operand:SI 1 "arith_reg_operand" "%0")
2783 (match_operand:SI 2 "const_int_operand" "Psz")))]
2784 "TARGET_SH2A && satisfies_constraint_Psz (operands[2])"
2786 [(set_attr "type" "arith")])
2788 (define_expand "iorsi3"
2789 [(set (match_operand:SI 0 "arith_reg_dest")
2790 (ior:SI (match_operand:SI 1 "arith_reg_operand")
2791 (match_operand:SI 2 "logical_operand")))])
2793 (define_insn "*iorsi3_compact"
2794 [(set (match_operand:SI 0 "arith_reg_dest" "=r,z")
2795 (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
2796 (match_operand:SI 2 "logical_operand" "r,K08")))]
2798 && !(TARGET_SH2A && satisfies_constraint_Pso (operands[2]))"
2800 [(set_attr "type" "arith")])
2802 (define_insn "*iorsi3_bset"
2803 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2804 (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0")
2805 (match_operand:SI 2 "const_int_operand" "Pso")))]
2806 "TARGET_SH2A && satisfies_constraint_Pso (operands[2])"
2808 [(set_attr "type" "arith")])
2810 (define_insn "xorsi3"
2811 [(set (match_operand:SI 0 "arith_reg_dest" "=z,r")
2812 (xor:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
2813 (match_operand:SI 2 "logical_operand" "K08,r")))]
2816 [(set_attr "type" "arith")])
2818 ;; The *logical_op_t pattern helps combine eliminating sign/zero extensions
2819 ;; of results where one of the inputs is a T bit store. Notice that this
2820 ;; pattern must not match during reload. If reload picks this pattern it
2821 ;; will be impossible to split it afterwards.
2822 (define_insn_and_split "*logical_op_t"
2823 [(set (match_operand:SI 0 "arith_reg_dest")
2824 (match_operator:SI 3 "logical_operator"
2825 [(match_operand:SI 1 "arith_reg_operand")
2826 (match_operand:SI 2 "t_reg_operand")]))]
2827 "TARGET_SH1 && can_create_pseudo_p ()"
2830 [(set (match_dup 4) (reg:SI T_REG))
2831 (set (match_dup 0) (match_dup 3))]
2833 operands[4] = gen_reg_rtx (SImode);
2834 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2835 operands[1], operands[4]);
2838 ;; -------------------------------------------------------------------------
2839 ;; Shifts and rotates
2840 ;; -------------------------------------------------------------------------
2842 ;; Let combine see that we can get the MSB and LSB into the T bit
2843 ;; via shll and shlr. This allows it to plug it into insns that can have
2844 ;; the T bit as an input (e.g. addc).
2845 ;; On SH2A use bld #0,Rn instead of shlr to avoid mutating the input.
2846 (define_insn_and_split "*reg_lsb_t"
2847 [(set (reg:SI T_REG)
2848 (and:SI (match_operand:SI 0 "arith_reg_operand")
2850 "TARGET_SH1 && can_create_pseudo_p ()"
2855 emit_insn (TARGET_SH2A ? gen_bldsi_reg (operands[0], const0_rtx)
2856 : gen_shlr (gen_reg_rtx (SImode), operands[0]));
2859 (define_insn_and_split "*reg_msb_t"
2860 [(set (reg:SI T_REG)
2861 (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
2863 "TARGET_SH1 && can_create_pseudo_p ()"
2868 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
2871 (define_expand "rotrsi3"
2872 [(set (match_operand:SI 0 "arith_reg_dest")
2873 (rotatert:SI (match_operand:SI 1 "arith_reg_operand")
2874 (match_operand:SI 2 "const_int_operand")))]
2877 HOST_WIDE_INT ival = INTVAL (operands[2]);
2880 emit_insn (gen_rotrsi3_1 (operands[0], operands[1]));
2887 (define_insn "rotrsi3_1"
2888 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2889 (rotatert:SI (match_operand:SI 1 "arith_reg_operand" "0")
2892 (and:SI (match_dup 1) (const_int 1)))]
2895 [(set_attr "type" "arith")])
2897 ;; A slimplified version of rotr for combine.
2898 (define_insn "*rotrsi3_1"
2899 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2900 (rotatert:SI (match_operand:SI 1 "arith_reg_operand" "0")
2902 (clobber (reg:SI T_REG))]
2905 [(set_attr "type" "arith")])
2907 (define_insn "rotlsi3_1"
2908 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2909 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
2912 (lshiftrt:SI (match_dup 1) (const_int 31)))]
2915 [(set_attr "type" "arith")])
2917 ;; A simplified version of rotl for combine.
2918 (define_insn "*rotlsi3_1"
2919 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2920 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
2922 (clobber (reg:SI T_REG))]
2925 [(set_attr "type" "arith")])
2927 (define_insn "rotlsi3_31"
2928 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2929 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
2931 (clobber (reg:SI T_REG))]
2934 [(set_attr "type" "arith")])
2936 (define_insn "rotlsi3_16"
2937 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2938 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "r")
2942 [(set_attr "type" "arith")])
2944 (define_expand "rotlsi3"
2945 [(set (match_operand:SI 0 "arith_reg_dest")
2946 (rotate:SI (match_operand:SI 1 "arith_reg_operand")
2947 (match_operand:SI 2 "const_int_operand")))]
2950 static const char rot_tab[] = {
2951 000, 000, 000, 000, 000, 000, 010, 001,
2952 001, 001, 011, 013, 003, 003, 003, 003,
2953 003, 003, 003, 003, 003, 013, 012, 002,
2954 002, 002, 010, 000, 000, 000, 000, 000,
2957 int count = INTVAL (operands[2]);
2958 int choice = rot_tab[count];
2959 if (choice & 010 && SH_DYNAMIC_SHIFT_COST <= 1)
2965 emit_move_insn (operands[0], operands[1]);
2966 count -= (count & 16) * 2;
2969 emit_insn (gen_rotlsi3_16 (operands[0], operands[1]));
2976 parts[0] = gen_reg_rtx (SImode);
2977 parts[1] = gen_reg_rtx (SImode);
2978 emit_insn (gen_rotlsi3_16 (parts[2-choice], operands[1]));
2979 emit_move_insn (parts[choice-1], operands[1]);
2980 emit_insn (gen_ashlsi3 (parts[0], parts[0], GEN_INT (8)));
2981 emit_insn (gen_lshrsi3 (parts[1], parts[1], GEN_INT (8)));
2982 emit_insn (gen_iorsi3 (operands[0], parts[0], parts[1]));
2983 count = (count & ~16) - 8;
2987 for (; count > 0; count--)
2988 emit_insn (gen_rotlsi3_1 (operands[0], operands[0]));
2989 for (; count < 0; count++)
2990 emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
2995 (define_insn "rotlhi3_8"
2996 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
2997 (rotate:HI (match_operand:HI 1 "arith_reg_operand" "r")
3001 [(set_attr "type" "arith")])
3003 (define_expand "rotlhi3"
3004 [(set (match_operand:HI 0 "arith_reg_operand")
3005 (rotate:HI (match_operand:HI 1 "arith_reg_operand")
3006 (match_operand:HI 2 "const_int_operand")))]
3009 if (INTVAL (operands[2]) != 8)
3013 ;; The rotcr and rotcl insns are used primarily in DImode shifts by one.
3014 ;; They can also be used to implement things like
3016 ;; int x0 = (y >> 1) | (t << 31); // rotcr
3017 ;; int x1 = (y << 1) | t; // rotcl
3018 (define_insn "rotcr"
3019 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3020 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3022 (ashift:SI (match_operand:SI 2 "t_reg_operand")
3025 (and:SI (match_dup 1) (const_int 1)))]
3028 [(set_attr "type" "arith")])
3030 (define_insn "rotcl"
3031 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3032 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3034 (match_operand:SI 2 "t_reg_operand")))
3036 (lshiftrt:SI (match_dup 1) (const_int 31)))]
3039 [(set_attr "type" "arith")])
3041 ;; Simplified rotcr version for combine, which allows arbitrary shift
3042 ;; amounts for the reg. If the shift amount is '1' rotcr can be used
3043 ;; directly. Otherwise we have to insert a shift in between.
3044 (define_insn_and_split "*rotcr"
3045 [(set (match_operand:SI 0 "arith_reg_dest")
3046 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_or_0_operand")
3047 (match_operand:SI 2 "const_int_operand"))
3048 (ashift:SI (match_operand 3 "arith_reg_or_treg_set_expr")
3050 (clobber (reg:SI T_REG))]
3051 "TARGET_SH1 && can_create_pseudo_p ()"
3056 rtx_insn *prev_set_t_insn = NULL;
3058 if (!arith_reg_operand (operands[3], SImode))
3060 sh_treg_insns ti = sh_split_treg_set_expr (operands[3], curr_insn);
3061 if (!ti.was_treg_operand ())
3062 prev_set_t_insn = ti.first_insn ();
3064 operands[3] = get_t_reg_rtx ();
3066 if (TARGET_SH2A && ti.has_trailing_nott () && operands[1] == const0_rtx)
3068 /* Convert to a movrt, rotr sequence. */
3069 remove_insn (ti.trailing_nott ());
3070 rtx tmp = gen_reg_rtx (SImode);
3071 emit_insn (gen_movnegt (tmp, get_t_reg_rtx ()));
3072 emit_insn (gen_rotrsi3_1 (operands[0], tmp));
3077 if (operands[1] == const0_rtx)
3079 operands[1] = gen_reg_rtx (SImode);
3080 emit_insn (gen_movt (operands[1], get_t_reg_rtx ()));
3083 if (INTVAL (operands[2]) > 1)
3085 const rtx shift_count = GEN_INT (INTVAL (operands[2]) - 1);
3086 rtx tmp_t_reg = NULL_RTX;
3088 /* If we're going to emit a shift sequence that clobbers the T_REG,
3089 try to find the previous insn that sets the T_REG and emit the
3090 shift insn before that insn, to remove the T_REG dependency.
3091 If the insn that sets the T_REG cannot be found, store the T_REG
3092 in a temporary reg and restore it after the shift. */
3093 if (sh_lshrsi_clobbers_t_reg_p (shift_count)
3094 && ! sh_dynamicalize_shift_p (shift_count))
3096 if (prev_set_t_insn == NULL)
3097 prev_set_t_insn = prev_nonnote_nondebug_insn_bb (curr_insn);
3099 /* Skip the nott insn, which was probably inserted by the splitter
3100 of *rotcr_neg_t. Don't use one of the recog functions
3101 here during insn splitting, since that causes problems in later
3103 if (prev_set_t_insn != NULL_RTX)
3105 rtx pat = PATTERN (prev_set_t_insn);
3106 if (GET_CODE (pat) == SET
3107 && t_reg_operand (XEXP (pat, 0), SImode)
3108 && negt_reg_operand (XEXP (pat, 1), SImode))
3109 prev_set_t_insn = prev_nonnote_nondebug_insn_bb
3113 if (! (prev_set_t_insn != NULL_RTX
3114 && reg_set_p (get_t_reg_rtx (), prev_set_t_insn)
3115 && ! reg_referenced_p (get_t_reg_rtx (),
3116 PATTERN (prev_set_t_insn))))
3118 prev_set_t_insn = NULL;
3119 tmp_t_reg = gen_reg_rtx (SImode);
3120 emit_insn (gen_move_insn (tmp_t_reg, get_t_reg_rtx ()));
3124 rtx shift_result = gen_reg_rtx (SImode);
3125 rtx shift_insn = gen_lshrsi3 (shift_result, operands[1], shift_count);
3126 operands[1] = shift_result;
3128 /* Emit the shift insn before the insn that sets T_REG, if possible. */
3129 if (prev_set_t_insn != NULL_RTX)
3130 emit_insn_before (shift_insn, prev_set_t_insn);
3132 emit_insn (shift_insn);
3134 /* Restore T_REG if it has been saved before. */
3135 if (tmp_t_reg != NULL_RTX)
3136 emit_insn (gen_cmpgtsi_t (tmp_t_reg, const0_rtx));
3139 /* For the rotcr insn to work, operands[3] must be in T_REG.
3140 If it is not we can get it there by shifting it right one bit.
3141 In this case T_REG is not an input for this insn, thus we don't have to
3142 pay attention as of where to insert the shlr insn. */
3143 if (! t_reg_operand (operands[3], SImode))
3145 /* We don't care about the shifted result here, only the T_REG. */
3146 emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[3]));
3147 operands[3] = get_t_reg_rtx ();
3150 emit_insn (gen_rotcr (operands[0], operands[1], operands[3]));
3154 ;; If combine tries the same as above but with swapped operands, split
3155 ;; it so that it will try the pattern above.
3157 [(set (match_operand:SI 0 "arith_reg_dest")
3158 (ior:SI (ashift:SI (match_operand 1 "arith_reg_or_treg_set_expr")
3160 (lshiftrt:SI (match_operand:SI 2 "arith_reg_or_0_operand")
3161 (match_operand:SI 3 "const_int_operand"))))]
3162 "TARGET_SH1 && can_create_pseudo_p ()"
3163 [(parallel [(set (match_dup 0)
3164 (ior:SI (lshiftrt:SI (match_dup 2) (match_dup 3))
3165 (ashift:SI (match_dup 1) (const_int 31))))
3166 (clobber (reg:SI T_REG))])])
3168 ;; Basically the same as the rotcr pattern above, but for rotcl.
3169 ;; FIXME: Fold copy pasted split code for rotcr and rotcl.
3170 (define_insn_and_split "*rotcl"
3171 [(set (match_operand:SI 0 "arith_reg_dest")
3172 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3173 (match_operand:SI 2 "const_int_operand"))
3174 (and:SI (match_operand:SI 3 "arith_reg_or_t_reg_operand")
3176 (clobber (reg:SI T_REG))]
3177 "TARGET_SH1 && can_create_pseudo_p ()"
3182 gcc_assert (INTVAL (operands[2]) > 0);
3184 if (INTVAL (operands[2]) > 1)
3186 const rtx shift_count = GEN_INT (INTVAL (operands[2]) - 1);
3187 rtx_insn *prev_set_t_insn = NULL;
3188 rtx tmp_t_reg = NULL_RTX;
3190 /* If we're going to emit a shift sequence that clobbers the T_REG,
3191 try to find the previous insn that sets the T_REG and emit the
3192 shift insn before that insn, to remove the T_REG dependency.
3193 If the insn that sets the T_REG cannot be found, store the T_REG
3194 in a temporary reg and restore it after the shift. */
3195 if (sh_ashlsi_clobbers_t_reg_p (shift_count)
3196 && ! sh_dynamicalize_shift_p (shift_count))
3198 prev_set_t_insn = prev_nonnote_nondebug_insn_bb (curr_insn);
3200 /* Skip the nott insn, which was probably inserted by the splitter
3201 of *rotcl_neg_t. Don't use one of the recog functions
3202 here during insn splitting, since that causes problems in later
3204 if (prev_set_t_insn != NULL_RTX)
3206 rtx pat = PATTERN (prev_set_t_insn);
3207 if (GET_CODE (pat) == SET
3208 && t_reg_operand (XEXP (pat, 0), SImode)
3209 && negt_reg_operand (XEXP (pat, 1), SImode))
3210 prev_set_t_insn = prev_nonnote_nondebug_insn_bb
3214 if (! (prev_set_t_insn != NULL_RTX
3215 && reg_set_p (get_t_reg_rtx (), prev_set_t_insn)
3216 && ! reg_referenced_p (get_t_reg_rtx (),
3217 PATTERN (prev_set_t_insn))))
3219 prev_set_t_insn = NULL;
3220 tmp_t_reg = gen_reg_rtx (SImode);
3221 emit_insn (gen_move_insn (tmp_t_reg, get_t_reg_rtx ()));
3225 rtx shift_result = gen_reg_rtx (SImode);
3226 rtx shift_insn = gen_ashlsi3 (shift_result, operands[1], shift_count);
3227 operands[1] = shift_result;
3229 /* Emit the shift insn before the insn that sets T_REG, if possible. */
3230 if (prev_set_t_insn != NULL_RTX)
3231 emit_insn_before (shift_insn, prev_set_t_insn);
3233 emit_insn (shift_insn);
3235 /* Restore T_REG if it has been saved before. */
3236 if (tmp_t_reg != NULL_RTX)
3237 emit_insn (gen_cmpgtsi_t (tmp_t_reg, const0_rtx));
3240 /* For the rotcl insn to work, operands[3] must be in T_REG.
3241 If it is not we can get it there by shifting it right one bit.
3242 In this case T_REG is not an input for this insn, thus we don't have to
3243 pay attention as of where to insert the shlr insn. */
3244 if (! t_reg_operand (operands[3], SImode))
3246 /* We don't care about the shifted result here, only the T_REG. */
3247 emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[3]));
3248 operands[3] = get_t_reg_rtx ();
3251 emit_insn (gen_rotcl (operands[0], operands[1], operands[3]));
3255 ;; rotcl combine pattern variations
3256 (define_insn_and_split "*rotcl"
3257 [(set (match_operand:SI 0 "arith_reg_dest")
3258 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3259 (match_operand:SI 2 "const_int_operand"))
3260 (match_operand 3 "treg_set_expr")))
3261 (clobber (reg:SI T_REG))]
3262 "TARGET_SH1 && can_create_pseudo_p ()"
3265 [(parallel [(set (match_dup 0)
3266 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3267 (and:SI (match_dup 3) (const_int 1))))
3268 (clobber (reg:SI T_REG))])]
3270 sh_split_treg_set_expr (operands[3], curr_insn);
3271 operands[3] = get_t_reg_rtx ();
3274 (define_insn_and_split "*rotcl"
3275 [(set (match_operand:SI 0 "arith_reg_dest")
3276 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_or_t_reg_operand")
3278 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
3279 (match_operand:SI 3 "const_int_operand"))))
3280 (clobber (reg:SI T_REG))]
3281 "TARGET_SH1 && can_create_pseudo_p ()"
3284 [(parallel [(set (match_dup 0)
3285 (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
3286 (and:SI (match_dup 1) (const_int 1))))
3287 (clobber (reg:SI T_REG))])])
3289 (define_insn_and_split "*rotcl"
3290 [(set (match_operand:SI 0 "arith_reg_dest")
3291 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3292 (match_operand:SI 2 "const_int_operand"))
3293 (lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
3295 (clobber (reg:SI T_REG))]
3296 "TARGET_SH1 && can_create_pseudo_p ()"
3299 [(parallel [(set (match_dup 0)
3300 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3301 (and:SI (reg:SI T_REG) (const_int 1))))
3302 (clobber (reg:SI T_REG))])]
3304 /* We don't care about the result of the left shift, only the T_REG. */
3305 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[3]));
3308 (define_insn_and_split "*rotcl"
3309 [(set (match_operand:SI 0 "arith_reg_dest")
3310 (ior:SI (lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
3312 (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3313 (match_operand:SI 2 "const_int_operand"))))
3314 (clobber (reg:SI T_REG))]
3315 "TARGET_SH1 && can_create_pseudo_p ()"
3318 [(parallel [(set (match_dup 0)
3319 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3320 (and:SI (reg:SI T_REG) (const_int 1))))
3321 (clobber (reg:SI T_REG))])]
3323 /* We don't care about the result of the left shift, only the T_REG. */
3324 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[3]));
3327 (define_insn_and_split "*rotcl"
3328 [(set (match_operand:SI 0 "arith_reg_dest")
3329 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3330 (match_operand 2 "const_int_operand"))
3331 (zero_extract:SI (match_operand:SI 3 "arith_reg_operand")
3333 (match_operand 4 "const_int_operand"))))
3334 (clobber (reg:SI T_REG))]
3335 "TARGET_SH1 && can_create_pseudo_p ()"
3338 [(parallel [(set (match_dup 0)
3339 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3340 (and:SI (match_dup 5) (const_int 1))))
3341 (clobber (reg:SI T_REG))])]
3343 if (TARGET_SH2A && satisfies_constraint_K03 (operands[4]))
3345 /* On SH2A we can use the bld insn to zero extract a single bit
3347 operands[5] = get_t_reg_rtx ();
3348 emit_insn (gen_bldsi_reg (operands[3], operands[4]));
3352 /* If we can't use the bld insn we have to emit a tst + nott sequence
3353 to get the extracted bit into the T bit.
3354 This will probably be worse than pre-shifting the operand. */
3355 operands[5] = gen_reg_rtx (SImode);
3356 emit_insn (gen_lshrsi3 (operands[5], operands[3], operands[4]));
3360 ;; rotcr combine bridge pattern which will make combine try out more
3361 ;; complex patterns.
3362 (define_insn_and_split "*rotcr"
3363 [(set (match_operand:SI 0 "arith_reg_dest")
3364 (ashift:SI (match_operand 1 "treg_set_expr") (const_int 31)))]
3365 "TARGET_SH1 && can_create_pseudo_p ()"
3368 [(parallel [(set (match_dup 0)
3369 (ior:SI (lshiftrt:SI (const_int 0) (const_int 1))
3370 (ashift:SI (match_dup 1) (const_int 31))))
3371 (clobber (reg:SI T_REG))])])
3373 (define_insn_and_split "*rotcr"
3374 [(set (match_operand:SI 0 "arith_reg_dest")
3375 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
3376 (const_int -2147483648)) ;; 0xffffffff80000000
3377 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
3379 (clobber (reg:SI T_REG))]
3380 "TARGET_SH1 && can_create_pseudo_p ()"
3385 rtx tmp = gen_reg_rtx (SImode);
3386 emit_insn (gen_shll (tmp, operands[1]));
3387 emit_insn (gen_rotcr (operands[0], operands[2], get_t_reg_rtx ()));
3391 (define_insn_and_split "*rotcr"
3392 [(set (match_operand:SI 0 "arith_reg_dest")
3393 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
3395 (const_int -2147483648))) ;; 0xffffffff80000000
3396 (clobber (reg:SI T_REG))]
3397 "TARGET_SH1 && can_create_pseudo_p ()"
3402 emit_insn (gen_sett ());
3403 emit_insn (gen_rotcr (operands[0], operands[1], get_t_reg_rtx ()));
3407 ;; rotcr combine patterns for rotating in the negated T_REG value.
3408 (define_insn_and_split "*rotcr_neg_t"
3409 [(set (match_operand:SI 0 "arith_reg_dest")
3410 (ior:SI (match_operand:SI 1 "negt_reg_shl31_operand")
3411 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
3412 (match_operand:SI 3 "const_int_operand"))))
3413 (clobber (reg:SI T_REG))]
3414 "TARGET_SH1 && can_create_pseudo_p ()"
3417 [(parallel [(set (match_dup 0)
3418 (ior:SI (lshiftrt:SI (match_dup 2) (match_dup 3))
3419 (ashift:SI (reg:SI T_REG) (const_int 31))))
3420 (clobber (reg:SI T_REG))])]
3422 emit_insn (gen_nott (get_t_reg_rtx ()));
3425 (define_insn_and_split "*rotcr_neg_t"
3426 [(set (match_operand:SI 0 "arith_reg_dest")
3427 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
3428 (match_operand:SI 2 "const_int_operand"))
3429 (match_operand:SI 3 "negt_reg_shl31_operand")))
3430 (clobber (reg:SI T_REG))]
3431 "TARGET_SH1 && can_create_pseudo_p ()"
3434 [(parallel [(set (match_dup 0)
3435 (ior:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
3436 (ashift:SI (reg:SI T_REG) (const_int 31))))
3437 (clobber (reg:SI T_REG))])]
3439 emit_insn (gen_nott (get_t_reg_rtx ()));
3442 ;; rotcl combine patterns for rotating in the negated T_REG value.
3443 ;; For some strange reason these have to be specified as splits which combine
3444 ;; will pick up. If they are specified as insn_and_split like the
3445 ;; *rotcr_neg_t patterns above, combine would recognize them successfully
3446 ;; but not emit them on non-SH2A targets.
3448 [(set (match_operand:SI 0 "arith_reg_dest")
3449 (ior:SI (match_operand:SI 1 "negt_reg_operand")
3450 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
3451 (match_operand:SI 3 "const_int_operand"))))]
3453 [(set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))
3454 (parallel [(set (match_dup 0)
3455 (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
3456 (and:SI (reg:SI T_REG) (const_int 1))))
3457 (clobber (reg:SI T_REG))])])
3460 [(set (match_operand:SI 0 "arith_reg_dest")
3461 (ior:SI (ashift:SI (match_operand:SI 2 "arith_reg_operand")
3462 (match_operand:SI 3 "const_int_operand"))
3463 (match_operand:SI 1 "negt_reg_operand")))]
3465 [(set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))
3466 (parallel [(set (match_dup 0)
3467 (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
3468 (and:SI (reg:SI T_REG) (const_int 1))))
3469 (clobber (reg:SI T_REG))])])
3471 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3472 ;; SImode shift left
3474 (define_expand "ashlsi3"
3475 [(set (match_operand:SI 0 "arith_reg_operand" "")
3476 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
3477 (match_operand:SI 2 "shift_count_operand" "")))]
3481 && CONST_INT_P (operands[2]) && sh_dynamicalize_shift_p (operands[2]))
3483 /* Don't force the constant into a reg yet. Some other optimizations
3484 might not see through the reg that holds the shift count. */
3487 /* If the ashlsi3_* insn is going to clobber the T_REG it must be
3489 if (CONST_INT_P (operands[2])
3490 && sh_ashlsi_clobbers_t_reg_p (operands[2])
3491 && ! sh_dynamicalize_shift_p (operands[2]))
3493 emit_insn (gen_ashlsi3_n_clobbers_t (operands[0], operands[1],
3498 /* Expand a library call for the dynamic shift. */
3499 if (!CONST_INT_P (operands[2]) && !TARGET_DYNSHIFT)
3501 emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
3502 rtx funcaddr = gen_reg_rtx (Pmode);
3503 rtx lab = function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC).lab;
3504 emit_insn (gen_ashlsi3_d_call (operands[0], operands[2], funcaddr, lab));
3510 (define_insn "ashlsi3_k"
3511 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
3512 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0,0")
3513 (match_operand:SI 2 "p27_shift_count_operand" "M,P27")))]
3518 [(set_attr "type" "arith")])
3520 (define_insn_and_split "ashlsi3_d"
3521 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3522 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3523 (match_operand:SI 2 "shift_count_operand" "r")))]
3526 "&& CONST_INT_P (operands[2]) && ! sh_dynamicalize_shift_p (operands[2])
3527 && ! sh_ashlsi_clobbers_t_reg_p (operands[2])"
3530 if (satisfies_constraint_P27 (operands[2]))
3532 emit_insn (gen_ashlsi3_k (operands[0], operands[1], operands[2]));
3535 else if (! satisfies_constraint_P27 (operands[2]))
3537 /* This must happen before reload, otherwise the constant will be moved
3538 into a register due to the "r" constraint, after which this split
3539 cannot be done anymore.
3540 Unfortunately the move insn will not always be eliminated.
3541 Also, here we must not create a shift sequence that clobbers the
3543 emit_move_insn (operands[0], operands[1]);
3544 gen_shifty_op (ASHIFT, operands);
3550 [(set_attr "type" "dyn_shift")])
3552 ;; If dynamic shifts are not available use a library function.
3553 ;; By specifying the pattern we reduce the number of call clobbered regs.
3554 ;; In order to make combine understand the truncation of the shift amount
3555 ;; operand we have to allow it to use pseudo regs for the shift operands.
3556 (define_insn "ashlsi3_d_call"
3557 [(set (match_operand:SI 0 "arith_reg_dest" "=z,z")
3558 (ashift:SI (reg:SI R4_REG)
3559 (and:SI (match_operand:SI 1 "arith_reg_operand" "z,z")
3561 (use (match_operand:SI 2 "arith_reg_operand" "r,r"))
3562 (use (match_operand 3 "" "Z,Ccl"))
3563 (clobber (reg:SI T_REG))
3564 (clobber (reg:SI PR_REG))]
3565 "TARGET_SH1 && !TARGET_DYNSHIFT"
3569 [(set_attr "type" "sfunc")
3570 (set_attr "needs_delay_slot" "yes")])
3572 (define_insn_and_split "ashlsi3_n"
3573 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3574 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3575 (match_operand:SI 2 "not_p27_shift_count_operand" "")))]
3576 "TARGET_SH1 && ! sh_ashlsi_clobbers_t_reg_p (operands[2])"
3578 "&& (reload_completed
3579 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
3582 if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
3584 /* If this pattern was picked and dynamic shifts are supported, switch
3585 to dynamic shift pattern before reload. */
3586 operands[2] = force_reg (SImode, operands[2]);
3587 emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
3590 gen_shifty_op (ASHIFT, operands);
3595 (define_insn_and_split "ashlsi3_n_clobbers_t"
3596 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3597 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3598 (match_operand:SI 2 "not_p27_shift_count_operand" "")))
3599 (clobber (reg:SI T_REG))]
3600 "TARGET_SH1 && sh_ashlsi_clobbers_t_reg_p (operands[2])"
3602 "&& (reload_completed || INTVAL (operands[2]) == 31
3603 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
3606 if (INTVAL (operands[2]) == 31)
3608 /* If the shift amount is 31 we split into a different sequence before
3609 reload so that it gets a chance to allocate R0 for the sequence.
3610 If it fails to do so (due to pressure on R0), it will take one insn
3611 more for the and. */
3612 emit_insn (gen_andsi3 (operands[0], operands[1], const1_rtx));
3613 emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
3615 else if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
3617 /* If this pattern was picked and dynamic shifts are supported, switch
3618 to dynamic shift pattern before reload. */
3619 operands[2] = force_reg (SImode, operands[2]);
3620 emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
3623 gen_shifty_op (ASHIFT, operands);
3629 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3630 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0") (const_int 1)))
3632 (lt:SI (match_dup 1) (const_int 0)))]
3635 [(set_attr "type" "arith")])
3637 (define_insn "*ashlsi_c_void"
3638 [(set (reg:SI T_REG)
3639 (lt:SI (match_operand:SI 0 "arith_reg_operand" "r") (const_int 0)))
3640 (clobber (match_scratch:SI 1 "=0"))]
3641 "TARGET_SH1 && cse_not_expected"
3643 [(set_attr "type" "arith")])
3646 [(set (match_operand:SI 0 "arith_reg_dest" "") (const_int 0))
3648 (gt:SI (match_dup 0) (match_operand:SI 1 "arith_reg_operand" "")))]
3650 && peep2_reg_dead_p (2, operands[0])
3651 && peep2_reg_dead_p (2, operands[1])"
3654 emit_insn (gen_shll (operands[1], operands[1]));
3658 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3659 ;; HImode shift left
3661 (define_expand "ashlhi3"
3662 [(parallel [(set (match_operand:HI 0 "arith_reg_operand" "")
3663 (ashift:HI (match_operand:HI 1 "arith_reg_operand" "")
3664 (match_operand:SI 2 "nonmemory_operand" "")))
3665 (clobber (reg:SI T_REG))])]
3668 if (!CONST_INT_P (operands[2]))
3670 /* It may be possible to call gen_ashlhi3 directly with more generic
3671 operands. Make sure operands[1] is a HImode register here. */
3672 if (!arith_reg_operand (operands[1], HImode))
3673 operands[1] = copy_to_mode_reg (HImode, operands[1]);
3676 (define_insn "ashlhi3_k"
3677 [(set (match_operand:HI 0 "arith_reg_dest" "=r,r")
3678 (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0,0")
3679 (match_operand:HI 2 "const_int_operand" "M,P27")))]
3680 "TARGET_SH1 && satisfies_constraint_P27 (operands[2])"
3684 [(set_attr "type" "arith")])
3686 (define_insn_and_split "*ashlhi3_n"
3687 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
3688 (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0")
3689 (match_operand:HI 2 "const_int_operand" "n")))
3690 (clobber (reg:SI T_REG))]
3693 "&& reload_completed"
3694 [(use (reg:SI R0_REG))]
3696 gen_shifty_hi_op (ASHIFT, operands);
3700 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3701 ;; DImode shift left
3703 (define_expand "ashldi3"
3704 [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
3705 (ashift:DI (match_operand:DI 1 "arith_reg_operand" "")
3706 (match_operand:DI 2 "immediate_operand" "")))
3707 (clobber (reg:SI T_REG))])]
3710 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 1)
3712 emit_insn (gen_ashldi3_k (operands[0], operands[1]));
3715 else if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 32)
3717 emit_insn (gen_ashldi3_std (operands[0], operands[1], operands[2]));
3724 ;; Expander for DImode shift left with SImode operations.
3725 (define_expand "ashldi3_std"
3726 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3727 (ashift:DI (match_operand:DI 1 "arith_reg_operand" "r")
3728 (match_operand:DI 2 "const_int_operand" "n")))]
3729 "TARGET_SH1 && INTVAL (operands[2]) < 32"
3731 rtx low_src = gen_lowpart (SImode, operands[1]);
3732 rtx high_src = gen_highpart (SImode, operands[1]);
3733 rtx dst = gen_reg_rtx (DImode);
3734 rtx low_dst = gen_lowpart (SImode, dst);
3735 rtx high_dst = gen_highpart (SImode, dst);
3736 rtx tmp0 = gen_reg_rtx (SImode);
3737 rtx tmp1 = gen_reg_rtx (SImode);
3739 emit_insn (gen_lshrsi3 (tmp0, low_src, GEN_INT (32 - INTVAL (operands[2]))));
3740 emit_insn (gen_ashlsi3 (low_dst, low_src, operands[2]));
3741 emit_insn (gen_ashlsi3 (tmp1, high_src, operands[2]));
3742 emit_insn (gen_iorsi3 (high_dst, tmp0, tmp1));
3743 emit_move_insn (operands[0], dst);
3747 (define_insn_and_split "ashldi3_k"
3748 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3749 (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
3751 (clobber (reg:SI T_REG))]
3754 "&& reload_completed"
3757 rtx high = gen_highpart (SImode, operands[0]);
3758 rtx low = gen_lowpart (SImode, operands[0]);
3759 emit_insn (gen_shll (low, low));
3760 emit_insn (gen_rotcl (high, high, get_t_reg_rtx ()));
3764 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3765 ;; SImode arithmetic shift right
3767 ;; We can't do HImode right shifts correctly unless we start out with an
3768 ;; explicit zero / sign extension; doing that would result in worse overall
3769 ;; code, so just let the machine independent code widen the mode.
3770 ;; That's why we don't have ashrhi3_k / lshrhi3_k / lshrhi3_m / lshrhi3 .
3772 (define_expand "ashrsi3"
3773 [(parallel [(set (match_operand:SI 0 "arith_reg_dest" "")
3774 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
3775 (match_operand:SI 2 "nonmemory_operand" "")))
3776 (clobber (reg:SI T_REG))])]
3779 if (expand_ashiftrt (operands))
3786 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3787 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3790 (and:SI (match_dup 1) (const_int 1)))]
3793 [(set_attr "type" "arith")])
3795 (define_insn "ashrsi3_k"
3796 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3797 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3798 (match_operand:SI 2 "const_int_operand" "M")))
3799 (clobber (reg:SI T_REG))]
3800 "TARGET_SH1 && INTVAL (operands[2]) == 1"
3802 [(set_attr "type" "arith")])
3804 (define_insn_and_split "ashrsi2_16"
3805 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3806 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
3811 [(set (match_dup 0) (rotate:SI (match_dup 1) (const_int 16)))
3812 (set (match_dup 0) (sign_extend:SI (match_dup 2)))]
3814 operands[2] = gen_lowpart (HImode, operands[0]);
3817 (define_insn_and_split "ashrsi2_31"
3818 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3819 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3821 (clobber (reg:SI T_REG))]
3827 emit_insn (gen_shll (operands[0], operands[1]));
3828 emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
3832 ;; If the shift amount is changed by combine it will try to plug the
3833 ;; use on the symbol of the library function and the PR clobber.
3834 (define_insn_and_split "*ashrsi2_31"
3835 [(set (match_operand:SI 0 "arith_reg_dest")
3836 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand")
3838 (clobber (reg:SI T_REG))
3839 (clobber (reg:SI PR_REG))
3840 (use (match_operand:SI 2 "symbol_ref_operand"))]
3844 [(parallel [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (const_int 31)))
3845 (clobber (reg:SI T_REG))])])
3847 (define_insn "ashrsi3_d"
3848 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3849 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3850 (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
3853 [(set_attr "type" "dyn_shift")])
3855 (define_insn "ashrsi3_n"
3856 [(set (reg:SI R4_REG)
3857 (ashiftrt:SI (reg:SI R4_REG)
3858 (match_operand:SI 0 "const_int_operand" "i,i")))
3859 (clobber (reg:SI T_REG))
3860 (clobber (reg:SI PR_REG))
3861 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
3862 (use (match_operand 2 "" "Z,Ccl"))]
3867 [(set_attr "type" "sfunc")
3868 (set_attr "needs_delay_slot" "yes")])
3870 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3871 ;; DImode arithmetic shift right
3873 (define_expand "ashrdi3"
3874 [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
3875 (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
3876 (match_operand:DI 2 "immediate_operand" "")))
3877 (clobber (reg:SI T_REG))])]
3880 if (!CONST_INT_P (operands[2]) || INTVAL (operands[2]) != 1)
3884 (define_insn_and_split "ashrdi3_k"
3885 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3886 (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
3888 (clobber (reg:SI T_REG))]
3891 "&& reload_completed"
3894 rtx high = gen_highpart (SImode, operands[0]);
3895 rtx low = gen_lowpart (SImode, operands[0]);
3896 emit_insn (gen_shar (high, high));
3897 emit_insn (gen_rotcr (low, low, get_t_reg_rtx ()));
3901 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3902 ;; SImode logical shift right
3904 (define_expand "lshrsi3"
3905 [(set (match_operand:SI 0 "arith_reg_dest" "")
3906 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
3907 (match_operand:SI 2 "shift_count_operand" "")))]
3910 /* If a dynamic shift is supposed to be used, expand the lshrsi3_d insn
3911 here, otherwise the pattern will never match due to the shift amount reg
3914 && CONST_INT_P (operands[2]) && sh_dynamicalize_shift_p (operands[2]))
3916 /* Don't force the constant into a reg yet. Some other optimizations
3917 might not see through the reg that holds the shift count. */
3918 if (sh_lshrsi_clobbers_t_reg_p (operands[2]))
3919 emit_insn (gen_lshrsi3_n_clobbers_t (operands[0], operands[1], operands[2]));
3921 emit_insn (gen_lshrsi3_n (operands[0], operands[1], operands[2]));
3925 if (TARGET_DYNSHIFT && ! CONST_INT_P (operands[2]))
3927 rtx neg_count = gen_reg_rtx (SImode);
3928 emit_insn (gen_negsi2 (neg_count, operands[2]));
3929 emit_insn (gen_lshrsi3_d (operands[0], operands[1], neg_count));
3933 /* If the lshrsi3_* insn is going to clobber the T_REG it must be
3935 if (CONST_INT_P (operands[2])
3936 && sh_lshrsi_clobbers_t_reg_p (operands[2])
3937 && ! sh_dynamicalize_shift_p (operands[2]))
3939 emit_insn (gen_lshrsi3_n_clobbers_t (operands[0], operands[1],
3944 /* Expand a library call for the dynamic shift. */
3945 if (!CONST_INT_P (operands[2]) && !TARGET_DYNSHIFT)
3947 emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
3948 rtx funcaddr = gen_reg_rtx (Pmode);
3949 rtx lab = function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC).lab;
3950 emit_insn (gen_lshrsi3_d_call (operands[0], operands[2], funcaddr, lab));
3955 (define_insn "lshrsi3_k"
3956 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3957 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3958 (match_operand:SI 2 "p27_rshift_count_operand" "P27")))]
3961 [(set_attr "type" "arith")])
3963 (define_insn_and_split "lshrsi3_d"
3964 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3965 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3966 (neg:SI (match_operand:SI 2 "shift_count_operand" "r"))))]
3969 "&& CONST_INT_P (operands[2]) && ! sh_dynamicalize_shift_p (operands[2])
3970 && ! sh_lshrsi_clobbers_t_reg_p (operands[2])"
3973 /* The shift count const_int is a negative value for all dynamic
3974 right shift insns. */
3975 operands[2] = GEN_INT (- INTVAL (operands[2]));
3977 if (satisfies_constraint_P27 (operands[2]))
3979 /* This will not be done for a shift amount of 1, because it would
3980 clobber the T_REG. */
3981 emit_insn (gen_lshrsi3_k (operands[0], operands[1], operands[2]));
3984 else if (! satisfies_constraint_P27 (operands[2]))
3986 /* This must happen before reload, otherwise the constant will be moved
3987 into a register due to the "r" constraint, after which this split
3988 cannot be done anymore.
3989 Unfortunately the move insn will not always be eliminated.
3990 Also, here we must not create a shift sequence that clobbers the
3992 emit_move_insn (operands[0], operands[1]);
3993 gen_shifty_op (LSHIFTRT, operands);
3999 [(set_attr "type" "dyn_shift")])
4001 ;; If dynamic shifts are not available use a library function.
4002 ;; By specifying the pattern we reduce the number of call clobbered regs.
4003 ;; In order to make combine understand the truncation of the shift amount
4004 ;; operand we have to allow it to use pseudo regs for the shift operands.
4005 (define_insn "lshrsi3_d_call"
4006 [(set (match_operand:SI 0 "arith_reg_dest" "=z,z")
4007 (lshiftrt:SI (reg:SI R4_REG)
4008 (and:SI (match_operand:SI 1 "arith_reg_operand" "z,z")
4010 (use (match_operand:SI 2 "arith_reg_operand" "r,r"))
4011 (use (match_operand 3 "" "Z,Ccl"))
4012 (clobber (reg:SI T_REG))
4013 (clobber (reg:SI PR_REG))]
4014 "TARGET_SH1 && !TARGET_DYNSHIFT"
4018 [(set_attr "type" "sfunc")
4019 (set_attr "needs_delay_slot" "yes")])
4021 (define_insn_and_split "lshrsi3_n"
4022 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4023 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4024 (match_operand:SI 2 "not_p27_rshift_count_operand")))]
4025 "TARGET_SH1 && ! sh_lshrsi_clobbers_t_reg_p (operands[2])"
4027 "&& (reload_completed
4028 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
4031 if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
4033 /* If this pattern was picked and dynamic shifts are supported, switch
4034 to dynamic shift pattern before reload. */
4035 operands[2] = GEN_INT (- INTVAL (operands[2]));
4036 emit_insn (gen_lshrsi3_d (operands[0], operands[1], operands[2]));
4039 gen_shifty_op (LSHIFTRT, operands);
4044 ;; The lshrsi3_n_clobbers_t pattern also works as a simplified version of
4045 ;; the shlr pattern.
4046 (define_insn_and_split "lshrsi3_n_clobbers_t"
4047 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4048 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4049 (match_operand:SI 2 "not_p27_rshift_count_operand")))
4050 (clobber (reg:SI T_REG))]
4051 "TARGET_SH1 && sh_lshrsi_clobbers_t_reg_p (operands[2])"
4053 "&& (reload_completed || INTVAL (operands[2]) == 31
4054 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
4057 if (INTVAL (operands[2]) == 31)
4059 emit_insn (gen_shll (operands[0], operands[1]));
4060 emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
4062 else if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
4064 /* If this pattern was picked and dynamic shifts are supported, switch
4065 to dynamic shift pattern before reload. */
4066 operands[2] = GEN_INT (- INTVAL (operands[2]));
4067 emit_insn (gen_lshrsi3_d (operands[0], operands[1], operands[2]));
4070 gen_shifty_op (LSHIFTRT, operands);
4076 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4077 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4080 (and:SI (match_dup 1) (const_int 1)))]
4083 [(set_attr "type" "arith")])
4085 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4086 ;; DImode logical shift right
4088 (define_expand "lshrdi3"
4089 [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
4090 (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
4091 (match_operand:DI 2 "immediate_operand" "")))
4092 (clobber (reg:SI T_REG))])]
4095 if (!CONST_INT_P (operands[2]) || INTVAL (operands[2]) != 1)
4099 (define_insn_and_split "lshrdi3_k"
4100 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
4101 (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
4103 (clobber (reg:SI T_REG))]
4106 "&& reload_completed"
4109 rtx high = gen_highpart (SImode, operands[0]);
4110 rtx low = gen_lowpart (SImode, operands[0]);
4111 emit_insn (gen_shlr (high, high));
4112 emit_insn (gen_rotcr (low, low, get_t_reg_rtx ()));
4116 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4117 ;; Combined left/right shifts
4120 [(set (match_operand:SI 0 "register_operand" "")
4121 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4122 (match_operand:SI 2 "const_int_operand" ""))
4123 (match_operand:SI 3 "const_int_operand" "")))]
4124 "TARGET_SH1 && reload_completed && (unsigned)INTVAL (operands[2]) < 32"
4125 [(use (reg:SI R0_REG))]
4127 if (gen_shl_and (operands[0], operands[2], operands[3], operands[1]))
4133 [(set (match_operand:SI 0 "register_operand" "")
4134 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4135 (match_operand:SI 2 "const_int_operand" ""))
4136 (match_operand:SI 3 "const_int_operand" "")))
4137 (clobber (reg:SI T_REG))]
4138 "TARGET_SH1 && reload_completed && (unsigned)INTVAL (operands[2]) < 32"
4139 [(use (reg:SI R0_REG))]
4141 if (gen_shl_and (operands[0], operands[2], operands[3], operands[1]))
4147 [(set (match_operand:SI 0 "register_operand" "=r")
4148 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
4149 (match_operand:SI 2 "const_int_operand" "n"))
4150 (match_operand:SI 3 "const_int_operand" "n")))
4151 (clobber (reg:SI T_REG))]
4152 "TARGET_SH1 && shl_and_kind (operands[2], operands[3], 0) == 1"
4154 [(set (attr "length")
4155 (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
4157 (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
4159 (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
4161 (eq (symbol_ref "shl_and_length (insn)") (const_int 5))
4163 (eq (symbol_ref "shl_and_length (insn)") (const_int 6))
4165 (eq (symbol_ref "shl_and_length (insn)") (const_int 7))
4167 (eq (symbol_ref "shl_and_length (insn)") (const_int 8))
4168 (const_string "16")]
4169 (const_string "18")))
4170 (set_attr "type" "arith")])
4173 [(set (match_operand:SI 0 "register_operand" "=z")
4174 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
4175 (match_operand:SI 2 "const_int_operand" "n"))
4176 (match_operand:SI 3 "const_int_operand" "n")))
4177 (clobber (reg:SI T_REG))]
4178 "TARGET_SH1 && shl_and_kind (operands[2], operands[3], 0) == 2"
4180 [(set (attr "length")
4181 (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
4183 (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
4185 (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
4187 (const_string "10")))
4188 (set_attr "type" "arith")])
4190 ;; shift left / and combination with a scratch register: The combine pass
4191 ;; does not accept the individual instructions, even though they are
4192 ;; cheap. But it needs a precise description so that it is usable after
4194 (define_insn "and_shl_scratch"
4195 [(set (match_operand:SI 0 "register_operand" "=r,&r")
4199 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
4200 (match_operand:SI 2 "const_int_operand" "N,n"))
4201 (match_operand:SI 3 "" "0,r"))
4202 (match_operand:SI 4 "const_int_operand" "n,n"))
4203 (match_operand:SI 5 "const_int_operand" "n,n")))
4204 (clobber (reg:SI T_REG))]
4207 [(set (attr "length")
4208 (cond [(eq (symbol_ref "shl_and_scr_length (insn)") (const_int 2))
4210 (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 3))
4212 (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 4))
4214 (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 5))
4215 (const_string "10")]
4216 (const_string "12")))
4217 (set_attr "type" "arith")])
4220 [(set (match_operand:SI 0 "register_operand" "")
4224 (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
4225 (match_operand:SI 2 "const_int_operand" ""))
4226 (match_operand:SI 3 "register_operand" ""))
4227 (match_operand:SI 4 "const_int_operand" ""))
4228 (match_operand:SI 5 "const_int_operand" "")))
4229 (clobber (reg:SI T_REG))]
4231 [(use (reg:SI R0_REG))]
4233 rtx and_source = operands[rtx_equal_p (operands[0], operands[1]) ? 3 : 1];
4235 if (INTVAL (operands[2]))
4237 gen_shifty_op (LSHIFTRT, operands);
4239 emit_insn (gen_andsi3 (operands[0], operands[0], and_source));
4240 operands[2] = operands[4];
4241 gen_shifty_op (ASHIFT, operands);
4242 if (INTVAL (operands[5]))
4244 operands[2] = operands[5];
4245 gen_shifty_op (LSHIFTRT, operands);
4250 ;; signed left/right shift combination.
4252 [(set (match_operand:SI 0 "register_operand" "")
4254 (ashift:SI (match_operand:SI 1 "register_operand" "")
4255 (match_operand:SI 2 "const_int_operand" ""))
4256 (match_operand:SI 3 "const_int_operand" "")
4258 (clobber (reg:SI T_REG))]
4260 [(use (reg:SI R0_REG))]
4262 if (gen_shl_sext (operands[0], operands[2], operands[3], operands[1]))
4267 (define_insn "shl_sext_ext"
4268 [(set (match_operand:SI 0 "register_operand" "=r")
4270 (ashift:SI (match_operand:SI 1 "register_operand" "0")
4271 (match_operand:SI 2 "const_int_operand" "n"))
4272 (match_operand:SI 3 "const_int_operand" "n")
4274 (clobber (reg:SI T_REG))]
4275 "TARGET_SH1 && (unsigned)shl_sext_kind (operands[2], operands[3], 0) - 1 < 5"
4277 [(set (attr "length")
4278 (cond [(match_test "shl_sext_length (insn)")
4280 (eq (symbol_ref "shl_sext_length (insn)") (const_int 2))
4282 (eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
4284 (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
4286 (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
4288 (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
4290 (eq (symbol_ref "shl_sext_length (insn)") (const_int 7))
4292 (eq (symbol_ref "shl_sext_length (insn)") (const_int 8))
4293 (const_string "16")]
4294 (const_string "18")))
4295 (set_attr "type" "arith")])
4297 (define_insn "shl_sext_sub"
4298 [(set (match_operand:SI 0 "register_operand" "=z")
4300 (ashift:SI (match_operand:SI 1 "register_operand" "0")
4301 (match_operand:SI 2 "const_int_operand" "n"))
4302 (match_operand:SI 3 "const_int_operand" "n")
4304 (clobber (reg:SI T_REG))]
4305 "TARGET_SH1 && (shl_sext_kind (operands[2], operands[3], 0) & ~1) == 6"
4307 [(set (attr "length")
4308 (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
4310 (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
4312 (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
4314 (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
4315 (const_string "12")]
4316 (const_string "14")))
4317 (set_attr "type" "arith")])
4319 ;; The xtrct_left and xtrct_right patterns are used in expansions of DImode
4320 ;; shifts by 16, and allow the xtrct instruction to be generated from C
4322 (define_insn "xtrct_left"
4323 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4324 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
4326 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand" "0")
4330 [(set_attr "type" "arith")])
4332 (define_insn "xtrct_right"
4333 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4334 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4336 (ashift:SI (match_operand:SI 2 "arith_reg_operand" "r")
4340 [(set_attr "type" "arith")])
4342 ;; -------------------------------------------------------------------------
4344 ;; -------------------------------------------------------------------------
4347 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4348 (neg:SI (plus:SI (reg:SI T_REG)
4349 (match_operand:SI 1 "arith_reg_operand" "r"))))
4351 (ne:SI (ior:SI (reg:SI T_REG) (match_dup 1))
4355 [(set_attr "type" "arith")])
4357 ;; A simplified version of the negc insn, where the exact value of the
4358 ;; T bit doesn't matter. This is easier for combine to pick up.
4359 ;; Notice that '0 - x - 1' is the same as '~x', thus we don't specify
4360 ;; extra patterns for this case.
4361 (define_insn_and_split "*negc"
4362 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4363 (minus:SI (neg:SI (match_operand:SI 1 "arith_reg_operand" "r"))
4364 (match_operand 2 "treg_set_expr")))
4365 (clobber (reg:SI T_REG))]
4366 "TARGET_SH1 && can_create_pseudo_p ()"
4371 sh_split_treg_set_expr (operands[2], curr_insn);
4372 emit_insn (gen_negc (operands[0], operands[1]));
4376 ;; Don't split into individual negc insns immediately so that neg:DI (abs:DI)
4378 (define_insn_and_split "negdi2"
4379 [(set (match_operand:DI 0 "arith_reg_dest")
4380 (neg:DI (match_operand:DI 1 "arith_reg_operand")))
4381 (clobber (reg:SI T_REG))]
4382 "TARGET_SH1 && can_create_pseudo_p ()"
4387 emit_insn (gen_clrt ());
4388 emit_insn (gen_negc (gen_lowpart (SImode, operands[0]),
4389 gen_lowpart (SImode, operands[1])));
4390 emit_insn (gen_negc (gen_highpart (SImode, operands[0]),
4391 gen_highpart (SImode, operands[1])));
4395 (define_insn "negsi2"
4396 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4397 (neg:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
4400 [(set_attr "type" "arith")])
4402 (define_insn_and_split "one_cmplsi2"
4403 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4404 (not:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
4407 "&& can_create_pseudo_p ()"
4408 [(set (reg:SI T_REG) (ge:SI (match_dup 1) (const_int 0)))
4409 (set (match_dup 0) (reg:SI T_REG))]
4412 If the result of 'unsigned int <= 0x7FFFFFFF' ends up as the following
4415 (set (reg0) (not:SI (reg0) (reg1)))
4416 (parallel [(set (reg2) (lshiftrt:SI (reg0) (const_int 31)))
4417 (clobber (reg:SI T_REG))])
4419 ... match and combine the sequence manually in the split pass after the
4420 combine pass. Notice that combine does try the target pattern of this
4421 split, but if the pattern is added it interferes with other patterns, in
4422 particular with the div0s comparisons.
4423 This could also be done with a peephole but doing it here before register
4424 allocation can save one temporary.
4425 When we're here, the not:SI pattern obviously has been matched already
4426 and we only have to see whether the following insn is the left shift. */
4428 rtx_insn *i = next_nonnote_nondebug_insn_bb (curr_insn);
4429 if (i == NULL_RTX || !NONJUMP_INSN_P (i))
4432 rtx p = PATTERN (i);
4433 if (GET_CODE (p) != PARALLEL || XVECLEN (p, 0) != 2)
4436 rtx p0 = XVECEXP (p, 0, 0);
4437 rtx p1 = XVECEXP (p, 0, 1);
4439 if (/* (set (reg2) (lshiftrt:SI (reg0) (const_int 31))) */
4440 GET_CODE (p0) == SET
4441 && GET_CODE (XEXP (p0, 1)) == LSHIFTRT
4442 && REG_P (XEXP (XEXP (p0, 1), 0))
4443 && REGNO (XEXP (XEXP (p0, 1), 0)) == REGNO (operands[0])
4444 && CONST_INT_P (XEXP (XEXP (p0, 1), 1))
4445 && INTVAL (XEXP (XEXP (p0, 1), 1)) == 31
4447 /* (clobber (reg:SI T_REG)) */
4448 && GET_CODE (p1) == CLOBBER && REG_P (XEXP (p1, 0))
4449 && REGNO (XEXP (p1, 0)) == T_REG)
4451 operands[0] = XEXP (p0, 0);
4452 set_insn_deleted (i);
4457 [(set_attr "type" "arith")])
4459 (define_insn_and_split "abs<mode>2"
4460 [(set (match_operand:SIDI 0 "arith_reg_dest")
4461 (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand")))
4462 (clobber (reg:SI T_REG))]
4463 "TARGET_SH1 && can_create_pseudo_p ()"
4468 if (<MODE>mode == SImode)
4469 emit_insn (gen_cmpgesi_t (operands[1], const0_rtx));
4472 rtx high_src = gen_highpart (SImode, operands[1]);
4473 emit_insn (gen_cmpgesi_t (high_src, const0_rtx));
4476 emit_insn (gen_neg<mode>_cond (operands[0], operands[1], operands[1],
4481 (define_insn_and_split "*negabs<mode>2"
4482 [(set (match_operand:SIDI 0 "arith_reg_dest")
4483 (neg:SIDI (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand"))))
4484 (clobber (reg:SI T_REG))]
4485 "TARGET_SH1 && can_create_pseudo_p ()"
4490 if (<MODE>mode == SImode)
4491 emit_insn (gen_cmpgesi_t (operands[1], const0_rtx));
4494 rtx high_src = gen_highpart (SImode, operands[1]);
4495 emit_insn (gen_cmpgesi_t (high_src, const0_rtx));
4498 emit_insn (gen_neg<mode>_cond (operands[0], operands[1], operands[1],
4503 ;; The SH4 202 can do zero-offset branches without pipeline stalls.
4504 ;; This can be used as some kind of conditional execution, which is useful
4506 ;; Actually the instruction scheduling should decide whether to use a
4507 ;; zero-offset branch or not for any generic case involving a single
4508 ;; instruction on SH4 202.
4509 (define_insn_and_split "negsi_cond"
4510 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4512 (eq:SI (reg:SI T_REG) (match_operand:SI 3 "const_int_operand" "M,N"))
4513 (match_operand:SI 1 "arith_reg_operand" "0,0")
4514 (neg:SI (match_operand:SI 2 "arith_reg_operand" "r,r"))))]
4515 "TARGET_SH1 && TARGET_ZDCBRANCH"
4517 static const char* alt[] =
4527 return alt[which_alternative];
4529 "TARGET_SH1 && ! TARGET_ZDCBRANCH"
4532 rtx_code_label *skip_neg_label = gen_label_rtx ();
4534 emit_move_insn (operands[0], operands[1]);
4536 emit_jump_insn (INTVAL (operands[3])
4537 ? gen_branch_true (skip_neg_label)
4538 : gen_branch_false (skip_neg_label));
4540 emit_label_after (skip_neg_label,
4541 emit_insn (gen_negsi2 (operands[0], operands[1])));
4544 [(set_attr "type" "arith") ;; poor approximation
4545 (set_attr "length" "4")])
4547 (define_insn_and_split "negdi_cond"
4548 [(set (match_operand:DI 0 "arith_reg_dest")
4550 (eq:SI (reg:SI T_REG) (match_operand:SI 3 "const_int_operand"))
4551 (match_operand:DI 1 "arith_reg_operand")
4552 (neg:DI (match_operand:DI 2 "arith_reg_operand"))))
4553 (clobber (reg:SI T_REG))]
4554 "TARGET_SH1 && can_create_pseudo_p ()"
4559 rtx_code_label *skip_neg_label = gen_label_rtx ();
4561 emit_move_insn (operands[0], operands[1]);
4563 emit_jump_insn (INTVAL (operands[3])
4564 ? gen_branch_true (skip_neg_label)
4565 : gen_branch_false (skip_neg_label));
4567 if (!INTVAL (operands[3]))
4568 emit_insn (gen_clrt ());
4570 emit_insn (gen_negc (gen_lowpart (SImode, operands[0]),
4571 gen_lowpart (SImode, operands[1])));
4572 emit_label_after (skip_neg_label,
4573 emit_insn (gen_negc (gen_highpart (SImode, operands[0]),
4574 gen_highpart (SImode, operands[1]))));
4578 (define_expand "bswapsi2"
4579 [(set (match_operand:SI 0 "arith_reg_dest" "")
4580 (bswap:SI (match_operand:SI 1 "arith_reg_operand" "")))]
4583 if (! can_create_pseudo_p ())
4587 rtx tmp0 = gen_reg_rtx (SImode);
4588 rtx tmp1 = gen_reg_rtx (SImode);
4590 emit_insn (gen_swapbsi2 (tmp0, operands[1]));
4591 emit_insn (gen_rotlsi3_16 (tmp1, tmp0));
4592 emit_insn (gen_swapbsi2 (operands[0], tmp1));
4597 (define_insn "swapbsi2"
4598 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4599 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "r")
4600 (const_int -65536)) ;; 0xFFFF0000
4601 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
4603 (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
4604 (const_int 255)))))]
4607 [(set_attr "type" "arith")])
4609 ;; The *swapbisi2_and_shl8 pattern helps the combine pass simplifying
4610 ;; partial byte swap expressions such as...
4611 ;; ((x & 0xFF) << 8) | ((x >> 8) & 0xFF).
4612 ;; ...which are currently not handled by the tree optimizers.
4613 ;; The combine pass will not initially try to combine the full expression,
4614 ;; but only some sub-expressions. In such a case the *swapbisi2_and_shl8
4615 ;; pattern acts as an intermediate pattern that will eventually lead combine
4616 ;; to the swapbsi2 pattern above.
4617 ;; As a side effect this also improves code that does (x & 0xFF) << 8
4618 ;; or (x << 8) & 0xFF00.
4619 (define_insn_and_split "*swapbisi2_and_shl8"
4620 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4621 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
4624 (match_operand:SI 2 "arith_reg_operand" "r")))]
4625 "TARGET_SH1 && ! reload_in_progress && ! reload_completed && can_create_pseudo_p ()"
4630 rtx tmp0 = gen_reg_rtx (SImode);
4631 rtx tmp1 = gen_reg_rtx (SImode);
4633 emit_insn (gen_zero_extendqisi2 (tmp0, gen_lowpart (QImode, operands[1])));
4634 emit_insn (gen_swapbsi2 (tmp1, tmp0));
4635 emit_insn (gen_iorsi3 (operands[0], tmp1, operands[2]));
4639 ;; The *swapbhisi2 pattern is, like the *swapbisi2_and_shl8 pattern, another
4640 ;; intermediate pattern that will help the combine pass arriving at swapbsi2.
4641 (define_insn_and_split "*swapbhisi2"
4642 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4643 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
4646 (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))))]
4647 "TARGET_SH1 && ! reload_in_progress && ! reload_completed && can_create_pseudo_p ()"
4652 rtx tmp = gen_reg_rtx (SImode);
4654 emit_insn (gen_zero_extendhisi2 (tmp, gen_lowpart (HImode, operands[1])));
4655 emit_insn (gen_swapbsi2 (operands[0], tmp));
4659 ;; In some cases the swapbsi2 pattern might leave a sequence such as...
4663 ;; which can be simplified to...
4666 [(set (match_operand:SI 0 "arith_reg_dest" "")
4667 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "")
4668 (const_int -65536)) ;; 0xFFFF0000
4669 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
4671 (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
4673 (set (match_operand:SI 2 "arith_reg_dest" "")
4675 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
4677 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "")
4678 (const_int -65536)) ;; 0xFFFF0000
4679 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
4681 (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
4682 (const_int 255)))))])
4684 ;; -------------------------------------------------------------------------
4685 ;; Zero extension instructions
4686 ;; -------------------------------------------------------------------------
4688 (define_expand "zero_extend<mode>si2"
4689 [(set (match_operand:SI 0 "arith_reg_dest")
4690 (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand")))])
4692 (define_insn_and_split "*zero_extend<mode>si2_compact"
4693 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4694 (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand" "r")))]
4697 "&& can_create_pseudo_p ()"
4698 [(set (match_dup 0) (match_dup 2))]
4700 /* Sometimes combine fails to combine a T bit or negated T bit store to a
4701 reg with a following zero extension. In the split pass after combine,
4702 try to figure out how the extended reg was set. If it originated from
4703 the T bit we can replace the zero extension with a reg move, which will
4704 be eliminated. Notice that this also helps the *cbranch_t splitter when
4705 it tries to post-combine tests and conditional branches, as it does not
4706 check for zero extensions. */
4707 operands[2] = sh_try_omit_signzero_extend (operands[1], curr_insn);
4708 if (operands[2] == NULL_RTX)
4711 [(set_attr "type" "arith")])
4713 (define_insn "zero_extendqihi2"
4714 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
4715 (zero_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
4718 [(set_attr "type" "arith")])
4720 ;; SH2A supports two zero extending load instructions: movu.b and movu.w.
4721 ;; They could also be used for simple memory addresses like @Rn by setting
4722 ;; the displacement value to zero. However, doing so too early results in
4723 ;; missed opportunities for other optimizations such as post-inc or index
4724 ;; addressing loads.
4725 ;; We don't allow the zero extending loads to match during RTL expansion,
4726 ;; as this would pessimize other optimization opportunities such as bit
4727 ;; extractions of unsigned mems, where the zero extraction is irrelevant.
4728 ;; If the zero extracting mem loads are emitted early it will be more
4729 ;; difficult to change them back to sign extending loads (which are preferred).
4730 ;; The combine pass will also try to combine mem loads and zero extends,
4731 ;; which is prevented by 'sh_legitimate_combined_insn'.
4732 (define_insn "*zero_extend<mode>si2_disp_mem"
4733 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4735 (match_operand:QIHI 1 "zero_extend_movu_operand" "Sdd,Sra")))]
4739 movu.<bw> @(0,%t1),%0"
4740 [(set_attr "type" "load")
4741 (set_attr "length" "4")])
4743 ;; Convert the zero extending loads in sequences such as:
4744 ;; movu.b @(1,r5),r0 movu.w @(2,r5),r0
4745 ;; mov.b r0,@(1,r4) mov.b r0,@(1,r4)
4747 ;; back to sign extending loads like:
4748 ;; mov.b @(1,r5),r0 mov.w @(2,r5),r0
4749 ;; mov.b r0,@(1,r4) mov.b r0,@(1,r4)
4751 ;; if the extension type is irrelevant. The sign extending mov.{b|w} insn
4752 ;; is only 2 bytes in size if the displacement is {K04|K05}.
4753 ;; If the displacement is greater it doesn't matter, so we convert anyways.
4755 [(set (match_operand:SI 0 "arith_reg_dest" "")
4756 (zero_extend:SI (match_operand 1 "displacement_mem_operand" "")))
4757 (set (match_operand 2 "nonimmediate_operand" "")
4758 (match_operand 3 "arith_reg_operand" ""))]
4760 && REGNO (operands[0]) == REGNO (operands[3])
4761 && peep2_reg_dead_p (2, operands[0])
4762 && GET_MODE_SIZE (GET_MODE (operands[2]))
4763 <= GET_MODE_SIZE (GET_MODE (operands[1]))"
4764 [(set (match_dup 0) (sign_extend:SI (match_dup 1)))
4765 (set (match_dup 2) (match_dup 3))])
4767 ;; Fold sequences such as
4771 ;; movu.b @(0,r3),r7
4772 ;; This does not reduce the code size but the number of instructions is
4773 ;; halved, which results in faster code.
4775 [(set (match_operand:SI 0 "arith_reg_dest" "")
4776 (sign_extend:SI (match_operand 1 "simple_mem_operand" "")))
4777 (set (match_operand:SI 2 "arith_reg_dest" "")
4778 (zero_extend:SI (match_operand 3 "arith_reg_operand" "")))]
4780 && GET_MODE (operands[1]) == GET_MODE (operands[3])
4781 && (GET_MODE (operands[1]) == QImode || GET_MODE (operands[1]) == HImode)
4782 && REGNO (operands[0]) == REGNO (operands[3])
4783 && (REGNO (operands[2]) == REGNO (operands[0])
4784 || peep2_reg_dead_p (2, operands[0]))"
4785 [(set (match_dup 2) (zero_extend:SI (match_dup 4)))]
4788 = replace_equiv_address (operands[1],
4789 gen_rtx_PLUS (SImode, XEXP (operands[1], 0),
4793 ;; -------------------------------------------------------------------------
4794 ;; Sign extension instructions
4795 ;; -------------------------------------------------------------------------
4797 ;; ??? This should be a define expand.
4798 ;; ??? Or perhaps it should be dropped?
4800 ;; convert_move generates good code for SH[1-4].
4802 (define_expand "extend<mode>si2"
4803 [(set (match_operand:SI 0 "arith_reg_dest")
4804 (sign_extend:SI (match_operand:QIHI 1 "general_extend_operand")))])
4806 (define_insn_and_split "*extend<mode>si2_compact_reg"
4807 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4808 (sign_extend:SI (match_operand:QIHI 1 "arith_reg_operand" "r")))]
4811 "&& can_create_pseudo_p ()"
4812 [(set (match_dup 0) (match_dup 2))]
4814 /* Sometimes combine fails to combine a T bit or negated T bit store to a
4815 reg with a following sign extension. In the split pass after combine,
4816 try to figure the extended reg was set. If it originated from the T
4817 bit we can replace the sign extension with a reg move, which will be
4819 operands[2] = sh_try_omit_signzero_extend (operands[1], curr_insn);
4820 if (operands[2] == NULL_RTX)
4823 [(set_attr "type" "arith")])
4825 ;; FIXME: Fold non-SH2A and SH2A alternatives with "enabled" attribute.
4827 (define_insn "*extend<mode>si2_compact_mem_disp"
4828 [(set (match_operand:SI 0 "arith_reg_dest" "=z,r")
4832 (match_operand:SI 1 "arith_reg_operand" "%r,r")
4833 (match_operand:SI 2 "const_int_operand" "<disp04>,N")))))]
4834 "TARGET_SH1 && ! TARGET_SH2A
4835 && sh_legitimate_index_p (<MODE>mode, operands[2], false, true)"
4837 mov.<bw> @(%O2,%1),%0
4839 [(set_attr "type" "load")])
4841 (define_insn "*extend<mode>si2_compact_mem_disp"
4842 [(set (match_operand:SI 0 "arith_reg_dest" "=z,r,r")
4846 (match_operand:SI 1 "arith_reg_operand" "%r,r,r")
4847 (match_operand:SI 2 "const_int_operand" "<disp04>,N,<disp12>")))))]
4848 "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[2], true, true)"
4850 mov.<bw> @(%O2,%1),%0
4852 mov.<bw> @(%O2,%1),%0"
4853 [(set_attr "type" "load")
4854 (set_attr "length" "2,2,4")])
4856 ;; The pre-dec and post-inc mems must be captured by the '<' and '>'
4857 ;; constraints, otherwise wrong code might get generated.
4858 (define_insn "*extend<mode>si2_predec"
4859 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
4860 (sign_extend:SI (match_operand:QIHI 1 "pre_dec_mem" "<")))]
4863 [(set_attr "type" "load")])
4865 ;; The *_snd patterns will take care of other QImode/HImode addressing
4866 ;; modes than displacement addressing. They must be defined _after_ the
4867 ;; displacement addressing patterns. Otherwise the displacement addressing
4868 ;; patterns will not be picked.
4869 (define_insn "*extend<mode>si2_compact_snd"
4870 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4872 (match_operand:QIHI 1 "movsrc_no_disp_mem_operand" "Snd")))]
4875 [(set_attr "type" "load")])
4877 (define_expand "extendqihi2"
4878 [(set (match_operand:HI 0 "arith_reg_dest")
4879 (sign_extend:HI (match_operand:QI 1 "arith_reg_operand")))]
4882 (define_insn "*extendqihi2_compact_reg"
4883 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
4884 (sign_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
4887 [(set_attr "type" "arith")])
4889 ;; -------------------------------------------------------------------------
4890 ;; Move instructions
4891 ;; -------------------------------------------------------------------------
4893 (define_expand "push"
4894 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4895 (match_operand:SI 0 "register_operand"))])
4897 (define_expand "pop"
4898 [(set (match_operand:SI 0 "register_operand")
4899 (mem:SI (post_inc:SI (reg:SI SP_REG))))])
4901 (define_expand "push_e"
4902 [(parallel [(set (mem:SF (pre_dec:SI (reg:SI SP_REG)))
4903 (match_operand:SF 0 "" ""))
4904 (use (reg:SI FPSCR_MODES_REG))
4905 (clobber (scratch:SI))])])
4907 (define_insn "push_fpul"
4908 [(set (mem:SF (pre_dec:SI (reg:SI SP_REG))) (reg:SF FPUL_REG))]
4911 [(set_attr "type" "fstore")
4912 (set_attr "late_fp_use" "yes")
4913 (set_attr "hit_stack" "yes")])
4915 ;; DFmode pushes for sh4 require a lot of what is defined for movdf_i4,
4917 (define_expand "push_4"
4918 [(parallel [(set (mem:DF (pre_dec:SI (reg:SI SP_REG)))
4919 (match_operand:DF 0 "" ""))
4920 (use (reg:SI FPSCR_MODES_REG))
4921 (clobber (scratch:SI))])])
4923 (define_expand "pop_e"
4924 [(parallel [(set (match_operand:SF 0 "" "")
4925 (mem:SF (post_inc:SI (reg:SI SP_REG))))
4926 (use (reg:SI FPSCR_MODES_REG))
4927 (clobber (scratch:SI))])])
4929 (define_insn "pop_fpul"
4930 [(set (reg:SF FPUL_REG) (mem:SF (post_inc:SI (reg:SI SP_REG))))]
4933 [(set_attr "type" "load")
4934 (set_attr "hit_stack" "yes")])
4936 (define_expand "pop_4"
4937 [(parallel [(set (match_operand:DF 0 "" "")
4938 (mem:DF (post_inc:SI (reg:SI SP_REG))))
4939 (use (reg:SI FPSCR_MODES_REG))
4940 (clobber (scratch:SI))])])
4942 (define_expand "push_fpscr"
4949 gen_frame_mem (SImode, gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)))),
4950 REG_INC, stack_pointer_rtx);
4954 (define_expand "pop_fpscr"
4961 gen_frame_mem (SImode, gen_rtx_POST_INC (Pmode, stack_pointer_rtx)))),
4962 REG_INC, stack_pointer_rtx);
4966 ;; The clrt and sett patterns can happen as the result of optimization and
4968 ;; Comparisons might get simplified to a move of zero or 1 into the T reg.
4969 ;; In this case they might not disappear completely, because the T reg is
4970 ;; a fixed hard reg.
4971 ;; When DImode operations that use the T reg as carry/borrow are split into
4972 ;; individual SImode operations, the T reg is usually cleared before the
4973 ;; first SImode insn.
4975 [(set (reg:SI T_REG) (const_int 0))]
4978 [(set_attr "type" "mt_group")])
4981 [(set (reg:SI T_REG) (const_int 1))]
4984 [(set_attr "type" "mt_group")])
4986 ;; Use the combine pass to transform sequences such as
4990 ;; mov.l @(r0,r4),r0
4996 ;; See also PR 39423.
4997 ;; Notice that these patterns have a T_REG clobber, because the shift
4998 ;; sequence that will be split out might clobber the T_REG. Ideally, the
4999 ;; clobber would be added conditionally, depending on the result of
5000 ;; sh_ashlsi_clobbers_t_reg_p. When splitting out the shifts we must go
5001 ;; through the ashlsi3 expander in order to get the right shift insn --
5002 ;; a T_REG clobbering or non-clobbering shift sequence or dynamic shift.
5003 ;; FIXME: Combine never tries this kind of patterns for DImode.
5004 (define_insn_and_split "*movsi_index_disp_load"
5005 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5006 (match_operand:SI 1 "mem_index_disp_operand" "m"))
5007 (clobber (reg:SI T_REG))]
5008 "TARGET_SH1 && can_create_pseudo_p ()"
5011 [(set (match_dup 6) (plus:SI (match_dup 5) (match_dup 3)))
5012 (set (match_dup 0) (match_dup 7))]
5014 rtx mem = operands[1];
5015 rtx plus0_rtx = XEXP (mem, 0);
5016 rtx plus1_rtx = XEXP (plus0_rtx, 0);
5017 rtx mult_rtx = XEXP (plus1_rtx, 0);
5019 operands[1] = XEXP (mult_rtx, 0);
5020 operands[2] = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
5021 operands[3] = XEXP (plus1_rtx, 1);
5022 operands[4] = XEXP (plus0_rtx, 1);
5023 operands[5] = gen_reg_rtx (SImode);
5024 operands[6] = gen_reg_rtx (SImode);
5026 replace_equiv_address (mem,
5027 gen_rtx_PLUS (SImode, operands[6], operands[4]));
5029 emit_insn (gen_ashlsi3 (operands[5], operands[1], operands[2]));
5032 (define_insn_and_split "*movhi_index_disp_load"
5033 [(set (match_operand:SI 0 "arith_reg_dest")
5034 (SZ_EXTEND:SI (match_operand:HI 1 "mem_index_disp_operand")))
5035 (clobber (reg:SI T_REG))]
5036 "TARGET_SH1 && can_create_pseudo_p ()"
5041 rtx mem = operands[1];
5042 rtx plus0_rtx = XEXP (mem, 0);
5043 rtx plus1_rtx = XEXP (plus0_rtx, 0);
5044 rtx mult_rtx = XEXP (plus1_rtx, 0);
5046 rtx op_1 = XEXP (mult_rtx, 0);
5047 rtx op_2 = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
5048 rtx op_3 = XEXP (plus1_rtx, 1);
5049 rtx op_4 = XEXP (plus0_rtx, 1);
5050 rtx op_5 = gen_reg_rtx (SImode);
5051 rtx op_6 = gen_reg_rtx (SImode);
5052 rtx op_7 = replace_equiv_address (mem, gen_rtx_PLUS (SImode, op_6, op_4));
5054 emit_insn (gen_ashlsi3 (op_5, op_1, op_2));
5055 emit_insn (gen_addsi3 (op_6, op_5, op_3));
5057 if (<CODE> == SIGN_EXTEND)
5059 emit_insn (gen_extendhisi2 (operands[0], op_7));
5062 else if (<CODE> == ZERO_EXTEND)
5064 /* On SH2A the movu.w insn can be used for zero extending loads. */
5066 emit_insn (gen_zero_extendhisi2 (operands[0], op_7));
5069 emit_insn (gen_extendhisi2 (operands[0], op_7));
5070 emit_insn (gen_zero_extendhisi2 (operands[0],
5071 gen_lowpart (HImode, operands[0])));
5079 (define_insn_and_split "*mov<mode>_index_disp_store"
5080 [(set (match_operand:HISI 0 "mem_index_disp_operand" "=m")
5081 (match_operand:HISI 1 "arith_reg_operand" "r"))
5082 (clobber (reg:SI T_REG))]
5083 "TARGET_SH1 && can_create_pseudo_p ()"
5086 [(set (match_dup 6) (plus:SI (match_dup 5) (match_dup 3)))
5087 (set (match_dup 7) (match_dup 1))]
5089 rtx mem = operands[0];
5090 rtx plus0_rtx = XEXP (mem, 0);
5091 rtx plus1_rtx = XEXP (plus0_rtx, 0);
5092 rtx mult_rtx = XEXP (plus1_rtx, 0);
5094 operands[0] = XEXP (mult_rtx, 0);
5095 operands[2] = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
5096 operands[3] = XEXP (plus1_rtx, 1);
5097 operands[4] = XEXP (plus0_rtx, 1);
5098 operands[5] = gen_reg_rtx (SImode);
5099 operands[6] = gen_reg_rtx (SImode);
5101 replace_equiv_address (mem,
5102 gen_rtx_PLUS (SImode, operands[6], operands[4]));
5104 emit_insn (gen_ashlsi3 (operands[5], operands[0], operands[2]));
5107 ;; t/r must come after r/r, lest reload will try to reload stuff like
5108 ;; (set (subreg:SI (mem:QI (plus:SI (reg:SI SP_REG) (const_int 12)) 0) 0)
5109 ;; (made from (set (subreg:SI (reg:QI ###) 0) ) into T.
5110 ;; Notice that although this pattern allows movi20 and movi20s on non-SH2A,
5111 ;; those alternatives will not be taken, as they will be converted into
5112 ;; PC-relative loads.
5113 (define_insn "movsi_i"
5114 [(set (match_operand:SI 0 "general_movdst_operand"
5115 "=r,r, r, r, r, r,r,r,m,<,<,x,l,x,l,r")
5116 (match_operand:SI 1 "general_movsrc_operand"
5117 " Q,r,I08,I20,I28,mr,x,l,r,x,l,r,r,>,>,i"))]
5118 "TARGET_SH1 && !TARGET_FPU_ANY
5119 && (register_operand (operands[0], SImode)
5120 || register_operand (operands[1], SImode))"
5138 [(set_attr "type" "pcload_si,move,movi8,move,move,load_si,mac_gp,prget,store,
5139 mac_mem,pstore,gp_mac,prset,mem_mac,pload,pcload_si")
5140 (set_attr_alternative "length"
5146 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5147 (const_int 4) (const_int 2))
5150 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5151 (const_int 4) (const_int 2))
5160 ;; t/r must come after r/r, lest reload will try to reload stuff like
5161 ;; (subreg:SI (reg:SF FR14_REG) 0) into T (compiling stdlib/strtod.c -m3e -O2)
5162 ;; ??? This allows moves from macl to fpul to be recognized, but these moves
5163 ;; will require a reload.
5164 ;; ??? We can't include f/f because we need the proper FPSCR setting when
5165 ;; TARGET_FMOVD is in effect, and mode switching is done before reload.
5166 ;; Notice that although this pattern allows movi20 and movi20s on non-SH2A,
5167 ;; those alternatives will not be taken, as they will be converted into
5168 ;; PC-relative loads.
5169 (define_insn "movsi_ie"
5170 [(set (match_operand:SI 0 "general_movdst_operand"
5171 "=r,r, r, r, r, r,r,r,mr,<,<,x,l,x,l,y,<,r,y,r,*f, y,*f,y")
5172 (match_operand:SI 1 "general_movsrc_operand"
5173 " Q,r,I08,I20,I28,mr,x,l, r,x,l,r,r,>,>,>,y,i,r,y, y,*f,*f,y"))]
5174 "TARGET_SH1 && TARGET_FPU_ANY
5175 && ((register_operand (operands[0], SImode)
5176 && !fpscr_operand (operands[0], SImode))
5177 || (register_operand (operands[1], SImode)
5178 && !fpscr_operand (operands[1], SImode)))"
5203 ! move optimized away"
5204 [(set_attr "type" "pcload_si,move,movi8,move,move,load_si,mac_gp,prget,store,
5205 mac_mem,pstore,gp_mac,prset,mem_mac,pload,load,fstore,
5206 pcload_si,gp_fpul,fpul_gp,fmove,fmove,fmove,nil")
5207 (set_attr "late_fp_use" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,yes,*,*,yes,*,*,*,*")
5208 (set_attr_alternative "length"
5214 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5215 (const_int 4) (const_int 2))
5218 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5219 (const_int 4) (const_int 2))
5236 ;; Notice that although this pattern allows movi20 and movi20s on non-SH2A,
5237 ;; those alternatives will not be taken, as they will be converted into
5238 ;; PC-relative loads.
5239 (define_insn "movsi_i_lowpart"
5240 [(set (strict_low_part
5241 (match_operand:SI 0 "general_movdst_operand"
5242 "+r,r, r, r, r, r,r,r,m,r"))
5243 (match_operand:SI 1 "general_movsrc_operand"
5244 " Q,r,I08,I20,I28,mr,x,l,r,i"))]
5246 && (register_operand (operands[0], SImode)
5247 || register_operand (operands[1], SImode))"
5259 [(set_attr "type" "pcload,move,movi8,move,move,load,mac_gp,prget,store,
5261 (set_attr_alternative "length"
5267 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5268 (const_int 4) (const_int 2))
5271 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5272 (const_int 4) (const_int 2))
5275 (define_insn_and_split "load_ra"
5276 [(set (match_operand:SI 0 "general_movdst_operand" "")
5277 (unspec:SI [(match_operand:SI 1 "register_operand" "")] UNSPEC_RA))]
5280 "&& ! currently_expanding_to_rtl"
5281 [(set (match_dup 0) (match_dup 1))])
5283 (define_expand "movsi"
5284 [(set (match_operand:SI 0 "general_movdst_operand" "")
5285 (match_operand:SI 1 "general_movsrc_operand" ""))]
5288 prepare_move_operands (operands, SImode);
5291 (define_expand "ic_invalidate_line"
5292 [(parallel [(unspec_volatile [(match_operand:SI 0 "register_operand")
5293 (match_dup 1)] UNSPEC_ICACHE)
5294 (clobber (scratch:SI))])]
5297 emit_insn (gen_ic_invalidate_line_sh4a (operands[0]));
5301 ;; The address %0 is assumed to be 4-aligned at least. Thus, by ORing
5302 ;; 0xf0000008, we get the low-oder bits *1*00 (binary), which fits
5303 ;; the requirement *1*00 for associative address writes. The alignment of
5304 ;; %0 implies that its least significant bit is cleared,
5305 ;; thus we clear the V bit of a matching entry if there is one.
5306 (define_insn "ic_invalidate_line_i"
5307 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")
5308 (match_operand:SI 1 "register_operand" "r")]
5310 (clobber (match_scratch:SI 2 "=&r"))]
5313 return "ocbwb @%0" "\n"
5314 " extu.w %0,%2" "\n"
5318 [(set_attr "length" "8")
5319 (set_attr "type" "cwb")])
5321 (define_insn "ic_invalidate_line_sh4a"
5322 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
5324 "TARGET_SH4A || TARGET_SH4_300"
5326 return "ocbwb @%0" "\n"
5330 [(set_attr "length" "6")
5331 (set_attr "type" "cwb")])
5333 (define_expand "mov<mode>"
5334 [(set (match_operand:QIHI 0 "general_movdst_operand")
5335 (match_operand:QIHI 1 "general_movsrc_operand"))]
5338 if (can_create_pseudo_p () && CONST_INT_P (operands[1])
5339 && REG_P (operands[0]) && REGNO (operands[0]) != R0_REG)
5341 rtx reg = gen_reg_rtx(SImode);
5342 emit_move_insn (reg, operands[1]);
5343 operands[1] = gen_lowpart (<MODE>mode, reg);
5346 prepare_move_operands (operands, <MODE>mode);
5349 ;; The pre-dec and post-inc mems must be captured by the '<' and '>'
5350 ;; constraints, otherwise wrong code might get generated.
5351 (define_insn "*mov<mode>_load_predec"
5352 [(set (match_operand:QIHISI 0 "arith_reg_dest" "=z")
5353 (match_operand:QIHISI 1 "pre_dec_mem" "<"))]
5356 [(set_attr "type" "load")])
5358 (define_insn "*mov<mode>_store_postinc"
5359 [(set (match_operand:QIHISI 0 "post_inc_mem" "=>")
5360 (match_operand:QIHISI 1 "arith_reg_operand" "z"))]
5363 [(set_attr "type" "store")])
5365 ;; Specifying the displacement addressing load / store patterns separately
5366 ;; before the generic movqi / movhi pattern allows controlling the order
5367 ;; in which load / store insns are selected in a more fine grained way.
5368 ;; FIXME: The non-SH2A and SH2A variants should be combined by adding
5369 ;; "enabled" attribute as it is done in other targets.
5370 (define_insn "*mov<mode>_store_mem_disp04"
5372 (plus:SI (match_operand:SI 0 "arith_reg_operand" "%r,r")
5373 (match_operand:SI 1 "const_int_operand" "<disp04>,N")))
5374 (match_operand:QIHI 2 "arith_reg_operand" "z,r"))]
5375 "TARGET_SH1 && sh_legitimate_index_p (<MODE>mode, operands[1], false, true)"
5377 mov.<bw> %2,@(%O1,%0)
5379 [(set_attr "type" "store")])
5381 (define_insn "*mov<mode>_store_mem_disp12"
5383 (plus:SI (match_operand:SI 0 "arith_reg_operand" "%r")
5384 (match_operand:SI 1 "const_int_operand" "<disp12>")))
5385 (match_operand:QIHI 2 "arith_reg_operand" "r"))]
5386 "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[1], true, true)"
5387 "mov.<bw> %2,@(%O1,%0)"
5388 [(set_attr "type" "store")
5389 (set_attr "length" "4")])
5391 (define_insn "*mov<mode>_load_mem_disp04"
5392 [(set (match_operand:QIHI 0 "arith_reg_dest" "=z,r")
5394 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%r,r")
5395 (match_operand:SI 2 "const_int_operand" "<disp04>,N"))))]
5396 "TARGET_SH1 && ! TARGET_SH2A
5397 && sh_legitimate_index_p (<MODE>mode, operands[2], false, true)"
5399 mov.<bw> @(%O2,%1),%0
5401 [(set_attr "type" "load")])
5403 (define_insn "*mov<mode>_load_mem_disp12"
5404 [(set (match_operand:QIHI 0 "arith_reg_dest" "=z,r,r")
5407 (match_operand:SI 1 "arith_reg_operand" "%r,r,r")
5408 (match_operand:SI 2 "const_int_operand" "<disp04>,N,<disp12>"))))]
5409 "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[2], true, true)"
5411 mov.<bw> @(%O2,%1),%0
5413 mov.<bw> @(%O2,%1),%0"
5414 [(set_attr "type" "load")
5415 (set_attr "length" "2,2,4")])
5417 ;; The order of the constraint alternatives is important here.
5418 ;; Q/r has to come first, otherwise PC relative loads might wrongly get
5419 ;; placed into delay slots. Since there is no QImode PC relative load, the
5420 ;; Q constraint and general_movsrc_operand will reject it for QImode.
5421 ;; The Sid/Ssd alternatives should come before Sdd in order to avoid
5422 ;; a preference of using r0 als the register operand for addressing modes
5423 ;; other than displacement addressing.
5424 ;; The Sdd alternatives allow only r0 as register operand, even though on
5425 ;; SH2A any register could be allowed by switching to a 32 bit insn.
5426 ;; Generally sticking to the r0 is preferrable, since it generates smaller
5427 ;; code. Obvious r0 reloads can then be eliminated with a peephole on SH2A.
5428 (define_insn "*mov<mode>"
5429 [(set (match_operand:QIHI 0 "general_movdst_operand"
5430 "=r,r,r,Sid,^zr,Ssd,r, Sdd,z, r,l")
5431 (match_operand:QIHI 1 "general_movsrc_operand"
5432 "Q,r,i,^zr,Sid,r, Ssd,z, Sdd,l,r"))]
5434 && (arith_reg_operand (operands[0], <MODE>mode)
5435 || arith_reg_operand (operands[1], <MODE>mode))"
5448 [(set_attr "type" "pcload,move,movi8,store,load,store,load,store,load,prget,prset")
5449 (set (attr "length")
5450 (cond [(match_operand 0 "long_displacement_mem_operand") (const_int 4)
5451 (match_operand 1 "long_displacement_mem_operand") (const_int 4)]
5454 ;; x/r can be created by inlining/cse, e.g. for execute/961213-1.c
5455 ;; compiled with -m2 -ml -O3 -funroll-loops
5456 (define_insn "*movdi_i"
5457 [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,m, r,r,r,*!x")
5458 (match_operand:DI 1 "general_movsrc_operand" " Q,r,m,r,I08,i,x, r"))]
5460 && (arith_reg_operand (operands[0], DImode)
5461 || arith_reg_operand (operands[1], DImode))"
5463 return output_movedouble (insn, operands, DImode);
5465 [(set_attr "type" "pcload,move,load,store,move,pcload,move,move")
5466 (set (attr "length")
5467 (cond [(match_operand 0 "long_displacement_mem_operand") (const_int 8)
5468 (match_operand 1 "long_displacement_mem_operand") (const_int 8)]
5471 ;; If the output is a register and the input is memory or a register, we have
5472 ;; to be careful and see which word needs to be loaded first.
5474 [(set (match_operand:DI 0 "general_movdst_operand" "")
5475 (match_operand:DI 1 "general_movsrc_operand" ""))]
5476 "TARGET_SH1 && reload_completed"
5477 [(set (match_dup 2) (match_dup 3))
5478 (set (match_dup 4) (match_dup 5))]
5482 if ((MEM_P (operands[0])
5483 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
5484 || (MEM_P (operands[1])
5485 && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
5488 switch (GET_CODE (operands[0]))
5491 regno = REGNO (operands[0]);
5494 regno = subreg_regno (operands[0]);
5503 if (regno == -1 || ! refers_to_regno_p (regno, operands[1]))
5505 operands[2] = operand_subword (operands[0], 0, 0, DImode);
5506 operands[3] = operand_subword (operands[1], 0, 0, DImode);
5507 operands[4] = operand_subword (operands[0], 1, 0, DImode);
5508 operands[5] = operand_subword (operands[1], 1, 0, DImode);
5512 operands[2] = operand_subword (operands[0], 1, 0, DImode);
5513 operands[3] = operand_subword (operands[1], 1, 0, DImode);
5514 operands[4] = operand_subword (operands[0], 0, 0, DImode);
5515 operands[5] = operand_subword (operands[1], 0, 0, DImode);
5518 if (operands[2] == 0 || operands[3] == 0
5519 || operands[4] == 0 || operands[5] == 0)
5523 (define_expand "movdi"
5524 [(set (match_operand:DI 0 "general_movdst_operand" "")
5525 (match_operand:DI 1 "general_movsrc_operand" ""))]
5528 prepare_move_operands (operands, DImode);
5530 /* When the dest operand is (R0, R1) register pair, split it to
5531 two movsi of which dest is R1 and R0 so as to lower R0-register
5532 pressure on the first movsi. Apply only for simple source not
5533 to make complex rtl here. */
5534 if (REG_P (operands[0]) && REGNO (operands[0]) == R0_REG
5535 && REG_P (operands[1]) && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
5537 emit_insn (gen_movsi (gen_rtx_REG (SImode, R1_REG),
5538 gen_rtx_SUBREG (SImode, operands[1], 4)));
5539 emit_insn (gen_movsi (gen_rtx_REG (SImode, R0_REG),
5540 gen_rtx_SUBREG (SImode, operands[1], 0)));
5545 ;; FIXME: This should be a define_insn_and_split.
5546 (define_insn "movdf_k"
5547 [(set (match_operand:DF 0 "general_movdst_operand" "=r, r,r,m")
5548 (match_operand:DF 1 "general_movsrc_operand" " r,FQ,m,r"))]
5550 && (!TARGET_FPU_DOUBLE || reload_completed
5551 /* ??? We provide some insn so that direct_{load,store}[DFmode] get set */
5552 || (REG_P (operands[0]) && REGNO (operands[0]) == 3)
5553 || (REG_P (operands[1]) && REGNO (operands[1]) == 3))
5554 && (arith_reg_operand (operands[0], DFmode)
5555 || arith_reg_operand (operands[1], DFmode))"
5557 return output_movedouble (insn, operands, DFmode);
5559 [(set_attr "type" "move,pcload,load,store")
5560 (set (attr "length")
5561 (cond [(match_operand 0 "long_displacement_mem_operand") (const_int 8)
5562 (match_operand 1 "long_displacement_mem_operand") (const_int 8)]
5565 ;; All alternatives of movdf_i4 are split for ! TARGET_FMOVD.
5566 ;; However, the d/F/c/z alternative cannot be split directly; it is converted
5567 ;; with special code in machine_dependent_reorg into a load of the R0_REG and
5568 ;; the d/m/c/X alternative, which is split later into single-precision
5569 ;; instructions. And when not optimizing, no splits are done before fixing
5570 ;; up pcloads, so we need usable length information for that.
5571 ;; A DF constant load results in the following worst-case 8 byte sequence:
5576 (define_insn "movdf_i4"
5577 [(set (match_operand:DF 0 "general_movdst_operand"
5578 "=d,r, d,d,m, r,r,m,!??r,!???d")
5579 (match_operand:DF 1 "general_movsrc_operand"
5580 " d,r, F,m,d,FQ,m,r, d, r"))
5581 (use (reg:SI FPSCR_MODES_REG))
5582 (clobber (match_scratch:SI 2
5583 "=X,X,&z,X,X, X,X,X, X, X"))]
5585 && (arith_reg_operand (operands[0], DFmode)
5586 || arith_reg_operand (operands[1], DFmode))"
5588 switch (which_alternative)
5592 return "fmov %1,%0";
5593 else if (REGNO (operands[0]) != REGNO (operands[1]) + 1)
5594 return "fmov %R1,%R0" "\n"
5597 return "fmov %S1,%S0" "\n"
5601 return "fmov.d %1,%0";
5606 [(set_attr_alternative "length"
5607 [(if_then_else (eq_attr "fmovd" "yes") (const_int 2) (const_int 4))
5609 (if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 8))
5610 (if_then_else (match_operand 1 "displacement_mem_operand")
5611 (if_then_else (eq_attr "fmovd" "yes")
5612 (const_int 4) (const_int 8))
5613 (if_then_else (eq_attr "fmovd" "yes")
5614 (const_int 2) (const_int 4)))
5615 (if_then_else (match_operand 0 "displacement_mem_operand")
5616 (if_then_else (eq_attr "fmovd" "yes")
5617 (const_int 4) (const_int 8))
5618 (if_then_else (eq_attr "fmovd" "yes")
5619 (const_int 2) (const_int 4)))
5621 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5622 (const_int 8) (const_int 4))
5623 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5624 (const_int 8) (const_int 4))
5627 (set_attr "type" "fmove,move,pcfload,fload,fstore,pcload,load,store,load,
5629 (set_attr "late_fp_use" "*,*,*,*,yes,*,*,*,*,*")
5630 (set (attr "fp_mode") (if_then_else (eq_attr "fmovd" "yes")
5631 (const_string "double")
5632 (const_string "none")))])
5634 ;; Moving DFmode between fp/general registers through memory
5635 ;; (the top of the stack) is faster than moving through fpul even for
5636 ;; little endian. Because the type of an instruction is important for its
5637 ;; scheduling, it is beneficial to split these operations, rather than
5638 ;; emitting them in one single chunk, even if this will expose a stack
5639 ;; use that will prevent scheduling of other stack accesses beyond this
5642 [(set (match_operand:DF 0 "register_operand")
5643 (match_operand:DF 1 "register_operand"))
5644 (use (reg:SI FPSCR_MODES_REG))
5645 (clobber (match_scratch:SI 2))]
5646 "TARGET_FPU_DOUBLE && reload_completed
5647 && (true_regnum (operands[0]) < 16) != (true_regnum (operands[1]) < 16)"
5652 tos = gen_tmp_stack_mem (DFmode, gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
5653 insn = emit_insn (gen_movdf_i4 (tos, operands[1]));
5654 add_reg_note (insn, REG_INC, stack_pointer_rtx);
5655 tos = gen_tmp_stack_mem (DFmode, gen_rtx_POST_INC (Pmode, stack_pointer_rtx));
5656 insn = emit_insn (gen_movdf_i4 (operands[0], tos));
5657 add_reg_note (insn, REG_INC, stack_pointer_rtx);
5661 ;; local-alloc sometimes allocates scratch registers even when not required,
5662 ;; so we must be prepared to handle these.
5664 ;; Remove the use and clobber from a movdf_i4 so that we can use movdf_k.
5666 [(set (match_operand:DF 0 "general_movdst_operand" "")
5667 (match_operand:DF 1 "general_movsrc_operand" ""))
5668 (use (reg:SI FPSCR_MODES_REG))
5669 (clobber (match_scratch:SI 2))]
5672 && true_regnum (operands[0]) < 16
5673 && true_regnum (operands[1]) < 16"
5674 [(set (match_dup 0) (match_dup 1))]
5676 /* If this was a reg <-> mem operation with base + index reg addressing,
5677 we have to handle this in a special way. */
5678 rtx mem = operands[0];
5680 if (! memory_operand (mem, DFmode))
5685 if (GET_CODE (mem) == SUBREG && SUBREG_BYTE (mem) == 0)
5686 mem = SUBREG_REG (mem);
5689 rtx addr = XEXP (mem, 0);
5690 if (GET_CODE (addr) == PLUS
5691 && REG_P (XEXP (addr, 0))
5692 && REG_P (XEXP (addr, 1)))
5695 rtx reg0 = gen_rtx_REG (Pmode, 0);
5696 rtx regop = operands[store_p], word0 ,word1;
5698 if (GET_CODE (regop) == SUBREG)
5699 alter_subreg (®op, true);
5700 if (REGNO (XEXP (addr, 0)) == REGNO (XEXP (addr, 1)))
5704 mem = copy_rtx (mem);
5705 PUT_MODE (mem, SImode);
5706 word0 = gen_rtx_SUBREG (SImode, regop, 0);
5707 alter_subreg (&word0, true);
5708 word1 = gen_rtx_SUBREG (SImode, regop, 4);
5709 alter_subreg (&word1, true);
5710 if (store_p || ! refers_to_regno_p (REGNO (word0), addr))
5713 ? gen_movsi_ie (mem, word0)
5714 : gen_movsi_ie (word0, mem));
5715 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
5716 mem = copy_rtx (mem);
5718 ? gen_movsi_ie (mem, word1)
5719 : gen_movsi_ie (word1, mem));
5720 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
5724 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
5725 emit_insn (gen_movsi_ie (word1, mem));
5726 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
5727 mem = copy_rtx (mem);
5728 emit_insn (gen_movsi_ie (word0, mem));
5735 ;; Split away the clobber of r0 after machine_dependent_reorg has fixed pcloads.
5737 [(set (match_operand:DF 0 "register_operand" "")
5738 (match_operand:DF 1 "memory_operand" ""))
5739 (use (reg:SI FPSCR_MODES_REG))
5740 (clobber (reg:SI R0_REG))]
5741 "TARGET_FPU_DOUBLE && reload_completed"
5742 [(parallel [(set (match_dup 0) (match_dup 1))
5743 (use (reg:SI FPSCR_MODES_REG))
5744 (clobber (scratch:SI))])]
5747 (define_expand "reload_indf__frn"
5748 [(parallel [(set (match_operand:DF 0 "register_operand" "=a")
5749 (match_operand:DF 1 "immediate_operand" "FQ"))
5750 (use (reg:SI FPSCR_MODES_REG))
5751 (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
5755 (define_expand "reload_outdf__RnFRm"
5756 [(parallel [(set (match_operand:DF 0 "register_operand" "=r,f")
5757 (match_operand:DF 1 "register_operand" "af,r"))
5758 (clobber (match_operand:SI 2 "register_operand" "=&y,y"))])]
5762 ;; Simplify no-op moves.
5764 [(set (match_operand:SF 0 "register_operand" "")
5765 (match_operand:SF 1 "register_operand" ""))
5766 (use (reg:SI FPSCR_MODES_REG))
5767 (clobber (match_scratch:SI 2))]
5768 "TARGET_SH2E && reload_completed
5769 && true_regnum (operands[0]) == true_regnum (operands[1])"
5770 [(set (match_dup 0) (match_dup 0))]
5773 ;; fmovd substitute post-reload splits
5775 [(set (match_operand:DF 0 "register_operand" "")
5776 (match_operand:DF 1 "register_operand" ""))
5777 (use (reg:SI FPSCR_MODES_REG))
5778 (clobber (match_scratch:SI 2))]
5779 "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
5780 && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))
5781 && FP_OR_XD_REGISTER_P (true_regnum (operands[1]))"
5784 int dst = true_regnum (operands[0]), src = true_regnum (operands[1]);
5785 emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode, dst),
5786 gen_rtx_REG (SFmode, src)));
5787 emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode, dst + 1),
5788 gen_rtx_REG (SFmode, src + 1)));
5793 [(set (match_operand:DF 0 "register_operand" "")
5794 (mem:DF (match_operand:SI 1 "register_operand" "")))
5795 (use (reg:SI FPSCR_MODES_REG))
5796 (clobber (match_scratch:SI 2))]
5797 "TARGET_FPU_DOUBLE && ! TARGET_FMOVD && reload_completed
5798 && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))
5799 && find_regno_note (insn, REG_DEAD, true_regnum (operands[1]))"
5802 int regno = true_regnum (operands[0]);
5804 rtx mem = SET_SRC (XVECEXP (PATTERN (curr_insn), 0, 0));
5806 = change_address (mem, SFmode, gen_rtx_POST_INC (Pmode, operands[1]));
5807 insn = emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode,
5808 regno + SH_REG_MSW_OFFSET),
5810 add_reg_note (insn, REG_INC, operands[1]);
5811 insn = emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode,
5812 regno + SH_REG_LSW_OFFSET),
5813 change_address (mem, SFmode, NULL_RTX)));
5818 [(set (match_operand:DF 0 "register_operand" "")
5819 (match_operand:DF 1 "memory_operand" ""))
5820 (use (reg:SI FPSCR_MODES_REG))
5821 (clobber (match_scratch:SI 2))]
5822 "TARGET_FPU_DOUBLE && ! TARGET_FMOVD && reload_completed
5823 && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))"
5826 int regno = true_regnum (operands[0]);
5828 rtx mem2 = change_address (operands[1], SFmode, NULL_RTX);
5829 rtx reg0 = gen_rtx_REG (SFmode, regno + SH_REG_MSW_OFFSET);
5830 rtx reg1 = gen_rtx_REG (SFmode, regno + SH_REG_LSW_OFFSET);
5832 operands[1] = copy_rtx (mem2);
5833 addr = XEXP (mem2, 0);
5835 switch (GET_CODE (addr))
5838 /* This is complicated. If the register is an arithmetic register
5839 we can just fall through to the REG+DISP case below. Otherwise
5840 we have to use a combination of POST_INC and REG addressing... */
5841 if (! arith_reg_operand (operands[1], SFmode))
5843 XEXP (mem2, 0) = addr = gen_rtx_POST_INC (SImode, addr);
5844 insn = emit_insn (gen_movsf_ie (reg0, mem2));
5845 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5847 emit_insn (gen_movsf_ie (reg1, operands[1]));
5849 /* If we have modified the stack pointer, the value that we have
5850 read with post-increment might be modified by an interrupt,
5851 so write it back. */
5852 if (REGNO (XEXP (addr, 0)) == STACK_POINTER_REGNUM)
5853 emit_insn (gen_push_e (reg0));
5855 emit_insn (gen_addsi3 (XEXP (operands[1], 0), XEXP (operands[1], 0),
5862 emit_insn (gen_movsf_ie (reg0, operands[1]));
5863 operands[1] = copy_rtx (operands[1]);
5864 XEXP (operands[1], 0) = plus_constant (Pmode, addr, 4);
5865 emit_insn (gen_movsf_ie (reg1, operands[1]));
5869 insn = emit_insn (gen_movsf_ie (reg0, operands[1]));
5870 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5872 insn = emit_insn (gen_movsf_ie (reg1, operands[1]));
5873 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5885 [(set (match_operand:DF 0 "memory_operand" "")
5886 (match_operand:DF 1 "register_operand" ""))
5887 (use (reg:SI FPSCR_MODES_REG))
5888 (clobber (match_scratch:SI 2))]
5889 "TARGET_FPU_DOUBLE && ! TARGET_FMOVD && reload_completed
5890 && FP_OR_XD_REGISTER_P (true_regnum (operands[1]))"
5893 int regno = true_regnum (operands[1]);
5895 rtx reg0 = gen_rtx_REG (SFmode, regno + SH_REG_MSW_OFFSET);
5896 rtx reg1 = gen_rtx_REG (SFmode, regno + SH_REG_LSW_OFFSET);
5898 operands[0] = copy_rtx (operands[0]);
5899 PUT_MODE (operands[0], SFmode);
5900 addr = XEXP (operands[0], 0);
5902 switch (GET_CODE (addr))
5905 /* This is complicated. If the register is an arithmetic register
5906 we can just fall through to the REG+DISP case below. Otherwise
5907 we have to use a combination of REG and PRE_DEC addressing... */
5908 if (! arith_reg_operand (operands[0], SFmode))
5910 emit_insn (gen_addsi3 (addr, addr, GEN_INT (4)));
5911 emit_insn (gen_movsf_ie (operands[0], reg1));
5913 operands[0] = copy_rtx (operands[0]);
5914 XEXP (operands[0], 0) = addr = gen_rtx_PRE_DEC (SImode, addr);
5916 insn = emit_insn (gen_movsf_ie (operands[0], reg0));
5917 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5923 /* Since REG+DISP addressing has already been decided upon by gcc
5924 we can rely upon it having chosen an arithmetic register as the
5925 register component of the address. Just emit the lower numbered
5926 register first, to the lower address, then the higher numbered
5927 register to the higher address. */
5928 emit_insn (gen_movsf_ie (operands[0], reg0));
5930 operands[0] = copy_rtx (operands[0]);
5931 XEXP (operands[0], 0) = plus_constant (Pmode, addr, 4);
5933 emit_insn (gen_movsf_ie (operands[0], reg1));
5937 /* This is easy. Output the word to go to the higher address
5938 first (ie the word in the higher numbered register) then the
5939 word to go to the lower address. */
5941 insn = emit_insn (gen_movsf_ie (operands[0], reg1));
5942 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5944 insn = emit_insn (gen_movsf_ie (operands[0], reg0));
5945 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5957 ;; If the output is a register and the input is memory or a register, we have
5958 ;; to be careful and see which word needs to be loaded first.
5960 [(set (match_operand:DF 0 "general_movdst_operand" "")
5961 (match_operand:DF 1 "general_movsrc_operand" ""))]
5962 "TARGET_SH1 && reload_completed"
5963 [(set (match_dup 2) (match_dup 3))
5964 (set (match_dup 4) (match_dup 5))]
5968 if ((MEM_P (operands[0])
5969 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
5970 || (MEM_P (operands[1])
5971 && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
5974 switch (GET_CODE (operands[0]))
5977 regno = REGNO (operands[0]);
5980 regno = subreg_regno (operands[0]);
5989 if (regno == -1 || ! refers_to_regno_p (regno, operands[1]))
5991 operands[2] = operand_subword (operands[0], 0, 0, DFmode);
5992 operands[3] = operand_subword (operands[1], 0, 0, DFmode);
5993 operands[4] = operand_subword (operands[0], 1, 0, DFmode);
5994 operands[5] = operand_subword (operands[1], 1, 0, DFmode);
5998 operands[2] = operand_subword (operands[0], 1, 0, DFmode);
5999 operands[3] = operand_subword (operands[1], 1, 0, DFmode);
6000 operands[4] = operand_subword (operands[0], 0, 0, DFmode);
6001 operands[5] = operand_subword (operands[1], 0, 0, DFmode);
6004 if (operands[2] == 0 || operands[3] == 0
6005 || operands[4] == 0 || operands[5] == 0)
6009 (define_expand "movdf"
6010 [(set (match_operand:DF 0 "general_movdst_operand" "")
6011 (match_operand:DF 1 "general_movsrc_operand" ""))]
6014 prepare_move_operands (operands, DFmode);
6015 if (TARGET_FPU_DOUBLE)
6017 emit_insn (gen_movdf_i4 (operands[0], operands[1]));
6022 ;; FIXME Although the movsf_i pattern is not used when there's an FPU,
6023 ;; it somehow influences some RA choices also on FPU targets.
6024 ;; For non-FPU targets it's actually not needed.
6025 (define_insn "movsf_i"
6026 [(set (match_operand:SF 0 "general_movdst_operand" "=r,r, r, r,m,l,r")
6027 (match_operand:SF 1 "general_movsrc_operand" "r,G,FQ,mr,r,r,l"))]
6030 /* ??? We provide some insn so that direct_{load,store}[SFmode] get set */
6031 || (REG_P (operands[0]) && REGNO (operands[0]) == 3)
6032 || (REG_P (operands[1]) && REGNO (operands[1]) == 3))
6033 && (arith_reg_operand (operands[0], SFmode)
6034 || arith_reg_operand (operands[1], SFmode))"
6043 [(set_attr "type" "move,move,pcload,load,store,move,move")
6044 (set_attr_alternative "length"
6047 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6048 (const_int 4) (const_int 2))
6049 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6050 (const_int 4) (const_int 2))
6051 (if_then_else (match_operand 0 "long_displacement_mem_operand")
6052 (const_int 4) (const_int 2))
6056 ;; We may not split the ry/yr/XX alternatives to movsi_ie, since
6057 ;; update_flow_info would not know where to put REG_EQUAL notes
6058 ;; when the destination changes mode.
6059 (define_insn "movsf_ie"
6060 [(set (match_operand:SF 0 "general_movdst_operand"
6061 "=f,r,f,f,fy, f,m, r, r,m,f,y,y,rf,r,y,<,y,y")
6062 (match_operand:SF 1 "general_movsrc_operand"
6063 " f,r,G,H,FQ,mf,f,FQ,mr,r,y,f,>,fr,y,r,y,>,y"))
6064 (use (reg:SI FPSCR_MODES_REG))
6065 (clobber (match_scratch:SI 2 "=X,X,X,X,&z, X,X, X, X,X,X,X,X, y,X,X,X,X,X"))]
6067 && (arith_reg_operand (operands[0], SFmode)
6068 || fpul_operand (operands[0], SFmode)
6069 || arith_reg_operand (operands[1], SFmode)
6070 || fpul_operand (operands[1], SFmode))"
6090 ! move optimized away"
6091 [(set_attr "type" "fmove,move,fmove,fmove,pcfload,fload,fstore,pcload,load,
6092 store,fmove,fmove,load,*,fpul_gp,gp_fpul,fstore,load,nil")
6093 (set_attr "late_fp_use" "*,*,*,*,*,*,yes,*,*,*,*,*,*,*,yes,*,yes,*,*")
6094 (set_attr_alternative "length"
6100 (if_then_else (match_operand 1 "displacement_mem_operand")
6101 (const_int 4) (const_int 2))
6102 (if_then_else (match_operand 0 "displacement_mem_operand")
6103 (const_int 4) (const_int 2))
6105 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6106 (const_int 4) (const_int 2))
6107 (if_then_else (match_operand 0 "long_displacement_mem_operand")
6108 (const_int 4) (const_int 2))
6118 (set_attr_alternative "fp_mode"
6119 [(if_then_else (eq_attr "fmovd" "yes")
6120 (const_string "single") (const_string "none"))
6121 (const_string "none")
6122 (const_string "single")
6123 (const_string "single")
6124 (const_string "none")
6125 (if_then_else (eq_attr "fmovd" "yes")
6126 (const_string "single") (const_string "none"))
6127 (if_then_else (eq_attr "fmovd" "yes")
6128 (const_string "single") (const_string "none"))
6129 (const_string "none")
6130 (const_string "none")
6131 (const_string "none")
6132 (const_string "none")
6133 (const_string "none")
6134 (const_string "none")
6135 (const_string "none")
6136 (const_string "none")
6137 (const_string "none")
6138 (const_string "none")
6139 (const_string "none")
6140 (const_string "none")])])
6142 (define_insn_and_split "movsf_ie_ra"
6143 [(set (match_operand:SF 0 "general_movdst_operand"
6144 "=f,r,f,f,fy,f,m, r,r,m,f,y,y,rf,r,y,<,y,y")
6145 (match_operand:SF 1 "general_movsrc_operand"
6146 " f,r,G,H,FQ,m,f,FQ,m,r,y,f,>,fr,y,r,y,>,y"))
6147 (use (reg:SI FPSCR_MODES_REG))
6148 (clobber (match_scratch:SF 2 "=r,r,X,X,&z,r,r, X,r,r,r,r,r, y,r,r,r,r,r"))
6151 && (arith_reg_operand (operands[0], SFmode)
6152 || fpul_operand (operands[0], SFmode)
6153 || arith_reg_operand (operands[1], SFmode)
6154 || fpul_operand (operands[1], SFmode))"
6174 ! move optimized away"
6176 && sh_movsf_ie_ra_split_p (operands[0], operands[1], operands[2])"
6179 if (! rtx_equal_p (operands[0], operands[1]))
6181 emit_insn (gen_movsf_ie (operands[2], operands[1]));
6182 emit_insn (gen_movsf_ie (operands[0], operands[2]));
6185 [(set_attr "type" "fmove,move,fmove,fmove,pcfload,fload,fstore,pcload,load,
6186 store,fmove,fmove,load,*,fpul_gp,gp_fpul,fstore,load,nil")
6187 (set_attr "late_fp_use" "*,*,*,*,*,*,yes,*,*,*,*,*,*,*,yes,*,yes,*,*")
6188 (set_attr_alternative "length"
6194 (if_then_else (match_operand 1 "displacement_mem_operand")
6195 (const_int 4) (const_int 2))
6196 (if_then_else (match_operand 0 "displacement_mem_operand")
6197 (const_int 4) (const_int 2))
6199 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6200 (const_int 4) (const_int 2))
6201 (if_then_else (match_operand 0 "long_displacement_mem_operand")
6202 (const_int 4) (const_int 2))
6212 (set_attr_alternative "fp_mode"
6213 [(if_then_else (eq_attr "fmovd" "yes")
6214 (const_string "single") (const_string "none"))
6215 (const_string "none")
6216 (const_string "single")
6217 (const_string "single")
6218 (const_string "none")
6219 (if_then_else (eq_attr "fmovd" "yes")
6220 (const_string "single") (const_string "none"))
6221 (if_then_else (eq_attr "fmovd" "yes")
6222 (const_string "single") (const_string "none"))
6223 (const_string "none")
6224 (const_string "none")
6225 (const_string "none")
6226 (const_string "none")
6227 (const_string "none")
6228 (const_string "none")
6229 (const_string "none")
6230 (const_string "none")
6231 (const_string "none")
6232 (const_string "none")
6233 (const_string "none")
6234 (const_string "none")])])
6237 [(set (match_operand:SF 0 "register_operand" "")
6238 (match_operand:SF 1 "register_operand" ""))
6239 (use (reg:SI FPSCR_MODES_REG))
6240 (clobber (reg:SI FPUL_REG))]
6242 [(parallel [(set (reg:SF FPUL_REG) (match_dup 1))
6243 (use (reg:SI FPSCR_MODES_REG))
6244 (clobber (scratch:SI))])
6245 (parallel [(set (match_dup 0) (reg:SF FPUL_REG))
6246 (use (reg:SI FPSCR_MODES_REG))
6247 (clobber (scratch:SI))])]
6250 (define_expand "movsf"
6251 [(set (match_operand:SF 0 "general_movdst_operand" "")
6252 (match_operand:SF 1 "general_movsrc_operand" ""))]
6255 prepare_move_operands (operands, SFmode);
6258 if (lra_in_progress)
6260 if (GET_CODE (operands[0]) == SCRATCH)
6262 emit_insn (gen_movsf_ie_ra (operands[0], operands[1]));
6266 emit_insn (gen_movsf_ie (operands[0], operands[1]));
6271 (define_expand "reload_insf__frn"
6272 [(parallel [(set (match_operand:SF 0 "register_operand" "=a")
6273 (match_operand:SF 1 "immediate_operand" "FQ"))
6274 (use (reg:SI FPSCR_MODES_REG))
6275 (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
6279 (define_expand "reload_insi__i_fpul"
6280 [(parallel [(set (match_operand:SI 0 "fpul_operand" "=y")
6281 (match_operand:SI 1 "immediate_operand" "i"))
6282 (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
6286 (define_insn "*movsi_y"
6287 [(set (match_operand:SI 0 "register_operand" "=y,y")
6288 (match_operand:SI 1 "immediate_operand" "Qi,I08"))
6289 (clobber (match_scratch:SI 2 "=&z,r"))]
6291 && (reload_in_progress || reload_completed)"
6293 [(set_attr "length" "4")
6294 (set_attr "type" "pcload,move")])
6297 [(set (match_operand:SI 0 "register_operand" "")
6298 (match_operand:SI 1 "immediate_operand" ""))
6299 (clobber (match_operand:SI 2 "register_operand" ""))]
6301 [(set (match_dup 2) (match_dup 1))
6302 (set (match_dup 0) (match_dup 2))]
6305 ;; ------------------------------------------------------------------------
6306 ;; Define the real conditional branch instructions.
6307 ;; ------------------------------------------------------------------------
6309 (define_expand "branch_true"
6310 [(set (pc) (if_then_else (ne (reg:SI T_REG) (const_int 0))
6311 (label_ref (match_operand 0))
6315 (define_expand "branch_false"
6316 [(set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
6317 (label_ref (match_operand 0))
6321 (define_insn_and_split "*cbranch_t"
6322 [(set (pc) (if_then_else (match_operand 1 "cbranch_treg_value")
6323 (label_ref (match_operand 0))
6327 return output_branch (sh_eval_treg_value (operands[1]), insn, operands);
6332 /* Try to canonicalize the branch condition if it is not one of:
6333 (ne (reg:SI T_REG) (const_int 0))
6334 (eq (reg:SI T_REG) (const_int 0))
6336 Instead of splitting out a new insn, we modify the current insn's
6337 operands as needed. This preserves things such as REG_DEAD notes. */
6339 if ((GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)
6340 && REG_P (XEXP (operands[1], 0)) && REGNO (XEXP (operands[1], 0)) == T_REG
6341 && XEXP (operands[1], 1) == const0_rtx)
6344 int branch_cond = sh_eval_treg_value (operands[1]);
6345 rtx new_cond_rtx = NULL_RTX;
6347 if (branch_cond == 0)
6348 new_cond_rtx = gen_rtx_EQ (VOIDmode, get_t_reg_rtx (), const0_rtx);
6349 else if (branch_cond == 1)
6350 new_cond_rtx = gen_rtx_NE (VOIDmode, get_t_reg_rtx (), const0_rtx);
6352 if (new_cond_rtx != NULL_RTX)
6353 validate_change (curr_insn, &XEXP (XEXP (PATTERN (curr_insn), 1), 0),
6354 new_cond_rtx, false);
6357 [(set_attr "type" "cbranch")])
6359 ;; Patterns to prevent reorg from re-combining a condbranch with a branch
6360 ;; which destination is too far away.
6361 ;; The const_int_operand is distinct for each branch target; it avoids
6362 ;; unwanted matches with redundant_insn.
6363 (define_insn "block_branch_redirect"
6364 [(set (pc) (unspec [(match_operand 0 "const_int_operand" "")] UNSPEC_BBR))]
6367 [(set_attr "length" "0")])
6369 ;; This one has the additional purpose to record a possible scratch register
6370 ;; for the following branch.
6371 ;; ??? Unfortunately, just setting the scratch register is not good enough,
6372 ;; because the insn then might be deemed dead and deleted. And we can't
6373 ;; make the use in the jump insn explicit because that would disable
6374 ;; delay slot scheduling from the target.
6375 (define_insn "indirect_jump_scratch"
6376 [(set (match_operand:SI 0 "register_operand" "=r")
6377 (unspec:SI [(match_operand 1 "const_int_operand" "")] UNSPEC_BBR))
6378 (set (pc) (unspec [(const_int 0)] UNSPEC_BBR))]
6381 [(set_attr "length" "0")])
6383 ;; This one is used to preemt an insn from beyond the bra / braf / jmp
6384 ;; being pulled into the delay slot of a condbranch that has been made to
6385 ;; jump around the unconditional jump because it was out of range.
6386 (define_insn "stuff_delay_slot"
6388 (unspec [(match_operand:SI 0 "const_int_operand" "") (pc)
6389 (match_operand:SI 1 "const_int_operand" "")] UNSPEC_BBR))]
6392 [(set_attr "length" "0")
6393 (set_attr "cond_delay_slot" "yes")])
6395 ;; Conditional branch insns
6397 ; operand 0 is the loop count pseudo register
6398 ; operand 1 is the label to jump to at the top of the loop
6399 (define_expand "doloop_end"
6400 [(parallel [(set (pc)
6401 (if_then_else (ne:SI (match_operand:SI 0 "" "")
6403 (label_ref (match_operand 1 "" ""))
6406 (plus:SI (match_dup 0) (const_int -1)))
6407 (clobber (reg:SI T_REG))])]
6410 if (GET_MODE (operands[0]) != SImode)
6412 emit_jump_insn (gen_doloop_end_split (operands[0], operands[1], operands[0]));
6416 (define_insn_and_split "doloop_end_split"
6418 (if_then_else (ne:SI (match_operand:SI 2 "arith_reg_dest" "0")
6420 (label_ref (match_operand 1 "" ""))
6422 (set (match_operand:SI 0 "arith_reg_dest" "=r")
6423 (plus:SI (match_dup 2) (const_int -1)))
6424 (clobber (reg:SI T_REG))]
6428 [(parallel [(set (reg:SI T_REG)
6429 (eq:SI (match_dup 2) (const_int 1)))
6430 (set (match_dup 0) (plus:SI (match_dup 2) (const_int -1)))])
6431 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
6432 (label_ref (match_dup 1))
6435 [(set_attr "type" "cbranch")])
6437 ;; ------------------------------------------------------------------------
6438 ;; Jump and linkage insns
6439 ;; ------------------------------------------------------------------------
6441 (define_insn "jump_compact"
6443 (label_ref (match_operand 0 "" "")))]
6444 "TARGET_SH1 && !CROSSING_JUMP_P (insn)"
6446 /* The length is 16 if the delay slot is unfilled. */
6447 if (get_attr_length(insn) > 4)
6448 return output_far_jump(insn, operands[0]);
6452 [(set_attr "type" "jump")
6453 (set_attr "needs_delay_slot" "yes")])
6455 (define_insn "*jump_compact_crossing"
6457 (label_ref (match_operand 0 "" "")))]
6459 && flag_reorder_blocks_and_partition
6460 && CROSSING_JUMP_P (insn)"
6462 /* The length is 16 if the delay slot is unfilled. */
6463 return output_far_jump(insn, operands[0]);
6465 [(set_attr "type" "jump")
6466 (set_attr "length" "16")])
6468 (define_expand "jump"
6470 (label_ref (match_operand 0 "" "")))]
6473 emit_jump_insn (gen_jump_compact (operands[0]));
6477 (define_insn "calli"
6478 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
6479 (match_operand 1 "" ""))
6480 (use (reg:SI FPSCR_MODES_REG))
6481 (clobber (reg:SI PR_REG))]
6482 "TARGET_SH1 && !TARGET_FDPIC"
6484 if (TARGET_SH2A && dbr_sequence_length () == 0)
6489 [(set_attr "type" "call")
6490 (set (attr "fp_mode")
6491 (if_then_else (eq_attr "fpu_single" "yes")
6492 (const_string "single") (const_string "double")))
6493 (set_attr "needs_delay_slot" "yes")
6494 (set_attr "fp_set" "unknown")])
6496 (define_insn "calli_fdpic"
6497 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
6499 (use (reg:SI FPSCR_MODES_REG))
6500 (use (reg:SI PIC_REG))
6501 (clobber (reg:SI PR_REG))]
6504 if (TARGET_SH2A && dbr_sequence_length () == 0)
6509 [(set_attr "type" "call")
6510 (set (attr "fp_mode")
6511 (if_then_else (eq_attr "fpu_single" "yes")
6512 (const_string "single") (const_string "double")))
6513 (set_attr "needs_delay_slot" "yes")
6514 (set_attr "fp_set" "unknown")])
6516 ;; This is TBR relative jump instruction for SH2A architecture.
6517 ;; Its use is enabled by assigning an attribute "function_vector"
6518 ;; and the vector number to a function during its declaration.
6519 (define_insn "calli_tbr_rel"
6520 [(call (mem (match_operand:SI 0 "symbol_ref_operand" ""))
6521 (match_operand 1 "" ""))
6522 (use (reg:SI FPSCR_MODES_REG))
6523 (use (match_scratch 2))
6524 (clobber (reg:SI PR_REG))]
6525 "TARGET_SH2A && sh2a_is_function_vector_call (operands[0])"
6527 unsigned HOST_WIDE_INT vect_num;
6528 vect_num = sh2a_get_function_vector_number (operands[0]);
6529 operands[2] = GEN_INT (vect_num * 4);
6531 return "jsr/n @@(%O2,tbr)";
6533 [(set_attr "type" "call")
6534 (set (attr "fp_mode")
6535 (if_then_else (eq_attr "fpu_single" "yes")
6536 (const_string "single") (const_string "double")))
6537 (set_attr "needs_delay_slot" "no")
6538 (set_attr "fp_set" "unknown")])
6540 ;; This is a pc-rel call, using bsrf, for use with PIC.
6541 (define_insn "calli_pcrel"
6542 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
6543 (match_operand 1 "" ""))
6544 (use (reg:SI FPSCR_MODES_REG))
6545 (use (reg:SI PIC_REG))
6546 (use (match_operand 2 "" ""))
6547 (clobber (reg:SI PR_REG))]
6550 return "bsrf %0" "\n"
6553 [(set_attr "type" "call")
6554 (set (attr "fp_mode")
6555 (if_then_else (eq_attr "fpu_single" "yes")
6556 (const_string "single") (const_string "double")))
6557 (set_attr "needs_delay_slot" "yes")
6558 (set_attr "fp_set" "unknown")])
6560 (define_insn_and_split "call_pcrel"
6561 [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
6562 (match_operand 1 "" ""))
6563 (use (reg:SI FPSCR_MODES_REG))
6564 (use (reg:SI PIC_REG))
6565 (clobber (reg:SI PR_REG))
6566 (clobber (match_scratch:SI 2 "=&r"))]
6572 rtx lab = PATTERN (gen_call_site ());
6574 sh_expand_sym_label2reg (operands[2], operands[0], lab, false);
6575 emit_call_insn (gen_calli_pcrel (operands[2], operands[1], copy_rtx (lab)));
6578 [(set_attr "type" "call")
6579 (set (attr "fp_mode")
6580 (if_then_else (eq_attr "fpu_single" "yes")
6581 (const_string "single") (const_string "double")))
6582 (set_attr "needs_delay_slot" "yes")
6583 (set_attr "fp_set" "unknown")])
6585 (define_insn "call_valuei"
6586 [(set (match_operand 0 "" "=rf")
6587 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
6588 (match_operand 2 "" "")))
6589 (use (reg:SI FPSCR_MODES_REG))
6590 (clobber (reg:SI PR_REG))]
6591 "TARGET_SH1 && !TARGET_FDPIC"
6593 if (TARGET_SH2A && dbr_sequence_length () == 0)
6598 [(set_attr "type" "call")
6599 (set (attr "fp_mode")
6600 (if_then_else (eq_attr "fpu_single" "yes")
6601 (const_string "single") (const_string "double")))
6602 (set_attr "needs_delay_slot" "yes")
6603 (set_attr "fp_set" "unknown")])
6605 (define_insn "call_valuei_fdpic"
6606 [(set (match_operand 0 "" "=rf")
6607 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
6609 (use (reg:SI FPSCR_REG))
6610 (use (reg:SI PIC_REG))
6611 (clobber (reg:SI PR_REG))]
6614 if (TARGET_SH2A && dbr_sequence_length () == 0)
6619 [(set_attr "type" "call")
6620 (set (attr "fp_mode")
6621 (if_then_else (eq_attr "fpu_single" "yes")
6622 (const_string "single") (const_string "double")))
6623 (set_attr "needs_delay_slot" "yes")
6624 (set_attr "fp_set" "unknown")])
6626 ;; This is TBR relative jump instruction for SH2A architecture.
6627 ;; Its use is enabled by assigning an attribute "function_vector"
6628 ;; and the vector number to a function during its declaration.
6629 (define_insn "call_valuei_tbr_rel"
6630 [(set (match_operand 0 "" "=rf")
6631 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
6632 (match_operand 2 "" "")))
6633 (use (reg:SI FPSCR_MODES_REG))
6634 (use (match_scratch 3))
6635 (clobber (reg:SI PR_REG))]
6636 "TARGET_SH2A && sh2a_is_function_vector_call (operands[1])"
6638 unsigned HOST_WIDE_INT vect_num;
6639 vect_num = sh2a_get_function_vector_number (operands[1]);
6640 operands[3] = GEN_INT (vect_num * 4);
6642 return "jsr/n @@(%O3,tbr)";
6644 [(set_attr "type" "call")
6645 (set (attr "fp_mode")
6646 (if_then_else (eq_attr "fpu_single" "yes")
6647 (const_string "single") (const_string "double")))
6648 (set_attr "needs_delay_slot" "no")
6649 (set_attr "fp_set" "unknown")])
6651 (define_insn "call_valuei_pcrel"
6652 [(set (match_operand 0 "" "=rf")
6653 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
6654 (match_operand 2 "" "")))
6655 (use (reg:SI FPSCR_MODES_REG))
6656 (use (reg:SI PIC_REG))
6657 (use (match_operand 3 "" ""))
6658 (clobber (reg:SI PR_REG))]
6661 return "bsrf %1" "\n"
6664 [(set_attr "type" "call")
6665 (set (attr "fp_mode")
6666 (if_then_else (eq_attr "fpu_single" "yes")
6667 (const_string "single") (const_string "double")))
6668 (set_attr "needs_delay_slot" "yes")
6669 (set_attr "fp_set" "unknown")])
6671 (define_insn_and_split "call_value_pcrel"
6672 [(set (match_operand 0 "" "=rf")
6673 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
6674 (match_operand 2 "" "")))
6675 (use (reg:SI FPSCR_MODES_REG))
6676 (use (reg:SI PIC_REG))
6677 (clobber (reg:SI PR_REG))
6678 (clobber (match_scratch:SI 3 "=&r"))]
6684 rtx lab = PATTERN (gen_call_site ());
6686 sh_expand_sym_label2reg (operands[3], operands[1], lab, false);
6687 emit_call_insn (gen_call_valuei_pcrel (operands[0], operands[3],
6688 operands[2], copy_rtx (lab)));
6691 [(set_attr "type" "call")
6692 (set (attr "fp_mode")
6693 (if_then_else (eq_attr "fpu_single" "yes")
6694 (const_string "single") (const_string "double")))
6695 (set_attr "needs_delay_slot" "yes")
6696 (set_attr "fp_set" "unknown")])
6698 (define_expand "call"
6699 [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
6700 (match_operand 1 "" ""))
6701 (match_operand 2 "" "")
6702 (use (reg:SI FPSCR_MODES_REG))
6703 (clobber (reg:SI PR_REG))])]
6708 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
6709 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
6712 if (!flag_pic && TARGET_SH2A
6713 && MEM_P (operands[0])
6714 && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
6716 if (sh2a_is_function_vector_call (XEXP (operands[0], 0)))
6718 emit_call_insn (gen_calli_tbr_rel (XEXP (operands[0], 0),
6723 if (flag_pic && TARGET_SH2
6724 && MEM_P (operands[0])
6725 && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
6727 emit_call_insn (gen_call_pcrel (XEXP (operands[0], 0), operands[1]));
6732 operands[0] = force_reg (SImode, XEXP (operands[0], 0));
6733 operands[1] = operands[2];
6738 operands[0] = sh_load_function_descriptor (operands[0]);
6739 emit_call_insn (gen_calli_fdpic (operands[0], operands[1]));
6742 emit_call_insn (gen_calli (operands[0], operands[1]));
6746 (define_expand "call_value"
6747 [(parallel [(set (match_operand 0 "arith_reg_operand" "")
6748 (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
6749 (match_operand 2 "" "")))
6750 (match_operand 3 "" "")
6751 (use (reg:SI FPSCR_MODES_REG))
6752 (clobber (reg:SI PR_REG))])]
6757 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
6758 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
6761 if (!flag_pic && TARGET_SH2A
6762 && MEM_P (operands[1])
6763 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
6765 if (sh2a_is_function_vector_call (XEXP (operands[1], 0)))
6767 emit_call_insn (gen_call_valuei_tbr_rel (operands[0],
6768 XEXP (operands[1], 0), operands[2]));
6772 if (flag_pic && TARGET_SH2
6773 && MEM_P (operands[1])
6774 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
6776 emit_call_insn (gen_call_value_pcrel (operands[0], XEXP (operands[1], 0),
6781 operands[1] = force_reg (SImode, XEXP (operands[1], 0));
6785 operands[1] = sh_load_function_descriptor (operands[1]);
6786 emit_call_insn (gen_call_valuei_fdpic (operands[0], operands[1],
6790 emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
6794 (define_insn "sibcalli"
6795 [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
6796 (match_operand 1 "" ""))
6797 (use (reg:SI FPSCR_MODES_REG))
6799 "TARGET_SH1 && !TARGET_FDPIC"
6801 [(set_attr "needs_delay_slot" "yes")
6802 (set (attr "fp_mode")
6803 (if_then_else (eq_attr "fpu_single" "yes")
6804 (const_string "single") (const_string "double")))
6805 (set_attr "type" "jump_ind")])
6807 (define_insn "sibcalli_fdpic"
6808 [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
6810 (use (reg:SI FPSCR_MODES_REG))
6811 (use (reg:SI PIC_REG))
6815 [(set_attr "needs_delay_slot" "yes")
6816 (set (attr "fp_mode")
6817 (if_then_else (eq_attr "fpu_single" "yes")
6818 (const_string "single") (const_string "double")))
6819 (set_attr "type" "jump_ind")])
6821 (define_insn "sibcalli_pcrel"
6822 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
6823 (match_operand 1 "" ""))
6824 (use (match_operand 2 "" ""))
6825 (use (reg:SI FPSCR_MODES_REG))
6827 "TARGET_SH2 && !TARGET_FDPIC"
6829 return "braf %0" "\n"
6832 [(set_attr "needs_delay_slot" "yes")
6833 (set (attr "fp_mode")
6834 (if_then_else (eq_attr "fpu_single" "yes")
6835 (const_string "single") (const_string "double")))
6836 (set_attr "type" "jump_ind")])
6838 (define_insn "sibcalli_pcrel_fdpic"
6839 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
6841 (use (match_operand 2))
6842 (use (reg:SI FPSCR_MODES_REG))
6843 (use (reg:SI PIC_REG))
6845 "TARGET_SH2 && TARGET_FDPIC"
6847 return "braf %0" "\n"
6850 [(set_attr "needs_delay_slot" "yes")
6851 (set (attr "fp_mode")
6852 (if_then_else (eq_attr "fpu_single" "yes")
6853 (const_string "single") (const_string "double")))
6854 (set_attr "type" "jump_ind")])
6856 ;; This uses an unspec to describe that the symbol_ref is very close.
6857 (define_insn "sibcalli_thunk"
6858 [(call (mem:SI (unspec:SI [(match_operand:SI 0 "symbol_ref_operand" "")]
6860 (match_operand 1 "" ""))
6861 (use (reg:SI FPSCR_MODES_REG))
6865 [(set_attr "needs_delay_slot" "yes")
6866 (set (attr "fp_mode")
6867 (if_then_else (eq_attr "fpu_single" "yes")
6868 (const_string "single") (const_string "double")))
6869 (set_attr "type" "jump")
6870 (set_attr "length" "2")])
6872 (define_insn_and_split "sibcall_pcrel"
6873 [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
6874 (match_operand 1 "" ""))
6875 (use (reg:SI FPSCR_MODES_REG))
6876 (clobber (match_scratch:SI 2 "=&k"))
6878 "TARGET_SH2 && !TARGET_FDPIC"
6883 rtx lab = PATTERN (gen_call_site ());
6886 sh_expand_sym_label2reg (operands[2], operands[0], lab, true);
6887 call_insn = emit_call_insn (gen_sibcalli_pcrel (operands[2], operands[1],
6889 SIBLING_CALL_P (call_insn) = 1;
6892 [(set_attr "needs_delay_slot" "yes")
6893 (set (attr "fp_mode")
6894 (if_then_else (eq_attr "fpu_single" "yes")
6895 (const_string "single") (const_string "double")))
6896 (set_attr "type" "jump_ind")])
6898 (define_insn_and_split "sibcall_pcrel_fdpic"
6899 [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand"))
6901 (use (reg:SI FPSCR_MODES_REG))
6902 (use (reg:SI PIC_REG))
6903 (clobber (match_scratch:SI 2 "=k"))
6905 "TARGET_SH2 && TARGET_FDPIC"
6907 "&& reload_completed"
6910 rtx lab = PATTERN (gen_call_site ());
6912 sh_expand_sym_label2reg (operands[2], operands[0], lab, true);
6913 rtx i = emit_call_insn (gen_sibcalli_pcrel_fdpic (operands[2], operands[1],
6915 SIBLING_CALL_P (i) = 1;
6918 [(set_attr "needs_delay_slot" "yes")
6919 (set (attr "fp_mode")
6920 (if_then_else (eq_attr "fpu_single" "yes")
6921 (const_string "single") (const_string "double")))
6922 (set_attr "type" "jump_ind")])
6924 (define_expand "sibcall"
6926 [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
6927 (match_operand 1 "" ""))
6928 (match_operand 2 "" "")
6929 (use (reg:SI FPSCR_MODES_REG))
6935 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
6936 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
6939 if (flag_pic && TARGET_SH2
6940 && MEM_P (operands[0])
6941 && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
6942 /* The PLT needs the PIC register, but the epilogue would have
6943 to restore it, so we can only use PC-relative PIC calls for
6944 static functions. */
6945 && SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
6948 emit_call_insn (gen_sibcall_pcrel_fdpic (XEXP (operands[0], 0),
6951 emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0), operands[1]));
6955 operands[0] = force_reg (SImode, XEXP (operands[0], 0));
6959 operands[0] = sh_load_function_descriptor (operands[0]);
6960 emit_call_insn (gen_sibcalli_fdpic (operands[0], operands[1]));
6963 emit_call_insn (gen_sibcalli (operands[0], operands[1]));
6967 (define_insn "sibcall_valuei"
6968 [(set (match_operand 0 "" "=rf")
6969 (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
6970 (match_operand 2 "" "")))
6971 (use (reg:SI FPSCR_MODES_REG))
6973 "TARGET_SH1 && !TARGET_FDPIC"
6975 [(set_attr "needs_delay_slot" "yes")
6976 (set (attr "fp_mode")
6977 (if_then_else (eq_attr "fpu_single" "yes")
6978 (const_string "single") (const_string "double")))
6979 (set_attr "type" "jump_ind")])
6981 (define_insn "sibcall_valuei_fdpic"
6982 [(set (match_operand 0 "" "=rf")
6983 (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
6985 (use (reg:SI FPSCR_MODES_REG))
6986 (use (reg:SI PIC_REG))
6990 [(set_attr "needs_delay_slot" "yes")
6991 (set (attr "fp_mode")
6992 (if_then_else (eq_attr "fpu_single" "yes")
6993 (const_string "single") (const_string "double")))
6994 (set_attr "type" "jump_ind")])
6996 (define_insn "sibcall_valuei_pcrel"
6997 [(set (match_operand 0 "" "=rf")
6998 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
6999 (match_operand 2 "" "")))
7000 (use (match_operand 3 "" ""))
7001 (use (reg:SI FPSCR_MODES_REG))
7003 "TARGET_SH2 && !TARGET_FDPIC"
7005 return "braf %1" "\n"
7008 [(set_attr "needs_delay_slot" "yes")
7009 (set (attr "fp_mode")
7010 (if_then_else (eq_attr "fpu_single" "yes")
7011 (const_string "single") (const_string "double")))
7012 (set_attr "type" "jump_ind")])
7014 (define_insn "sibcall_valuei_pcrel_fdpic"
7015 [(set (match_operand 0 "" "=rf")
7016 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
7018 (use (match_operand 3))
7019 (use (reg:SI FPSCR_MODES_REG))
7020 (use (reg:SI PIC_REG))
7022 "TARGET_SH2 && TARGET_FDPIC"
7024 return "braf %1" "\n"
7027 [(set_attr "needs_delay_slot" "yes")
7028 (set (attr "fp_mode")
7029 (if_then_else (eq_attr "fpu_single" "yes")
7030 (const_string "single") (const_string "double")))
7031 (set_attr "type" "jump_ind")])
7033 ;; sibcall_value_pcrel used to have a =&k clobber for the scratch register
7034 ;; that it needs for the branch address. This causes troubles when there
7035 ;; is a big overlap of argument and return value registers. Hence, use a
7036 ;; fixed call clobbered register for the address. See also PR 67260.
7037 (define_insn_and_split "sibcall_value_pcrel"
7038 [(set (match_operand 0 "" "=rf")
7039 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
7040 (match_operand 2 "" "")))
7041 (use (reg:SI FPSCR_MODES_REG))
7042 (clobber (reg:SI R1_REG))
7044 "TARGET_SH2 && !TARGET_FDPIC"
7049 rtx lab = PATTERN (gen_call_site ());
7050 rtx tmp = gen_rtx_REG (SImode, R1_REG);
7052 sh_expand_sym_label2reg (tmp, operands[1], lab, true);
7053 rtx call_insn = emit_call_insn (gen_sibcall_valuei_pcrel (operands[0],
7057 SIBLING_CALL_P (call_insn) = 1;
7060 [(set_attr "needs_delay_slot" "yes")
7061 (set (attr "fp_mode")
7062 (if_then_else (eq_attr "fpu_single" "yes")
7063 (const_string "single") (const_string "double")))
7064 (set_attr "type" "jump_ind")])
7066 ;; Like for sibcall_value_pcrel, use a fixed call clobbered register for
7067 ;; the branch address.
7068 (define_insn_and_split "sibcall_value_pcrel_fdpic"
7069 [(set (match_operand 0 "" "=rf")
7070 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand"))
7072 (use (reg:SI FPSCR_MODES_REG))
7073 (use (reg:SI PIC_REG))
7074 (clobber (reg:SI R1_REG))
7076 "TARGET_SH2 && TARGET_FDPIC"
7078 "&& reload_completed"
7081 rtx lab = PATTERN (gen_call_site ());
7082 rtx tmp = gen_rtx_REG (SImode, R1_REG);
7084 sh_expand_sym_label2reg (tmp, operands[1], lab, true);
7085 rtx i = emit_call_insn (gen_sibcall_valuei_pcrel_fdpic (operands[0],
7089 SIBLING_CALL_P (i) = 1;
7092 [(set_attr "needs_delay_slot" "yes")
7093 (set (attr "fp_mode")
7094 (if_then_else (eq_attr "fpu_single" "yes")
7095 (const_string "single") (const_string "double")))
7096 (set_attr "type" "jump_ind")])
7098 (define_expand "sibcall_value"
7100 [(set (match_operand 0 "arith_reg_operand" "")
7101 (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
7102 (match_operand 2 "" "")))
7103 (match_operand 3 "" "")
7104 (use (reg:SI FPSCR_MODES_REG))
7110 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
7111 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
7114 if (flag_pic && TARGET_SH2
7115 && MEM_P (operands[1])
7116 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
7117 /* The PLT needs the PIC register, but the epilogue would have
7118 to restore it, so we can only use PC-relative PIC calls for
7119 static functions. */
7120 && SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
7123 emit_call_insn (gen_sibcall_value_pcrel_fdpic (operands[0],
7124 XEXP (operands[1], 0),
7127 emit_call_insn (gen_sibcall_value_pcrel (operands[0],
7128 XEXP (operands[1], 0),
7133 operands[1] = force_reg (SImode, XEXP (operands[1], 0));
7137 operands[1] = sh_load_function_descriptor (operands[1]);
7138 emit_call_insn (gen_sibcall_valuei_fdpic (operands[0], operands[1],
7142 emit_call_insn (gen_sibcall_valuei (operands[0], operands[1], operands[2]));
7146 (define_expand "sibcall_epilogue"
7150 sh_expand_epilogue (true);
7154 (define_insn "indirect_jump_compact"
7156 (match_operand:SI 0 "arith_reg_operand" "r"))]
7159 [(set_attr "needs_delay_slot" "yes")
7160 (set_attr "type" "jump_ind")])
7162 (define_expand "indirect_jump"
7164 (match_operand 0 "register_operand" ""))]
7167 if (GET_MODE (operands[0]) != Pmode)
7168 operands[0] = gen_rtx_SUBREG (Pmode, operands[0], 0);
7171 ;; The use of operand 1 / 2 helps us distinguish case table jumps
7172 ;; which can be present in structured code from indirect jumps which cannot
7173 ;; be present in structured code. This allows -fprofile-arcs to work.
7175 ;; For SH1 processors.
7176 (define_insn "casesi_jump_1"
7178 (match_operand:SI 0 "register_operand" "r"))
7179 (use (label_ref (match_operand 1 "" "")))]
7182 [(set_attr "needs_delay_slot" "yes")
7183 (set_attr "type" "jump_ind")])
7185 ;; For all later processors.
7186 (define_insn "casesi_jump_2"
7187 [(set (pc) (plus:SI (match_operand:SI 0 "register_operand" "r")
7188 (label_ref (match_operand 1 "" ""))))
7189 (use (label_ref (match_operand 2 "" "")))]
7191 && (! INSN_UID (operands[1])
7192 || prev_real_insn (as_a<rtx_insn *> (operands[1])) == insn)"
7194 [(set_attr "needs_delay_slot" "yes")
7195 (set_attr "type" "jump_ind")])
7197 ;; Call subroutine returning any type.
7198 ;; ??? This probably doesn't work.
7199 (define_expand "untyped_call"
7200 [(parallel [(call (match_operand 0 "" "")
7202 (match_operand 1 "" "")
7203 (match_operand 2 "" "")])]
7204 "TARGET_SH2E || TARGET_SH2A"
7206 /* RA does not know that the call sets the function value registers.
7207 We avoid problems by claiming that those registers are clobbered
7209 for (int i = 0; i < XVECLEN (operands[2], 0); i++)
7210 emit_clobber (SET_SRC (XVECEXP (operands[2], 0, i)));
7212 emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
7214 for (int i = 0; i < XVECLEN (operands[2], 0); i++)
7216 rtx set = XVECEXP (operands[2], 0, i);
7217 emit_move_insn (SET_DEST (set), SET_SRC (set));
7220 /* The optimizer does not know that the call sets the function value
7221 registers we stored in the result block. We avoid problems by
7222 claiming that all hard registers are used and clobbered at this
7224 emit_insn (gen_blockage ());
7229 ;; ------------------------------------------------------------------------
7231 ;; ------------------------------------------------------------------------
7234 [(set (reg:SI T_REG)
7235 (eq:SI (match_operand:SI 1 "arith_reg_dest" "0") (const_int 1)))
7236 (set (match_operand:SI 0 "arith_reg_dest" "=r")
7237 (plus:SI (match_dup 1) (const_int -1)))]
7240 [(set_attr "type" "arith")])
7247 ;; Load address of a label. This is only generated by the casesi expand,
7248 ;; and by machine_dependent_reorg (fixing up fp moves).
7249 ;; This must use unspec, because this only works for labels that are
7252 [(set (reg:SI R0_REG)
7253 (unspec:SI [(label_ref (match_operand 0 "" ""))] UNSPEC_MOVA))]
7256 [(set_attr "in_delay_slot" "no")
7257 (set_attr "type" "arith")])
7259 ;; machine_dependent_reorg will make this a `mova'.
7260 (define_insn "mova_const"
7261 [(set (reg:SI R0_REG)
7262 (unspec:SI [(match_operand 0 "immediate_operand" "i")] UNSPEC_MOVA))]
7265 [(set_attr "in_delay_slot" "no")
7266 (set_attr "type" "arith")])
7268 ;; Loads of the GOTPC relocation values must not be optimized away
7269 ;; by e.g. any kind of CSE and must stay as they are. Although there
7270 ;; are other various ways to ensure this, we use an artificial counter
7271 ;; operand to generate unique symbols.
7272 (define_expand "GOTaddr2picreg"
7273 [(set (reg:SI R0_REG)
7274 (unspec:SI [(const:SI (unspec:SI [(match_dup 2)
7275 (match_operand:SI 0 "" "")]
7276 UNSPEC_PIC))] UNSPEC_MOVA))
7278 (const:SI (unspec:SI [(match_dup 2) (match_dup 0)] UNSPEC_PIC)))
7279 (set (match_dup 1) (plus:SI (match_dup 1) (reg:SI R0_REG)))]
7282 if (TARGET_VXWORKS_RTP)
7284 rtx gott_base = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE);
7285 rtx gott_index = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7286 emit_insn (gen_vxworks_picreg (gott_base, gott_index));
7292 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
7293 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
7297 operands[1] = gen_rtx_REG (Pmode, PIC_REG);
7298 operands[2] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
7301 ;; A helper for GOTaddr2picreg to finish up the initialization of the
7303 (define_expand "vxworks_picreg"
7304 [(set (reg:SI PIC_REG)
7305 (const:SI (unspec:SI [(match_operand:SI 0 "" "")] UNSPEC_PIC)))
7306 (set (reg:SI R0_REG)
7307 (const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PIC)))
7308 (set (reg:SI PIC_REG)
7309 (mem:SI (reg:SI PIC_REG)))
7310 (set (reg:SI PIC_REG)
7311 (mem:SI (plus:SI (reg:SI PIC_REG)
7313 "TARGET_VXWORKS_RTP")
7315 (define_expand "builtin_setjmp_receiver"
7316 [(match_operand 0 "" "")]
7319 emit_insn (gen_GOTaddr2picreg (const0_rtx));
7323 (define_expand "call_site"
7324 [(unspec [(match_dup 0)] UNSPEC_CALLER)]
7327 static HOST_WIDE_INT i = 0;
7328 operands[0] = GEN_INT (i);
7332 ;; op0 = op1 + r12 but hide it before reload completed. See the comment
7333 ;; in symGOT_load expand.
7334 (define_insn_and_split "chk_guard_add"
7335 [(set (match_operand:SI 0 "register_operand" "=&r")
7336 (unspec:SI [(match_operand:SI 1 "register_operand" "r")
7341 "TARGET_SH1 && reload_completed"
7342 [(set (match_dup 0) (reg:SI PIC_REG))
7343 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))]
7345 [(set_attr "type" "arith")])
7347 (define_expand "sym_label2reg"
7348 [(set (match_operand:SI 0 "" "")
7349 (const:SI (unspec:SI [(match_operand:SI 1 "" "")
7350 (const (plus:SI (match_operand:SI 2 "" "")
7355 (define_expand "symPCREL_label2reg"
7356 [(set (match_operand:SI 0 "" "")
7359 [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PCREL))
7360 (const:SI (plus:SI (match_operand:SI 2 "" "")
7361 (const_int 2)))] UNSPEC_PCREL_SYMOFF)))]
7365 (define_expand "symGOT_load"
7366 [(set (match_dup 2) (match_operand 1 "" ""))
7367 (set (match_dup 3) (plus (match_dup 2) (reg PIC_REG)))
7368 (set (match_operand 0 "" "") (mem (match_dup 3)))]
7372 bool stack_chk_guard_p = false;
7374 rtx picreg = TARGET_FDPIC ? sh_get_fdpic_reg_initial_val ()
7375 : gen_rtx_REG (Pmode, PIC_REG);
7377 operands[2] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
7378 operands[3] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
7381 && flag_stack_protect
7382 && GET_CODE (operands[1]) == CONST
7383 && GET_CODE (XEXP (operands[1], 0)) == UNSPEC
7384 && GET_CODE (XVECEXP (XEXP (operands[1], 0), 0, 0)) == SYMBOL_REF
7385 && strcmp (XSTR (XVECEXP (XEXP (operands[1], 0), 0, 0), 0),
7386 "__stack_chk_guard") == 0)
7387 stack_chk_guard_p = true;
7389 emit_move_insn (operands[2], operands[1]);
7391 /* When stack protector inserts codes after the result is set to
7392 R0, @(rX, r12) will cause a spill failure for R0. Use a unspec
7393 insn to avoid combining (set A (plus rX r12)) and (set op0 (mem A))
7394 when rX is a GOT address for the guard symbol. Ugly but doesn't
7395 matter because this is a rare situation. */
7396 if (stack_chk_guard_p)
7397 emit_insn (gen_chk_guard_add (operands[3], operands[2]));
7399 emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2], picreg));
7401 /* N.B. This is not constant for a GOTPLT relocation. */
7402 mem = gen_rtx_MEM (Pmode, operands[3]);
7403 MEM_NOTRAP_P (mem) = 1;
7404 /* ??? Should we have a special alias set for the GOT? */
7405 emit_move_insn (operands[0], mem);
7410 (define_expand "sym2GOT"
7411 [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOT))]
7415 (define_expand "symGOT2reg"
7416 [(match_operand 0 "" "") (match_operand 1 "" "")]
7421 gotsym = gen_sym2GOT (operands[1]);
7422 PUT_MODE (gotsym, Pmode);
7423 insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
7425 MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
7430 (define_expand "sym2GOTFUNCDESC"
7431 [(const (unspec [(match_operand 0)] UNSPEC_GOTFUNCDESC))]
7434 (define_expand "symGOTFUNCDESC2reg"
7435 [(match_operand 0) (match_operand 1)]
7438 rtx gotsym = gen_sym2GOTFUNCDESC (operands[1]);
7439 PUT_MODE (gotsym, Pmode);
7440 rtx insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
7442 MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
7447 (define_expand "symGOTPLT2reg"
7448 [(match_operand 0 "" "") (match_operand 1 "" "")]
7451 rtx pltsym = gen_rtx_CONST (Pmode,
7452 gen_rtx_UNSPEC (Pmode,
7453 gen_rtvec (1, operands[1]),
7455 emit_insn (gen_symGOT_load (operands[0], pltsym));
7459 (define_expand "sym2GOTOFF"
7460 [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTOFF))]
7464 (define_expand "symGOTOFF2reg"
7465 [(match_operand 0 "" "") (match_operand 1 "" "")]
7469 rtx t = (!can_create_pseudo_p ()
7471 : gen_reg_rtx (GET_MODE (operands[0])));
7473 rtx picreg = TARGET_FDPIC ? sh_get_fdpic_reg_initial_val ()
7474 : gen_rtx_REG (Pmode, PIC_REG);
7476 gotoffsym = gen_sym2GOTOFF (operands[1]);
7477 PUT_MODE (gotoffsym, Pmode);
7478 emit_move_insn (t, gotoffsym);
7479 rtx_insn *insn = emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
7481 set_unique_reg_note (insn, REG_EQUAL, operands[1]);
7486 (define_expand "sym2GOTOFFFUNCDESC"
7487 [(const (unspec [(match_operand 0)] UNSPEC_GOTOFFFUNCDESC))]
7490 (define_expand "symGOTOFFFUNCDESC2reg"
7491 [(match_operand 0) (match_operand 1)]
7494 rtx picreg = sh_get_fdpic_reg_initial_val ();
7495 rtx t = !can_create_pseudo_p ()
7497 : gen_reg_rtx (GET_MODE (operands[0]));
7499 rtx gotoffsym = gen_sym2GOTOFFFUNCDESC (operands[1]);
7500 PUT_MODE (gotoffsym, Pmode);
7501 emit_move_insn (t, gotoffsym);
7502 emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
7506 (define_expand "symPLT_label2reg"
7507 [(set (match_operand:SI 0 "" "")
7510 [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PLT))
7511 (const:SI (plus:SI (match_operand:SI 2 "" "")
7512 (const_int 2)))] UNSPEC_PCREL_SYMOFF)))
7513 ;; Even though the PIC register is not really used by the call
7514 ;; sequence in which this is expanded, the PLT code assumes the PIC
7515 ;; register is set, so we must not skip its initialization. Since
7516 ;; we only use this expand as part of calling sequences, and never
7517 ;; to take the address of a function, this is the best point to
7518 ;; insert the (use). Using the PLT to take the address of a
7519 ;; function would be wrong, not only because the PLT entry could
7520 ;; then be called from a function that doesn't initialize the PIC
7521 ;; register to the proper GOT, but also because pointers to the
7522 ;; same function might not compare equal, should they be set by
7523 ;; different shared libraries.
7524 (use (reg:SI PIC_REG))]
7528 (define_expand "sym2PIC"
7529 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PIC))]
7533 ;; -------------------------------------------------------------------------
7534 ;; TLS code generation.
7536 ;; FIXME: The multi-insn asm blocks should be converted to use
7537 ;; define_insn_and_split.
7538 ;; See the thread [PATCH/RFA] SH TLS support on gcc-patches
7539 ;; <http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01898.html>
7542 (define_insn "tls_global_dynamic"
7543 [(set (match_operand:SI 0 "register_operand" "=&z")
7544 (call:SI (mem:SI (unspec:SI [(match_operand:SI 1 "" "")]
7547 (use (reg:SI FPSCR_MODES_REG))
7548 (use (reg:SI PIC_REG))
7549 (clobber (reg:SI PR_REG))
7550 (clobber (scratch:SI))]
7553 return "mov.l 1f,r4" "\n"
7562 "1: .long %a1@TLSGD" "\n"
7563 "2: .long __tls_get_addr@PLT" "\n"
7566 [(set_attr "type" "tls_load")
7567 (set_attr "length" "26")])
7569 (define_insn "tls_local_dynamic"
7570 [(set (match_operand:SI 0 "register_operand" "=&z")
7571 (call:SI (mem:SI (unspec:SI [(match_operand:SI 1 "" "")]
7574 (use (reg:SI FPSCR_MODES_REG))
7575 (use (reg:SI PIC_REG))
7576 (clobber (reg:SI PR_REG))
7577 (clobber (scratch:SI))]
7580 return "mov.l 1f,r4" "\n"
7589 "1: .long %a1@TLSLDM" "\n"
7590 "2: .long __tls_get_addr@PLT" "\n"
7593 [(set_attr "type" "tls_load")
7594 (set_attr "length" "26")])
7596 (define_expand "sym2DTPOFF"
7597 [(const (unspec [(match_operand 0 "" "")] UNSPEC_DTPOFF))]
7601 (define_expand "symDTPOFF2reg"
7602 [(match_operand 0 "" "") (match_operand 1 "" "") (match_operand 2 "" "")]
7606 rtx t = (!can_create_pseudo_p ()
7608 : gen_reg_rtx (GET_MODE (operands[0])));
7610 dtpoffsym = gen_sym2DTPOFF (operands[1]);
7611 PUT_MODE (dtpoffsym, Pmode);
7612 emit_move_insn (t, dtpoffsym);
7613 emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, operands[2]));
7617 (define_expand "sym2GOTTPOFF"
7618 [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTTPOFF))]
7622 (define_insn "tls_initial_exec"
7623 [(set (match_operand:SI 0 "register_operand" "=&r")
7624 (unspec:SI [(match_operand:SI 1 "" "")]
7626 (use (reg:SI GBR_REG))
7627 (use (reg:SI PIC_REG))
7628 (clobber (reg:SI R0_REG))]
7631 return "mov.l 1f,r0" "\n"
7633 " mov.l @(r0,r12),r0" "\n"
7640 [(set_attr "type" "tls_load")
7641 (set_attr "length" "16")])
7643 (define_expand "sym2TPOFF"
7644 [(const (unspec [(match_operand 0 "" "")] UNSPEC_TPOFF))]
7648 (define_expand "symTPOFF2reg"
7649 [(match_operand 0 "" "") (match_operand 1 "" "")]
7654 tpoffsym = gen_sym2TPOFF (operands[1]);
7655 PUT_MODE (tpoffsym, Pmode);
7656 emit_move_insn (operands[0], tpoffsym);
7660 ;;------------------------------------------------------------------------------
7661 ;; Thread pointer getter and setter.
7663 ;; On SH the thread pointer is kept in the GBR.
7664 ;; These patterns are usually expanded from the respective built-in functions.
7665 (define_expand "get_thread_pointersi"
7666 [(set (match_operand:SI 0 "arith_reg_dest") (reg:SI GBR_REG))]
7669 ;; The store_gbr insn can also be used on !TARGET_SH1 for doing TLS accesses.
7670 (define_insn "store_gbr"
7671 [(set (match_operand:SI 0 "arith_reg_dest" "=r") (reg:SI GBR_REG))]
7674 [(set_attr "type" "tls_load")])
7676 (define_expand "set_thread_pointersi"
7677 [(set (reg:SI GBR_REG)
7678 (unspec_volatile:SI [(match_operand:SI 0 "arith_reg_operand")]
7682 (define_insn "load_gbr"
7683 [(set (reg:SI GBR_REG)
7684 (unspec_volatile:SI [(match_operand:SI 0 "arith_reg_operand" "r")]
7688 [(set_attr "type" "move")])
7690 ;;------------------------------------------------------------------------------
7691 ;; Thread pointer relative memory loads and stores.
7693 ;; On SH there are GBR displacement address modes which can be utilized to
7694 ;; access memory behind the thread pointer.
7695 ;; Since we do not allow using GBR for general purpose memory accesses, these
7696 ;; GBR addressing modes are formed by the combine pass.
7697 ;; This could be done with fewer patterns than below by using a mem predicate
7698 ;; for the GBR mem, but then reload would try to reload addresses with a
7699 ;; zero displacement for some strange reason.
7701 (define_insn "*mov<mode>_gbr_load"
7702 [(set (match_operand:QIHISI 0 "arith_reg_dest" "=z")
7703 (mem:QIHISI (plus:SI (reg:SI GBR_REG)
7704 (match_operand:QIHISI 1 "gbr_displacement"))))]
7706 "mov.<bwl> @(%O1,gbr),%0"
7707 [(set_attr "type" "load")])
7709 (define_insn "*mov<mode>_gbr_load"
7710 [(set (match_operand:QIHISI 0 "arith_reg_dest" "=z")
7711 (mem:QIHISI (reg:SI GBR_REG)))]
7713 "mov.<bwl> @(0,gbr),%0"
7714 [(set_attr "type" "load")])
7716 (define_insn "*mov<mode>_gbr_load"
7717 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
7719 (mem:QIHI (plus:SI (reg:SI GBR_REG)
7720 (match_operand:QIHI 1 "gbr_displacement")))))]
7722 "mov.<bw> @(%O1,gbr),%0"
7723 [(set_attr "type" "load")])
7725 (define_insn "*mov<mode>_gbr_load"
7726 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
7727 (sign_extend:SI (mem:QIHI (reg:SI GBR_REG))))]
7729 "mov.<bw> @(0,gbr),%0"
7730 [(set_attr "type" "load")])
7732 (define_insn "*mov<mode>_gbr_store"
7733 [(set (mem:QIHISI (plus:SI (reg:SI GBR_REG)
7734 (match_operand:QIHISI 0 "gbr_displacement")))
7735 (match_operand:QIHISI 1 "register_operand" "z"))]
7737 "mov.<bwl> %1,@(%O0,gbr)"
7738 [(set_attr "type" "store")])
7740 (define_insn "*mov<mode>_gbr_store"
7741 [(set (mem:QIHISI (reg:SI GBR_REG))
7742 (match_operand:QIHISI 0 "register_operand" "z"))]
7744 "mov.<bwl> %0,@(0,gbr)"
7745 [(set_attr "type" "store")])
7747 ;; DImode memory accesses have to be split in two SImode accesses.
7748 ;; Split them before reload, so that it gets a better chance to figure out
7749 ;; how to deal with the R0 restriction for the individual SImode accesses.
7750 ;; Do not match this insn during or after reload because it can't be split
7752 (define_insn_and_split "*movdi_gbr_load"
7753 [(set (match_operand:DI 0 "arith_reg_dest")
7754 (match_operand:DI 1 "gbr_address_mem"))]
7755 "TARGET_SH1 && can_create_pseudo_p ()"
7758 [(set (match_dup 3) (match_dup 5))
7759 (set (match_dup 4) (match_dup 6))]
7761 /* Swap low/high part load order on little endian, so that the result reg
7762 of the second load can be used better. */
7763 int off = TARGET_LITTLE_ENDIAN ? 1 : 0;
7764 operands[3 + off] = gen_lowpart (SImode, operands[0]);
7765 operands[5 + off] = gen_lowpart (SImode, operands[1]);
7766 operands[4 - off] = gen_highpart (SImode, operands[0]);
7767 operands[6 - off] = gen_highpart (SImode, operands[1]);
7770 (define_insn_and_split "*movdi_gbr_store"
7771 [(set (match_operand:DI 0 "gbr_address_mem")
7772 (match_operand:DI 1 "register_operand"))]
7773 "TARGET_SH1 && can_create_pseudo_p ()"
7776 [(set (match_dup 3) (match_dup 5))
7777 (set (match_dup 4) (match_dup 6))]
7779 /* Swap low/high part store order on big endian, so that stores of function
7780 call results can save a reg copy. */
7781 int off = TARGET_LITTLE_ENDIAN ? 0 : 1;
7782 operands[3 + off] = gen_lowpart (SImode, operands[0]);
7783 operands[5 + off] = gen_lowpart (SImode, operands[1]);
7784 operands[4 - off] = gen_highpart (SImode, operands[0]);
7785 operands[6 - off] = gen_highpart (SImode, operands[1]);
7788 ;; Sometimes memory accesses do not get combined with the store_gbr insn,
7789 ;; in particular when the displacements are in the range of the regular move
7790 ;; insns. Thus, in the first split pass after the combine pass we search
7791 ;; for missed opportunities and try to fix them up ourselves.
7792 ;; If an equivalent GBR address can be determined the load / store is split
7793 ;; into one of the GBR load / store patterns.
7794 ;; All of that must happen before reload (GBR address modes use R0 as the
7795 ;; other operand) and there's no point of doing it if the GBR is not
7796 ;; referenced in a function at all.
7798 [(set (match_operand:QIHISIDI 0 "register_operand")
7799 (match_operand:QIHISIDI 1 "memory_operand"))]
7800 "TARGET_SH1 && !reload_in_progress && !reload_completed
7801 && df_regs_ever_live_p (GBR_REG)"
7802 [(set (match_dup 0) (match_dup 1))]
7804 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
7805 if (gbr_mem != NULL_RTX)
7806 operands[1] = replace_equiv_address (operands[1], gbr_mem);
7812 [(set (match_operand:SI 0 "register_operand")
7813 (sign_extend:SI (match_operand:QIHI 1 "memory_operand")))]
7814 "TARGET_SH1 && !reload_in_progress && !reload_completed
7815 && df_regs_ever_live_p (GBR_REG)"
7816 [(set (match_dup 0) (sign_extend:SI (match_dup 1)))]
7818 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
7819 if (gbr_mem != NULL_RTX)
7820 operands[1] = replace_equiv_address (operands[1], gbr_mem);
7825 ;; On SH2A we've got movu.b and movu.w for doing zero-extending mem loads.
7826 ;; Split those so that a GBR load can be used.
7828 [(set (match_operand:SI 0 "register_operand")
7829 (zero_extend:SI (match_operand:QIHI 1 "memory_operand")))]
7830 "TARGET_SH2A && !reload_in_progress && !reload_completed
7831 && df_regs_ever_live_p (GBR_REG)"
7832 [(set (match_dup 2) (match_dup 1))
7833 (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
7835 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
7836 if (gbr_mem != NULL_RTX)
7838 operands[2] = gen_reg_rtx (GET_MODE (operands[1]));
7839 operands[1] = replace_equiv_address (operands[1], gbr_mem);
7846 [(set (match_operand:QIHISIDI 0 "memory_operand")
7847 (match_operand:QIHISIDI 1 "register_operand"))]
7848 "TARGET_SH1 && !reload_in_progress && !reload_completed
7849 && df_regs_ever_live_p (GBR_REG)"
7850 [(set (match_dup 0) (match_dup 1))]
7852 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[0]);
7853 if (gbr_mem != NULL_RTX)
7854 operands[0] = replace_equiv_address (operands[0], gbr_mem);
7859 ;;------------------------------------------------------------------------------
7860 ;; case instruction for switch statements.
7862 ;; operand 0 is index
7863 ;; operand 1 is the minimum bound
7864 ;; operand 2 is the maximum bound - minimum bound + 1
7865 ;; operand 3 is CODE_LABEL for the table;
7866 ;; operand 4 is the CODE_LABEL to go to if index out of range.
7867 (define_expand "casesi"
7868 [(match_operand:SI 0 "arith_reg_operand" "")
7869 (match_operand:SI 1 "arith_reg_operand" "")
7870 (match_operand:SI 2 "arith_reg_operand" "")
7871 (match_operand 3 "" "") (match_operand 4 "" "")]
7874 rtx reg = gen_reg_rtx (SImode);
7875 rtx reg2 = gen_reg_rtx (SImode);
7877 operands[1] = copy_to_mode_reg (SImode, operands[1]);
7878 operands[2] = copy_to_mode_reg (SImode, operands[2]);
7879 /* If optimizing, casesi_worker depends on the mode of the instruction
7880 before label it 'uses' - operands[3]. */
7881 emit_insn (gen_casesi_0 (operands[0], operands[1], operands[2], operands[4],
7883 emit_insn (gen_casesi_worker_0 (reg2, reg, operands[3]));
7885 emit_jump_insn (gen_casesi_jump_2 (reg2, gen_label_rtx (), operands[3]));
7887 emit_jump_insn (gen_casesi_jump_1 (reg2, operands[3]));
7888 /* For SH2 and newer, the ADDR_DIFF_VEC is not actually relative to
7889 operands[3], but to lab. We will fix this up in
7890 machine_dependent_reorg. */
7895 (define_expand "casesi_0"
7896 [(set (match_operand:SI 4 "" "") (match_operand:SI 0 "arith_reg_operand" ""))
7897 (set (match_dup 4) (minus:SI (match_dup 4)
7898 (match_operand:SI 1 "arith_operand" "")))
7900 (gtu:SI (match_dup 4)
7901 (match_operand:SI 2 "arith_reg_operand" "")))
7903 (if_then_else (ne (reg:SI T_REG)
7905 (label_ref (match_operand 3 "" ""))
7910 ;; ??? reload might clobber r0 if we use it explicitly in the RTL before
7911 ;; reload; using a R0_REGS pseudo reg is likely to give poor code.
7912 ;; So we keep the use of r0 hidden in a R0_REGS clobber until after reload.
7914 ;; The use on the T_REG in the casesi_worker* patterns links the bounds
7915 ;; checking insns and the table memory access. See also PR 69713.
7916 (define_insn "casesi_worker_0"
7917 [(set (match_operand:SI 0 "register_operand" "=r,r")
7918 (unspec:SI [(match_operand:SI 1 "register_operand" "0,r")
7919 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7920 (clobber (match_scratch:SI 3 "=X,1"))
7921 (clobber (match_scratch:SI 4 "=&z,z"))
7922 (use (reg:SI T_REG))]
7927 [(set (match_operand:SI 0 "register_operand" "")
7928 (unspec:SI [(match_operand:SI 1 "register_operand" "")
7929 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7930 (clobber (match_scratch:SI 3 ""))
7931 (clobber (match_scratch:SI 4))
7932 (use (reg:SI T_REG))]
7933 "TARGET_SH1 && ! TARGET_SH2 && reload_completed"
7934 [(set (reg:SI R0_REG) (unspec:SI [(label_ref (match_dup 2))] UNSPEC_MOVA))
7935 (parallel [(set (match_dup 0)
7936 (unspec:SI [(reg:SI R0_REG) (match_dup 1)
7937 (label_ref (match_dup 2))] UNSPEC_CASESI))
7938 (clobber (match_dup 3))])
7939 (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI R0_REG)))]
7941 if (GET_CODE (operands[2]) == CODE_LABEL)
7942 LABEL_NUSES (operands[2])++;
7946 [(set (match_operand:SI 0 "register_operand" "")
7947 (unspec:SI [(match_operand:SI 1 "register_operand" "")
7948 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7949 (clobber (match_scratch:SI 3 ""))
7950 (clobber (match_scratch:SI 4))
7951 (use (reg:SI T_REG))]
7952 "TARGET_SH2 && reload_completed"
7953 [(set (reg:SI R0_REG) (unspec:SI [(label_ref (match_dup 2))] UNSPEC_MOVA))
7954 (parallel [(set (match_dup 0)
7955 (unspec:SI [(reg:SI R0_REG) (match_dup 1)
7956 (label_ref (match_dup 2))] UNSPEC_CASESI))
7957 (clobber (match_dup 3))])]
7959 if (GET_CODE (operands[2]) == CODE_LABEL)
7960 LABEL_NUSES (operands[2])++;
7963 ;; This may be replaced with casesi_worker_2 in sh_reorg for PIC.
7964 ;; The insn length is set to 8 for that case.
7965 (define_insn "casesi_worker_1"
7966 [(set (match_operand:SI 0 "register_operand" "=r,r")
7967 (unspec:SI [(reg:SI R0_REG)
7968 (match_operand:SI 1 "register_operand" "0,r")
7969 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7970 (clobber (match_scratch:SI 3 "=X,1"))]
7973 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
7975 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
7977 switch (GET_MODE (diff_vec))
7980 return "shll2 %1" "\n"
7981 " mov.l @(r0,%1),%0";
7983 return "add %1,%1" "\n"
7984 " mov.w @(r0,%1),%0";
7986 if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
7987 return "mov.b @(r0,%1),%0" "\n"
7990 return "mov.b @(r0,%1),%0";
7996 [(set_attr_alternative "length"
7997 [(if_then_else (match_test "flag_pic") (const_int 8) (const_int 4))
7998 (if_then_else (match_test "flag_pic") (const_int 8) (const_int 4))])])
8000 (define_insn "casesi_worker_2"
8001 [(set (match_operand:SI 0 "register_operand" "=r,r")
8002 (unspec:SI [(reg:SI R0_REG)
8003 (match_operand:SI 1 "register_operand" "0,r")
8004 (label_ref (match_operand 2 "" ""))
8005 (label_ref (match_operand 3 "" ""))] UNSPEC_CASESI))
8006 (clobber (match_operand:SI 4 "" "=X,1"))]
8007 "TARGET_SH2 && reload_completed && flag_pic"
8009 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
8010 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
8012 switch (GET_MODE (diff_vec))
8015 return "shll2 %1" "\n"
8018 " mov.l @(r0,%1),%0";
8020 return "add %1,%1" "\n"
8023 " mov.w @(r0,%1),%0";
8025 if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
8026 return "add r0,%1" "\n"
8028 " mov.b @(r0,%1),%0" "\n"
8031 return "add r0,%1" "\n"
8033 " mov.b @(r0,%1),%0";
8038 [(set_attr "length" "8")])
8040 (define_expand "simple_return"
8042 "sh_can_use_simple_return_p ()")
8044 (define_expand "return"
8046 "reload_completed && epilogue_completed")
8048 (define_insn "*<code>_i"
8052 && ! sh_cfun_trap_exit_p ()"
8054 if (TARGET_SH2A && (dbr_sequence_length () == 0)
8055 && !current_function_interrupt)
8060 [(set_attr "type" "return")
8061 (set_attr "needs_delay_slot" "yes")])
8063 ;; trapa has no delay slot.
8064 (define_insn "*return_trapa"
8066 "TARGET_SH1 && reload_completed"
8068 [(set_attr "type" "return")])
8070 (define_expand "prologue"
8074 sh_expand_prologue ();
8078 (define_expand "epilogue"
8082 sh_expand_epilogue (false);
8085 (define_expand "eh_return"
8086 [(use (match_operand 0 "register_operand" ""))]
8089 emit_insn (gen_eh_set_ra_si (operands[0]));
8093 ;; Clobber the return address on the stack. We can't expand this
8094 ;; until we know where it will be put in the stack frame.
8096 (define_insn "eh_set_ra_si"
8097 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
8099 (clobber (match_scratch:SI 1 "=&r"))]
8104 [(unspec_volatile [(match_operand 0 "register_operand" "")]
8106 (clobber (match_scratch 1 ""))]
8110 sh_set_return_address (operands[0], operands[1]);
8114 (define_insn "blockage"
8115 [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
8118 [(set_attr "length" "0")])
8120 ;; Define movml instructions for SH2A target. Currently they are
8121 ;; used to push and pop all banked registers only.
8123 (define_insn "movml_push_banked"
8124 [(set (match_operand:SI 0 "register_operand" "=r")
8125 (plus (match_dup 0) (const_int -32)))
8126 (set (mem:SI (plus:SI (match_dup 0) (const_int 28))) (reg:SI R7_REG))
8127 (set (mem:SI (plus:SI (match_dup 0) (const_int 24))) (reg:SI R6_REG))
8128 (set (mem:SI (plus:SI (match_dup 0) (const_int 20))) (reg:SI R5_REG))
8129 (set (mem:SI (plus:SI (match_dup 0) (const_int 16))) (reg:SI R4_REG))
8130 (set (mem:SI (plus:SI (match_dup 0) (const_int 12))) (reg:SI R3_REG))
8131 (set (mem:SI (plus:SI (match_dup 0) (const_int 8))) (reg:SI R2_REG))
8132 (set (mem:SI (plus:SI (match_dup 0) (const_int 4))) (reg:SI R1_REG))
8133 (set (mem:SI (plus:SI (match_dup 0) (const_int 0))) (reg:SI R0_REG))]
8134 "TARGET_SH2A && REGNO (operands[0]) == 15"
8136 [(set_attr "in_delay_slot" "no")])
8138 (define_insn "movml_pop_banked"
8139 [(set (match_operand:SI 0 "register_operand" "=r")
8140 (plus (match_dup 0) (const_int 32)))
8141 (set (reg:SI R0_REG) (mem:SI (plus:SI (match_dup 0) (const_int -32))))
8142 (set (reg:SI R1_REG) (mem:SI (plus:SI (match_dup 0) (const_int -28))))
8143 (set (reg:SI R2_REG) (mem:SI (plus:SI (match_dup 0) (const_int -24))))
8144 (set (reg:SI R3_REG) (mem:SI (plus:SI (match_dup 0) (const_int -20))))
8145 (set (reg:SI R4_REG) (mem:SI (plus:SI (match_dup 0) (const_int -16))))
8146 (set (reg:SI R5_REG) (mem:SI (plus:SI (match_dup 0) (const_int -12))))
8147 (set (reg:SI R6_REG) (mem:SI (plus:SI (match_dup 0) (const_int -8))))
8148 (set (reg:SI R7_REG) (mem:SI (plus:SI (match_dup 0) (const_int -4))))]
8149 "TARGET_SH2A && REGNO (operands[0]) == 15"
8151 [(set_attr "in_delay_slot" "no")])
8153 ;; ------------------------------------------------------------------------
8155 ;; ------------------------------------------------------------------------
8158 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8159 (match_operand:SI 1 "t_reg_operand"))]
8162 [(set_attr "type" "arith")])
8164 (define_insn "movrt"
8165 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8166 (xor:SI (match_operand:SI 1 "t_reg_operand" "") (const_int 1)))]
8169 [(set_attr "type" "arith")])
8171 (define_expand "cstoresi4"
8172 [(set (match_operand:SI 0 "register_operand")
8173 (match_operator:SI 1 "comparison_operator"
8174 [(match_operand:SI 2 "cmpsi_operand")
8175 (match_operand:SI 3 "arith_operand")]))]
8178 if (sh_expand_t_scc (operands))
8181 if (! currently_expanding_to_rtl)
8184 sh_emit_compare_and_set (operands, SImode);
8188 (define_expand "cstoredi4"
8189 [(set (match_operand:SI 0 "register_operand")
8190 (match_operator:SI 1 "comparison_operator"
8191 [(match_operand:DI 2 "arith_operand")
8192 (match_operand:DI 3 "arith_operand")]))]
8195 if (sh_expand_t_scc (operands))
8198 if (! currently_expanding_to_rtl)
8201 sh_emit_compare_and_set (operands, DImode);
8205 ;; Move the complement of the T reg to a reg.
8206 ;; On SH2A the movrt insn can be used.
8207 ;; On anything else than SH2A this has to be done with multiple instructions.
8208 ;; One obvious way would be:
8213 ;; However, this puts pressure on r0 in most cases and thus the following is
8219 ;; If the constant -1 can be CSE-ed or lifted out of a loop it effectively
8220 ;; becomes a one instruction operation. Moreover, care must be taken that
8221 ;; the insn can still be combined with inverted compare and branch code
8222 ;; around it. On the other hand, if a function returns the complement of
8223 ;; a previous comparison result in the T bit, the xor #1,r0 approach might
8224 ;; lead to better code.
8225 (define_expand "movnegt"
8226 [(set (match_operand:SI 0 "arith_reg_dest" "")
8227 (xor:SI (match_operand:SI 1 "t_reg_operand" "") (const_int 1)))]
8231 emit_insn (gen_movrt (operands[0], operands[1]));
8234 rtx val = force_reg (SImode, gen_int_mode (-1, SImode));
8235 emit_insn (gen_movrt_negc (operands[0], operands[1], val));
8240 (define_insn_and_split "movrt_negc"
8241 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8242 (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
8243 (set (reg:SI T_REG) (const_int 1))
8244 (use (match_operand:SI 2 "arith_reg_operand" "r"))]
8247 "&& !sh_in_recog_treg_set_expr ()"
8250 if (sh_split_movrt_negc_to_movt_xor (curr_insn, operands))
8255 [(set_attr "type" "arith")])
8257 ;; The -1 constant will not be CSE-ed for the *movrt_negc pattern, but the
8258 ;; pattern can be used by the combine pass. Using a scratch reg for the
8259 ;; -1 constant results in slightly better register allocations compared to
8260 ;; generating a pseudo reg before reload.
8261 (define_insn_and_split "*movrt_negc"
8262 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8263 (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
8264 (clobber (match_scratch:SI 2 "=r"))
8265 (clobber (reg:SI T_REG))]
8266 "TARGET_SH1 && ! TARGET_SH2A"
8268 "&& !sh_in_recog_treg_set_expr ()"
8271 if (sh_split_movrt_negc_to_movt_xor (curr_insn, operands))
8273 else if (reload_completed)
8275 emit_move_insn (operands[2], gen_int_mode (-1, SImode));
8276 emit_insn (gen_movrt_negc (operands[0], operands[1], operands[2]));
8283 ;; Store the negated T bit in a reg using r0 and xor. This one doesn't
8284 ;; clobber the T bit, which is useful when storing the T bit and the
8285 ;; negated T bit in parallel. On SH2A the movrt insn can be used for that.
8286 ;; Usually we don't want this insn to be matched, except for cases where the
8287 ;; T bit clobber is really not appreciated. Hence the extra use on T_REG.
8288 (define_insn_and_split "movrt_xor"
8289 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
8290 (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
8291 (use (reg:SI T_REG))]
8294 "&& reload_completed"
8295 [(set (match_dup 0) (reg:SI T_REG))
8296 (set (match_dup 0) (xor:SI (match_dup 0) (const_int 1)))])
8299 ;; 0x7fffffff + (1-T) = 0 - 0x80000000 - T
8301 ;; Notice that 0 - 0x80000000 = 0x80000000.
8303 ;; Single bit tests are usually done with zero_extract. On non-SH2A this
8304 ;; will use a tst-negc sequence. On SH2A it will use a bld-addc sequence.
8305 ;; The zeroth bit requires a special pattern, otherwise we get a shlr-addc.
8306 ;; This is a special case of the generic treg_set_expr pattern and thus has
8307 ;; to come first or it will never match.
8308 (define_insn_and_split "*mov_t_msb_neg"
8309 [(set (match_operand:SI 0 "arith_reg_dest")
8310 (plus:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
8312 (const_int 2147483647)))
8313 (clobber (reg:SI T_REG))]
8314 "TARGET_SH1 && can_create_pseudo_p ()"
8317 [(parallel [(set (match_dup 0)
8318 (plus:SI (zero_extract:SI (match_dup 1)
8319 (const_int 1) (const_int 0))
8320 (const_int 2147483647)))
8321 (clobber (reg:SI T_REG))])])
8323 (define_insn_and_split "*mov_t_msb_neg"
8324 [(set (match_operand:SI 0 "arith_reg_dest")
8325 (plus:SI (match_operand 1 "treg_set_expr")
8326 (const_int 2147483647))) ;; 0x7fffffff
8327 (clobber (reg:SI T_REG))]
8328 "TARGET_SH1 && can_create_pseudo_p ()"
8333 if (negt_reg_operand (operands[1], VOIDmode))
8335 emit_insn (gen_negc (operands[0],
8336 force_reg (SImode, GEN_INT (-2147483648LL))));
8340 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8341 if (ti.remove_trailing_nott ())
8342 emit_insn (gen_negc (operands[0],
8343 force_reg (SImode, GEN_INT (-2147483648LL))));
8345 emit_insn (gen_addc (operands[0],
8346 force_reg (SImode, const0_rtx),
8347 force_reg (SImode, GEN_INT (2147483647))));
8351 (define_insn_and_split "*mov_t_msb_neg"
8352 [(set (match_operand:SI 0 "arith_reg_dest")
8353 (if_then_else:SI (match_operand 1 "treg_set_expr")
8354 (match_operand 2 "const_int_operand")
8355 (match_operand 3 "const_int_operand")))
8356 (clobber (reg:SI T_REG))]
8357 "TARGET_SH1 && can_create_pseudo_p ()
8358 && ((INTVAL (operands[2]) == -2147483648LL
8359 && INTVAL (operands[3]) == 2147483647LL)
8360 || (INTVAL (operands[2]) == 2147483647LL
8361 && INTVAL (operands[3]) == -2147483648LL))"
8366 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8368 if (INTVAL (operands[2]) == -2147483648LL)
8370 if (ti.remove_trailing_nott ())
8371 emit_insn (gen_negc (operands[0],
8372 force_reg (SImode, GEN_INT (-2147483648LL))));
8374 emit_insn (gen_addc (operands[0],
8375 force_reg (SImode, const0_rtx),
8376 force_reg (SImode, operands[3])));
8379 else if (INTVAL (operands[2]) == 2147483647LL)
8381 if (ti.remove_trailing_nott ())
8382 emit_insn (gen_addc (operands[0],
8383 force_reg (SImode, const0_rtx),
8384 force_reg (SImode, GEN_INT (2147483647LL))));
8386 emit_insn (gen_negc (operands[0],
8387 force_reg (SImode, GEN_INT (-2147483648LL))));
8394 ;; Store (negated) T bit as all zeros or ones in a reg.
8395 ;; subc Rn,Rn ! Rn = Rn - Rn - T; T = T
8396 ;; not Rn,Rn ! Rn = 0 - Rn
8398 ;; Note the call to sh_split_treg_set_expr may clobber
8399 ;; the T reg. We must express this, even though it's
8400 ;; not immediately obvious this pattern changes the
8402 (define_insn_and_split "mov_neg_si_t"
8403 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8404 (neg:SI (match_operand 1 "treg_set_expr")))
8405 (clobber (reg:SI T_REG))]
8408 gcc_assert (t_reg_operand (operands[1], VOIDmode));
8409 return "subc %0,%0";
8411 "&& !t_reg_operand (operands[1], VOIDmode)"
8414 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8415 emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
8417 if (ti.remove_trailing_nott ())
8418 emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
8422 [(set_attr "type" "arith")])
8424 ;; no-op T bit move which can result from other optimizations.
8425 (define_insn_and_split "*treg_noop_move"
8426 [(set (reg:SI T_REG) (reg:SI T_REG))]
8432 ;; Invert the T bit.
8433 ;; On SH2A we can use the nott insn. On anything else this must be done with
8434 ;; multiple insns like:
8437 ;; This requires an additional pseudo. The SH specific sh_treg_combine RTL
8438 ;; pass will look for this insn. Disallow using it if pseudos can't be
8440 ;; Don't split the nott inside the splitting of a treg_set_expr, or else
8441 ;; surrounding insns might not see and recombine it. Defer the splitting
8442 ;; of the nott until after the whole insn containing the treg_set_expr
8444 (define_insn_and_split "nott"
8445 [(set (reg:SI T_REG)
8446 (xor:SI (match_operand:SI 0 "t_reg_operand") (const_int 1)))]
8447 "TARGET_SH2A || (TARGET_SH1 && can_create_pseudo_p ())"
8449 gcc_assert (TARGET_SH2A);
8452 "!TARGET_SH2A && can_create_pseudo_p () && !sh_in_recog_treg_set_expr ()"
8453 [(set (match_dup 0) (reg:SI T_REG))
8454 (set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))]
8456 operands[0] = gen_reg_rtx (SImode);
8459 ;; Store T bit as MSB in a reg.
8460 ;; T = 0: 0x00000000 -> reg
8461 ;; T = 1: 0x80000000 -> reg
8462 (define_insn_and_split "*movt_msb"
8463 [(set (match_operand:SI 0 "arith_reg_dest")
8464 (mult:SI (match_operand:SI 1 "t_reg_operand")
8465 (const_int -2147483648))) ;; 0xffffffff80000000
8466 (clobber (reg:SI T_REG))]
8470 [(set (match_dup 0) (ashift:SI (reg:SI T_REG) (const_int 31)))])
8472 ;; Store inverted T bit as MSB in a reg.
8473 ;; T = 0: 0x80000000 -> reg
8474 ;; T = 1: 0x00000000 -> reg
8475 ;; On SH2A we can get away without clobbering the T_REG using the movrt insn.
8476 ;; On non SH2A we resort to the following sequence:
8480 ;; The T bit value will be modified during the sequence, but the rotcr insn
8481 ;; will restore its original value.
8482 (define_insn_and_split "*negt_msb"
8483 [(set (match_operand:SI 0 "arith_reg_dest")
8484 (match_operand:SI 1 "negt_reg_shl31_operand"))]
8485 "TARGET_SH1 && can_create_pseudo_p ()"
8490 rtx tmp = gen_reg_rtx (SImode);
8494 emit_insn (gen_movrt (tmp, get_t_reg_rtx ()));
8495 emit_insn (gen_rotrsi3 (operands[0], tmp, const1_rtx));
8499 emit_move_insn (tmp, get_t_reg_rtx ());
8500 emit_insn (gen_cmpeqsi_t (tmp, const0_rtx));
8501 emit_insn (gen_rotcr (operands[0], tmp, get_t_reg_rtx ()));
8506 ;; The *cset_zero patterns convert optimizations such as
8507 ;; "if (test) x = 0;"
8509 ;; "x &= -(test == 0);"
8510 ;; back to conditional branch sequences if zero-displacement branches
8512 ;; FIXME: These patterns can be removed when conditional execution patterns
8513 ;; are implemented, since ifcvt will not perform these optimizations if
8514 ;; conditional execution is supported.
8515 (define_insn "*cset_zero"
8516 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8517 (and:SI (plus:SI (match_operand:SI 1 "t_reg_operand")
8519 (match_operand:SI 2 "arith_reg_operand" "0")))]
8520 "TARGET_SH1 && TARGET_ZDCBRANCH"
8526 [(set_attr "type" "arith") ;; poor approximation
8527 (set_attr "length" "4")])
8529 (define_insn "*cset_zero"
8530 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8531 (if_then_else:SI (match_operand:SI 1 "cbranch_treg_value")
8532 (match_operand:SI 2 "arith_reg_operand" "0")
8534 "TARGET_SH1 && TARGET_ZDCBRANCH"
8536 int tval = sh_eval_treg_value (operands[1]);
8541 else if (tval == false)
8548 [(set_attr "type" "arith") ;; poor approximation
8549 (set_attr "length" "4")])
8551 (define_insn_and_split "*cset_zero"
8552 [(set (match_operand:SI 0 "arith_reg_dest")
8553 (if_then_else:SI (match_operand 1 "treg_set_expr_not_const01")
8554 (match_dup 0) (const_int 0)))
8555 (clobber (reg:SI T_REG))]
8556 "TARGET_SH1 && TARGET_ZDCBRANCH && can_create_pseudo_p ()"
8560 (if_then_else:SI (match_dup 1) (match_dup 0) (const_int 0)))]
8562 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8563 if (ti.remove_trailing_nott ())
8564 operands[1] = gen_rtx_EQ (SImode, get_t_reg_rtx (), const0_rtx);
8566 operands[1] = gen_rtx_EQ (SImode, get_t_reg_rtx (), const1_rtx);
8569 (define_expand "cstoresf4"
8570 [(set (match_operand:SI 0 "register_operand")
8571 (match_operator:SI 1 "ordered_comparison_operator"
8572 [(match_operand:SF 2 "arith_operand")
8573 (match_operand:SF 3 "arith_operand")]))]
8576 if (! currently_expanding_to_rtl)
8579 sh_emit_compare_and_set (operands, SFmode);
8583 (define_expand "cstoredf4"
8584 [(set (match_operand:SI 0 "register_operand")
8585 (match_operator:SI 1 "ordered_comparison_operator"
8586 [(match_operand:DF 2 "arith_operand")
8587 (match_operand:DF 3 "arith_operand")]))]
8590 if (! currently_expanding_to_rtl)
8593 sh_emit_compare_and_set (operands, DFmode);
8597 ;; Sometimes the T bit result of insns is needed in normal registers.
8598 ;; Instead of open coding all the pattern variations, use the treg_set_expr
8599 ;; predicate to match any T bit output insn and split it out after.
8600 ;; This pattern should be below all other related patterns so that it is
8601 ;; considered as a last resort option during matching. This allows
8602 ;; overriding it with special case patterns.
8603 (define_insn_and_split "any_treg_expr_to_reg"
8604 [(set (match_operand:SI 0 "arith_reg_dest")
8605 (match_operand 1 "treg_set_expr"))
8606 (clobber (reg:SI T_REG))]
8607 "TARGET_SH1 && can_create_pseudo_p ()"
8609 "&& !sh_in_recog_treg_set_expr ()"
8613 fprintf (dump_file, "splitting any_treg_expr_to_reg\n");
8615 if (t_reg_operand (operands[1], VOIDmode))
8618 fprintf (dump_file, "t_reg_operand: emitting movt\n");
8619 emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
8622 if (negt_reg_operand (operands[1], VOIDmode))
8625 fprintf (dump_file, "negt_reg_operand: emitting movrt\n");
8626 emit_insn (gen_movnegt (operands[0], get_t_reg_rtx ()));
8630 /* If the split out insns ended with a nott, emit a movrt sequence,
8631 otherwise a normal movt. */
8632 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8634 if (ti.remove_trailing_nott ())
8636 /* Emit this same insn_and_split again. However, the next time it
8637 is split, it will emit the actual negc/movrt insn. This gives
8638 other surrounding insns the chance to see the trailing movrt. */
8641 "any_treg_expr_to_reg: replacing trailing nott with movrt\n");
8642 i = emit_insn (gen_any_treg_expr_to_reg (
8643 operands[0], gen_rtx_XOR (SImode, get_t_reg_rtx (),
8648 i = emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
8650 fprintf (dump_file, "any_treg_expr_to_reg: appending movt\n");
8653 add_reg_note (i, REG_UNUSED, get_t_reg_rtx ());
8657 ;; -------------------------------------------------------------------------
8658 ;; Instructions to cope with inline literal tables
8659 ;; -------------------------------------------------------------------------
8661 ;; 2 byte integer in line
8662 (define_insn "consttable_2"
8663 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
8664 (match_operand 1 "" "")]
8668 if (operands[1] != const0_rtx)
8669 assemble_integer (operands[0], 2, BITS_PER_UNIT * 2, 1);
8672 [(set_attr "length" "2")
8673 (set_attr "in_delay_slot" "no")])
8675 ;; 4 byte integer in line
8676 (define_insn "consttable_4"
8677 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
8678 (match_operand 1 "" "")]
8682 if (operands[1] != const0_rtx)
8684 assemble_integer (operands[0], 4, BITS_PER_UNIT * 4, 1);
8685 mark_symbol_refs_as_used (operands[0]);
8689 [(set_attr "length" "4")
8690 (set_attr "in_delay_slot" "no")])
8692 ;; 8 byte integer in line
8693 (define_insn "consttable_8"
8694 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
8695 (match_operand 1 "" "")]
8699 if (operands[1] != const0_rtx)
8700 assemble_integer (operands[0], 8, BITS_PER_UNIT * 8, 1);
8703 [(set_attr "length" "8")
8704 (set_attr "in_delay_slot" "no")])
8706 ;; 4 byte floating point
8707 (define_insn "consttable_sf"
8708 [(unspec_volatile [(match_operand:SF 0 "general_operand" "=g")
8709 (match_operand 1 "" "")]
8713 if (operands[1] != const0_rtx)
8714 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
8715 SFmode, GET_MODE_ALIGNMENT (SFmode));
8718 [(set_attr "length" "4")
8719 (set_attr "in_delay_slot" "no")])
8721 ;; 8 byte floating point
8722 (define_insn "consttable_df"
8723 [(unspec_volatile [(match_operand:DF 0 "general_operand" "=g")
8724 (match_operand 1 "" "")]
8728 if (operands[1] != const0_rtx)
8729 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
8730 DFmode, GET_MODE_ALIGNMENT (DFmode));
8733 [(set_attr "length" "8")
8734 (set_attr "in_delay_slot" "no")])
8736 ;; Alignment is needed for some constant tables; it may also be added for
8737 ;; Instructions at the start of loops, or after unconditional branches.
8738 ;; ??? We would get more accurate lengths if we did instruction
8739 ;; alignment based on the value of INSN_CURRENT_ADDRESS; the approach used
8740 ;; here is too conservative.
8742 ;; align to a two byte boundary
8743 (define_expand "align_2"
8744 [(unspec_volatile [(const_int 1)] UNSPECV_ALIGN)]
8748 ;; Align to a four byte boundary.
8749 ;; align_4 and align_log are instructions for the starts of loops, or
8750 ;; after unconditional branches, which may take up extra room.
8751 (define_expand "align_4"
8752 [(unspec_volatile [(const_int 2)] UNSPECV_ALIGN)]
8756 ;; Align to a cache line boundary.
8757 (define_insn "align_log"
8758 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPECV_ALIGN)]
8761 [(set_attr "length" "0")
8762 (set_attr "in_delay_slot" "no")])
8764 ;; Emitted at the end of the literal table, used to emit the
8765 ;; 32bit branch labels if needed.
8766 (define_insn "consttable_end"
8767 [(unspec_volatile [(const_int 0)] UNSPECV_CONST_END)]
8770 return output_jump_label_table ();
8772 [(set_attr "in_delay_slot" "no")])
8774 ;; Emitted at the end of the window in the literal table.
8775 (define_insn "consttable_window_end"
8776 [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_WINDOW_END)]
8779 [(set_attr "length" "0")
8780 (set_attr "in_delay_slot" "no")])
8782 ;; -------------------------------------------------------------------------
8783 ;; Minimum / maximum operations.
8784 ;; -------------------------------------------------------------------------
8786 ;; The SH2A clips.b and clips.w insns do a signed min-max function. If smin
8787 ;; and smax standard name patterns are defined, they will be used during
8788 ;; initial expansion and combine will then be able to form the actual min-max
8790 ;; The clips.b and clips.w set the SR.CS bit if the value in the register is
8791 ;; clipped, but there is currently no way of making use of this information.
8792 ;; The only way to read or reset the SR.CS bit is by accessing the SR.
8793 (define_expand "<code>si3"
8794 [(parallel [(set (match_operand:SI 0 "arith_reg_dest")
8795 (SMIN_SMAX:SI (match_operand:SI 1 "arith_reg_operand")
8796 (match_operand 2 "const_int_operand")))
8797 (clobber (reg:SI T_REG))])]
8800 /* Force the comparison value into a register, because greater-than
8801 comparisons can work only on registers. Combine will be able to pick up
8802 the constant value from the REG_EQUAL note when trying to form a min-max
8804 operands[2] = force_reg (SImode, operands[2]);
8808 ;; smax (smin (...))
8810 ;; smin (smax (...))
8811 (define_insn_and_split "*clips"
8812 [(set (match_operand:SI 0 "arith_reg_dest")
8813 (smax:SI (smin:SI (match_operand:SI 1 "arith_reg_operand")
8814 (match_operand 2 "clips_max_const_int"))
8815 (match_operand 3 "clips_min_const_int")))]
8820 (smin:SI (smax:SI (match_dup 1) (match_dup 3)) (match_dup 2)))])
8822 (define_insn "*clips"
8823 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8824 (smin:SI (smax:SI (match_operand:SI 1 "arith_reg_operand" "0")
8825 (match_operand 2 "clips_min_const_int"))
8826 (match_operand 3 "clips_max_const_int")))]
8829 if (INTVAL (operands[3]) == 127)
8830 return "clips.b %0";
8831 else if (INTVAL (operands[3]) == 32767)
8832 return "clips.w %0";
8836 [(set_attr "type" "arith")])
8838 ;; If the expanded smin or smax patterns were not combined, split them into
8839 ;; a compare and branch sequence, because there are no real smin or smax
8841 (define_insn_and_split "*<code>si3"
8842 [(set (match_operand:SI 0 "arith_reg_dest")
8843 (SMIN_SMAX:SI (match_operand:SI 1 "arith_reg_operand")
8844 (match_operand:SI 2 "arith_reg_or_0_or_1_operand")))
8845 (clobber (reg:SI T_REG))]
8846 "TARGET_SH2A && can_create_pseudo_p ()"
8851 rtx_code_label *skip_label = gen_label_rtx ();
8852 emit_move_insn (operands[0], operands[1]);
8854 rtx cmp_val = operands[2];
8855 if (satisfies_constraint_M (cmp_val))
8856 cmp_val = const0_rtx;
8858 emit_insn (gen_cmpgtsi_t (operands[0], cmp_val));
8859 emit_jump_insn (<CODE> == SMIN
8860 ? gen_branch_false (skip_label)
8861 : gen_branch_true (skip_label));
8863 emit_label_after (skip_label, emit_move_insn (operands[0], operands[2]));
8867 ;; The SH2A clipu.b and clipu.w insns can be used to implement a min function
8868 ;; with a register and a constant.
8869 ;; The clipu.b and clipu.w set the SR.CS bit if the value in the register is
8870 ;; clipped, but there is currently no way of making use of this information.
8871 ;; The only way to read or reset the SR.CS bit is by accessing the SR.
8872 (define_expand "uminsi3"
8873 [(set (match_operand:SI 0 "arith_reg_dest")
8874 (umin:SI (match_operand:SI 1 "arith_reg_operand")
8875 (match_operand 2 "const_int_operand")))]
8878 if (INTVAL (operands[2]) == 1)
8880 emit_insn (gen_clipu_one (operands[0], operands[1]));
8883 else if (! clipu_max_const_int (operands[2], VOIDmode))
8887 (define_insn "*clipu"
8888 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8889 (umin:SI (match_operand:SI 1 "arith_reg_operand" "0")
8890 (match_operand 2 "clipu_max_const_int")))]
8893 if (INTVAL (operands[2]) == 255)
8894 return "clipu.b %0";
8895 else if (INTVAL (operands[2]) == 65535)
8896 return "clipu.w %0";
8900 [(set_attr "type" "arith")])
8902 (define_insn_and_split "clipu_one"
8903 [(set (match_operand:SI 0 "arith_reg_dest")
8904 (umin:SI (match_operand:SI 1 "arith_reg_operand") (const_int 1)))
8905 (clobber (reg:SI T_REG))]
8906 "TARGET_SH2A && can_create_pseudo_p ()"
8911 emit_insn (gen_cmpeqsi_t (operands[1], const0_rtx));
8912 emit_insn (gen_movnegt (operands[0], get_t_reg_rtx ()));
8916 ;; -------------------------------------------------------------------------
8918 ;; -------------------------------------------------------------------------
8920 ;; String/block move insn.
8922 (define_expand "cpymemsi"
8923 [(parallel [(set (mem:BLK (match_operand:BLK 0))
8924 (mem:BLK (match_operand:BLK 1)))
8925 (use (match_operand:SI 2 "nonmemory_operand"))
8926 (use (match_operand:SI 3 "immediate_operand"))
8927 (clobber (reg:SI PR_REG))
8928 (clobber (reg:SI R4_REG))
8929 (clobber (reg:SI R5_REG))
8930 (clobber (reg:SI R0_REG))])]
8933 if (expand_block_move (operands))
8939 (define_insn "block_move_real"
8940 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8941 (mem:BLK (reg:SI R5_REG)))
8942 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8943 (use (match_operand 1 "" "Z,Ccl"))
8944 (clobber (reg:SI PR_REG))
8945 (clobber (reg:SI R0_REG))])]
8946 "TARGET_SH1 && ! TARGET_HARD_SH4"
8950 [(set_attr "type" "sfunc")
8951 (set_attr "needs_delay_slot" "yes")])
8953 (define_insn "block_lump_real"
8954 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8955 (mem:BLK (reg:SI R5_REG)))
8956 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8957 (use (match_operand 1 "" "Z,Ccl"))
8958 (use (reg:SI R6_REG))
8959 (clobber (reg:SI PR_REG))
8960 (clobber (reg:SI T_REG))
8961 (clobber (reg:SI R4_REG))
8962 (clobber (reg:SI R5_REG))
8963 (clobber (reg:SI R6_REG))
8964 (clobber (reg:SI R0_REG))])]
8965 "TARGET_SH1 && ! TARGET_HARD_SH4"
8969 [(set_attr "type" "sfunc")
8970 (set_attr "needs_delay_slot" "yes")])
8972 (define_insn "block_move_real_i4"
8973 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8974 (mem:BLK (reg:SI R5_REG)))
8975 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8976 (use (match_operand 1 "" "Z,Ccl"))
8977 (clobber (reg:SI PR_REG))
8978 (clobber (reg:SI R0_REG))
8979 (clobber (reg:SI R1_REG))
8980 (clobber (reg:SI R2_REG))])]
8985 [(set_attr "type" "sfunc")
8986 (set_attr "needs_delay_slot" "yes")])
8988 (define_insn "block_lump_real_i4"
8989 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8990 (mem:BLK (reg:SI R5_REG)))
8991 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8992 (use (match_operand 1 "" "Z,Ccl"))
8993 (use (reg:SI R6_REG))
8994 (clobber (reg:SI PR_REG))
8995 (clobber (reg:SI T_REG))
8996 (clobber (reg:SI R4_REG))
8997 (clobber (reg:SI R5_REG))
8998 (clobber (reg:SI R6_REG))
8999 (clobber (reg:SI R0_REG))
9000 (clobber (reg:SI R1_REG))
9001 (clobber (reg:SI R2_REG))
9002 (clobber (reg:SI R3_REG))])]
9007 [(set_attr "type" "sfunc")
9008 (set_attr "needs_delay_slot" "yes")])
9010 ;; byte compare pattern
9012 ;; !((temp & 0xF000) && (temp & 0x0F00) && (temp & 0x00F0) && (temp & 0x000F))
9013 (define_insn "cmpstr_t"
9014 [(set (reg:SI T_REG)
9019 (xor:SI (match_operand:SI 0 "arith_reg_operand" "r")
9020 (match_operand:SI 1 "arith_reg_operand" "r"))
9021 (const_int 8) (const_int 0))
9022 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
9023 (const_int 8) (const_int 8)))
9024 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
9025 (const_int 8) (const_int 16)))
9026 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
9027 (const_int 8) (const_int 24)))
9031 [(set_attr "type" "mt_group")])
9033 (define_expand "cmpstrsi"
9034 [(set (match_operand:SI 0 "register_operand")
9035 (compare:SI (match_operand:BLK 1 "memory_operand")
9036 (match_operand:BLK 2 "memory_operand")))
9037 (use (match_operand 3 "immediate_operand"))]
9038 "TARGET_SH1 && optimize"
9040 if (! optimize_insn_for_size_p () && sh_expand_cmpstr (operands))
9046 (define_expand "cmpstrnsi"
9047 [(set (match_operand:SI 0 "register_operand")
9048 (compare:SI (match_operand:BLK 1 "memory_operand")
9049 (match_operand:BLK 2 "memory_operand")))
9050 (use (match_operand:SI 3 "nonmemory_operand"))
9051 (use (match_operand:SI 4 "immediate_operand"))]
9052 "TARGET_SH1 && optimize"
9054 if (! optimize_insn_for_size_p () && sh_expand_cmpnstr (operands))
9060 (define_expand "strlensi"
9061 [(set (match_operand:SI 0 "register_operand")
9062 (unspec:SI [(match_operand:BLK 1 "memory_operand")
9063 (match_operand:SI 2 "immediate_operand")
9064 (match_operand:SI 3 "immediate_operand")]
9065 UNSPEC_BUILTIN_STRLEN))]
9066 "TARGET_SH1 && optimize"
9068 if (! optimize_insn_for_size_p () && sh_expand_strlen (operands))
9074 (define_expand "setmemqi"
9075 [(parallel [(set (match_operand:BLK 0 "memory_operand")
9076 (match_operand 2 "const_int_operand"))
9077 (use (match_operand:QI 1 "const_int_operand"))
9078 (use (match_operand:QI 3 "const_int_operand"))])]
9079 "TARGET_SH1 && optimize"
9081 if (optimize_insn_for_size_p ())
9084 sh_expand_setmem (operands);
9089 ;; -------------------------------------------------------------------------
9090 ;; Floating point instructions.
9091 ;; -------------------------------------------------------------------------
9093 ;; FIXME: For now we disallow any memory operands for fpscr loads/stores,
9094 ;; except for post-inc loads and pre-dec stores for push/pop purposes.
9095 ;; This avoids problems with reload. As a consequence, user initiated fpscr
9096 ;; stores to memory will always be ferried through a general register.
9097 ;; User initiated fpscr loads always have to undergo bit masking to preserve
9098 ;; the current fpu mode settings for the compiler generated code. Thus such
9099 ;; fpscr loads will always have to go through general registers anyways.
9100 (define_insn "lds_fpscr"
9101 [(set (reg:SI FPSCR_REG)
9102 (match_operand:SI 0 "fpscr_movsrc_operand" "r,>"))
9103 (set (reg:SI FPSCR_STAT_REG)
9104 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_STAT))
9105 (set (reg:SI FPSCR_MODES_REG)
9106 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
9111 [(set_attr "type" "gp_fpscr,mem_fpscr")])
9113 ;; A move fpscr -> reg schedules like a move mac -> reg. Thus we use mac_gp
9115 (define_insn "sts_fpscr"
9116 [(set (match_operand:SI 0 "fpscr_movdst_operand" "=r,<")
9118 (use (reg:SI FPSCR_STAT_REG))
9119 (use (reg:SI FPSCR_MODES_REG))]
9124 [(set_attr "type" "mac_gp,fstore")])
9126 (define_expand "set_fpscr"
9127 [(parallel [(set (reg:SI FPSCR_REG)
9128 (match_operand:SI 0 "general_operand"))
9129 (set (reg:SI FPSCR_STAT_REG)
9130 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))])]
9133 /* We have to mask out the FR, SZ and PR bits. To do that, we need to
9134 get the current FPSCR value first.
9135 (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) */
9137 rtx mask = force_reg (SImode, GEN_INT (FPSCR_FR | FPSCR_SZ | FPSCR_PR));
9139 rtx a = force_reg (SImode, operands[0]);
9141 rtx b = gen_reg_rtx (SImode);
9142 emit_insn (gen_sts_fpscr (b));
9144 rtx a_xor_b = gen_reg_rtx (SImode);
9145 emit_insn (gen_xorsi3 (a_xor_b, a, b));
9147 rtx a_xor_b_and_mask = gen_reg_rtx (SImode);
9148 emit_insn (gen_andsi3 (a_xor_b_and_mask, a_xor_b, mask));
9150 rtx r = gen_reg_rtx (SImode);
9151 emit_insn (gen_xorsi3 (r, a_xor_b_and_mask, a));
9152 emit_insn (gen_lds_fpscr (r));
9157 ;; ??? This uses the fp unit, but has no type indicating that.
9158 ;; If we did that, this would either give a bogus latency or introduce
9159 ;; a bogus FIFO constraint.
9160 ;; Since this insn is currently only used for prologues/epilogues,
9161 ;; it is probably best to claim no function unit, which matches the
9163 (define_insn "toggle_sz"
9164 [(set (reg:SI FPSCR_REG)
9165 (xor:SI (reg:SI FPSCR_REG) (const_int FPSCR_SZ)))
9166 (set (reg:SI FPSCR_MODES_REG)
9167 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
9170 [(set_attr "type" "fpscr_toggle") (set_attr "fp_set" "unknown")])
9172 ;; Toggle FPU precision PR mode.
9174 (define_insn "toggle_pr"
9175 [(set (reg:SI FPSCR_REG)
9176 (xor:SI (reg:SI FPSCR_REG) (const_int FPSCR_PR)))
9177 (set (reg:SI FPSCR_MODES_REG)
9178 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
9179 "TARGET_SH4A_FP || TARGET_FPU_SH4_300"
9181 [(set_attr "type" "fpscr_toggle")])
9183 (define_expand "addsf3"
9184 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9185 (plus:SF (match_operand:SF 1 "fp_arith_reg_operand")
9186 (match_operand:SF 2 "fp_arith_reg_operand")))]
9189 emit_insn (gen_addsf3_i (operands[0], operands[1], operands[2]));
9193 (define_insn "addsf3_i"
9194 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9195 (plus:SF (match_operand:SF 1 "fp_arith_reg_operand" "%0")
9196 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9197 (clobber (reg:SI FPSCR_STAT_REG))
9198 (use (reg:SI FPSCR_MODES_REG))]
9201 [(set_attr "type" "fp")
9202 (set_attr "fp_mode" "single")])
9204 (define_expand "subsf3"
9205 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9206 (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "")
9207 (match_operand:SF 2 "fp_arith_reg_operand" "")))]
9210 emit_insn (gen_subsf3_i (operands[0], operands[1], operands[2]));
9214 (define_insn "subsf3_i"
9215 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9216 (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
9217 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9218 (clobber (reg:SI FPSCR_STAT_REG))
9219 (use (reg:SI FPSCR_MODES_REG))]
9222 [(set_attr "type" "fp")
9223 (set_attr "fp_mode" "single")])
9225 (define_expand "mulsf3"
9226 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9227 (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "")
9228 (match_operand:SF 2 "fp_arith_reg_operand" "")))]
9231 emit_insn (gen_mulsf3_i (operands[0], operands[1], operands[2]));
9235 (define_insn "mulsf3_i"
9236 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9237 (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%0")
9238 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9239 (clobber (reg:SI FPSCR_STAT_REG))
9240 (use (reg:SI FPSCR_MODES_REG))]
9243 [(set_attr "type" "fp")
9244 (set_attr "fp_mode" "single")])
9246 ;; FMA (fused multiply-add) patterns
9247 (define_expand "fmasf4"
9248 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9249 (fma:SF (match_operand:SF 1 "fp_arith_reg_operand")
9250 (match_operand:SF 2 "fp_arith_reg_operand")
9251 (match_operand:SF 3 "fp_arith_reg_operand")))]
9254 emit_insn (gen_fmasf4_i (operands[0], operands[1], operands[2], operands[3]));
9258 (define_insn "fmasf4_i"
9259 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9260 (fma:SF (match_operand:SF 1 "fp_arith_reg_operand" "w")
9261 (match_operand:SF 2 "fp_arith_reg_operand" "f")
9262 (match_operand:SF 3 "fp_arith_reg_operand" "0")))
9263 (clobber (reg:SI FPSCR_STAT_REG))
9264 (use (reg:SI FPSCR_MODES_REG))]
9267 [(set_attr "type" "fp")
9268 (set_attr "fp_mode" "single")])
9270 ;; For some cases such as 'a * b + a' the FMA pattern is not generated by
9271 ;; previous transformations. If FMA is generally allowed, let the combine
9273 (define_insn_and_split "*fmasf4"
9274 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9275 (plus:SF (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%w")
9276 (match_operand:SF 2 "fp_arith_reg_operand" "f"))
9277 (match_operand:SF 3 "arith_reg_operand" "0")))
9278 (clobber (reg:SI FPSCR_STAT_REG))
9279 (use (reg:SI FPSCR_MODES_REG))]
9280 "TARGET_SH2E && flag_fp_contract_mode == FP_CONTRACT_FAST"
9282 "&& can_create_pseudo_p ()"
9283 [(parallel [(set (match_dup 0)
9284 (fma:SF (match_dup 1) (match_dup 2) (match_dup 3)))
9285 (clobber (reg:SI FPSCR_STAT_REG))
9286 (use (reg:SI FPSCR_MODES_REG))])]
9288 /* Change 'b * a + a' into 'a * b + a'.
9289 This is better for register allocation. */
9290 if (REGNO (operands[2]) == REGNO (operands[3]))
9291 std::swap (operands[1], operands[2]);
9293 [(set_attr "type" "fp")
9294 (set_attr "fp_mode" "single")])
9296 (define_expand "divsf3"
9297 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9298 (div:SF (match_operand:SF 1 "fp_arith_reg_operand")
9299 (match_operand:SF 2 "fp_arith_reg_operand")))]
9302 emit_insn (gen_divsf3_i (operands[0], operands[1], operands[2]));
9306 (define_insn "divsf3_i"
9307 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9308 (div:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
9309 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9310 (clobber (reg:SI FPSCR_STAT_REG))
9311 (use (reg:SI FPSCR_MODES_REG))]
9314 [(set_attr "type" "fdiv")
9315 (set_attr "fp_mode" "single")])
9317 (define_expand "floatsisf2"
9318 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9319 (float:SF (match_operand:SI 1 "fpul_operand" "")))]
9322 emit_insn (gen_floatsisf2_i4 (operands[0], operands[1]));
9326 (define_insn "floatsisf2_i4"
9327 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9328 (float:SF (match_operand:SI 1 "fpul_operand" "y")))
9329 (clobber (reg:SI FPSCR_STAT_REG))
9330 (use (reg:SI FPSCR_MODES_REG))]
9333 [(set_attr "type" "fp")
9334 (set_attr "fp_mode" "single")])
9336 (define_expand "fix_truncsfsi2"
9337 [(set (match_operand:SI 0 "fpul_operand")
9338 (fix:SI (match_operand:SF 1 "fp_arith_reg_operand")))]
9341 emit_insn (gen_fix_truncsfsi2_i4 (operands[0], operands[1]));
9345 (define_insn "fix_truncsfsi2_i4"
9346 [(set (match_operand:SI 0 "fpul_operand" "=y")
9347 (fix:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")))
9348 (clobber (reg:SI FPSCR_STAT_REG))
9349 (use (reg:SI FPSCR_MODES_REG))]
9352 [(set_attr "type" "ftrc_s")
9353 (set_attr "fp_mode" "single")])
9355 (define_insn "cmpgtsf_t"
9356 [(set (reg:SI T_REG)
9357 (gt:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
9358 (match_operand:SF 1 "fp_arith_reg_operand" "f")))
9359 (clobber (reg:SI FPSCR_STAT_REG))
9360 (use (reg:SI FPSCR_MODES_REG))]
9361 "TARGET_SH2E || TARGET_SH4 || TARGET_SH2A_SINGLE"
9363 [(set_attr "type" "fp_cmp")
9364 (set_attr "fp_mode" "single")])
9366 (define_insn "cmpeqsf_t"
9367 [(set (reg:SI T_REG)
9368 (eq:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
9369 (match_operand:SF 1 "fp_arith_reg_operand" "f")))
9370 (clobber (reg:SI FPSCR_STAT_REG))
9371 (use (reg:SI FPSCR_MODES_REG))]
9372 "TARGET_SH2E || TARGET_SH4 || TARGET_SH2A_SINGLE"
9374 [(set_attr "type" "fp_cmp")
9375 (set_attr "fp_mode" "single")])
9377 (define_insn "ieee_ccmpeqsf_t"
9378 [(set (reg:SI T_REG)
9379 (ior:SI (reg:SI T_REG)
9380 (eq:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
9381 (match_operand:SF 1 "fp_arith_reg_operand" "f"))))
9382 (clobber (reg:SI FPSCR_STAT_REG))
9383 (use (reg:SI FPSCR_MODES_REG))]
9384 "TARGET_IEEE && TARGET_SH2E"
9386 return output_ieee_ccmpeq (insn, operands);
9388 [(set_attr "length" "4")
9389 (set_attr "fp_mode" "single")])
9391 (define_expand "cbranchsf4"
9393 (if_then_else (match_operator 0 "ordered_comparison_operator"
9394 [(match_operand:SF 1 "arith_operand" "")
9395 (match_operand:SF 2 "arith_operand" "")])
9396 (match_operand 3 "" "")
9400 sh_emit_compare_and_branch (operands, SFmode);
9404 (define_expand "negsf2"
9405 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9406 (neg:SF (match_operand:SF 1 "fp_arith_reg_operand")))]
9409 if (TARGET_FPU_SH4_300)
9410 emit_insn (gen_negsf2_fpscr (operands[0], operands[1]));
9412 emit_insn (gen_negsf2_no_fpscr (operands[0], operands[1]));
9416 (define_insn "negsf2_no_fpscr"
9417 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9418 (neg:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))]
9419 "TARGET_FPU_ANY && !TARGET_FPU_SH4_300"
9421 [(set_attr "type" "fmove")])
9423 (define_insn "negsf2_fpscr"
9424 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9425 (neg:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))
9426 (use (reg:SI FPSCR_MODES_REG))]
9427 "TARGET_FPU_SH4_300"
9429 [(set_attr "type" "fmove")
9430 (set_attr "fp_mode" "single")])
9432 (define_expand "sqrtsf2"
9433 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9434 (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "")))]
9437 emit_insn (gen_sqrtsf2_i (operands[0], operands[1]));
9441 (define_insn "sqrtsf2_i"
9442 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9443 (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))
9444 (clobber (reg:SI FPSCR_STAT_REG))
9445 (use (reg:SI FPSCR_MODES_REG))]
9448 [(set_attr "type" "fdiv")
9449 (set_attr "fp_mode" "single")])
9451 (define_insn "rsqrtsf2"
9452 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9453 (unspec:SF [(match_operand:SF 1 "fp_arith_reg_operand" "0")]
9455 (clobber (reg:SI FPSCR_STAT_REG))
9456 (use (reg:SI FPSCR_MODES_REG))]
9457 "TARGET_FPU_ANY && TARGET_FSRRA"
9459 [(set_attr "type" "fsrra")
9460 (set_attr "fp_mode" "single")])
9462 ;; When the sincos pattern is defined, the builtin functions sin and cos
9463 ;; will be expanded to the sincos pattern and one of the output values will
9465 (define_expand "sincossf3"
9466 [(set (match_operand:SF 0 "nonimmediate_operand")
9467 (unspec:SF [(match_operand:SF 2 "fp_arith_reg_operand")] UNSPEC_FCOSA))
9468 (set (match_operand:SF 1 "nonimmediate_operand")
9469 (unspec:SF [(match_dup 2)] UNSPEC_FSINA))]
9470 "TARGET_FPU_ANY && TARGET_FSCA"
9472 rtx scaled = gen_reg_rtx (SFmode);
9473 rtx truncated = gen_reg_rtx (SImode);
9474 rtx fsca = gen_reg_rtx (V2SFmode);
9475 rtx scale_reg = force_reg (SFmode, sh_fsca_sf2int ());
9477 emit_insn (gen_mulsf3 (scaled, operands[2], scale_reg));
9478 emit_insn (gen_fix_truncsfsi2 (truncated, scaled));
9479 emit_insn (gen_fsca (fsca, truncated, sh_fsca_int2sf ()));
9481 emit_move_insn (operands[0], gen_rtx_SUBREG (SFmode, fsca, 4));
9482 emit_move_insn (operands[1], gen_rtx_SUBREG (SFmode, fsca, 0));
9486 (define_insn_and_split "fsca"
9487 [(set (match_operand:V2SF 0 "fp_arith_reg_operand" "=f")
9489 (unspec:SF [(mult:SF
9490 (float:SF (match_operand:SI 1 "fpul_fsca_operand" "y"))
9491 (match_operand:SF 2 "fsca_scale_factor" "i"))
9493 (unspec:SF [(mult:SF (float:SF (match_dup 1)) (match_dup 2))
9495 (clobber (reg:SI FPSCR_STAT_REG))
9496 (use (reg:SI FPSCR_MODES_REG))]
9497 "TARGET_FPU_ANY && TARGET_FSCA"
9499 "&& !fpul_operand (operands[1], SImode)"
9502 /* If operands[1] is something like (fix:SF (float:SF (reg:SI))) reduce it
9503 to a simple reg, otherwise reload will have trouble reloading the
9504 pseudo into fpul. */
9505 rtx x = XEXP (operands[1], 0);
9506 while (x != NULL_RTX && !fpul_operand (x, SImode))
9508 gcc_assert (GET_CODE (x) == FIX || GET_CODE (x) == FLOAT);
9511 gcc_assert (x != NULL_RTX && fpul_operand (x, SImode));
9512 emit_insn (gen_fsca (operands[0], x, operands[2]));
9515 [(set_attr "type" "fsca")
9516 (set_attr "fp_mode" "single")])
9518 (define_expand "abssf2"
9519 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9520 (abs:SF (match_operand:SF 1 "fp_arith_reg_operand")))]
9523 if (TARGET_FPU_SH4_300)
9524 emit_insn (gen_abssf2_fpscr (operands[0], operands[1]));
9526 emit_insn (gen_abssf2_no_fpscr (operands[0], operands[1]));
9530 (define_insn "abssf2_no_fpscr"
9531 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9532 (abs:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))]
9533 "TARGET_FPU_ANY && !TARGET_FPU_SH4_300"
9535 [(set_attr "type" "fmove")])
9537 (define_insn "abssf2_fpscr"
9538 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9539 (abs:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))
9540 (use (reg:SI FPSCR_MODES_REG))]
9541 "TARGET_FPU_SH4_300"
9543 [(set_attr "type" "fmove")
9544 (set_attr "fp_mode" "single")])
9546 (define_expand "adddf3"
9547 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9548 (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9549 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9552 emit_insn (gen_adddf3_i (operands[0], operands[1], operands[2]));
9556 (define_insn "adddf3_i"
9557 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9558 (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "%0")
9559 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9560 (clobber (reg:SI FPSCR_STAT_REG))
9561 (use (reg:SI FPSCR_MODES_REG))]
9564 [(set_attr "type" "dfp_arith")
9565 (set_attr "fp_mode" "double")])
9567 (define_expand "subdf3"
9568 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9569 (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9570 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9573 emit_insn (gen_subdf3_i (operands[0], operands[1], operands[2]));
9577 (define_insn "subdf3_i"
9578 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9579 (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")
9580 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9581 (clobber (reg:SI FPSCR_STAT_REG))
9582 (use (reg:SI FPSCR_MODES_REG))]
9585 [(set_attr "type" "dfp_arith")
9586 (set_attr "fp_mode" "double")])
9588 (define_expand "muldf3"
9589 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9590 (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9591 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9594 emit_insn (gen_muldf3_i (operands[0], operands[1], operands[2]));
9598 (define_insn "muldf3_i"
9599 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9600 (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "%0")
9601 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9602 (clobber (reg:SI FPSCR_STAT_REG))
9603 (use (reg:SI FPSCR_MODES_REG))]
9606 [(set_attr "type" "dfp_mul")
9607 (set_attr "fp_mode" "double")])
9609 (define_expand "divdf3"
9610 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9611 (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9612 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9615 emit_insn (gen_divdf3_i (operands[0], operands[1], operands[2]));
9619 (define_insn "divdf3_i"
9620 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9621 (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")
9622 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9623 (clobber (reg:SI FPSCR_STAT_REG))
9624 (use (reg:SI FPSCR_MODES_REG))]
9627 [(set_attr "type" "dfdiv")
9628 (set_attr "fp_mode" "double")])
9630 (define_expand "floatsidf2"
9631 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9632 (float:DF (match_operand:SI 1 "fpul_operand" "")))]
9635 emit_insn (gen_floatsidf2_i (operands[0], operands[1]));
9639 (define_insn "floatsidf2_i"
9640 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9641 (float:DF (match_operand:SI 1 "fpul_operand" "y")))
9642 (clobber (reg:SI FPSCR_STAT_REG))
9643 (use (reg:SI FPSCR_MODES_REG))]
9646 [(set_attr "type" "dfp_conv")
9647 (set_attr "fp_mode" "double")])
9649 (define_expand "fix_truncdfsi2"
9650 [(set (match_operand:SI 0 "fpul_operand" "")
9651 (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "")))]
9654 emit_insn (gen_fix_truncdfsi2_i (operands[0], operands[1]));
9658 (define_insn "fix_truncdfsi2_i"
9659 [(set (match_operand:SI 0 "fpul_operand" "=y")
9660 (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9661 (clobber (reg:SI FPSCR_STAT_REG))
9662 (use (reg:SI FPSCR_MODES_REG))]
9665 [(set_attr "type" "dfp_conv")
9666 (set_attr "dfp_comp" "no")
9667 (set_attr "fp_mode" "double")])
9669 (define_insn "cmpgtdf_t"
9670 [(set (reg:SI T_REG)
9671 (gt:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
9672 (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9673 (clobber (reg:SI FPSCR_STAT_REG))
9674 (use (reg:SI FPSCR_MODES_REG))]
9677 [(set_attr "type" "dfp_cmp")
9678 (set_attr "fp_mode" "double")])
9680 (define_insn "cmpeqdf_t"
9681 [(set (reg:SI T_REG)
9682 (eq:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
9683 (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9684 (clobber (reg:SI FPSCR_STAT_REG))
9685 (use (reg:SI FPSCR_MODES_REG))]
9688 [(set_attr "type" "dfp_cmp")
9689 (set_attr "fp_mode" "double")])
9691 (define_insn "*ieee_ccmpeqdf_t"
9692 [(set (reg:SI T_REG)
9693 (ior:SI (reg:SI T_REG)
9694 (eq:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
9695 (match_operand:DF 1 "fp_arith_reg_operand" "f"))))
9696 (clobber (reg:SI FPSCR_STAT_REG))
9697 (use (reg:SI FPSCR_MODES_REG))]
9698 "TARGET_IEEE && TARGET_FPU_DOUBLE"
9700 return output_ieee_ccmpeq (insn, operands);
9702 [(set_attr "length" "4")
9703 (set_attr "fp_mode" "double")])
9705 (define_expand "cbranchdf4"
9707 (if_then_else (match_operator 0 "ordered_comparison_operator"
9708 [(match_operand:DF 1 "arith_operand" "")
9709 (match_operand:DF 2 "arith_operand" "")])
9710 (match_operand 3 "" "")
9714 sh_emit_compare_and_branch (operands, DFmode);
9718 (define_expand "negdf2"
9719 [(set (match_operand:DF 0 "fp_arith_reg_operand")
9720 (neg:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
9723 if (TARGET_FPU_SH4_300)
9724 emit_insn (gen_negdf2_fpscr (operands[0], operands[1]));
9726 emit_insn (gen_negdf2_no_fpscr (operands[0], operands[1]));
9730 (define_insn "negdf2_fpscr"
9731 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9732 (neg:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))
9733 (use (reg:SI FPSCR_MODES_REG))]
9734 "TARGET_FPU_SH4_300"
9736 [(set_attr "type" "fmove")
9737 (set_attr "fp_mode" "double")])
9739 (define_insn "negdf2_no_fpscr"
9740 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9741 (neg:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))]
9742 "TARGET_FPU_DOUBLE && !TARGET_FPU_SH4_300"
9744 [(set_attr "type" "fmove")])
9746 (define_expand "sqrtdf2"
9747 [(set (match_operand:DF 0 "fp_arith_reg_operand")
9748 (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
9751 emit_insn (gen_sqrtdf2_i (operands[0], operands[1]));
9755 (define_insn "sqrtdf2_i"
9756 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9757 (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))
9758 (clobber (reg:SI FPSCR_STAT_REG))
9759 (use (reg:SI FPSCR_MODES_REG))]
9762 [(set_attr "type" "dfdiv")
9763 (set_attr "fp_mode" "double")])
9765 (define_expand "absdf2"
9766 [(set (match_operand:DF 0 "fp_arith_reg_operand")
9767 (abs:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
9770 if (TARGET_FPU_SH4_300)
9771 emit_insn (gen_absdf2_fpscr (operands[0], operands[1]));
9773 emit_insn (gen_absdf2_no_fpscr (operands[0], operands[1]));
9777 (define_insn "absdf2_no_fpscr"
9778 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9779 (abs:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))]
9780 "TARGET_FPU_DOUBLE && !TARGET_FPU_SH4_300"
9782 [(set_attr "type" "fmove")])
9784 (define_insn "absdf2_fpscr"
9785 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9786 (abs:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))
9787 (use (reg:SI FPSCR_MODES_REG))]
9788 "TARGET_FPU_SH4_300"
9790 [(set_attr "type" "fmove")
9791 (set_attr "fp_mode" "double")])
9793 (define_expand "extendsfdf2"
9794 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9795 (float_extend:DF (match_operand:SF 1 "fpul_operand" "")))]
9798 emit_insn (gen_extendsfdf2_i4 (operands[0], operands[1]));
9802 (define_insn "extendsfdf2_i4"
9803 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9804 (float_extend:DF (match_operand:SF 1 "fpul_operand" "y")))
9805 (clobber (reg:SI FPSCR_STAT_REG))
9806 (use (reg:SI FPSCR_MODES_REG))]
9809 [(set_attr "type" "fp")
9810 (set_attr "fp_mode" "double")])
9812 (define_expand "truncdfsf2"
9813 [(set (match_operand:SF 0 "fpul_operand" "")
9814 (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "")))]
9817 emit_insn (gen_truncdfsf2_i4 (operands[0], operands[1]));
9821 (define_insn "truncdfsf2_i4"
9822 [(set (match_operand:SF 0 "fpul_operand" "=y")
9823 (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9824 (clobber (reg:SI FPSCR_STAT_REG))
9825 (use (reg:SI FPSCR_MODES_REG))]
9828 [(set_attr "type" "fp")
9829 (set_attr "fp_mode" "double")])
9831 ;; -------------------------------------------------------------------------
9832 ;; Bit field extract patterns.
9833 ;; -------------------------------------------------------------------------
9835 ;; These give better code for packed bitfields, because they allow
9836 ;; auto-increment addresses to be generated.
9838 (define_expand "insv"
9839 [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "")
9840 (match_operand:SI 1 "immediate_operand" "")
9841 (match_operand:SI 2 "immediate_operand" ""))
9842 (match_operand:SI 3 "general_operand" ""))]
9843 "TARGET_SH1 && TARGET_BIG_ENDIAN"
9845 rtx addr_target, orig_address, shift_reg, qi_val;
9846 HOST_WIDE_INT bitsize, size, v = 0;
9847 rtx x = operands[3];
9849 if (TARGET_SH2A && TARGET_BITOPS
9850 && (satisfies_constraint_Sbw (operands[0])
9851 || satisfies_constraint_Sbv (operands[0]))
9852 && satisfies_constraint_M (operands[1])
9853 && satisfies_constraint_K03 (operands[2]))
9855 if (satisfies_constraint_N (operands[3]))
9857 emit_insn (gen_bclr_m2a (operands[0], operands[2]));
9860 else if (satisfies_constraint_M (operands[3]))
9862 emit_insn (gen_bset_m2a (operands[0], operands[2]));
9865 else if ((REG_P (operands[3]) && REGNO (operands[3]) == T_REG)
9866 && satisfies_constraint_M (operands[1]))
9868 emit_insn (gen_bst_m2a (operands[0], operands[2]));
9871 else if (REG_P (operands[3])
9872 && satisfies_constraint_M (operands[1]))
9874 emit_insn (gen_bldsi_reg (operands[3], const0_rtx));
9875 emit_insn (gen_bst_m2a (operands[0], operands[2]));
9879 /* ??? expmed doesn't care for non-register predicates. */
9880 if (! memory_operand (operands[0], VOIDmode)
9881 || ! immediate_operand (operands[1], VOIDmode)
9882 || ! immediate_operand (operands[2], VOIDmode)
9883 || ! general_operand (x, VOIDmode))
9885 /* If this isn't a 16 / 24 / 32 bit field, or if
9886 it doesn't start on a byte boundary, then fail. */
9887 bitsize = INTVAL (operands[1]);
9888 if (bitsize < 16 || bitsize > 32 || bitsize % 8 != 0
9889 || (INTVAL (operands[2]) % 8) != 0)
9893 orig_address = XEXP (operands[0], 0);
9894 shift_reg = gen_reg_rtx (SImode);
9895 if (CONST_INT_P (x))
9898 qi_val = force_reg (QImode, GEN_INT (trunc_int_for_mode (v, QImode)));
9902 emit_insn (gen_movsi (shift_reg, operands[3]));
9903 qi_val = gen_rtx_SUBREG (QImode, shift_reg, 3);
9905 addr_target = copy_addr_to_reg (plus_constant (Pmode,
9906 orig_address, size - 1));
9908 operands[0] = replace_equiv_address (operands[0], addr_target);
9909 emit_insn (gen_movqi (operands[0], qi_val));
9913 if (CONST_INT_P (x))
9915 = force_reg (QImode, GEN_INT (trunc_int_for_mode (v >>= 8, QImode)));
9918 emit_insn (gen_lshrsi3_k (shift_reg, shift_reg, GEN_INT (8)));
9919 qi_val = gen_rtx_SUBREG (QImode, shift_reg, 3);
9921 emit_insn (gen_addsi3 (addr_target, addr_target, constm1_rtx));
9922 emit_insn (gen_movqi (operands[0], qi_val));
9928 (define_insn "movua"
9929 [(set (match_operand:SI 0 "register_operand" "=z")
9930 (unspec:SI [(match_operand:BLK 1 "unaligned_load_operand" "Sua>")]
9934 [(set_attr "type" "movua")])
9936 ;; We shouldn't need this, but cse replaces increments with references
9937 ;; to other regs before flow has a chance to create post_inc
9938 ;; addressing modes, and only postreload's cse_move2add brings the
9939 ;; increments back to a usable form.
9941 [(set (match_operand:SI 0 "register_operand" "")
9942 (sign_extract:SI (mem:SI (match_operand:SI 1 "register_operand" ""))
9943 (const_int 32) (const_int 0)))
9944 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
9945 "TARGET_SH4A && REGNO (operands[0]) != REGNO (operands[1])"
9946 [(set (match_operand:SI 0 "register_operand" "")
9947 (sign_extract:SI (mem:SI (post_inc:SI
9948 (match_operand:SI 1 "register_operand" "")))
9949 (const_int 32) (const_int 0)))]
9952 (define_expand "extv"
9953 [(set (match_operand:SI 0 "register_operand" "")
9954 (sign_extract:SI (match_operand:QI 1 "unaligned_load_operand" "")
9955 (match_operand 2 "const_int_operand" "")
9956 (match_operand 3 "const_int_operand" "")))]
9957 "TARGET_SH4A || TARGET_SH2A"
9959 if (TARGET_SH2A && TARGET_BITOPS
9960 && (satisfies_constraint_Sbw (operands[1])
9961 || satisfies_constraint_Sbv (operands[1]))
9962 && satisfies_constraint_M (operands[2])
9963 && satisfies_constraint_K03 (operands[3]))
9965 emit_insn (gen_bldsign_m2a (operands[1], operands[3]));
9966 if (REGNO (operands[0]) != T_REG)
9967 emit_insn (gen_movsi (operands[0], gen_rtx_REG (SImode, T_REG)));
9971 && INTVAL (operands[2]) == 32
9972 && INTVAL (operands[3]) == 0
9973 && MEM_P (operands[1]) && MEM_ALIGN (operands[1]) < 32)
9975 rtx src = adjust_address (operands[1], BLKmode, 0);
9976 set_mem_size (src, 4);
9977 emit_insn (gen_movua (operands[0], src));
9984 (define_expand "extzv"
9985 [(set (match_operand:SI 0 "register_operand" "")
9986 (zero_extract:SI (match_operand:QI 1 "unaligned_load_operand" "")
9987 (match_operand 2 "const_int_operand" "")
9988 (match_operand 3 "const_int_operand" "")))]
9989 "TARGET_SH4A || TARGET_SH2A"
9991 if (TARGET_SH2A && TARGET_BITOPS
9992 && (satisfies_constraint_Sbw (operands[1])
9993 || satisfies_constraint_Sbv (operands[1]))
9994 && satisfies_constraint_M (operands[2])
9995 && satisfies_constraint_K03 (operands[3]))
9997 emit_insn (gen_bld_m2a (operands[1], operands[3]));
9998 if (REGNO (operands[0]) != T_REG)
9999 emit_insn (gen_movsi (operands[0], gen_rtx_REG (SImode, T_REG)));
10003 && INTVAL (operands[2]) == 32
10004 && INTVAL (operands[3]) == 0
10005 && MEM_P (operands[1]) && MEM_ALIGN (operands[1]) < 32)
10007 rtx src = adjust_address (operands[1], BLKmode, 0);
10008 set_mem_size (src, 4);
10009 emit_insn (gen_movua (operands[0], src));
10016 ;; -------------------------------------------------------------------------
10017 ;; Extract negated single bit and zero extend it.
10018 ;; Generally we don't care about the exact xor const_int value, as long
10019 ;; as it contains the extracted bit. For simplicity, the pattern variations
10020 ;; that convert everything into the primary '*neg_zero_extract_0' pattern use
10021 ;; a xor const_int -1 value.
10023 (define_insn_and_split "*neg_zero_extract_0"
10024 [(set (reg:SI T_REG)
10025 (zero_extract:SI (xor:QIHISI (match_operand:QIHISI 0 "arith_reg_operand")
10026 (match_operand 1 "const_int_operand"))
10028 (match_operand 2 "const_int_operand")))]
10029 "TARGET_SH1 && can_create_pseudo_p ()
10030 && INTVAL (operands[1]) & (1LL << INTVAL (operands[2]))"
10033 [(set (reg:SI T_REG) (eq:SI (and:SI (match_dup 0) (match_dup 2))
10036 if (INTVAL (operands[2]) == 31 && <MODE>mode == SImode)
10038 /* Use cmp/pz to extract bit 31 into the T bit. */
10039 emit_insn (gen_cmpgesi_t (operands[0], const0_rtx));
10043 operands[2] = GEN_INT ((1 << INTVAL (operands[2])));
10044 if (GET_MODE (operands[0]) != SImode)
10045 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
10048 (define_insn_and_split "*neg_zero_extract_1"
10049 [(set (reg:SI T_REG)
10050 (and:SI (not:SI (match_operand:SI 0 "arith_reg_operand"))
10055 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10056 (const_int 1) (const_int 0)))])
10058 ;; x & (1 << n) == 0: 0x00000000 + 1 = 1
10059 ;; x & (1 << n) != 0: 0xFFFFFFFF + 1 = 0
10060 (define_insn_and_split "*neg_zero_extract_2"
10061 [(set (reg:SI T_REG)
10062 (plus:SI (sign_extract:SI (match_operand:QIHISI 0 "arith_reg_operand")
10064 (match_operand 1 "const_int_operand"))
10066 "TARGET_SH1 && can_create_pseudo_p ()"
10069 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10070 (const_int 1) (match_dup 1)))])
10072 ;; (signed)x >> 31 + 1 = (x >= 0) ^ 1
10073 (define_insn_and_split "*neg_zero_extract_3"
10074 [(set (reg:SI T_REG)
10075 (plus:SI (ashiftrt:SI (match_operand:SI 0 "arith_reg_operand")
10078 "TARGET_SH1 && can_create_pseudo_p ()"
10081 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10082 (const_int 1) (const_int 31)))])
10084 ;; This is required for some bit patterns of DImode subregs.
10085 ;; It looks like combine gets confused by the DImode right shift and fails
10086 ;; to simplify things.
10087 (define_insn_and_split "*neg_zero_extract_4"
10088 [(set (reg:SI T_REG)
10090 (lshiftrt:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
10091 (match_operand 1 "const_int_operand"))
10092 (match_operand 2 "const_int_operand"))
10093 (not:SI (ashift:SI (match_operand:SI 3 "arith_reg_operand")
10094 (match_operand 4 "const_int_operand"))))
10096 "TARGET_SH1 && can_create_pseudo_p ()
10097 && INTVAL (operands[4]) > 0
10098 && INTVAL (operands[1]) & (1LL << INTVAL (operands[2]))"
10101 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
10102 (const_int 1) (match_dup 2)))])
10104 ;; Same thing, but when we use a PLUS rather than IOR/XOR for the rotation
10105 ;; which causes things to simplify somewhat differently.
10106 (define_insn_and_split "*neg_zero_extract_4b"
10107 [(set (reg:SI T_REG)
10108 (and:SI (not:SI (plus:SI
10109 (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
10110 (match_operand 1 "const_int_operand"))
10111 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
10112 (match_operand 3 "const_int_operand"))))
10114 "TARGET_SH1 && can_create_pseudo_p ()
10115 && INTVAL (operands[3]) > 0
10116 && INTVAL (operands[1]) + INTVAL (operands[3]) == 32"
10119 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (match_dup 4))
10120 (const_int 1) (match_dup 1)))]
10121 { operands[4] = GEN_INT (1 << INTVAL (operands[1])); })
10123 (define_insn_and_split "*neg_zero_extract_5"
10124 [(set (reg:SI T_REG)
10125 (and:SI (not:SI (subreg:SI
10126 (lshiftrt:DI (match_operand:DI 0 "arith_reg_operand")
10127 (match_operand 1 "const_int_operand"))
10130 "TARGET_SH1 && TARGET_LITTLE_ENDIAN && can_create_pseudo_p ()
10131 && INTVAL (operands[1]) < 32"
10134 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10135 (const_int 1) (match_dup 1)))]
10137 operands[0] = gen_lowpart (SImode, operands[0]);
10140 (define_insn_and_split "*neg_zero_extract_6"
10141 [(set (reg:SI T_REG)
10142 (and:SI (not:SI (subreg:SI
10143 (lshiftrt:DI (match_operand:DI 0 "arith_reg_operand")
10144 (match_operand 1 "const_int_operand"))
10147 "TARGET_SH1 && TARGET_BIG_ENDIAN && can_create_pseudo_p ()
10148 && INTVAL (operands[1]) < 32"
10151 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10152 (const_int 1) (match_dup 1)))]
10154 operands[0] = gen_lowpart (SImode, operands[0]);
10157 ;; -------------------------------------------------------------------------
10158 ;; Extract single bit and zero extend it.
10159 ;; All patterns store the result bit in the T bit, although that is not
10160 ;; always possible to do with a single insn and a nott must be appended.
10161 ;; The trailing nott will be optimized away in most cases. E.g. if the
10162 ;; extracted bit is fed into a branch condition, the condition can be
10163 ;; inverted and the nott will be eliminated.
10164 ;; FIXME: In cases where the trailing nott can't be eliminated, try to
10165 ;; convert it into a (not, tst) sequence, which could be better on non-SH2A.
10167 ;; On SH2A the 'bld<mode>_reg' insn will be used if the bit position fits.
10168 (define_insn_and_split "*zero_extract_0"
10169 [(set (reg:SI T_REG)
10170 (zero_extract:SI (match_operand:QIHISI 0 "arith_reg_operand")
10172 (match_operand 1 "const_int_operand")))]
10173 "TARGET_SH1 && can_create_pseudo_p ()
10174 && !(TARGET_SH2A && satisfies_constraint_K03 (operands[1]))"
10177 [(set (reg:SI T_REG) (eq:SI (and:SI (match_dup 0) (match_dup 1))
10179 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))]
10181 if (INTVAL (operands[1]) == 31 && <MODE>mode == SImode)
10183 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
10187 operands[1] = GEN_INT (1 << INTVAL (operands[1]));
10188 if (GET_MODE (operands[0]) != SImode)
10189 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
10192 ;; This is required for some bit patterns of DImode subregs.
10193 ;; It looks like combine gets confused by the DImode right shift and fails
10194 ;; to simplify things.
10195 (define_insn_and_split "*zero_extract_1"
10196 [(set (reg:SI T_REG)
10197 (subreg:SI (zero_extract:DI (match_operand:SI 0 "arith_reg_operand")
10199 (match_operand 1 "const_int_operand"))
10201 "TARGET_SH1 && TARGET_LITTLE_ENDIAN && can_create_pseudo_p ()
10202 && INTVAL (operands[1]) < 32"
10205 [(set (reg:SI T_REG)
10206 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1)))])
10208 (define_insn_and_split "*zero_extract_2"
10209 [(set (reg:SI T_REG)
10210 (subreg:SI (zero_extract:DI (match_operand:SI 0 "arith_reg_operand")
10212 (match_operand 1 "const_int_operand"))
10214 "TARGET_SH1 && TARGET_BIG_ENDIAN && can_create_pseudo_p ()
10215 && INTVAL (operands[1]) < 32"
10218 [(set (reg:SI T_REG)
10219 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1)))])
10221 (define_insn_and_split "*zero_extract_3"
10222 [(set (match_operand:SI 0 "arith_reg_dest")
10223 (and:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
10224 (match_operand 2 "const_int_operand"))
10225 (match_operand 3 "const_int_operand")))
10226 (clobber (reg:SI T_REG))]
10227 "TARGET_SH1 && can_create_pseudo_p ()
10228 && exact_log2 (INTVAL (operands[3])) >= 0"
10233 int rshift = INTVAL (operands[2]);
10234 int lshift = exact_log2 (INTVAL (operands[3]));
10236 rtx tmp = gen_reg_rtx (SImode);
10237 emit_insn (gen_rtx_PARALLEL (VOIDmode,
10240 gen_rtx_ZERO_EXTRACT (SImode, operands[1], const1_rtx,
10241 GEN_INT (rshift + lshift))),
10242 gen_rtx_CLOBBER (VOIDmode, get_t_reg_rtx ()))));
10243 emit_insn (gen_ashlsi3 (operands[0], tmp, GEN_INT (lshift)));
10246 ;; -------------------------------------------------------------------------
10247 ;; SH2A instructions for bitwise operations.
10248 ;; FIXME: Convert multiple instruction insns to insn_and_split.
10249 ;; FIXME: Use iterators to fold at least and,xor,or insn variations.
10251 ;; Clear a bit in a memory location.
10252 (define_insn "bclr_m2a"
10253 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10255 (not:QI (ashift:QI (const_int 1)
10256 (match_operand:QI 1 "const_int_operand" "K03,K03")))
10258 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10261 bclr.b %1,@(0,%t0)"
10262 [(set_attr "length" "4,4")])
10264 (define_insn "bclrmem_m2a"
10265 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10266 (and:QI (match_dup 0)
10267 (match_operand:QI 1 "const_int_operand" "Psz,Psz")))]
10268 "TARGET_SH2A && satisfies_constraint_Psz (operands[1]) && TARGET_BITOPS"
10271 bclr.b %W1,@(0,%t0)"
10272 [(set_attr "length" "4,4")])
10274 ;; Set a bit in a memory location.
10275 (define_insn "bset_m2a"
10276 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10278 (ashift:QI (const_int 1)
10279 (match_operand:QI 1 "const_int_operand" "K03,K03"))
10281 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10284 bset.b %1,@(0,%t0)"
10285 [(set_attr "length" "4,4")])
10287 (define_insn "bsetmem_m2a"
10288 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10289 (ior:QI (match_dup 0)
10290 (match_operand:QI 1 "const_int_operand" "Pso,Pso")))]
10291 "TARGET_SH2A && satisfies_constraint_Pso (operands[1]) && TARGET_BITOPS"
10294 bset.b %V1,@(0,%t0)"
10295 [(set_attr "length" "4,4")])
10297 ;;; Transfer the contents of the T bit to a specified bit of memory.
10298 (define_insn "bst_m2a"
10299 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,m")
10300 (if_then_else (eq (reg:SI T_REG) (const_int 0))
10302 (not:QI (ashift:QI (const_int 1)
10303 (match_operand:QI 1 "const_int_operand" "K03,K03")))
10306 (ashift:QI (const_int 1) (match_dup 1))
10308 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10312 [(set_attr "length" "4")])
10314 ;; Store a specified bit of memory in the T bit.
10315 (define_insn "bld_m2a"
10316 [(set (reg:SI T_REG)
10318 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,Sbv")
10320 (match_operand 1 "const_int_operand" "K03,K03")))]
10321 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10325 [(set_attr "length" "4,4")])
10327 ;; Store a specified bit of memory in the T bit.
10328 (define_insn "bldsign_m2a"
10329 [(set (reg:SI T_REG)
10331 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10333 (match_operand 1 "const_int_operand" "K03,K03")))]
10334 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10338 [(set_attr "length" "4,4")])
10340 ;; Store a specified bit of the LSB 8 bits of a register in the T bit.
10341 (define_insn "bld<mode>_reg"
10342 [(set (reg:SI T_REG)
10343 (zero_extract:SI (match_operand:QIHISI 0 "arith_reg_operand" "r")
10345 (match_operand 1 "const_int_operand" "K03")))]
10346 "TARGET_SH2A && satisfies_constraint_K03 (operands[1])"
10349 ;; Take logical and of a specified bit of memory with the T bit and
10350 ;; store its result in the T bit.
10351 (define_insn "band_m2a"
10352 [(set (reg:SI T_REG)
10353 (and:SI (reg:SI T_REG)
10355 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10357 (match_operand 1 "const_int_operand" "K03,K03"))))]
10358 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10361 band.b %1,@(0,%t0)"
10362 [(set_attr "length" "4,4")])
10364 (define_insn "bandreg_m2a"
10365 [(set (match_operand:SI 0 "register_operand" "=r,r")
10366 (and:SI (zero_extract:SI
10367 (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
10369 (match_operand 2 "const_int_operand" "K03,K03"))
10370 (match_operand:SI 3 "register_operand" "r,r")))]
10371 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
10373 static const char* alt[] =
10375 "band.b %2,%1" "\n"
10378 "band.b %2,@(0,%t1)" "\n"
10381 return alt[which_alternative];
10383 [(set_attr "length" "6,6")])
10385 ;; Take logical or of a specified bit of memory with the T bit and
10386 ;; store its result in the T bit.
10387 (define_insn "bor_m2a"
10388 [(set (reg:SI T_REG)
10389 (ior:SI (reg:SI T_REG)
10391 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10393 (match_operand 1 "const_int_operand" "K03,K03"))))]
10394 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10398 [(set_attr "length" "4,4")])
10400 (define_insn "borreg_m2a"
10401 [(set (match_operand:SI 0 "register_operand" "=r,r")
10402 (ior:SI (zero_extract:SI
10403 (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
10405 (match_operand 2 "const_int_operand" "K03,K03"))
10406 (match_operand:SI 3 "register_operand" "=r,r")))]
10407 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
10409 static const char* alt[] =
10414 "bor.b %2,@(0,%t1)" "\n"
10417 return alt[which_alternative];
10419 [(set_attr "length" "6,6")])
10421 ;; Take exclusive or of a specified bit of memory with the T bit and
10422 ;; store its result in the T bit.
10423 (define_insn "bxor_m2a"
10424 [(set (reg:SI T_REG)
10425 (xor:SI (reg:SI T_REG)
10427 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10429 (match_operand 1 "const_int_operand" "K03,K03"))))]
10430 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10433 bxor.b %1,@(0,%t0)"
10434 [(set_attr "length" "4,4")])
10436 (define_insn "bxorreg_m2a"
10437 [(set (match_operand:SI 0 "register_operand" "=r,r")
10438 (xor:SI (zero_extract:SI
10439 (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
10441 (match_operand 2 "const_int_operand" "K03,K03"))
10442 (match_operand:SI 3 "register_operand" "=r,r")))]
10443 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
10445 static const char* alt[] =
10447 "bxor.b %2,%1" "\n"
10450 "bxor.b %2,@(0,%t1)" "\n"
10453 return alt[which_alternative];
10455 [(set_attr "length" "6,6")])
10457 ;; -------------------------------------------------------------------------
10459 ;; -------------------------------------------------------------------------
10460 ;; This matches cases where the bit in a memory location is set.
10462 [(set (match_operand:SI 0 "register_operand")
10463 (sign_extend:SI (match_operand:QI 1 "bitwise_memory_operand")))
10465 (ior:SI (match_dup 0)
10466 (match_operand:SI 2 "const_int_operand")))
10468 (match_operand 3 "arith_reg_operand"))]
10469 "TARGET_SH2A && TARGET_BITOPS
10470 && satisfies_constraint_Pso (operands[2])
10471 && REGNO (operands[0]) == REGNO (operands[3])"
10472 [(set (match_dup 1)
10473 (ior:QI (match_dup 1) (match_dup 2)))]
10476 ;; This matches cases where the bit in a memory location is cleared.
10478 [(set (match_operand:SI 0 "register_operand")
10479 (sign_extend:SI (match_operand:QI 1 "bitwise_memory_operand")))
10481 (and:SI (match_dup 0)
10482 (match_operand:SI 2 "const_int_operand")))
10484 (match_operand 3 "arith_reg_operand"))]
10485 "TARGET_SH2A && TARGET_BITOPS
10486 && satisfies_constraint_Psz (operands[2])
10487 && REGNO (operands[0]) == REGNO (operands[3])"
10488 [(set (match_dup 1)
10489 (and:QI (match_dup 1) (match_dup 2)))]
10492 ;; This matches cases where a stack pointer increment at the start of the
10493 ;; epilogue combines with a stack slot read loading the return value.
10495 [(set (match_operand:SI 0 "arith_reg_operand" "")
10496 (mem:SI (match_operand:SI 1 "arith_reg_operand" "")))
10497 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
10498 "TARGET_SH1 && REGNO (operands[1]) != REGNO (operands[0])"
10501 ;; See the comment on the dt combiner pattern above.
10503 [(set (match_operand:SI 0 "arith_reg_operand" "=r")
10504 (plus:SI (match_dup 0)
10506 (set (reg:SI T_REG)
10507 (eq:SI (match_dup 0) (const_int 0)))]
10511 ;; The following peepholes fold load sequences for which reload was not
10512 ;; able to generate a displacement addressing move insn.
10513 ;; This can happen when reload has to transform a move insn
10514 ;; without displacement into one with displacement. Or when reload can't
10515 ;; fit a displacement into the insn's constraints. In the latter case, the
10516 ;; load destination reg remains at r0, which reload compensates by inserting
10517 ;; another mov insn.
10521 ;; mov.{b,w} @(r0,r15),r0
10524 ;; mov.{b,w} @(54,r15),r3
10527 [(set (match_operand:SI 0 "arith_reg_dest" "")
10528 (match_operand:SI 1 "const_int_operand" ""))
10529 (set (match_operand:SI 2 "arith_reg_dest" "")
10531 (mem:QI (plus:SI (match_dup 0)
10532 (match_operand:SI 3 "arith_reg_operand" "")))))
10533 (set (match_operand:QI 4 "arith_reg_dest" "")
10534 (match_operand:QI 5 "arith_reg_operand" ""))]
10536 && sh_legitimate_index_p (QImode, operands[1], true, true)
10537 && REGNO (operands[2]) == REGNO (operands[5])
10538 && peep2_reg_dead_p (3, operands[5])"
10539 [(set (match_dup 4) (mem:QI (plus:SI (match_dup 3) (match_dup 1))))]
10543 [(set (match_operand:SI 0 "arith_reg_dest" "")
10544 (match_operand:SI 1 "const_int_operand" ""))
10545 (set (match_operand:SI 2 "arith_reg_dest" "")
10547 (mem:HI (plus:SI (match_dup 0)
10548 (match_operand:SI 3 "arith_reg_operand" "")))))
10549 (set (match_operand:HI 4 "arith_reg_dest" "")
10550 (match_operand:HI 5 "arith_reg_operand" ""))]
10552 && sh_legitimate_index_p (HImode, operands[1], true, true)
10553 && REGNO (operands[2]) == REGNO (operands[5])
10554 && peep2_reg_dead_p (3, operands[5])"
10555 [(set (match_dup 4) (mem:HI (plus:SI (match_dup 3) (match_dup 1))))]
10560 ;; mov.{b,w} @(r0,r15),r1
10562 ;; mov.{b,w} @(54,r15),r1
10565 [(set (match_operand:SI 0 "arith_reg_dest" "")
10566 (match_operand:SI 1 "const_int_operand" ""))
10567 (set (match_operand:SI 2 "arith_reg_dest" "")
10569 (mem:QI (plus:SI (match_dup 0)
10570 (match_operand:SI 3 "arith_reg_operand" "")))))]
10572 && sh_legitimate_index_p (QImode, operands[1], true, true)
10573 && (peep2_reg_dead_p (2, operands[0])
10574 || REGNO (operands[0]) == REGNO (operands[2]))"
10575 [(set (match_dup 2)
10576 (sign_extend:SI (mem:QI (plus:SI (match_dup 3) (match_dup 1)))))]
10580 [(set (match_operand:SI 0 "arith_reg_dest" "")
10581 (match_operand:SI 1 "const_int_operand" ""))
10582 (set (match_operand:SI 2 "arith_reg_dest" "")
10584 (mem:HI (plus:SI (match_dup 0)
10585 (match_operand:SI 3 "arith_reg_operand" "")))))]
10587 && sh_legitimate_index_p (HImode, operands[1], true, true)
10588 && (peep2_reg_dead_p (2, operands[0])
10589 || REGNO (operands[0]) == REGNO (operands[2]))"
10590 [(set (match_dup 2)
10591 (sign_extend:SI (mem:HI (plus:SI (match_dup 3) (match_dup 1)))))]
10595 ;; mov.{b,w} @(r0,r15),r0
10598 ;; mov.{b,w} @(r0,r15),r3
10600 ;; This can happen when initially a displacement address is picked, where
10601 ;; the destination reg is fixed to r0, and then the address is transformed
10602 ;; into 'r0 + reg'.
10604 [(set (match_operand:SI 0 "arith_reg_dest" "")
10606 (mem:QI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
10607 (match_operand:SI 2 "arith_reg_operand" "")))))
10608 (set (match_operand:QI 3 "arith_reg_dest" "")
10609 (match_operand:QI 4 "arith_reg_operand" ""))]
10611 && REGNO (operands[0]) == REGNO (operands[4])
10612 && peep2_reg_dead_p (2, operands[0])"
10613 [(set (match_dup 3)
10614 (mem:QI (plus:SI (match_dup 1) (match_dup 2))))]
10618 [(set (match_operand:SI 0 "arith_reg_dest" "")
10620 (mem:HI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
10621 (match_operand:SI 2 "arith_reg_operand" "")))))
10622 (set (match_operand:HI 3 "arith_reg_dest" "")
10623 (match_operand:HI 4 "arith_reg_operand" ""))]
10625 && REGNO (operands[0]) == REGNO (operands[4])
10626 && peep2_reg_dead_p (2, operands[0])"
10627 [(set (match_dup 3)
10628 (mem:HI (plus:SI (match_dup 1) (match_dup 2))))]
10632 ;; mov b,c -> extu.bw a,c
10634 [(set (match_operand:SI 0 "arith_reg_dest")
10635 (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand")))
10636 (set (match_operand:SI 2 "arith_reg_dest")
10638 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10639 [(set (match_dup 2) (zero_extend:SI (match_dup 1)))])
10642 ;; extu.bw r1,r1 -> extu.bw r0,r1
10644 [(set (match_operand 0 "arith_reg_dest")
10645 (match_operand 1 "arith_reg_operand"))
10646 (set (match_operand:SI 2 "arith_reg_dest")
10647 (zero_extend:SI (match_operand:QIHI 3 "arith_reg_operand")))]
10649 && REGNO (operands[0]) == REGNO (operands[3])
10650 && (REGNO (operands[0]) == REGNO (operands[2])
10651 || peep2_reg_dead_p (2, operands[0]))"
10652 [(set (match_dup 2) (zero_extend:SI (match_dup 1)))]
10654 operands[1] = gen_rtx_REG (<MODE>mode, REGNO (operands[1]));
10658 ;; mov b,a -> < nop >
10660 [(set (match_operand 0 "register_operand")
10661 (match_operand 1 "register_operand"))
10662 (set (match_operand 2 "register_operand")
10663 (match_operand 3 "register_operand"))]
10665 && REGNO (operands[0]) == REGNO (operands[3])
10666 && REGNO (operands[1]) == REGNO (operands[2])
10667 && peep2_reg_dead_p (2, operands[3])"
10671 ;; and r4,r1 -> mov r1,r0
10672 ;; mov r1,r0 and #3,r0
10673 (define_code_iterator ANDIORXOR [and ior xor])
10675 [(set (match_operand:SI 0 "register_operand")
10676 (match_operand:SI 1 "const_logical_operand"))
10677 (set (match_operand:SI 2) (ANDIORXOR:SI (match_dup 2) (match_dup 0)))
10678 (set (reg:SI R0_REG) (match_dup 2))]
10680 && peep2_reg_dead_p (3, operands[0]) && peep2_reg_dead_p (3, operands[2])"
10681 [(set (reg:SI R0_REG) (match_dup 2))
10682 (set (reg:SI R0_REG) (ANDIORXOR:SI (reg:SI R0_REG) (match_dup 1)))])
10684 ;; ... r2,r0 ... r2,r0
10685 ;; or r1,r0 -> or r0,r1
10688 (define_code_iterator ANDIORXORPLUS [and ior xor plus])
10690 [(set (match_operand:SI 0 "arith_reg_dest")
10691 (ANDIORXORPLUS:SI (match_dup 0) (match_operand:SI 1 "arith_reg_dest")))
10692 (set (match_dup 1) (match_dup 0))]
10693 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10694 [(set (match_dup 1) (ANDIORXORPLUS:SI (match_dup 1) (match_dup 0)))])
10697 ;; add #-48,r0 -> add #-48,r12
10698 ;; mov.l r0,@(4,r10) mov.l r12,@(4,r10)
10701 [(set (match_operand:SI 0 "arith_reg_dest")
10702 (match_operand:SI 1 "arith_reg_dest"))
10703 (set (match_dup 0) (plus:SI (match_dup 0)
10704 (match_operand:SI 2 "const_int_operand")))
10705 (set (match_operand:SI 3 "general_movdst_operand") (match_dup 0))]
10707 && peep2_reg_dead_p (2, operands[1]) && peep2_reg_dead_p (3, operands[0])"
10710 if (MEM_P (operands[3]) && reg_overlap_mentioned_p (operands[0], operands[3]))
10712 // Take care when the eliminated operand[0] register is part of
10713 // the destination memory address.
10714 rtx addr = XEXP (operands[3], 0);
10717 operands[3] = replace_equiv_address (operands[3], operands[1]);
10719 else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0))
10720 && CONST_INT_P (XEXP (addr, 1))
10721 && REGNO (operands[0]) == REGNO (XEXP (addr, 0)))
10722 operands[3] = replace_equiv_address (operands[3],
10723 gen_rtx_PLUS (SImode, operands[1], XEXP (addr, 1)));
10725 else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0))
10726 && REG_P (XEXP (addr, 1)))
10728 // register + register address @(R0, Rn)
10729 // can change only the Rn in the address, not R0.
10730 if (REGNO (operands[0]) == REGNO (XEXP (addr, 0))
10731 && REGNO (XEXP (addr, 0)) != 0)
10733 operands[3] = replace_equiv_address (operands[3],
10734 gen_rtx_PLUS (SImode, operands[1], XEXP (addr, 1)));
10736 else if (REGNO (operands[0]) == REGNO (XEXP (addr, 1))
10737 && REGNO (XEXP (addr, 1)) != 0)
10739 operands[3] = replace_equiv_address (operands[3],
10740 gen_rtx_PLUS (SImode, XEXP (addr, 0), operands[1]));
10749 emit_insn (gen_addsi3 (operands[1], operands[1], operands[2]));
10750 sh_peephole_emit_move_insn (operands[3], operands[1]);
10753 ;; mov.l @(r0,r9),r1
10754 ;; mov r1,r0 -> mov @(r0,r9),r0
10756 [(set (match_operand:SI 0 "arith_reg_dest")
10757 (match_operand:SI 1 "general_movsrc_operand"))
10758 (set (match_operand:SI 2 "arith_reg_dest")
10760 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10763 sh_peephole_emit_move_insn (operands[2], operands[1]);
10767 [(set (match_operand:QIHI 0 "register_operand")
10768 (match_operand:QIHI 1 "movsrc_no_disp_mem_operand"))
10769 (set (match_operand:QIHI 2 "register_operand")
10771 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10774 sh_peephole_emit_move_insn (operands[2], operands[1]);
10778 [(set (match_operand:SI 0 "arith_reg_dest")
10779 (sign_extend:SI (match_operand:QIHI 1 "movsrc_no_disp_mem_operand")))
10780 (set (match_operand:SI 2 "arith_reg_dest")
10782 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10785 sh_check_add_incdec_notes (emit_insn (gen_extend<mode>si2 (operands[2],
10786 sh_remove_overlapping_post_inc (operands[2], operands[1]))));
10789 ;; mov.w @(18,r1),r0 (r0 = HImode)
10790 ;; mov r0,r1 (r0 = r1 = HImode) mov.w @(18,r1),r0
10791 ;; ... ..,r13 (r13 = SImode) -> ... ..,r13
10792 ;; tst r1,r13 tst r0,r13
10794 [(set (match_operand 0 "arith_reg_dest")
10795 (match_operand 1 "arith_reg_dest"))
10796 (set (match_operand:SI 2 "arith_reg_dest")
10797 (match_operand:SI 3))
10798 (set (reg:SI T_REG)
10799 (eq:SI (and:SI (match_operand:SI 4 "arith_reg_operand")
10800 (match_operand:SI 5 "arith_reg_operand"))
10803 && peep2_reg_dead_p (3, operands[0])
10804 && !reg_overlap_mentioned_p (operands[0], operands[3])
10805 && (REGNO (operands[0]) == REGNO (operands[4])
10806 || REGNO (operands[0]) == REGNO (operands[5]))
10807 && (REGNO (operands[2]) == REGNO (operands[4])
10808 || REGNO (operands[2]) == REGNO (operands[5]))"
10811 if (REGNO (operands[1]) == REGNO (operands[2]))
10812 operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]));
10814 // We don't know what the new set insn will be in detail. Just make sure
10815 // that it still can be recognized and the constraints are satisfied.
10816 rtx_insn* i = emit_insn (gen_rtx_SET (operands[2],
10817 sh_remove_overlapping_post_inc (operands[2], operands[3])));
10819 recog_data_d prev_recog_data = recog_data;
10820 bool i_invalid = insn_invalid_p (i, false);
10821 recog_data = prev_recog_data;
10826 sh_check_add_incdec_notes (i);
10828 emit_insn (gen_tstsi_t (operands[2],
10829 gen_rtx_REG (SImode, (REGNO (operands[1])))));
10832 ;; mov.w @(18,r1),r0 (r0 = HImode)
10833 ;; ... ..,r13 (r13 = SImode) mov.w @(18,r1),r0
10834 ;; mov r0,r1 (r0 = r1 = HImode) -> ... ..,r13
10835 ;; tst r1,r13 tst r0,r13
10837 [(set (match_operand:SI 2 "arith_reg_dest")
10838 (match_operand:SI 3))
10839 (set (match_operand 0 "arith_reg_dest")
10840 (match_operand 1 "arith_reg_operand"))
10841 (set (reg:SI T_REG)
10842 (eq:SI (and:SI (match_operand:SI 4 "arith_reg_operand")
10843 (match_operand:SI 5 "arith_reg_operand"))
10846 && peep2_reg_dead_p (3, operands[0])
10847 && !reg_overlap_mentioned_p (operands[0], operands[3])
10848 && (REGNO (operands[0]) == REGNO (operands[4])
10849 || REGNO (operands[0]) == REGNO (operands[5]))
10850 && (REGNO (operands[2]) == REGNO (operands[4])
10851 || REGNO (operands[2]) == REGNO (operands[5]))"
10854 // We don't know what the new set insn will be in detail. Just make sure
10855 // that it still can be recognized and the constraints are satisfied.
10856 rtx_insn* i = emit_insn (gen_rtx_SET (operands[2],
10857 sh_remove_overlapping_post_inc (operands[2], operands[3])));
10859 recog_data_d prev_recog_data = recog_data;
10860 bool i_invalid = insn_invalid_p (i, false);
10861 recog_data = prev_recog_data;
10866 sh_check_add_incdec_notes (i);
10868 emit_insn (gen_tstsi_t (operands[2],
10869 gen_rtx_REG (SImode, (REGNO (operands[1])))));
10872 ;; This is not a peephole, but it's here because it's actually supposed
10873 ;; to be one. It tries to convert a sequence such as
10874 ;; movt r2 -> movt r2
10875 ;; movt r13 mov r2,r13
10876 ;; This gives the schduler a bit more freedom to hoist a following
10877 ;; comparison insn. Moreover, it the reg-reg mov insn is MT group which has
10878 ;; better chances for parallel execution.
10879 ;; We can do this with a peephole2 pattern, but then the cprop_hardreg
10880 ;; pass will revert the change. See also PR 64331.
10881 ;; Thus do it manually in one of the split passes after register allocation.
10882 ;; Sometimes the cprop_hardreg pass might also eliminate the reg-reg copy.
10884 [(set (match_operand:SI 0 "arith_reg_dest")
10885 (match_operand:SI 1 "t_reg_operand"))]
10886 "TARGET_SH1 && reload_completed"
10887 [(set (match_dup 0) (match_dup 1))]
10889 rtx t_reg = get_t_reg_rtx ();
10891 for (rtx_insn* i = prev_nonnote_nondebug_insn_bb (curr_insn); i != NULL;
10892 i = prev_nonnote_nondebug_insn_bb (i))
10894 if (!INSN_P (i) || DEBUG_INSN_P (i))
10897 if (modified_in_p (t_reg, i) || BARRIER_P (i))
10900 if (sh_is_movt_insn (i))
10902 rtx r = sh_movt_set_dest (i);
10903 if (!modified_between_p (r, i, curr_insn))
10913 [(set (match_operand:SI 0 "register_operand" "=r")
10914 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10915 (set (mem:SF (match_dup 0))
10916 (match_operand:SF 2 "general_movsrc_operand" ""))]
10917 "TARGET_SH1 && REGNO (operands[0]) == 0
10918 && ((REG_P (operands[2]) && REGNO (operands[2]) < 16)
10919 || (GET_CODE (operands[2]) == SUBREG
10920 && REGNO (SUBREG_REG (operands[2])) < 16))
10921 && reg_unused_after (operands[0], insn)"
10922 "mov.l %2,@(%0,%1)")
10925 [(set (match_operand:SI 0 "register_operand" "=r")
10926 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10927 (set (match_operand:SF 2 "general_movdst_operand" "")
10929 (mem:SF (match_dup 0)))]
10930 "TARGET_SH1 && REGNO (operands[0]) == 0
10931 && ((REG_P (operands[2]) && REGNO (operands[2]) < 16)
10932 || (GET_CODE (operands[2]) == SUBREG
10933 && REGNO (SUBREG_REG (operands[2])) < 16))
10934 && reg_unused_after (operands[0], insn)"
10935 "mov.l @(%0,%1),%2")
10938 [(set (match_operand:SI 0 "register_operand" "=r")
10939 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10940 (set (mem:SF (match_dup 0))
10941 (match_operand:SF 2 "general_movsrc_operand" ""))]
10942 "TARGET_SH2E && REGNO (operands[0]) == 0
10943 && ((REG_P (operands[2])
10944 && FP_OR_XD_REGISTER_P (REGNO (operands[2])))
10945 || (GET_CODE (operands[2]) == SUBREG
10946 && FP_OR_XD_REGISTER_P (REGNO (SUBREG_REG (operands[2])))))
10947 && reg_unused_after (operands[0], insn)"
10948 "fmov{.s|} %2,@(%0,%1)")
10951 [(set (match_operand:SI 0 "register_operand" "=r")
10952 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10953 (set (match_operand:SF 2 "general_movdst_operand" "")
10955 (mem:SF (match_dup 0)))]
10956 "TARGET_SH2E && REGNO (operands[0]) == 0
10957 && ((REG_P (operands[2])
10958 && FP_OR_XD_REGISTER_P (REGNO (operands[2])))
10959 || (GET_CODE (operands[2]) == SUBREG
10960 && FP_OR_XD_REGISTER_P (REGNO (SUBREG_REG (operands[2])))))
10961 && reg_unused_after (operands[0], insn)"
10962 "fmov{.s|} @(%0,%1),%2")
10964 ;; Switch to a new stack with its address in sp_switch (a SYMBOL_REF).
10965 (define_insn "sp_switch_1"
10966 [(set (reg:SI SP_REG) (unspec_volatile:SI [(match_operand:SI 0 "" "")]
10967 UNSPECV_SP_SWITCH_B))]
10970 return "mov.l r0,@-r15" "\n"
10971 " mov.l %0,r0" "\n"
10972 " mov.l @r0,r0" "\n"
10973 " mov.l r15,@-r0" "\n"
10976 [(set_attr "length" "10")])
10978 ;; Switch back to the original stack for interrupt functions with the
10979 ;; sp_switch attribute.
10980 (define_insn "sp_switch_2"
10981 [(unspec_volatile [(const_int 0)]
10982 UNSPECV_SP_SWITCH_E)]
10985 return "mov.l @r15,r15" "\n"
10988 [(set_attr "length" "4")])
10991 ;; In user mode, the "pref" instruction will raise a RADDERR exception
10992 ;; for accesses to [0x80000000,0xffffffff]. This makes it an unsuitable
10993 ;; implementation of __builtin_prefetch for VxWorks RTPs.
10994 (define_expand "prefetch"
10995 [(prefetch (match_operand 0 "address_operand" "")
10996 (match_operand:SI 1 "const_int_operand" "")
10997 (match_operand:SI 2 "const_int_operand" ""))]
10998 "(TARGET_SH2A || TARGET_SH3) && !TARGET_VXWORKS_RTP")
11000 (define_insn "*prefetch"
11001 [(prefetch (match_operand:SI 0 "register_operand" "r")
11002 (match_operand:SI 1 "const_int_operand" "n")
11003 (match_operand:SI 2 "const_int_operand" "n"))]
11004 "(TARGET_SH2A || TARGET_SH3) && ! TARGET_VXWORKS_RTP"
11006 [(set_attr "type" "other")])
11008 ;; -------------------------------------------------------------------------
11009 ;; Stack Protector Patterns
11010 ;; -------------------------------------------------------------------------
11012 (define_expand "stack_protect_set"
11013 [(set (match_operand 0 "memory_operand" "")
11014 (match_operand 1 "memory_operand" ""))]
11017 emit_insn (gen_stack_protect_set_si (operands[0], operands[1]));
11021 (define_insn "stack_protect_set_si"
11022 [(set (match_operand:SI 0 "memory_operand" "=m")
11023 (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11024 (set (match_scratch:SI 2 "=&r") (const_int 0))]
11027 return "mov.l %1,%2" "\n"
11028 " mov.l %2,%0" "\n"
11031 [(set_attr "type" "other")
11032 (set_attr "length" "6")])
11034 (define_expand "stack_protect_test"
11035 [(match_operand 0 "memory_operand" "")
11036 (match_operand 1 "memory_operand" "")
11037 (match_operand 2 "" "")]
11040 emit_insn (gen_stack_protect_test_si (operands[0], operands[1]));
11041 emit_jump_insn (gen_branch_true (operands[2]));
11045 (define_insn "stack_protect_test_si"
11046 [(set (reg:SI T_REG)
11047 (unspec:SI [(match_operand:SI 0 "memory_operand" "m")
11048 (match_operand:SI 1 "memory_operand" "m")]
11050 (set (match_scratch:SI 2 "=&r") (const_int 0))
11051 (set (match_scratch:SI 3 "=&r") (const_int 0))]
11054 return "mov.l %0,%2" "\n"
11055 " mov.l %1,%3" "\n"
11056 " cmp/eq %2,%3" "\n"
11060 [(set_attr "type" "other")
11061 (set_attr "length" "10")])
11063 ;; -------------------------------------------------------------------------
11064 ;; Atomic operations
11065 ;; -------------------------------------------------------------------------
11067 (include "sync.md")