]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/sh/sh.md
Update copyright years.
[thirdparty/gcc.git] / gcc / config / sh / sh.md
1 ;;- Machine description for Renesas / SuperH SH.
2 ;; Copyright (C) 1993-2017 Free Software Foundation, Inc.
3 ;; Contributed by Steve Chamberlain (sac@cygnus.com).
4 ;; Improved by Jim Wilson (wilson@cygnus.com).
5
6 ;; This file is part of GCC.
7
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)
11 ;; any later version.
12
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.
17
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/>.
21
22
23 ;; ??? Should prepend a * to all pattern names which are not used.
24 ;; This will make the compiler smaller, and rebuilds after changes faster.
25
26 ;; ??? Should be enhanced to include support for many more GNU superoptimizer
27 ;; sequences. Especially the sequences for arithmetic right shifts.
28
29 ;; ??? Should check all DImode patterns for consistency and usefulness.
30
31 ;; ??? The MAC.W and MAC.L instructions are not supported. There is no
32 ;; way to generate them.
33
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
37
38 ;; Special constraints for SH machine description:
39 ;;
40 ;; t -- T
41 ;; x -- mac
42 ;; l -- pr
43 ;; z -- r0
44 ;;
45 ;; Special formats used for outputting SH instructions:
46 ;;
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
54 ;;
55 ;; Special predicates:
56 ;;
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
62
63 ;; -------------------------------------------------------------------------
64 ;; Constants
65 ;; -------------------------------------------------------------------------
66
67 (define_constants [
68 (AP_REG 145)
69 (PR_REG 146)
70 (T_REG 147)
71 (GBR_REG 144)
72 (MACH_REG 148)
73 (MACL_REG 149)
74 (FPUL_REG 150)
75 (RAP_REG 152)
76
77 (FPSCR_REG 151)
78
79 ;; Virtual FPSCR - bits that are used by FP ops.
80 (FPSCR_MODES_REG 154)
81
82 ;; Virtual FPSCR - bits that are updated by FP ops.
83 (FPSCR_STAT_REG 155)
84
85 (PIC_REG 12)
86 (FP_REG 14)
87 (SP_REG 15)
88
89 (R0_REG 0)
90 (R1_REG 1)
91 (R2_REG 2)
92 (R3_REG 3)
93 (R4_REG 4)
94 (R5_REG 5)
95 (R6_REG 6)
96 (R7_REG 7)
97 (R8_REG 8)
98 (R9_REG 9)
99 (R10_REG 10)
100 (R20_REG 20)
101 (R21_REG 21)
102 (R22_REG 22)
103 (R23_REG 23)
104
105 (DR0_REG 64)
106 (DR2_REG 66)
107 (DR4_REG 68)
108
109 (XD0_REG 136)
110
111 (FPSCR_PR 524288) ;; 1 << 19
112 (FPSCR_SZ 1048576) ;; 1 << 20
113 (FPSCR_FR 2097152) ;; 1 << 21
114 ])
115
116 (define_c_enum "unspec" [
117 ;; These are used with unspec.
118 UNSPEC_MOVA
119 UNSPEC_CASESI
120 UNSPEC_BBR
121 UNSPEC_SFUNC
122 UNSPEC_PIC
123 UNSPEC_GOT
124 UNSPEC_GOTOFF
125 UNSPEC_PLT
126 UNSPEC_CALLER
127 UNSPEC_GOTPLT
128 UNSPEC_PCREL
129 UNSPEC_ICACHE
130 UNSPEC_FCOSA
131 UNSPEC_FSRRA
132 UNSPEC_FSINA
133 UNSPEC_ALLOCO
134 UNSPEC_TLSGD
135 UNSPEC_TLSLDM
136 UNSPEC_TLSIE
137 UNSPEC_DTPOFF
138 UNSPEC_GOTTPOFF
139 UNSPEC_TPOFF
140 UNSPEC_RA
141 UNSPEC_THUNK
142 UNSPEC_CHKADD
143 UNSPEC_SP_SET
144 UNSPEC_SP_TEST
145 UNSPEC_MOVUA
146 ;; (unspec [TARGET ANCHOR] UNSPEC_SYMOFF) == TARGET - ANCHOR.
147 UNSPEC_SYMOFF
148 ;; (unspec [OFFSET ANCHOR] UNSPEC_PCREL_SYMOFF) == OFFSET - (ANCHOR - .).
149 UNSPEC_PCREL_SYMOFF
150 ;; For FDPIC
151 UNSPEC_GOTFUNCDESC
152 UNSPEC_GOTOFFFUNCDESC
153 ;; Misc builtins
154 UNSPEC_BUILTIN_STRLEN
155 ])
156
157 (define_c_enum "unspecv" [
158 ;; These are used with unspec_volatile.
159 UNSPECV_BLOCKAGE
160 UNSPECV_ALIGN
161 UNSPECV_CONST2
162 UNSPECV_CONST4
163 UNSPECV_CONST8
164 UNSPECV_WINDOW_END
165 UNSPECV_CONST_END
166 UNSPECV_EH_RETURN
167 UNSPECV_GBR
168 UNSPECV_SP_SWITCH_B
169 UNSPECV_SP_SWITCH_E
170
171 UNSPECV_FPSCR_MODES
172 UNSPECV_FPSCR_STAT
173 ])
174
175 ;; -------------------------------------------------------------------------
176 ;; Attributes
177 ;; -------------------------------------------------------------------------
178
179 ;; Target CPU.
180
181 (define_attr "cpu"
182 "sh1,sh2,sh2e,sh2a,sh3,sh3e,sh4,sh4a"
183 (const (symbol_ref "sh_cpu_attr")))
184
185 (define_attr "endian" "big,little"
186 (const (if_then_else (symbol_ref "TARGET_LITTLE_ENDIAN")
187 (const_string "little") (const_string "big"))))
188
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"))))
193
194 (define_attr "fmovd" "yes,no"
195 (const (if_then_else (symbol_ref "TARGET_FMOVD")
196 (const_string "yes") (const_string "no"))))
197 ;; pipeline model
198 (define_attr "pipe_model" "sh1,sh4"
199 (const
200 (cond [(symbol_ref "TARGET_SUPERSCALAR") (const_string "sh4")]
201 (const_string "sh1"))))
202
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
209 ;; load from memory
210 ;; load_si Likewise, SImode variant for general register.
211 ;; fload Likewise, but load to fp register.
212 ;; store to memory
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
220 ;; return rts
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
231 ;; fp floating point
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.
249
250 (define_attr "type"
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,
256 nil,other"
257 (const_string "other"))
258
259 ;; We define a new attribute namely "insn_class".We use
260 ;; this for the DFA based pipeline description.
261 ;;
262 ;; mt_group SH4 "mt" group instructions.
263 ;;
264 ;; ex_group SH4 "ex" group instructions.
265 ;;
266 ;; ls_group SH4 "ls" group instructions.
267 ;;
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")))
281
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.
285
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"))
288
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
292 ;; state.
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"))
296
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
302 ; 2 bytes.
303
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.
316 ;;
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.
319
320 ;; ??? This looks ugly because genattrtab won't allow if_then_else or cond
321 ;; inside an le.
322 (define_attr "short_cbranch_p" "no,yes"
323 (cond [(match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
324 (const_string "no")
325 (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 506))
326 (const_string "yes")
327 (match_test "NEXT_INSN (PREV_INSN (insn)) != insn")
328 (const_string "no")
329 (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 508))
330 (const_string "yes")
331 ] (const_string "no")))
332
333 (define_attr "med_branch_p" "no,yes"
334 (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 990))
335 (const_int 1988))
336 (const_string "yes")
337 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
338 (const_string "no")
339 (leu (plus (minus (match_dup 0) (pc)) (const_int 4092))
340 (const_int 8186))
341 (const_string "yes")
342 ] (const_string "no")))
343
344 (define_attr "med_cbranch_p" "no,yes"
345 (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 988))
346 (const_int 1986))
347 (const_string "yes")
348 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
349 (const_string "no")
350 (leu (plus (minus (match_dup 0) (pc)) (const_int 4090))
351 (const_int 8184))
352 (const_string "yes")
353 ] (const_string "no")))
354
355 (define_attr "braf_branch_p" "no,yes"
356 (cond [(match_test "! TARGET_SH2")
357 (const_string "no")
358 (leu (plus (minus (match_dup 0) (pc)) (const_int 10330))
359 (const_int 20660))
360 (const_string "yes")
361 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
362 (const_string "no")
363 (leu (plus (minus (match_dup 0) (pc)) (const_int 32764))
364 (const_int 65530))
365 (const_string "yes")
366 ] (const_string "no")))
367
368 (define_attr "braf_cbranch_p" "no,yes"
369 (cond [(match_test "! TARGET_SH2")
370 (const_string "no")
371 (leu (plus (minus (match_dup 0) (pc)) (const_int 10328))
372 (const_int 20658))
373 (const_string "yes")
374 (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
375 (const_string "no")
376 (leu (plus (minus (match_dup 0) (pc)) (const_int 32762))
377 (const_int 65528))
378 (const_string "yes")
379 ] (const_string "no")))
380
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.
387
388 ;; All other instructions are two bytes long by default.
389
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")
395 (const_int 2)
396 (eq_attr "med_cbranch_p" "yes")
397 (const_int 6)
398 (eq_attr "braf_cbranch_p" "yes")
399 (const_int 12)
400 ;; ??? using pc is not computed transitively.
401 (ne (match_dup 0) (match_dup 0))
402 (const_int 14)
403 (match_test "flag_pic")
404 (const_int 24)
405 ] (const_int 16))
406 (eq_attr "type" "jump")
407 (cond [(eq_attr "med_branch_p" "yes")
408 (const_int 2)
409 (and (match_test "prev_nonnote_insn (insn)")
410 (and (eq (symbol_ref "GET_CODE (prev_nonnote_insn (insn))")
411 (symbol_ref "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")
415 (const_int 6)
416 (not (match_test "flag_pic"))
417 (const_int 10)
418 (match_test "TARGET_SH2")
419 (const_int 10)] (const_int 18))
420 (eq_attr "braf_branch_p" "yes")
421 (const_int 10)
422 ;; ??? using pc is not computed transitively.
423 (ne (match_dup 0) (match_dup 0))
424 (const_int 12)
425 (match_test "flag_pic")
426 (const_int 22)
427 ] (const_int 14))
428 ] (const_int 2)))
429
430 ;; DFA descriptions for the pipelines
431
432 (include "sh1.md")
433 (include "sh4.md")
434
435 (include "iterators.md")
436 (include "predicates.md")
437 (include "constraints.md")
438
439 ;; Definitions for filling delay slots
440
441 (define_attr "needs_delay_slot" "yes,no" (const_string "no"))
442
443 (define_attr "banked" "yes,no"
444 (cond [(match_test "sh_loads_bankedreg_p (insn)")
445 (const_string "yes")]
446 (const_string "no")))
447
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)"))
451 (const_string "no")]
452 (const_string "yes")))
453
454 (define_attr "interrupt_function" "no,yes"
455 (const (symbol_ref "current_function_interrupt")))
456
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")))
464
465 (define_attr "cond_delay_slot" "yes,no"
466 (cond [(eq_attr "in_delay_slot" "yes") (const_string "yes")
467 ] (const_string "no")))
468
469 (define_attr "is_sfunc" ""
470 (if_then_else (eq_attr "type" "sfunc") (const_int 1) (const_int 0)))
471
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")))
477
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")))
485
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")))
490
491 (define_attr "highpart" "user, ignore, extend, depend, must_split"
492 (const_string "user"))
493
494 (define_delay
495 (eq_attr "needs_delay_slot" "yes")
496 [(eq_attr "in_delay_slot" "yes") (nil) (nil)])
497
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).
505 (define_delay
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"))))
513 (nil) (nil)])
514
515 ;; Since a call implicitly uses the PR register, we can't allow
516 ;; a PR register store in a jsr delay slot.
517
518 (define_delay
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)])
522
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.
526 (define_delay
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)])
532 \f
533 ;; -------------------------------------------------------------------------
534 ;; SImode signed integer comparisons
535 ;; -------------------------------------------------------------------------
536
537 ;; Patterns to generate the tst instruction which are usually formed by
538 ;; the combine pass.
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"
549 [(set (reg:SI T_REG)
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"))
552 (const_int 0)))]
553 "TARGET_SH1
554 && (can_create_pseudo_p () || arith_reg_operand (operands[1], SImode)
555 || satisfies_constraint_K08 (operands[1]))"
556 "tst %1,%0"
557 "TARGET_SH1 && can_create_pseudo_p () && CONST_INT_P (operands[1])
558 && !sh_in_recog_treg_set_expr ()"
559 [(const_int 0)]
560 {
561 gcc_assert (CONST_INT_P (operands[1]));
562
563 HOST_WIDE_INT op1val = INTVAL (operands[1]);
564 bool op0_dead_after_this =
565 sh_reg_dead_or_unused_after_insn (curr_insn, REGNO (operands[0]));
566
567 if (optimize)
568 {
569 if (dump_file)
570 fprintf (dump_file,
571 "tstsi_t: trying to optimize const_int 0x%08x\n",
572 (uint32_t)op1val);
573
574 /* See if we can convert a test with a reg and a constant into
575 something simpler, if the reg is known to be zero or sign
576 extended. */
577 sh_extending_set_of_reg eop0 = sh_find_extending_set_of_reg (operands[0],
578 curr_insn);
579 if (eop0.ext_code != UNKNOWN)
580 {
581 /* Adjust the constant, trying to eliminate bits that are not
582 contributing to the result. */
583 if (eop0.from_mode == QImode)
584 op1val = (op1val
585 | (eop0.ext_code == SIGN_EXTEND && (op1val & 0xFFFFFF80)
586 ? 0x80 : 0)) & 0xFF;
587 else if (eop0.from_mode == HImode)
588 op1val = (op1val
589 | (eop0.ext_code == SIGN_EXTEND && (op1val & 0xFFFF8000)
590 ? 0x8000 : 0)) & 0xFFFF;
591
592 if (dump_file)
593 fprintf (dump_file, "tstsi_t: using effective const_int: 0x%08x\n",
594 (uint32_t)op1val);
595
596 /* Try to bypass the sign/zero extension first if op0 dies after
597 this insn. */
598 if (op0_dead_after_this && eop0.can_use_as_unextended_reg ())
599 {
600 if (dump_file)
601 fprintf (dump_file, "tstsi_t: bypassing sign/zero extension\n");
602
603 operands[0] = eop0.use_as_unextended_reg (curr_insn);
604 }
605 else if ((eop0.from_mode == QImode && op1val == 0xFF)
606 || (eop0.from_mode == HImode && op1val == 0xFFFF))
607 {
608 if (dump_file)
609 fprintf (dump_file, "tstsi_t: converting to cmpeqsi_t\n");
610 emit_insn (gen_cmpeqsi_t (eop0.use_as_extended_reg (curr_insn),
611 const0_rtx));
612 DONE;
613 }
614 else if (eop0.ext_code == SIGN_EXTEND
615 && ((eop0.from_mode == QImode && op1val == 0x80)
616 || (eop0.from_mode == HImode && op1val == 0x8000)))
617 {
618 if (dump_file)
619 fprintf (dump_file, "tstsi_t: converting to cmpgesi_t\n");
620 emit_insn (gen_cmpgesi_t (eop0.use_as_extended_reg (curr_insn),
621 const0_rtx));
622 DONE;
623 }
624 else if (!CONST_OK_FOR_K08 (op1val))
625 {
626 if (dump_file)
627 fprintf (dump_file, "tstsi_t: converting const_int to signed "
628 "value\n");
629
630 /* If here we haven't done anything yet. Convert the constant
631 to a signed value to reduce the constant pool size. */
632 operands[0] = eop0.use_as_extended_reg (curr_insn);
633
634 if (eop0.from_mode == QImode)
635 op1val |= (op1val & 0x80) ? 0xFFFFFFFFFFFFFF00LL : 0;
636 else if (eop0.from_mode == HImode)
637 op1val |= (op1val & 0x8000) ? 0xFFFFFFFFFFFF0000LL : 0;
638 }
639 else
640 operands[0] = eop0.use_as_extended_reg (curr_insn);
641 }
642 }
643
644 if (dump_file)
645 fprintf (dump_file, "tstsi_t: using const_int 0x%08x\n",
646 (uint32_t)op1val);
647
648 /* Try to fit the constant into 8 bits by shuffling the value in the
649 register operand.
650 Doing that usually results in smaller code as the constants in the
651 pools are avoided (32 bit constant = load + constant = 6 bytes).
652 However, if the constant load (LS insn) can be hoisted insn dependencies
653 can be avoided and chances for parallel execution increase. The common
654 usage pattern is:
655 - load reg from mem
656 - test bits
657 - conditional branch
658
659 FIXME: For now we do that only when optimizing for size until there is
660 a better heuristic.
661
662 FIXME: If there are multiple tst insns in the block with the same
663 constant, avoid the #imm variant to avoid R0 loads. Use the 'tst Rn,Rm'
664 variant instead and load the constant into a reg. For that we'd need
665 to do some analysis. */
666
667 if (CONST_OK_FOR_K08 (op1val))
668 {
669 /* Do nothing. */
670 }
671 else if ((op1val & 0xFFFF) == 0
672 && CONST_OK_FOR_K08 (op1val >> 16) && optimize_size)
673 {
674 /* Use a swap.w insn to do a shift + reg copy (to R0) in one insn. */
675 op1val = op1val >> 16;
676 rtx r = gen_reg_rtx (SImode);
677 emit_insn (gen_rotlsi3_16 (r, operands[0]));
678 operands[0] = r;
679 }
680 else if ((op1val & 0xFF) == 0
681 && CONST_OK_FOR_K08 (op1val >> 8) && optimize_size)
682 {
683 /* Use a swap.b insn to do a shift + reg copy (to R0) in one insn. */
684 op1val = op1val >> 8;
685 rtx r = gen_reg_rtx (SImode);
686 emit_insn (gen_swapbsi2 (r, operands[0]));
687 operands[0] = r;
688 }
689 else if ((op1val & 3) == 0
690 && CONST_OK_FOR_K08 (op1val >> 2) && optimize_size)
691 {
692 op1val = op1val >> 2;
693 rtx r = gen_reg_rtx (SImode);
694 emit_insn (gen_lshrsi3_k (r, operands[0], GEN_INT (2)));
695 operands[0] = r;
696 }
697 else if ((op1val & 1) == 0
698 && CONST_OK_FOR_K08 (op1val >> 1) && optimize_size)
699 {
700 op1val = op1val >> 1;
701 rtx r = gen_reg_rtx (SImode);
702 emit_insn (gen_shlr (r, operands[0]));
703 operands[0] = r;
704 }
705
706 operands[1] = GEN_INT (op1val);
707
708 if (!satisfies_constraint_K08 (operands[1]))
709 operands[1] = force_reg (SImode, operands[1]);
710
711 emit_insn (gen_tstsi_t (operands[0], operands[1]));
712 DONE;
713 }
714 [(set_attr "type" "mt_group")])
715
716 ;; This pattern is used by combine when testing QI/HImode subregs with a
717 ;; negative constant. Ignore high bits by masking them out in the constant.
718 (define_insn_and_split "*tst<mode>_t"
719 [(set (reg:SI T_REG)
720 (eq:SI (subreg:SI
721 (and:QIHI (match_operand:QIHI 0 "arith_reg_operand")
722 (match_operand 1 "const_int_operand")) 0)
723 (const_int 0)))]
724 "TARGET_SH1 && can_create_pseudo_p ()"
725 "#"
726 "&& 1"
727 [(set (reg:SI T_REG)
728 (eq:SI (and:SI (match_dup 0) (match_dup 1)) (const_int 0)))]
729 {
730 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
731 operands[1] = GEN_INT (INTVAL (operands[1])
732 & (<MODE>mode == HImode ? 0xFFFF : 0xFF));
733 })
734
735 ;; This pattern might be risky because it also tests the upper bits and not
736 ;; only the subreg. We have to check whether the operands have been sign
737 ;; or zero extended. In the worst case, a zero extension has to be inserted
738 ;; to mask out the unwanted bits.
739 (define_insn_and_split "*tst<mode>_t_subregs"
740 [(set (reg:SI T_REG)
741 (eq:SI
742 (subreg:QIHI
743 (and:SI (match_operand:SI 0 "arith_reg_operand")
744 (match_operand:SI 1 "arith_reg_operand")) <lowpart_le>)
745 (const_int 0)))]
746 "TARGET_SH1 && TARGET_LITTLE_ENDIAN && can_create_pseudo_p ()"
747 "#"
748 "&& !sh_in_recog_treg_set_expr ()"
749 [(const_int 0)]
750 {
751 sh_split_tst_subregs (curr_insn, <MODE>mode, <lowpart_le>, operands);
752 DONE;
753 })
754
755 (define_insn_and_split "*tst<mode>_t_subregs"
756 [(set (reg:SI T_REG)
757 (eq:SI
758 (subreg:QIHI
759 (and:SI (match_operand:SI 0 "arith_reg_operand")
760 (match_operand:SI 1 "arith_reg_operand")) <lowpart_be>)
761 (const_int 0)))]
762 "TARGET_SH1 && TARGET_BIG_ENDIAN && can_create_pseudo_p ()"
763 "#"
764 "&& !sh_in_recog_treg_set_expr ()"
765 [(const_int 0)]
766 {
767 sh_split_tst_subregs (curr_insn, <MODE>mode, <lowpart_be>, operands);
768 DONE;
769 })
770
771 ;; Extract contiguous bits and compare them against zero.
772 ;; Notice that this will not be used for single bits. Special single bit
773 ;; extraction patterns are in the 'bit field extract patterns' section.
774 (define_insn_and_split "*tst<mode>_t_zero_extract"
775 [(set (reg:SI T_REG)
776 (eq:SI (zero_extract:SI (match_operand:QIHISI 0 "arith_reg_operand")
777 (match_operand 1 "const_int_operand")
778 (match_operand 2 "const_int_operand"))
779 (const_int 0)))]
780 "TARGET_SH1 && can_create_pseudo_p ()"
781 "#"
782 "&& 1"
783 [(set (reg:SI T_REG)
784 (eq:SI (and:SI (match_dup 0) (match_dup 1)) (const_int 0)))]
785 {
786 operands[1] = GEN_INT (ZERO_EXTRACT_ANDMASK (operands[1], operands[2]));
787 if (GET_MODE (operands[0]) != SImode)
788 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
789 })
790
791 ;; Convert '(reg << shift) & mask' into 'reg & (mask >> shift)'.
792 ;; The shifted-out bits in the mask will always be zero, since the
793 ;; shifted-in bits in the reg will also be always zero.
794 (define_insn_and_split "*tstsi_t_shift_mask"
795 [(set (reg:SI T_REG)
796 (eq:SI (and:SI (ashift:SI (match_operand:SI 0 "arith_reg_operand")
797 (match_operand 1 "const_int_operand"))
798 (match_operand 2 "const_int_operand"))
799 (const_int 0)))]
800 "TARGET_SH1 && can_create_pseudo_p ()"
801 "#"
802 "&& 1"
803 [(set (reg:SI T_REG)
804 (eq:SI (and:SI (match_dup 0) (match_dup 2)) (const_int 0)))]
805 {
806 operands[2] = GEN_INT (INTVAL (operands[2]) >> INTVAL (operands[1]));
807 })
808
809 (define_insn "cmpeqsi_t"
810 [(set (reg:SI T_REG)
811 (eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
812 (match_operand:SI 1 "arith_operand" "N,rI08,r")))]
813 "TARGET_SH1"
814 "@
815 tst %0,%0
816 cmp/eq %1,%0
817 cmp/eq %1,%0"
818 [(set_attr "type" "mt_group")])
819
820 ;; Sometimes combine fails to form the (eq (and (op) (op)) 0) tst insn.
821 ;; Try to fix that in the split1 pass by looking for the previous set
822 ;; of the tested op. Also see if there is a preceeding sign/zero
823 ;; extension that can be avoided.
824 (define_split
825 [(set (reg:SI T_REG)
826 (eq:SI (match_operand:SI 0 "arith_reg_operand") (const_int 0)))]
827 "TARGET_SH1 && can_create_pseudo_p () && optimize
828 && !sh_in_recog_treg_set_expr ()"
829 [(set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))]
830 {
831 if (dump_file)
832 fprintf (dump_file, "cmpeqsi_t: trying to optimize const_int 0\n");
833
834 /* If the tested reg is not dead after this insn, it's probably used by
835 something else after the comparison. It's probably better to leave
836 it as it is. */
837 if (find_regno_note (curr_insn, REG_DEAD, REGNO (operands[0])) == NULL_RTX)
838 FAIL;
839
840 /* FIXME: Maybe also search the predecessor basic blocks to catch
841 more cases. */
842 set_of_reg op = sh_find_set_of_reg (operands[0], curr_insn,
843 prev_nonnote_insn_bb);
844
845 if (op.set_src != NULL && GET_CODE (op.set_src) == AND
846 && !sh_insn_operands_modified_between_p (op.insn, op.insn, curr_insn))
847 {
848 if (dump_file)
849 fprintf (dump_file, "cmpeqsi_t: found preceeding and in insn %d\n",
850 INSN_UID (op.insn));
851
852 if (!(arith_reg_operand (XEXP (op.set_src, 0), SImode)
853 && (arith_reg_operand (XEXP (op.set_src, 1), SImode)
854 || CONST_INT_P (XEXP (op.set_src, 1)))))
855 FAIL;
856
857 /* Assume that the operands of the andsi insn are compatible with the
858 operands of the tstsi_t insn, which is generally the case. */
859 if (dump_file)
860 fprintf (dump_file, "cmpeqsi_t: replacing with tstsi_t\n");
861 emit_insn (gen_tstsi_t (XEXP (op.set_src, 0), XEXP (op.set_src, 1)));
862 DONE;
863 }
864
865 /* Converting HImode into tests against 0xFFFF tends to increase the code
866 size, as it will create constant pool entries. Disable it for now. */
867 const bool enable_himode = false;
868
869 /* FIXME: try to keep the (eq (reg) (const_int 0)). Even if the zero
870 extended reg is used after this insn, if we know that _before_ the zero
871 extension the value was loaded via sign extending mem load, we can just
872 use the value of the mem load directly. */
873 sh_extending_set_of_reg eop = sh_find_extending_set_of_reg (operands[0],
874 curr_insn);
875
876 if (eop.ext_code != UNKNOWN
877 && (eop.from_mode == QImode || (eop.from_mode == HImode && enable_himode))
878 && eop.can_use_as_unextended_reg ()
879 && !reg_used_between_p (operands[0], eop.insn, curr_insn))
880 {
881 /* Bypass the sign/zero extension and test against the bit mask, but
882 only if it's the only use of the sign/zero extracted value.
883 Otherwise we'd be introducing new constants in the pool. */
884 if (dump_file)
885 fprintf (dump_file, "cmpeqsi_t: bypassing sign/zero extension in "
886 "insn %d and using tstsi_t\n", INSN_UID (op.insn));
887
888 emit_insn (gen_tstsi_t (
889 eop.use_as_unextended_reg (curr_insn),
890 GEN_INT (eop.from_mode == QImode ? 0xFF : 0xFFFF)));
891 DONE;
892 }
893
894 if (dump_file)
895 fprintf (dump_file, "cmpeqsi_t: nothing optimized\n");
896 FAIL;
897 })
898
899 (define_insn "cmpgtsi_t"
900 [(set (reg:SI T_REG)
901 (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
902 (match_operand:SI 1 "arith_reg_or_0_operand" "N,r")))]
903 "TARGET_SH1"
904 "@
905 cmp/pl %0
906 cmp/gt %1,%0"
907 [(set_attr "type" "mt_group")])
908
909 (define_insn "cmpgesi_t"
910 [(set (reg:SI T_REG)
911 (ge:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
912 (match_operand:SI 1 "arith_reg_or_0_operand" "N,r")))]
913 "TARGET_SH1"
914 "@
915 cmp/pz %0
916 cmp/ge %1,%0"
917 [(set_attr "type" "mt_group")])
918
919 ;; Recombine a cmp/pz followed by a nott into a shll.
920 ;; On non-SH2A recombine a cmp/pz followed by a movrt into shll-movt.
921 ;; On SH2A cmp/pz-movrt is slightly better, as it does not mutate the input.
922 (define_split
923 [(set (reg:SI T_REG)
924 (ge:SI (match_operand:SI 0 "arith_reg_operand") (const_int 0)))]
925
926 "TARGET_SH1 && can_create_pseudo_p () && optimize
927 && !sh_in_recog_treg_set_expr ()"
928 [(const_int 0)]
929 {
930 if (dump_file)
931 fprintf (dump_file, "cmpgesi_t: trying to optimize for const_int 0\n");
932
933 rtx_insn* i = next_nonnote_insn_bb (curr_insn);
934
935 if (dump_file)
936 {
937 fprintf (dump_file, "cmpgesi_t: following insn is \n");
938 print_rtl_single (dump_file, i);
939 fprintf (dump_file, "\n");
940 }
941
942 if (sh_is_nott_insn (i))
943 {
944 if (dump_file)
945 fprintf (dump_file,
946 "cmpgesi_t: replacing (cmp/pz, nott) with (shll)\n");
947 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
948 set_insn_deleted (i);
949 DONE;
950 }
951
952 /* On non-SH2A negc is used as movrt replacement, which sets T = 1.
953 Thus we can remove it only if T is marked as dead afterwards. */
954 if (rtx dest_reg = !TARGET_SH2A
955 && sh_reg_dead_or_unused_after_insn (i, T_REG)
956 ? sh_movrt_set_dest (i) : NULL)
957 {
958 if (dump_file)
959 fprintf (dump_file,
960 "cmpgesi_t: replacing (cmp/pz, movrt) with (shll, movt)\n");
961 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
962 add_reg_note (emit_insn (gen_movt (dest_reg, get_t_reg_rtx ())),
963 REG_DEAD, get_t_reg_rtx ());
964 set_insn_deleted (i);
965 DONE;
966 }
967
968 if (dump_file)
969 fprintf (dump_file, "cmpgesi_t: nothing optimized\n");
970
971 FAIL;
972 })
973
974 ;; FIXME: This is actually wrong. There is no way to literally move a
975 ;; general reg to t reg. Luckily, it seems that this pattern will be only
976 ;; used when the general reg is known be either '0' or '1' during combine.
977 ;; What we actually need is reg != 0 -> T, but we have only reg == 0 -> T.
978 ;; Due to interactions with other patterns, combine fails to pick the latter
979 ;; and invert the dependent logic.
980 (define_insn "*negtstsi"
981 [(set (reg:SI T_REG) (match_operand:SI 0 "arith_reg_operand" "r"))]
982 "TARGET_SH1 && !sh_in_recog_treg_set_expr ()"
983 "cmp/pl %0"
984 [(set_attr "type" "mt_group")])
985
986 ;; Some integer sign comparison patterns can be realized with the div0s insn.
987 ;; div0s Rm,Rn T = (Rm >> 31) ^ (Rn >> 31)
988 ;;
989 ;; The 'cmp_div0s' pattern is our canonical form, into which all the other
990 ;; variations are converted. The negative forms will split into a trailing
991 ;; nott sequence, which will be eliminated either by the
992 ;; 'any_treg_expr_to_reg' pattern, or by the 'sh_treg_combine' pass.
993 (define_insn "cmp_div0s"
994 [(set (reg:SI T_REG)
995 (lshiftrt:SI (xor:SI (match_operand:SI 0 "arith_reg_operand" "%r")
996 (match_operand:SI 1 "arith_reg_operand" "r"))
997 (const_int 31)))]
998 "TARGET_SH1"
999 "div0s %0,%1"
1000 [(set_attr "type" "arith")])
1001
1002 (define_insn_and_split "*cmp_div0s_1"
1003 [(set (reg:SI T_REG)
1004 (xor:SI (ge:SI (match_operand:SI 0 "arith_reg_operand")
1005 (const_int 0))
1006 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1007 (const_int 0))))]
1008 "TARGET_SH1 && can_create_pseudo_p ()"
1009 "#"
1010 "&& 1"
1011 [(set (reg:SI T_REG)
1012 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))])
1013
1014 (define_insn_and_split "*cmp_div0s_2"
1015 [(set (reg:SI T_REG)
1016 (eq:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
1017 (const_int 31))
1018 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1019 (const_int 0))))]
1020 "TARGET_SH1 && can_create_pseudo_p ()"
1021 "#"
1022 "&& 1"
1023 [(set (reg:SI T_REG)
1024 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))])
1025
1026 (define_insn_and_split "*cmp_div0s_3"
1027 [(set (reg:SI T_REG)
1028 (eq:SI (ge:SI (match_operand:SI 0 "arith_reg_operand")
1029 (const_int 0))
1030 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1031 (const_int 0))))]
1032 "TARGET_SH1 && can_create_pseudo_p ()"
1033 "#"
1034 "&& 1"
1035 [(set (reg:SI T_REG)
1036 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1037 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1038
1039 (define_insn_and_split "*cmp_div0s_4"
1040 [(set (reg:SI T_REG)
1041 (ge:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
1042 (match_operand:SI 1 "arith_reg_operand"))
1043 (const_int 0)))]
1044 "TARGET_SH1 && can_create_pseudo_p ()"
1045 "#"
1046 "&& 1"
1047 [(set (reg:SI T_REG)
1048 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1049 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1050
1051 (define_insn_and_split "*cmp_div0s_5"
1052 [(set (reg:SI T_REG)
1053 (xor:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
1054 (const_int 31))
1055 (ge:SI (match_operand:SI 1 "arith_reg_operand")
1056 (const_int 0))))]
1057 "TARGET_SH1 && can_create_pseudo_p ()"
1058 "#"
1059 "&& 1"
1060 [(set (reg:SI T_REG)
1061 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1062 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1063
1064 (define_insn_and_split "*cmp_div0s_6"
1065 [(set (reg:SI T_REG)
1066 (eq:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
1067 (const_int 31))
1068 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
1069 (const_int 31))))]
1070 "TARGET_SH1 && can_create_pseudo_p ()"
1071 "#"
1072 "&& 1"
1073 [(set (reg:SI T_REG)
1074 (lshiftrt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 31)))
1075 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1076
1077 ;; In some cases, it might be shorter to get a tested bit into bit 31 and
1078 ;; use div0s. Otherwise it's usually better to just leave the xor and tst
1079 ;; sequence. The only thing we can try to do here is avoiding the large
1080 ;; tst constant.
1081 (define_insn_and_split "*cmp_div0s_7"
1082 [(set (reg:SI T_REG)
1083 (zero_extract:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
1084 (match_operand:SI 1 "arith_reg_operand"))
1085 (const_int 1)
1086 (match_operand 2 "const_int_operand")))]
1087 "TARGET_SH1 && can_create_pseudo_p ()
1088 && (INTVAL (operands[2]) == 7 || INTVAL (operands[2]) == 15
1089 || INTVAL (operands[2]) == 23 || INTVAL (operands[2]) == 29
1090 || INTVAL (operands[2]) == 30 || INTVAL (operands[2]) == 31)"
1091 "#"
1092 "&& 1"
1093 [(const_int 0)]
1094 {
1095 const int bitpos = INTVAL (operands[2]);
1096
1097 rtx op0 = gen_reg_rtx (SImode);
1098 rtx op1 = gen_reg_rtx (SImode);
1099
1100 if (bitpos == 23 || bitpos == 30 || bitpos == 29)
1101 {
1102 emit_insn (gen_ashlsi3 (op0, operands[0], GEN_INT (31 - bitpos)));
1103 emit_insn (gen_ashlsi3 (op1, operands[1], GEN_INT (31 - bitpos)));
1104 }
1105 else if (bitpos == 15)
1106 {
1107 emit_insn (gen_extendhisi2 (op0, gen_lowpart (HImode, operands[0])));
1108 emit_insn (gen_extendhisi2 (op1, gen_lowpart (HImode, operands[1])));
1109 }
1110 else if (bitpos == 7)
1111 {
1112 emit_insn (gen_extendqisi2 (op0, gen_lowpart (QImode, operands[0])));
1113 emit_insn (gen_extendqisi2 (op1, gen_lowpart (QImode, operands[1])));
1114 }
1115 else if (bitpos == 31)
1116 {
1117 op0 = operands[0];
1118 op1 = operands[1];
1119 }
1120 else
1121 gcc_unreachable ();
1122
1123 emit_insn (gen_cmp_div0s (op0, op1));
1124 DONE;
1125 })
1126
1127 ;; For bits 0..7 using a xor and tst #imm,r0 sequence seems to be better.
1128 ;; Thus allow the following patterns only for higher bit positions where
1129 ;; we it's more likely to save the large tst constant.
1130 (define_insn_and_split "*cmp_div0s_8"
1131 [(set (reg:SI T_REG)
1132 (eq:SI (zero_extract:SI (match_operand:SI 0 "arith_reg_operand")
1133 (const_int 1)
1134 (match_operand 2 "const_int_operand"))
1135 (zero_extract:SI (match_operand:SI 1 "arith_reg_operand")
1136 (const_int 1)
1137 (match_dup 2))))]
1138 "TARGET_SH1 && can_create_pseudo_p ()
1139 && (INTVAL (operands[2]) == 15
1140 || INTVAL (operands[2]) == 23 || INTVAL (operands[2]) == 29
1141 || INTVAL (operands[2]) == 30 || INTVAL (operands[2]) == 31)"
1142 "#"
1143 "&& 1"
1144 [(set (reg:SI T_REG)
1145 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
1146 (const_int 1) (match_dup 2)))
1147 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1148
1149 (define_insn_and_split "*cmp_div0s_9"
1150 [(set (reg:SI T_REG)
1151 (zero_extract:SI (xor:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
1152 (match_operand:SI 1 "arith_reg_operand"))
1153 (match_operand 2 "const_int_operand"))
1154 (const_int 1)
1155 (match_operand 3 "const_int_operand")))]
1156 "TARGET_SH1 && can_create_pseudo_p ()
1157 && (INTVAL (operands[2]) & 0xFFFFFFFF) == (1U << INTVAL (operands[3]))
1158 && (INTVAL (operands[3]) == 15
1159 || INTVAL (operands[3]) == 23 || INTVAL (operands[3]) == 29
1160 || INTVAL (operands[3]) == 30 || INTVAL (operands[3]) == 31)"
1161 "#"
1162 "&& 1"
1163 [(set (reg:SI T_REG)
1164 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
1165 (const_int 1) (match_dup 3)))
1166 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
1167
1168 ;; -------------------------------------------------------------------------
1169 ;; SImode compare and branch
1170 ;; -------------------------------------------------------------------------
1171
1172 (define_expand "cbranchsi4"
1173 [(set (pc)
1174 (if_then_else (match_operator 0 "comparison_operator"
1175 [(match_operand:SI 1 "arith_operand" "")
1176 (match_operand:SI 2 "arith_operand" "")])
1177 (label_ref (match_operand 3 "" ""))
1178 (pc)))
1179 (clobber (reg:SI T_REG))]
1180 "can_create_pseudo_p ()"
1181 {
1182 expand_cbranchsi4 (operands, LAST_AND_UNUSED_RTX_CODE, -1);
1183 DONE;
1184 })
1185
1186 ;; Combine patterns to invert compare and branch operations for which we
1187 ;; don't have actual comparison insns. These patterns are used in cases
1188 ;; which appear after the initial cbranchsi expansion, which also does
1189 ;; some condition inversion.
1190 (define_split
1191 [(set (pc)
1192 (if_then_else (ne (match_operand:SI 0 "arith_reg_operand" "")
1193 (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1194 (label_ref (match_operand 2))
1195 (pc)))
1196 (clobber (reg:SI T_REG))]
1197 "TARGET_SH1"
1198 [(set (reg:SI T_REG) (eq:SI (match_dup 0) (match_dup 1)))
1199 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1200 (label_ref (match_dup 2))
1201 (pc)))])
1202
1203 ;; FIXME: These don't seem to have any effect on the generated cbranch code
1204 ;; anymore, but only on some register allocation choices.
1205 (define_split
1206 [(set (pc)
1207 (if_then_else (le (match_operand:SI 0 "arith_reg_operand" "")
1208 (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1209 (label_ref (match_operand 2))
1210 (pc)))
1211 (clobber (reg:SI T_REG))]
1212 "TARGET_SH1"
1213 [(set (reg:SI T_REG) (gt:SI (match_dup 0) (match_dup 1)))
1214 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1215 (label_ref (match_dup 2))
1216 (pc)))])
1217
1218 (define_split
1219 [(set (pc)
1220 (if_then_else (lt (match_operand:SI 0 "arith_reg_operand" "")
1221 (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1222 (label_ref (match_operand 2))
1223 (pc)))
1224 (clobber (reg:SI T_REG))]
1225 "TARGET_SH1"
1226 [(set (reg:SI T_REG) (ge:SI (match_dup 0) (match_dup 1)))
1227 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1228 (label_ref (match_dup 2))
1229 (pc)))])
1230
1231 (define_split
1232 [(set (pc)
1233 (if_then_else (leu (match_operand:SI 0 "arith_reg_operand" "")
1234 (match_operand:SI 1 "arith_reg_operand" ""))
1235 (label_ref (match_operand 2))
1236 (pc)))
1237 (clobber (reg:SI T_REG))]
1238 "TARGET_SH1"
1239 [(set (reg:SI T_REG) (gtu:SI (match_dup 0) (match_dup 1)))
1240 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1241 (label_ref (match_dup 2))
1242 (pc)))])
1243
1244 (define_split
1245 [(set (pc)
1246 (if_then_else (ltu (match_operand:SI 0 "arith_reg_operand" "")
1247 (match_operand:SI 1 "arith_reg_operand" ""))
1248 (label_ref (match_operand 2))
1249 (pc)))
1250 (clobber (reg:SI T_REG))]
1251 "TARGET_SH1"
1252 [(set (reg:SI T_REG) (geu:SI (match_dup 0) (match_dup 1)))
1253 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1254 (label_ref (match_dup 2))
1255 (pc)))])
1256
1257 ;; -------------------------------------------------------------------------
1258 ;; SImode unsigned integer comparisons
1259 ;; -------------------------------------------------------------------------
1260
1261 ;; Usually comparisons of 'unsigned int >= 0' are optimized away completely.
1262 ;; However, especially when optimizations are off (e.g. -O0) such comparisons
1263 ;; might remain and we have to handle them. If the '>= 0' case wasn't
1264 ;; handled here, something else would just load a '0' into the second operand
1265 ;; and do the comparison. We can do slightly better by just setting the
1266 ;; T bit to '1'.
1267 (define_insn_and_split "cmpgeusi_t"
1268 [(set (reg:SI T_REG)
1269 (geu:SI (match_operand:SI 0 "arith_reg_operand" "r")
1270 (match_operand:SI 1 "arith_reg_or_0_operand" "r")))]
1271 "TARGET_SH1"
1272 "cmp/hs %1,%0"
1273 "&& satisfies_constraint_Z (operands[1])"
1274 [(set (reg:SI T_REG) (const_int 1))]
1275 ""
1276 [(set_attr "type" "mt_group")])
1277
1278 (define_insn "cmpgtusi_t"
1279 [(set (reg:SI T_REG)
1280 (gtu:SI (match_operand:SI 0 "arith_reg_operand" "r")
1281 (match_operand:SI 1 "arith_reg_operand" "r")))]
1282 "TARGET_SH1"
1283 "cmp/hi %1,%0"
1284 [(set_attr "type" "mt_group")])
1285 \f
1286 ;; -------------------------------------------------------------------------
1287 ;; DImode compare and branch
1288 ;; -------------------------------------------------------------------------
1289
1290 ;; arith3 patterns don't work well with the sh4-300 branch prediction mechanism.
1291 ;; Therefore, we aim to have a set of three branches that go straight to the
1292 ;; destination, i.e. only one of them is taken at any one time.
1293 ;; This mechanism should also be slightly better for the sh4-200.
1294
1295 (define_expand "cbranchdi4"
1296 [(set (pc)
1297 (if_then_else (match_operator 0 "comparison_operator"
1298 [(match_operand:DI 1 "arith_operand")
1299 (match_operand:DI 2 "arith_operand")])
1300 (label_ref (match_operand 3))
1301 (pc)))
1302 (clobber (reg:SI T_REG))]
1303 "TARGET_SH2 && can_create_pseudo_p ()"
1304 {
1305 if (!expand_cbranchdi4 (operands, GET_CODE (operands[0])))
1306 FAIL;
1307 DONE;
1308 })
1309
1310 ;; -------------------------------------------------------------------------
1311 ;; DImode signed integer comparisons
1312 ;; -------------------------------------------------------------------------
1313
1314 (define_insn ""
1315 [(set (reg:SI T_REG)
1316 (eq:SI (and:DI (match_operand:DI 0 "arith_reg_operand" "r")
1317 (match_operand:DI 1 "arith_operand" "r"))
1318 (const_int 0)))]
1319 "TARGET_SH1"
1320 {
1321 return output_branchy_insn (EQ, "tst\t%S1,%S0;bf\t%l9;tst\t%R1,%R0",
1322 insn, operands);
1323 }
1324 [(set_attr "length" "6")
1325 (set_attr "type" "arith3b")])
1326
1327 (define_insn "cmpeqdi_t"
1328 [(set (reg:SI T_REG)
1329 (eq:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1330 (match_operand:DI 1 "arith_reg_or_0_operand" "N,r")))]
1331 "TARGET_SH1"
1332 {
1333 static const char* alt[] =
1334 {
1335 "tst %S0,%S0" "\n"
1336 " bf 0f" "\n"
1337 " tst %R0,%R0" "\n"
1338 "0:",
1339
1340 "cmp/eq %S1,%S0" "\n"
1341 " bf 0f" "\n"
1342 " cmp/eq %R1,%R0" "\n"
1343 "0:"
1344 };
1345 return alt[which_alternative];
1346 }
1347 [(set_attr "length" "6")
1348 (set_attr "type" "arith3b")])
1349
1350 (define_split
1351 [(set (reg:SI T_REG)
1352 (eq:SI (match_operand:DI 0 "arith_reg_operand" "")
1353 (match_operand:DI 1 "arith_reg_or_0_operand" "")))]
1354 ;; If we applied this split when not optimizing, it would only be
1355 ;; applied during the machine-dependent reorg, when no new basic blocks
1356 ;; may be created.
1357 "TARGET_SH1 && reload_completed && optimize"
1358 [(set (reg:SI T_REG) (eq:SI (match_dup 2) (match_dup 3)))
1359 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1360 (label_ref (match_dup 6))
1361 (pc)))
1362 (set (reg:SI T_REG) (eq:SI (match_dup 4) (match_dup 5)))
1363 (match_dup 6)]
1364 {
1365 operands[2] = gen_highpart (SImode, operands[0]);
1366 operands[3] = operands[1] == const0_rtx
1367 ? const0_rtx
1368 : gen_highpart (SImode, operands[1]);
1369 operands[4] = gen_lowpart (SImode, operands[0]);
1370 operands[5] = gen_lowpart (SImode, operands[1]);
1371 operands[6] = gen_label_rtx ();
1372 })
1373
1374 (define_insn "cmpgtdi_t"
1375 [(set (reg:SI T_REG)
1376 (gt:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1377 (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
1378 "TARGET_SH2"
1379 {
1380 static const char* alt[] =
1381 {
1382 "cmp/eq %S1,%S0" "\n"
1383 " bf{.|/}s 0f" "\n"
1384 " cmp/gt %S1,%S0" "\n"
1385 " cmp/hi %R1,%R0" "\n"
1386 "0:",
1387
1388 "tst %S0,%S0" "\n"
1389 " bf{.|/}s 0f" "\n"
1390 " cmp/pl %S0" "\n"
1391 " cmp/hi %S0,%R0" "\n"
1392 "0:"
1393 };
1394 return alt[which_alternative];
1395 }
1396 [(set_attr "length" "8")
1397 (set_attr "type" "arith3")])
1398
1399 (define_insn "cmpgedi_t"
1400 [(set (reg:SI T_REG)
1401 (ge:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1402 (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
1403 "TARGET_SH2"
1404 {
1405 static const char* alt[] =
1406 {
1407 "cmp/eq %S1,%S0" "\n"
1408 " bf{.|/}s 0f" "\n"
1409 " cmp/ge %S1,%S0" "\n"
1410 " cmp/hs %R1,%R0" "\n"
1411 "0:",
1412
1413 "cmp/pz %S0"
1414 };
1415 return alt[which_alternative];
1416 }
1417 [(set_attr "length" "8,2")
1418 (set_attr "type" "arith3,mt_group")])
1419 \f
1420 ;; -------------------------------------------------------------------------
1421 ;; DImode unsigned integer comparisons
1422 ;; -------------------------------------------------------------------------
1423
1424 (define_insn "cmpgeudi_t"
1425 [(set (reg:SI T_REG)
1426 (geu:SI (match_operand:DI 0 "arith_reg_operand" "r")
1427 (match_operand:DI 1 "arith_reg_operand" "r")))]
1428 "TARGET_SH2"
1429 {
1430 return "cmp/eq %S1,%S0" "\n"
1431 " bf{.|/}s 0f" "\n"
1432 " cmp/hs %S1,%S0" "\n"
1433 " cmp/hs %R1,%R0" "\n"
1434 "0:";
1435 }
1436 [(set_attr "length" "8")
1437 (set_attr "type" "arith3")])
1438
1439 (define_insn "cmpgtudi_t"
1440 [(set (reg:SI T_REG)
1441 (gtu:SI (match_operand:DI 0 "arith_reg_operand" "r")
1442 (match_operand:DI 1 "arith_reg_operand" "r")))]
1443 "TARGET_SH2"
1444 {
1445 return "cmp/eq %S1,%S0" "\n"
1446 " bf{.|/}s 0f" "\n"
1447 " cmp/hi %S1,%S0" "\n"
1448 " cmp/hi %R1,%R0" "\n"
1449 "0:";
1450 }
1451 [(set_attr "length" "8")
1452 (set_attr "type" "arith3")])
1453
1454 ;; -------------------------------------------------------------------------
1455 ;; Conditional move instructions
1456 ;; -------------------------------------------------------------------------
1457
1458 (define_insn "*movsicc_t_false"
1459 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1460 (if_then_else (eq (reg:SI T_REG) (const_int 0))
1461 (match_operand:SI 1 "general_movsrc_operand" "r,I08")
1462 (match_operand:SI 2 "arith_reg_operand" "0,0")))]
1463 "TARGET_PRETEND_CMOVE
1464 && (arith_reg_operand (operands[1], SImode)
1465 || (immediate_operand (operands[1], SImode)
1466 && satisfies_constraint_I08 (operands[1])))"
1467 {
1468 return "bt 0f" "\n"
1469 " mov %1,%0" "\n"
1470 "0:";
1471 }
1472 [(set_attr "type" "mt_group,arith") ;; poor approximation
1473 (set_attr "length" "4")])
1474
1475 (define_insn "*movsicc_t_true"
1476 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1477 (if_then_else (ne (reg:SI T_REG) (const_int 0))
1478 (match_operand:SI 1 "general_movsrc_operand" "r,I08")
1479 (match_operand:SI 2 "arith_reg_operand" "0,0")))]
1480 "TARGET_PRETEND_CMOVE
1481 && (arith_reg_operand (operands[1], SImode)
1482 || (immediate_operand (operands[1], SImode)
1483 && satisfies_constraint_I08 (operands[1])))"
1484 {
1485 return "bf 0f" "\n"
1486 " mov %1,%0" "\n"
1487 "0:";
1488 }
1489 [(set_attr "type" "mt_group,arith") ;; poor approximation
1490 (set_attr "length" "4")])
1491
1492 (define_expand "movsicc"
1493 [(set (match_operand:SI 0 "arith_reg_dest" "")
1494 (if_then_else:SI (match_operand 1 "comparison_operator" "")
1495 (match_operand:SI 2 "arith_reg_or_0_operand" "")
1496 (match_operand:SI 3 "arith_reg_operand" "")))]
1497 "TARGET_PRETEND_CMOVE"
1498 {
1499 rtx_code code = GET_CODE (operands[1]);
1500 rtx_code new_code = code;
1501 rtx op0 = XEXP (operands[1], 0);
1502 rtx op1 = XEXP (operands[1], 1);
1503
1504 if (! currently_expanding_to_rtl)
1505 FAIL;
1506
1507 switch (code)
1508 {
1509 case LT: case LE: case LEU: case LTU:
1510 if (GET_MODE_CLASS (GET_MODE (op0)) != MODE_INT)
1511 break;
1512 /* FALLTHRU */
1513 case NE:
1514 new_code = reverse_condition (code);
1515 break;
1516 case EQ: case GT: case GE: case GEU: case GTU:
1517 break;
1518 default:
1519 FAIL;
1520 }
1521
1522 sh_emit_scc_to_t (new_code, op0, op1);
1523 operands[1] = gen_rtx_fmt_ee (new_code == code ? NE : EQ, VOIDmode,
1524 gen_rtx_REG (SImode, T_REG), const0_rtx);
1525 })
1526
1527 ;; -------------------------------------------------------------------------
1528 ;; Addition instructions
1529 ;; -------------------------------------------------------------------------
1530
1531 (define_insn_and_split "adddi3"
1532 [(set (match_operand:DI 0 "arith_reg_dest")
1533 (plus:DI (match_operand:DI 1 "arith_reg_operand")
1534 (match_operand:DI 2 "arith_reg_operand")))
1535 (clobber (reg:SI T_REG))]
1536 "TARGET_SH1"
1537 "#"
1538 "&& can_create_pseudo_p ()"
1539 [(const_int 0)]
1540 {
1541 emit_insn (gen_clrt ());
1542 emit_insn (gen_addc (gen_lowpart (SImode, operands[0]),
1543 gen_lowpart (SImode, operands[1]),
1544 gen_lowpart (SImode, operands[2])));
1545 emit_insn (gen_addc (gen_highpart (SImode, operands[0]),
1546 gen_highpart (SImode, operands[1]),
1547 gen_highpart (SImode, operands[2])));
1548 DONE;
1549 })
1550
1551 (define_insn "addc"
1552 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1553 (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0")
1554 (match_operand:SI 2 "arith_reg_operand" "r"))
1555 (reg:SI T_REG)))
1556 (set (reg:SI T_REG)
1557 (ltu:SI (plus:SI (match_dup 1) (match_dup 2)) (match_dup 1)))]
1558 "TARGET_SH1"
1559 "addc %2,%0"
1560 [(set_attr "type" "arith")])
1561
1562 ;; A simplified version of the addc insn, where the exact value of the
1563 ;; T bit doesn't matter. This is easier for combine to pick up.
1564 ;; We allow a reg or 0 for one of the operands in order to be able to
1565 ;; do 'reg + T' sequences.
1566 (define_insn_and_split "*addc"
1567 [(set (match_operand:SI 0 "arith_reg_dest")
1568 (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand")
1569 (match_operand:SI 2 "arith_reg_or_0_operand"))
1570 (match_operand 3 "treg_set_expr")))
1571 (clobber (reg:SI T_REG))]
1572 "TARGET_SH1 && can_create_pseudo_p ()"
1573 "#"
1574 "&& 1"
1575 [(const_int 0)]
1576 {
1577 sh_treg_insns ti = sh_split_treg_set_expr (operands[3], curr_insn);
1578 if (ti.has_trailing_nott ())
1579 {
1580 if (operands[2] == const0_rtx)
1581 {
1582 /* op1 + 0 + (1 - T) = op1 + 1 - T = op1 - (-1) - T */
1583 remove_insn (ti.trailing_nott ());
1584 emit_insn (gen_subc (operands[0], operands[1],
1585 force_reg (SImode, GEN_INT (-1))));
1586 DONE;
1587 }
1588 else if (!TARGET_SH2A)
1589 {
1590 /* op1 + op2 + (1 - T) = op1 - (0 - op2 - 1) - T = op1 - ~op2 - T
1591 On SH2A keep the nott insn, because nott-addc sequence doesn't
1592 mutate the inputs. */
1593 remove_insn (ti.trailing_nott ());
1594 rtx tmp = gen_reg_rtx (SImode);
1595 emit_insn (gen_one_cmplsi2 (tmp, operands[2]));
1596 emit_insn (gen_subc (operands[0], operands[1], tmp));
1597 DONE;
1598 }
1599 }
1600
1601 emit_insn (gen_addc (operands[0], operands[1],
1602 force_reg (SImode, operands[2])));
1603 DONE;
1604 })
1605
1606 (define_insn_and_split "*addc"
1607 [(set (match_operand:SI 0 "arith_reg_dest")
1608 (plus:SI (plus:SI (match_operand 1 "treg_set_expr")
1609 (match_operand:SI 2 "arith_reg_operand"))
1610 (match_operand:SI 3 "arith_reg_operand")))
1611 (clobber (reg:SI T_REG))]
1612 "TARGET_SH1 && can_create_pseudo_p ()"
1613 "#"
1614 "&& 1"
1615 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 3))
1616 (match_dup 1)))
1617 (clobber (reg:SI T_REG))])])
1618
1619 (define_insn_and_split "*addc"
1620 [(set (match_operand:SI 0 "arith_reg_dest")
1621 (plus:SI (match_operand 1 "treg_set_expr")
1622 (plus:SI (match_operand:SI 2 "arith_reg_operand")
1623 (match_operand:SI 3 "arith_reg_operand"))))
1624 (clobber (reg:SI T_REG))]
1625 "TARGET_SH1 && can_create_pseudo_p ()"
1626 "#"
1627 "&& 1"
1628 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 3))
1629 (match_dup 1)))
1630 (clobber (reg:SI T_REG))])])
1631
1632 ;; Sometimes combine will try to do 'reg + (0-reg) + 1' if the *addc pattern
1633 ;; matched. Split this up into a simple sub add sequence, as this will save
1634 ;; us one sett insn.
1635 (define_insn_and_split "*minus_plus_one"
1636 [(set (match_operand:SI 0 "arith_reg_dest" "")
1637 (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "")
1638 (match_operand:SI 2 "arith_reg_operand" ""))
1639 (const_int 1)))]
1640 "TARGET_SH1"
1641 "#"
1642 "&& 1"
1643 [(set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))
1644 (set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))])
1645
1646
1647 ;; The tree optimiziers canonicalize
1648 ;; reg + (reg & 1)
1649 ;; into
1650 ;; (reg + 1) & -2
1651 ;;
1652 ;; On SH2A an add-bclr sequence will be used to handle this.
1653 ;; On non-SH2A re-emit the add-and sequence to improve register utilization.
1654 (define_insn_and_split "*round_int_even"
1655 [(set (match_operand:SI 0 "arith_reg_dest")
1656 (and:SI (plus:SI (match_operand:SI 1 "arith_reg_operand")
1657 (const_int 1))
1658 (const_int -2)))]
1659 "TARGET_SH1 && !TARGET_SH2A && can_create_pseudo_p ()
1660 && !reg_overlap_mentioned_p (operands[0], operands[1])"
1661 "#"
1662 "&& 1"
1663 [(set (match_dup 0) (const_int -2))
1664 (set (match_dup 2) (plus:SI (match_dup 1) (const_int 1)))
1665 (set (match_dup 0) (and:SI (match_dup 0) (match_dup 2)))]
1666 {
1667 operands[2] = gen_reg_rtx (SImode);
1668 })
1669
1670 ;; If the *round_int_even pattern is combined with another plus,
1671 ;; convert it into an addc pattern to emit an shlr-addc sequence.
1672 ;; This split is taken by combine on non-SH2A and SH2A.
1673 (define_split
1674 [(set (match_operand:SI 0 "arith_reg_dest")
1675 (plus:SI (and:SI (plus:SI (match_operand:SI 1 "arith_reg_operand")
1676 (const_int 1))
1677 (const_int -2))
1678 (match_operand:SI 2 "arith_reg_operand")))]
1679 "TARGET_SH1 && can_create_pseudo_p ()"
1680 [(parallel [(set (match_dup 0)
1681 (plus:SI (plus:SI (match_dup 1) (match_dup 2))
1682 (and:SI (match_dup 1) (const_int 1))))
1683 (clobber (reg:SI T_REG))])])
1684
1685 ;; Split 'reg + T' into 'reg + 0 + T' to utilize the addc insn.
1686 ;; If the 0 constant can be CSE-ed, this becomes a one instruction
1687 ;; operation, as opposed to sequences such as
1688 ;; movt r2
1689 ;; add r2,r3
1690 ;;
1691 ;; Even if the constant is not CSE-ed, a sequence such as
1692 ;; mov #0,r2
1693 ;; addc r2,r3
1694 ;; can be scheduled much better since the load of the constant can be
1695 ;; done earlier, before any comparison insns that store the result in
1696 ;; the T bit.
1697 ;; However, avoid things like 'reg + 1', which would expand into a
1698 ;; 3 insn sequence, instead of add #imm8.
1699 (define_insn_and_split "*addc_t_r"
1700 [(set (match_operand:SI 0 "arith_reg_dest")
1701 (plus:SI (match_operand 1 "treg_set_expr_not_const01")
1702 (match_operand:SI 2 "arith_reg_operand")))
1703 (clobber (reg:SI T_REG))]
1704 "TARGET_SH1 && can_create_pseudo_p ()"
1705 "#"
1706 "&& 1"
1707 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (const_int 0))
1708 (match_dup 1)))
1709 (clobber (reg:SI T_REG))])])
1710
1711 (define_insn_and_split "*addc_r_t"
1712 [(set (match_operand:SI 0 "arith_reg_dest")
1713 (plus:SI (match_operand:SI 1 "arith_reg_operand")
1714 (match_operand 2 "treg_set_expr_not_const01")))
1715 (clobber (reg:SI T_REG))]
1716 "TARGET_SH1 && can_create_pseudo_p ()"
1717 "#"
1718 "&& 1"
1719 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (const_int 0))
1720 (match_dup 2)))
1721 (clobber (reg:SI T_REG))])])
1722
1723 ;; Convert '2 * reg + T' into 'reg + reg + T'.
1724 (define_insn_and_split "*addc_2r_t"
1725 [(set (match_operand:SI 0 "arith_reg_dest")
1726 (plus:SI (match_operand 1 "treg_set_expr")
1727 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
1728 (const_int 1))))
1729 (clobber (reg:SI T_REG))]
1730 "TARGET_SH1 && can_create_pseudo_p ()"
1731 "#"
1732 "&& 1"
1733 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 2))
1734 (match_dup 1)))
1735 (clobber (reg:SI T_REG))])])
1736
1737 (define_insn_and_split "*addc_2r_t"
1738 [(set (match_operand:SI 0 "arith_reg_dest")
1739 (plus:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
1740 (const_int 1))
1741 (match_operand 2 "treg_set_expr")))
1742 (clobber (reg:SI T_REG))]
1743 "TARGET_SH1 && can_create_pseudo_p ()"
1744 "#"
1745 "&& 1"
1746 [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (match_dup 1))
1747 (match_dup 2)))
1748 (clobber (reg:SI T_REG))])])
1749
1750 ;; Convert '(op2 + T) - op3' into 'op2 + (-op3) + T'
1751 (define_insn_and_split "*addc_negreg_t"
1752 [(set (match_operand:SI 0 "arith_reg_dest")
1753 (minus:SI (plus:SI (match_operand 1 "treg_set_expr")
1754 (match_operand:SI 2 "arith_reg_operand"))
1755 (match_operand:SI 3 "arith_reg_operand")))
1756 (clobber (reg:SI T_REG))]
1757 "TARGET_SH1 && can_create_pseudo_p ()"
1758 "#"
1759 "&& 1"
1760 [(set (match_dup 4) (neg:SI (match_dup 3)))
1761 (parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 4))
1762 (match_dup 1)))
1763 (clobber (reg:SI T_REG))])]
1764 {
1765 operands[4] = gen_reg_rtx (SImode);
1766 })
1767
1768 (define_expand "addsi3"
1769 [(set (match_operand:SI 0 "arith_reg_dest")
1770 (plus:SI (match_operand:SI 1 "arith_reg_operand")
1771 (match_operand:SI 2 "arith_or_int_operand")))]
1772 ""
1773 {
1774 if (!arith_operand (operands[2], SImode))
1775 {
1776 if (!sh_lra_p () || reg_overlap_mentioned_p (operands[0], operands[1]))
1777 {
1778 emit_insn (gen_addsi3_scr (operands[0], operands[1], operands[2]));
1779 DONE;
1780 }
1781 }
1782 })
1783
1784 ;; The *addsi3_compact is made an insn_and_split and accepts actually
1785 ;; impossible constraints to make LRA's register elimination work well on SH.
1786 ;; The problem is that LRA expects something like
1787 ;; (set rA (plus rB (const_int N)))
1788 ;; to work. We can do that, but we have to split out an additional reg-reg
1789 ;; copy or constant load before the actual add insn.
1790 ;; Use u constraint for that case to avoid the invalid value in the stack
1791 ;; pointer.
1792 ;; This also results in better code when LRA is not used. However, we have
1793 ;; to use different sets of patterns and the order of these patterns is
1794 ;; important.
1795 ;; In some cases the constant zero might end up in operands[2] of the
1796 ;; patterns. We have to accept that and convert it into a reg-reg move.
1797 (define_insn_and_split "*addsi3_compact_lra"
1798 [(set (match_operand:SI 0 "arith_reg_dest" "=r,&u")
1799 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0,r")
1800 (match_operand:SI 2 "arith_or_int_operand" "rI08,rn")))]
1801 "TARGET_SH1 && sh_lra_p ()
1802 && (! reg_overlap_mentioned_p (operands[0], operands[1])
1803 || arith_operand (operands[2], SImode))"
1804 "@
1805 add %2,%0
1806 #"
1807 "&& reload_completed
1808 && ! reg_overlap_mentioned_p (operands[0], operands[1])"
1809 [(set (match_dup 0) (match_dup 2))
1810 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))]
1811 {
1812 /* Prefer 'mov r0,r1; add #imm8,r1' over 'mov #imm8,r1; add r0,r1' */
1813 if (satisfies_constraint_I08 (operands[2]))
1814 std::swap (operands[1], operands[2]);
1815 }
1816 [(set_attr "type" "arith")])
1817
1818 (define_insn_and_split "addsi3_scr"
1819 [(set (match_operand:SI 0 "arith_reg_dest" "=r,&u,&u")
1820 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0,r,r")
1821 (match_operand:SI 2 "arith_or_int_operand" "rI08,r,n")))
1822 (clobber (match_scratch:SI 3 "=X,X,&u"))]
1823 "TARGET_SH1"
1824 "@
1825 add %2,%0
1826 #
1827 #"
1828 "&& reload_completed"
1829 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1830 {
1831 if (operands[2] == const0_rtx)
1832 {
1833 emit_move_insn (operands[0], operands[1]);
1834 DONE;
1835 }
1836
1837 if (CONST_INT_P (operands[2]) && !satisfies_constraint_I08 (operands[2]))
1838 {
1839 if (reg_overlap_mentioned_p (operands[0], operands[1]))
1840 {
1841 emit_move_insn (operands[3], operands[2]);
1842 emit_move_insn (operands[0], operands[1]);
1843 operands[2] = operands[3];
1844 }
1845 else
1846 {
1847 emit_move_insn (operands[0], operands[2]);
1848 operands[2] = operands[1];
1849 }
1850 }
1851 else if (!reg_overlap_mentioned_p (operands[0], operands[1]))
1852 {
1853 if (!reg_overlap_mentioned_p (operands[0], operands[2]))
1854 emit_move_insn (operands[0], operands[1]);
1855 else
1856 operands[2] = operands[1];
1857 }
1858 }
1859 [(set_attr "type" "arith")])
1860
1861 ;; Old reload might generate add insns directly (not through the expander) for
1862 ;; address register calculations when reloading, in which case it won't try
1863 ;; the addsi_scr pattern. Because reload will sometimes try to validate
1864 ;; the generated insns and their constraints, this pattern must be
1865 ;; recognizable during and after reload. However, when reload generates
1866 ;; address register calculations for the stack pointer, we don't allow this
1867 ;; pattern. This will make reload prefer using indexed @(reg + reg) address
1868 ;; modes when the displacement of a @(disp + reg) doesn't fit.
1869 (define_insn_and_split "*addsi3"
1870 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1871 (plus:SI (match_operand:SI 1 "arith_reg_operand" "r")
1872 (match_operand:SI 2 "arith_or_int_operand" "rn")))]
1873 "TARGET_SH1 && !sh_lra_p ()
1874 && (reload_completed || reload_in_progress)
1875 && !reg_overlap_mentioned_p (operands[0], operands[1])
1876 && (!reload_in_progress
1877 || ((!REG_P (operands[1]) || REGNO (operands[1]) != SP_REG)
1878 && (!REG_P (operands[2]) || REGNO (operands[2]) != SP_REG)))"
1879 "#"
1880 "&& 1"
1881 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1882 {
1883 if (operands[2] == const0_rtx)
1884 {
1885 emit_move_insn (operands[0], operands[1]);
1886 DONE;
1887 }
1888
1889 if (CONST_INT_P (operands[2]))
1890 {
1891 if (satisfies_constraint_I08 (operands[2]))
1892 emit_move_insn (operands[0], operands[1]);
1893 else
1894 {
1895 emit_move_insn (operands[0], operands[2]);
1896 operands[2] = operands[1];
1897 }
1898 }
1899 else if (!reg_overlap_mentioned_p (operands[0], operands[2]))
1900 emit_move_insn (operands[0], operands[1]);
1901 else
1902 operands[2] = operands[1];
1903 })
1904
1905 (define_insn_and_split "*addsi3"
1906 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1907 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0,r")
1908 (match_operand:SI 2 "arith_operand" "rI08,Z")))]
1909 "TARGET_SH1 && !sh_lra_p ()"
1910 "@
1911 add %2,%0
1912 #"
1913 "&& operands[2] == const0_rtx"
1914 [(set (match_dup 0) (match_dup 1))]
1915 {
1916 }
1917 [(set_attr "type" "arith")])
1918
1919 ;; -------------------------------------------------------------------------
1920 ;; Subtraction instructions
1921 ;; -------------------------------------------------------------------------
1922
1923 (define_insn_and_split "subdi3"
1924 [(set (match_operand:DI 0 "arith_reg_dest")
1925 (minus:DI (match_operand:DI 1 "arith_reg_operand")
1926 (match_operand:DI 2 "arith_reg_operand")))
1927 (clobber (reg:SI T_REG))]
1928 "TARGET_SH1"
1929 "#"
1930 "&& can_create_pseudo_p ()"
1931 [(const_int 0)]
1932 {
1933 emit_insn (gen_clrt ());
1934 emit_insn (gen_subc (gen_lowpart (SImode, operands[0]),
1935 gen_lowpart (SImode, operands[1]),
1936 gen_lowpart (SImode, operands[2])));
1937 emit_insn (gen_subc (gen_highpart (SImode, operands[0]),
1938 gen_highpart (SImode, operands[1]),
1939 gen_highpart (SImode, operands[2])));
1940 DONE;
1941 })
1942
1943 (define_insn "subc"
1944 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1945 (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
1946 (match_operand:SI 2 "arith_reg_operand" "r"))
1947 (reg:SI T_REG)))
1948 (set (reg:SI T_REG)
1949 (gtu:SI (minus:SI (minus:SI (match_dup 1) (match_dup 2))
1950 (reg:SI T_REG))
1951 (match_dup 1)))]
1952 "TARGET_SH1"
1953 "subc %2,%0"
1954 [(set_attr "type" "arith")])
1955
1956 ;; A simplified version of the subc insn, where the exact value of the
1957 ;; T bit doesn't matter. This is easier for combine to pick up.
1958 ;; We allow a reg or 0 for one of the operands in order to be able to
1959 ;; do 'reg - T' sequences. Reload will load the constant 0 into the reg
1960 ;; as needed.
1961 (define_insn_and_split "*subc"
1962 [(set (match_operand:SI 0 "arith_reg_dest")
1963 (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand")
1964 (match_operand:SI 2 "arith_reg_or_0_operand"))
1965 (match_operand 3 "treg_set_expr")))
1966 (clobber (reg:SI T_REG))]
1967 "TARGET_SH1 && can_create_pseudo_p ()"
1968 "#"
1969 "&& 1"
1970 [(const_int 0)]
1971 {
1972 sh_treg_insns ti = sh_split_treg_set_expr (operands[3], curr_insn);
1973 if (ti.has_trailing_nott ())
1974 {
1975 if (operands[2] == const0_rtx)
1976 {
1977 /* op1 - (1 - T) = op1 - 1 + T = op1 + (-1) + T */
1978 remove_insn (ti.trailing_nott ());
1979 emit_insn (gen_addc (operands[0], operands[1],
1980 force_reg (SImode, GEN_INT (-1))));
1981 DONE;
1982 }
1983 else if (!TARGET_SH2A)
1984 {
1985 /* op1 - op2 - (1 - T) = op1 + (0 - op2 - 1) + T = op1 + ~op2 + T
1986 On SH2A keep the nott insn, because nott-subc sequence doesn't
1987 mutate the inputs. */
1988 remove_insn (ti.trailing_nott ());
1989 rtx tmp = gen_reg_rtx (SImode);
1990 emit_insn (gen_one_cmplsi2 (tmp, operands[2]));
1991 emit_insn (gen_addc (operands[0], operands[1], tmp));
1992 DONE;
1993 }
1994 }
1995
1996 emit_insn (gen_subc (operands[0], operands[1],
1997 force_reg (SImode, operands[2])));
1998 DONE;
1999 })
2000
2001 ;; Convert reg - T - reg = reg - reg - T
2002 (define_insn_and_split "*subc"
2003 [(set (match_operand:SI 0 "arith_reg_dest")
2004 (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand")
2005 (match_operand 2 "treg_set_expr"))
2006 (match_operand:SI 3 "arith_reg_operand")))
2007 (clobber (reg:SI T_REG))]
2008 "TARGET_SH1 && can_create_pseudo_p ()"
2009 "#"
2010 "&& 1"
2011 [(parallel [(set (match_dup 0)
2012 (minus:SI (minus:SI (match_dup 1) (match_dup 3))
2013 (match_dup 2)))
2014 (clobber (reg:SI T_REG))])])
2015
2016 ;; Split reg - reg - 1 into a sett subc sequence, as it can be scheduled
2017 ;; better, if the sett insn can be done early.
2018 ;; Notice that combine turns 'a - b - 1' into 'a + (~b)'.
2019 (define_insn_and_split "*subc"
2020 [(set (match_operand:SI 0 "arith_reg_dest" "")
2021 (plus:SI (not:SI (match_operand:SI 1 "arith_reg_operand" ""))
2022 (match_operand:SI 2 "arith_reg_operand" "")))
2023 (clobber (reg:SI T_REG))]
2024 "TARGET_SH1 && can_create_pseudo_p ()"
2025 "#"
2026 "&& 1"
2027 [(parallel [(set (match_dup 0)
2028 (minus:SI (minus:SI (match_dup 2) (match_dup 1))
2029 (const_int 1)))
2030 (clobber (reg:SI T_REG))])])
2031
2032 ;; Split 'reg - T' into 'reg - 0 - T' to utilize the subc insn.
2033 ;; If the 0 constant can be CSE-ed, this becomes a one instruction
2034 ;; operation, as opposed to sequences such as
2035 ;; movt r2
2036 ;; sub r2,r3
2037 ;;
2038 ;; Even if the constant is not CSE-ed, a sequence such as
2039 ;; mov #0,r2
2040 ;; subc r2,r3
2041 ;; can be scheduled much better since the load of the constant can be
2042 ;; done earlier, before any comparison insns that store the result in
2043 ;; the T bit.
2044 ;; However, avoid things like 'reg - 1', which would expand into a
2045 ;; 3 insn sequence, instead of add #imm8.
2046 (define_insn_and_split "*subc"
2047 [(set (match_operand:SI 0 "arith_reg_dest" "")
2048 (minus:SI (match_operand:SI 1 "arith_reg_operand" "")
2049 (match_operand 2 "treg_set_expr_not_const01")))
2050 (clobber (reg:SI T_REG))]
2051 "TARGET_SH1 && can_create_pseudo_p ()"
2052 "#"
2053 "&& 1"
2054 [(parallel [(set (match_dup 0)
2055 (minus:SI (minus:SI (match_dup 1) (const_int 0))
2056 (match_dup 2)))
2057 (clobber (reg:SI T_REG))])])
2058
2059 ;; Convert
2060 ;; (1 - T) - op2 = 1 - op2 - T
2061 (define_insn_and_split "*subc_negt_reg"
2062 [(set (match_operand:SI 0 "arith_reg_dest")
2063 (minus:SI (match_operand 1 "treg_set_expr_not_const01")
2064 (match_operand:SI 2 "arith_reg_operand")))
2065 (clobber (reg:SI T_REG))]
2066 "TARGET_SH1 && can_create_pseudo_p ()"
2067 "#"
2068 "&& 1"
2069 [(const_int 0)]
2070 {
2071 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
2072 if (ti.remove_trailing_nott ())
2073 {
2074 /* (1 - T) - op2 = 1 - op2 - T */
2075 emit_insn (gen_subc (operands[0],
2076 force_reg (SImode, GEN_INT (1)), operands[2]));
2077 }
2078 else
2079 {
2080 /* T - op2: use movt,sub sequence. */
2081 rtx tmp = gen_reg_rtx (SImode);
2082 emit_insn (gen_movt (tmp, get_t_reg_rtx ()));
2083 emit_insn (gen_subsi3 (operands[0], tmp, operands[2]));
2084 }
2085 DONE;
2086 })
2087
2088 ;; Convert
2089 ;; op1 - (1 - T) + op3 = op1 - 1 + T + op3
2090 ;; (op1 - T) + op3 = op1 - (-op3) - T
2091 (define_insn_and_split "*subc_negreg_t"
2092 [(set (match_operand:SI 0 "arith_reg_dest")
2093 (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand")
2094 (match_operand 2 "treg_set_expr"))
2095 (match_operand:SI 3 "arith_reg_operand")))
2096 (clobber (reg:SI T_REG))]
2097 "TARGET_SH1 && can_create_pseudo_p ()"
2098 "#"
2099 "&& 1"
2100 [(const_int 0)]
2101 {
2102 sh_treg_insns ti = sh_split_treg_set_expr (operands[2], curr_insn);
2103 if (ti.remove_trailing_nott ())
2104 {
2105 /* op1 - (1 - T) + op3 = (op1 - 1) + op3 + T */
2106 rtx tmp = gen_reg_rtx (SImode);
2107 emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (-1)));
2108 emit_insn (gen_addc (operands[0], tmp, operands[3]));
2109 }
2110 else
2111 {
2112 /* (op1 - T) + op3' = 'op1 - (-op3) - T */
2113 rtx tmp = gen_reg_rtx (SImode);
2114 emit_insn (gen_negsi2 (tmp, operands[3]));
2115 emit_insn (gen_subc (operands[0], operands[1], tmp));
2116 }
2117 DONE;
2118 })
2119
2120 (define_insn "*subsi3_internal"
2121 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2122 (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
2123 (match_operand:SI 2 "arith_reg_operand" "r")))]
2124 "TARGET_SH1"
2125 "sub %2,%0"
2126 [(set_attr "type" "arith")])
2127
2128 ;; Convert
2129 ;; constant - reg
2130 ;; to
2131 ;; neg reg
2132 ;; add reg, #const
2133 ;; since this will sometimes save one instruction.
2134 ;; Otherwise we might get a sequence like
2135 ;; mov #const, rY
2136 ;; sub rY, rX
2137 ;; mov rX, rY
2138 ;; if the source and dest regs are the same.
2139 (define_expand "subsi3"
2140 [(set (match_operand:SI 0 "arith_reg_operand" "")
2141 (minus:SI (match_operand:SI 1 "arith_operand" "")
2142 (match_operand:SI 2 "arith_reg_operand" "")))]
2143 ""
2144 {
2145 if (CONST_INT_P (operands[1]))
2146 {
2147 emit_insn (gen_negsi2 (operands[0], operands[2]));
2148 emit_insn (gen_addsi3 (operands[0], operands[0], operands[1]));
2149 DONE;
2150 }
2151 })
2152 \f
2153 ;; -------------------------------------------------------------------------
2154 ;; Division instructions
2155 ;; -------------------------------------------------------------------------
2156
2157 ;; We take advantage of the library routines which don't clobber as many
2158 ;; registers as a normal function call would.
2159
2160 ;; The INSN_REFERENCES_ARE_DELAYED in sh.h is problematic because it
2161 ;; also has an effect on the register that holds the address of the sfunc.
2162 ;; To make this work, we have an extra dummy insn that shows the use
2163 ;; of this register for reorg.
2164
2165 (define_insn "use_sfunc_addr"
2166 [(set (reg:SI PR_REG)
2167 (unspec:SI [(match_operand:SI 0 "register_operand" "r")] UNSPEC_SFUNC))]
2168 "TARGET_SH1 && check_use_sfunc_addr (insn, operands[0])"
2169 ""
2170 [(set_attr "length" "0")])
2171
2172 (define_insn "udivsi3_sh2a"
2173 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2174 (udiv:SI (match_operand:SI 1 "arith_reg_operand" "0")
2175 (match_operand:SI 2 "arith_reg_operand" "z")))]
2176 "TARGET_SH2A"
2177 "divu %2,%1"
2178 [(set_attr "type" "arith")
2179 (set_attr "in_delay_slot" "no")])
2180
2181 ;; We must use a pseudo-reg forced to reg 0 in the SET_DEST rather than
2182 ;; hard register 0. If we used hard register 0, then the next instruction
2183 ;; would be a move from hard register 0 to a pseudo-reg. If the pseudo-reg
2184 ;; gets allocated to a stack slot that needs its address reloaded, then
2185 ;; there is nothing to prevent reload from using r0 to reload the address.
2186 ;; This reload would clobber the value in r0 we are trying to store.
2187 ;; If we let reload allocate r0, then this problem can never happen.
2188 (define_insn "udivsi3_i1"
2189 [(set (match_operand:SI 0 "register_operand" "=z,z")
2190 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2191 (clobber (reg:SI T_REG))
2192 (clobber (reg:SI PR_REG))
2193 (clobber (reg:SI R1_REG))
2194 (clobber (reg:SI R4_REG))
2195 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2196 (use (match_operand 2 "" "Z,Ccl"))]
2197 "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
2198 "@
2199 jsr @%1%#
2200 bsrf %1\n%O2:%#"
2201 [(set_attr "type" "sfunc")
2202 (set_attr "needs_delay_slot" "yes")])
2203
2204 (define_insn "udivsi3_i4"
2205 [(set (match_operand:SI 0 "register_operand" "=y,y")
2206 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2207 (clobber (reg:SI T_REG))
2208 (clobber (reg:SI PR_REG))
2209 (clobber (reg:DF DR0_REG))
2210 (clobber (reg:DF DR2_REG))
2211 (clobber (reg:DF DR4_REG))
2212 (clobber (reg:SI R0_REG))
2213 (clobber (reg:SI R1_REG))
2214 (clobber (reg:SI R4_REG))
2215 (clobber (reg:SI R5_REG))
2216 (clobber (reg:SI FPSCR_STAT_REG))
2217 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2218 (use (match_operand 2 "" "Z,Ccl"))
2219 (use (reg:SI FPSCR_MODES_REG))]
2220 "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
2221 "@
2222 jsr @%1%#
2223 bsrf %1\n%O2:%#"
2224 [(set_attr "type" "sfunc")
2225 (set_attr "fp_mode" "double")
2226 (set_attr "needs_delay_slot" "yes")])
2227
2228 (define_insn "udivsi3_i4_single"
2229 [(set (match_operand:SI 0 "register_operand" "=y,y")
2230 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2231 (clobber (reg:SI T_REG))
2232 (clobber (reg:SI PR_REG))
2233 (clobber (reg:DF DR0_REG))
2234 (clobber (reg:DF DR2_REG))
2235 (clobber (reg:DF DR4_REG))
2236 (clobber (reg:SI R0_REG))
2237 (clobber (reg:SI R1_REG))
2238 (clobber (reg:SI R4_REG))
2239 (clobber (reg:SI R5_REG))
2240 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2241 (use (match_operand 2 "" "Z,Ccl"))]
2242 "TARGET_FPU_ANY && TARGET_FPU_SINGLE"
2243 "@
2244 jsr @%1%#
2245 bsrf %1\n%O2:%#"
2246 [(set_attr "type" "sfunc")
2247 (set_attr "needs_delay_slot" "yes")])
2248
2249 (define_insn "udivsi3_i4_int"
2250 [(set (match_operand:SI 0 "register_operand" "=z")
2251 (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2252 (clobber (reg:SI T_REG))
2253 (clobber (reg:SI R1_REG))
2254 (clobber (reg:SI PR_REG))
2255 (clobber (reg:SI MACH_REG))
2256 (clobber (reg:SI MACL_REG))
2257 (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2258 "TARGET_SH1"
2259 "jsr @%1%#"
2260 [(set_attr "type" "sfunc")
2261 (set_attr "needs_delay_slot" "yes")])
2262
2263
2264 (define_expand "udivsi3"
2265 [(set (match_operand:SI 0 "register_operand")
2266 (udiv:SI (match_operand:SI 1 "general_operand")
2267 (match_operand:SI 2 "general_operand")))]
2268 ""
2269 {
2270 rtx last;
2271
2272 operands[3] = gen_reg_rtx (Pmode);
2273 /* Emit the move of the address to a pseudo outside of the libcall. */
2274 if (TARGET_DIVIDE_CALL_TABLE)
2275 {
2276 /* libgcc2:__udivmoddi4 is not supposed to use an actual division, since
2277 that causes problems when the divide code is supposed to come from a
2278 separate library. Division by zero is undefined, so dividing 1 can be
2279 implemented by comparing with the divisor. */
2280 if (operands[1] == const1_rtx && currently_expanding_to_rtl)
2281 {
2282 rtx test = gen_rtx_GEU (VOIDmode, operands[1], operands[2]);
2283 emit_insn (gen_cstoresi4 (operands[0], test,
2284 operands[1], operands[2]));
2285 DONE;
2286 }
2287 else if (operands[2] == const0_rtx)
2288 {
2289 emit_move_insn (operands[0], operands[2]);
2290 DONE;
2291 }
2292 function_symbol (operands[3], "__udivsi3_i4i", SFUNC_GOT);
2293 last = gen_udivsi3_i4_int (operands[0], operands[3]);
2294 }
2295 else if (TARGET_DIVIDE_CALL_FP)
2296 {
2297 rtx lab = function_symbol (operands[3], "__udivsi3_i4", SFUNC_STATIC).lab;
2298 if (TARGET_FPU_SINGLE)
2299 last = gen_udivsi3_i4_single (operands[0], operands[3], lab);
2300 else
2301 last = gen_udivsi3_i4 (operands[0], operands[3], lab);
2302 }
2303 else if (TARGET_SH2A)
2304 {
2305 operands[1] = force_reg (SImode, operands[1]);
2306 operands[2] = force_reg (SImode, operands[2]);
2307 emit_insn (gen_udivsi3_sh2a (operands[0], operands[1], operands[2]));
2308 DONE;
2309 }
2310 else
2311 {
2312 rtx lab = function_symbol (operands[3], "__udivsi3", SFUNC_STATIC).lab;
2313 last = gen_udivsi3_i1 (operands[0], operands[3], lab);
2314 }
2315 emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
2316 emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
2317 emit_insn (last);
2318 DONE;
2319 })
2320
2321 (define_insn "divsi3_sh2a"
2322 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2323 (div:SI (match_operand:SI 1 "arith_reg_operand" "0")
2324 (match_operand:SI 2 "arith_reg_operand" "z")))]
2325 "TARGET_SH2A"
2326 "divs %2,%1"
2327 [(set_attr "type" "arith")
2328 (set_attr "in_delay_slot" "no")])
2329
2330 (define_insn "divsi3_i1"
2331 [(set (match_operand:SI 0 "register_operand" "=z")
2332 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2333 (clobber (reg:SI T_REG))
2334 (clobber (reg:SI PR_REG))
2335 (clobber (reg:SI R1_REG))
2336 (clobber (reg:SI R2_REG))
2337 (clobber (reg:SI R3_REG))
2338 (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2339 "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
2340 "jsr @%1%#"
2341 [(set_attr "type" "sfunc")
2342 (set_attr "needs_delay_slot" "yes")])
2343
2344 (define_insn "divsi3_i4"
2345 [(set (match_operand:SI 0 "register_operand" "=y,y")
2346 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2347 (clobber (reg:SI PR_REG))
2348 (clobber (reg:DF DR0_REG))
2349 (clobber (reg:DF DR2_REG))
2350 (clobber (reg:SI FPSCR_STAT_REG))
2351 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2352 (use (match_operand 2 "" "Z,Ccl"))
2353 (use (reg:SI FPSCR_MODES_REG))]
2354 "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
2355 "@
2356 jsr @%1%#
2357 bsrf %1\n%O2:%#"
2358 [(set_attr "type" "sfunc")
2359 (set_attr "fp_mode" "double")
2360 (set_attr "needs_delay_slot" "yes")])
2361
2362 (define_insn "divsi3_i4_single"
2363 [(set (match_operand:SI 0 "register_operand" "=y,y")
2364 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2365 (clobber (reg:SI PR_REG))
2366 (clobber (reg:DF DR0_REG))
2367 (clobber (reg:DF DR2_REG))
2368 (clobber (reg:SI R2_REG))
2369 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
2370 (use (match_operand 2 "" "Z,Ccl"))]
2371 "TARGET_FPU_ANY && TARGET_FPU_SINGLE"
2372 "@
2373 jsr @%1%#
2374 bsrf %1\n%O2:%#"
2375 [(set_attr "type" "sfunc")
2376 (set_attr "needs_delay_slot" "yes")])
2377
2378 (define_insn "divsi3_i4_int"
2379 [(set (match_operand:SI 0 "register_operand" "=z")
2380 (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2381 (clobber (reg:SI T_REG))
2382 (clobber (reg:SI PR_REG))
2383 (clobber (reg:SI R1_REG))
2384 (clobber (reg:SI MACH_REG))
2385 (clobber (reg:SI MACL_REG))
2386 (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2387 "TARGET_SH1"
2388 "jsr @%1%#"
2389 [(set_attr "type" "sfunc")
2390 (set_attr "needs_delay_slot" "yes")])
2391
2392 (define_expand "divsi3"
2393 [(set (match_operand:SI 0 "register_operand")
2394 (div:SI (match_operand:SI 1 "general_operand")
2395 (match_operand:SI 2 "general_operand")))]
2396 ""
2397 {
2398 rtx last;
2399
2400 operands[3] = gen_reg_rtx (Pmode);
2401 /* Emit the move of the address to a pseudo outside of the libcall. */
2402 if (TARGET_DIVIDE_CALL_TABLE)
2403 {
2404 function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
2405 last = gen_divsi3_i4_int (operands[0], operands[3]);
2406 }
2407 else if (TARGET_DIVIDE_CALL_FP)
2408 {
2409 rtx lab = function_symbol (operands[3], sh_divsi3_libfunc,
2410 SFUNC_STATIC).lab;
2411 if (TARGET_FPU_SINGLE)
2412 last = gen_divsi3_i4_single (operands[0], operands[3], lab);
2413 else
2414 last = gen_divsi3_i4 (operands[0], operands[3], lab);
2415 }
2416 else if (TARGET_SH2A)
2417 {
2418 operands[1] = force_reg (SImode, operands[1]);
2419 operands[2] = force_reg (SImode, operands[2]);
2420 emit_insn (gen_divsi3_sh2a (operands[0], operands[1], operands[2]));
2421 DONE;
2422 }
2423 else
2424 {
2425 function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
2426 last = gen_divsi3_i1 (operands[0], operands[3]);
2427 }
2428 emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
2429 emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
2430 emit_insn (last);
2431 DONE;
2432 })
2433
2434 \f
2435 ;; -------------------------------------------------------------------------
2436 ;; Multiplication instructions
2437 ;; -------------------------------------------------------------------------
2438
2439 (define_insn_and_split "mulhisi3"
2440 [(set (match_operand:SI 0 "arith_reg_dest")
2441 (mult:SI (sign_extend:SI (match_operand:HI 1 "arith_reg_operand"))
2442 (sign_extend:SI (match_operand:HI 2 "arith_reg_operand"))))
2443 (clobber (reg:SI MACL_REG))]
2444 "TARGET_SH1 && can_create_pseudo_p ()"
2445 "#"
2446 "&& 1"
2447 [(set (reg:SI MACL_REG) (mult:SI (sign_extend:SI (match_dup 1))
2448 (sign_extend:SI (match_dup 2))))
2449 (set (match_dup 0) (reg:SI MACL_REG))])
2450
2451 (define_insn_and_split "umulhisi3"
2452 [(set (match_operand:SI 0 "arith_reg_dest")
2453 (mult:SI (zero_extend:SI (match_operand:HI 1 "arith_reg_operand"))
2454 (zero_extend:SI (match_operand:HI 2 "arith_reg_operand"))))
2455 (clobber (reg:SI MACL_REG))]
2456 "TARGET_SH1 && can_create_pseudo_p ()"
2457 "#"
2458 "&& 1"
2459 [(set (reg:SI MACL_REG) (mult:SI (zero_extend:SI (match_dup 1))
2460 (zero_extend:SI (match_dup 2))))
2461 (set (match_dup 0) (reg:SI MACL_REG))])
2462
2463 (define_insn "umulhisi3_i"
2464 [(set (reg:SI MACL_REG)
2465 (mult:SI (zero_extend:SI
2466 (match_operand:HI 0 "arith_reg_operand" "r"))
2467 (zero_extend:SI
2468 (match_operand:HI 1 "arith_reg_operand" "r"))))]
2469 "TARGET_SH1"
2470 "mulu.w %1,%0"
2471 [(set_attr "type" "smpy")])
2472
2473 (define_insn "mulhisi3_i"
2474 [(set (reg:SI MACL_REG)
2475 (mult:SI (sign_extend:SI
2476 (match_operand:HI 0 "arith_reg_operand" "r"))
2477 (sign_extend:SI
2478 (match_operand:HI 1 "arith_reg_operand" "r"))))]
2479 "TARGET_SH1"
2480 "muls.w %1,%0"
2481 [(set_attr "type" "smpy")])
2482
2483
2484 ;; mulsi3 on the SH2 can be done in one instruction, on the SH1 we generate
2485 ;; a call to a routine which clobbers known registers.
2486 (define_insn "mulsi3_call"
2487 [(set (match_operand:SI 1 "register_operand" "=z")
2488 (mult:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2489 (clobber (reg:SI MACL_REG))
2490 (clobber (reg:SI T_REG))
2491 (clobber (reg:SI PR_REG))
2492 (clobber (reg:SI R3_REG))
2493 (clobber (reg:SI R2_REG))
2494 (clobber (reg:SI R1_REG))
2495 (use (match_operand:SI 0 "arith_reg_operand" "r"))]
2496 "TARGET_SH1"
2497 "jsr @%0%#"
2498 [(set_attr "type" "sfunc")
2499 (set_attr "needs_delay_slot" "yes")])
2500
2501 (define_insn "mul_r"
2502 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2503 (mult:SI (match_operand:SI 1 "arith_reg_operand" "0")
2504 (match_operand:SI 2 "arith_reg_operand" "z")))]
2505 "TARGET_SH2A"
2506 "mulr %2,%0"
2507 [(set_attr "type" "dmpy")])
2508
2509 (define_insn "mul_l"
2510 [(set (reg:SI MACL_REG)
2511 (mult:SI (match_operand:SI 0 "arith_reg_operand" "r")
2512 (match_operand:SI 1 "arith_reg_operand" "r")))]
2513 "TARGET_SH2"
2514 "mul.l %1,%0"
2515 [(set_attr "type" "dmpy")])
2516
2517 (define_insn_and_split "mulsi3_i"
2518 [(set (match_operand:SI 0 "arith_reg_dest")
2519 (mult:SI (match_operand:SI 1 "arith_reg_operand")
2520 (match_operand:SI 2 "arith_reg_operand")))
2521 (clobber (reg:SI MACL_REG))]
2522 "TARGET_SH2 && can_create_pseudo_p ()"
2523 "#"
2524 "&& 1"
2525 [(set (reg:SI MACL_REG) (mult:SI (match_dup 1) (match_dup 2)))
2526 (set (match_dup 0) (reg:SI MACL_REG))])
2527
2528 (define_expand "mulsi3"
2529 [(set (match_operand:SI 0 "arith_reg_dest")
2530 (mult:SI (match_operand:SI 1 "arith_reg_operand")
2531 (match_operand:SI 2 "arith_reg_operand")))]
2532 "TARGET_SH1"
2533 {
2534 if (!TARGET_SH2)
2535 {
2536 emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
2537 emit_move_insn (gen_rtx_REG (SImode, R5_REG), operands[2]);
2538
2539 rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC).sym;
2540
2541 emit_insn (gen_mulsi3_call (force_reg (SImode, sym), operands[0]));
2542 }
2543 else
2544 {
2545 /* FIXME: For some reason, expanding the mul_l insn and the macl store
2546 insn early gives slightly better code. In particular it prevents
2547 the decrement-test loop type to be used in some cases which saves
2548 one multiplication in the loop setup code.
2549
2550 emit_insn (gen_mulsi3_i (operands[0], operands[1], operands[2]));
2551 */
2552
2553 emit_insn (gen_mul_l (operands[1], operands[2]));
2554 emit_move_insn (operands[0], gen_rtx_REG (SImode, MACL_REG));
2555 }
2556 DONE;
2557 })
2558
2559 (define_insn "mulsidi3_i"
2560 [(set (reg:SI MACH_REG)
2561 (truncate:SI
2562 (lshiftrt:DI
2563 (mult:DI
2564 (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2565 (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2566 (const_int 32))))
2567 (set (reg:SI MACL_REG)
2568 (mult:SI (match_dup 0)
2569 (match_dup 1)))]
2570 "TARGET_SH2"
2571 "dmuls.l %1,%0"
2572 [(set_attr "type" "dmpy")])
2573
2574 (define_expand "mulsidi3"
2575 [(set (match_operand:DI 0 "arith_reg_dest")
2576 (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2577 (sign_extend:DI (match_operand:SI 2 "arith_reg_operand"))))]
2578 "TARGET_SH2"
2579 {
2580 emit_insn (gen_mulsidi3_compact (operands[0], operands[1], operands[2]));
2581 DONE;
2582 })
2583
2584 (define_insn_and_split "mulsidi3_compact"
2585 [(set (match_operand:DI 0 "arith_reg_dest")
2586 (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2587 (sign_extend:DI (match_operand:SI 2 "arith_reg_operand"))))
2588 (clobber (reg:SI MACH_REG))
2589 (clobber (reg:SI MACL_REG))]
2590 "TARGET_SH2 && can_create_pseudo_p ()"
2591 "#"
2592 "&& 1"
2593 [(const_int 0)]
2594 {
2595 rtx low_dst = gen_lowpart (SImode, operands[0]);
2596 rtx high_dst = gen_highpart (SImode, operands[0]);
2597
2598 emit_insn (gen_mulsidi3_i (operands[1], operands[2]));
2599
2600 emit_move_insn (low_dst, gen_rtx_REG (SImode, MACL_REG));
2601 emit_move_insn (high_dst, gen_rtx_REG (SImode, MACH_REG));
2602 /* We need something to tag the possible REG_EQUAL notes on to. */
2603 emit_move_insn (operands[0], operands[0]);
2604 DONE;
2605 })
2606
2607 (define_insn "umulsidi3_i"
2608 [(set (reg:SI MACH_REG)
2609 (truncate:SI
2610 (lshiftrt:DI
2611 (mult:DI
2612 (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2613 (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2614 (const_int 32))))
2615 (set (reg:SI MACL_REG)
2616 (mult:SI (match_dup 0)
2617 (match_dup 1)))]
2618 "TARGET_SH2"
2619 "dmulu.l %1,%0"
2620 [(set_attr "type" "dmpy")])
2621
2622 (define_expand "umulsidi3"
2623 [(set (match_operand:DI 0 "arith_reg_dest")
2624 (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2625 (zero_extend:DI (match_operand:SI 2 "arith_reg_operand"))))]
2626 "TARGET_SH2"
2627 {
2628 emit_insn (gen_umulsidi3_compact (operands[0], operands[1], operands[2]));
2629 DONE;
2630 })
2631
2632 (define_insn_and_split "umulsidi3_compact"
2633 [(set (match_operand:DI 0 "arith_reg_dest")
2634 (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2635 (zero_extend:DI (match_operand:SI 2 "arith_reg_operand"))))
2636 (clobber (reg:SI MACH_REG))
2637 (clobber (reg:SI MACL_REG))]
2638 "TARGET_SH2 && can_create_pseudo_p ()"
2639 "#"
2640 "&& 1"
2641 [(const_int 0)]
2642 {
2643 rtx low_dst = gen_lowpart (SImode, operands[0]);
2644 rtx high_dst = gen_highpart (SImode, operands[0]);
2645
2646 emit_insn (gen_umulsidi3_i (operands[1], operands[2]));
2647
2648 emit_move_insn (low_dst, gen_rtx_REG (SImode, MACL_REG));
2649 emit_move_insn (high_dst, gen_rtx_REG (SImode, MACH_REG));
2650 /* We need something to tag the possible REG_EQUAL notes on to. */
2651 emit_move_insn (operands[0], operands[0]);
2652 DONE;
2653 })
2654
2655 (define_insn "smulsi3_highpart_i"
2656 [(set (reg:SI MACH_REG)
2657 (truncate:SI
2658 (lshiftrt:DI
2659 (mult:DI
2660 (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2661 (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2662 (const_int 32))))
2663 (clobber (reg:SI MACL_REG))]
2664 "TARGET_SH2"
2665 "dmuls.l %1,%0"
2666 [(set_attr "type" "dmpy")])
2667
2668 (define_insn_and_split "smulsi3_highpart"
2669 [(set (match_operand:SI 0 "arith_reg_dest")
2670 (truncate:SI
2671 (lshiftrt:DI
2672 (mult:DI
2673 (sign_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2674 (sign_extend:DI (match_operand:SI 2 "arith_reg_operand")))
2675 (const_int 32))))
2676 (clobber (reg:SI MACL_REG))
2677 (clobber (reg:SI MACH_REG))]
2678 "TARGET_SH2 && can_create_pseudo_p ()"
2679 "#"
2680 "&& 1"
2681 [(const_int 0)]
2682 {
2683 emit_insn (gen_smulsi3_highpart_i (operands[1], operands[2]));
2684 emit_move_insn (operands[0], gen_rtx_REG (SImode, MACH_REG));
2685 })
2686
2687 (define_insn "umulsi3_highpart_i"
2688 [(set (reg:SI MACH_REG)
2689 (truncate:SI
2690 (lshiftrt:DI
2691 (mult:DI
2692 (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
2693 (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
2694 (const_int 32))))
2695 (clobber (reg:SI MACL_REG))]
2696 "TARGET_SH2"
2697 "dmulu.l %1,%0"
2698 [(set_attr "type" "dmpy")])
2699
2700 (define_insn_and_split "umulsi3_highpart"
2701 [(set (match_operand:SI 0 "arith_reg_dest")
2702 (truncate:SI
2703 (lshiftrt:DI
2704 (mult:DI
2705 (zero_extend:DI (match_operand:SI 1 "arith_reg_operand"))
2706 (zero_extend:DI (match_operand:SI 2 "arith_reg_operand")))
2707 (const_int 32))))
2708 (clobber (reg:SI MACL_REG))]
2709 "TARGET_SH2 && can_create_pseudo_p ()"
2710 "#"
2711 "&& 1"
2712 [(const_int 0)]
2713 {
2714 emit_insn (gen_umulsi3_highpart_i (operands[1], operands[2]));
2715 emit_move_insn (operands[0], gen_rtx_REG (SImode, MACH_REG));
2716 })
2717
2718 ;; -------------------------------------------------------------------------
2719 ;; Logical operations
2720 ;; -------------------------------------------------------------------------
2721
2722 (define_expand "andsi3"
2723 [(set (match_operand:SI 0 "arith_reg_dest")
2724 (and:SI (match_operand:SI 1 "arith_reg_operand")
2725 (match_operand:SI 2 "logical_and_operand")))]
2726 ""
2727 {
2728 /* If it is possible to turn the and insn into a zero extension
2729 already, redundant zero extensions will be folded, which results
2730 in better code.
2731 Ideally the splitter of *andsi_compact would be enough, if redundant
2732 zero extensions were detected after the combine pass, which does not
2733 happen at the moment. */
2734
2735 if (satisfies_constraint_Jmb (operands[2]))
2736 {
2737 emit_insn (gen_zero_extendqisi2 (operands[0],
2738 gen_lowpart (QImode, operands[1])));
2739 DONE;
2740 }
2741 else if (satisfies_constraint_Jmw (operands[2]))
2742 {
2743 emit_insn (gen_zero_extendhisi2 (operands[0],
2744 gen_lowpart (HImode, operands[1])));
2745 DONE;
2746 }
2747 })
2748
2749 (define_insn_and_split "*andsi_compact"
2750 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r,z,r")
2751 (and:SI (match_operand:SI 1 "arith_reg_operand" "%r,r,0,0")
2752 (match_operand:SI 2 "logical_and_operand" "Jmb,Jmw,K08,r")))]
2753 "TARGET_SH1"
2754 "@
2755 extu.b %1,%0
2756 extu.w %1,%0
2757 and %2,%0
2758 and %2,%0"
2759 "&& 1"
2760 [(set (match_dup 0) (zero_extend:SI (match_dup 1)))]
2761 {
2762 if (satisfies_constraint_Jmb (operands[2]))
2763 operands[1] = gen_lowpart (QImode, operands[1]);
2764 else if (satisfies_constraint_Jmw (operands[2]))
2765 operands[1] = gen_lowpart (HImode, operands[1]);
2766 else
2767 FAIL;
2768 }
2769 [(set_attr "type" "arith")])
2770
2771 (define_insn "*andsi3_bclr"
2772 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2773 (and:SI (match_operand:SI 1 "arith_reg_operand" "%0")
2774 (match_operand:SI 2 "const_int_operand" "Psz")))]
2775 "TARGET_SH2A && satisfies_constraint_Psz (operands[2])"
2776 "bclr %W2,%0"
2777 [(set_attr "type" "arith")])
2778
2779 (define_expand "iorsi3"
2780 [(set (match_operand:SI 0 "arith_reg_dest")
2781 (ior:SI (match_operand:SI 1 "arith_reg_operand")
2782 (match_operand:SI 2 "logical_operand")))])
2783
2784 (define_insn "*iorsi3_compact"
2785 [(set (match_operand:SI 0 "arith_reg_dest" "=r,z")
2786 (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
2787 (match_operand:SI 2 "logical_operand" "r,K08")))]
2788 "TARGET_SH1
2789 && !(TARGET_SH2A && satisfies_constraint_Pso (operands[2]))"
2790 "or %2,%0"
2791 [(set_attr "type" "arith")])
2792
2793 (define_insn "*iorsi3_bset"
2794 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2795 (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0")
2796 (match_operand:SI 2 "const_int_operand" "Pso")))]
2797 "TARGET_SH2A && satisfies_constraint_Pso (operands[2])"
2798 "bset %V2,%0"
2799 [(set_attr "type" "arith")])
2800
2801 (define_insn "xorsi3"
2802 [(set (match_operand:SI 0 "arith_reg_dest" "=z,r")
2803 (xor:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
2804 (match_operand:SI 2 "logical_operand" "K08,r")))]
2805 "TARGET_SH1"
2806 "xor %2,%0"
2807 [(set_attr "type" "arith")])
2808
2809 ;; The *logical_op_t pattern helps combine eliminating sign/zero extensions
2810 ;; of results where one of the inputs is a T bit store. Notice that this
2811 ;; pattern must not match during reload. If reload picks this pattern it
2812 ;; will be impossible to split it afterwards.
2813 (define_insn_and_split "*logical_op_t"
2814 [(set (match_operand:SI 0 "arith_reg_dest")
2815 (match_operator:SI 3 "logical_operator"
2816 [(match_operand:SI 1 "arith_reg_operand")
2817 (match_operand:SI 2 "t_reg_operand")]))]
2818 "TARGET_SH1 && can_create_pseudo_p ()"
2819 "#"
2820 "&& 1"
2821 [(set (match_dup 4) (reg:SI T_REG))
2822 (set (match_dup 0) (match_dup 3))]
2823 {
2824 operands[4] = gen_reg_rtx (SImode);
2825 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2826 operands[1], operands[4]);
2827 })
2828
2829 ;; -------------------------------------------------------------------------
2830 ;; Shifts and rotates
2831 ;; -------------------------------------------------------------------------
2832
2833 ;; Let combine see that we can get the MSB and LSB into the T bit
2834 ;; via shll and shlr. This allows it to plug it into insns that can have
2835 ;; the T bit as an input (e.g. addc).
2836 ;; On SH2A use bld #0,Rn instead of shlr to avoid mutating the input.
2837 (define_insn_and_split "*reg_lsb_t"
2838 [(set (reg:SI T_REG)
2839 (and:SI (match_operand:SI 0 "arith_reg_operand")
2840 (const_int 1)))]
2841 "TARGET_SH1 && can_create_pseudo_p ()"
2842 "#"
2843 "&& 1"
2844 [(const_int 0)]
2845 {
2846 emit_insn (TARGET_SH2A ? gen_bldsi_reg (operands[0], const0_rtx)
2847 : gen_shlr (gen_reg_rtx (SImode), operands[0]));
2848 })
2849
2850 (define_insn_and_split "*reg_msb_t"
2851 [(set (reg:SI T_REG)
2852 (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
2853 (const_int 31)))]
2854 "TARGET_SH1 && can_create_pseudo_p ()"
2855 "#"
2856 "&& 1"
2857 [(const_int 0)]
2858 {
2859 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
2860 })
2861
2862 (define_expand "rotrsi3"
2863 [(set (match_operand:SI 0 "arith_reg_dest")
2864 (rotatert:SI (match_operand:SI 1 "arith_reg_operand")
2865 (match_operand:SI 2 "const_int_operand")))]
2866 "TARGET_SH1"
2867 {
2868 HOST_WIDE_INT ival = INTVAL (operands[2]);
2869 if (ival == 1)
2870 {
2871 emit_insn (gen_rotrsi3_1 (operands[0], operands[1]));
2872 DONE;
2873 }
2874
2875 FAIL;
2876 })
2877
2878 (define_insn "rotrsi3_1"
2879 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2880 (rotatert:SI (match_operand:SI 1 "arith_reg_operand" "0")
2881 (const_int 1)))
2882 (set (reg:SI T_REG)
2883 (and:SI (match_dup 1) (const_int 1)))]
2884 "TARGET_SH1"
2885 "rotr %0"
2886 [(set_attr "type" "arith")])
2887
2888 ;; A slimplified version of rotr for combine.
2889 (define_insn "*rotrsi3_1"
2890 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2891 (rotatert:SI (match_operand:SI 1 "arith_reg_operand" "0")
2892 (const_int 1)))
2893 (clobber (reg:SI T_REG))]
2894 "TARGET_SH1"
2895 "rotr %0"
2896 [(set_attr "type" "arith")])
2897
2898 (define_insn "rotlsi3_1"
2899 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2900 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
2901 (const_int 1)))
2902 (set (reg:SI T_REG)
2903 (lshiftrt:SI (match_dup 1) (const_int 31)))]
2904 "TARGET_SH1"
2905 "rotl %0"
2906 [(set_attr "type" "arith")])
2907
2908 ;; A simplified version of rotl for combine.
2909 (define_insn "*rotlsi3_1"
2910 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2911 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
2912 (const_int 1)))
2913 (clobber (reg:SI T_REG))]
2914 "TARGET_SH1"
2915 "rotl %0"
2916 [(set_attr "type" "arith")])
2917
2918 (define_insn "rotlsi3_31"
2919 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2920 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
2921 (const_int 31)))
2922 (clobber (reg:SI T_REG))]
2923 "TARGET_SH1"
2924 "rotr %0"
2925 [(set_attr "type" "arith")])
2926
2927 (define_insn "rotlsi3_16"
2928 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2929 (rotate:SI (match_operand:SI 1 "arith_reg_operand" "r")
2930 (const_int 16)))]
2931 "TARGET_SH1"
2932 "swap.w %1,%0"
2933 [(set_attr "type" "arith")])
2934
2935 (define_expand "rotlsi3"
2936 [(set (match_operand:SI 0 "arith_reg_dest")
2937 (rotate:SI (match_operand:SI 1 "arith_reg_operand")
2938 (match_operand:SI 2 "const_int_operand")))]
2939 "TARGET_SH1"
2940 {
2941 static const char rot_tab[] = {
2942 000, 000, 000, 000, 000, 000, 010, 001,
2943 001, 001, 011, 013, 003, 003, 003, 003,
2944 003, 003, 003, 003, 003, 013, 012, 002,
2945 002, 002, 010, 000, 000, 000, 000, 000,
2946 };
2947
2948 int count = INTVAL (operands[2]);
2949 int choice = rot_tab[count];
2950 if (choice & 010 && SH_DYNAMIC_SHIFT_COST <= 1)
2951 FAIL;
2952 choice &= 7;
2953 switch (choice)
2954 {
2955 case 0:
2956 emit_move_insn (operands[0], operands[1]);
2957 count -= (count & 16) * 2;
2958 break;
2959 case 3:
2960 emit_insn (gen_rotlsi3_16 (operands[0], operands[1]));
2961 count -= 16;
2962 break;
2963 case 1:
2964 case 2:
2965 {
2966 rtx parts[2];
2967 parts[0] = gen_reg_rtx (SImode);
2968 parts[1] = gen_reg_rtx (SImode);
2969 emit_insn (gen_rotlsi3_16 (parts[2-choice], operands[1]));
2970 emit_move_insn (parts[choice-1], operands[1]);
2971 emit_insn (gen_ashlsi3 (parts[0], parts[0], GEN_INT (8)));
2972 emit_insn (gen_lshrsi3 (parts[1], parts[1], GEN_INT (8)));
2973 emit_insn (gen_iorsi3 (operands[0], parts[0], parts[1]));
2974 count = (count & ~16) - 8;
2975 }
2976 }
2977
2978 for (; count > 0; count--)
2979 emit_insn (gen_rotlsi3_1 (operands[0], operands[0]));
2980 for (; count < 0; count++)
2981 emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
2982
2983 DONE;
2984 })
2985
2986 (define_insn "rotlhi3_8"
2987 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
2988 (rotate:HI (match_operand:HI 1 "arith_reg_operand" "r")
2989 (const_int 8)))]
2990 "TARGET_SH1"
2991 "swap.b %1,%0"
2992 [(set_attr "type" "arith")])
2993
2994 (define_expand "rotlhi3"
2995 [(set (match_operand:HI 0 "arith_reg_operand")
2996 (rotate:HI (match_operand:HI 1 "arith_reg_operand")
2997 (match_operand:HI 2 "const_int_operand")))]
2998 "TARGET_SH1"
2999 {
3000 if (INTVAL (operands[2]) != 8)
3001 FAIL;
3002 })
3003
3004 ;; The rotcr and rotcl insns are used primarily in DImode shifts by one.
3005 ;; They can also be used to implement things like
3006 ;; bool t = a == b;
3007 ;; int x0 = (y >> 1) | (t << 31); // rotcr
3008 ;; int x1 = (y << 1) | t; // rotcl
3009 (define_insn "rotcr"
3010 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3011 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3012 (const_int 1))
3013 (ashift:SI (match_operand:SI 2 "t_reg_operand")
3014 (const_int 31))))
3015 (set (reg:SI T_REG)
3016 (and:SI (match_dup 1) (const_int 1)))]
3017 "TARGET_SH1"
3018 "rotcr %0"
3019 [(set_attr "type" "arith")])
3020
3021 (define_insn "rotcl"
3022 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3023 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3024 (const_int 1))
3025 (match_operand:SI 2 "t_reg_operand")))
3026 (set (reg:SI T_REG)
3027 (lshiftrt:SI (match_dup 1) (const_int 31)))]
3028 "TARGET_SH1"
3029 "rotcl %0"
3030 [(set_attr "type" "arith")])
3031
3032 ;; Simplified rotcr version for combine, which allows arbitrary shift
3033 ;; amounts for the reg. If the shift amount is '1' rotcr can be used
3034 ;; directly. Otherwise we have to insert a shift in between.
3035 (define_insn_and_split "*rotcr"
3036 [(set (match_operand:SI 0 "arith_reg_dest")
3037 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_or_0_operand")
3038 (match_operand:SI 2 "const_int_operand"))
3039 (ashift:SI (match_operand 3 "arith_reg_or_treg_set_expr")
3040 (const_int 31))))
3041 (clobber (reg:SI T_REG))]
3042 "TARGET_SH1 && can_create_pseudo_p ()"
3043 "#"
3044 "&& 1"
3045 [(const_int 0)]
3046 {
3047 rtx_insn *prev_set_t_insn = NULL;
3048
3049 if (!arith_reg_operand (operands[3], SImode))
3050 {
3051 sh_treg_insns ti = sh_split_treg_set_expr (operands[3], curr_insn);
3052 if (!ti.was_treg_operand ())
3053 prev_set_t_insn = ti.first_insn ();
3054
3055 operands[3] = get_t_reg_rtx ();
3056
3057 if (TARGET_SH2A && ti.has_trailing_nott () && operands[1] == const0_rtx)
3058 {
3059 /* Convert to a movrt, rotr sequence. */
3060 remove_insn (ti.trailing_nott ());
3061 rtx tmp = gen_reg_rtx (SImode);
3062 emit_insn (gen_movnegt (tmp, get_t_reg_rtx ()));
3063 emit_insn (gen_rotrsi3_1 (operands[0], tmp));
3064 DONE;
3065 }
3066 }
3067
3068 if (operands[1] == const0_rtx)
3069 {
3070 operands[1] = gen_reg_rtx (SImode);
3071 emit_insn (gen_movt (operands[1], get_t_reg_rtx ()));
3072 }
3073
3074 if (INTVAL (operands[2]) > 1)
3075 {
3076 const rtx shift_count = GEN_INT (INTVAL (operands[2]) - 1);
3077 rtx tmp_t_reg = NULL_RTX;
3078
3079 /* If we're going to emit a shift sequence that clobbers the T_REG,
3080 try to find the previous insn that sets the T_REG and emit the
3081 shift insn before that insn, to remove the T_REG dependency.
3082 If the insn that sets the T_REG cannot be found, store the T_REG
3083 in a temporary reg and restore it after the shift. */
3084 if (sh_lshrsi_clobbers_t_reg_p (shift_count)
3085 && ! sh_dynamicalize_shift_p (shift_count))
3086 {
3087 if (prev_set_t_insn == NULL)
3088 prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
3089
3090 /* Skip the nott insn, which was probably inserted by the splitter
3091 of *rotcr_neg_t. Don't use one of the recog functions
3092 here during insn splitting, since that causes problems in later
3093 passes. */
3094 if (prev_set_t_insn != NULL_RTX)
3095 {
3096 rtx pat = PATTERN (prev_set_t_insn);
3097 if (GET_CODE (pat) == SET
3098 && t_reg_operand (XEXP (pat, 0), SImode)
3099 && negt_reg_operand (XEXP (pat, 1), SImode))
3100 prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
3101 }
3102
3103 if (! (prev_set_t_insn != NULL_RTX
3104 && reg_set_p (get_t_reg_rtx (), prev_set_t_insn)
3105 && ! reg_referenced_p (get_t_reg_rtx (),
3106 PATTERN (prev_set_t_insn))))
3107 {
3108 prev_set_t_insn = NULL;
3109 tmp_t_reg = gen_reg_rtx (SImode);
3110 emit_insn (gen_move_insn (tmp_t_reg, get_t_reg_rtx ()));
3111 }
3112 }
3113
3114 rtx shift_result = gen_reg_rtx (SImode);
3115 rtx shift_insn = gen_lshrsi3 (shift_result, operands[1], shift_count);
3116 operands[1] = shift_result;
3117
3118 /* Emit the shift insn before the insn that sets T_REG, if possible. */
3119 if (prev_set_t_insn != NULL_RTX)
3120 emit_insn_before (shift_insn, prev_set_t_insn);
3121 else
3122 emit_insn (shift_insn);
3123
3124 /* Restore T_REG if it has been saved before. */
3125 if (tmp_t_reg != NULL_RTX)
3126 emit_insn (gen_cmpgtsi_t (tmp_t_reg, const0_rtx));
3127 }
3128
3129 /* For the rotcr insn to work, operands[3] must be in T_REG.
3130 If it is not we can get it there by shifting it right one bit.
3131 In this case T_REG is not an input for this insn, thus we don't have to
3132 pay attention as of where to insert the shlr insn. */
3133 if (! t_reg_operand (operands[3], SImode))
3134 {
3135 /* We don't care about the shifted result here, only the T_REG. */
3136 emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[3]));
3137 operands[3] = get_t_reg_rtx ();
3138 }
3139
3140 emit_insn (gen_rotcr (operands[0], operands[1], operands[3]));
3141 DONE;
3142 })
3143
3144 ;; If combine tries the same as above but with swapped operands, split
3145 ;; it so that it will try the pattern above.
3146 (define_split
3147 [(set (match_operand:SI 0 "arith_reg_dest")
3148 (ior:SI (ashift:SI (match_operand 1 "arith_reg_or_treg_set_expr")
3149 (const_int 31))
3150 (lshiftrt:SI (match_operand:SI 2 "arith_reg_or_0_operand")
3151 (match_operand:SI 3 "const_int_operand"))))]
3152 "TARGET_SH1 && can_create_pseudo_p ()"
3153 [(parallel [(set (match_dup 0)
3154 (ior:SI (lshiftrt:SI (match_dup 2) (match_dup 3))
3155 (ashift:SI (match_dup 1) (const_int 31))))
3156 (clobber (reg:SI T_REG))])])
3157
3158 ;; Basically the same as the rotcr pattern above, but for rotcl.
3159 ;; FIXME: Fold copy pasted split code for rotcr and rotcl.
3160 (define_insn_and_split "*rotcl"
3161 [(set (match_operand:SI 0 "arith_reg_dest")
3162 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3163 (match_operand:SI 2 "const_int_operand"))
3164 (and:SI (match_operand:SI 3 "arith_reg_or_t_reg_operand")
3165 (const_int 1))))
3166 (clobber (reg:SI T_REG))]
3167 "TARGET_SH1"
3168 "#"
3169 "&& can_create_pseudo_p ()"
3170 [(const_int 0)]
3171 {
3172 gcc_assert (INTVAL (operands[2]) > 0);
3173
3174 if (INTVAL (operands[2]) > 1)
3175 {
3176 const rtx shift_count = GEN_INT (INTVAL (operands[2]) - 1);
3177 rtx_insn *prev_set_t_insn = NULL;
3178 rtx tmp_t_reg = NULL_RTX;
3179
3180 /* If we're going to emit a shift sequence that clobbers the T_REG,
3181 try to find the previous insn that sets the T_REG and emit the
3182 shift insn before that insn, to remove the T_REG dependency.
3183 If the insn that sets the T_REG cannot be found, store the T_REG
3184 in a temporary reg and restore it after the shift. */
3185 if (sh_ashlsi_clobbers_t_reg_p (shift_count)
3186 && ! sh_dynamicalize_shift_p (shift_count))
3187 {
3188 prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
3189
3190 /* Skip the nott insn, which was probably inserted by the splitter
3191 of *rotcl_neg_t. Don't use one of the recog functions
3192 here during insn splitting, since that causes problems in later
3193 passes. */
3194 if (prev_set_t_insn != NULL_RTX)
3195 {
3196 rtx pat = PATTERN (prev_set_t_insn);
3197 if (GET_CODE (pat) == SET
3198 && t_reg_operand (XEXP (pat, 0), SImode)
3199 && negt_reg_operand (XEXP (pat, 1), SImode))
3200 prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
3201 }
3202
3203 if (! (prev_set_t_insn != NULL_RTX
3204 && reg_set_p (get_t_reg_rtx (), prev_set_t_insn)
3205 && ! reg_referenced_p (get_t_reg_rtx (),
3206 PATTERN (prev_set_t_insn))))
3207 {
3208 prev_set_t_insn = NULL;
3209 tmp_t_reg = gen_reg_rtx (SImode);
3210 emit_insn (gen_move_insn (tmp_t_reg, get_t_reg_rtx ()));
3211 }
3212 }
3213
3214 rtx shift_result = gen_reg_rtx (SImode);
3215 rtx shift_insn = gen_ashlsi3 (shift_result, operands[1], shift_count);
3216 operands[1] = shift_result;
3217
3218 /* Emit the shift insn before the insn that sets T_REG, if possible. */
3219 if (prev_set_t_insn != NULL_RTX)
3220 emit_insn_before (shift_insn, prev_set_t_insn);
3221 else
3222 emit_insn (shift_insn);
3223
3224 /* Restore T_REG if it has been saved before. */
3225 if (tmp_t_reg != NULL_RTX)
3226 emit_insn (gen_cmpgtsi_t (tmp_t_reg, const0_rtx));
3227 }
3228
3229 /* For the rotcl insn to work, operands[3] must be in T_REG.
3230 If it is not we can get it there by shifting it right one bit.
3231 In this case T_REG is not an input for this insn, thus we don't have to
3232 pay attention as of where to insert the shlr insn. */
3233 if (! t_reg_operand (operands[3], SImode))
3234 {
3235 /* We don't care about the shifted result here, only the T_REG. */
3236 emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[3]));
3237 operands[3] = get_t_reg_rtx ();
3238 }
3239
3240 emit_insn (gen_rotcl (operands[0], operands[1], operands[3]));
3241 DONE;
3242 })
3243
3244 ;; rotcl combine pattern variations
3245 (define_insn_and_split "*rotcl"
3246 [(set (match_operand:SI 0 "arith_reg_dest")
3247 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3248 (match_operand:SI 2 "const_int_operand"))
3249 (match_operand 3 "treg_set_expr")))
3250 (clobber (reg:SI T_REG))]
3251 "TARGET_SH1"
3252 "#"
3253 "&& can_create_pseudo_p ()"
3254 [(parallel [(set (match_dup 0)
3255 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3256 (and:SI (match_dup 3) (const_int 1))))
3257 (clobber (reg:SI T_REG))])]
3258 {
3259 sh_split_treg_set_expr (operands[3], curr_insn);
3260 operands[3] = get_t_reg_rtx ();
3261 })
3262
3263 (define_insn_and_split "*rotcl"
3264 [(set (match_operand:SI 0 "arith_reg_dest")
3265 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_or_t_reg_operand")
3266 (const_int 1))
3267 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
3268 (match_operand:SI 3 "const_int_operand"))))
3269 (clobber (reg:SI T_REG))]
3270 "TARGET_SH1"
3271 "#"
3272 "&& can_create_pseudo_p ()"
3273 [(parallel [(set (match_dup 0)
3274 (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
3275 (and:SI (match_dup 1) (const_int 1))))
3276 (clobber (reg:SI T_REG))])])
3277
3278 (define_insn_and_split "*rotcl"
3279 [(set (match_operand:SI 0 "arith_reg_dest")
3280 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3281 (match_operand:SI 2 "const_int_operand"))
3282 (lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
3283 (const_int 31))))
3284 (clobber (reg:SI T_REG))]
3285 "TARGET_SH1"
3286 "#"
3287 "&& can_create_pseudo_p ()"
3288 [(parallel [(set (match_dup 0)
3289 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3290 (and:SI (reg:SI T_REG) (const_int 1))))
3291 (clobber (reg:SI T_REG))])]
3292 {
3293 /* We don't care about the result of the left shift, only the T_REG. */
3294 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[3]));
3295 })
3296
3297 (define_insn_and_split "*rotcl"
3298 [(set (match_operand:SI 0 "arith_reg_dest")
3299 (ior:SI (lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
3300 (const_int 31))
3301 (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3302 (match_operand:SI 2 "const_int_operand"))))
3303 (clobber (reg:SI T_REG))]
3304 "TARGET_SH1"
3305 "#"
3306 "&& can_create_pseudo_p ()"
3307 [(parallel [(set (match_dup 0)
3308 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3309 (and:SI (reg:SI T_REG) (const_int 1))))
3310 (clobber (reg:SI T_REG))])]
3311 {
3312 /* We don't care about the result of the left shift, only the T_REG. */
3313 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[3]));
3314 })
3315
3316 (define_insn_and_split "*rotcl"
3317 [(set (match_operand:SI 0 "arith_reg_dest")
3318 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
3319 (match_operand 2 "const_int_operand"))
3320 (zero_extract:SI (match_operand:SI 3 "arith_reg_operand")
3321 (const_int 1)
3322 (match_operand 4 "const_int_operand"))))
3323 (clobber (reg:SI T_REG))]
3324 "TARGET_SH1"
3325 "#"
3326 "&& can_create_pseudo_p ()"
3327 [(parallel [(set (match_dup 0)
3328 (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
3329 (and:SI (match_dup 5) (const_int 1))))
3330 (clobber (reg:SI T_REG))])]
3331 {
3332 if (TARGET_SH2A && satisfies_constraint_K03 (operands[4]))
3333 {
3334 /* On SH2A we can use the bld insn to zero extract a single bit
3335 into the T bit. */
3336 operands[5] = get_t_reg_rtx ();
3337 emit_insn (gen_bldsi_reg (operands[3], operands[4]));
3338 }
3339 else
3340 {
3341 /* If we can't use the bld insn we have to emit a tst + nott sequence
3342 to get the extracted bit into the T bit.
3343 This will probably be worse than pre-shifting the operand. */
3344 operands[5] = gen_reg_rtx (SImode);
3345 emit_insn (gen_lshrsi3 (operands[5], operands[3], operands[4]));
3346 }
3347 })
3348
3349 ;; rotcr combine bridge pattern which will make combine try out more
3350 ;; complex patterns.
3351 (define_insn_and_split "*rotcr"
3352 [(set (match_operand:SI 0 "arith_reg_dest")
3353 (ashift:SI (match_operand 1 "treg_set_expr") (const_int 31)))]
3354 "TARGET_SH1 && can_create_pseudo_p ()"
3355 "#"
3356 "&& 1"
3357 [(parallel [(set (match_dup 0)
3358 (ior:SI (lshiftrt:SI (const_int 0) (const_int 1))
3359 (ashift:SI (match_dup 1) (const_int 31))))
3360 (clobber (reg:SI T_REG))])])
3361
3362 (define_insn_and_split "*rotcr"
3363 [(set (match_operand:SI 0 "arith_reg_dest")
3364 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
3365 (const_int -2147483648)) ;; 0xffffffff80000000
3366 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
3367 (const_int 1))))
3368 (clobber (reg:SI T_REG))]
3369 "TARGET_SH1"
3370 "#"
3371 "&& can_create_pseudo_p ()"
3372 [(const_int 0)]
3373 {
3374 rtx tmp = gen_reg_rtx (SImode);
3375 emit_insn (gen_shll (tmp, operands[1]));
3376 emit_insn (gen_rotcr (operands[0], operands[2], get_t_reg_rtx ()));
3377 DONE;
3378 })
3379
3380 (define_insn_and_split "*rotcr"
3381 [(set (match_operand:SI 0 "arith_reg_dest")
3382 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
3383 (const_int 1))
3384 (const_int -2147483648))) ;; 0xffffffff80000000
3385 (clobber (reg:SI T_REG))]
3386 "TARGET_SH1"
3387 "#"
3388 "&& can_create_pseudo_p ()"
3389 [(const_int 0)]
3390 {
3391 emit_insn (gen_sett ());
3392 emit_insn (gen_rotcr (operands[0], operands[1], get_t_reg_rtx ()));
3393 DONE;
3394 })
3395
3396 ;; rotcr combine patterns for rotating in the negated T_REG value.
3397 (define_insn_and_split "*rotcr_neg_t"
3398 [(set (match_operand:SI 0 "arith_reg_dest")
3399 (ior:SI (match_operand:SI 1 "negt_reg_shl31_operand")
3400 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
3401 (match_operand:SI 3 "const_int_operand"))))
3402 (clobber (reg:SI T_REG))]
3403 "TARGET_SH1"
3404 "#"
3405 "&& can_create_pseudo_p ()"
3406 [(parallel [(set (match_dup 0)
3407 (ior:SI (lshiftrt:SI (match_dup 2) (match_dup 3))
3408 (ashift:SI (reg:SI T_REG) (const_int 31))))
3409 (clobber (reg:SI T_REG))])]
3410 {
3411 emit_insn (gen_nott (get_t_reg_rtx ()));
3412 })
3413
3414 (define_insn_and_split "*rotcr_neg_t"
3415 [(set (match_operand:SI 0 "arith_reg_dest")
3416 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
3417 (match_operand:SI 2 "const_int_operand"))
3418 (match_operand:SI 3 "negt_reg_shl31_operand")))
3419 (clobber (reg:SI T_REG))]
3420 "TARGET_SH1"
3421 "#"
3422 "&& can_create_pseudo_p ()"
3423 [(parallel [(set (match_dup 0)
3424 (ior:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
3425 (ashift:SI (reg:SI T_REG) (const_int 31))))
3426 (clobber (reg:SI T_REG))])]
3427 {
3428 emit_insn (gen_nott (get_t_reg_rtx ()));
3429 })
3430
3431 ;; rotcl combine patterns for rotating in the negated T_REG value.
3432 ;; For some strange reason these have to be specified as splits which combine
3433 ;; will pick up. If they are specified as insn_and_split like the
3434 ;; *rotcr_neg_t patterns above, combine would recognize them successfully
3435 ;; but not emit them on non-SH2A targets.
3436 (define_split
3437 [(set (match_operand:SI 0 "arith_reg_dest")
3438 (ior:SI (match_operand:SI 1 "negt_reg_operand")
3439 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
3440 (match_operand:SI 3 "const_int_operand"))))]
3441 "TARGET_SH1"
3442 [(set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))
3443 (parallel [(set (match_dup 0)
3444 (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
3445 (and:SI (reg:SI T_REG) (const_int 1))))
3446 (clobber (reg:SI T_REG))])])
3447
3448 (define_split
3449 [(set (match_operand:SI 0 "arith_reg_dest")
3450 (ior:SI (ashift:SI (match_operand:SI 2 "arith_reg_operand")
3451 (match_operand:SI 3 "const_int_operand"))
3452 (match_operand:SI 1 "negt_reg_operand")))]
3453 "TARGET_SH1"
3454 [(set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))
3455 (parallel [(set (match_dup 0)
3456 (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
3457 (and:SI (reg:SI T_REG) (const_int 1))))
3458 (clobber (reg:SI T_REG))])])
3459
3460 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3461 ;; SImode shift left
3462
3463 (define_expand "ashlsi3"
3464 [(set (match_operand:SI 0 "arith_reg_operand" "")
3465 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
3466 (match_operand:SI 2 "shift_count_operand" "")))]
3467 ""
3468 {
3469 if (TARGET_DYNSHIFT
3470 && CONST_INT_P (operands[2]) && sh_dynamicalize_shift_p (operands[2]))
3471 {
3472 /* Don't force the constant into a reg yet. Some other optimizations
3473 might not see through the reg that holds the shift count. */
3474 }
3475
3476 /* If the ashlsi3_* insn is going to clobber the T_REG it must be
3477 expanded here. */
3478 if (CONST_INT_P (operands[2])
3479 && sh_ashlsi_clobbers_t_reg_p (operands[2])
3480 && ! sh_dynamicalize_shift_p (operands[2]))
3481 {
3482 emit_insn (gen_ashlsi3_n_clobbers_t (operands[0], operands[1],
3483 operands[2]));
3484 DONE;
3485 }
3486
3487 /* Expand a library call for the dynamic shift. */
3488 if (!CONST_INT_P (operands[2]) && !TARGET_DYNSHIFT)
3489 {
3490 emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
3491 rtx funcaddr = gen_reg_rtx (Pmode);
3492 rtx lab = function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC).lab;
3493 emit_insn (gen_ashlsi3_d_call (operands[0], operands[2], funcaddr, lab));
3494
3495 DONE;
3496 }
3497 })
3498
3499 (define_insn "ashlsi3_k"
3500 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
3501 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0,0")
3502 (match_operand:SI 2 "p27_shift_count_operand" "M,P27")))]
3503 "TARGET_SH1"
3504 "@
3505 add %0,%0
3506 shll%O2 %0"
3507 [(set_attr "type" "arith")])
3508
3509 (define_insn_and_split "ashlsi3_d"
3510 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3511 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3512 (match_operand:SI 2 "shift_count_operand" "r")))]
3513 "TARGET_DYNSHIFT"
3514 "shld %2,%0"
3515 "&& CONST_INT_P (operands[2]) && ! sh_dynamicalize_shift_p (operands[2])
3516 && ! sh_ashlsi_clobbers_t_reg_p (operands[2])"
3517 [(const_int 0)]
3518 {
3519 if (satisfies_constraint_P27 (operands[2]))
3520 {
3521 emit_insn (gen_ashlsi3_k (operands[0], operands[1], operands[2]));
3522 DONE;
3523 }
3524 else if (! satisfies_constraint_P27 (operands[2]))
3525 {
3526 /* This must happen before reload, otherwise the constant will be moved
3527 into a register due to the "r" constraint, after which this split
3528 cannot be done anymore.
3529 Unfortunately the move insn will not always be eliminated.
3530 Also, here we must not create a shift sequence that clobbers the
3531 T_REG. */
3532 emit_move_insn (operands[0], operands[1]);
3533 gen_shifty_op (ASHIFT, operands);
3534 DONE;
3535 }
3536
3537 FAIL;
3538 }
3539 [(set_attr "type" "dyn_shift")])
3540
3541 ;; If dynamic shifts are not available use a library function.
3542 ;; By specifying the pattern we reduce the number of call clobbered regs.
3543 ;; In order to make combine understand the truncation of the shift amount
3544 ;; operand we have to allow it to use pseudo regs for the shift operands.
3545 (define_insn "ashlsi3_d_call"
3546 [(set (match_operand:SI 0 "arith_reg_dest" "=z,z")
3547 (ashift:SI (reg:SI R4_REG)
3548 (and:SI (match_operand:SI 1 "arith_reg_operand" "z,z")
3549 (const_int 31))))
3550 (use (match_operand:SI 2 "arith_reg_operand" "r,r"))
3551 (use (match_operand 3 "" "Z,Ccl"))
3552 (clobber (reg:SI T_REG))
3553 (clobber (reg:SI PR_REG))]
3554 "TARGET_SH1 && !TARGET_DYNSHIFT"
3555 "@
3556 jsr @%2%#
3557 bsrf %2\n%O3:%#"
3558 [(set_attr "type" "sfunc")
3559 (set_attr "needs_delay_slot" "yes")])
3560
3561 (define_insn_and_split "ashlsi3_n"
3562 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3563 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3564 (match_operand:SI 2 "not_p27_shift_count_operand" "")))]
3565 "TARGET_SH1 && ! sh_ashlsi_clobbers_t_reg_p (operands[2])"
3566 "#"
3567 "&& (reload_completed
3568 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
3569 [(const_int 0)]
3570 {
3571 if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
3572 {
3573 /* If this pattern was picked and dynamic shifts are supported, switch
3574 to dynamic shift pattern before reload. */
3575 operands[2] = force_reg (SImode, operands[2]);
3576 emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
3577 }
3578 else
3579 gen_shifty_op (ASHIFT, operands);
3580
3581 DONE;
3582 })
3583
3584 (define_insn_and_split "ashlsi3_n_clobbers_t"
3585 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3586 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
3587 (match_operand:SI 2 "not_p27_shift_count_operand" "")))
3588 (clobber (reg:SI T_REG))]
3589 "TARGET_SH1 && sh_ashlsi_clobbers_t_reg_p (operands[2])"
3590 "#"
3591 "&& (reload_completed || INTVAL (operands[2]) == 31
3592 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
3593 [(const_int 0)]
3594 {
3595 if (INTVAL (operands[2]) == 31)
3596 {
3597 /* If the shift amount is 31 we split into a different sequence before
3598 reload so that it gets a chance to allocate R0 for the sequence.
3599 If it fails to do so (due to pressure on R0), it will take one insn
3600 more for the and. */
3601 emit_insn (gen_andsi3 (operands[0], operands[1], const1_rtx));
3602 emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
3603 }
3604 else if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
3605 {
3606 /* If this pattern was picked and dynamic shifts are supported, switch
3607 to dynamic shift pattern before reload. */
3608 operands[2] = force_reg (SImode, operands[2]);
3609 emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
3610 }
3611 else
3612 gen_shifty_op (ASHIFT, operands);
3613
3614 DONE;
3615 })
3616
3617 (define_insn "shll"
3618 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3619 (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0") (const_int 1)))
3620 (set (reg:SI T_REG)
3621 (lt:SI (match_dup 1) (const_int 0)))]
3622 "TARGET_SH1"
3623 "shll %0"
3624 [(set_attr "type" "arith")])
3625
3626 (define_insn "*ashlsi_c_void"
3627 [(set (reg:SI T_REG)
3628 (lt:SI (match_operand:SI 0 "arith_reg_operand" "r") (const_int 0)))
3629 (clobber (match_scratch:SI 1 "=0"))]
3630 "TARGET_SH1 && cse_not_expected"
3631 "shll %0"
3632 [(set_attr "type" "arith")])
3633
3634 (define_peephole2
3635 [(set (match_operand:SI 0 "arith_reg_dest" "") (const_int 0))
3636 (set (reg:SI T_REG)
3637 (gt:SI (match_dup 0) (match_operand:SI 1 "arith_reg_operand" "")))]
3638 "TARGET_SH1
3639 && peep2_reg_dead_p (2, operands[0])
3640 && peep2_reg_dead_p (2, operands[1])"
3641 [(const_int 0)]
3642 {
3643 emit_insn (gen_shll (operands[1], operands[1]));
3644 DONE;
3645 })
3646
3647 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3648 ;; HImode shift left
3649
3650 (define_expand "ashlhi3"
3651 [(parallel [(set (match_operand:HI 0 "arith_reg_operand" "")
3652 (ashift:HI (match_operand:HI 1 "arith_reg_operand" "")
3653 (match_operand:SI 2 "nonmemory_operand" "")))
3654 (clobber (reg:SI T_REG))])]
3655 "TARGET_SH1"
3656 {
3657 if (!CONST_INT_P (operands[2]))
3658 FAIL;
3659 /* It may be possible to call gen_ashlhi3 directly with more generic
3660 operands. Make sure operands[1] is a HImode register here. */
3661 if (!arith_reg_operand (operands[1], HImode))
3662 operands[1] = copy_to_mode_reg (HImode, operands[1]);
3663 })
3664
3665 (define_insn "ashlhi3_k"
3666 [(set (match_operand:HI 0 "arith_reg_dest" "=r,r")
3667 (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0,0")
3668 (match_operand:HI 2 "const_int_operand" "M,P27")))]
3669 "TARGET_SH1 && satisfies_constraint_P27 (operands[2])"
3670 "@
3671 add %0,%0
3672 shll%O2 %0"
3673 [(set_attr "type" "arith")])
3674
3675 (define_insn_and_split "*ashlhi3_n"
3676 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
3677 (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0")
3678 (match_operand:HI 2 "const_int_operand" "n")))
3679 (clobber (reg:SI T_REG))]
3680 "TARGET_SH1"
3681 "#"
3682 "&& reload_completed"
3683 [(use (reg:SI R0_REG))]
3684 {
3685 gen_shifty_hi_op (ASHIFT, operands);
3686 DONE;
3687 })
3688
3689 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3690 ;; DImode shift left
3691
3692 (define_expand "ashldi3"
3693 [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
3694 (ashift:DI (match_operand:DI 1 "arith_reg_operand" "")
3695 (match_operand:DI 2 "immediate_operand" "")))
3696 (clobber (reg:SI T_REG))])]
3697 ""
3698 {
3699 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 1)
3700 {
3701 emit_insn (gen_ashldi3_k (operands[0], operands[1]));
3702 DONE;
3703 }
3704 else if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 32)
3705 {
3706 emit_insn (gen_ashldi3_std (operands[0], operands[1], operands[2]));
3707 DONE;
3708 }
3709 else
3710 FAIL;
3711 })
3712
3713 ;; Expander for DImode shift left with SImode operations.
3714 (define_expand "ashldi3_std"
3715 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3716 (ashift:DI (match_operand:DI 1 "arith_reg_operand" "r")
3717 (match_operand:DI 2 "const_int_operand" "n")))]
3718 "TARGET_SH1 && INTVAL (operands[2]) < 32"
3719 {
3720 rtx low_src = gen_lowpart (SImode, operands[1]);
3721 rtx high_src = gen_highpart (SImode, operands[1]);
3722 rtx dst = gen_reg_rtx (DImode);
3723 rtx low_dst = gen_lowpart (SImode, dst);
3724 rtx high_dst = gen_highpart (SImode, dst);
3725 rtx tmp0 = gen_reg_rtx (SImode);
3726 rtx tmp1 = gen_reg_rtx (SImode);
3727
3728 emit_insn (gen_lshrsi3 (tmp0, low_src, GEN_INT (32 - INTVAL (operands[2]))));
3729 emit_insn (gen_ashlsi3 (low_dst, low_src, operands[2]));
3730 emit_insn (gen_ashlsi3 (tmp1, high_src, operands[2]));
3731 emit_insn (gen_iorsi3 (high_dst, tmp0, tmp1));
3732 emit_move_insn (operands[0], dst);
3733 DONE;
3734 })
3735
3736 (define_insn_and_split "ashldi3_k"
3737 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3738 (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
3739 (const_int 1)))
3740 (clobber (reg:SI T_REG))]
3741 "TARGET_SH1"
3742 "#"
3743 "&& reload_completed"
3744 [(const_int 0)]
3745 {
3746 rtx high = gen_highpart (SImode, operands[0]);
3747 rtx low = gen_lowpart (SImode, operands[0]);
3748 emit_insn (gen_shll (low, low));
3749 emit_insn (gen_rotcl (high, high, get_t_reg_rtx ()));
3750 DONE;
3751 })
3752
3753 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3754 ;; SImode arithmetic shift right
3755 ;;
3756 ;; We can't do HImode right shifts correctly unless we start out with an
3757 ;; explicit zero / sign extension; doing that would result in worse overall
3758 ;; code, so just let the machine independent code widen the mode.
3759 ;; That's why we don't have ashrhi3_k / lshrhi3_k / lshrhi3_m / lshrhi3 .
3760
3761 (define_expand "ashrsi3"
3762 [(parallel [(set (match_operand:SI 0 "arith_reg_dest" "")
3763 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
3764 (match_operand:SI 2 "nonmemory_operand" "")))
3765 (clobber (reg:SI T_REG))])]
3766 ""
3767 {
3768 if (expand_ashiftrt (operands))
3769 DONE;
3770 else
3771 FAIL;
3772 })
3773
3774 (define_insn "shar"
3775 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3776 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3777 (const_int 1)))
3778 (set (reg:SI T_REG)
3779 (and:SI (match_dup 1) (const_int 1)))]
3780 "TARGET_SH1"
3781 "shar %0"
3782 [(set_attr "type" "arith")])
3783
3784 (define_insn "ashrsi3_k"
3785 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3786 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3787 (match_operand:SI 2 "const_int_operand" "M")))
3788 (clobber (reg:SI T_REG))]
3789 "TARGET_SH1 && INTVAL (operands[2]) == 1"
3790 "shar %0"
3791 [(set_attr "type" "arith")])
3792
3793 (define_insn_and_split "ashrsi2_16"
3794 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3795 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
3796 (const_int 16)))]
3797 "TARGET_SH1"
3798 "#"
3799 "&& 1"
3800 [(set (match_dup 0) (rotate:SI (match_dup 1) (const_int 16)))
3801 (set (match_dup 0) (sign_extend:SI (match_dup 2)))]
3802 {
3803 operands[2] = gen_lowpart (HImode, operands[0]);
3804 })
3805
3806 (define_insn_and_split "ashrsi2_31"
3807 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3808 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3809 (const_int 31)))
3810 (clobber (reg:SI T_REG))]
3811 "TARGET_SH1"
3812 "#"
3813 "&& 1"
3814 [(const_int 0)]
3815 {
3816 emit_insn (gen_shll (operands[0], operands[1]));
3817 emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
3818 DONE;
3819 })
3820
3821 ;; If the shift amount is changed by combine it will try to plug the
3822 ;; use on the symbol of the library function and the PR clobber.
3823 (define_insn_and_split "*ashrsi2_31"
3824 [(set (match_operand:SI 0 "arith_reg_dest")
3825 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand")
3826 (const_int 31)))
3827 (clobber (reg:SI T_REG))
3828 (clobber (reg:SI PR_REG))
3829 (use (match_operand:SI 2 "symbol_ref_operand"))]
3830 "TARGET_SH1"
3831 "#"
3832 "&& 1"
3833 [(parallel [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (const_int 31)))
3834 (clobber (reg:SI T_REG))])])
3835
3836 (define_insn "ashrsi3_d"
3837 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3838 (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3839 (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
3840 "TARGET_DYNSHIFT"
3841 "shad %2,%0"
3842 [(set_attr "type" "dyn_shift")])
3843
3844 (define_insn "ashrsi3_n"
3845 [(set (reg:SI R4_REG)
3846 (ashiftrt:SI (reg:SI R4_REG)
3847 (match_operand:SI 0 "const_int_operand" "i,i")))
3848 (clobber (reg:SI T_REG))
3849 (clobber (reg:SI PR_REG))
3850 (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
3851 (use (match_operand 2 "" "Z,Ccl"))]
3852 "TARGET_SH1"
3853 "@
3854 jsr @%1%#
3855 bsrf %1\n%O2:%#"
3856 [(set_attr "type" "sfunc")
3857 (set_attr "needs_delay_slot" "yes")])
3858
3859 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3860 ;; DImode arithmetic shift right
3861
3862 (define_expand "ashrdi3"
3863 [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
3864 (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
3865 (match_operand:DI 2 "immediate_operand" "")))
3866 (clobber (reg:SI T_REG))])]
3867 ""
3868 {
3869 if (!CONST_INT_P (operands[2]) || INTVAL (operands[2]) != 1)
3870 FAIL;
3871 })
3872
3873 (define_insn_and_split "ashrdi3_k"
3874 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3875 (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
3876 (const_int 1)))
3877 (clobber (reg:SI T_REG))]
3878 "TARGET_SH1"
3879 "#"
3880 "&& reload_completed"
3881 [(const_int 0)]
3882 {
3883 rtx high = gen_highpart (SImode, operands[0]);
3884 rtx low = gen_lowpart (SImode, operands[0]);
3885 emit_insn (gen_shar (high, high));
3886 emit_insn (gen_rotcr (low, low, get_t_reg_rtx ()));
3887 DONE;
3888 })
3889
3890 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3891 ;; SImode logical shift right
3892
3893 (define_expand "lshrsi3"
3894 [(set (match_operand:SI 0 "arith_reg_dest" "")
3895 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
3896 (match_operand:SI 2 "shift_count_operand" "")))]
3897 ""
3898 {
3899 /* If a dynamic shift is supposed to be used, expand the lshrsi3_d insn
3900 here, otherwise the pattern will never match due to the shift amount reg
3901 negation. */
3902 if (TARGET_DYNSHIFT
3903 && CONST_INT_P (operands[2]) && sh_dynamicalize_shift_p (operands[2]))
3904 {
3905 /* Don't force the constant into a reg yet. Some other optimizations
3906 might not see through the reg that holds the shift count. */
3907 if (sh_lshrsi_clobbers_t_reg_p (operands[2]))
3908 emit_insn (gen_lshrsi3_n_clobbers_t (operands[0], operands[1], operands[2]));
3909 else
3910 emit_insn (gen_lshrsi3_n (operands[0], operands[1], operands[2]));
3911 DONE;
3912 }
3913
3914 if (TARGET_DYNSHIFT && ! CONST_INT_P (operands[2]))
3915 {
3916 rtx neg_count = gen_reg_rtx (SImode);
3917 emit_insn (gen_negsi2 (neg_count, operands[2]));
3918 emit_insn (gen_lshrsi3_d (operands[0], operands[1], neg_count));
3919 DONE;
3920 }
3921
3922 /* If the lshrsi3_* insn is going to clobber the T_REG it must be
3923 expanded here. */
3924 if (CONST_INT_P (operands[2])
3925 && sh_lshrsi_clobbers_t_reg_p (operands[2])
3926 && ! sh_dynamicalize_shift_p (operands[2]))
3927 {
3928 emit_insn (gen_lshrsi3_n_clobbers_t (operands[0], operands[1],
3929 operands[2]));
3930 DONE;
3931 }
3932
3933 /* Expand a library call for the dynamic shift. */
3934 if (!CONST_INT_P (operands[2]) && !TARGET_DYNSHIFT)
3935 {
3936 emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
3937 rtx funcaddr = gen_reg_rtx (Pmode);
3938 rtx lab = function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC).lab;
3939 emit_insn (gen_lshrsi3_d_call (operands[0], operands[2], funcaddr, lab));
3940 DONE;
3941 }
3942 })
3943
3944 (define_insn "lshrsi3_k"
3945 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3946 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3947 (match_operand:SI 2 "p27_rshift_count_operand" "P27")))]
3948 "TARGET_SH1"
3949 "shlr%O2 %0"
3950 [(set_attr "type" "arith")])
3951
3952 (define_insn_and_split "lshrsi3_d"
3953 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3954 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
3955 (neg:SI (match_operand:SI 2 "shift_count_operand" "r"))))]
3956 "TARGET_DYNSHIFT"
3957 "shld %2,%0"
3958 "&& CONST_INT_P (operands[2]) && ! sh_dynamicalize_shift_p (operands[2])
3959 && ! sh_lshrsi_clobbers_t_reg_p (operands[2])"
3960 [(const_int 0)]
3961 {
3962 /* The shift count const_int is a negative value for all dynamic
3963 right shift insns. */
3964 operands[2] = GEN_INT (- INTVAL (operands[2]));
3965
3966 if (satisfies_constraint_P27 (operands[2]))
3967 {
3968 /* This will not be done for a shift amount of 1, because it would
3969 clobber the T_REG. */
3970 emit_insn (gen_lshrsi3_k (operands[0], operands[1], operands[2]));
3971 DONE;
3972 }
3973 else if (! satisfies_constraint_P27 (operands[2]))
3974 {
3975 /* This must happen before reload, otherwise the constant will be moved
3976 into a register due to the "r" constraint, after which this split
3977 cannot be done anymore.
3978 Unfortunately the move insn will not always be eliminated.
3979 Also, here we must not create a shift sequence that clobbers the
3980 T_REG. */
3981 emit_move_insn (operands[0], operands[1]);
3982 gen_shifty_op (LSHIFTRT, operands);
3983 DONE;
3984 }
3985
3986 FAIL;
3987 }
3988 [(set_attr "type" "dyn_shift")])
3989
3990 ;; If dynamic shifts are not available use a library function.
3991 ;; By specifying the pattern we reduce the number of call clobbered regs.
3992 ;; In order to make combine understand the truncation of the shift amount
3993 ;; operand we have to allow it to use pseudo regs for the shift operands.
3994 (define_insn "lshrsi3_d_call"
3995 [(set (match_operand:SI 0 "arith_reg_dest" "=z,z")
3996 (lshiftrt:SI (reg:SI R4_REG)
3997 (and:SI (match_operand:SI 1 "arith_reg_operand" "z,z")
3998 (const_int 31))))
3999 (use (match_operand:SI 2 "arith_reg_operand" "r,r"))
4000 (use (match_operand 3 "" "Z,Ccl"))
4001 (clobber (reg:SI T_REG))
4002 (clobber (reg:SI PR_REG))]
4003 "TARGET_SH1 && !TARGET_DYNSHIFT"
4004 "@
4005 jsr @%2%#
4006 bsrf %2\n%O3:%#"
4007 [(set_attr "type" "sfunc")
4008 (set_attr "needs_delay_slot" "yes")])
4009
4010 (define_insn_and_split "lshrsi3_n"
4011 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4012 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4013 (match_operand:SI 2 "not_p27_rshift_count_operand")))]
4014 "TARGET_SH1 && ! sh_lshrsi_clobbers_t_reg_p (operands[2])"
4015 "#"
4016 "&& (reload_completed
4017 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
4018 [(const_int 0)]
4019 {
4020 if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
4021 {
4022 /* If this pattern was picked and dynamic shifts are supported, switch
4023 to dynamic shift pattern before reload. */
4024 operands[2] = GEN_INT (- INTVAL (operands[2]));
4025 emit_insn (gen_lshrsi3_d (operands[0], operands[1], operands[2]));
4026 }
4027 else
4028 gen_shifty_op (LSHIFTRT, operands);
4029
4030 DONE;
4031 })
4032
4033 ;; The lshrsi3_n_clobbers_t pattern also works as a simplified version of
4034 ;; the shlr pattern.
4035 (define_insn_and_split "lshrsi3_n_clobbers_t"
4036 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4037 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4038 (match_operand:SI 2 "not_p27_rshift_count_operand")))
4039 (clobber (reg:SI T_REG))]
4040 "TARGET_SH1 && sh_lshrsi_clobbers_t_reg_p (operands[2])"
4041 "#"
4042 "&& (reload_completed || INTVAL (operands[2]) == 31
4043 || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
4044 [(const_int 0)]
4045 {
4046 if (INTVAL (operands[2]) == 31)
4047 {
4048 emit_insn (gen_shll (operands[0], operands[1]));
4049 emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
4050 }
4051 else if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
4052 {
4053 /* If this pattern was picked and dynamic shifts are supported, switch
4054 to dynamic shift pattern before reload. */
4055 operands[2] = GEN_INT (- INTVAL (operands[2]));
4056 emit_insn (gen_lshrsi3_d (operands[0], operands[1], operands[2]));
4057 }
4058 else
4059 gen_shifty_op (LSHIFTRT, operands);
4060
4061 DONE;
4062 })
4063
4064 (define_insn "shlr"
4065 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4066 (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4067 (const_int 1)))
4068 (set (reg:SI T_REG)
4069 (and:SI (match_dup 1) (const_int 1)))]
4070 "TARGET_SH1"
4071 "shlr %0"
4072 [(set_attr "type" "arith")])
4073
4074 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4075 ;; DImode logical shift right
4076
4077 (define_expand "lshrdi3"
4078 [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
4079 (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
4080 (match_operand:DI 2 "immediate_operand" "")))
4081 (clobber (reg:SI T_REG))])]
4082 ""
4083 {
4084 if (!CONST_INT_P (operands[2]) || INTVAL (operands[2]) != 1)
4085 FAIL;
4086 })
4087
4088 (define_insn_and_split "lshrdi3_k"
4089 [(set (match_operand:DI 0 "arith_reg_dest" "=r")
4090 (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
4091 (const_int 1)))
4092 (clobber (reg:SI T_REG))]
4093 "TARGET_SH1"
4094 "#"
4095 "&& reload_completed"
4096 [(const_int 0)]
4097 {
4098 rtx high = gen_highpart (SImode, operands[0]);
4099 rtx low = gen_lowpart (SImode, operands[0]);
4100 emit_insn (gen_shlr (high, high));
4101 emit_insn (gen_rotcr (low, low, get_t_reg_rtx ()));
4102 DONE;
4103 })
4104
4105 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4106 ;; Combined left/right shifts
4107
4108 (define_split
4109 [(set (match_operand:SI 0 "register_operand" "")
4110 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4111 (match_operand:SI 2 "const_int_operand" ""))
4112 (match_operand:SI 3 "const_int_operand" "")))]
4113 "TARGET_SH1 && reload_completed && (unsigned)INTVAL (operands[2]) < 32"
4114 [(use (reg:SI R0_REG))]
4115 {
4116 if (gen_shl_and (operands[0], operands[2], operands[3], operands[1]))
4117 FAIL;
4118 DONE;
4119 })
4120
4121 (define_split
4122 [(set (match_operand:SI 0 "register_operand" "")
4123 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4124 (match_operand:SI 2 "const_int_operand" ""))
4125 (match_operand:SI 3 "const_int_operand" "")))
4126 (clobber (reg:SI T_REG))]
4127 "TARGET_SH1 && reload_completed && (unsigned)INTVAL (operands[2]) < 32"
4128 [(use (reg:SI R0_REG))]
4129 {
4130 if (gen_shl_and (operands[0], operands[2], operands[3], operands[1]))
4131 FAIL;
4132 DONE;
4133 })
4134
4135 (define_insn ""
4136 [(set (match_operand:SI 0 "register_operand" "=r")
4137 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
4138 (match_operand:SI 2 "const_int_operand" "n"))
4139 (match_operand:SI 3 "const_int_operand" "n")))
4140 (clobber (reg:SI T_REG))]
4141 "TARGET_SH1 && shl_and_kind (operands[2], operands[3], 0) == 1"
4142 "#"
4143 [(set (attr "length")
4144 (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
4145 (const_string "4")
4146 (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
4147 (const_string "6")
4148 (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
4149 (const_string "8")
4150 (eq (symbol_ref "shl_and_length (insn)") (const_int 5))
4151 (const_string "10")
4152 (eq (symbol_ref "shl_and_length (insn)") (const_int 6))
4153 (const_string "12")
4154 (eq (symbol_ref "shl_and_length (insn)") (const_int 7))
4155 (const_string "14")
4156 (eq (symbol_ref "shl_and_length (insn)") (const_int 8))
4157 (const_string "16")]
4158 (const_string "18")))
4159 (set_attr "type" "arith")])
4160
4161 (define_insn ""
4162 [(set (match_operand:SI 0 "register_operand" "=z")
4163 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
4164 (match_operand:SI 2 "const_int_operand" "n"))
4165 (match_operand:SI 3 "const_int_operand" "n")))
4166 (clobber (reg:SI T_REG))]
4167 "TARGET_SH1 && shl_and_kind (operands[2], operands[3], 0) == 2"
4168 "#"
4169 [(set (attr "length")
4170 (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
4171 (const_string "4")
4172 (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
4173 (const_string "6")
4174 (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
4175 (const_string "8")]
4176 (const_string "10")))
4177 (set_attr "type" "arith")])
4178
4179 ;; shift left / and combination with a scratch register: The combine pass
4180 ;; does not accept the individual instructions, even though they are
4181 ;; cheap. But it needs a precise description so that it is usable after
4182 ;; reload.
4183 (define_insn "and_shl_scratch"
4184 [(set (match_operand:SI 0 "register_operand" "=r,&r")
4185 (lshiftrt:SI
4186 (ashift:SI
4187 (and:SI
4188 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
4189 (match_operand:SI 2 "const_int_operand" "N,n"))
4190 (match_operand:SI 3 "" "0,r"))
4191 (match_operand:SI 4 "const_int_operand" "n,n"))
4192 (match_operand:SI 5 "const_int_operand" "n,n")))
4193 (clobber (reg:SI T_REG))]
4194 "TARGET_SH1"
4195 "#"
4196 [(set (attr "length")
4197 (cond [(eq (symbol_ref "shl_and_scr_length (insn)") (const_int 2))
4198 (const_string "4")
4199 (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 3))
4200 (const_string "6")
4201 (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 4))
4202 (const_string "8")
4203 (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 5))
4204 (const_string "10")]
4205 (const_string "12")))
4206 (set_attr "type" "arith")])
4207
4208 (define_split
4209 [(set (match_operand:SI 0 "register_operand" "")
4210 (lshiftrt:SI
4211 (ashift:SI
4212 (and:SI
4213 (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
4214 (match_operand:SI 2 "const_int_operand" ""))
4215 (match_operand:SI 3 "register_operand" ""))
4216 (match_operand:SI 4 "const_int_operand" ""))
4217 (match_operand:SI 5 "const_int_operand" "")))
4218 (clobber (reg:SI T_REG))]
4219 "TARGET_SH1"
4220 [(use (reg:SI R0_REG))]
4221 {
4222 rtx and_source = operands[rtx_equal_p (operands[0], operands[1]) ? 3 : 1];
4223
4224 if (INTVAL (operands[2]))
4225 {
4226 gen_shifty_op (LSHIFTRT, operands);
4227 }
4228 emit_insn (gen_andsi3 (operands[0], operands[0], and_source));
4229 operands[2] = operands[4];
4230 gen_shifty_op (ASHIFT, operands);
4231 if (INTVAL (operands[5]))
4232 {
4233 operands[2] = operands[5];
4234 gen_shifty_op (LSHIFTRT, operands);
4235 }
4236 DONE;
4237 })
4238
4239 ;; signed left/right shift combination.
4240 (define_split
4241 [(set (match_operand:SI 0 "register_operand" "")
4242 (sign_extract:SI
4243 (ashift:SI (match_operand:SI 1 "register_operand" "")
4244 (match_operand:SI 2 "const_int_operand" ""))
4245 (match_operand:SI 3 "const_int_operand" "")
4246 (const_int 0)))
4247 (clobber (reg:SI T_REG))]
4248 "TARGET_SH1"
4249 [(use (reg:SI R0_REG))]
4250 {
4251 if (gen_shl_sext (operands[0], operands[2], operands[3], operands[1]))
4252 FAIL;
4253 DONE;
4254 })
4255
4256 (define_insn "shl_sext_ext"
4257 [(set (match_operand:SI 0 "register_operand" "=r")
4258 (sign_extract:SI
4259 (ashift:SI (match_operand:SI 1 "register_operand" "0")
4260 (match_operand:SI 2 "const_int_operand" "n"))
4261 (match_operand:SI 3 "const_int_operand" "n")
4262 (const_int 0)))
4263 (clobber (reg:SI T_REG))]
4264 "TARGET_SH1 && (unsigned)shl_sext_kind (operands[2], operands[3], 0) - 1 < 5"
4265 "#"
4266 [(set (attr "length")
4267 (cond [(match_test "shl_sext_length (insn)")
4268 (const_string "2")
4269 (eq (symbol_ref "shl_sext_length (insn)") (const_int 2))
4270 (const_string "4")
4271 (eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
4272 (const_string "6")
4273 (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
4274 (const_string "8")
4275 (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
4276 (const_string "10")
4277 (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
4278 (const_string "12")
4279 (eq (symbol_ref "shl_sext_length (insn)") (const_int 7))
4280 (const_string "14")
4281 (eq (symbol_ref "shl_sext_length (insn)") (const_int 8))
4282 (const_string "16")]
4283 (const_string "18")))
4284 (set_attr "type" "arith")])
4285
4286 (define_insn "shl_sext_sub"
4287 [(set (match_operand:SI 0 "register_operand" "=z")
4288 (sign_extract:SI
4289 (ashift:SI (match_operand:SI 1 "register_operand" "0")
4290 (match_operand:SI 2 "const_int_operand" "n"))
4291 (match_operand:SI 3 "const_int_operand" "n")
4292 (const_int 0)))
4293 (clobber (reg:SI T_REG))]
4294 "TARGET_SH1 && (shl_sext_kind (operands[2], operands[3], 0) & ~1) == 6"
4295 "#"
4296 [(set (attr "length")
4297 (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
4298 (const_string "6")
4299 (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
4300 (const_string "8")
4301 (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
4302 (const_string "10")
4303 (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
4304 (const_string "12")]
4305 (const_string "14")))
4306 (set_attr "type" "arith")])
4307
4308 ;; The xtrct_left and xtrct_right patterns are used in expansions of DImode
4309 ;; shifts by 16, and allow the xtrct instruction to be generated from C
4310 ;; source.
4311 (define_insn "xtrct_left"
4312 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4313 (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
4314 (const_int 16))
4315 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand" "0")
4316 (const_int 16))))]
4317 "TARGET_SH1"
4318 "xtrct %1,%0"
4319 [(set_attr "type" "arith")])
4320
4321 (define_insn "xtrct_right"
4322 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4323 (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4324 (const_int 16))
4325 (ashift:SI (match_operand:SI 2 "arith_reg_operand" "r")
4326 (const_int 16))))]
4327 "TARGET_SH1"
4328 "xtrct %2,%0"
4329 [(set_attr "type" "arith")])
4330
4331 ;; -------------------------------------------------------------------------
4332 ;; Unary arithmetic
4333 ;; -------------------------------------------------------------------------
4334
4335 (define_insn "negc"
4336 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4337 (neg:SI (plus:SI (reg:SI T_REG)
4338 (match_operand:SI 1 "arith_reg_operand" "r"))))
4339 (set (reg:SI T_REG)
4340 (ne:SI (ior:SI (reg:SI T_REG) (match_dup 1))
4341 (const_int 0)))]
4342 "TARGET_SH1"
4343 "negc %1,%0"
4344 [(set_attr "type" "arith")])
4345
4346 ;; A simplified version of the negc insn, where the exact value of the
4347 ;; T bit doesn't matter. This is easier for combine to pick up.
4348 ;; Notice that '0 - x - 1' is the same as '~x', thus we don't specify
4349 ;; extra patterns for this case.
4350 (define_insn_and_split "*negc"
4351 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4352 (minus:SI (neg:SI (match_operand:SI 1 "arith_reg_operand" "r"))
4353 (match_operand 2 "treg_set_expr")))
4354 (clobber (reg:SI T_REG))]
4355 "TARGET_SH1 && can_create_pseudo_p ()"
4356 "#"
4357 "&& 1"
4358 [(const_int 0)]
4359 {
4360 sh_split_treg_set_expr (operands[2], curr_insn);
4361 emit_insn (gen_negc (operands[0], operands[1]));
4362 DONE;
4363 });
4364
4365 ;; Don't split into individual negc insns immediately so that neg:DI (abs:DI)
4366 ;; can be combined.
4367 (define_insn_and_split "negdi2"
4368 [(set (match_operand:DI 0 "arith_reg_dest")
4369 (neg:DI (match_operand:DI 1 "arith_reg_operand")))
4370 (clobber (reg:SI T_REG))]
4371 "TARGET_SH1"
4372 "#"
4373 "&& can_create_pseudo_p ()"
4374 [(const_int 0)]
4375 {
4376 emit_insn (gen_clrt ());
4377 emit_insn (gen_negc (gen_lowpart (SImode, operands[0]),
4378 gen_lowpart (SImode, operands[1])));
4379 emit_insn (gen_negc (gen_highpart (SImode, operands[0]),
4380 gen_highpart (SImode, operands[1])));
4381 DONE;
4382 })
4383
4384 (define_insn "negsi2"
4385 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4386 (neg:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
4387 "TARGET_SH1"
4388 "neg %1,%0"
4389 [(set_attr "type" "arith")])
4390
4391 (define_insn_and_split "one_cmplsi2"
4392 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4393 (not:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
4394 "TARGET_SH1"
4395 "not %1,%0"
4396 "&& can_create_pseudo_p ()"
4397 [(set (reg:SI T_REG) (ge:SI (match_dup 1) (const_int 0)))
4398 (set (match_dup 0) (reg:SI T_REG))]
4399 {
4400 /* PR 54685
4401 If the result of 'unsigned int <= 0x7FFFFFFF' ends up as the following
4402 sequence:
4403
4404 (set (reg0) (not:SI (reg0) (reg1)))
4405 (parallel [(set (reg2) (lshiftrt:SI (reg0) (const_int 31)))
4406 (clobber (reg:SI T_REG))])
4407
4408 ... match and combine the sequence manually in the split pass after the
4409 combine pass. Notice that combine does try the target pattern of this
4410 split, but if the pattern is added it interferes with other patterns, in
4411 particular with the div0s comparisons.
4412 This could also be done with a peephole but doing it here before register
4413 allocation can save one temporary.
4414 When we're here, the not:SI pattern obviously has been matched already
4415 and we only have to see whether the following insn is the left shift. */
4416
4417 rtx_insn *i = next_nonnote_insn_bb (curr_insn);
4418 if (i == NULL_RTX || !NONJUMP_INSN_P (i))
4419 FAIL;
4420
4421 rtx p = PATTERN (i);
4422 if (GET_CODE (p) != PARALLEL || XVECLEN (p, 0) != 2)
4423 FAIL;
4424
4425 rtx p0 = XVECEXP (p, 0, 0);
4426 rtx p1 = XVECEXP (p, 0, 1);
4427
4428 if (/* (set (reg2) (lshiftrt:SI (reg0) (const_int 31))) */
4429 GET_CODE (p0) == SET
4430 && GET_CODE (XEXP (p0, 1)) == LSHIFTRT
4431 && REG_P (XEXP (XEXP (p0, 1), 0))
4432 && REGNO (XEXP (XEXP (p0, 1), 0)) == REGNO (operands[0])
4433 && CONST_INT_P (XEXP (XEXP (p0, 1), 1))
4434 && INTVAL (XEXP (XEXP (p0, 1), 1)) == 31
4435
4436 /* (clobber (reg:SI T_REG)) */
4437 && GET_CODE (p1) == CLOBBER && REG_P (XEXP (p1, 0))
4438 && REGNO (XEXP (p1, 0)) == T_REG)
4439 {
4440 operands[0] = XEXP (p0, 0);
4441 set_insn_deleted (i);
4442 }
4443 else
4444 FAIL;
4445 }
4446 [(set_attr "type" "arith")])
4447
4448 (define_insn_and_split "abs<mode>2"
4449 [(set (match_operand:SIDI 0 "arith_reg_dest")
4450 (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand")))
4451 (clobber (reg:SI T_REG))]
4452 "TARGET_SH1"
4453 "#"
4454 "&& can_create_pseudo_p ()"
4455 [(const_int 0)]
4456 {
4457 if (<MODE>mode == SImode)
4458 emit_insn (gen_cmpgesi_t (operands[1], const0_rtx));
4459 else
4460 {
4461 rtx high_src = gen_highpart (SImode, operands[1]);
4462 emit_insn (gen_cmpgesi_t (high_src, const0_rtx));
4463 }
4464
4465 emit_insn (gen_neg<mode>_cond (operands[0], operands[1], operands[1],
4466 const1_rtx));
4467 DONE;
4468 })
4469
4470 (define_insn_and_split "*negabs<mode>2"
4471 [(set (match_operand:SIDI 0 "arith_reg_dest")
4472 (neg:SIDI (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand"))))
4473 (clobber (reg:SI T_REG))]
4474 "TARGET_SH1"
4475 "#"
4476 "&& can_create_pseudo_p ()"
4477 [(const_int 0)]
4478 {
4479 if (<MODE>mode == SImode)
4480 emit_insn (gen_cmpgesi_t (operands[1], const0_rtx));
4481 else
4482 {
4483 rtx high_src = gen_highpart (SImode, operands[1]);
4484 emit_insn (gen_cmpgesi_t (high_src, const0_rtx));
4485 }
4486
4487 emit_insn (gen_neg<mode>_cond (operands[0], operands[1], operands[1],
4488 const0_rtx));
4489 DONE;
4490 })
4491
4492 ;; The SH4 202 can do zero-offset branches without pipeline stalls.
4493 ;; This can be used as some kind of conditional execution, which is useful
4494 ;; for abs.
4495 ;; Actually the instruction scheduling should decide whether to use a
4496 ;; zero-offset branch or not for any generic case involving a single
4497 ;; instruction on SH4 202.
4498 (define_insn_and_split "negsi_cond"
4499 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4500 (if_then_else
4501 (eq:SI (reg:SI T_REG) (match_operand:SI 3 "const_int_operand" "M,N"))
4502 (match_operand:SI 1 "arith_reg_operand" "0,0")
4503 (neg:SI (match_operand:SI 2 "arith_reg_operand" "r,r"))))]
4504 "TARGET_SH1 && TARGET_ZDCBRANCH"
4505 {
4506 static const char* alt[] =
4507 {
4508 "bt 0f" "\n"
4509 " neg %2,%0" "\n"
4510 "0:",
4511
4512 "bf 0f" "\n"
4513 " neg %2,%0" "\n"
4514 "0:"
4515 };
4516 return alt[which_alternative];
4517 }
4518 "TARGET_SH1 && ! TARGET_ZDCBRANCH"
4519 [(const_int 0)]
4520 {
4521 rtx_code_label *skip_neg_label = gen_label_rtx ();
4522
4523 emit_move_insn (operands[0], operands[1]);
4524
4525 emit_jump_insn (INTVAL (operands[3])
4526 ? gen_branch_true (skip_neg_label)
4527 : gen_branch_false (skip_neg_label));
4528
4529 emit_label_after (skip_neg_label,
4530 emit_insn (gen_negsi2 (operands[0], operands[1])));
4531 DONE;
4532 }
4533 [(set_attr "type" "arith") ;; poor approximation
4534 (set_attr "length" "4")])
4535
4536 (define_insn_and_split "negdi_cond"
4537 [(set (match_operand:DI 0 "arith_reg_dest")
4538 (if_then_else
4539 (eq:SI (reg:SI T_REG) (match_operand:SI 3 "const_int_operand"))
4540 (match_operand:DI 1 "arith_reg_operand")
4541 (neg:DI (match_operand:DI 2 "arith_reg_operand"))))
4542 (clobber (reg:SI T_REG))]
4543 "TARGET_SH1"
4544 "#"
4545 "&& can_create_pseudo_p ()"
4546 [(const_int 0)]
4547 {
4548 rtx_code_label *skip_neg_label = gen_label_rtx ();
4549
4550 emit_move_insn (operands[0], operands[1]);
4551
4552 emit_jump_insn (INTVAL (operands[3])
4553 ? gen_branch_true (skip_neg_label)
4554 : gen_branch_false (skip_neg_label));
4555
4556 if (!INTVAL (operands[3]))
4557 emit_insn (gen_clrt ());
4558
4559 emit_insn (gen_negc (gen_lowpart (SImode, operands[0]),
4560 gen_lowpart (SImode, operands[1])));
4561 emit_label_after (skip_neg_label,
4562 emit_insn (gen_negc (gen_highpart (SImode, operands[0]),
4563 gen_highpart (SImode, operands[1]))));
4564 DONE;
4565 })
4566
4567 (define_expand "bswapsi2"
4568 [(set (match_operand:SI 0 "arith_reg_dest" "")
4569 (bswap:SI (match_operand:SI 1 "arith_reg_operand" "")))]
4570 "TARGET_SH1"
4571 {
4572 if (! can_create_pseudo_p ())
4573 FAIL;
4574 else
4575 {
4576 rtx tmp0 = gen_reg_rtx (SImode);
4577 rtx tmp1 = gen_reg_rtx (SImode);
4578
4579 emit_insn (gen_swapbsi2 (tmp0, operands[1]));
4580 emit_insn (gen_rotlsi3_16 (tmp1, tmp0));
4581 emit_insn (gen_swapbsi2 (operands[0], tmp1));
4582 DONE;
4583 }
4584 })
4585
4586 (define_insn "swapbsi2"
4587 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4588 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "r")
4589 (const_int -65536)) ;; 0xFFFF0000
4590 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
4591 (const_int 65280))
4592 (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
4593 (const_int 255)))))]
4594 "TARGET_SH1"
4595 "swap.b %1,%0"
4596 [(set_attr "type" "arith")])
4597
4598 ;; The *swapbisi2_and_shl8 pattern helps the combine pass simplifying
4599 ;; partial byte swap expressions such as...
4600 ;; ((x & 0xFF) << 8) | ((x >> 8) & 0xFF).
4601 ;; ...which are currently not handled by the tree optimizers.
4602 ;; The combine pass will not initially try to combine the full expression,
4603 ;; but only some sub-expressions. In such a case the *swapbisi2_and_shl8
4604 ;; pattern acts as an intermediate pattern that will eventually lead combine
4605 ;; to the swapbsi2 pattern above.
4606 ;; As a side effect this also improves code that does (x & 0xFF) << 8
4607 ;; or (x << 8) & 0xFF00.
4608 (define_insn_and_split "*swapbisi2_and_shl8"
4609 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4610 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
4611 (const_int 8))
4612 (const_int 65280))
4613 (match_operand:SI 2 "arith_reg_operand" "r")))]
4614 "TARGET_SH1 && ! reload_in_progress && ! reload_completed"
4615 "#"
4616 "&& can_create_pseudo_p ()"
4617 [(const_int 0)]
4618 {
4619 rtx tmp0 = gen_reg_rtx (SImode);
4620 rtx tmp1 = gen_reg_rtx (SImode);
4621
4622 emit_insn (gen_zero_extendqisi2 (tmp0, gen_lowpart (QImode, operands[1])));
4623 emit_insn (gen_swapbsi2 (tmp1, tmp0));
4624 emit_insn (gen_iorsi3 (operands[0], tmp1, operands[2]));
4625 DONE;
4626 })
4627
4628 ;; The *swapbhisi2 pattern is, like the *swapbisi2_and_shl8 pattern, another
4629 ;; intermediate pattern that will help the combine pass arriving at swapbsi2.
4630 (define_insn_and_split "*swapbhisi2"
4631 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4632 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
4633 (const_int 8))
4634 (const_int 65280))
4635 (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))))]
4636 "TARGET_SH1 && ! reload_in_progress && ! reload_completed"
4637 "#"
4638 "&& can_create_pseudo_p ()"
4639 [(const_int 0)]
4640 {
4641 rtx tmp = gen_reg_rtx (SImode);
4642
4643 emit_insn (gen_zero_extendhisi2 (tmp, gen_lowpart (HImode, operands[1])));
4644 emit_insn (gen_swapbsi2 (operands[0], tmp));
4645 DONE;
4646 })
4647
4648 ;; In some cases the swapbsi2 pattern might leave a sequence such as...
4649 ;; swap.b r4,r4
4650 ;; mov r4,r0
4651 ;;
4652 ;; which can be simplified to...
4653 ;; swap.b r4,r0
4654 (define_peephole2
4655 [(set (match_operand:SI 0 "arith_reg_dest" "")
4656 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "")
4657 (const_int -65536)) ;; 0xFFFF0000
4658 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
4659 (const_int 65280))
4660 (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
4661 (const_int 255)))))
4662 (set (match_operand:SI 2 "arith_reg_dest" "")
4663 (match_dup 0))]
4664 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
4665 [(set (match_dup 2)
4666 (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "")
4667 (const_int -65536)) ;; 0xFFFF0000
4668 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
4669 (const_int 65280))
4670 (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
4671 (const_int 255)))))])
4672 \f
4673 ;; -------------------------------------------------------------------------
4674 ;; Zero extension instructions
4675 ;; -------------------------------------------------------------------------
4676
4677 (define_expand "zero_extend<mode>si2"
4678 [(set (match_operand:SI 0 "arith_reg_dest")
4679 (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand")))])
4680
4681 (define_insn_and_split "*zero_extend<mode>si2_compact"
4682 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4683 (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand" "r")))]
4684 "TARGET_SH1"
4685 "extu.<bw> %1,%0"
4686 "&& can_create_pseudo_p ()"
4687 [(set (match_dup 0) (match_dup 2))]
4688 {
4689 /* Sometimes combine fails to combine a T bit or negated T bit store to a
4690 reg with a following zero extension. In the split pass after combine,
4691 try to figure out how the extended reg was set. If it originated from
4692 the T bit we can replace the zero extension with a reg move, which will
4693 be eliminated. Notice that this also helps the *cbranch_t splitter when
4694 it tries to post-combine tests and conditional branches, as it does not
4695 check for zero extensions. */
4696 operands[2] = sh_try_omit_signzero_extend (operands[1], curr_insn);
4697 if (operands[2] == NULL_RTX)
4698 FAIL;
4699 }
4700 [(set_attr "type" "arith")])
4701
4702 (define_insn "zero_extendqihi2"
4703 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
4704 (zero_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
4705 "TARGET_SH1"
4706 "extu.b %1,%0"
4707 [(set_attr "type" "arith")])
4708
4709 ;; SH2A supports two zero extending load instructions: movu.b and movu.w.
4710 ;; They could also be used for simple memory addresses like @Rn by setting
4711 ;; the displacement value to zero. However, doing so too early results in
4712 ;; missed opportunities for other optimizations such as post-inc or index
4713 ;; addressing loads.
4714 ;; We don't allow the zero extending loads to match during RTL expansion,
4715 ;; as this would pessimize other optimization opportunities such as bit
4716 ;; extractions of unsigned mems, where the zero extraction is irrelevant.
4717 ;; If the zero extracting mem loads are emitted early it will be more
4718 ;; difficult to change them back to sign extending loads (which are preferred).
4719 ;; The combine pass will also try to combine mem loads and zero extends,
4720 ;; which is prevented by 'sh_legitimate_combined_insn'.
4721 (define_insn "*zero_extend<mode>si2_disp_mem"
4722 [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4723 (zero_extend:SI
4724 (match_operand:QIHI 1 "zero_extend_movu_operand" "Sdd,Sra")))]
4725 "TARGET_SH2A"
4726 "@
4727 movu.<bw> %1,%0
4728 movu.<bw> @(0,%t1),%0"
4729 [(set_attr "type" "load")
4730 (set_attr "length" "4")])
4731
4732 ;; Convert the zero extending loads in sequences such as:
4733 ;; movu.b @(1,r5),r0 movu.w @(2,r5),r0
4734 ;; mov.b r0,@(1,r4) mov.b r0,@(1,r4)
4735 ;;
4736 ;; back to sign extending loads like:
4737 ;; mov.b @(1,r5),r0 mov.w @(2,r5),r0
4738 ;; mov.b r0,@(1,r4) mov.b r0,@(1,r4)
4739 ;;
4740 ;; if the extension type is irrelevant. The sign extending mov.{b|w} insn
4741 ;; is only 2 bytes in size if the displacement is {K04|K05}.
4742 ;; If the displacement is greater it doesn't matter, so we convert anyways.
4743 (define_peephole2
4744 [(set (match_operand:SI 0 "arith_reg_dest" "")
4745 (zero_extend:SI (match_operand 1 "displacement_mem_operand" "")))
4746 (set (match_operand 2 "nonimmediate_operand" "")
4747 (match_operand 3 "arith_reg_operand" ""))]
4748 "TARGET_SH2A
4749 && REGNO (operands[0]) == REGNO (operands[3])
4750 && peep2_reg_dead_p (2, operands[0])
4751 && GET_MODE_SIZE (GET_MODE (operands[2]))
4752 <= GET_MODE_SIZE (GET_MODE (operands[1]))"
4753 [(set (match_dup 0) (sign_extend:SI (match_dup 1)))
4754 (set (match_dup 2) (match_dup 3))])
4755
4756 ;; Fold sequences such as
4757 ;; mov.b @r3,r7
4758 ;; extu.b r7,r7
4759 ;; into
4760 ;; movu.b @(0,r3),r7
4761 ;; This does not reduce the code size but the number of instructions is
4762 ;; halved, which results in faster code.
4763 (define_peephole2
4764 [(set (match_operand:SI 0 "arith_reg_dest" "")
4765 (sign_extend:SI (match_operand 1 "simple_mem_operand" "")))
4766 (set (match_operand:SI 2 "arith_reg_dest" "")
4767 (zero_extend:SI (match_operand 3 "arith_reg_operand" "")))]
4768 "TARGET_SH2A
4769 && GET_MODE (operands[1]) == GET_MODE (operands[3])
4770 && (GET_MODE (operands[1]) == QImode || GET_MODE (operands[1]) == HImode)
4771 && REGNO (operands[0]) == REGNO (operands[3])
4772 && (REGNO (operands[2]) == REGNO (operands[0])
4773 || peep2_reg_dead_p (2, operands[0]))"
4774 [(set (match_dup 2) (zero_extend:SI (match_dup 4)))]
4775 {
4776 operands[4]
4777 = replace_equiv_address (operands[1],
4778 gen_rtx_PLUS (SImode, XEXP (operands[1], 0),
4779 const0_rtx));
4780 })
4781
4782 ;; -------------------------------------------------------------------------
4783 ;; Sign extension instructions
4784 ;; -------------------------------------------------------------------------
4785
4786 ;; ??? This should be a define expand.
4787 ;; ??? Or perhaps it should be dropped?
4788
4789 ;; convert_move generates good code for SH[1-4].
4790
4791 (define_expand "extend<mode>si2"
4792 [(set (match_operand:SI 0 "arith_reg_dest")
4793 (sign_extend:SI (match_operand:QIHI 1 "general_extend_operand")))])
4794
4795 (define_insn_and_split "*extend<mode>si2_compact_reg"
4796 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4797 (sign_extend:SI (match_operand:QIHI 1 "arith_reg_operand" "r")))]
4798 "TARGET_SH1"
4799 "exts.<bw> %1,%0"
4800 "&& can_create_pseudo_p ()"
4801 [(set (match_dup 0) (match_dup 2))]
4802 {
4803 /* Sometimes combine fails to combine a T bit or negated T bit store to a
4804 reg with a following sign extension. In the split pass after combine,
4805 try to figure the extended reg was set. If it originated from the T
4806 bit we can replace the sign extension with a reg move, which will be
4807 eliminated. */
4808 operands[2] = sh_try_omit_signzero_extend (operands[1], curr_insn);
4809 if (operands[2] == NULL_RTX)
4810 FAIL;
4811 }
4812 [(set_attr "type" "arith")])
4813
4814 ;; FIXME: Fold non-SH2A and SH2A alternatives with "enabled" attribute.
4815 ;; See movqi insns.
4816 (define_insn "*extend<mode>si2_compact_mem_disp"
4817 [(set (match_operand:SI 0 "arith_reg_dest" "=z,r")
4818 (sign_extend:SI
4819 (mem:QIHI
4820 (plus:SI
4821 (match_operand:SI 1 "arith_reg_operand" "%r,r")
4822 (match_operand:SI 2 "const_int_operand" "<disp04>,N")))))]
4823 "TARGET_SH1 && ! TARGET_SH2A
4824 && sh_legitimate_index_p (<MODE>mode, operands[2], false, true)"
4825 "@
4826 mov.<bw> @(%O2,%1),%0
4827 mov.<bw> @%1,%0"
4828 [(set_attr "type" "load")])
4829
4830 (define_insn "*extend<mode>si2_compact_mem_disp"
4831 [(set (match_operand:SI 0 "arith_reg_dest" "=z,r,r")
4832 (sign_extend:SI
4833 (mem:QIHI
4834 (plus:SI
4835 (match_operand:SI 1 "arith_reg_operand" "%r,r,r")
4836 (match_operand:SI 2 "const_int_operand" "<disp04>,N,<disp12>")))))]
4837 "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[2], true, true)"
4838 "@
4839 mov.<bw> @(%O2,%1),%0
4840 mov.<bw> @%1,%0
4841 mov.<bw> @(%O2,%1),%0"
4842 [(set_attr "type" "load")
4843 (set_attr "length" "2,2,4")])
4844
4845 ;; The pre-dec and post-inc mems must be captured by the '<' and '>'
4846 ;; constraints, otherwise wrong code might get generated.
4847 (define_insn "*extend<mode>si2_predec"
4848 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
4849 (sign_extend:SI (match_operand:QIHI 1 "pre_dec_mem" "<")))]
4850 "TARGET_SH2A"
4851 "mov.<bw> %1,%0"
4852 [(set_attr "type" "load")])
4853
4854 ;; The *_snd patterns will take care of other QImode/HImode addressing
4855 ;; modes than displacement addressing. They must be defined _after_ the
4856 ;; displacement addressing patterns. Otherwise the displacement addressing
4857 ;; patterns will not be picked.
4858 (define_insn "*extend<mode>si2_compact_snd"
4859 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4860 (sign_extend:SI
4861 (match_operand:QIHI 1 "movsrc_no_disp_mem_operand" "Snd")))]
4862 "TARGET_SH1"
4863 "mov.<bw> %1,%0"
4864 [(set_attr "type" "load")])
4865
4866 (define_expand "extendqihi2"
4867 [(set (match_operand:HI 0 "arith_reg_dest")
4868 (sign_extend:HI (match_operand:QI 1 "arith_reg_operand")))]
4869 "TARGET_SH1")
4870
4871 (define_insn "*extendqihi2_compact_reg"
4872 [(set (match_operand:HI 0 "arith_reg_dest" "=r")
4873 (sign_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
4874 "TARGET_SH1"
4875 "exts.b %1,%0"
4876 [(set_attr "type" "arith")])
4877
4878 ;; -------------------------------------------------------------------------
4879 ;; Move instructions
4880 ;; -------------------------------------------------------------------------
4881
4882 (define_expand "push"
4883 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4884 (match_operand:SI 0 "register_operand"))])
4885
4886 (define_expand "pop"
4887 [(set (match_operand:SI 0 "register_operand")
4888 (mem:SI (post_inc:SI (reg:SI SP_REG))))])
4889
4890 (define_expand "push_e"
4891 [(parallel [(set (mem:SF (pre_dec:SI (reg:SI SP_REG)))
4892 (match_operand:SF 0 "" ""))
4893 (use (reg:SI FPSCR_MODES_REG))
4894 (clobber (scratch:SI))])])
4895
4896 (define_insn "push_fpul"
4897 [(set (mem:SF (pre_dec:SI (reg:SI SP_REG))) (reg:SF FPUL_REG))]
4898 "TARGET_SH2E"
4899 "sts.l fpul,@-r15"
4900 [(set_attr "type" "fstore")
4901 (set_attr "late_fp_use" "yes")
4902 (set_attr "hit_stack" "yes")])
4903
4904 ;; DFmode pushes for sh4 require a lot of what is defined for movdf_i4,
4905 ;; so use that.
4906 (define_expand "push_4"
4907 [(parallel [(set (mem:DF (pre_dec:SI (reg:SI SP_REG)))
4908 (match_operand:DF 0 "" ""))
4909 (use (reg:SI FPSCR_MODES_REG))
4910 (clobber (scratch:SI))])])
4911
4912 (define_expand "pop_e"
4913 [(parallel [(set (match_operand:SF 0 "" "")
4914 (mem:SF (post_inc:SI (reg:SI SP_REG))))
4915 (use (reg:SI FPSCR_MODES_REG))
4916 (clobber (scratch:SI))])])
4917
4918 (define_insn "pop_fpul"
4919 [(set (reg:SF FPUL_REG) (mem:SF (post_inc:SI (reg:SI SP_REG))))]
4920 "TARGET_SH2E"
4921 "lds.l @r15+,fpul"
4922 [(set_attr "type" "load")
4923 (set_attr "hit_stack" "yes")])
4924
4925 (define_expand "pop_4"
4926 [(parallel [(set (match_operand:DF 0 "" "")
4927 (mem:DF (post_inc:SI (reg:SI SP_REG))))
4928 (use (reg:SI FPSCR_MODES_REG))
4929 (clobber (scratch:SI))])])
4930
4931 (define_expand "push_fpscr"
4932 [(const_int 0)]
4933 "TARGET_SH2E"
4934 {
4935 add_reg_note (
4936 emit_insn (
4937 gen_sts_fpscr (
4938 gen_frame_mem (SImode, gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)))),
4939 REG_INC, stack_pointer_rtx);
4940 DONE;
4941 })
4942
4943 (define_expand "pop_fpscr"
4944 [(const_int 0)]
4945 "TARGET_SH2E"
4946 {
4947 add_reg_note (
4948 emit_insn (
4949 gen_lds_fpscr (
4950 gen_frame_mem (SImode, gen_rtx_POST_INC (Pmode, stack_pointer_rtx)))),
4951 REG_INC, stack_pointer_rtx);
4952 DONE;
4953 })
4954
4955 ;; The clrt and sett patterns can happen as the result of optimization and
4956 ;; insn expansion.
4957 ;; Comparisons might get simplified to a move of zero or 1 into the T reg.
4958 ;; In this case they might not disappear completely, because the T reg is
4959 ;; a fixed hard reg.
4960 ;; When DImode operations that use the T reg as carry/borrow are split into
4961 ;; individual SImode operations, the T reg is usually cleared before the
4962 ;; first SImode insn.
4963 (define_insn "clrt"
4964 [(set (reg:SI T_REG) (const_int 0))]
4965 "TARGET_SH1"
4966 "clrt"
4967 [(set_attr "type" "mt_group")])
4968
4969 (define_insn "sett"
4970 [(set (reg:SI T_REG) (const_int 1))]
4971 "TARGET_SH1"
4972 "sett"
4973 [(set_attr "type" "mt_group")])
4974
4975 ;; Use the combine pass to transform sequences such as
4976 ;; mov r5,r0
4977 ;; add #1,r0
4978 ;; shll2 r0
4979 ;; mov.l @(r0,r4),r0
4980 ;; into
4981 ;; shll2 r5
4982 ;; add r4,r5
4983 ;; mov.l @(4,r5),r0
4984 ;;
4985 ;; See also PR 39423.
4986 ;; Notice that these patterns have a T_REG clobber, because the shift
4987 ;; sequence that will be split out might clobber the T_REG. Ideally, the
4988 ;; clobber would be added conditionally, depending on the result of
4989 ;; sh_ashlsi_clobbers_t_reg_p. When splitting out the shifts we must go
4990 ;; through the ashlsi3 expander in order to get the right shift insn --
4991 ;; a T_REG clobbering or non-clobbering shift sequence or dynamic shift.
4992 ;; FIXME: Combine never tries this kind of patterns for DImode.
4993 (define_insn_and_split "*movsi_index_disp_load"
4994 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4995 (match_operand:SI 1 "mem_index_disp_operand" "m"))
4996 (clobber (reg:SI T_REG))]
4997 "TARGET_SH1"
4998 "#"
4999 "&& can_create_pseudo_p ()"
5000 [(set (match_dup 6) (plus:SI (match_dup 5) (match_dup 3)))
5001 (set (match_dup 0) (match_dup 7))]
5002 {
5003 rtx mem = operands[1];
5004 rtx plus0_rtx = XEXP (mem, 0);
5005 rtx plus1_rtx = XEXP (plus0_rtx, 0);
5006 rtx mult_rtx = XEXP (plus1_rtx, 0);
5007
5008 operands[1] = XEXP (mult_rtx, 0);
5009 operands[2] = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
5010 operands[3] = XEXP (plus1_rtx, 1);
5011 operands[4] = XEXP (plus0_rtx, 1);
5012 operands[5] = gen_reg_rtx (SImode);
5013 operands[6] = gen_reg_rtx (SImode);
5014 operands[7] =
5015 replace_equiv_address (mem,
5016 gen_rtx_PLUS (SImode, operands[6], operands[4]));
5017
5018 emit_insn (gen_ashlsi3 (operands[5], operands[1], operands[2]));
5019 })
5020
5021 (define_insn_and_split "*movhi_index_disp_load"
5022 [(set (match_operand:SI 0 "arith_reg_dest")
5023 (SZ_EXTEND:SI (match_operand:HI 1 "mem_index_disp_operand")))
5024 (clobber (reg:SI T_REG))]
5025 "TARGET_SH1"
5026 "#"
5027 "&& can_create_pseudo_p ()"
5028 [(const_int 0)]
5029 {
5030 rtx mem = operands[1];
5031 rtx plus0_rtx = XEXP (mem, 0);
5032 rtx plus1_rtx = XEXP (plus0_rtx, 0);
5033 rtx mult_rtx = XEXP (plus1_rtx, 0);
5034
5035 rtx op_1 = XEXP (mult_rtx, 0);
5036 rtx op_2 = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
5037 rtx op_3 = XEXP (plus1_rtx, 1);
5038 rtx op_4 = XEXP (plus0_rtx, 1);
5039 rtx op_5 = gen_reg_rtx (SImode);
5040 rtx op_6 = gen_reg_rtx (SImode);
5041 rtx op_7 = replace_equiv_address (mem, gen_rtx_PLUS (SImode, op_6, op_4));
5042
5043 emit_insn (gen_ashlsi3 (op_5, op_1, op_2));
5044 emit_insn (gen_addsi3 (op_6, op_5, op_3));
5045
5046 if (<CODE> == SIGN_EXTEND)
5047 {
5048 emit_insn (gen_extendhisi2 (operands[0], op_7));
5049 DONE;
5050 }
5051 else if (<CODE> == ZERO_EXTEND)
5052 {
5053 /* On SH2A the movu.w insn can be used for zero extending loads. */
5054 if (TARGET_SH2A)
5055 emit_insn (gen_zero_extendhisi2 (operands[0], op_7));
5056 else
5057 {
5058 emit_insn (gen_extendhisi2 (operands[0], op_7));
5059 emit_insn (gen_zero_extendhisi2 (operands[0],
5060 gen_lowpart (HImode, operands[0])));
5061 }
5062 DONE;
5063 }
5064 else
5065 FAIL;
5066 })
5067
5068 (define_insn_and_split "*mov<mode>_index_disp_store"
5069 [(set (match_operand:HISI 0 "mem_index_disp_operand" "=m")
5070 (match_operand:HISI 1 "arith_reg_operand" "r"))
5071 (clobber (reg:SI T_REG))]
5072 "TARGET_SH1"
5073 "#"
5074 "&& can_create_pseudo_p ()"
5075 [(set (match_dup 6) (plus:SI (match_dup 5) (match_dup 3)))
5076 (set (match_dup 7) (match_dup 1))]
5077 {
5078 rtx mem = operands[0];
5079 rtx plus0_rtx = XEXP (mem, 0);
5080 rtx plus1_rtx = XEXP (plus0_rtx, 0);
5081 rtx mult_rtx = XEXP (plus1_rtx, 0);
5082
5083 operands[0] = XEXP (mult_rtx, 0);
5084 operands[2] = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
5085 operands[3] = XEXP (plus1_rtx, 1);
5086 operands[4] = XEXP (plus0_rtx, 1);
5087 operands[5] = gen_reg_rtx (SImode);
5088 operands[6] = gen_reg_rtx (SImode);
5089 operands[7] =
5090 replace_equiv_address (mem,
5091 gen_rtx_PLUS (SImode, operands[6], operands[4]));
5092
5093 emit_insn (gen_ashlsi3 (operands[5], operands[0], operands[2]));
5094 })
5095
5096 ;; t/r must come after r/r, lest reload will try to reload stuff like
5097 ;; (set (subreg:SI (mem:QI (plus:SI (reg:SI SP_REG) (const_int 12)) 0) 0)
5098 ;; (made from (set (subreg:SI (reg:QI ###) 0) ) into T.
5099 ;; Notice that although this pattern allows movi20 and movi20s on non-SH2A,
5100 ;; those alternatives will not be taken, as they will be converted into
5101 ;; PC-relative loads.
5102 (define_insn "movsi_i"
5103 [(set (match_operand:SI 0 "general_movdst_operand"
5104 "=r,r, r, r, r, r,r,r,m,<,<,x,l,x,l,r")
5105 (match_operand:SI 1 "general_movsrc_operand"
5106 " Q,r,I08,I20,I28,mr,x,l,r,x,l,r,r,>,>,i"))]
5107 "TARGET_SH1 && !TARGET_FPU_ANY
5108 && (register_operand (operands[0], SImode)
5109 || register_operand (operands[1], SImode))"
5110 "@
5111 mov.l %1,%0
5112 mov %1,%0
5113 mov %1,%0
5114 movi20 %1,%0
5115 movi20s %1,%0
5116 mov.l %1,%0
5117 sts %1,%0
5118 sts %1,%0
5119 mov.l %1,%0
5120 sts.l %1,%0
5121 sts.l %1,%0
5122 lds %1,%0
5123 lds %1,%0
5124 lds.l %1,%0
5125 lds.l %1,%0
5126 fake %1,%0"
5127 [(set_attr "type" "pcload_si,move,movi8,move,move,load_si,mac_gp,prget,store,
5128 mac_mem,pstore,gp_mac,prset,mem_mac,pload,pcload_si")
5129 (set_attr_alternative "length"
5130 [(const_int 2)
5131 (const_int 2)
5132 (const_int 2)
5133 (const_int 4)
5134 (const_int 4)
5135 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5136 (const_int 4) (const_int 2))
5137 (const_int 2)
5138 (const_int 2)
5139 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5140 (const_int 4) (const_int 2))
5141 (const_int 2)
5142 (const_int 2)
5143 (const_int 2)
5144 (const_int 2)
5145 (const_int 2)
5146 (const_int 2)
5147 (const_int 2)])])
5148
5149 ;; t/r must come after r/r, lest reload will try to reload stuff like
5150 ;; (subreg:SI (reg:SF FR14_REG) 0) into T (compiling stdlib/strtod.c -m3e -O2)
5151 ;; ??? This allows moves from macl to fpul to be recognized, but these moves
5152 ;; will require a reload.
5153 ;; ??? We can't include f/f because we need the proper FPSCR setting when
5154 ;; TARGET_FMOVD is in effect, and mode switching is done before reload.
5155 ;; Notice that although this pattern allows movi20 and movi20s on non-SH2A,
5156 ;; those alternatives will not be taken, as they will be converted into
5157 ;; PC-relative loads.
5158 (define_insn "movsi_ie"
5159 [(set (match_operand:SI 0 "general_movdst_operand"
5160 "=r,r, r, r, r, r,r,r,mr,<,<,x,l,x,l,y,<,r,y,r,*f, y,*f,y")
5161 (match_operand:SI 1 "general_movsrc_operand"
5162 " Q,r,I08,I20,I28,mr,x,l, r,x,l,r,r,>,>,>,y,i,r,y, y,*f,*f,y"))]
5163 "TARGET_SH1 && TARGET_FPU_ANY
5164 && ((register_operand (operands[0], SImode)
5165 && !fpscr_operand (operands[0], SImode))
5166 || (register_operand (operands[1], SImode)
5167 && !fpscr_operand (operands[1], SImode)))"
5168 "@
5169 mov.l %1,%0
5170 mov %1,%0
5171 mov %1,%0
5172 movi20 %1,%0
5173 movi20s %1,%0
5174 mov.l %1,%0
5175 sts %1,%0
5176 sts %1,%0
5177 mov.l %1,%0
5178 sts.l %1,%0
5179 sts.l %1,%0
5180 lds %1,%0
5181 lds %1,%0
5182 lds.l %1,%0
5183 lds.l %1,%0
5184 lds.l %1,%0
5185 sts.l %1,%0
5186 fake %1,%0
5187 lds %1,%0
5188 sts %1,%0
5189 fsts fpul,%0
5190 flds %1,fpul
5191 fmov %1,%0
5192 ! move optimized away"
5193 [(set_attr "type" "pcload_si,move,movi8,move,move,load_si,mac_gp,prget,store,
5194 mac_mem,pstore,gp_mac,prset,mem_mac,pload,load,fstore,
5195 pcload_si,gp_fpul,fpul_gp,fmove,fmove,fmove,nil")
5196 (set_attr "late_fp_use" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,yes,*,*,yes,*,*,*,*")
5197 (set_attr_alternative "length"
5198 [(const_int 2)
5199 (const_int 2)
5200 (const_int 2)
5201 (const_int 4)
5202 (const_int 4)
5203 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5204 (const_int 4) (const_int 2))
5205 (const_int 2)
5206 (const_int 2)
5207 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5208 (const_int 4) (const_int 2))
5209 (const_int 2)
5210 (const_int 2)
5211 (const_int 2)
5212 (const_int 2)
5213 (const_int 2)
5214 (const_int 2)
5215 (const_int 2)
5216 (const_int 2)
5217 (const_int 2)
5218 (const_int 2)
5219 (const_int 2)
5220 (const_int 2)
5221 (const_int 2)
5222 (const_int 2)
5223 (const_int 0)])])
5224
5225 ;; Notice that although this pattern allows movi20 and movi20s on non-SH2A,
5226 ;; those alternatives will not be taken, as they will be converted into
5227 ;; PC-relative loads.
5228 (define_insn "movsi_i_lowpart"
5229 [(set (strict_low_part
5230 (match_operand:SI 0 "general_movdst_operand"
5231 "+r,r, r, r, r, r,r,r,m,r"))
5232 (match_operand:SI 1 "general_movsrc_operand"
5233 " Q,r,I08,I20,I28,mr,x,l,r,i"))]
5234 "TARGET_SH1
5235 && (register_operand (operands[0], SImode)
5236 || register_operand (operands[1], SImode))"
5237 "@
5238 mov.l %1,%0
5239 mov %1,%0
5240 mov %1,%0
5241 movi20 %1,%0
5242 movi20s %1,%0
5243 mov.l %1,%0
5244 sts %1,%0
5245 sts %1,%0
5246 mov.l %1,%0
5247 fake %1,%0"
5248 [(set_attr "type" "pcload,move,movi8,move,move,load,mac_gp,prget,store,
5249 pcload")
5250 (set_attr_alternative "length"
5251 [(const_int 2)
5252 (const_int 2)
5253 (const_int 2)
5254 (const_int 4)
5255 (const_int 4)
5256 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5257 (const_int 4) (const_int 2))
5258 (const_int 2)
5259 (const_int 2)
5260 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5261 (const_int 4) (const_int 2))
5262 (const_int 2)])])
5263
5264 (define_insn_and_split "load_ra"
5265 [(set (match_operand:SI 0 "general_movdst_operand" "")
5266 (unspec:SI [(match_operand:SI 1 "register_operand" "")] UNSPEC_RA))]
5267 "TARGET_SH1"
5268 "#"
5269 "&& ! currently_expanding_to_rtl"
5270 [(set (match_dup 0) (match_dup 1))])
5271
5272 (define_expand "movsi"
5273 [(set (match_operand:SI 0 "general_movdst_operand" "")
5274 (match_operand:SI 1 "general_movsrc_operand" ""))]
5275 ""
5276 {
5277 prepare_move_operands (operands, SImode);
5278 })
5279
5280 (define_expand "ic_invalidate_line"
5281 [(parallel [(unspec_volatile [(match_operand:SI 0 "register_operand")
5282 (match_dup 1)] UNSPEC_ICACHE)
5283 (clobber (scratch:SI))])]
5284 "TARGET_HARD_SH4"
5285 {
5286 emit_insn (gen_ic_invalidate_line_sh4a (operands[0]));
5287 DONE;
5288 })
5289
5290 ;; The address %0 is assumed to be 4-aligned at least. Thus, by ORing
5291 ;; 0xf0000008, we get the low-oder bits *1*00 (binary), which fits
5292 ;; the requirement *1*00 for associative address writes. The alignment of
5293 ;; %0 implies that its least significant bit is cleared,
5294 ;; thus we clear the V bit of a matching entry if there is one.
5295 (define_insn "ic_invalidate_line_i"
5296 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")
5297 (match_operand:SI 1 "register_operand" "r")]
5298 UNSPEC_ICACHE)
5299 (clobber (match_scratch:SI 2 "=&r"))]
5300 "TARGET_HARD_SH4"
5301 {
5302 return "ocbwb @%0" "\n"
5303 " extu.w %0,%2" "\n"
5304 " or %1,%2" "\n"
5305 " mov.l %0,@%2";
5306 }
5307 [(set_attr "length" "8")
5308 (set_attr "type" "cwb")])
5309
5310 (define_insn "ic_invalidate_line_sh4a"
5311 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
5312 UNSPEC_ICACHE)]
5313 "TARGET_SH4A || TARGET_SH4_300"
5314 {
5315 return "ocbwb @%0" "\n"
5316 " synco" "\n"
5317 " icbi @%0";
5318 }
5319 [(set_attr "length" "6")
5320 (set_attr "type" "cwb")])
5321
5322 (define_expand "mov<mode>"
5323 [(set (match_operand:QIHI 0 "general_movdst_operand")
5324 (match_operand:QIHI 1 "general_movsrc_operand"))]
5325 ""
5326 {
5327 if (can_create_pseudo_p () && CONST_INT_P (operands[1])
5328 && REG_P (operands[0]) && REGNO (operands[0]) != R0_REG)
5329 {
5330 rtx reg = gen_reg_rtx(SImode);
5331 emit_move_insn (reg, operands[1]);
5332 operands[1] = gen_lowpart (<MODE>mode, reg);
5333 }
5334
5335 prepare_move_operands (operands, <MODE>mode);
5336 })
5337
5338 ;; The pre-dec and post-inc mems must be captured by the '<' and '>'
5339 ;; constraints, otherwise wrong code might get generated.
5340 (define_insn "*mov<mode>_load_predec"
5341 [(set (match_operand:QIHISI 0 "arith_reg_dest" "=z")
5342 (match_operand:QIHISI 1 "pre_dec_mem" "<"))]
5343 "TARGET_SH2A"
5344 "mov.<bwl> %1,%0"
5345 [(set_attr "type" "load")])
5346
5347 (define_insn "*mov<mode>_store_postinc"
5348 [(set (match_operand:QIHISI 0 "post_inc_mem" "=>")
5349 (match_operand:QIHISI 1 "arith_reg_operand" "z"))]
5350 "TARGET_SH2A"
5351 "mov.<bwl> %1,%0"
5352 [(set_attr "type" "store")])
5353
5354 ;; Specifying the displacement addressing load / store patterns separately
5355 ;; before the generic movqi / movhi pattern allows controlling the order
5356 ;; in which load / store insns are selected in a more fine grained way.
5357 ;; FIXME: The non-SH2A and SH2A variants should be combined by adding
5358 ;; "enabled" attribute as it is done in other targets.
5359 (define_insn "*mov<mode>_store_mem_disp04"
5360 [(set (mem:QIHI
5361 (plus:SI (match_operand:SI 0 "arith_reg_operand" "%r,r")
5362 (match_operand:SI 1 "const_int_operand" "<disp04>,N")))
5363 (match_operand:QIHI 2 "arith_reg_operand" "z,r"))]
5364 "TARGET_SH1 && sh_legitimate_index_p (<MODE>mode, operands[1], false, true)"
5365 "@
5366 mov.<bw> %2,@(%O1,%0)
5367 mov.<bw> %2,@%0"
5368 [(set_attr "type" "store")])
5369
5370 (define_insn "*mov<mode>_store_mem_disp12"
5371 [(set (mem:QIHI
5372 (plus:SI (match_operand:SI 0 "arith_reg_operand" "%r")
5373 (match_operand:SI 1 "const_int_operand" "<disp12>")))
5374 (match_operand:QIHI 2 "arith_reg_operand" "r"))]
5375 "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[1], true, true)"
5376 "mov.<bw> %2,@(%O1,%0)"
5377 [(set_attr "type" "store")
5378 (set_attr "length" "4")])
5379
5380 (define_insn "*mov<mode>_load_mem_disp04"
5381 [(set (match_operand:QIHI 0 "arith_reg_dest" "=z,r")
5382 (mem:QIHI
5383 (plus:SI (match_operand:SI 1 "arith_reg_operand" "%r,r")
5384 (match_operand:SI 2 "const_int_operand" "<disp04>,N"))))]
5385 "TARGET_SH1 && ! TARGET_SH2A
5386 && sh_legitimate_index_p (<MODE>mode, operands[2], false, true)"
5387 "@
5388 mov.<bw> @(%O2,%1),%0
5389 mov.<bw> @%1,%0"
5390 [(set_attr "type" "load")])
5391
5392 (define_insn "*mov<mode>_load_mem_disp12"
5393 [(set (match_operand:QIHI 0 "arith_reg_dest" "=z,r,r")
5394 (mem:QIHI
5395 (plus:SI
5396 (match_operand:SI 1 "arith_reg_operand" "%r,r,r")
5397 (match_operand:SI 2 "const_int_operand" "<disp04>,N,<disp12>"))))]
5398 "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[2], true, true)"
5399 "@
5400 mov.<bw> @(%O2,%1),%0
5401 mov.<bw> @%1,%0
5402 mov.<bw> @(%O2,%1),%0"
5403 [(set_attr "type" "load")
5404 (set_attr "length" "2,2,4")])
5405
5406 ;; The order of the constraint alternatives is important here.
5407 ;; Q/r has to come first, otherwise PC relative loads might wrongly get
5408 ;; placed into delay slots. Since there is no QImode PC relative load, the
5409 ;; Q constraint and general_movsrc_operand will reject it for QImode.
5410 ;; The Sid/Ssd alternatives should come before Sdd in order to avoid
5411 ;; a preference of using r0 als the register operand for addressing modes
5412 ;; other than displacement addressing.
5413 ;; The Sdd alternatives allow only r0 as register operand, even though on
5414 ;; SH2A any register could be allowed by switching to a 32 bit insn.
5415 ;; Generally sticking to the r0 is preferrable, since it generates smaller
5416 ;; code. Obvious r0 reloads can then be eliminated with a peephole on SH2A.
5417 (define_insn "*mov<mode>"
5418 [(set (match_operand:QIHI 0 "general_movdst_operand"
5419 "=r,r,r,Sid,^zr,Ssd,r, Sdd,z, r,l")
5420 (match_operand:QIHI 1 "general_movsrc_operand"
5421 "Q,r,i,^zr,Sid,r, Ssd,z, Sdd,l,r"))]
5422 "TARGET_SH1
5423 && (arith_reg_operand (operands[0], <MODE>mode)
5424 || arith_reg_operand (operands[1], <MODE>mode))"
5425 "@
5426 mov.<bw> %1,%0
5427 mov %1,%0
5428 mov %1,%0
5429 mov.<bw> %1,%0
5430 mov.<bw> %1,%0
5431 mov.<bw> %1,%0
5432 mov.<bw> %1,%0
5433 mov.<bw> %1,%0
5434 mov.<bw> %1,%0
5435 sts %1,%0
5436 lds %1,%0"
5437 [(set_attr "type" "pcload,move,movi8,store,load,store,load,store,load,prget,prset")
5438 (set (attr "length")
5439 (cond [(match_operand 0 "long_displacement_mem_operand") (const_int 4)
5440 (match_operand 1 "long_displacement_mem_operand") (const_int 4)]
5441 (const_int 2)))])
5442
5443 ;; x/r can be created by inlining/cse, e.g. for execute/961213-1.c
5444 ;; compiled with -m2 -ml -O3 -funroll-loops
5445 (define_insn "*movdi_i"
5446 [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,m, r,r,r,*!x")
5447 (match_operand:DI 1 "general_movsrc_operand" " Q,r,m,r,I08,i,x, r"))]
5448 "TARGET_SH1
5449 && (arith_reg_operand (operands[0], DImode)
5450 || arith_reg_operand (operands[1], DImode))"
5451 {
5452 return output_movedouble (insn, operands, DImode);
5453 }
5454 [(set_attr "type" "pcload,move,load,store,move,pcload,move,move")
5455 (set (attr "length")
5456 (cond [(match_operand 0 "long_displacement_mem_operand") (const_int 8)
5457 (match_operand 1 "long_displacement_mem_operand") (const_int 8)]
5458 (const_int 4)))])
5459
5460 ;; If the output is a register and the input is memory or a register, we have
5461 ;; to be careful and see which word needs to be loaded first.
5462 (define_split
5463 [(set (match_operand:DI 0 "general_movdst_operand" "")
5464 (match_operand:DI 1 "general_movsrc_operand" ""))]
5465 "TARGET_SH1 && reload_completed"
5466 [(set (match_dup 2) (match_dup 3))
5467 (set (match_dup 4) (match_dup 5))]
5468 {
5469 int regno;
5470
5471 if ((MEM_P (operands[0])
5472 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
5473 || (MEM_P (operands[1])
5474 && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
5475 FAIL;
5476
5477 switch (GET_CODE (operands[0]))
5478 {
5479 case REG:
5480 regno = REGNO (operands[0]);
5481 break;
5482 case SUBREG:
5483 regno = subreg_regno (operands[0]);
5484 break;
5485 case MEM:
5486 regno = -1;
5487 break;
5488 default:
5489 gcc_unreachable ();
5490 }
5491
5492 if (regno == -1 || ! refers_to_regno_p (regno, operands[1]))
5493 {
5494 operands[2] = operand_subword (operands[0], 0, 0, DImode);
5495 operands[3] = operand_subword (operands[1], 0, 0, DImode);
5496 operands[4] = operand_subword (operands[0], 1, 0, DImode);
5497 operands[5] = operand_subword (operands[1], 1, 0, DImode);
5498 }
5499 else
5500 {
5501 operands[2] = operand_subword (operands[0], 1, 0, DImode);
5502 operands[3] = operand_subword (operands[1], 1, 0, DImode);
5503 operands[4] = operand_subword (operands[0], 0, 0, DImode);
5504 operands[5] = operand_subword (operands[1], 0, 0, DImode);
5505 }
5506
5507 if (operands[2] == 0 || operands[3] == 0
5508 || operands[4] == 0 || operands[5] == 0)
5509 FAIL;
5510 })
5511
5512 (define_expand "movdi"
5513 [(set (match_operand:DI 0 "general_movdst_operand" "")
5514 (match_operand:DI 1 "general_movsrc_operand" ""))]
5515 ""
5516 {
5517 prepare_move_operands (operands, DImode);
5518
5519 /* When the dest operand is (R0, R1) register pair, split it to
5520 two movsi of which dest is R1 and R0 so as to lower R0-register
5521 pressure on the first movsi. Apply only for simple source not
5522 to make complex rtl here. */
5523 if (REG_P (operands[0]) && REGNO (operands[0]) == R0_REG
5524 && REG_P (operands[1]) && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
5525 {
5526 emit_insn (gen_movsi (gen_rtx_REG (SImode, R1_REG),
5527 gen_rtx_SUBREG (SImode, operands[1], 4)));
5528 emit_insn (gen_movsi (gen_rtx_REG (SImode, R0_REG),
5529 gen_rtx_SUBREG (SImode, operands[1], 0)));
5530 DONE;
5531 }
5532 })
5533
5534 ;; FIXME: This should be a define_insn_and_split.
5535 (define_insn "movdf_k"
5536 [(set (match_operand:DF 0 "general_movdst_operand" "=r, r,r,m")
5537 (match_operand:DF 1 "general_movsrc_operand" " r,FQ,m,r"))]
5538 "TARGET_SH1
5539 && (!TARGET_FPU_DOUBLE || reload_completed
5540 /* ??? We provide some insn so that direct_{load,store}[DFmode] get set */
5541 || (REG_P (operands[0]) && REGNO (operands[0]) == 3)
5542 || (REG_P (operands[1]) && REGNO (operands[1]) == 3))
5543 && (arith_reg_operand (operands[0], DFmode)
5544 || arith_reg_operand (operands[1], DFmode))"
5545 {
5546 return output_movedouble (insn, operands, DFmode);
5547 }
5548 [(set_attr "type" "move,pcload,load,store")
5549 (set (attr "length")
5550 (cond [(match_operand 0 "long_displacement_mem_operand") (const_int 8)
5551 (match_operand 1 "long_displacement_mem_operand") (const_int 8)]
5552 (const_int 4)))])
5553
5554 ;; All alternatives of movdf_i4 are split for ! TARGET_FMOVD.
5555 ;; However, the d/F/c/z alternative cannot be split directly; it is converted
5556 ;; with special code in machine_dependent_reorg into a load of the R0_REG and
5557 ;; the d/m/c/X alternative, which is split later into single-precision
5558 ;; instructions. And when not optimizing, no splits are done before fixing
5559 ;; up pcloads, so we need usable length information for that.
5560 ;; A DF constant load results in the following worst-case 8 byte sequence:
5561 ;; mova ...,r0
5562 ;; fmov.s @r0+,..
5563 ;; fmov.s @r0,...
5564 ;; add #-4,r0
5565 (define_insn "movdf_i4"
5566 [(set (match_operand:DF 0 "general_movdst_operand"
5567 "=d,r, d,d,m, r,r,m,!??r,!???d")
5568 (match_operand:DF 1 "general_movsrc_operand"
5569 " d,r, F,m,d,FQ,m,r, d, r"))
5570 (use (reg:SI FPSCR_MODES_REG))
5571 (clobber (match_scratch:SI 2
5572 "=X,X,&z,X,X, X,X,X, X, X"))]
5573 "TARGET_FPU_DOUBLE
5574 && (arith_reg_operand (operands[0], DFmode)
5575 || arith_reg_operand (operands[1], DFmode))"
5576 {
5577 switch (which_alternative)
5578 {
5579 case 0:
5580 if (TARGET_FMOVD)
5581 return "fmov %1,%0";
5582 else if (REGNO (operands[0]) != REGNO (operands[1]) + 1)
5583 return "fmov %R1,%R0" "\n"
5584 " fmov %S1,%S0";
5585 else
5586 return "fmov %S1,%S0" "\n"
5587 " fmov %R1,%R0";
5588 case 3:
5589 case 4:
5590 return "fmov.d %1,%0";
5591 default:
5592 return "#";
5593 }
5594 }
5595 [(set_attr_alternative "length"
5596 [(if_then_else (eq_attr "fmovd" "yes") (const_int 2) (const_int 4))
5597 (const_int 4)
5598 (if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 8))
5599 (if_then_else (match_operand 1 "displacement_mem_operand")
5600 (if_then_else (eq_attr "fmovd" "yes")
5601 (const_int 4) (const_int 8))
5602 (if_then_else (eq_attr "fmovd" "yes")
5603 (const_int 2) (const_int 4)))
5604 (if_then_else (match_operand 0 "displacement_mem_operand")
5605 (if_then_else (eq_attr "fmovd" "yes")
5606 (const_int 4) (const_int 8))
5607 (if_then_else (eq_attr "fmovd" "yes")
5608 (const_int 2) (const_int 4)))
5609 (const_int 4)
5610 (if_then_else (match_operand 1 "long_displacement_mem_operand")
5611 (const_int 8) (const_int 4))
5612 (if_then_else (match_operand 0 "long_displacement_mem_operand")
5613 (const_int 8) (const_int 4))
5614 (const_int 8)
5615 (const_int 8)])
5616 (set_attr "type" "fmove,move,pcfload,fload,fstore,pcload,load,store,load,
5617 fload")
5618 (set_attr "late_fp_use" "*,*,*,*,yes,*,*,*,*,*")
5619 (set (attr "fp_mode") (if_then_else (eq_attr "fmovd" "yes")
5620 (const_string "double")
5621 (const_string "none")))])
5622
5623 ;; Moving DFmode between fp/general registers through memory
5624 ;; (the top of the stack) is faster than moving through fpul even for
5625 ;; little endian. Because the type of an instruction is important for its
5626 ;; scheduling, it is beneficial to split these operations, rather than
5627 ;; emitting them in one single chunk, even if this will expose a stack
5628 ;; use that will prevent scheduling of other stack accesses beyond this
5629 ;; instruction.
5630 (define_split
5631 [(set (match_operand:DF 0 "register_operand")
5632 (match_operand:DF 1 "register_operand"))
5633 (use (reg:SI FPSCR_MODES_REG))
5634 (clobber (match_scratch:SI 2))]
5635 "TARGET_FPU_DOUBLE && reload_completed
5636 && (true_regnum (operands[0]) < 16) != (true_regnum (operands[1]) < 16)"
5637 [(const_int 0)]
5638 {
5639 rtx insn, tos;
5640
5641 tos = gen_tmp_stack_mem (DFmode, gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
5642 insn = emit_insn (gen_movdf_i4 (tos, operands[1]));
5643 add_reg_note (insn, REG_INC, stack_pointer_rtx);
5644 tos = gen_tmp_stack_mem (DFmode, gen_rtx_POST_INC (Pmode, stack_pointer_rtx));
5645 insn = emit_insn (gen_movdf_i4 (operands[0], tos));
5646 add_reg_note (insn, REG_INC, stack_pointer_rtx);
5647 DONE;
5648 })
5649
5650 ;; local-alloc sometimes allocates scratch registers even when not required,
5651 ;; so we must be prepared to handle these.
5652
5653 ;; Remove the use and clobber from a movdf_i4 so that we can use movdf_k.
5654 (define_split
5655 [(set (match_operand:DF 0 "general_movdst_operand" "")
5656 (match_operand:DF 1 "general_movsrc_operand" ""))
5657 (use (reg:SI FPSCR_MODES_REG))
5658 (clobber (match_scratch:SI 2))]
5659 "TARGET_FPU_DOUBLE
5660 && reload_completed
5661 && true_regnum (operands[0]) < 16
5662 && true_regnum (operands[1]) < 16"
5663 [(set (match_dup 0) (match_dup 1))]
5664 {
5665 /* If this was a reg <-> mem operation with base + index reg addressing,
5666 we have to handle this in a special way. */
5667 rtx mem = operands[0];
5668 int store_p = 1;
5669 if (! memory_operand (mem, DFmode))
5670 {
5671 mem = operands[1];
5672 store_p = 0;
5673 }
5674 if (GET_CODE (mem) == SUBREG && SUBREG_BYTE (mem) == 0)
5675 mem = SUBREG_REG (mem);
5676 if (MEM_P (mem))
5677 {
5678 rtx addr = XEXP (mem, 0);
5679 if (GET_CODE (addr) == PLUS
5680 && REG_P (XEXP (addr, 0))
5681 && REG_P (XEXP (addr, 1)))
5682 {
5683 int offset;
5684 rtx reg0 = gen_rtx_REG (Pmode, 0);
5685 rtx regop = operands[store_p], word0 ,word1;
5686
5687 if (GET_CODE (regop) == SUBREG)
5688 alter_subreg (&regop, true);
5689 if (REGNO (XEXP (addr, 0)) == REGNO (XEXP (addr, 1)))
5690 offset = 2;
5691 else
5692 offset = 4;
5693 mem = copy_rtx (mem);
5694 PUT_MODE (mem, SImode);
5695 word0 = gen_rtx_SUBREG (SImode, regop, 0);
5696 alter_subreg (&word0, true);
5697 word1 = gen_rtx_SUBREG (SImode, regop, 4);
5698 alter_subreg (&word1, true);
5699 if (store_p || ! refers_to_regno_p (REGNO (word0), addr))
5700 {
5701 emit_insn (store_p
5702 ? gen_movsi_ie (mem, word0)
5703 : gen_movsi_ie (word0, mem));
5704 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
5705 mem = copy_rtx (mem);
5706 emit_insn (store_p
5707 ? gen_movsi_ie (mem, word1)
5708 : gen_movsi_ie (word1, mem));
5709 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
5710 }
5711 else
5712 {
5713 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
5714 emit_insn (gen_movsi_ie (word1, mem));
5715 emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
5716 mem = copy_rtx (mem);
5717 emit_insn (gen_movsi_ie (word0, mem));
5718 }
5719 DONE;
5720 }
5721 }
5722 })
5723
5724 ;; Split away the clobber of r0 after machine_dependent_reorg has fixed pcloads.
5725 (define_split
5726 [(set (match_operand:DF 0 "register_operand" "")
5727 (match_operand:DF 1 "memory_operand" ""))
5728 (use (reg:SI FPSCR_MODES_REG))
5729 (clobber (reg:SI R0_REG))]
5730 "TARGET_FPU_DOUBLE && reload_completed"
5731 [(parallel [(set (match_dup 0) (match_dup 1))
5732 (use (reg:SI FPSCR_MODES_REG))
5733 (clobber (scratch:SI))])]
5734 "")
5735
5736 (define_expand "reload_indf__frn"
5737 [(parallel [(set (match_operand:DF 0 "register_operand" "=a")
5738 (match_operand:DF 1 "immediate_operand" "FQ"))
5739 (use (reg:SI FPSCR_MODES_REG))
5740 (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
5741 "TARGET_SH1"
5742 "")
5743
5744 (define_expand "reload_outdf__RnFRm"
5745 [(parallel [(set (match_operand:DF 0 "register_operand" "=r,f")
5746 (match_operand:DF 1 "register_operand" "af,r"))
5747 (clobber (match_operand:SI 2 "register_operand" "=&y,y"))])]
5748 "TARGET_SH1"
5749 "")
5750
5751 ;; Simplify no-op moves.
5752 (define_split
5753 [(set (match_operand:SF 0 "register_operand" "")
5754 (match_operand:SF 1 "register_operand" ""))
5755 (use (reg:SI FPSCR_MODES_REG))
5756 (clobber (match_scratch:SI 2))]
5757 "TARGET_SH2E && reload_completed
5758 && true_regnum (operands[0]) == true_regnum (operands[1])"
5759 [(set (match_dup 0) (match_dup 0))]
5760 "")
5761
5762 ;; fmovd substitute post-reload splits
5763 (define_split
5764 [(set (match_operand:DF 0 "register_operand" "")
5765 (match_operand:DF 1 "register_operand" ""))
5766 (use (reg:SI FPSCR_MODES_REG))
5767 (clobber (match_scratch:SI 2))]
5768 "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
5769 && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))
5770 && FP_OR_XD_REGISTER_P (true_regnum (operands[1]))"
5771 [(const_int 0)]
5772 {
5773 int dst = true_regnum (operands[0]), src = true_regnum (operands[1]);
5774 emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode, dst),
5775 gen_rtx_REG (SFmode, src)));
5776 emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode, dst + 1),
5777 gen_rtx_REG (SFmode, src + 1)));
5778 DONE;
5779 })
5780
5781 (define_split
5782 [(set (match_operand:DF 0 "register_operand" "")
5783 (mem:DF (match_operand:SI 1 "register_operand" "")))
5784 (use (reg:SI FPSCR_MODES_REG))
5785 (clobber (match_scratch:SI 2))]
5786 "TARGET_FPU_DOUBLE && ! TARGET_FMOVD && reload_completed
5787 && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))
5788 && find_regno_note (insn, REG_DEAD, true_regnum (operands[1]))"
5789 [(const_int 0)]
5790 {
5791 int regno = true_regnum (operands[0]);
5792 rtx insn;
5793 rtx mem = SET_SRC (XVECEXP (PATTERN (curr_insn), 0, 0));
5794 rtx mem2
5795 = change_address (mem, SFmode, gen_rtx_POST_INC (Pmode, operands[1]));
5796 insn = emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode,
5797 regno + SH_REG_MSW_OFFSET),
5798 mem2));
5799 add_reg_note (insn, REG_INC, operands[1]);
5800 insn = emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode,
5801 regno + SH_REG_LSW_OFFSET),
5802 change_address (mem, SFmode, NULL_RTX)));
5803 DONE;
5804 })
5805
5806 (define_split
5807 [(set (match_operand:DF 0 "register_operand" "")
5808 (match_operand:DF 1 "memory_operand" ""))
5809 (use (reg:SI FPSCR_MODES_REG))
5810 (clobber (match_scratch:SI 2))]
5811 "TARGET_FPU_DOUBLE && ! TARGET_FMOVD && reload_completed
5812 && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))"
5813 [(const_int 0)]
5814 {
5815 int regno = true_regnum (operands[0]);
5816 rtx addr, insn;
5817 rtx mem2 = change_address (operands[1], SFmode, NULL_RTX);
5818 rtx reg0 = gen_rtx_REG (SFmode, regno + SH_REG_MSW_OFFSET);
5819 rtx reg1 = gen_rtx_REG (SFmode, regno + SH_REG_LSW_OFFSET);
5820
5821 operands[1] = copy_rtx (mem2);
5822 addr = XEXP (mem2, 0);
5823
5824 switch (GET_CODE (addr))
5825 {
5826 case REG:
5827 /* This is complicated. If the register is an arithmetic register
5828 we can just fall through to the REG+DISP case below. Otherwise
5829 we have to use a combination of POST_INC and REG addressing... */
5830 if (! arith_reg_operand (operands[1], SFmode))
5831 {
5832 XEXP (mem2, 0) = addr = gen_rtx_POST_INC (SImode, addr);
5833 insn = emit_insn (gen_movsf_ie (reg0, mem2));
5834 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5835
5836 emit_insn (gen_movsf_ie (reg1, operands[1]));
5837
5838 /* If we have modified the stack pointer, the value that we have
5839 read with post-increment might be modified by an interrupt,
5840 so write it back. */
5841 if (REGNO (XEXP (addr, 0)) == STACK_POINTER_REGNUM)
5842 emit_insn (gen_push_e (reg0));
5843 else
5844 emit_insn (gen_addsi3 (XEXP (operands[1], 0), XEXP (operands[1], 0),
5845 GEN_INT (-4)));
5846 break;
5847 }
5848 /* Fall through. */
5849
5850 case PLUS:
5851 emit_insn (gen_movsf_ie (reg0, operands[1]));
5852 operands[1] = copy_rtx (operands[1]);
5853 XEXP (operands[1], 0) = plus_constant (Pmode, addr, 4);
5854 emit_insn (gen_movsf_ie (reg1, operands[1]));
5855 break;
5856
5857 case POST_INC:
5858 insn = emit_insn (gen_movsf_ie (reg0, operands[1]));
5859 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5860
5861 insn = emit_insn (gen_movsf_ie (reg1, operands[1]));
5862 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5863 break;
5864
5865 default:
5866 debug_rtx (addr);
5867 gcc_unreachable ();
5868 }
5869
5870 DONE;
5871 })
5872
5873 (define_split
5874 [(set (match_operand:DF 0 "memory_operand" "")
5875 (match_operand:DF 1 "register_operand" ""))
5876 (use (reg:SI FPSCR_MODES_REG))
5877 (clobber (match_scratch:SI 2))]
5878 "TARGET_FPU_DOUBLE && ! TARGET_FMOVD && reload_completed
5879 && FP_OR_XD_REGISTER_P (true_regnum (operands[1]))"
5880 [(const_int 0)]
5881 {
5882 int regno = true_regnum (operands[1]);
5883 rtx insn, addr;
5884 rtx reg0 = gen_rtx_REG (SFmode, regno + SH_REG_MSW_OFFSET);
5885 rtx reg1 = gen_rtx_REG (SFmode, regno + SH_REG_LSW_OFFSET);
5886
5887 operands[0] = copy_rtx (operands[0]);
5888 PUT_MODE (operands[0], SFmode);
5889 addr = XEXP (operands[0], 0);
5890
5891 switch (GET_CODE (addr))
5892 {
5893 case REG:
5894 /* This is complicated. If the register is an arithmetic register
5895 we can just fall through to the REG+DISP case below. Otherwise
5896 we have to use a combination of REG and PRE_DEC addressing... */
5897 if (! arith_reg_operand (operands[0], SFmode))
5898 {
5899 emit_insn (gen_addsi3 (addr, addr, GEN_INT (4)));
5900 emit_insn (gen_movsf_ie (operands[0], reg1));
5901
5902 operands[0] = copy_rtx (operands[0]);
5903 XEXP (operands[0], 0) = addr = gen_rtx_PRE_DEC (SImode, addr);
5904
5905 insn = emit_insn (gen_movsf_ie (operands[0], reg0));
5906 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5907 break;
5908 }
5909 /* Fall through. */
5910
5911 case PLUS:
5912 /* Since REG+DISP addressing has already been decided upon by gcc
5913 we can rely upon it having chosen an arithmetic register as the
5914 register component of the address. Just emit the lower numbered
5915 register first, to the lower address, then the higher numbered
5916 register to the higher address. */
5917 emit_insn (gen_movsf_ie (operands[0], reg0));
5918
5919 operands[0] = copy_rtx (operands[0]);
5920 XEXP (operands[0], 0) = plus_constant (Pmode, addr, 4);
5921
5922 emit_insn (gen_movsf_ie (operands[0], reg1));
5923 break;
5924
5925 case PRE_DEC:
5926 /* This is easy. Output the word to go to the higher address
5927 first (ie the word in the higher numbered register) then the
5928 word to go to the lower address. */
5929
5930 insn = emit_insn (gen_movsf_ie (operands[0], reg1));
5931 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5932
5933 insn = emit_insn (gen_movsf_ie (operands[0], reg0));
5934 add_reg_note (insn, REG_INC, XEXP (addr, 0));
5935 break;
5936
5937 default:
5938 /* FAIL; */
5939 debug_rtx (addr);
5940 gcc_unreachable ();
5941 }
5942
5943 DONE;
5944 })
5945
5946 ;; If the output is a register and the input is memory or a register, we have
5947 ;; to be careful and see which word needs to be loaded first.
5948 (define_split
5949 [(set (match_operand:DF 0 "general_movdst_operand" "")
5950 (match_operand:DF 1 "general_movsrc_operand" ""))]
5951 "TARGET_SH1 && reload_completed"
5952 [(set (match_dup 2) (match_dup 3))
5953 (set (match_dup 4) (match_dup 5))]
5954 {
5955 int regno;
5956
5957 if ((MEM_P (operands[0])
5958 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
5959 || (MEM_P (operands[1])
5960 && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
5961 FAIL;
5962
5963 switch (GET_CODE (operands[0]))
5964 {
5965 case REG:
5966 regno = REGNO (operands[0]);
5967 break;
5968 case SUBREG:
5969 regno = subreg_regno (operands[0]);
5970 break;
5971 case MEM:
5972 regno = -1;
5973 break;
5974 default:
5975 gcc_unreachable ();
5976 }
5977
5978 if (regno == -1 || ! refers_to_regno_p (regno, operands[1]))
5979 {
5980 operands[2] = operand_subword (operands[0], 0, 0, DFmode);
5981 operands[3] = operand_subword (operands[1], 0, 0, DFmode);
5982 operands[4] = operand_subword (operands[0], 1, 0, DFmode);
5983 operands[5] = operand_subword (operands[1], 1, 0, DFmode);
5984 }
5985 else
5986 {
5987 operands[2] = operand_subword (operands[0], 1, 0, DFmode);
5988 operands[3] = operand_subword (operands[1], 1, 0, DFmode);
5989 operands[4] = operand_subword (operands[0], 0, 0, DFmode);
5990 operands[5] = operand_subword (operands[1], 0, 0, DFmode);
5991 }
5992
5993 if (operands[2] == 0 || operands[3] == 0
5994 || operands[4] == 0 || operands[5] == 0)
5995 FAIL;
5996 })
5997
5998 (define_expand "movdf"
5999 [(set (match_operand:DF 0 "general_movdst_operand" "")
6000 (match_operand:DF 1 "general_movsrc_operand" ""))]
6001 ""
6002 {
6003 prepare_move_operands (operands, DFmode);
6004 if (TARGET_FPU_DOUBLE)
6005 {
6006 emit_insn (gen_movdf_i4 (operands[0], operands[1]));
6007 DONE;
6008 }
6009 })
6010
6011 ;; FIXME Although the movsf_i pattern is not used when there's an FPU,
6012 ;; it somehow influences some RA choices also on FPU targets.
6013 ;; For non-FPU targets it's actually not needed.
6014 (define_insn "movsf_i"
6015 [(set (match_operand:SF 0 "general_movdst_operand" "=r,r, r, r,m,l,r")
6016 (match_operand:SF 1 "general_movsrc_operand" "r,G,FQ,mr,r,r,l"))]
6017 "TARGET_SH1
6018 && (! TARGET_SH2E
6019 /* ??? We provide some insn so that direct_{load,store}[SFmode] get set */
6020 || (REG_P (operands[0]) && REGNO (operands[0]) == 3)
6021 || (REG_P (operands[1]) && REGNO (operands[1]) == 3))
6022 && (arith_reg_operand (operands[0], SFmode)
6023 || arith_reg_operand (operands[1], SFmode))"
6024 "@
6025 mov %1,%0
6026 mov #0,%0
6027 mov.l %1,%0
6028 mov.l %1,%0
6029 mov.l %1,%0
6030 lds %1,%0
6031 sts %1,%0"
6032 [(set_attr "type" "move,move,pcload,load,store,move,move")
6033 (set_attr_alternative "length"
6034 [(const_int 2)
6035 (const_int 2)
6036 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6037 (const_int 4) (const_int 2))
6038 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6039 (const_int 4) (const_int 2))
6040 (if_then_else (match_operand 0 "long_displacement_mem_operand")
6041 (const_int 4) (const_int 2))
6042 (const_int 2)
6043 (const_int 2)])])
6044
6045 ;; We may not split the ry/yr/XX alternatives to movsi_ie, since
6046 ;; update_flow_info would not know where to put REG_EQUAL notes
6047 ;; when the destination changes mode.
6048 (define_insn "movsf_ie"
6049 [(set (match_operand:SF 0 "general_movdst_operand"
6050 "=f,r,f,f,fy, f,m, r, r,m,f,y,y,rf,r,y,<,y,y")
6051 (match_operand:SF 1 "general_movsrc_operand"
6052 " f,r,G,H,FQ,mf,f,FQ,mr,r,y,f,>,fr,y,r,y,>,y"))
6053 (use (reg:SI FPSCR_MODES_REG))
6054 (clobber (match_scratch:SI 2 "=X,X,X,X,&z, X,X, X, X,X,X,X,X, y,X,X,X,X,X"))]
6055 "TARGET_SH2E
6056 && (arith_reg_operand (operands[0], SFmode)
6057 || fpul_operand (operands[0], SFmode)
6058 || arith_reg_operand (operands[1], SFmode)
6059 || fpul_operand (operands[1], SFmode)
6060 || arith_reg_operand (operands[2], SImode))"
6061 "@
6062 fmov %1,%0
6063 mov %1,%0
6064 fldi0 %0
6065 fldi1 %0
6066 #
6067 fmov.s %1,%0
6068 fmov.s %1,%0
6069 mov.l %1,%0
6070 mov.l %1,%0
6071 mov.l %1,%0
6072 fsts fpul,%0
6073 flds %1,fpul
6074 lds.l %1,%0
6075 #
6076 sts %1,%0
6077 lds %1,%0
6078 sts.l %1,%0
6079 lds.l %1,%0
6080 ! move optimized away"
6081 [(set_attr "type" "fmove,move,fmove,fmove,pcfload,fload,fstore,pcload,load,
6082 store,fmove,fmove,load,*,fpul_gp,gp_fpul,fstore,load,nil")
6083 (set_attr "late_fp_use" "*,*,*,*,*,*,yes,*,*,*,*,*,*,*,yes,*,yes,*,*")
6084 (set_attr_alternative "length"
6085 [(const_int 2)
6086 (const_int 2)
6087 (const_int 2)
6088 (const_int 2)
6089 (const_int 4)
6090 (if_then_else (match_operand 1 "displacement_mem_operand")
6091 (const_int 4) (const_int 2))
6092 (if_then_else (match_operand 0 "displacement_mem_operand")
6093 (const_int 4) (const_int 2))
6094 (const_int 2)
6095 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6096 (const_int 4) (const_int 2))
6097 (if_then_else (match_operand 0 "long_displacement_mem_operand")
6098 (const_int 4) (const_int 2))
6099 (const_int 2)
6100 (const_int 2)
6101 (const_int 2)
6102 (const_int 4)
6103 (const_int 2)
6104 (const_int 2)
6105 (const_int 2)
6106 (const_int 2)
6107 (const_int 0)])
6108 (set_attr_alternative "fp_mode"
6109 [(if_then_else (eq_attr "fmovd" "yes")
6110 (const_string "single") (const_string "none"))
6111 (const_string "none")
6112 (const_string "single")
6113 (const_string "single")
6114 (const_string "none")
6115 (if_then_else (eq_attr "fmovd" "yes")
6116 (const_string "single") (const_string "none"))
6117 (if_then_else (eq_attr "fmovd" "yes")
6118 (const_string "single") (const_string "none"))
6119 (const_string "none")
6120 (const_string "none")
6121 (const_string "none")
6122 (const_string "none")
6123 (const_string "none")
6124 (const_string "none")
6125 (const_string "none")
6126 (const_string "none")
6127 (const_string "none")
6128 (const_string "none")
6129 (const_string "none")
6130 (const_string "none")])])
6131
6132 (define_insn_and_split "movsf_ie_ra"
6133 [(set (match_operand:SF 0 "general_movdst_operand"
6134 "=f,r,f,f,fy,f,m, r,r,m,f,y,y,rf,r,y,<,y,y")
6135 (match_operand:SF 1 "general_movsrc_operand"
6136 " f,r,G,H,FQ,m,f,FQ,m,r,y,f,>,fr,y,r,y,>,y"))
6137 (use (reg:SI FPSCR_MODES_REG))
6138 (clobber (match_scratch:SF 2 "=r,r,X,X,&z,r,r, X,r,r,r,r,r, y,r,r,r,r,r"))
6139 (const_int 0)]
6140 "TARGET_SH2E
6141 && (arith_reg_operand (operands[0], SFmode)
6142 || fpul_operand (operands[0], SFmode)
6143 || arith_reg_operand (operands[1], SFmode)
6144 || fpul_operand (operands[1], SFmode))"
6145 "@
6146 fmov %1,%0
6147 mov %1,%0
6148 fldi0 %0
6149 fldi1 %0
6150 #
6151 fmov.s %1,%0
6152 fmov.s %1,%0
6153 mov.l %1,%0
6154 mov.l %1,%0
6155 mov.l %1,%0
6156 fsts fpul,%0
6157 flds %1,fpul
6158 lds.l %1,%0
6159 #
6160 sts %1,%0
6161 lds %1,%0
6162 sts.l %1,%0
6163 lds.l %1,%0
6164 ! move optimized away"
6165 "reload_completed
6166 && sh_movsf_ie_ra_split_p (operands[0], operands[1], operands[2])"
6167 [(const_int 0)]
6168 {
6169 if (! rtx_equal_p (operands[0], operands[1]))
6170 {
6171 emit_insn (gen_movsf_ie (operands[2], operands[1]));
6172 emit_insn (gen_movsf_ie (operands[0], operands[2]));
6173 }
6174 }
6175 [(set_attr "type" "fmove,move,fmove,fmove,pcfload,fload,fstore,pcload,load,
6176 store,fmove,fmove,load,*,fpul_gp,gp_fpul,fstore,load,nil")
6177 (set_attr "late_fp_use" "*,*,*,*,*,*,yes,*,*,*,*,*,*,*,yes,*,yes,*,*")
6178 (set_attr_alternative "length"
6179 [(const_int 2)
6180 (const_int 2)
6181 (const_int 2)
6182 (const_int 2)
6183 (const_int 4)
6184 (if_then_else (match_operand 1 "displacement_mem_operand")
6185 (const_int 4) (const_int 2))
6186 (if_then_else (match_operand 0 "displacement_mem_operand")
6187 (const_int 4) (const_int 2))
6188 (const_int 2)
6189 (if_then_else (match_operand 1 "long_displacement_mem_operand")
6190 (const_int 4) (const_int 2))
6191 (if_then_else (match_operand 0 "long_displacement_mem_operand")
6192 (const_int 4) (const_int 2))
6193 (const_int 2)
6194 (const_int 2)
6195 (const_int 2)
6196 (const_int 4)
6197 (const_int 2)
6198 (const_int 2)
6199 (const_int 2)
6200 (const_int 2)
6201 (const_int 0)])
6202 (set_attr_alternative "fp_mode"
6203 [(if_then_else (eq_attr "fmovd" "yes")
6204 (const_string "single") (const_string "none"))
6205 (const_string "none")
6206 (const_string "single")
6207 (const_string "single")
6208 (const_string "none")
6209 (if_then_else (eq_attr "fmovd" "yes")
6210 (const_string "single") (const_string "none"))
6211 (if_then_else (eq_attr "fmovd" "yes")
6212 (const_string "single") (const_string "none"))
6213 (const_string "none")
6214 (const_string "none")
6215 (const_string "none")
6216 (const_string "none")
6217 (const_string "none")
6218 (const_string "none")
6219 (const_string "none")
6220 (const_string "none")
6221 (const_string "none")
6222 (const_string "none")
6223 (const_string "none")
6224 (const_string "none")])])
6225
6226 (define_split
6227 [(set (match_operand:SF 0 "register_operand" "")
6228 (match_operand:SF 1 "register_operand" ""))
6229 (use (reg:SI FPSCR_MODES_REG))
6230 (clobber (reg:SI FPUL_REG))]
6231 "TARGET_SH1"
6232 [(parallel [(set (reg:SF FPUL_REG) (match_dup 1))
6233 (use (reg:SI FPSCR_MODES_REG))
6234 (clobber (scratch:SI))])
6235 (parallel [(set (match_dup 0) (reg:SF FPUL_REG))
6236 (use (reg:SI FPSCR_MODES_REG))
6237 (clobber (scratch:SI))])]
6238 "")
6239
6240 (define_expand "movsf"
6241 [(set (match_operand:SF 0 "general_movdst_operand" "")
6242 (match_operand:SF 1 "general_movsrc_operand" ""))]
6243 ""
6244 {
6245 prepare_move_operands (operands, SFmode);
6246 if (TARGET_SH2E)
6247 {
6248 if (lra_in_progress)
6249 {
6250 if (GET_CODE (operands[0]) == SCRATCH)
6251 DONE;
6252 emit_insn (gen_movsf_ie_ra (operands[0], operands[1]));
6253 DONE;
6254 }
6255
6256 emit_insn (gen_movsf_ie (operands[0], operands[1]));
6257 DONE;
6258 }
6259 })
6260
6261 (define_expand "reload_insf__frn"
6262 [(parallel [(set (match_operand:SF 0 "register_operand" "=a")
6263 (match_operand:SF 1 "immediate_operand" "FQ"))
6264 (use (reg:SI FPSCR_MODES_REG))
6265 (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
6266 "TARGET_SH1"
6267 "")
6268
6269 (define_expand "reload_insi__i_fpul"
6270 [(parallel [(set (match_operand:SI 0 "fpul_operand" "=y")
6271 (match_operand:SI 1 "immediate_operand" "i"))
6272 (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
6273 "TARGET_SH1"
6274 "")
6275
6276 (define_insn "*movsi_y"
6277 [(set (match_operand:SI 0 "register_operand" "=y,y")
6278 (match_operand:SI 1 "immediate_operand" "Qi,I08"))
6279 (clobber (match_scratch:SI 2 "=&z,r"))]
6280 "TARGET_SH2E
6281 && (reload_in_progress || reload_completed)"
6282 "#"
6283 [(set_attr "length" "4")
6284 (set_attr "type" "pcload,move")])
6285
6286 (define_split
6287 [(set (match_operand:SI 0 "register_operand" "")
6288 (match_operand:SI 1 "immediate_operand" ""))
6289 (clobber (match_operand:SI 2 "register_operand" ""))]
6290 "TARGET_SH1"
6291 [(set (match_dup 2) (match_dup 1))
6292 (set (match_dup 0) (match_dup 2))]
6293 "")
6294 \f
6295 ;; ------------------------------------------------------------------------
6296 ;; Define the real conditional branch instructions.
6297 ;; ------------------------------------------------------------------------
6298
6299 (define_expand "branch_true"
6300 [(set (pc) (if_then_else (ne (reg:SI T_REG) (const_int 0))
6301 (label_ref (match_operand 0))
6302 (pc)))]
6303 "TARGET_SH1")
6304
6305 (define_expand "branch_false"
6306 [(set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
6307 (label_ref (match_operand 0))
6308 (pc)))]
6309 "TARGET_SH1")
6310
6311 (define_insn_and_split "*cbranch_t"
6312 [(set (pc) (if_then_else (match_operand 1 "cbranch_treg_value")
6313 (label_ref (match_operand 0))
6314 (pc)))]
6315 "TARGET_SH1"
6316 {
6317 return output_branch (sh_eval_treg_value (operands[1]), insn, operands);
6318 }
6319 "&& 1"
6320 [(const_int 0)]
6321 {
6322 /* Try to canonicalize the branch condition if it is not one of:
6323 (ne (reg:SI T_REG) (const_int 0))
6324 (eq (reg:SI T_REG) (const_int 0))
6325
6326 Instead of splitting out a new insn, we modify the current insn's
6327 operands as needed. This preserves things such as REG_DEAD notes. */
6328
6329 if ((GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)
6330 && REG_P (XEXP (operands[1], 0)) && REGNO (XEXP (operands[1], 0)) == T_REG
6331 && XEXP (operands[1], 1) == const0_rtx)
6332 DONE;
6333
6334 int branch_cond = sh_eval_treg_value (operands[1]);
6335 rtx new_cond_rtx = NULL_RTX;
6336
6337 if (branch_cond == 0)
6338 new_cond_rtx = gen_rtx_EQ (VOIDmode, get_t_reg_rtx (), const0_rtx);
6339 else if (branch_cond == 1)
6340 new_cond_rtx = gen_rtx_NE (VOIDmode, get_t_reg_rtx (), const0_rtx);
6341
6342 if (new_cond_rtx != NULL_RTX)
6343 validate_change (curr_insn, &XEXP (XEXP (PATTERN (curr_insn), 1), 0),
6344 new_cond_rtx, false);
6345 DONE;
6346 }
6347 [(set_attr "type" "cbranch")])
6348
6349 ;; Patterns to prevent reorg from re-combining a condbranch with a branch
6350 ;; which destination is too far away.
6351 ;; The const_int_operand is distinct for each branch target; it avoids
6352 ;; unwanted matches with redundant_insn.
6353 (define_insn "block_branch_redirect"
6354 [(set (pc) (unspec [(match_operand 0 "const_int_operand" "")] UNSPEC_BBR))]
6355 "TARGET_SH1"
6356 ""
6357 [(set_attr "length" "0")])
6358
6359 ;; This one has the additional purpose to record a possible scratch register
6360 ;; for the following branch.
6361 ;; ??? Unfortunately, just setting the scratch register is not good enough,
6362 ;; because the insn then might be deemed dead and deleted. And we can't
6363 ;; make the use in the jump insn explicit because that would disable
6364 ;; delay slot scheduling from the target.
6365 (define_insn "indirect_jump_scratch"
6366 [(set (match_operand:SI 0 "register_operand" "=r")
6367 (unspec:SI [(match_operand 1 "const_int_operand" "")] UNSPEC_BBR))
6368 (set (pc) (unspec [(const_int 0)] UNSPEC_BBR))]
6369 "TARGET_SH1"
6370 ""
6371 [(set_attr "length" "0")])
6372
6373 ;; This one is used to preemt an insn from beyond the bra / braf / jmp
6374 ;; being pulled into the delay slot of a condbranch that has been made to
6375 ;; jump around the unconditional jump because it was out of range.
6376 (define_insn "stuff_delay_slot"
6377 [(set (pc)
6378 (unspec [(match_operand:SI 0 "const_int_operand" "") (pc)
6379 (match_operand:SI 1 "const_int_operand" "")] UNSPEC_BBR))]
6380 "TARGET_SH1"
6381 ""
6382 [(set_attr "length" "0")
6383 (set_attr "cond_delay_slot" "yes")])
6384 \f
6385 ;; Conditional branch insns
6386
6387 ; operand 0 is the loop count pseudo register
6388 ; operand 1 is the label to jump to at the top of the loop
6389 (define_expand "doloop_end"
6390 [(parallel [(set (pc)
6391 (if_then_else (ne:SI (match_operand:SI 0 "" "")
6392 (const_int 1))
6393 (label_ref (match_operand 1 "" ""))
6394 (pc)))
6395 (set (match_dup 0)
6396 (plus:SI (match_dup 0) (const_int -1)))
6397 (clobber (reg:SI T_REG))])]
6398 "TARGET_SH2"
6399 {
6400 if (GET_MODE (operands[0]) != SImode)
6401 FAIL;
6402 emit_jump_insn (gen_doloop_end_split (operands[0], operands[1], operands[0]));
6403 DONE;
6404 })
6405
6406 (define_insn_and_split "doloop_end_split"
6407 [(set (pc)
6408 (if_then_else (ne:SI (match_operand:SI 2 "arith_reg_dest" "0")
6409 (const_int 1))
6410 (label_ref (match_operand 1 "" ""))
6411 (pc)))
6412 (set (match_operand:SI 0 "arith_reg_dest" "=r")
6413 (plus:SI (match_dup 2) (const_int -1)))
6414 (clobber (reg:SI T_REG))]
6415 "TARGET_SH2"
6416 "#"
6417 ""
6418 [(parallel [(set (reg:SI T_REG)
6419 (eq:SI (match_dup 2) (const_int 1)))
6420 (set (match_dup 0) (plus:SI (match_dup 2) (const_int -1)))])
6421 (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
6422 (label_ref (match_dup 1))
6423 (pc)))]
6424 ""
6425 [(set_attr "type" "cbranch")])
6426 \f
6427 ;; ------------------------------------------------------------------------
6428 ;; Jump and linkage insns
6429 ;; ------------------------------------------------------------------------
6430
6431 (define_insn "jump_compact"
6432 [(set (pc)
6433 (label_ref (match_operand 0 "" "")))]
6434 "TARGET_SH1 && !CROSSING_JUMP_P (insn)"
6435 {
6436 /* The length is 16 if the delay slot is unfilled. */
6437 if (get_attr_length(insn) > 4)
6438 return output_far_jump(insn, operands[0]);
6439 else
6440 return "bra %l0%#";
6441 }
6442 [(set_attr "type" "jump")
6443 (set_attr "needs_delay_slot" "yes")])
6444
6445 (define_insn "*jump_compact_crossing"
6446 [(set (pc)
6447 (label_ref (match_operand 0 "" "")))]
6448 "TARGET_SH1
6449 && flag_reorder_blocks_and_partition
6450 && CROSSING_JUMP_P (insn)"
6451 {
6452 /* The length is 16 if the delay slot is unfilled. */
6453 return output_far_jump(insn, operands[0]);
6454 }
6455 [(set_attr "type" "jump")
6456 (set_attr "length" "16")])
6457
6458 (define_expand "jump"
6459 [(set (pc)
6460 (label_ref (match_operand 0 "" "")))]
6461 ""
6462 {
6463 emit_jump_insn (gen_jump_compact (operands[0]));
6464 DONE;
6465 })
6466
6467 (define_insn "calli"
6468 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
6469 (match_operand 1 "" ""))
6470 (use (reg:SI FPSCR_MODES_REG))
6471 (clobber (reg:SI PR_REG))]
6472 "TARGET_SH1 && !TARGET_FDPIC"
6473 {
6474 if (TARGET_SH2A && dbr_sequence_length () == 0)
6475 return "jsr/n @%0";
6476 else
6477 return "jsr @%0%#";
6478 }
6479 [(set_attr "type" "call")
6480 (set (attr "fp_mode")
6481 (if_then_else (eq_attr "fpu_single" "yes")
6482 (const_string "single") (const_string "double")))
6483 (set_attr "needs_delay_slot" "yes")
6484 (set_attr "fp_set" "unknown")])
6485
6486 (define_insn "calli_fdpic"
6487 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
6488 (match_operand 1))
6489 (use (reg:SI FPSCR_MODES_REG))
6490 (use (reg:SI PIC_REG))
6491 (clobber (reg:SI PR_REG))]
6492 "TARGET_FDPIC"
6493 {
6494 if (TARGET_SH2A && dbr_sequence_length () == 0)
6495 return "jsr/n @%0";
6496 else
6497 return "jsr @%0%#";
6498 }
6499 [(set_attr "type" "call")
6500 (set (attr "fp_mode")
6501 (if_then_else (eq_attr "fpu_single" "yes")
6502 (const_string "single") (const_string "double")))
6503 (set_attr "needs_delay_slot" "yes")
6504 (set_attr "fp_set" "unknown")])
6505
6506 ;; This is TBR relative jump instruction for SH2A architecture.
6507 ;; Its use is enabled by assigning an attribute "function_vector"
6508 ;; and the vector number to a function during its declaration.
6509 (define_insn "calli_tbr_rel"
6510 [(call (mem (match_operand:SI 0 "symbol_ref_operand" ""))
6511 (match_operand 1 "" ""))
6512 (use (reg:SI FPSCR_MODES_REG))
6513 (clobber (reg:SI PR_REG))]
6514 "TARGET_SH2A && sh2a_is_function_vector_call (operands[0])"
6515 {
6516 unsigned HOST_WIDE_INT vect_num;
6517 vect_num = sh2a_get_function_vector_number (operands[0]);
6518 operands[2] = GEN_INT (vect_num * 4);
6519
6520 return "jsr/n @@(%O2,tbr)";
6521 }
6522 [(set_attr "type" "call")
6523 (set (attr "fp_mode")
6524 (if_then_else (eq_attr "fpu_single" "yes")
6525 (const_string "single") (const_string "double")))
6526 (set_attr "needs_delay_slot" "no")
6527 (set_attr "fp_set" "unknown")])
6528
6529 ;; This is a pc-rel call, using bsrf, for use with PIC.
6530 (define_insn "calli_pcrel"
6531 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
6532 (match_operand 1 "" ""))
6533 (use (reg:SI FPSCR_MODES_REG))
6534 (use (reg:SI PIC_REG))
6535 (use (match_operand 2 "" ""))
6536 (clobber (reg:SI PR_REG))]
6537 "TARGET_SH2"
6538 {
6539 return "bsrf %0" "\n"
6540 "%O2:%#";
6541 }
6542 [(set_attr "type" "call")
6543 (set (attr "fp_mode")
6544 (if_then_else (eq_attr "fpu_single" "yes")
6545 (const_string "single") (const_string "double")))
6546 (set_attr "needs_delay_slot" "yes")
6547 (set_attr "fp_set" "unknown")])
6548
6549 (define_insn_and_split "call_pcrel"
6550 [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
6551 (match_operand 1 "" ""))
6552 (use (reg:SI FPSCR_MODES_REG))
6553 (use (reg:SI PIC_REG))
6554 (clobber (reg:SI PR_REG))
6555 (clobber (match_scratch:SI 2 "=&r"))]
6556 "TARGET_SH2"
6557 "#"
6558 "reload_completed"
6559 [(const_int 0)]
6560 {
6561 rtx lab = PATTERN (gen_call_site ());
6562
6563 sh_expand_sym_label2reg (operands[2], operands[0], lab, false);
6564 emit_call_insn (gen_calli_pcrel (operands[2], operands[1], copy_rtx (lab)));
6565 DONE;
6566 }
6567 [(set_attr "type" "call")
6568 (set (attr "fp_mode")
6569 (if_then_else (eq_attr "fpu_single" "yes")
6570 (const_string "single") (const_string "double")))
6571 (set_attr "needs_delay_slot" "yes")
6572 (set_attr "fp_set" "unknown")])
6573
6574 (define_insn "call_valuei"
6575 [(set (match_operand 0 "" "=rf")
6576 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
6577 (match_operand 2 "" "")))
6578 (use (reg:SI FPSCR_MODES_REG))
6579 (clobber (reg:SI PR_REG))]
6580 "TARGET_SH1 && !TARGET_FDPIC"
6581 {
6582 if (TARGET_SH2A && dbr_sequence_length () == 0)
6583 return "jsr/n @%1";
6584 else
6585 return "jsr @%1%#";
6586 }
6587 [(set_attr "type" "call")
6588 (set (attr "fp_mode")
6589 (if_then_else (eq_attr "fpu_single" "yes")
6590 (const_string "single") (const_string "double")))
6591 (set_attr "needs_delay_slot" "yes")
6592 (set_attr "fp_set" "unknown")])
6593
6594 (define_insn "call_valuei_fdpic"
6595 [(set (match_operand 0 "" "=rf")
6596 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
6597 (match_operand 2)))
6598 (use (reg:SI FPSCR_REG))
6599 (use (reg:SI PIC_REG))
6600 (clobber (reg:SI PR_REG))]
6601 "TARGET_FDPIC"
6602 {
6603 if (TARGET_SH2A && dbr_sequence_length () == 0)
6604 return "jsr/n @%1";
6605 else
6606 return "jsr @%1%#";
6607 }
6608 [(set_attr "type" "call")
6609 (set (attr "fp_mode")
6610 (if_then_else (eq_attr "fpu_single" "yes")
6611 (const_string "single") (const_string "double")))
6612 (set_attr "needs_delay_slot" "yes")
6613 (set_attr "fp_set" "unknown")])
6614
6615 ;; This is TBR relative jump instruction for SH2A architecture.
6616 ;; Its use is enabled by assigning an attribute "function_vector"
6617 ;; and the vector number to a function during its declaration.
6618 (define_insn "call_valuei_tbr_rel"
6619 [(set (match_operand 0 "" "=rf")
6620 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
6621 (match_operand 2 "" "")))
6622 (use (reg:SI FPSCR_MODES_REG))
6623 (clobber (reg:SI PR_REG))]
6624 "TARGET_SH2A && sh2a_is_function_vector_call (operands[1])"
6625 {
6626 unsigned HOST_WIDE_INT vect_num;
6627 vect_num = sh2a_get_function_vector_number (operands[1]);
6628 operands[3] = GEN_INT (vect_num * 4);
6629
6630 return "jsr/n @@(%O3,tbr)";
6631 }
6632 [(set_attr "type" "call")
6633 (set (attr "fp_mode")
6634 (if_then_else (eq_attr "fpu_single" "yes")
6635 (const_string "single") (const_string "double")))
6636 (set_attr "needs_delay_slot" "no")
6637 (set_attr "fp_set" "unknown")])
6638
6639 (define_insn "call_valuei_pcrel"
6640 [(set (match_operand 0 "" "=rf")
6641 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
6642 (match_operand 2 "" "")))
6643 (use (reg:SI FPSCR_MODES_REG))
6644 (use (reg:SI PIC_REG))
6645 (use (match_operand 3 "" ""))
6646 (clobber (reg:SI PR_REG))]
6647 "TARGET_SH2"
6648 {
6649 return "bsrf %1" "\n"
6650 "%O3:%#";
6651 }
6652 [(set_attr "type" "call")
6653 (set (attr "fp_mode")
6654 (if_then_else (eq_attr "fpu_single" "yes")
6655 (const_string "single") (const_string "double")))
6656 (set_attr "needs_delay_slot" "yes")
6657 (set_attr "fp_set" "unknown")])
6658
6659 (define_insn_and_split "call_value_pcrel"
6660 [(set (match_operand 0 "" "=rf")
6661 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
6662 (match_operand 2 "" "")))
6663 (use (reg:SI FPSCR_MODES_REG))
6664 (use (reg:SI PIC_REG))
6665 (clobber (reg:SI PR_REG))
6666 (clobber (match_scratch:SI 3 "=&r"))]
6667 "TARGET_SH2"
6668 "#"
6669 "reload_completed"
6670 [(const_int 0)]
6671 {
6672 rtx lab = PATTERN (gen_call_site ());
6673
6674 sh_expand_sym_label2reg (operands[3], operands[1], lab, false);
6675 emit_call_insn (gen_call_valuei_pcrel (operands[0], operands[3],
6676 operands[2], copy_rtx (lab)));
6677 DONE;
6678 }
6679 [(set_attr "type" "call")
6680 (set (attr "fp_mode")
6681 (if_then_else (eq_attr "fpu_single" "yes")
6682 (const_string "single") (const_string "double")))
6683 (set_attr "needs_delay_slot" "yes")
6684 (set_attr "fp_set" "unknown")])
6685
6686 (define_expand "call"
6687 [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
6688 (match_operand 1 "" ""))
6689 (match_operand 2 "" "")
6690 (use (reg:SI FPSCR_MODES_REG))
6691 (clobber (reg:SI PR_REG))])]
6692 ""
6693 {
6694 if (TARGET_FDPIC)
6695 {
6696 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
6697 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
6698 }
6699
6700 if (!flag_pic && TARGET_SH2A
6701 && MEM_P (operands[0])
6702 && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
6703 {
6704 if (sh2a_is_function_vector_call (XEXP (operands[0], 0)))
6705 {
6706 emit_call_insn (gen_calli_tbr_rel (XEXP (operands[0], 0),
6707 operands[1]));
6708 DONE;
6709 }
6710 }
6711 if (flag_pic && TARGET_SH2
6712 && MEM_P (operands[0])
6713 && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
6714 {
6715 emit_call_insn (gen_call_pcrel (XEXP (operands[0], 0), operands[1]));
6716 DONE;
6717 }
6718 else
6719 {
6720 operands[0] = force_reg (SImode, XEXP (operands[0], 0));
6721 operands[1] = operands[2];
6722 }
6723
6724 if (TARGET_FDPIC)
6725 {
6726 operands[0] = sh_load_function_descriptor (operands[0]);
6727 emit_call_insn (gen_calli_fdpic (operands[0], operands[1]));
6728 }
6729 else
6730 emit_call_insn (gen_calli (operands[0], operands[1]));
6731 DONE;
6732 })
6733
6734 (define_expand "call_value"
6735 [(parallel [(set (match_operand 0 "arith_reg_operand" "")
6736 (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
6737 (match_operand 2 "" "")))
6738 (match_operand 3 "" "")
6739 (use (reg:SI FPSCR_MODES_REG))
6740 (clobber (reg:SI PR_REG))])]
6741 ""
6742 {
6743 if (TARGET_FDPIC)
6744 {
6745 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
6746 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
6747 }
6748
6749 if (!flag_pic && TARGET_SH2A
6750 && MEM_P (operands[1])
6751 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
6752 {
6753 if (sh2a_is_function_vector_call (XEXP (operands[1], 0)))
6754 {
6755 emit_call_insn (gen_call_valuei_tbr_rel (operands[0],
6756 XEXP (operands[1], 0), operands[2]));
6757 DONE;
6758 }
6759 }
6760 if (flag_pic && TARGET_SH2
6761 && MEM_P (operands[1])
6762 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
6763 {
6764 emit_call_insn (gen_call_value_pcrel (operands[0], XEXP (operands[1], 0),
6765 operands[2]));
6766 DONE;
6767 }
6768 else
6769 operands[1] = force_reg (SImode, XEXP (operands[1], 0));
6770
6771 if (TARGET_FDPIC)
6772 {
6773 operands[1] = sh_load_function_descriptor (operands[1]);
6774 emit_call_insn (gen_call_valuei_fdpic (operands[0], operands[1],
6775 operands[2]));
6776 }
6777 else
6778 emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
6779 DONE;
6780 })
6781
6782 (define_insn "sibcalli"
6783 [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
6784 (match_operand 1 "" ""))
6785 (use (reg:SI FPSCR_MODES_REG))
6786 (return)]
6787 "TARGET_SH1 && !TARGET_FDPIC"
6788 "jmp @%0%#"
6789 [(set_attr "needs_delay_slot" "yes")
6790 (set (attr "fp_mode")
6791 (if_then_else (eq_attr "fpu_single" "yes")
6792 (const_string "single") (const_string "double")))
6793 (set_attr "type" "jump_ind")])
6794
6795 (define_insn "sibcalli_fdpic"
6796 [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
6797 (match_operand 1))
6798 (use (reg:SI FPSCR_MODES_REG))
6799 (use (reg:SI PIC_REG))
6800 (return)]
6801 "TARGET_FDPIC"
6802 "jmp @%0%#"
6803 [(set_attr "needs_delay_slot" "yes")
6804 (set (attr "fp_mode")
6805 (if_then_else (eq_attr "fpu_single" "yes")
6806 (const_string "single") (const_string "double")))
6807 (set_attr "type" "jump_ind")])
6808
6809 (define_insn "sibcalli_pcrel"
6810 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
6811 (match_operand 1 "" ""))
6812 (use (match_operand 2 "" ""))
6813 (use (reg:SI FPSCR_MODES_REG))
6814 (return)]
6815 "TARGET_SH2 && !TARGET_FDPIC"
6816 {
6817 return "braf %0" "\n"
6818 "%O2:%#";
6819 }
6820 [(set_attr "needs_delay_slot" "yes")
6821 (set (attr "fp_mode")
6822 (if_then_else (eq_attr "fpu_single" "yes")
6823 (const_string "single") (const_string "double")))
6824 (set_attr "type" "jump_ind")])
6825
6826 (define_insn "sibcalli_pcrel_fdpic"
6827 [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
6828 (match_operand 1))
6829 (use (match_operand 2))
6830 (use (reg:SI FPSCR_MODES_REG))
6831 (use (reg:SI PIC_REG))
6832 (return)]
6833 "TARGET_SH2 && TARGET_FDPIC"
6834 {
6835 return "braf %0" "\n"
6836 "%O2:%#";
6837 }
6838 [(set_attr "needs_delay_slot" "yes")
6839 (set (attr "fp_mode")
6840 (if_then_else (eq_attr "fpu_single" "yes")
6841 (const_string "single") (const_string "double")))
6842 (set_attr "type" "jump_ind")])
6843
6844 ;; This uses an unspec to describe that the symbol_ref is very close.
6845 (define_insn "sibcalli_thunk"
6846 [(call (mem:SI (unspec:SI [(match_operand:SI 0 "symbol_ref_operand" "")]
6847 UNSPEC_THUNK))
6848 (match_operand 1 "" ""))
6849 (use (reg:SI FPSCR_MODES_REG))
6850 (return)]
6851 "TARGET_SH1"
6852 "bra %O0"
6853 [(set_attr "needs_delay_slot" "yes")
6854 (set (attr "fp_mode")
6855 (if_then_else (eq_attr "fpu_single" "yes")
6856 (const_string "single") (const_string "double")))
6857 (set_attr "type" "jump")
6858 (set_attr "length" "2")])
6859
6860 (define_insn_and_split "sibcall_pcrel"
6861 [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
6862 (match_operand 1 "" ""))
6863 (use (reg:SI FPSCR_MODES_REG))
6864 (clobber (match_scratch:SI 2 "=&k"))
6865 (return)]
6866 "TARGET_SH2 && !TARGET_FDPIC"
6867 "#"
6868 "reload_completed"
6869 [(const_int 0)]
6870 {
6871 rtx lab = PATTERN (gen_call_site ());
6872 rtx call_insn;
6873
6874 sh_expand_sym_label2reg (operands[2], operands[0], lab, true);
6875 call_insn = emit_call_insn (gen_sibcalli_pcrel (operands[2], operands[1],
6876 copy_rtx (lab)));
6877 SIBLING_CALL_P (call_insn) = 1;
6878 DONE;
6879 }
6880 [(set_attr "needs_delay_slot" "yes")
6881 (set (attr "fp_mode")
6882 (if_then_else (eq_attr "fpu_single" "yes")
6883 (const_string "single") (const_string "double")))
6884 (set_attr "type" "jump_ind")])
6885
6886 (define_insn_and_split "sibcall_pcrel_fdpic"
6887 [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand"))
6888 (match_operand 1))
6889 (use (reg:SI FPSCR_MODES_REG))
6890 (use (reg:SI PIC_REG))
6891 (clobber (match_scratch:SI 2 "=k"))
6892 (return)]
6893 "TARGET_SH2 && TARGET_FDPIC"
6894 "#"
6895 "&& reload_completed"
6896 [(const_int 0)]
6897 {
6898 rtx lab = PATTERN (gen_call_site ());
6899
6900 sh_expand_sym_label2reg (operands[2], operands[0], lab, true);
6901 rtx i = emit_call_insn (gen_sibcalli_pcrel_fdpic (operands[2], operands[1],
6902 copy_rtx (lab)));
6903 SIBLING_CALL_P (i) = 1;
6904 DONE;
6905 }
6906 [(set_attr "needs_delay_slot" "yes")
6907 (set (attr "fp_mode")
6908 (if_then_else (eq_attr "fpu_single" "yes")
6909 (const_string "single") (const_string "double")))
6910 (set_attr "type" "jump_ind")])
6911
6912 (define_expand "sibcall"
6913 [(parallel
6914 [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
6915 (match_operand 1 "" ""))
6916 (match_operand 2 "" "")
6917 (use (reg:SI FPSCR_MODES_REG))
6918 (return)])]
6919 ""
6920 {
6921 if (TARGET_FDPIC)
6922 {
6923 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
6924 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
6925 }
6926
6927 if (flag_pic && TARGET_SH2
6928 && MEM_P (operands[0])
6929 && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
6930 /* The PLT needs the PIC register, but the epilogue would have
6931 to restore it, so we can only use PC-relative PIC calls for
6932 static functions. */
6933 && SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
6934 {
6935 if (TARGET_FDPIC)
6936 emit_call_insn (gen_sibcall_pcrel_fdpic (XEXP (operands[0], 0),
6937 operands[1]));
6938 else
6939 emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0), operands[1]));
6940 DONE;
6941 }
6942 else
6943 operands[0] = force_reg (SImode, XEXP (operands[0], 0));
6944
6945 if (TARGET_FDPIC)
6946 {
6947 operands[0] = sh_load_function_descriptor (operands[0]);
6948 emit_call_insn (gen_sibcalli_fdpic (operands[0], operands[1]));
6949 }
6950 else
6951 emit_call_insn (gen_sibcalli (operands[0], operands[1]));
6952 DONE;
6953 })
6954
6955 (define_insn "sibcall_valuei"
6956 [(set (match_operand 0 "" "=rf")
6957 (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
6958 (match_operand 2 "" "")))
6959 (use (reg:SI FPSCR_MODES_REG))
6960 (return)]
6961 "TARGET_SH1 && !TARGET_FDPIC"
6962 "jmp @%1%#"
6963 [(set_attr "needs_delay_slot" "yes")
6964 (set (attr "fp_mode")
6965 (if_then_else (eq_attr "fpu_single" "yes")
6966 (const_string "single") (const_string "double")))
6967 (set_attr "type" "jump_ind")])
6968
6969 (define_insn "sibcall_valuei_fdpic"
6970 [(set (match_operand 0 "" "=rf")
6971 (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
6972 (match_operand 2)))
6973 (use (reg:SI FPSCR_MODES_REG))
6974 (use (reg:SI PIC_REG))
6975 (return)]
6976 "TARGET_FDPIC"
6977 "jmp @%1%#"
6978 [(set_attr "needs_delay_slot" "yes")
6979 (set (attr "fp_mode")
6980 (if_then_else (eq_attr "fpu_single" "yes")
6981 (const_string "single") (const_string "double")))
6982 (set_attr "type" "jump_ind")])
6983
6984 (define_insn "sibcall_valuei_pcrel"
6985 [(set (match_operand 0 "" "=rf")
6986 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
6987 (match_operand 2 "" "")))
6988 (use (match_operand 3 "" ""))
6989 (use (reg:SI FPSCR_MODES_REG))
6990 (return)]
6991 "TARGET_SH2 && !TARGET_FDPIC"
6992 {
6993 return "braf %1" "\n"
6994 "%O3:%#";
6995 }
6996 [(set_attr "needs_delay_slot" "yes")
6997 (set (attr "fp_mode")
6998 (if_then_else (eq_attr "fpu_single" "yes")
6999 (const_string "single") (const_string "double")))
7000 (set_attr "type" "jump_ind")])
7001
7002 (define_insn "sibcall_valuei_pcrel_fdpic"
7003 [(set (match_operand 0 "" "=rf")
7004 (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
7005 (match_operand 2)))
7006 (use (match_operand 3))
7007 (use (reg:SI FPSCR_MODES_REG))
7008 (use (reg:SI PIC_REG))
7009 (return)]
7010 "TARGET_SH2 && TARGET_FDPIC"
7011 {
7012 return "braf %1" "\n"
7013 "%O3:%#";
7014 }
7015 [(set_attr "needs_delay_slot" "yes")
7016 (set (attr "fp_mode")
7017 (if_then_else (eq_attr "fpu_single" "yes")
7018 (const_string "single") (const_string "double")))
7019 (set_attr "type" "jump_ind")])
7020
7021 ;; sibcall_value_pcrel used to have a =&k clobber for the scratch register
7022 ;; that it needs for the branch address. This causes troubles when there
7023 ;; is a big overlap of argument and return value registers. Hence, use a
7024 ;; fixed call clobbered register for the address. See also PR 67260.
7025 (define_insn_and_split "sibcall_value_pcrel"
7026 [(set (match_operand 0 "" "=rf")
7027 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
7028 (match_operand 2 "" "")))
7029 (use (reg:SI FPSCR_MODES_REG))
7030 (clobber (reg:SI R1_REG))
7031 (return)]
7032 "TARGET_SH2 && !TARGET_FDPIC"
7033 "#"
7034 "reload_completed"
7035 [(const_int 0)]
7036 {
7037 rtx lab = PATTERN (gen_call_site ());
7038 rtx call_insn;
7039
7040 operands[3] = gen_rtx_REG (SImode, R1_REG);
7041
7042 sh_expand_sym_label2reg (operands[3], operands[1], lab, true);
7043 call_insn = emit_call_insn (gen_sibcall_valuei_pcrel (operands[0],
7044 operands[3],
7045 operands[2],
7046 copy_rtx (lab)));
7047 SIBLING_CALL_P (call_insn) = 1;
7048 DONE;
7049 }
7050 [(set_attr "needs_delay_slot" "yes")
7051 (set (attr "fp_mode")
7052 (if_then_else (eq_attr "fpu_single" "yes")
7053 (const_string "single") (const_string "double")))
7054 (set_attr "type" "jump_ind")])
7055
7056 ;; Like for sibcall_value_pcrel, use a fixed call clobbered register for
7057 ;; the branch address.
7058 (define_insn_and_split "sibcall_value_pcrel_fdpic"
7059 [(set (match_operand 0 "" "=rf")
7060 (call (mem:SI (match_operand:SI 1 "symbol_ref_operand"))
7061 (match_operand 2)))
7062 (use (reg:SI FPSCR_MODES_REG))
7063 (use (reg:SI PIC_REG))
7064 (clobber (reg:SI R1_REG))
7065 (return)]
7066 "TARGET_SH2 && TARGET_FDPIC"
7067 "#"
7068 "&& reload_completed"
7069 [(const_int 0)]
7070 {
7071 rtx lab = PATTERN (gen_call_site ());
7072
7073 operands[3] = gen_rtx_REG (SImode, R1_REG);
7074
7075 sh_expand_sym_label2reg (operands[3], operands[1], lab, true);
7076 rtx i = emit_call_insn (gen_sibcall_valuei_pcrel_fdpic (operands[0],
7077 operands[3],
7078 operands[2],
7079 copy_rtx (lab)));
7080 SIBLING_CALL_P (i) = 1;
7081 DONE;
7082 }
7083 [(set_attr "needs_delay_slot" "yes")
7084 (set (attr "fp_mode")
7085 (if_then_else (eq_attr "fpu_single" "yes")
7086 (const_string "single") (const_string "double")))
7087 (set_attr "type" "jump_ind")])
7088
7089 (define_expand "sibcall_value"
7090 [(parallel
7091 [(set (match_operand 0 "arith_reg_operand" "")
7092 (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
7093 (match_operand 2 "" "")))
7094 (match_operand 3 "" "")
7095 (use (reg:SI FPSCR_MODES_REG))
7096 (return)])]
7097 ""
7098 {
7099 if (TARGET_FDPIC)
7100 {
7101 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
7102 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
7103 }
7104
7105 if (flag_pic && TARGET_SH2
7106 && MEM_P (operands[1])
7107 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
7108 /* The PLT needs the PIC register, but the epilogue would have
7109 to restore it, so we can only use PC-relative PIC calls for
7110 static functions. */
7111 && SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
7112 {
7113 if (TARGET_FDPIC)
7114 emit_call_insn (gen_sibcall_value_pcrel_fdpic (operands[0],
7115 XEXP (operands[1], 0),
7116 operands[2]));
7117 else
7118 emit_call_insn (gen_sibcall_value_pcrel (operands[0],
7119 XEXP (operands[1], 0),
7120 operands[2]));
7121 DONE;
7122 }
7123 else
7124 operands[1] = force_reg (SImode, XEXP (operands[1], 0));
7125
7126 if (TARGET_FDPIC)
7127 {
7128 operands[1] = sh_load_function_descriptor (operands[1]);
7129 emit_call_insn (gen_sibcall_valuei_fdpic (operands[0], operands[1],
7130 operands[2]));
7131 }
7132 else
7133 emit_call_insn (gen_sibcall_valuei (operands[0], operands[1], operands[2]));
7134 DONE;
7135 })
7136
7137 (define_expand "sibcall_epilogue"
7138 [(return)]
7139 ""
7140 {
7141 sh_expand_epilogue (true);
7142 DONE;
7143 })
7144
7145 (define_insn "indirect_jump_compact"
7146 [(set (pc)
7147 (match_operand:SI 0 "arith_reg_operand" "r"))]
7148 "TARGET_SH1"
7149 "jmp @%0%#"
7150 [(set_attr "needs_delay_slot" "yes")
7151 (set_attr "type" "jump_ind")])
7152
7153 (define_expand "indirect_jump"
7154 [(set (pc)
7155 (match_operand 0 "register_operand" ""))]
7156 ""
7157 {
7158 if (GET_MODE (operands[0]) != Pmode)
7159 operands[0] = gen_rtx_SUBREG (Pmode, operands[0], 0);
7160 })
7161
7162 ;; The use of operand 1 / 2 helps us distinguish case table jumps
7163 ;; which can be present in structured code from indirect jumps which can not
7164 ;; be present in structured code. This allows -fprofile-arcs to work.
7165
7166 ;; For SH1 processors.
7167 (define_insn "casesi_jump_1"
7168 [(set (pc)
7169 (match_operand:SI 0 "register_operand" "r"))
7170 (use (label_ref (match_operand 1 "" "")))]
7171 "TARGET_SH1"
7172 "jmp @%0%#"
7173 [(set_attr "needs_delay_slot" "yes")
7174 (set_attr "type" "jump_ind")])
7175
7176 ;; For all later processors.
7177 (define_insn "casesi_jump_2"
7178 [(set (pc) (plus:SI (match_operand:SI 0 "register_operand" "r")
7179 (label_ref (match_operand 1 "" ""))))
7180 (use (label_ref (match_operand 2 "" "")))]
7181 "TARGET_SH2
7182 && (! INSN_UID (operands[1])
7183 || prev_real_insn (as_a<rtx_insn *> (operands[1])) == insn)"
7184 "braf %0%#"
7185 [(set_attr "needs_delay_slot" "yes")
7186 (set_attr "type" "jump_ind")])
7187
7188 ;; Call subroutine returning any type.
7189 ;; ??? This probably doesn't work.
7190 (define_expand "untyped_call"
7191 [(parallel [(call (match_operand 0 "" "")
7192 (const_int 0))
7193 (match_operand 1 "" "")
7194 (match_operand 2 "" "")])]
7195 "TARGET_SH2E || TARGET_SH2A"
7196 {
7197 /* RA does not know that the call sets the function value registers.
7198 We avoid problems by claiming that those registers are clobbered
7199 at this point. */
7200 for (int i = 0; i < XVECLEN (operands[2], 0); i++)
7201 emit_clobber (SET_SRC (XVECEXP (operands[2], 0, i)));
7202
7203 emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
7204
7205 for (int i = 0; i < XVECLEN (operands[2], 0); i++)
7206 {
7207 rtx set = XVECEXP (operands[2], 0, i);
7208 emit_move_insn (SET_DEST (set), SET_SRC (set));
7209 }
7210
7211 /* The optimizer does not know that the call sets the function value
7212 registers we stored in the result block. We avoid problems by
7213 claiming that all hard registers are used and clobbered at this
7214 point. */
7215 emit_insn (gen_blockage ());
7216
7217 DONE;
7218 })
7219 \f
7220 ;; ------------------------------------------------------------------------
7221 ;; Misc insns
7222 ;; ------------------------------------------------------------------------
7223
7224 (define_insn "dect"
7225 [(set (reg:SI T_REG)
7226 (eq:SI (match_operand:SI 1 "arith_reg_dest" "0") (const_int 1)))
7227 (set (match_operand:SI 0 "arith_reg_dest" "=r")
7228 (plus:SI (match_dup 1) (const_int -1)))]
7229 "TARGET_SH2"
7230 "dt %0"
7231 [(set_attr "type" "arith")])
7232
7233 (define_insn "nop"
7234 [(const_int 0)]
7235 ""
7236 "nop")
7237
7238 ;; Load address of a label. This is only generated by the casesi expand,
7239 ;; and by machine_dependent_reorg (fixing up fp moves).
7240 ;; This must use unspec, because this only works for labels that are
7241 ;; within range.
7242 (define_insn "mova"
7243 [(set (reg:SI R0_REG)
7244 (unspec:SI [(label_ref (match_operand 0 "" ""))] UNSPEC_MOVA))]
7245 "TARGET_SH1"
7246 "mova %O0,r0"
7247 [(set_attr "in_delay_slot" "no")
7248 (set_attr "type" "arith")])
7249
7250 ;; machine_dependent_reorg will make this a `mova'.
7251 (define_insn "mova_const"
7252 [(set (reg:SI R0_REG)
7253 (unspec:SI [(match_operand 0 "immediate_operand" "i")] UNSPEC_MOVA))]
7254 "TARGET_SH1"
7255 "#"
7256 [(set_attr "in_delay_slot" "no")
7257 (set_attr "type" "arith")])
7258
7259 ;; Loads of the GOTPC relocation values must not be optimized away
7260 ;; by e.g. any kind of CSE and must stay as they are. Although there
7261 ;; are other various ways to ensure this, we use an artificial counter
7262 ;; operand to generate unique symbols.
7263 (define_expand "GOTaddr2picreg"
7264 [(set (reg:SI R0_REG)
7265 (unspec:SI [(const:SI (unspec:SI [(match_dup 2)
7266 (match_operand:SI 0 "" "")]
7267 UNSPEC_PIC))] UNSPEC_MOVA))
7268 (set (match_dup 1)
7269 (const:SI (unspec:SI [(match_dup 2) (match_dup 0)] UNSPEC_PIC)))
7270 (set (match_dup 1) (plus:SI (match_dup 1) (reg:SI R0_REG)))]
7271 ""
7272 {
7273 if (TARGET_VXWORKS_RTP)
7274 {
7275 rtx gott_base = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE);
7276 rtx gott_index = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7277 emit_insn (gen_vxworks_picreg (gott_base, gott_index));
7278 DONE;
7279 }
7280
7281 if (TARGET_FDPIC)
7282 {
7283 rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
7284 emit_move_insn (pic_reg, sh_get_fdpic_reg_initial_val ());
7285 DONE;
7286 }
7287
7288 operands[1] = gen_rtx_REG (Pmode, PIC_REG);
7289 operands[2] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
7290 })
7291
7292 ;; A helper for GOTaddr2picreg to finish up the initialization of the
7293 ;; PIC register.
7294 (define_expand "vxworks_picreg"
7295 [(set (reg:SI PIC_REG)
7296 (const:SI (unspec:SI [(match_operand:SI 0 "" "")] UNSPEC_PIC)))
7297 (set (reg:SI R0_REG)
7298 (const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PIC)))
7299 (set (reg:SI PIC_REG)
7300 (mem:SI (reg:SI PIC_REG)))
7301 (set (reg:SI PIC_REG)
7302 (mem:SI (plus:SI (reg:SI PIC_REG)
7303 (reg:SI R0_REG))))]
7304 "TARGET_VXWORKS_RTP")
7305
7306 (define_expand "builtin_setjmp_receiver"
7307 [(match_operand 0 "" "")]
7308 "flag_pic"
7309 {
7310 emit_insn (gen_GOTaddr2picreg (const0_rtx));
7311 DONE;
7312 })
7313
7314 (define_expand "call_site"
7315 [(unspec [(match_dup 0)] UNSPEC_CALLER)]
7316 "TARGET_SH1"
7317 {
7318 static HOST_WIDE_INT i = 0;
7319 operands[0] = GEN_INT (i);
7320 i++;
7321 })
7322
7323 ;; op0 = op1 + r12 but hide it before reload completed. See the comment
7324 ;; in symGOT_load expand.
7325 (define_insn_and_split "chk_guard_add"
7326 [(set (match_operand:SI 0 "register_operand" "=&r")
7327 (unspec:SI [(match_operand:SI 1 "register_operand" "r")
7328 (reg:SI PIC_REG)]
7329 UNSPEC_CHKADD))]
7330 "TARGET_SH1"
7331 "#"
7332 "TARGET_SH1 && reload_completed"
7333 [(set (match_dup 0) (reg:SI PIC_REG))
7334 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))]
7335 ""
7336 [(set_attr "type" "arith")])
7337
7338 (define_expand "sym_label2reg"
7339 [(set (match_operand:SI 0 "" "")
7340 (const:SI (unspec:SI [(match_operand:SI 1 "" "")
7341 (const (plus:SI (match_operand:SI 2 "" "")
7342 (const_int 2)))]
7343 UNSPEC_SYMOFF)))]
7344 "TARGET_SH1" "")
7345
7346 (define_expand "symPCREL_label2reg"
7347 [(set (match_operand:SI 0 "" "")
7348 (const:SI
7349 (unspec:SI
7350 [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PCREL))
7351 (const:SI (plus:SI (match_operand:SI 2 "" "")
7352 (const_int 2)))] UNSPEC_PCREL_SYMOFF)))]
7353 "TARGET_SH1"
7354 "")
7355
7356 (define_expand "symGOT_load"
7357 [(set (match_dup 2) (match_operand 1 "" ""))
7358 (set (match_dup 3) (plus (match_dup 2) (reg PIC_REG)))
7359 (set (match_operand 0 "" "") (mem (match_dup 3)))]
7360 ""
7361 {
7362 rtx mem;
7363 bool stack_chk_guard_p = false;
7364
7365 rtx picreg = TARGET_FDPIC ? sh_get_fdpic_reg_initial_val ()
7366 : gen_rtx_REG (Pmode, PIC_REG);
7367
7368 operands[2] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
7369 operands[3] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
7370
7371 if (!TARGET_FDPIC
7372 && flag_stack_protect
7373 && GET_CODE (operands[1]) == CONST
7374 && GET_CODE (XEXP (operands[1], 0)) == UNSPEC
7375 && GET_CODE (XVECEXP (XEXP (operands[1], 0), 0, 0)) == SYMBOL_REF
7376 && strcmp (XSTR (XVECEXP (XEXP (operands[1], 0), 0, 0), 0),
7377 "__stack_chk_guard") == 0)
7378 stack_chk_guard_p = true;
7379
7380 emit_move_insn (operands[2], operands[1]);
7381
7382 /* When stack protector inserts codes after the result is set to
7383 R0, @(rX, r12) will cause a spill failure for R0. Use a unspec
7384 insn to avoid combining (set A (plus rX r12)) and (set op0 (mem A))
7385 when rX is a GOT address for the guard symbol. Ugly but doesn't
7386 matter because this is a rare situation. */
7387 if (stack_chk_guard_p)
7388 emit_insn (gen_chk_guard_add (operands[3], operands[2]));
7389 else
7390 emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2], picreg));
7391
7392 /* N.B. This is not constant for a GOTPLT relocation. */
7393 mem = gen_rtx_MEM (Pmode, operands[3]);
7394 MEM_NOTRAP_P (mem) = 1;
7395 /* ??? Should we have a special alias set for the GOT? */
7396 emit_move_insn (operands[0], mem);
7397
7398 DONE;
7399 })
7400
7401 (define_expand "sym2GOT"
7402 [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOT))]
7403 ""
7404 "")
7405
7406 (define_expand "symGOT2reg"
7407 [(match_operand 0 "" "") (match_operand 1 "" "")]
7408 ""
7409 {
7410 rtx gotsym, insn;
7411
7412 gotsym = gen_sym2GOT (operands[1]);
7413 PUT_MODE (gotsym, Pmode);
7414 insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
7415
7416 MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
7417
7418 DONE;
7419 })
7420
7421 (define_expand "sym2GOTFUNCDESC"
7422 [(const (unspec [(match_operand 0)] UNSPEC_GOTFUNCDESC))]
7423 "TARGET_FDPIC")
7424
7425 (define_expand "symGOTFUNCDESC2reg"
7426 [(match_operand 0) (match_operand 1)]
7427 "TARGET_FDPIC"
7428 {
7429 rtx gotsym = gen_sym2GOTFUNCDESC (operands[1]);
7430 PUT_MODE (gotsym, Pmode);
7431 rtx insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
7432
7433 MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
7434
7435 DONE;
7436 })
7437
7438 (define_expand "symGOTPLT2reg"
7439 [(match_operand 0 "" "") (match_operand 1 "" "")]
7440 ""
7441 {
7442 rtx pltsym = gen_rtx_CONST (Pmode,
7443 gen_rtx_UNSPEC (Pmode,
7444 gen_rtvec (1, operands[1]),
7445 UNSPEC_GOTPLT));
7446 emit_insn (gen_symGOT_load (operands[0], pltsym));
7447 DONE;
7448 })
7449
7450 (define_expand "sym2GOTOFF"
7451 [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTOFF))]
7452 ""
7453 "")
7454
7455 (define_expand "symGOTOFF2reg"
7456 [(match_operand 0 "" "") (match_operand 1 "" "")]
7457 ""
7458 {
7459 rtx gotoffsym;
7460 rtx t = (!can_create_pseudo_p ()
7461 ? operands[0]
7462 : gen_reg_rtx (GET_MODE (operands[0])));
7463
7464 rtx picreg = TARGET_FDPIC ? sh_get_fdpic_reg_initial_val ()
7465 : gen_rtx_REG (Pmode, PIC_REG);
7466
7467 gotoffsym = gen_sym2GOTOFF (operands[1]);
7468 PUT_MODE (gotoffsym, Pmode);
7469 emit_move_insn (t, gotoffsym);
7470 rtx_insn *insn = emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
7471
7472 set_unique_reg_note (insn, REG_EQUAL, operands[1]);
7473
7474 DONE;
7475 })
7476
7477 (define_expand "sym2GOTOFFFUNCDESC"
7478 [(const (unspec [(match_operand 0)] UNSPEC_GOTOFFFUNCDESC))]
7479 "TARGET_FDPIC")
7480
7481 (define_expand "symGOTOFFFUNCDESC2reg"
7482 [(match_operand 0) (match_operand 1)]
7483 "TARGET_FDPIC"
7484 {
7485 rtx picreg = sh_get_fdpic_reg_initial_val ();
7486 rtx t = !can_create_pseudo_p ()
7487 ? operands[0]
7488 : gen_reg_rtx (GET_MODE (operands[0]));
7489
7490 rtx gotoffsym = gen_sym2GOTOFFFUNCDESC (operands[1]);
7491 PUT_MODE (gotoffsym, Pmode);
7492 emit_move_insn (t, gotoffsym);
7493 emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
7494 DONE;
7495 })
7496
7497 (define_expand "symPLT_label2reg"
7498 [(set (match_operand:SI 0 "" "")
7499 (const:SI
7500 (unspec:SI
7501 [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PLT))
7502 (const:SI (plus:SI (match_operand:SI 2 "" "")
7503 (const_int 2)))] UNSPEC_PCREL_SYMOFF)))
7504 ;; Even though the PIC register is not really used by the call
7505 ;; sequence in which this is expanded, the PLT code assumes the PIC
7506 ;; register is set, so we must not skip its initialization. Since
7507 ;; we only use this expand as part of calling sequences, and never
7508 ;; to take the address of a function, this is the best point to
7509 ;; insert the (use). Using the PLT to take the address of a
7510 ;; function would be wrong, not only because the PLT entry could
7511 ;; then be called from a function that doesn't initialize the PIC
7512 ;; register to the proper GOT, but also because pointers to the
7513 ;; same function might not compare equal, should they be set by
7514 ;; different shared libraries.
7515 (use (reg:SI PIC_REG))]
7516 "TARGET_SH1"
7517 "")
7518
7519 (define_expand "sym2PIC"
7520 [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PIC))]
7521 ""
7522 "")
7523
7524 ;; -------------------------------------------------------------------------
7525 ;; TLS code generation.
7526
7527 ;; FIXME: The multi-insn asm blocks should be converted to use
7528 ;; define_insn_and_split.
7529 ;; See the thread [PATCH/RFA] SH TLS support on gcc-patches
7530 ;; <http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01898.html>
7531 ;; for details.
7532
7533 (define_insn "tls_global_dynamic"
7534 [(set (match_operand:SI 0 "register_operand" "=&z")
7535 (call:SI (mem:SI (unspec:SI [(match_operand:SI 1 "" "")]
7536 UNSPEC_TLSGD))
7537 (const_int 0)))
7538 (use (reg:SI FPSCR_MODES_REG))
7539 (use (reg:SI PIC_REG))
7540 (clobber (reg:SI PR_REG))
7541 (clobber (scratch:SI))]
7542 "TARGET_SH1"
7543 {
7544 return "mov.l 1f,r4" "\n"
7545 " mova 2f,r0" "\n"
7546 " mov.l 2f,r1" "\n"
7547 " add r0,r1" "\n"
7548 " jsr @r1" "\n"
7549 " add r12,r4" "\n"
7550 " bra 3f" "\n"
7551 " nop" "\n"
7552 " .align 2" "\n"
7553 "1: .long %a1@TLSGD" "\n"
7554 "2: .long __tls_get_addr@PLT" "\n"
7555 "3:";
7556 }
7557 [(set_attr "type" "tls_load")
7558 (set_attr "length" "26")])
7559
7560 (define_insn "tls_local_dynamic"
7561 [(set (match_operand:SI 0 "register_operand" "=&z")
7562 (call:SI (mem:SI (unspec:SI [(match_operand:SI 1 "" "")]
7563 UNSPEC_TLSLDM))
7564 (const_int 0)))
7565 (use (reg:SI FPSCR_MODES_REG))
7566 (use (reg:SI PIC_REG))
7567 (clobber (reg:SI PR_REG))
7568 (clobber (scratch:SI))]
7569 "TARGET_SH1"
7570 {
7571 return "mov.l 1f,r4" "\n"
7572 " mova 2f,r0" "\n"
7573 " mov.l 2f,r1" "\n"
7574 " add r0,r1" "\n"
7575 " jsr @r1" "\n"
7576 " add r12,r4" "\n"
7577 " bra 3f" "\n"
7578 " nop" "\n"
7579 " .align 2" "\n"
7580 "1: .long %a1@TLSLDM" "\n"
7581 "2: .long __tls_get_addr@PLT" "\n"
7582 "3:";
7583 }
7584 [(set_attr "type" "tls_load")
7585 (set_attr "length" "26")])
7586
7587 (define_expand "sym2DTPOFF"
7588 [(const (unspec [(match_operand 0 "" "")] UNSPEC_DTPOFF))]
7589 ""
7590 "")
7591
7592 (define_expand "symDTPOFF2reg"
7593 [(match_operand 0 "" "") (match_operand 1 "" "") (match_operand 2 "" "")]
7594 ""
7595 {
7596 rtx dtpoffsym;
7597 rtx t = (!can_create_pseudo_p ()
7598 ? operands[0]
7599 : gen_reg_rtx (GET_MODE (operands[0])));
7600
7601 dtpoffsym = gen_sym2DTPOFF (operands[1]);
7602 PUT_MODE (dtpoffsym, Pmode);
7603 emit_move_insn (t, dtpoffsym);
7604 emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, operands[2]));
7605 DONE;
7606 })
7607
7608 (define_expand "sym2GOTTPOFF"
7609 [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTTPOFF))]
7610 ""
7611 "")
7612
7613 (define_insn "tls_initial_exec"
7614 [(set (match_operand:SI 0 "register_operand" "=&r")
7615 (unspec:SI [(match_operand:SI 1 "" "")]
7616 UNSPEC_TLSIE))
7617 (use (reg:SI GBR_REG))
7618 (use (reg:SI PIC_REG))
7619 (clobber (reg:SI R0_REG))]
7620 ""
7621 {
7622 return "mov.l 1f,r0" "\n"
7623 " stc gbr,%0" "\n"
7624 " mov.l @(r0,r12),r0" "\n"
7625 " bra 2f" "\n"
7626 " add r0,%0" "\n"
7627 " .align 2" "\n"
7628 "1: .long %a1" "\n"
7629 "2:";
7630 }
7631 [(set_attr "type" "tls_load")
7632 (set_attr "length" "16")])
7633
7634 (define_expand "sym2TPOFF"
7635 [(const (unspec [(match_operand 0 "" "")] UNSPEC_TPOFF))]
7636 ""
7637 "")
7638
7639 (define_expand "symTPOFF2reg"
7640 [(match_operand 0 "" "") (match_operand 1 "" "")]
7641 ""
7642 {
7643 rtx tpoffsym;
7644
7645 tpoffsym = gen_sym2TPOFF (operands[1]);
7646 PUT_MODE (tpoffsym, Pmode);
7647 emit_move_insn (operands[0], tpoffsym);
7648 DONE;
7649 })
7650
7651 ;;------------------------------------------------------------------------------
7652 ;; Thread pointer getter and setter.
7653 ;;
7654 ;; On SH the thread pointer is kept in the GBR.
7655 ;; These patterns are usually expanded from the respective built-in functions.
7656 (define_expand "get_thread_pointersi"
7657 [(set (match_operand:SI 0 "arith_reg_dest") (reg:SI GBR_REG))]
7658 "TARGET_SH1")
7659
7660 ;; The store_gbr insn can also be used on !TARGET_SH1 for doing TLS accesses.
7661 (define_insn "store_gbr"
7662 [(set (match_operand:SI 0 "arith_reg_dest" "=r") (reg:SI GBR_REG))]
7663 ""
7664 "stc gbr,%0"
7665 [(set_attr "type" "tls_load")])
7666
7667 (define_expand "set_thread_pointersi"
7668 [(set (reg:SI GBR_REG)
7669 (unspec_volatile:SI [(match_operand:SI 0 "arith_reg_operand")]
7670 UNSPECV_GBR))]
7671 "TARGET_SH1")
7672
7673 (define_insn "load_gbr"
7674 [(set (reg:SI GBR_REG)
7675 (unspec_volatile:SI [(match_operand:SI 0 "arith_reg_operand" "r")]
7676 UNSPECV_GBR))]
7677 "TARGET_SH1"
7678 "ldc %0,gbr"
7679 [(set_attr "type" "move")])
7680
7681 ;;------------------------------------------------------------------------------
7682 ;; Thread pointer relative memory loads and stores.
7683 ;;
7684 ;; On SH there are GBR displacement address modes which can be utilized to
7685 ;; access memory behind the thread pointer.
7686 ;; Since we do not allow using GBR for general purpose memory accesses, these
7687 ;; GBR addressing modes are formed by the combine pass.
7688 ;; This could be done with fewer patterns than below by using a mem predicate
7689 ;; for the GBR mem, but then reload would try to reload addresses with a
7690 ;; zero displacement for some strange reason.
7691
7692 (define_insn "*mov<mode>_gbr_load"
7693 [(set (match_operand:QIHISI 0 "arith_reg_dest" "=z")
7694 (mem:QIHISI (plus:SI (reg:SI GBR_REG)
7695 (match_operand:QIHISI 1 "gbr_displacement"))))]
7696 "TARGET_SH1"
7697 "mov.<bwl> @(%O1,gbr),%0"
7698 [(set_attr "type" "load")])
7699
7700 (define_insn "*mov<mode>_gbr_load"
7701 [(set (match_operand:QIHISI 0 "arith_reg_dest" "=z")
7702 (mem:QIHISI (reg:SI GBR_REG)))]
7703 "TARGET_SH1"
7704 "mov.<bwl> @(0,gbr),%0"
7705 [(set_attr "type" "load")])
7706
7707 (define_insn "*mov<mode>_gbr_load"
7708 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
7709 (sign_extend:SI
7710 (mem:QIHI (plus:SI (reg:SI GBR_REG)
7711 (match_operand:QIHI 1 "gbr_displacement")))))]
7712 "TARGET_SH1"
7713 "mov.<bw> @(%O1,gbr),%0"
7714 [(set_attr "type" "load")])
7715
7716 (define_insn "*mov<mode>_gbr_load"
7717 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
7718 (sign_extend:SI (mem:QIHI (reg:SI GBR_REG))))]
7719 "TARGET_SH1"
7720 "mov.<bw> @(0,gbr),%0"
7721 [(set_attr "type" "load")])
7722
7723 (define_insn "*mov<mode>_gbr_store"
7724 [(set (mem:QIHISI (plus:SI (reg:SI GBR_REG)
7725 (match_operand:QIHISI 0 "gbr_displacement")))
7726 (match_operand:QIHISI 1 "register_operand" "z"))]
7727 "TARGET_SH1"
7728 "mov.<bwl> %1,@(%O0,gbr)"
7729 [(set_attr "type" "store")])
7730
7731 (define_insn "*mov<mode>_gbr_store"
7732 [(set (mem:QIHISI (reg:SI GBR_REG))
7733 (match_operand:QIHISI 0 "register_operand" "z"))]
7734 "TARGET_SH1"
7735 "mov.<bwl> %0,@(0,gbr)"
7736 [(set_attr "type" "store")])
7737
7738 ;; DImode memory accesses have to be split in two SImode accesses.
7739 ;; Split them before reload, so that it gets a better chance to figure out
7740 ;; how to deal with the R0 restriction for the individual SImode accesses.
7741 ;; Do not match this insn during or after reload because it can't be split
7742 ;; afterwards.
7743 (define_insn_and_split "*movdi_gbr_load"
7744 [(set (match_operand:DI 0 "arith_reg_dest")
7745 (match_operand:DI 1 "gbr_address_mem"))]
7746 "TARGET_SH1 && can_create_pseudo_p ()"
7747 "#"
7748 "&& 1"
7749 [(set (match_dup 3) (match_dup 5))
7750 (set (match_dup 4) (match_dup 6))]
7751 {
7752 /* Swap low/high part load order on little endian, so that the result reg
7753 of the second load can be used better. */
7754 int off = TARGET_LITTLE_ENDIAN ? 1 : 0;
7755 operands[3 + off] = gen_lowpart (SImode, operands[0]);
7756 operands[5 + off] = gen_lowpart (SImode, operands[1]);
7757 operands[4 - off] = gen_highpart (SImode, operands[0]);
7758 operands[6 - off] = gen_highpart (SImode, operands[1]);
7759 })
7760
7761 (define_insn_and_split "*movdi_gbr_store"
7762 [(set (match_operand:DI 0 "gbr_address_mem")
7763 (match_operand:DI 1 "register_operand"))]
7764 "TARGET_SH1 && can_create_pseudo_p ()"
7765 "#"
7766 "&& 1"
7767 [(set (match_dup 3) (match_dup 5))
7768 (set (match_dup 4) (match_dup 6))]
7769 {
7770 /* Swap low/high part store order on big endian, so that stores of function
7771 call results can save a reg copy. */
7772 int off = TARGET_LITTLE_ENDIAN ? 0 : 1;
7773 operands[3 + off] = gen_lowpart (SImode, operands[0]);
7774 operands[5 + off] = gen_lowpart (SImode, operands[1]);
7775 operands[4 - off] = gen_highpart (SImode, operands[0]);
7776 operands[6 - off] = gen_highpart (SImode, operands[1]);
7777 })
7778
7779 ;; Sometimes memory accesses do not get combined with the store_gbr insn,
7780 ;; in particular when the displacements are in the range of the regular move
7781 ;; insns. Thus, in the first split pass after the combine pass we search
7782 ;; for missed opportunities and try to fix them up ourselves.
7783 ;; If an equivalent GBR address can be determined the load / store is split
7784 ;; into one of the GBR load / store patterns.
7785 ;; All of that must happen before reload (GBR address modes use R0 as the
7786 ;; other operand) and there's no point of doing it if the GBR is not
7787 ;; referenced in a function at all.
7788 (define_split
7789 [(set (match_operand:QIHISIDI 0 "register_operand")
7790 (match_operand:QIHISIDI 1 "memory_operand"))]
7791 "TARGET_SH1 && !reload_in_progress && !reload_completed
7792 && df_regs_ever_live_p (GBR_REG)"
7793 [(set (match_dup 0) (match_dup 1))]
7794 {
7795 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
7796 if (gbr_mem != NULL_RTX)
7797 operands[1] = replace_equiv_address (operands[1], gbr_mem);
7798 else
7799 FAIL;
7800 })
7801
7802 (define_split
7803 [(set (match_operand:SI 0 "register_operand")
7804 (sign_extend:SI (match_operand:QIHI 1 "memory_operand")))]
7805 "TARGET_SH1 && !reload_in_progress && !reload_completed
7806 && df_regs_ever_live_p (GBR_REG)"
7807 [(set (match_dup 0) (sign_extend:SI (match_dup 1)))]
7808 {
7809 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
7810 if (gbr_mem != NULL_RTX)
7811 operands[1] = replace_equiv_address (operands[1], gbr_mem);
7812 else
7813 FAIL;
7814 })
7815
7816 ;; On SH2A we've got movu.b and movu.w for doing zero-extending mem loads.
7817 ;; Split those so that a GBR load can be used.
7818 (define_split
7819 [(set (match_operand:SI 0 "register_operand")
7820 (zero_extend:SI (match_operand:QIHI 1 "memory_operand")))]
7821 "TARGET_SH2A && !reload_in_progress && !reload_completed
7822 && df_regs_ever_live_p (GBR_REG)"
7823 [(set (match_dup 2) (match_dup 1))
7824 (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
7825 {
7826 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
7827 if (gbr_mem != NULL_RTX)
7828 {
7829 operands[2] = gen_reg_rtx (GET_MODE (operands[1]));
7830 operands[1] = replace_equiv_address (operands[1], gbr_mem);
7831 }
7832 else
7833 FAIL;
7834 })
7835
7836 (define_split
7837 [(set (match_operand:QIHISIDI 0 "memory_operand")
7838 (match_operand:QIHISIDI 1 "register_operand"))]
7839 "TARGET_SH1 && !reload_in_progress && !reload_completed
7840 && df_regs_ever_live_p (GBR_REG)"
7841 [(set (match_dup 0) (match_dup 1))]
7842 {
7843 rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[0]);
7844 if (gbr_mem != NULL_RTX)
7845 operands[0] = replace_equiv_address (operands[0], gbr_mem);
7846 else
7847 FAIL;
7848 })
7849
7850 ;;------------------------------------------------------------------------------
7851 ;; case instruction for switch statements.
7852
7853 ;; operand 0 is index
7854 ;; operand 1 is the minimum bound
7855 ;; operand 2 is the maximum bound - minimum bound + 1
7856 ;; operand 3 is CODE_LABEL for the table;
7857 ;; operand 4 is the CODE_LABEL to go to if index out of range.
7858 (define_expand "casesi"
7859 [(match_operand:SI 0 "arith_reg_operand" "")
7860 (match_operand:SI 1 "arith_reg_operand" "")
7861 (match_operand:SI 2 "arith_reg_operand" "")
7862 (match_operand 3 "" "") (match_operand 4 "" "")]
7863 ""
7864 {
7865 rtx reg = gen_reg_rtx (SImode);
7866 rtx reg2 = gen_reg_rtx (SImode);
7867
7868 operands[1] = copy_to_mode_reg (SImode, operands[1]);
7869 operands[2] = copy_to_mode_reg (SImode, operands[2]);
7870 /* If optimizing, casesi_worker depends on the mode of the instruction
7871 before label it 'uses' - operands[3]. */
7872 emit_insn (gen_casesi_0 (operands[0], operands[1], operands[2], operands[4],
7873 reg));
7874 emit_insn (gen_casesi_worker_0 (reg2, reg, operands[3]));
7875 if (TARGET_SH2)
7876 emit_jump_insn (gen_casesi_jump_2 (reg2, gen_label_rtx (), operands[3]));
7877 else
7878 emit_jump_insn (gen_casesi_jump_1 (reg2, operands[3]));
7879 /* For SH2 and newer, the ADDR_DIFF_VEC is not actually relative to
7880 operands[3], but to lab. We will fix this up in
7881 machine_dependent_reorg. */
7882 emit_barrier ();
7883 DONE;
7884 })
7885
7886 (define_expand "casesi_0"
7887 [(set (match_operand:SI 4 "" "") (match_operand:SI 0 "arith_reg_operand" ""))
7888 (set (match_dup 4) (minus:SI (match_dup 4)
7889 (match_operand:SI 1 "arith_operand" "")))
7890 (set (reg:SI T_REG)
7891 (gtu:SI (match_dup 4)
7892 (match_operand:SI 2 "arith_reg_operand" "")))
7893 (set (pc)
7894 (if_then_else (ne (reg:SI T_REG)
7895 (const_int 0))
7896 (label_ref (match_operand 3 "" ""))
7897 (pc)))]
7898 "TARGET_SH1"
7899 "")
7900
7901 ;; ??? reload might clobber r0 if we use it explicitly in the RTL before
7902 ;; reload; using a R0_REGS pseudo reg is likely to give poor code.
7903 ;; So we keep the use of r0 hidden in a R0_REGS clobber until after reload.
7904 ;;
7905 ;; The use on the T_REG in the casesi_worker* patterns links the bounds
7906 ;; checking insns and the table memory access. See also PR 69713.
7907 (define_insn "casesi_worker_0"
7908 [(set (match_operand:SI 0 "register_operand" "=r,r")
7909 (unspec:SI [(match_operand:SI 1 "register_operand" "0,r")
7910 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7911 (clobber (match_scratch:SI 3 "=X,1"))
7912 (clobber (match_scratch:SI 4 "=&z,z"))
7913 (use (reg:SI T_REG))]
7914 "TARGET_SH1"
7915 "#")
7916
7917 (define_split
7918 [(set (match_operand:SI 0 "register_operand" "")
7919 (unspec:SI [(match_operand:SI 1 "register_operand" "")
7920 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7921 (clobber (match_scratch:SI 3 ""))
7922 (clobber (match_scratch:SI 4))
7923 (use (reg:SI T_REG))]
7924 "TARGET_SH1 && ! TARGET_SH2 && reload_completed"
7925 [(set (reg:SI R0_REG) (unspec:SI [(label_ref (match_dup 2))] UNSPEC_MOVA))
7926 (parallel [(set (match_dup 0)
7927 (unspec:SI [(reg:SI R0_REG) (match_dup 1)
7928 (label_ref (match_dup 2))] UNSPEC_CASESI))
7929 (clobber (match_dup 3))])
7930 (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI R0_REG)))]
7931 {
7932 if (GET_CODE (operands[2]) == CODE_LABEL)
7933 LABEL_NUSES (operands[2])++;
7934 })
7935
7936 (define_split
7937 [(set (match_operand:SI 0 "register_operand" "")
7938 (unspec:SI [(match_operand:SI 1 "register_operand" "")
7939 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7940 (clobber (match_scratch:SI 3 ""))
7941 (clobber (match_scratch:SI 4))
7942 (use (reg:SI T_REG))]
7943 "TARGET_SH2 && reload_completed"
7944 [(set (reg:SI R0_REG) (unspec:SI [(label_ref (match_dup 2))] UNSPEC_MOVA))
7945 (parallel [(set (match_dup 0)
7946 (unspec:SI [(reg:SI R0_REG) (match_dup 1)
7947 (label_ref (match_dup 2))] UNSPEC_CASESI))
7948 (clobber (match_dup 3))])]
7949 {
7950 if (GET_CODE (operands[2]) == CODE_LABEL)
7951 LABEL_NUSES (operands[2])++;
7952 })
7953
7954 ;; This may be replaced with casesi_worker_2 in sh_reorg for PIC.
7955 ;; The insn length is set to 8 for that case.
7956 (define_insn "casesi_worker_1"
7957 [(set (match_operand:SI 0 "register_operand" "=r,r")
7958 (unspec:SI [(reg:SI R0_REG)
7959 (match_operand:SI 1 "register_operand" "0,r")
7960 (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
7961 (clobber (match_scratch:SI 3 "=X,1"))]
7962 "TARGET_SH1"
7963 {
7964 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
7965
7966 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
7967
7968 switch (GET_MODE (diff_vec))
7969 {
7970 case SImode:
7971 return "shll2 %1" "\n"
7972 " mov.l @(r0,%1),%0";
7973 case HImode:
7974 return "add %1,%1" "\n"
7975 " mov.w @(r0,%1),%0";
7976 case QImode:
7977 if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
7978 return "mov.b @(r0,%1),%0" "\n"
7979 " extu.b %0,%0";
7980 else
7981 return "mov.b @(r0,%1),%0";
7982
7983 default:
7984 gcc_unreachable ();
7985 }
7986 }
7987 [(set_attr_alternative "length"
7988 [(if_then_else (match_test "flag_pic") (const_int 8) (const_int 4))
7989 (if_then_else (match_test "flag_pic") (const_int 8) (const_int 4))])])
7990
7991 (define_insn "casesi_worker_2"
7992 [(set (match_operand:SI 0 "register_operand" "=r,r")
7993 (unspec:SI [(reg:SI R0_REG)
7994 (match_operand:SI 1 "register_operand" "0,r")
7995 (label_ref (match_operand 2 "" ""))
7996 (label_ref (match_operand 3 "" ""))] UNSPEC_CASESI))
7997 (clobber (match_operand:SI 4 "" "=X,1"))]
7998 "TARGET_SH2 && reload_completed && flag_pic"
7999 {
8000 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
8001 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
8002
8003 switch (GET_MODE (diff_vec))
8004 {
8005 case SImode:
8006 return "shll2 %1" "\n"
8007 " add r0,%1" "\n"
8008 " mova %O3,r0" "\n"
8009 " mov.l @(r0,%1),%0";
8010 case HImode:
8011 return "add %1,%1" "\n"
8012 " add r0,%1" "\n"
8013 " mova %O3,r0" "\n"
8014 " mov.w @(r0,%1),%0";
8015 case QImode:
8016 if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
8017 return "add r0,%1" "\n"
8018 " mova %O3,r0" "\n"
8019 " mov.b @(r0,%1),%0" "\n"
8020 " extu.b %0,%0";
8021 else
8022 return "add r0,%1" "\n"
8023 " mova %O3,r0" "\n"
8024 " mov.b @(r0,%1),%0";
8025 default:
8026 gcc_unreachable ();
8027 }
8028 }
8029 [(set_attr "length" "8")])
8030
8031 (define_expand "simple_return"
8032 [(simple_return)]
8033 "sh_can_use_simple_return_p ()")
8034
8035 (define_expand "return"
8036 [(return)]
8037 "reload_completed && epilogue_completed")
8038
8039 (define_insn "*<code>_i"
8040 [(any_return)]
8041 "TARGET_SH1
8042 && reload_completed
8043 && ! sh_cfun_trap_exit_p ()"
8044 {
8045 if (TARGET_SH2A && (dbr_sequence_length () == 0)
8046 && !current_function_interrupt)
8047 return "rts/n";
8048 else
8049 return "%@ %#";
8050 }
8051 [(set_attr "type" "return")
8052 (set_attr "needs_delay_slot" "yes")])
8053
8054 ;; trapa has no delay slot.
8055 (define_insn "*return_trapa"
8056 [(return)]
8057 "TARGET_SH1 && reload_completed"
8058 "%@"
8059 [(set_attr "type" "return")])
8060
8061 (define_expand "prologue"
8062 [(const_int 0)]
8063 ""
8064 {
8065 sh_expand_prologue ();
8066 DONE;
8067 })
8068
8069 (define_expand "epilogue"
8070 [(return)]
8071 ""
8072 {
8073 sh_expand_epilogue (false);
8074 })
8075
8076 (define_expand "eh_return"
8077 [(use (match_operand 0 "register_operand" ""))]
8078 ""
8079 {
8080 emit_insn (gen_eh_set_ra_si (operands[0]));
8081 DONE;
8082 })
8083
8084 ;; Clobber the return address on the stack. We can't expand this
8085 ;; until we know where it will be put in the stack frame.
8086
8087 (define_insn "eh_set_ra_si"
8088 [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
8089 UNSPECV_EH_RETURN)
8090 (clobber (match_scratch:SI 1 "=&r"))]
8091 ""
8092 "#")
8093
8094 (define_split
8095 [(unspec_volatile [(match_operand 0 "register_operand" "")]
8096 UNSPECV_EH_RETURN)
8097 (clobber (match_scratch 1 ""))]
8098 "reload_completed"
8099 [(const_int 0)]
8100 {
8101 sh_set_return_address (operands[0], operands[1]);
8102 DONE;
8103 })
8104
8105 (define_insn "blockage"
8106 [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
8107 ""
8108 ""
8109 [(set_attr "length" "0")])
8110 \f
8111 ;; Define movml instructions for SH2A target. Currently they are
8112 ;; used to push and pop all banked registers only.
8113
8114 (define_insn "movml_push_banked"
8115 [(set (match_operand:SI 0 "register_operand" "=r")
8116 (plus (match_dup 0) (const_int -32)))
8117 (set (mem:SI (plus:SI (match_dup 0) (const_int 28))) (reg:SI R7_REG))
8118 (set (mem:SI (plus:SI (match_dup 0) (const_int 24))) (reg:SI R6_REG))
8119 (set (mem:SI (plus:SI (match_dup 0) (const_int 20))) (reg:SI R5_REG))
8120 (set (mem:SI (plus:SI (match_dup 0) (const_int 16))) (reg:SI R4_REG))
8121 (set (mem:SI (plus:SI (match_dup 0) (const_int 12))) (reg:SI R3_REG))
8122 (set (mem:SI (plus:SI (match_dup 0) (const_int 8))) (reg:SI R2_REG))
8123 (set (mem:SI (plus:SI (match_dup 0) (const_int 4))) (reg:SI R1_REG))
8124 (set (mem:SI (plus:SI (match_dup 0) (const_int 0))) (reg:SI R0_REG))]
8125 "TARGET_SH2A && REGNO (operands[0]) == 15"
8126 "movml.l r7,@-r15"
8127 [(set_attr "in_delay_slot" "no")])
8128
8129 (define_insn "movml_pop_banked"
8130 [(set (match_operand:SI 0 "register_operand" "=r")
8131 (plus (match_dup 0) (const_int 32)))
8132 (set (reg:SI R0_REG) (mem:SI (plus:SI (match_dup 0) (const_int -32))))
8133 (set (reg:SI R1_REG) (mem:SI (plus:SI (match_dup 0) (const_int -28))))
8134 (set (reg:SI R2_REG) (mem:SI (plus:SI (match_dup 0) (const_int -24))))
8135 (set (reg:SI R3_REG) (mem:SI (plus:SI (match_dup 0) (const_int -20))))
8136 (set (reg:SI R4_REG) (mem:SI (plus:SI (match_dup 0) (const_int -16))))
8137 (set (reg:SI R5_REG) (mem:SI (plus:SI (match_dup 0) (const_int -12))))
8138 (set (reg:SI R6_REG) (mem:SI (plus:SI (match_dup 0) (const_int -8))))
8139 (set (reg:SI R7_REG) (mem:SI (plus:SI (match_dup 0) (const_int -4))))]
8140 "TARGET_SH2A && REGNO (operands[0]) == 15"
8141 "movml.l @r15+,r7"
8142 [(set_attr "in_delay_slot" "no")])
8143 \f
8144 ;; ------------------------------------------------------------------------
8145 ;; Scc instructions
8146 ;; ------------------------------------------------------------------------
8147
8148 (define_insn "movt"
8149 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8150 (match_operand:SI 1 "t_reg_operand"))]
8151 "TARGET_SH1"
8152 "movt %0"
8153 [(set_attr "type" "arith")])
8154
8155 (define_insn "movrt"
8156 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8157 (xor:SI (match_operand:SI 1 "t_reg_operand" "") (const_int 1)))]
8158 "TARGET_SH2A"
8159 "movrt %0"
8160 [(set_attr "type" "arith")])
8161
8162 (define_expand "cstoresi4"
8163 [(set (match_operand:SI 0 "register_operand")
8164 (match_operator:SI 1 "comparison_operator"
8165 [(match_operand:SI 2 "cmpsi_operand")
8166 (match_operand:SI 3 "arith_operand")]))]
8167 "TARGET_SH1"
8168 {
8169 if (sh_expand_t_scc (operands))
8170 DONE;
8171
8172 if (! currently_expanding_to_rtl)
8173 FAIL;
8174
8175 sh_emit_compare_and_set (operands, SImode);
8176 DONE;
8177 })
8178
8179 (define_expand "cstoredi4"
8180 [(set (match_operand:SI 0 "register_operand")
8181 (match_operator:SI 1 "comparison_operator"
8182 [(match_operand:DI 2 "arith_operand")
8183 (match_operand:DI 3 "arith_operand")]))]
8184 "TARGET_SH2"
8185 {
8186 if (sh_expand_t_scc (operands))
8187 DONE;
8188
8189 if (! currently_expanding_to_rtl)
8190 FAIL;
8191
8192 sh_emit_compare_and_set (operands, DImode);
8193 DONE;
8194 })
8195
8196 ;; Move the complement of the T reg to a reg.
8197 ;; On SH2A the movrt insn can be used.
8198 ;; On anything else than SH2A this has to be done with multiple instructions.
8199 ;; One obvious way would be:
8200 ;; cmp/eq ...
8201 ;; movt r0
8202 ;; xor #1,r0
8203 ;;
8204 ;; However, this puts pressure on r0 in most cases and thus the following is
8205 ;; more appealing:
8206 ;; cmp/eq ...
8207 ;; mov #-1,temp
8208 ;; negc temp,dest
8209 ;;
8210 ;; If the constant -1 can be CSE-ed or lifted out of a loop it effectively
8211 ;; becomes a one instruction operation. Moreover, care must be taken that
8212 ;; the insn can still be combined with inverted compare and branch code
8213 ;; around it. On the other hand, if a function returns the complement of
8214 ;; a previous comparison result in the T bit, the xor #1,r0 approach might
8215 ;; lead to better code.
8216 (define_expand "movnegt"
8217 [(set (match_operand:SI 0 "arith_reg_dest" "")
8218 (xor:SI (match_operand:SI 1 "t_reg_operand" "") (const_int 1)))]
8219 "TARGET_SH1"
8220 {
8221 if (TARGET_SH2A)
8222 emit_insn (gen_movrt (operands[0], operands[1]));
8223 else
8224 {
8225 rtx val = force_reg (SImode, gen_int_mode (-1, SImode));
8226 emit_insn (gen_movrt_negc (operands[0], operands[1], val));
8227 }
8228 DONE;
8229 })
8230
8231 (define_insn_and_split "movrt_negc"
8232 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8233 (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
8234 (set (reg:SI T_REG) (const_int 1))
8235 (use (match_operand:SI 2 "arith_reg_operand" "r"))]
8236 "TARGET_SH1"
8237 "negc %2,%0"
8238 "&& !sh_in_recog_treg_set_expr ()"
8239 [(const_int 0)]
8240 {
8241 if (sh_split_movrt_negc_to_movt_xor (curr_insn, operands))
8242 DONE;
8243 else
8244 FAIL;
8245 }
8246 [(set_attr "type" "arith")])
8247
8248 ;; The -1 constant will not be CSE-ed for the *movrt_negc pattern, but the
8249 ;; pattern can be used by the combine pass. Using a scratch reg for the
8250 ;; -1 constant results in slightly better register allocations compared to
8251 ;; generating a pseudo reg before reload.
8252 (define_insn_and_split "*movrt_negc"
8253 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8254 (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
8255 (clobber (match_scratch:SI 2 "=r"))
8256 (clobber (reg:SI T_REG))]
8257 "TARGET_SH1 && ! TARGET_SH2A"
8258 "#"
8259 "&& !sh_in_recog_treg_set_expr ()"
8260 [(const_int 0)]
8261 {
8262 if (sh_split_movrt_negc_to_movt_xor (curr_insn, operands))
8263 DONE;
8264 else if (reload_completed)
8265 {
8266 emit_move_insn (operands[2], gen_int_mode (-1, SImode));
8267 emit_insn (gen_movrt_negc (operands[0], operands[1], operands[2]));
8268 DONE;
8269 }
8270 else
8271 FAIL;
8272 })
8273
8274 ;; Store the negated T bit in a reg using r0 and xor. This one doesn't
8275 ;; clobber the T bit, which is useful when storing the T bit and the
8276 ;; negated T bit in parallel. On SH2A the movrt insn can be used for that.
8277 ;; Usually we don't want this insn to be matched, except for cases where the
8278 ;; T bit clobber is really not appreciated. Hence the extra use on T_REG.
8279 (define_insn_and_split "movrt_xor"
8280 [(set (match_operand:SI 0 "arith_reg_dest" "=z")
8281 (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
8282 (use (reg:SI T_REG))]
8283 "TARGET_SH1"
8284 "#"
8285 "&& reload_completed"
8286 [(set (match_dup 0) (reg:SI T_REG))
8287 (set (match_dup 0) (xor:SI (match_dup 0) (const_int 1)))])
8288
8289 ;; 0x7fffffff + T
8290 ;; 0x7fffffff + (1-T) = 0 - 0x80000000 - T
8291 ;;
8292 ;; Notice that 0 - 0x80000000 = 0x80000000.
8293
8294 ;; Single bit tests are usually done with zero_extract. On non-SH2A this
8295 ;; will use a tst-negc sequence. On SH2A it will use a bld-addc sequence.
8296 ;; The zeroth bit requires a special pattern, otherwise we get a shlr-addc.
8297 ;; This is a special case of the generic treg_set_expr pattern and thus has
8298 ;; to come first or it will never match.
8299 (define_insn_and_split "*mov_t_msb_neg"
8300 [(set (match_operand:SI 0 "arith_reg_dest")
8301 (plus:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
8302 (const_int 1))
8303 (const_int 2147483647)))
8304 (clobber (reg:SI T_REG))]
8305 "TARGET_SH1"
8306 "#"
8307 "&& can_create_pseudo_p ()"
8308 [(parallel [(set (match_dup 0)
8309 (plus:SI (zero_extract:SI (match_dup 1)
8310 (const_int 1) (const_int 0))
8311 (const_int 2147483647)))
8312 (clobber (reg:SI T_REG))])])
8313
8314 (define_insn_and_split "*mov_t_msb_neg"
8315 [(set (match_operand:SI 0 "arith_reg_dest")
8316 (plus:SI (match_operand 1 "treg_set_expr")
8317 (const_int 2147483647))) ;; 0x7fffffff
8318 (clobber (reg:SI T_REG))]
8319 "TARGET_SH1"
8320 "#"
8321 "&& can_create_pseudo_p ()"
8322 [(const_int 0)]
8323 {
8324 if (negt_reg_operand (operands[1], VOIDmode))
8325 {
8326 emit_insn (gen_negc (operands[0],
8327 force_reg (SImode, GEN_INT (-2147483648LL))));
8328 DONE;
8329 }
8330
8331 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8332 if (ti.remove_trailing_nott ())
8333 emit_insn (gen_negc (operands[0],
8334 force_reg (SImode, GEN_INT (-2147483648LL))));
8335 else
8336 emit_insn (gen_addc (operands[0],
8337 force_reg (SImode, const0_rtx),
8338 force_reg (SImode, GEN_INT (2147483647))));
8339 DONE;
8340 })
8341
8342 (define_insn_and_split "*mov_t_msb_neg"
8343 [(set (match_operand:SI 0 "arith_reg_dest")
8344 (if_then_else:SI (match_operand 1 "treg_set_expr")
8345 (match_operand 2 "const_int_operand")
8346 (match_operand 3 "const_int_operand")))
8347 (clobber (reg:SI T_REG))]
8348 "TARGET_SH1 && can_create_pseudo_p ()
8349 && ((INTVAL (operands[2]) == -2147483648LL
8350 && INTVAL (operands[3]) == 2147483647LL)
8351 || (INTVAL (operands[2]) == 2147483647LL
8352 && INTVAL (operands[3]) == -2147483648LL))"
8353 "#"
8354 "&& 1"
8355 [(const_int 0)]
8356 {
8357 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8358
8359 if (INTVAL (operands[2]) == -2147483648LL)
8360 {
8361 if (ti.remove_trailing_nott ())
8362 emit_insn (gen_negc (operands[0],
8363 force_reg (SImode, GEN_INT (-2147483648LL))));
8364 else
8365 emit_insn (gen_addc (operands[0],
8366 force_reg (SImode, const0_rtx),
8367 force_reg (SImode, operands[3])));
8368 DONE;
8369 }
8370 else if (INTVAL (operands[2]) == 2147483647LL)
8371 {
8372 if (ti.remove_trailing_nott ())
8373 emit_insn (gen_addc (operands[0],
8374 force_reg (SImode, const0_rtx),
8375 force_reg (SImode, GEN_INT (2147483647LL))));
8376 else
8377 emit_insn (gen_negc (operands[0],
8378 force_reg (SImode, GEN_INT (-2147483648LL))));
8379 DONE;
8380 }
8381 else
8382 gcc_unreachable ();
8383 })
8384
8385 ;; Store (negated) T bit as all zeros or ones in a reg.
8386 ;; subc Rn,Rn ! Rn = Rn - Rn - T; T = T
8387 ;; not Rn,Rn ! Rn = 0 - Rn
8388 (define_insn_and_split "mov_neg_si_t"
8389 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8390 (neg:SI (match_operand 1 "treg_set_expr")))]
8391 "TARGET_SH1"
8392 {
8393 gcc_assert (t_reg_operand (operands[1], VOIDmode));
8394 return "subc %0,%0";
8395 }
8396 "&& can_create_pseudo_p () && !t_reg_operand (operands[1], VOIDmode)"
8397 [(const_int 0)]
8398 {
8399 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8400 emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
8401
8402 if (ti.remove_trailing_nott ())
8403 emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
8404
8405 DONE;
8406 }
8407 [(set_attr "type" "arith")])
8408
8409 ;; Invert the T bit.
8410 ;; On SH2A we can use the nott insn. On anything else this must be done with
8411 ;; multiple insns like:
8412 ;; movt Rn
8413 ;; tst Rn,Rn
8414 ;; This requires an additional pseudo. The SH specific sh_treg_combine RTL
8415 ;; pass will look for this insn. Disallow using it if pseudos can't be
8416 ;; created.
8417 ;; Don't split the nott inside the splitting of a treg_set_expr, or else
8418 ;; surrounding insns might not see and recombine it. Defer the splitting
8419 ;; of the nott until after the whole insn containing the treg_set_expr
8420 ;; has been split.
8421 (define_insn_and_split "nott"
8422 [(set (reg:SI T_REG)
8423 (xor:SI (match_operand:SI 0 "t_reg_operand") (const_int 1)))]
8424 "TARGET_SH2A || (TARGET_SH1 && can_create_pseudo_p ())"
8425 {
8426 gcc_assert (TARGET_SH2A);
8427 return "nott";
8428 }
8429 "!TARGET_SH2A && can_create_pseudo_p () && !sh_in_recog_treg_set_expr ()"
8430 [(set (match_dup 0) (reg:SI T_REG))
8431 (set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))]
8432 {
8433 operands[0] = gen_reg_rtx (SImode);
8434 })
8435
8436 ;; Store T bit as MSB in a reg.
8437 ;; T = 0: 0x00000000 -> reg
8438 ;; T = 1: 0x80000000 -> reg
8439 (define_insn_and_split "*movt_msb"
8440 [(set (match_operand:SI 0 "arith_reg_dest")
8441 (mult:SI (match_operand:SI 1 "t_reg_operand")
8442 (const_int -2147483648))) ;; 0xffffffff80000000
8443 (clobber (reg:SI T_REG))]
8444 "TARGET_SH1"
8445 "#"
8446 "&& 1"
8447 [(set (match_dup 0) (ashift:SI (reg:SI T_REG) (const_int 31)))])
8448
8449 ;; Store inverted T bit as MSB in a reg.
8450 ;; T = 0: 0x80000000 -> reg
8451 ;; T = 1: 0x00000000 -> reg
8452 ;; On SH2A we can get away without clobbering the T_REG using the movrt insn.
8453 ;; On non SH2A we resort to the following sequence:
8454 ;; movt Rn
8455 ;; tst Rn,Rn
8456 ;; rotcr Rn
8457 ;; The T bit value will be modified during the sequence, but the rotcr insn
8458 ;; will restore its original value.
8459 (define_insn_and_split "*negt_msb"
8460 [(set (match_operand:SI 0 "arith_reg_dest")
8461 (match_operand:SI 1 "negt_reg_shl31_operand"))]
8462 "TARGET_SH1"
8463 "#"
8464 "&& can_create_pseudo_p ()"
8465 [(const_int 0)]
8466 {
8467 rtx tmp = gen_reg_rtx (SImode);
8468
8469 if (TARGET_SH2A)
8470 {
8471 emit_insn (gen_movrt (tmp, get_t_reg_rtx ()));
8472 emit_insn (gen_rotrsi3 (operands[0], tmp, const1_rtx));
8473 }
8474 else
8475 {
8476 emit_move_insn (tmp, get_t_reg_rtx ());
8477 emit_insn (gen_cmpeqsi_t (tmp, const0_rtx));
8478 emit_insn (gen_rotcr (operands[0], tmp, get_t_reg_rtx ()));
8479 }
8480 DONE;
8481 })
8482
8483 ;; The *cset_zero patterns convert optimizations such as
8484 ;; "if (test) x = 0;"
8485 ;; to
8486 ;; "x &= -(test == 0);"
8487 ;; back to conditional branch sequences if zero-displacement branches
8488 ;; are enabled.
8489 ;; FIXME: These patterns can be removed when conditional execution patterns
8490 ;; are implemented, since ifcvt will not perform these optimizations if
8491 ;; conditional execution is supported.
8492 (define_insn "*cset_zero"
8493 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8494 (and:SI (plus:SI (match_operand:SI 1 "t_reg_operand")
8495 (const_int -1))
8496 (match_operand:SI 2 "arith_reg_operand" "0")))]
8497 "TARGET_SH1 && TARGET_ZDCBRANCH"
8498 {
8499 return "bf 0f" "\n"
8500 " mov #0,%0" "\n"
8501 "0:";
8502 }
8503 [(set_attr "type" "arith") ;; poor approximation
8504 (set_attr "length" "4")])
8505
8506 (define_insn "*cset_zero"
8507 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8508 (if_then_else:SI (match_operand:SI 1 "cbranch_treg_value")
8509 (match_operand:SI 2 "arith_reg_operand" "0")
8510 (const_int 0)))]
8511 "TARGET_SH1 && TARGET_ZDCBRANCH"
8512 {
8513 int tval = sh_eval_treg_value (operands[1]);
8514 if (tval == true)
8515 return "bt 0f" "\n"
8516 " mov #0,%0" "\n"
8517 "0:";
8518 else if (tval == false)
8519 return "bf 0f" "\n"
8520 " mov #0,%0" "\n"
8521 "0:";
8522 else
8523 gcc_unreachable ();
8524 }
8525 [(set_attr "type" "arith") ;; poor approximation
8526 (set_attr "length" "4")])
8527
8528 (define_insn_and_split "*cset_zero"
8529 [(set (match_operand:SI 0 "arith_reg_dest")
8530 (if_then_else:SI (match_operand 1 "treg_set_expr_not_const01")
8531 (match_dup 0) (const_int 0)))
8532 (clobber (reg:SI T_REG))]
8533 "TARGET_SH1 && TARGET_ZDCBRANCH && can_create_pseudo_p ()"
8534 "#"
8535 "&& 1"
8536 [(set (match_dup 0)
8537 (if_then_else:SI (match_dup 1) (match_dup 0) (const_int 0)))]
8538 {
8539 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8540 if (ti.remove_trailing_nott ())
8541 operands[1] = gen_rtx_EQ (SImode, get_t_reg_rtx (), const0_rtx);
8542 else
8543 operands[1] = gen_rtx_EQ (SImode, get_t_reg_rtx (), const1_rtx);
8544 })
8545
8546 (define_expand "cstoresf4"
8547 [(set (match_operand:SI 0 "register_operand")
8548 (match_operator:SI 1 "ordered_comparison_operator"
8549 [(match_operand:SF 2 "arith_operand")
8550 (match_operand:SF 3 "arith_operand")]))]
8551 "TARGET_SH2E"
8552 {
8553 if (! currently_expanding_to_rtl)
8554 FAIL;
8555
8556 sh_emit_compare_and_set (operands, SFmode);
8557 DONE;
8558 })
8559
8560 (define_expand "cstoredf4"
8561 [(set (match_operand:SI 0 "register_operand")
8562 (match_operator:SI 1 "ordered_comparison_operator"
8563 [(match_operand:DF 2 "arith_operand")
8564 (match_operand:DF 3 "arith_operand")]))]
8565 "TARGET_FPU_DOUBLE"
8566 {
8567 if (! currently_expanding_to_rtl)
8568 FAIL;
8569
8570 sh_emit_compare_and_set (operands, DFmode);
8571 DONE;
8572 })
8573
8574 ;; Sometimes the T bit result of insns is needed in normal registers.
8575 ;; Instead of open coding all the pattern variations, use the treg_set_expr
8576 ;; predicate to match any T bit output insn and split it out after.
8577 ;; This pattern should be below all other related patterns so that it is
8578 ;; considered as a last resort option during matching. This allows
8579 ;; overriding it with special case patterns.
8580 (define_insn_and_split "any_treg_expr_to_reg"
8581 [(set (match_operand:SI 0 "arith_reg_dest")
8582 (match_operand 1 "treg_set_expr"))
8583 (clobber (reg:SI T_REG))]
8584 "TARGET_SH1 && can_create_pseudo_p ()"
8585 "#"
8586 "&& !sh_in_recog_treg_set_expr ()"
8587 [(const_int 0)]
8588 {
8589 if (dump_file)
8590 fprintf (dump_file, "splitting any_treg_expr_to_reg\n");
8591
8592 if (t_reg_operand (operands[1], VOIDmode))
8593 {
8594 if (dump_file)
8595 fprintf (dump_file, "t_reg_operand: emitting movt\n");
8596 emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
8597 DONE;
8598 }
8599 if (negt_reg_operand (operands[1], VOIDmode))
8600 {
8601 if (dump_file)
8602 fprintf (dump_file, "negt_reg_operand: emitting movrt\n");
8603 emit_insn (gen_movnegt (operands[0], get_t_reg_rtx ()));
8604 DONE;
8605 }
8606
8607 /* If the split out insns ended with a nott, emit a movrt sequence,
8608 otherwise a normal movt. */
8609 sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
8610 rtx_insn* i = NULL;
8611 if (ti.remove_trailing_nott ())
8612 {
8613 /* Emit this same insn_and_split again. However, the next time it
8614 is split, it will emit the actual negc/movrt insn. This gives
8615 other surrounding insns the chance to see the trailing movrt. */
8616 if (dump_file)
8617 fprintf (dump_file,
8618 "any_treg_expr_to_reg: replacing trailing nott with movrt\n");
8619 i = emit_insn (gen_any_treg_expr_to_reg (
8620 operands[0], gen_rtx_XOR (SImode, get_t_reg_rtx (),
8621 const1_rtx)));
8622 }
8623 else
8624 {
8625 i = emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
8626 if (dump_file)
8627 fprintf (dump_file, "any_treg_expr_to_reg: appending movt\n");
8628 }
8629
8630 add_reg_note (i, REG_UNUSED, get_t_reg_rtx ());
8631 DONE;
8632 })
8633
8634 ;; -------------------------------------------------------------------------
8635 ;; Instructions to cope with inline literal tables
8636 ;; -------------------------------------------------------------------------
8637
8638 ;; 2 byte integer in line
8639 (define_insn "consttable_2"
8640 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
8641 (match_operand 1 "" "")]
8642 UNSPECV_CONST2)]
8643 ""
8644 {
8645 if (operands[1] != const0_rtx)
8646 assemble_integer (operands[0], 2, BITS_PER_UNIT * 2, 1);
8647 return "";
8648 }
8649 [(set_attr "length" "2")
8650 (set_attr "in_delay_slot" "no")])
8651
8652 ;; 4 byte integer in line
8653 (define_insn "consttable_4"
8654 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
8655 (match_operand 1 "" "")]
8656 UNSPECV_CONST4)]
8657 ""
8658 {
8659 if (operands[1] != const0_rtx)
8660 {
8661 assemble_integer (operands[0], 4, BITS_PER_UNIT * 4, 1);
8662 mark_symbol_refs_as_used (operands[0]);
8663 }
8664 return "";
8665 }
8666 [(set_attr "length" "4")
8667 (set_attr "in_delay_slot" "no")])
8668
8669 ;; 8 byte integer in line
8670 (define_insn "consttable_8"
8671 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
8672 (match_operand 1 "" "")]
8673 UNSPECV_CONST8)]
8674 ""
8675 {
8676 if (operands[1] != const0_rtx)
8677 assemble_integer (operands[0], 8, BITS_PER_UNIT * 8, 1);
8678 return "";
8679 }
8680 [(set_attr "length" "8")
8681 (set_attr "in_delay_slot" "no")])
8682
8683 ;; 4 byte floating point
8684 (define_insn "consttable_sf"
8685 [(unspec_volatile [(match_operand:SF 0 "general_operand" "=g")
8686 (match_operand 1 "" "")]
8687 UNSPECV_CONST4)]
8688 ""
8689 {
8690 if (operands[1] != const0_rtx)
8691 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
8692 SFmode, GET_MODE_ALIGNMENT (SFmode));
8693 return "";
8694 }
8695 [(set_attr "length" "4")
8696 (set_attr "in_delay_slot" "no")])
8697
8698 ;; 8 byte floating point
8699 (define_insn "consttable_df"
8700 [(unspec_volatile [(match_operand:DF 0 "general_operand" "=g")
8701 (match_operand 1 "" "")]
8702 UNSPECV_CONST8)]
8703 ""
8704 {
8705 if (operands[1] != const0_rtx)
8706 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
8707 DFmode, GET_MODE_ALIGNMENT (DFmode));
8708 return "";
8709 }
8710 [(set_attr "length" "8")
8711 (set_attr "in_delay_slot" "no")])
8712
8713 ;; Alignment is needed for some constant tables; it may also be added for
8714 ;; Instructions at the start of loops, or after unconditional branches.
8715 ;; ??? We would get more accurate lengths if we did instruction
8716 ;; alignment based on the value of INSN_CURRENT_ADDRESS; the approach used
8717 ;; here is too conservative.
8718
8719 ;; align to a two byte boundary
8720 (define_expand "align_2"
8721 [(unspec_volatile [(const_int 1)] UNSPECV_ALIGN)]
8722 ""
8723 "")
8724
8725 ;; Align to a four byte boundary.
8726 ;; align_4 and align_log are instructions for the starts of loops, or
8727 ;; after unconditional branches, which may take up extra room.
8728 (define_expand "align_4"
8729 [(unspec_volatile [(const_int 2)] UNSPECV_ALIGN)]
8730 ""
8731 "")
8732
8733 ;; Align to a cache line boundary.
8734 (define_insn "align_log"
8735 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPECV_ALIGN)]
8736 ""
8737 ""
8738 [(set_attr "length" "0")
8739 (set_attr "in_delay_slot" "no")])
8740
8741 ;; Emitted at the end of the literal table, used to emit the
8742 ;; 32bit branch labels if needed.
8743 (define_insn "consttable_end"
8744 [(unspec_volatile [(const_int 0)] UNSPECV_CONST_END)]
8745 ""
8746 {
8747 return output_jump_label_table ();
8748 }
8749 [(set_attr "in_delay_slot" "no")])
8750
8751 ;; Emitted at the end of the window in the literal table.
8752 (define_insn "consttable_window_end"
8753 [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_WINDOW_END)]
8754 ""
8755 ""
8756 [(set_attr "length" "0")
8757 (set_attr "in_delay_slot" "no")])
8758
8759 ;; -------------------------------------------------------------------------
8760 ;; Minimum / maximum operations.
8761 ;; -------------------------------------------------------------------------
8762
8763 ;; The SH2A clips.b and clips.w insns do a signed min-max function. If smin
8764 ;; and smax standard name patterns are defined, they will be used during
8765 ;; initial expansion and combine will then be able to form the actual min-max
8766 ;; pattern.
8767 ;; The clips.b and clips.w set the SR.CS bit if the value in the register is
8768 ;; clipped, but there is currently no way of making use of this information.
8769 ;; The only way to read or reset the SR.CS bit is by accessing the SR.
8770 (define_expand "<code>si3"
8771 [(parallel [(set (match_operand:SI 0 "arith_reg_dest")
8772 (SMIN_SMAX:SI (match_operand:SI 1 "arith_reg_operand")
8773 (match_operand 2 "const_int_operand")))
8774 (clobber (reg:SI T_REG))])]
8775 "TARGET_SH2A"
8776 {
8777 /* Force the comparison value into a register, because greater-than
8778 comparisons can work only on registers. Combine will be able to pick up
8779 the constant value from the REG_EQUAL note when trying to form a min-max
8780 pattern. */
8781 operands[2] = force_reg (SImode, operands[2]);
8782 })
8783
8784 ;; Convert
8785 ;; smax (smin (...))
8786 ;; to
8787 ;; smin (smax (...))
8788 (define_insn_and_split "*clips"
8789 [(set (match_operand:SI 0 "arith_reg_dest")
8790 (smax:SI (smin:SI (match_operand:SI 1 "arith_reg_operand")
8791 (match_operand 2 "clips_max_const_int"))
8792 (match_operand 3 "clips_min_const_int")))]
8793 "TARGET_SH2A"
8794 "#"
8795 "&& 1"
8796 [(set (match_dup 0)
8797 (smin:SI (smax:SI (match_dup 1) (match_dup 3)) (match_dup 2)))])
8798
8799 (define_insn "*clips"
8800 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8801 (smin:SI (smax:SI (match_operand:SI 1 "arith_reg_operand" "0")
8802 (match_operand 2 "clips_min_const_int"))
8803 (match_operand 3 "clips_max_const_int")))]
8804 "TARGET_SH2A"
8805 {
8806 if (INTVAL (operands[3]) == 127)
8807 return "clips.b %0";
8808 else if (INTVAL (operands[3]) == 32767)
8809 return "clips.w %0";
8810 else
8811 gcc_unreachable ();
8812 }
8813 [(set_attr "type" "arith")])
8814
8815 ;; If the expanded smin or smax patterns were not combined, split them into
8816 ;; a compare and branch sequence, because there are no real smin or smax
8817 ;; insns.
8818 (define_insn_and_split "*<code>si3"
8819 [(set (match_operand:SI 0 "arith_reg_dest")
8820 (SMIN_SMAX:SI (match_operand:SI 1 "arith_reg_operand")
8821 (match_operand:SI 2 "arith_reg_or_0_or_1_operand")))
8822 (clobber (reg:SI T_REG))]
8823 "TARGET_SH2A && can_create_pseudo_p ()"
8824 "#"
8825 "&& 1"
8826 [(const_int 0)]
8827 {
8828 rtx_code_label *skip_label = gen_label_rtx ();
8829 emit_move_insn (operands[0], operands[1]);
8830
8831 rtx cmp_val = operands[2];
8832 if (satisfies_constraint_M (cmp_val))
8833 cmp_val = const0_rtx;
8834
8835 emit_insn (gen_cmpgtsi_t (operands[0], cmp_val));
8836 emit_jump_insn (<CODE> == SMIN
8837 ? gen_branch_false (skip_label)
8838 : gen_branch_true (skip_label));
8839
8840 emit_label_after (skip_label, emit_move_insn (operands[0], operands[2]));
8841 DONE;
8842 })
8843
8844 ;; The SH2A clipu.b and clipu.w insns can be used to implement a min function
8845 ;; with a register and a constant.
8846 ;; The clipu.b and clipu.w set the SR.CS bit if the value in the register is
8847 ;; clipped, but there is currently no way of making use of this information.
8848 ;; The only way to read or reset the SR.CS bit is by accessing the SR.
8849 (define_expand "uminsi3"
8850 [(set (match_operand:SI 0 "arith_reg_dest")
8851 (umin:SI (match_operand:SI 1 "arith_reg_operand")
8852 (match_operand 2 "const_int_operand")))]
8853 "TARGET_SH2A"
8854 {
8855 if (INTVAL (operands[2]) == 1)
8856 {
8857 emit_insn (gen_clipu_one (operands[0], operands[1]));
8858 DONE;
8859 }
8860 else if (! clipu_max_const_int (operands[2], VOIDmode))
8861 FAIL;
8862 })
8863
8864 (define_insn "*clipu"
8865 [(set (match_operand:SI 0 "arith_reg_dest" "=r")
8866 (umin:SI (match_operand:SI 1 "arith_reg_operand" "0")
8867 (match_operand 2 "clipu_max_const_int")))]
8868 "TARGET_SH2A"
8869 {
8870 if (INTVAL (operands[2]) == 255)
8871 return "clipu.b %0";
8872 else if (INTVAL (operands[2]) == 65535)
8873 return "clipu.w %0";
8874 else
8875 gcc_unreachable ();
8876 }
8877 [(set_attr "type" "arith")])
8878
8879 (define_insn_and_split "clipu_one"
8880 [(set (match_operand:SI 0 "arith_reg_dest")
8881 (umin:SI (match_operand:SI 1 "arith_reg_operand") (const_int 1)))
8882 (clobber (reg:SI T_REG))]
8883 "TARGET_SH2A"
8884 "#"
8885 "&& can_create_pseudo_p ()"
8886 [(const_int 0)]
8887 {
8888 emit_insn (gen_cmpeqsi_t (operands[1], const0_rtx));
8889 emit_insn (gen_movnegt (operands[0], get_t_reg_rtx ()));
8890 DONE;
8891 })
8892
8893 ;; -------------------------------------------------------------------------
8894 ;; Misc
8895 ;; -------------------------------------------------------------------------
8896
8897 ;; String/block move insn.
8898
8899 (define_expand "movmemsi"
8900 [(parallel [(set (mem:BLK (match_operand:BLK 0))
8901 (mem:BLK (match_operand:BLK 1)))
8902 (use (match_operand:SI 2 "nonmemory_operand"))
8903 (use (match_operand:SI 3 "immediate_operand"))
8904 (clobber (reg:SI PR_REG))
8905 (clobber (reg:SI R4_REG))
8906 (clobber (reg:SI R5_REG))
8907 (clobber (reg:SI R0_REG))])]
8908 "TARGET_SH1"
8909 {
8910 if (expand_block_move (operands))
8911 DONE;
8912 else
8913 FAIL;
8914 })
8915
8916 (define_insn "block_move_real"
8917 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8918 (mem:BLK (reg:SI R5_REG)))
8919 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8920 (use (match_operand 1 "" "Z,Ccl"))
8921 (clobber (reg:SI PR_REG))
8922 (clobber (reg:SI R0_REG))])]
8923 "TARGET_SH1 && ! TARGET_HARD_SH4"
8924 "@
8925 jsr @%0%#
8926 bsrf %0\n%O1:%#"
8927 [(set_attr "type" "sfunc")
8928 (set_attr "needs_delay_slot" "yes")])
8929
8930 (define_insn "block_lump_real"
8931 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8932 (mem:BLK (reg:SI R5_REG)))
8933 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8934 (use (match_operand 1 "" "Z,Ccl"))
8935 (use (reg:SI R6_REG))
8936 (clobber (reg:SI PR_REG))
8937 (clobber (reg:SI T_REG))
8938 (clobber (reg:SI R4_REG))
8939 (clobber (reg:SI R5_REG))
8940 (clobber (reg:SI R6_REG))
8941 (clobber (reg:SI R0_REG))])]
8942 "TARGET_SH1 && ! TARGET_HARD_SH4"
8943 "@
8944 jsr @%0%#
8945 bsrf %0\n%O1:%#"
8946 [(set_attr "type" "sfunc")
8947 (set_attr "needs_delay_slot" "yes")])
8948
8949 (define_insn "block_move_real_i4"
8950 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8951 (mem:BLK (reg:SI R5_REG)))
8952 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8953 (use (match_operand 1 "" "Z,Ccl"))
8954 (clobber (reg:SI PR_REG))
8955 (clobber (reg:SI R0_REG))
8956 (clobber (reg:SI R1_REG))
8957 (clobber (reg:SI R2_REG))])]
8958 "TARGET_HARD_SH4"
8959 "@
8960 jsr @%0%#
8961 bsrf %0\n%O1:%#"
8962 [(set_attr "type" "sfunc")
8963 (set_attr "needs_delay_slot" "yes")])
8964
8965 (define_insn "block_lump_real_i4"
8966 [(parallel [(set (mem:BLK (reg:SI R4_REG))
8967 (mem:BLK (reg:SI R5_REG)))
8968 (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
8969 (use (match_operand 1 "" "Z,Ccl"))
8970 (use (reg:SI R6_REG))
8971 (clobber (reg:SI PR_REG))
8972 (clobber (reg:SI T_REG))
8973 (clobber (reg:SI R4_REG))
8974 (clobber (reg:SI R5_REG))
8975 (clobber (reg:SI R6_REG))
8976 (clobber (reg:SI R0_REG))
8977 (clobber (reg:SI R1_REG))
8978 (clobber (reg:SI R2_REG))
8979 (clobber (reg:SI R3_REG))])]
8980 "TARGET_HARD_SH4"
8981 "@
8982 jsr @%0%#
8983 bsrf %0\n%O1:%#"
8984 [(set_attr "type" "sfunc")
8985 (set_attr "needs_delay_slot" "yes")])
8986
8987 ;; byte compare pattern
8988 ;; temp = a ^ b;
8989 ;; !((temp & 0xF000) && (temp & 0x0F00) && (temp & 0x00F0) && (temp & 0x000F))
8990 (define_insn "cmpstr_t"
8991 [(set (reg:SI T_REG)
8992 (eq:SI (and:SI
8993 (and:SI
8994 (and:SI
8995 (zero_extract:SI
8996 (xor:SI (match_operand:SI 0 "arith_reg_operand" "r")
8997 (match_operand:SI 1 "arith_reg_operand" "r"))
8998 (const_int 8) (const_int 0))
8999 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
9000 (const_int 8) (const_int 8)))
9001 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
9002 (const_int 8) (const_int 16)))
9003 (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
9004 (const_int 8) (const_int 24)))
9005 (const_int 0)))]
9006 "TARGET_SH1"
9007 "cmp/str %0,%1"
9008 [(set_attr "type" "mt_group")])
9009
9010 (define_expand "cmpstrsi"
9011 [(set (match_operand:SI 0 "register_operand")
9012 (compare:SI (match_operand:BLK 1 "memory_operand")
9013 (match_operand:BLK 2 "memory_operand")))
9014 (use (match_operand 3 "immediate_operand"))]
9015 "TARGET_SH1 && optimize"
9016 {
9017 if (! optimize_insn_for_size_p () && sh_expand_cmpstr (operands))
9018 DONE;
9019 else
9020 FAIL;
9021 })
9022
9023 (define_expand "cmpstrnsi"
9024 [(set (match_operand:SI 0 "register_operand")
9025 (compare:SI (match_operand:BLK 1 "memory_operand")
9026 (match_operand:BLK 2 "memory_operand")))
9027 (use (match_operand:SI 3 "nonmemory_operand"))
9028 (use (match_operand:SI 4 "immediate_operand"))]
9029 "TARGET_SH1 && optimize"
9030 {
9031 if (! optimize_insn_for_size_p () && sh_expand_cmpnstr (operands))
9032 DONE;
9033 else
9034 FAIL;
9035 })
9036
9037 (define_expand "strlensi"
9038 [(set (match_operand:SI 0 "register_operand")
9039 (unspec:SI [(match_operand:BLK 1 "memory_operand")
9040 (match_operand:SI 2 "immediate_operand")
9041 (match_operand:SI 3 "immediate_operand")]
9042 UNSPEC_BUILTIN_STRLEN))]
9043 "TARGET_SH1 && optimize"
9044 {
9045 if (! optimize_insn_for_size_p () && sh_expand_strlen (operands))
9046 DONE;
9047 else
9048 FAIL;
9049 })
9050
9051 (define_expand "setmemqi"
9052 [(parallel [(set (match_operand:BLK 0 "memory_operand")
9053 (match_operand 2 "const_int_operand"))
9054 (use (match_operand:QI 1 "const_int_operand"))
9055 (use (match_operand:QI 3 "const_int_operand"))])]
9056 "TARGET_SH1 && optimize"
9057 {
9058 if (optimize_insn_for_size_p ())
9059 FAIL;
9060
9061 sh_expand_setmem (operands);
9062 DONE;
9063 })
9064
9065 \f
9066 ;; -------------------------------------------------------------------------
9067 ;; Floating point instructions.
9068 ;; -------------------------------------------------------------------------
9069
9070 ;; FIXME: For now we disallow any memory operands for fpscr loads/stores,
9071 ;; except for post-inc loads and pre-dec stores for push/pop purposes.
9072 ;; This avoids problems with reload. As a consequence, user initiated fpscr
9073 ;; stores to memory will always be ferried through a general register.
9074 ;; User initiated fpscr loads always have to undergo bit masking to preserve
9075 ;; the current fpu mode settings for the compiler generated code. Thus such
9076 ;; fpscr loads will always have to go through general registers anyways.
9077 (define_insn "lds_fpscr"
9078 [(set (reg:SI FPSCR_REG)
9079 (match_operand:SI 0 "fpscr_movsrc_operand" "r,>"))
9080 (set (reg:SI FPSCR_STAT_REG)
9081 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_STAT))
9082 (set (reg:SI FPSCR_MODES_REG)
9083 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
9084 "TARGET_FPU_ANY"
9085 "@
9086 lds %0,fpscr
9087 lds.l %0,fpscr"
9088 [(set_attr "type" "gp_fpscr,mem_fpscr")])
9089
9090 ;; A move fpscr -> reg schedules like a move mac -> reg. Thus we use mac_gp
9091 ;; type for it.
9092 (define_insn "sts_fpscr"
9093 [(set (match_operand:SI 0 "fpscr_movdst_operand" "=r,<")
9094 (reg:SI FPSCR_REG))
9095 (use (reg:SI FPSCR_STAT_REG))
9096 (use (reg:SI FPSCR_MODES_REG))]
9097 "TARGET_FPU_ANY"
9098 "@
9099 sts fpscr,%0
9100 sts.l fpscr,%0"
9101 [(set_attr "type" "mac_gp,fstore")])
9102
9103 (define_expand "set_fpscr"
9104 [(parallel [(set (reg:SI FPSCR_REG)
9105 (match_operand:SI 0 "general_operand"))
9106 (set (reg:SI FPSCR_STAT_REG)
9107 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))])]
9108 "TARGET_FPU_ANY"
9109 {
9110 /* We have to mask out the FR, SZ and PR bits. To do that, we need to
9111 get the current FPSCR value first.
9112 (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask) */
9113
9114 rtx mask = force_reg (SImode, GEN_INT (FPSCR_FR | FPSCR_SZ | FPSCR_PR));
9115
9116 rtx a = force_reg (SImode, operands[0]);
9117
9118 rtx b = gen_reg_rtx (SImode);
9119 emit_insn (gen_sts_fpscr (b));
9120
9121 rtx a_xor_b = gen_reg_rtx (SImode);
9122 emit_insn (gen_xorsi3 (a_xor_b, a, b));
9123
9124 rtx a_xor_b_and_mask = gen_reg_rtx (SImode);
9125 emit_insn (gen_andsi3 (a_xor_b_and_mask, a_xor_b, mask));
9126
9127 rtx r = gen_reg_rtx (SImode);
9128 emit_insn (gen_xorsi3 (r, a_xor_b_and_mask, a));
9129 emit_insn (gen_lds_fpscr (r));
9130
9131 DONE;
9132 })
9133
9134 ;; ??? This uses the fp unit, but has no type indicating that.
9135 ;; If we did that, this would either give a bogus latency or introduce
9136 ;; a bogus FIFO constraint.
9137 ;; Since this insn is currently only used for prologues/epilogues,
9138 ;; it is probably best to claim no function unit, which matches the
9139 ;; current setting.
9140 (define_insn "toggle_sz"
9141 [(set (reg:SI FPSCR_REG)
9142 (xor:SI (reg:SI FPSCR_REG) (const_int FPSCR_SZ)))
9143 (set (reg:SI FPSCR_MODES_REG)
9144 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
9145 "TARGET_FPU_DOUBLE"
9146 "fschg"
9147 [(set_attr "type" "fpscr_toggle") (set_attr "fp_set" "unknown")])
9148
9149 ;; Toggle FPU precision PR mode.
9150
9151 (define_insn "toggle_pr"
9152 [(set (reg:SI FPSCR_REG)
9153 (xor:SI (reg:SI FPSCR_REG) (const_int FPSCR_PR)))
9154 (set (reg:SI FPSCR_MODES_REG)
9155 (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
9156 "TARGET_SH4A_FP"
9157 "fpchg"
9158 [(set_attr "type" "fpscr_toggle")])
9159
9160 (define_expand "addsf3"
9161 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9162 (plus:SF (match_operand:SF 1 "fp_arith_reg_operand")
9163 (match_operand:SF 2 "fp_arith_reg_operand")))]
9164 "TARGET_SH2E"
9165 {
9166 emit_insn (gen_addsf3_i (operands[0], operands[1], operands[2]));
9167 DONE;
9168 })
9169
9170 (define_insn "addsf3_i"
9171 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9172 (plus:SF (match_operand:SF 1 "fp_arith_reg_operand" "%0")
9173 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9174 (clobber (reg:SI FPSCR_STAT_REG))
9175 (use (reg:SI FPSCR_MODES_REG))]
9176 "TARGET_SH2E"
9177 "fadd %2,%0"
9178 [(set_attr "type" "fp")
9179 (set_attr "fp_mode" "single")])
9180
9181 (define_expand "subsf3"
9182 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9183 (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "")
9184 (match_operand:SF 2 "fp_arith_reg_operand" "")))]
9185 "TARGET_SH2E"
9186 {
9187 emit_insn (gen_subsf3_i (operands[0], operands[1], operands[2]));
9188 DONE;
9189 })
9190
9191 (define_insn "subsf3_i"
9192 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9193 (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
9194 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9195 (clobber (reg:SI FPSCR_STAT_REG))
9196 (use (reg:SI FPSCR_MODES_REG))]
9197 "TARGET_SH2E"
9198 "fsub %2,%0"
9199 [(set_attr "type" "fp")
9200 (set_attr "fp_mode" "single")])
9201
9202 (define_expand "mulsf3"
9203 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9204 (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "")
9205 (match_operand:SF 2 "fp_arith_reg_operand" "")))]
9206 "TARGET_SH2E"
9207 {
9208 emit_insn (gen_mulsf3_i (operands[0], operands[1], operands[2]));
9209 DONE;
9210 })
9211
9212 (define_insn "mulsf3_i"
9213 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9214 (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%0")
9215 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9216 (clobber (reg:SI FPSCR_STAT_REG))
9217 (use (reg:SI FPSCR_MODES_REG))]
9218 "TARGET_SH2E"
9219 "fmul %2,%0"
9220 [(set_attr "type" "fp")
9221 (set_attr "fp_mode" "single")])
9222
9223 ;; FMA (fused multiply-add) patterns
9224 (define_expand "fmasf4"
9225 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9226 (fma:SF (match_operand:SF 1 "fp_arith_reg_operand")
9227 (match_operand:SF 2 "fp_arith_reg_operand")
9228 (match_operand:SF 3 "fp_arith_reg_operand")))]
9229 "TARGET_SH2E"
9230 {
9231 emit_insn (gen_fmasf4_i (operands[0], operands[1], operands[2], operands[3]));
9232 DONE;
9233 })
9234
9235 (define_insn "fmasf4_i"
9236 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9237 (fma:SF (match_operand:SF 1 "fp_arith_reg_operand" "w")
9238 (match_operand:SF 2 "fp_arith_reg_operand" "f")
9239 (match_operand:SF 3 "fp_arith_reg_operand" "0")))
9240 (clobber (reg:SI FPSCR_STAT_REG))
9241 (use (reg:SI FPSCR_MODES_REG))]
9242 "TARGET_SH2E"
9243 "fmac %1,%2,%0"
9244 [(set_attr "type" "fp")
9245 (set_attr "fp_mode" "single")])
9246
9247 ;; For some cases such as 'a * b + a' the FMA pattern is not generated by
9248 ;; previous transformations. If FMA is generally allowed, let the combine
9249 ;; pass utilize it.
9250 (define_insn_and_split "*fmasf4"
9251 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9252 (plus:SF (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%w")
9253 (match_operand:SF 2 "fp_arith_reg_operand" "f"))
9254 (match_operand:SF 3 "arith_reg_operand" "0")))
9255 (clobber (reg:SI FPSCR_STAT_REG))
9256 (use (reg:SI FPSCR_MODES_REG))]
9257 "TARGET_SH2E && flag_fp_contract_mode != FP_CONTRACT_OFF"
9258 "fmac %1,%2,%0"
9259 "&& can_create_pseudo_p ()"
9260 [(parallel [(set (match_dup 0)
9261 (fma:SF (match_dup 1) (match_dup 2) (match_dup 3)))
9262 (clobber (reg:SI FPSCR_STAT_REG))
9263 (use (reg:SI FPSCR_MODES_REG))])]
9264 {
9265 /* Change 'b * a + a' into 'a * b + a'.
9266 This is better for register allocation. */
9267 if (REGNO (operands[2]) == REGNO (operands[3]))
9268 std::swap (operands[1], operands[2]);
9269 }
9270 [(set_attr "type" "fp")
9271 (set_attr "fp_mode" "single")])
9272
9273 (define_expand "divsf3"
9274 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9275 (div:SF (match_operand:SF 1 "fp_arith_reg_operand")
9276 (match_operand:SF 2 "fp_arith_reg_operand")))]
9277 "TARGET_SH2E"
9278 {
9279 emit_insn (gen_divsf3_i (operands[0], operands[1], operands[2]));
9280 DONE;
9281 })
9282
9283 (define_insn "divsf3_i"
9284 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9285 (div:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
9286 (match_operand:SF 2 "fp_arith_reg_operand" "f")))
9287 (clobber (reg:SI FPSCR_STAT_REG))
9288 (use (reg:SI FPSCR_MODES_REG))]
9289 "TARGET_SH2E"
9290 "fdiv %2,%0"
9291 [(set_attr "type" "fdiv")
9292 (set_attr "fp_mode" "single")])
9293
9294 (define_expand "floatsisf2"
9295 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9296 (float:SF (match_operand:SI 1 "fpul_operand" "")))]
9297 "TARGET_SH2E"
9298 {
9299 emit_insn (gen_floatsisf2_i4 (operands[0], operands[1]));
9300 DONE;
9301 })
9302
9303 (define_insn "floatsisf2_i4"
9304 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9305 (float:SF (match_operand:SI 1 "fpul_operand" "y")))
9306 (clobber (reg:SI FPSCR_STAT_REG))
9307 (use (reg:SI FPSCR_MODES_REG))]
9308 "TARGET_SH2E"
9309 "float %1,%0"
9310 [(set_attr "type" "fp")
9311 (set_attr "fp_mode" "single")])
9312
9313 (define_expand "fix_truncsfsi2"
9314 [(set (match_operand:SI 0 "fpul_operand")
9315 (fix:SI (match_operand:SF 1 "fp_arith_reg_operand")))]
9316 "TARGET_SH2E"
9317 {
9318 emit_insn (gen_fix_truncsfsi2_i4 (operands[0], operands[1]));
9319 DONE;
9320 })
9321
9322 (define_insn "fix_truncsfsi2_i4"
9323 [(set (match_operand:SI 0 "fpul_operand" "=y")
9324 (fix:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")))
9325 (clobber (reg:SI FPSCR_STAT_REG))
9326 (use (reg:SI FPSCR_MODES_REG))]
9327 "TARGET_SH2E"
9328 "ftrc %1,%0"
9329 [(set_attr "type" "ftrc_s")
9330 (set_attr "fp_mode" "single")])
9331
9332 (define_insn "cmpgtsf_t"
9333 [(set (reg:SI T_REG)
9334 (gt:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
9335 (match_operand:SF 1 "fp_arith_reg_operand" "f")))
9336 (clobber (reg:SI FPSCR_STAT_REG))
9337 (use (reg:SI FPSCR_MODES_REG))]
9338 "TARGET_SH2E || TARGET_SH4 || TARGET_SH2A_SINGLE"
9339 "fcmp/gt %1,%0"
9340 [(set_attr "type" "fp_cmp")
9341 (set_attr "fp_mode" "single")])
9342
9343 (define_insn "cmpeqsf_t"
9344 [(set (reg:SI T_REG)
9345 (eq:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
9346 (match_operand:SF 1 "fp_arith_reg_operand" "f")))
9347 (clobber (reg:SI FPSCR_STAT_REG))
9348 (use (reg:SI FPSCR_MODES_REG))]
9349 "TARGET_SH2E || TARGET_SH4 || TARGET_SH2A_SINGLE"
9350 "fcmp/eq %1,%0"
9351 [(set_attr "type" "fp_cmp")
9352 (set_attr "fp_mode" "single")])
9353
9354 (define_insn "ieee_ccmpeqsf_t"
9355 [(set (reg:SI T_REG)
9356 (ior:SI (reg:SI T_REG)
9357 (eq: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_IEEE && TARGET_SH2E"
9362 {
9363 return output_ieee_ccmpeq (insn, operands);
9364 }
9365 [(set_attr "length" "4")
9366 (set_attr "fp_mode" "single")])
9367
9368 (define_expand "cbranchsf4"
9369 [(set (pc)
9370 (if_then_else (match_operator 0 "ordered_comparison_operator"
9371 [(match_operand:SF 1 "arith_operand" "")
9372 (match_operand:SF 2 "arith_operand" "")])
9373 (match_operand 3 "" "")
9374 (pc)))]
9375 "TARGET_SH2E"
9376 {
9377 sh_emit_compare_and_branch (operands, SFmode);
9378 DONE;
9379 })
9380
9381 (define_expand "negsf2"
9382 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9383 (neg:SF (match_operand:SF 1 "fp_arith_reg_operand")))]
9384 "TARGET_SH2E")
9385
9386 (define_insn "*negsf2_i"
9387 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9388 (neg:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))]
9389 "TARGET_SH2E"
9390 "fneg %0"
9391 [(set_attr "type" "fmove")])
9392
9393 (define_expand "sqrtsf2"
9394 [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
9395 (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "")))]
9396 "TARGET_SH3E"
9397 {
9398 emit_insn (gen_sqrtsf2_i (operands[0], operands[1]));
9399 DONE;
9400 })
9401
9402 (define_insn "sqrtsf2_i"
9403 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9404 (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))
9405 (clobber (reg:SI FPSCR_STAT_REG))
9406 (use (reg:SI FPSCR_MODES_REG))]
9407 "TARGET_SH3E"
9408 "fsqrt %0"
9409 [(set_attr "type" "fdiv")
9410 (set_attr "fp_mode" "single")])
9411
9412 (define_insn "rsqrtsf2"
9413 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9414 (unspec:SF [(match_operand:SF 1 "fp_arith_reg_operand" "0")]
9415 UNSPEC_FSRRA))
9416 (clobber (reg:SI FPSCR_STAT_REG))
9417 (use (reg:SI FPSCR_MODES_REG))]
9418 "TARGET_FPU_ANY && TARGET_FSRRA"
9419 "fsrra %0"
9420 [(set_attr "type" "fsrra")
9421 (set_attr "fp_mode" "single")])
9422
9423 ;; When the sincos pattern is defined, the builtin functions sin and cos
9424 ;; will be expanded to the sincos pattern and one of the output values will
9425 ;; remain unused.
9426 (define_expand "sincossf3"
9427 [(set (match_operand:SF 0 "nonimmediate_operand")
9428 (unspec:SF [(match_operand:SF 2 "fp_arith_reg_operand")] UNSPEC_FCOSA))
9429 (set (match_operand:SF 1 "nonimmediate_operand")
9430 (unspec:SF [(match_dup 2)] UNSPEC_FSINA))]
9431 "TARGET_FPU_ANY && TARGET_FSCA"
9432 {
9433 rtx scaled = gen_reg_rtx (SFmode);
9434 rtx truncated = gen_reg_rtx (SImode);
9435 rtx fsca = gen_reg_rtx (V2SFmode);
9436 rtx scale_reg = force_reg (SFmode, sh_fsca_sf2int ());
9437
9438 emit_insn (gen_mulsf3 (scaled, operands[2], scale_reg));
9439 emit_insn (gen_fix_truncsfsi2 (truncated, scaled));
9440 emit_insn (gen_fsca (fsca, truncated, sh_fsca_int2sf ()));
9441
9442 emit_move_insn (operands[0], gen_rtx_SUBREG (SFmode, fsca, 4));
9443 emit_move_insn (operands[1], gen_rtx_SUBREG (SFmode, fsca, 0));
9444 DONE;
9445 })
9446
9447 (define_insn_and_split "fsca"
9448 [(set (match_operand:V2SF 0 "fp_arith_reg_operand" "=f")
9449 (vec_concat:V2SF
9450 (unspec:SF [(mult:SF
9451 (float:SF (match_operand:SI 1 "fpul_fsca_operand" "y"))
9452 (match_operand:SF 2 "fsca_scale_factor" "i"))
9453 ] UNSPEC_FSINA)
9454 (unspec:SF [(mult:SF (float:SF (match_dup 1)) (match_dup 2))
9455 ] UNSPEC_FCOSA)))
9456 (clobber (reg:SI FPSCR_STAT_REG))
9457 (use (reg:SI FPSCR_MODES_REG))]
9458 "TARGET_FPU_ANY && TARGET_FSCA"
9459 "fsca fpul,%d0"
9460 "&& !fpul_operand (operands[1], SImode)"
9461 [(const_int 0)]
9462 {
9463 /* If operands[1] is something like (fix:SF (float:SF (reg:SI))) reduce it
9464 to a simple reg, otherwise reload will have trouble reloading the
9465 pseudo into fpul. */
9466 rtx x = XEXP (operands[1], 0);
9467 while (x != NULL_RTX && !fpul_operand (x, SImode))
9468 {
9469 gcc_assert (GET_CODE (x) == FIX || GET_CODE (x) == FLOAT);
9470 x = XEXP (x, 0);
9471 }
9472 gcc_assert (x != NULL_RTX && fpul_operand (x, SImode));
9473 emit_insn (gen_fsca (operands[0], x, operands[2]));
9474 DONE;
9475 }
9476 [(set_attr "type" "fsca")
9477 (set_attr "fp_mode" "single")])
9478
9479 (define_expand "abssf2"
9480 [(set (match_operand:SF 0 "fp_arith_reg_operand")
9481 (abs:SF (match_operand:SF 1 "fp_arith_reg_operand")))]
9482 "TARGET_SH2E")
9483
9484 (define_insn "*abssf2_i"
9485 [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
9486 (abs:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))]
9487 "TARGET_SH2E"
9488 "fabs %0"
9489 [(set_attr "type" "fmove")])
9490
9491 (define_expand "adddf3"
9492 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9493 (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9494 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9495 "TARGET_FPU_DOUBLE"
9496 {
9497 emit_insn (gen_adddf3_i (operands[0], operands[1], operands[2]));
9498 DONE;
9499 })
9500
9501 (define_insn "adddf3_i"
9502 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9503 (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "%0")
9504 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9505 (clobber (reg:SI FPSCR_STAT_REG))
9506 (use (reg:SI FPSCR_MODES_REG))]
9507 "TARGET_FPU_DOUBLE"
9508 "fadd %2,%0"
9509 [(set_attr "type" "dfp_arith")
9510 (set_attr "fp_mode" "double")])
9511
9512 (define_expand "subdf3"
9513 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9514 (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9515 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9516 "TARGET_FPU_DOUBLE"
9517 {
9518 emit_insn (gen_subdf3_i (operands[0], operands[1], operands[2]));
9519 DONE;
9520 })
9521
9522 (define_insn "subdf3_i"
9523 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9524 (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")
9525 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9526 (clobber (reg:SI FPSCR_STAT_REG))
9527 (use (reg:SI FPSCR_MODES_REG))]
9528 "TARGET_FPU_DOUBLE"
9529 "fsub %2,%0"
9530 [(set_attr "type" "dfp_arith")
9531 (set_attr "fp_mode" "double")])
9532
9533 (define_expand "muldf3"
9534 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9535 (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9536 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9537 "TARGET_FPU_DOUBLE"
9538 {
9539 emit_insn (gen_muldf3_i (operands[0], operands[1], operands[2]));
9540 DONE;
9541 })
9542
9543 (define_insn "muldf3_i"
9544 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9545 (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "%0")
9546 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9547 (clobber (reg:SI FPSCR_STAT_REG))
9548 (use (reg:SI FPSCR_MODES_REG))]
9549 "TARGET_FPU_DOUBLE"
9550 "fmul %2,%0"
9551 [(set_attr "type" "dfp_mul")
9552 (set_attr "fp_mode" "double")])
9553
9554 (define_expand "divdf3"
9555 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9556 (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
9557 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
9558 "TARGET_FPU_DOUBLE"
9559 {
9560 emit_insn (gen_divdf3_i (operands[0], operands[1], operands[2]));
9561 DONE;
9562 })
9563
9564 (define_insn "divdf3_i"
9565 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9566 (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")
9567 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
9568 (clobber (reg:SI FPSCR_STAT_REG))
9569 (use (reg:SI FPSCR_MODES_REG))]
9570 "TARGET_FPU_DOUBLE"
9571 "fdiv %2,%0"
9572 [(set_attr "type" "dfdiv")
9573 (set_attr "fp_mode" "double")])
9574
9575 (define_expand "floatsidf2"
9576 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9577 (float:DF (match_operand:SI 1 "fpul_operand" "")))]
9578 "TARGET_FPU_DOUBLE"
9579 {
9580 emit_insn (gen_floatsidf2_i (operands[0], operands[1]));
9581 DONE;
9582 })
9583
9584 (define_insn "floatsidf2_i"
9585 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9586 (float:DF (match_operand:SI 1 "fpul_operand" "y")))
9587 (clobber (reg:SI FPSCR_STAT_REG))
9588 (use (reg:SI FPSCR_MODES_REG))]
9589 "TARGET_FPU_DOUBLE"
9590 "float %1,%0"
9591 [(set_attr "type" "dfp_conv")
9592 (set_attr "fp_mode" "double")])
9593
9594 (define_expand "fix_truncdfsi2"
9595 [(set (match_operand:SI 0 "fpul_operand" "")
9596 (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "")))]
9597 "TARGET_FPU_DOUBLE"
9598 {
9599 emit_insn (gen_fix_truncdfsi2_i (operands[0], operands[1]));
9600 DONE;
9601 })
9602
9603 (define_insn "fix_truncdfsi2_i"
9604 [(set (match_operand:SI 0 "fpul_operand" "=y")
9605 (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9606 (clobber (reg:SI FPSCR_STAT_REG))
9607 (use (reg:SI FPSCR_MODES_REG))]
9608 "TARGET_FPU_DOUBLE"
9609 "ftrc %1,%0"
9610 [(set_attr "type" "dfp_conv")
9611 (set_attr "dfp_comp" "no")
9612 (set_attr "fp_mode" "double")])
9613
9614 (define_insn "cmpgtdf_t"
9615 [(set (reg:SI T_REG)
9616 (gt:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
9617 (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9618 (clobber (reg:SI FPSCR_STAT_REG))
9619 (use (reg:SI FPSCR_MODES_REG))]
9620 "TARGET_FPU_DOUBLE"
9621 "fcmp/gt %1,%0"
9622 [(set_attr "type" "dfp_cmp")
9623 (set_attr "fp_mode" "double")])
9624
9625 (define_insn "cmpeqdf_t"
9626 [(set (reg:SI T_REG)
9627 (eq:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
9628 (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9629 (clobber (reg:SI FPSCR_STAT_REG))
9630 (use (reg:SI FPSCR_MODES_REG))]
9631 "TARGET_FPU_DOUBLE"
9632 "fcmp/eq %1,%0"
9633 [(set_attr "type" "dfp_cmp")
9634 (set_attr "fp_mode" "double")])
9635
9636 (define_insn "*ieee_ccmpeqdf_t"
9637 [(set (reg:SI T_REG)
9638 (ior:SI (reg:SI T_REG)
9639 (eq:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
9640 (match_operand:DF 1 "fp_arith_reg_operand" "f"))))
9641 (clobber (reg:SI FPSCR_STAT_REG))
9642 (use (reg:SI FPSCR_MODES_REG))]
9643 "TARGET_IEEE && TARGET_FPU_DOUBLE"
9644 {
9645 return output_ieee_ccmpeq (insn, operands);
9646 }
9647 [(set_attr "length" "4")
9648 (set_attr "fp_mode" "double")])
9649
9650 (define_expand "cbranchdf4"
9651 [(set (pc)
9652 (if_then_else (match_operator 0 "ordered_comparison_operator"
9653 [(match_operand:DF 1 "arith_operand" "")
9654 (match_operand:DF 2 "arith_operand" "")])
9655 (match_operand 3 "" "")
9656 (pc)))]
9657 "TARGET_FPU_DOUBLE"
9658 {
9659 sh_emit_compare_and_branch (operands, DFmode);
9660 DONE;
9661 })
9662
9663 (define_expand "negdf2"
9664 [(set (match_operand:DF 0 "fp_arith_reg_operand")
9665 (neg:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
9666 "TARGET_FPU_DOUBLE")
9667
9668 (define_insn "*negdf2_i"
9669 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9670 (neg:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))]
9671 "TARGET_FPU_DOUBLE"
9672 "fneg %0"
9673 [(set_attr "type" "fmove")])
9674
9675 (define_expand "sqrtdf2"
9676 [(set (match_operand:DF 0 "fp_arith_reg_operand")
9677 (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
9678 "TARGET_FPU_DOUBLE"
9679 {
9680 emit_insn (gen_sqrtdf2_i (operands[0], operands[1]));
9681 DONE;
9682 })
9683
9684 (define_insn "sqrtdf2_i"
9685 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9686 (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))
9687 (clobber (reg:SI FPSCR_STAT_REG))
9688 (use (reg:SI FPSCR_MODES_REG))]
9689 "TARGET_FPU_DOUBLE"
9690 "fsqrt %0"
9691 [(set_attr "type" "dfdiv")
9692 (set_attr "fp_mode" "double")])
9693
9694 (define_expand "absdf2"
9695 [(set (match_operand:DF 0 "fp_arith_reg_operand")
9696 (abs:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
9697 "TARGET_FPU_DOUBLE")
9698
9699 (define_insn "*absdf2_i"
9700 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9701 (abs:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))]
9702 "TARGET_FPU_DOUBLE"
9703 "fabs %0"
9704 [(set_attr "type" "fmove")])
9705
9706 (define_expand "extendsfdf2"
9707 [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
9708 (float_extend:DF (match_operand:SF 1 "fpul_operand" "")))]
9709 "TARGET_FPU_DOUBLE"
9710 {
9711 emit_insn (gen_extendsfdf2_i4 (operands[0], operands[1]));
9712 DONE;
9713 })
9714
9715 (define_insn "extendsfdf2_i4"
9716 [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
9717 (float_extend:DF (match_operand:SF 1 "fpul_operand" "y")))
9718 (clobber (reg:SI FPSCR_STAT_REG))
9719 (use (reg:SI FPSCR_MODES_REG))]
9720 "TARGET_FPU_DOUBLE"
9721 "fcnvsd %1,%0"
9722 [(set_attr "type" "fp")
9723 (set_attr "fp_mode" "double")])
9724
9725 (define_expand "truncdfsf2"
9726 [(set (match_operand:SF 0 "fpul_operand" "")
9727 (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "")))]
9728 "TARGET_FPU_DOUBLE"
9729 {
9730 emit_insn (gen_truncdfsf2_i4 (operands[0], operands[1]));
9731 DONE;
9732 })
9733
9734 (define_insn "truncdfsf2_i4"
9735 [(set (match_operand:SF 0 "fpul_operand" "=y")
9736 (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "f")))
9737 (clobber (reg:SI FPSCR_STAT_REG))
9738 (use (reg:SI FPSCR_MODES_REG))]
9739 "TARGET_FPU_DOUBLE"
9740 "fcnvds %1,%0"
9741 [(set_attr "type" "fp")
9742 (set_attr "fp_mode" "double")])
9743 \f
9744 ;; -------------------------------------------------------------------------
9745 ;; Bit field extract patterns.
9746 ;; -------------------------------------------------------------------------
9747
9748 ;; These give better code for packed bitfields, because they allow
9749 ;; auto-increment addresses to be generated.
9750
9751 (define_expand "insv"
9752 [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "")
9753 (match_operand:SI 1 "immediate_operand" "")
9754 (match_operand:SI 2 "immediate_operand" ""))
9755 (match_operand:SI 3 "general_operand" ""))]
9756 "TARGET_SH1 && TARGET_BIG_ENDIAN"
9757 {
9758 rtx addr_target, orig_address, shift_reg, qi_val;
9759 HOST_WIDE_INT bitsize, size, v = 0;
9760 rtx x = operands[3];
9761
9762 if (TARGET_SH2A && TARGET_BITOPS
9763 && (satisfies_constraint_Sbw (operands[0])
9764 || satisfies_constraint_Sbv (operands[0]))
9765 && satisfies_constraint_M (operands[1])
9766 && satisfies_constraint_K03 (operands[2]))
9767 {
9768 if (satisfies_constraint_N (operands[3]))
9769 {
9770 emit_insn (gen_bclr_m2a (operands[0], operands[2]));
9771 DONE;
9772 }
9773 else if (satisfies_constraint_M (operands[3]))
9774 {
9775 emit_insn (gen_bset_m2a (operands[0], operands[2]));
9776 DONE;
9777 }
9778 else if ((REG_P (operands[3]) && REGNO (operands[3]) == T_REG)
9779 && satisfies_constraint_M (operands[1]))
9780 {
9781 emit_insn (gen_bst_m2a (operands[0], operands[2]));
9782 DONE;
9783 }
9784 else if (REG_P (operands[3])
9785 && satisfies_constraint_M (operands[1]))
9786 {
9787 emit_insn (gen_bldsi_reg (operands[3], const0_rtx));
9788 emit_insn (gen_bst_m2a (operands[0], operands[2]));
9789 DONE;
9790 }
9791 }
9792 /* ??? expmed doesn't care for non-register predicates. */
9793 if (! memory_operand (operands[0], VOIDmode)
9794 || ! immediate_operand (operands[1], VOIDmode)
9795 || ! immediate_operand (operands[2], VOIDmode)
9796 || ! general_operand (x, VOIDmode))
9797 FAIL;
9798 /* If this isn't a 16 / 24 / 32 bit field, or if
9799 it doesn't start on a byte boundary, then fail. */
9800 bitsize = INTVAL (operands[1]);
9801 if (bitsize < 16 || bitsize > 32 || bitsize % 8 != 0
9802 || (INTVAL (operands[2]) % 8) != 0)
9803 FAIL;
9804
9805 size = bitsize / 8;
9806 orig_address = XEXP (operands[0], 0);
9807 shift_reg = gen_reg_rtx (SImode);
9808 if (CONST_INT_P (x))
9809 {
9810 v = INTVAL (x);
9811 qi_val = force_reg (QImode, GEN_INT (trunc_int_for_mode (v, QImode)));
9812 }
9813 else
9814 {
9815 emit_insn (gen_movsi (shift_reg, operands[3]));
9816 qi_val = gen_rtx_SUBREG (QImode, shift_reg, 3);
9817 }
9818 addr_target = copy_addr_to_reg (plus_constant (Pmode,
9819 orig_address, size - 1));
9820
9821 operands[0] = replace_equiv_address (operands[0], addr_target);
9822 emit_insn (gen_movqi (operands[0], qi_val));
9823
9824 while (size -= 1)
9825 {
9826 if (CONST_INT_P (x))
9827 qi_val
9828 = force_reg (QImode, GEN_INT (trunc_int_for_mode (v >>= 8, QImode)));
9829 else
9830 {
9831 emit_insn (gen_lshrsi3_k (shift_reg, shift_reg, GEN_INT (8)));
9832 qi_val = gen_rtx_SUBREG (QImode, shift_reg, 3);
9833 }
9834 emit_insn (gen_addsi3 (addr_target, addr_target, constm1_rtx));
9835 emit_insn (gen_movqi (operands[0], qi_val));
9836 }
9837
9838 DONE;
9839 })
9840
9841 (define_insn "movua"
9842 [(set (match_operand:SI 0 "register_operand" "=z")
9843 (unspec:SI [(match_operand:BLK 1 "unaligned_load_operand" "Sua>")]
9844 UNSPEC_MOVUA))]
9845 "TARGET_SH4A"
9846 "movua.l %1,%0"
9847 [(set_attr "type" "movua")])
9848
9849 ;; We shouldn't need this, but cse replaces increments with references
9850 ;; to other regs before flow has a chance to create post_inc
9851 ;; addressing modes, and only postreload's cse_move2add brings the
9852 ;; increments back to a usable form.
9853 (define_peephole2
9854 [(set (match_operand:SI 0 "register_operand" "")
9855 (sign_extract:SI (mem:SI (match_operand:SI 1 "register_operand" ""))
9856 (const_int 32) (const_int 0)))
9857 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
9858 "TARGET_SH4A && REGNO (operands[0]) != REGNO (operands[1])"
9859 [(set (match_operand:SI 0 "register_operand" "")
9860 (sign_extract:SI (mem:SI (post_inc:SI
9861 (match_operand:SI 1 "register_operand" "")))
9862 (const_int 32) (const_int 0)))]
9863 "")
9864
9865 (define_expand "extv"
9866 [(set (match_operand:SI 0 "register_operand" "")
9867 (sign_extract:SI (match_operand:QI 1 "unaligned_load_operand" "")
9868 (match_operand 2 "const_int_operand" "")
9869 (match_operand 3 "const_int_operand" "")))]
9870 "TARGET_SH4A || TARGET_SH2A"
9871 {
9872 if (TARGET_SH2A && TARGET_BITOPS
9873 && (satisfies_constraint_Sbw (operands[1])
9874 || satisfies_constraint_Sbv (operands[1]))
9875 && satisfies_constraint_M (operands[2])
9876 && satisfies_constraint_K03 (operands[3]))
9877 {
9878 emit_insn (gen_bldsign_m2a (operands[1], operands[3]));
9879 if (REGNO (operands[0]) != T_REG)
9880 emit_insn (gen_movsi (operands[0], gen_rtx_REG (SImode, T_REG)));
9881 DONE;
9882 }
9883 if (TARGET_SH4A
9884 && INTVAL (operands[2]) == 32
9885 && INTVAL (operands[3]) == 0
9886 && MEM_P (operands[1]) && MEM_ALIGN (operands[1]) < 32)
9887 {
9888 rtx src = adjust_address (operands[1], BLKmode, 0);
9889 set_mem_size (src, 4);
9890 emit_insn (gen_movua (operands[0], src));
9891 DONE;
9892 }
9893
9894 FAIL;
9895 })
9896
9897 (define_expand "extzv"
9898 [(set (match_operand:SI 0 "register_operand" "")
9899 (zero_extract:SI (match_operand:QI 1 "unaligned_load_operand" "")
9900 (match_operand 2 "const_int_operand" "")
9901 (match_operand 3 "const_int_operand" "")))]
9902 "TARGET_SH4A || TARGET_SH2A"
9903 {
9904 if (TARGET_SH2A && TARGET_BITOPS
9905 && (satisfies_constraint_Sbw (operands[1])
9906 || satisfies_constraint_Sbv (operands[1]))
9907 && satisfies_constraint_M (operands[2])
9908 && satisfies_constraint_K03 (operands[3]))
9909 {
9910 emit_insn (gen_bld_m2a (operands[1], operands[3]));
9911 if (REGNO (operands[0]) != T_REG)
9912 emit_insn (gen_movsi (operands[0], gen_rtx_REG (SImode, T_REG)));
9913 DONE;
9914 }
9915 if (TARGET_SH4A
9916 && INTVAL (operands[2]) == 32
9917 && INTVAL (operands[3]) == 0
9918 && MEM_P (operands[1]) && MEM_ALIGN (operands[1]) < 32)
9919 {
9920 rtx src = adjust_address (operands[1], BLKmode, 0);
9921 set_mem_size (src, 4);
9922 emit_insn (gen_movua (operands[0], src));
9923 DONE;
9924 }
9925
9926 FAIL;
9927 })
9928
9929 ;; -------------------------------------------------------------------------
9930 ;; Extract negated single bit and zero extend it.
9931 ;; Generally we don't care about the exact xor const_int value, as long
9932 ;; as it contains the extracted bit. For simplicity, the pattern variations
9933 ;; that convert everything into the primary '*neg_zero_extract_0' pattern use
9934 ;; a xor const_int -1 value.
9935
9936 (define_insn_and_split "*neg_zero_extract_0"
9937 [(set (reg:SI T_REG)
9938 (zero_extract:SI (xor:QIHISI (match_operand:QIHISI 0 "arith_reg_operand")
9939 (match_operand 1 "const_int_operand"))
9940 (const_int 1)
9941 (match_operand 2 "const_int_operand")))]
9942 "TARGET_SH1 && can_create_pseudo_p ()
9943 && INTVAL (operands[1]) & (1LL << INTVAL (operands[2]))"
9944 "#"
9945 "&& 1"
9946 [(set (reg:SI T_REG) (eq:SI (and:SI (match_dup 0) (match_dup 2))
9947 (const_int 0)))]
9948 {
9949 if (INTVAL (operands[2]) == 31 && <MODE>mode == SImode)
9950 {
9951 /* Use cmp/pz to extract bit 31 into the T bit. */
9952 emit_insn (gen_cmpgesi_t (operands[0], const0_rtx));
9953 DONE;
9954 }
9955
9956 operands[2] = GEN_INT ((1 << INTVAL (operands[2])));
9957 if (GET_MODE (operands[0]) != SImode)
9958 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
9959 })
9960
9961 (define_insn_and_split "*neg_zero_extract_1"
9962 [(set (reg:SI T_REG)
9963 (and:SI (not:SI (match_operand:SI 0 "arith_reg_operand"))
9964 (const_int 1)))]
9965 "TARGET_SH1"
9966 "#"
9967 "&& 1"
9968 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
9969 (const_int 1) (const_int 0)))])
9970
9971 ;; x & (1 << n) == 0: 0x00000000 + 1 = 1
9972 ;; x & (1 << n) != 0: 0xFFFFFFFF + 1 = 0
9973 (define_insn_and_split "*neg_zero_extract_2"
9974 [(set (reg:SI T_REG)
9975 (plus:SI (sign_extract:SI (match_operand:QIHISI 0 "arith_reg_operand")
9976 (const_int 1)
9977 (match_operand 1 "const_int_operand"))
9978 (const_int 1)))]
9979 "TARGET_SH1 && can_create_pseudo_p ()"
9980 "#"
9981 "&& 1"
9982 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
9983 (const_int 1) (match_dup 1)))])
9984
9985 ;; (signed)x >> 31 + 1 = (x >= 0) ^ 1
9986 (define_insn_and_split "*neg_zero_extract_3"
9987 [(set (reg:SI T_REG)
9988 (plus:SI (ashiftrt:SI (match_operand:SI 0 "arith_reg_operand")
9989 (const_int 31))
9990 (const_int 1)))]
9991 "TARGET_SH1 && can_create_pseudo_p ()"
9992 "#"
9993 "&& 1"
9994 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
9995 (const_int 1) (const_int 31)))])
9996
9997 ;; This is required for some bit patterns of DImode subregs.
9998 ;; It looks like combine gets confused by the DImode right shift and fails
9999 ;; to simplify things.
10000 (define_insn_and_split "*neg_zero_extract_4"
10001 [(set (reg:SI T_REG)
10002 (and:SI (and:SI
10003 (lshiftrt:SI (xor:SI (match_operand:SI 0 "arith_reg_operand")
10004 (match_operand 1 "const_int_operand"))
10005 (match_operand 2 "const_int_operand"))
10006 (not:SI (ashift:SI (match_operand:SI 3 "arith_reg_operand")
10007 (match_operand 4 "const_int_operand"))))
10008 (const_int 1)))]
10009 "TARGET_SH1 && can_create_pseudo_p ()
10010 && INTVAL (operands[4]) > 0
10011 && INTVAL (operands[1]) & (1LL << INTVAL (operands[2]))"
10012 "#"
10013 "&& 1"
10014 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
10015 (const_int 1) (match_dup 2)))])
10016
10017 (define_insn_and_split "*neg_zero_extract_5"
10018 [(set (reg:SI T_REG)
10019 (and:SI (not:SI (subreg:SI
10020 (lshiftrt:DI (match_operand:DI 0 "arith_reg_operand")
10021 (match_operand 1 "const_int_operand"))
10022 0))
10023 (const_int 1)))]
10024 "TARGET_SH1 && TARGET_LITTLE_ENDIAN && can_create_pseudo_p ()
10025 && INTVAL (operands[1]) < 32"
10026 "#"
10027 "&& 1"
10028 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10029 (const_int 1) (match_dup 1)))]
10030 {
10031 operands[0] = gen_lowpart (SImode, operands[0]);
10032 })
10033
10034 (define_insn_and_split "*neg_zero_extract_6"
10035 [(set (reg:SI T_REG)
10036 (and:SI (not:SI (subreg:SI
10037 (lshiftrt:DI (match_operand:DI 0 "arith_reg_operand")
10038 (match_operand 1 "const_int_operand"))
10039 4))
10040 (const_int 1)))]
10041 "TARGET_SH1 && TARGET_BIG_ENDIAN && can_create_pseudo_p ()
10042 && INTVAL (operands[1]) < 32"
10043 "#"
10044 "&& 1"
10045 [(set (reg:SI T_REG) (zero_extract:SI (xor:SI (match_dup 0) (const_int -1))
10046 (const_int 1) (match_dup 1)))]
10047 {
10048 operands[0] = gen_lowpart (SImode, operands[0]);
10049 })
10050
10051 ;; -------------------------------------------------------------------------
10052 ;; Extract single bit and zero extend it.
10053 ;; All patterns store the result bit in the T bit, although that is not
10054 ;; always possible to do with a single insn and a nott must be appended.
10055 ;; The trailing nott will be optimized away in most cases. E.g. if the
10056 ;; extracted bit is fed into a branch condition, the condition can be
10057 ;; inverted and the nott will be eliminated.
10058 ;; FIXME: In cases where the trailing nott can't be eliminated, try to
10059 ;; convert it into a (not, tst) sequence, which could be better on non-SH2A.
10060
10061 ;; On SH2A the 'bld<mode>_reg' insn will be used if the bit position fits.
10062 (define_insn_and_split "*zero_extract_0"
10063 [(set (reg:SI T_REG)
10064 (zero_extract:SI (match_operand:QIHISI 0 "arith_reg_operand")
10065 (const_int 1)
10066 (match_operand 1 "const_int_operand")))]
10067 "TARGET_SH1 && can_create_pseudo_p ()
10068 && !(TARGET_SH2A && satisfies_constraint_K03 (operands[1]))"
10069 "#"
10070 "&& 1"
10071 [(set (reg:SI T_REG) (eq:SI (and:SI (match_dup 0) (match_dup 1))
10072 (const_int 0)))
10073 (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))]
10074 {
10075 if (INTVAL (operands[1]) == 31 && <MODE>mode == SImode)
10076 {
10077 emit_insn (gen_shll (gen_reg_rtx (SImode), operands[0]));
10078 DONE;
10079 }
10080
10081 operands[1] = GEN_INT (1 << INTVAL (operands[1]));
10082 if (GET_MODE (operands[0]) != SImode)
10083 operands[0] = simplify_gen_subreg (SImode, operands[0], <MODE>mode, 0);
10084 })
10085
10086 ;; This is required for some bit patterns of DImode subregs.
10087 ;; It looks like combine gets confused by the DImode right shift and fails
10088 ;; to simplify things.
10089 (define_insn_and_split "*zero_extract_1"
10090 [(set (reg:SI T_REG)
10091 (subreg:SI (zero_extract:DI (match_operand:SI 0 "arith_reg_operand")
10092 (const_int 1)
10093 (match_operand 1 "const_int_operand"))
10094 0))]
10095 "TARGET_SH1 && TARGET_LITTLE_ENDIAN && can_create_pseudo_p ()
10096 && INTVAL (operands[1]) < 32"
10097 "#"
10098 "&& 1"
10099 [(set (reg:SI T_REG)
10100 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1)))])
10101
10102 (define_insn_and_split "*zero_extract_2"
10103 [(set (reg:SI T_REG)
10104 (subreg:SI (zero_extract:DI (match_operand:SI 0 "arith_reg_operand")
10105 (const_int 1)
10106 (match_operand 1 "const_int_operand"))
10107 4))]
10108 "TARGET_SH1 && TARGET_BIG_ENDIAN && can_create_pseudo_p ()
10109 && INTVAL (operands[1]) < 32"
10110 "#"
10111 "&& 1"
10112 [(set (reg:SI T_REG)
10113 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1)))])
10114
10115 (define_insn_and_split "*zero_extract_3"
10116 [(set (match_operand:SI 0 "arith_reg_dest")
10117 (and:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
10118 (match_operand 2 "const_int_operand"))
10119 (match_operand 3 "const_int_operand")))
10120 (clobber (reg:SI T_REG))]
10121 "TARGET_SH1 && can_create_pseudo_p ()
10122 && exact_log2 (INTVAL (operands[3])) >= 0"
10123 "#"
10124 "&& 1"
10125 [(const_int 0)]
10126 {
10127 int rshift = INTVAL (operands[2]);
10128 int lshift = exact_log2 (INTVAL (operands[3]));
10129
10130 rtx tmp = gen_reg_rtx (SImode);
10131 emit_insn (gen_rtx_PARALLEL (VOIDmode,
10132 gen_rtvec (2,
10133 gen_rtx_SET (tmp,
10134 gen_rtx_ZERO_EXTRACT (SImode, operands[1], const1_rtx,
10135 GEN_INT (rshift + lshift))),
10136 gen_rtx_CLOBBER (VOIDmode, get_t_reg_rtx ()))));
10137 emit_insn (gen_ashlsi3 (operands[0], tmp, GEN_INT (lshift)));
10138 })
10139
10140 ;; -------------------------------------------------------------------------
10141 ;; SH2A instructions for bitwise operations.
10142 ;; FIXME: Convert multiple instruction insns to insn_and_split.
10143 ;; FIXME: Use iterators to fold at least and,xor,or insn variations.
10144
10145 ;; Clear a bit in a memory location.
10146 (define_insn "bclr_m2a"
10147 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10148 (and:QI
10149 (not:QI (ashift:QI (const_int 1)
10150 (match_operand:QI 1 "const_int_operand" "K03,K03")))
10151 (match_dup 0)))]
10152 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10153 "@
10154 bclr.b %1,%0
10155 bclr.b %1,@(0,%t0)"
10156 [(set_attr "length" "4,4")])
10157
10158 (define_insn "bclrmem_m2a"
10159 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10160 (and:QI (match_dup 0)
10161 (match_operand:QI 1 "const_int_operand" "Psz,Psz")))]
10162 "TARGET_SH2A && satisfies_constraint_Psz (operands[1]) && TARGET_BITOPS"
10163 "@
10164 bclr.b %W1,%0
10165 bclr.b %W1,@(0,%t0)"
10166 [(set_attr "length" "4,4")])
10167
10168 ;; Set a bit in a memory location.
10169 (define_insn "bset_m2a"
10170 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10171 (ior:QI
10172 (ashift:QI (const_int 1)
10173 (match_operand:QI 1 "const_int_operand" "K03,K03"))
10174 (match_dup 0)))]
10175 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10176 "@
10177 bset.b %1,%0
10178 bset.b %1,@(0,%t0)"
10179 [(set_attr "length" "4,4")])
10180
10181 (define_insn "bsetmem_m2a"
10182 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
10183 (ior:QI (match_dup 0)
10184 (match_operand:QI 1 "const_int_operand" "Pso,Pso")))]
10185 "TARGET_SH2A && satisfies_constraint_Pso (operands[1]) && TARGET_BITOPS"
10186 "@
10187 bset.b %V1,%0
10188 bset.b %V1,@(0,%t0)"
10189 [(set_attr "length" "4,4")])
10190
10191 ;;; Transfer the contents of the T bit to a specified bit of memory.
10192 (define_insn "bst_m2a"
10193 [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,m")
10194 (if_then_else (eq (reg:SI T_REG) (const_int 0))
10195 (and:QI
10196 (not:QI (ashift:QI (const_int 1)
10197 (match_operand:QI 1 "const_int_operand" "K03,K03")))
10198 (match_dup 0))
10199 (ior:QI
10200 (ashift:QI (const_int 1) (match_dup 1))
10201 (match_dup 0))))]
10202 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10203 "@
10204 bst.b %1,%0
10205 bst.b %1,@(0,%t0)"
10206 [(set_attr "length" "4")])
10207
10208 ;; Store a specified bit of memory in the T bit.
10209 (define_insn "bld_m2a"
10210 [(set (reg:SI T_REG)
10211 (zero_extract:SI
10212 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,Sbv")
10213 (const_int 1)
10214 (match_operand 1 "const_int_operand" "K03,K03")))]
10215 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10216 "@
10217 bld.b %1,%0
10218 bld.b %1,@(0,%t0)"
10219 [(set_attr "length" "4,4")])
10220
10221 ;; Store a specified bit of memory in the T bit.
10222 (define_insn "bldsign_m2a"
10223 [(set (reg:SI T_REG)
10224 (sign_extract:SI
10225 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10226 (const_int 1)
10227 (match_operand 1 "const_int_operand" "K03,K03")))]
10228 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10229 "@
10230 bld.b %1,%0
10231 bld.b %1,@(0,%t0)"
10232 [(set_attr "length" "4,4")])
10233
10234 ;; Store a specified bit of the LSB 8 bits of a register in the T bit.
10235 (define_insn "bld<mode>_reg"
10236 [(set (reg:SI T_REG)
10237 (zero_extract:SI (match_operand:QIHISI 0 "arith_reg_operand" "r")
10238 (const_int 1)
10239 (match_operand 1 "const_int_operand" "K03")))]
10240 "TARGET_SH2A && satisfies_constraint_K03 (operands[1])"
10241 "bld %1,%0")
10242
10243 ;; Take logical and of a specified bit of memory with the T bit and
10244 ;; store its result in the T bit.
10245 (define_insn "band_m2a"
10246 [(set (reg:SI T_REG)
10247 (and:SI (reg:SI T_REG)
10248 (zero_extract:SI
10249 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10250 (const_int 1)
10251 (match_operand 1 "const_int_operand" "K03,K03"))))]
10252 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10253 "@
10254 band.b %1,%0
10255 band.b %1,@(0,%t0)"
10256 [(set_attr "length" "4,4")])
10257
10258 (define_insn "bandreg_m2a"
10259 [(set (match_operand:SI 0 "register_operand" "=r,r")
10260 (and:SI (zero_extract:SI
10261 (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
10262 (const_int 1)
10263 (match_operand 2 "const_int_operand" "K03,K03"))
10264 (match_operand:SI 3 "register_operand" "r,r")))]
10265 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
10266 {
10267 static const char* alt[] =
10268 {
10269 "band.b %2,%1" "\n"
10270 " movt %0",
10271
10272 "band.b %2,@(0,%t1)" "\n"
10273 " movt %0"
10274 };
10275 return alt[which_alternative];
10276 }
10277 [(set_attr "length" "6,6")])
10278
10279 ;; Take logical or of a specified bit of memory with the T bit and
10280 ;; store its result in the T bit.
10281 (define_insn "bor_m2a"
10282 [(set (reg:SI T_REG)
10283 (ior:SI (reg:SI T_REG)
10284 (zero_extract:SI
10285 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10286 (const_int 1)
10287 (match_operand 1 "const_int_operand" "K03,K03"))))]
10288 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10289 "@
10290 bor.b %1,%0
10291 bor.b %1,@(0,%t0)"
10292 [(set_attr "length" "4,4")])
10293
10294 (define_insn "borreg_m2a"
10295 [(set (match_operand:SI 0 "register_operand" "=r,r")
10296 (ior:SI (zero_extract:SI
10297 (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
10298 (const_int 1)
10299 (match_operand 2 "const_int_operand" "K03,K03"))
10300 (match_operand:SI 3 "register_operand" "=r,r")))]
10301 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
10302 {
10303 static const char* alt[] =
10304 {
10305 "bor.b %2,%1" "\n"
10306 " movt %0",
10307
10308 "bor.b %2,@(0,%t1)" "\n"
10309 " movt %0"
10310 };
10311 return alt[which_alternative];
10312 }
10313 [(set_attr "length" "6,6")])
10314
10315 ;; Take exclusive or of a specified bit of memory with the T bit and
10316 ;; store its result in the T bit.
10317 (define_insn "bxor_m2a"
10318 [(set (reg:SI T_REG)
10319 (xor:SI (reg:SI T_REG)
10320 (zero_extract:SI
10321 (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
10322 (const_int 1)
10323 (match_operand 1 "const_int_operand" "K03,K03"))))]
10324 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
10325 "@
10326 bxor.b %1,%0
10327 bxor.b %1,@(0,%t0)"
10328 [(set_attr "length" "4,4")])
10329
10330 (define_insn "bxorreg_m2a"
10331 [(set (match_operand:SI 0 "register_operand" "=r,r")
10332 (xor:SI (zero_extract:SI
10333 (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
10334 (const_int 1)
10335 (match_operand 2 "const_int_operand" "K03,K03"))
10336 (match_operand:SI 3 "register_operand" "=r,r")))]
10337 "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
10338 {
10339 static const char* alt[] =
10340 {
10341 "bxor.b %2,%1" "\n"
10342 " movt %0",
10343
10344 "bxor.b %2,@(0,%t1)" "\n"
10345 " movt %0"
10346 };
10347 return alt[which_alternative];
10348 }
10349 [(set_attr "length" "6,6")])
10350 \f
10351 ;; -------------------------------------------------------------------------
10352 ;; Peepholes
10353 ;; -------------------------------------------------------------------------
10354 ;; This matches cases where the bit in a memory location is set.
10355 (define_peephole2
10356 [(set (match_operand:SI 0 "register_operand")
10357 (sign_extend:SI (match_operand:QI 1 "bitwise_memory_operand")))
10358 (set (match_dup 0)
10359 (ior:SI (match_dup 0)
10360 (match_operand:SI 2 "const_int_operand")))
10361 (set (match_dup 1)
10362 (match_operand 3 "arith_reg_operand"))]
10363 "TARGET_SH2A && TARGET_BITOPS
10364 && satisfies_constraint_Pso (operands[2])
10365 && REGNO (operands[0]) == REGNO (operands[3])"
10366 [(set (match_dup 1)
10367 (ior:QI (match_dup 1) (match_dup 2)))]
10368 "")
10369
10370 ;; This matches cases where the bit in a memory location is cleared.
10371 (define_peephole2
10372 [(set (match_operand:SI 0 "register_operand")
10373 (sign_extend:SI (match_operand:QI 1 "bitwise_memory_operand")))
10374 (set (match_dup 0)
10375 (and:SI (match_dup 0)
10376 (match_operand:SI 2 "const_int_operand")))
10377 (set (match_dup 1)
10378 (match_operand 3 "arith_reg_operand"))]
10379 "TARGET_SH2A && TARGET_BITOPS
10380 && satisfies_constraint_Psz (operands[2])
10381 && REGNO (operands[0]) == REGNO (operands[3])"
10382 [(set (match_dup 1)
10383 (and:QI (match_dup 1) (match_dup 2)))]
10384 "")
10385
10386 ;; This matches cases where a stack pointer increment at the start of the
10387 ;; epilogue combines with a stack slot read loading the return value.
10388 (define_peephole
10389 [(set (match_operand:SI 0 "arith_reg_operand" "")
10390 (mem:SI (match_operand:SI 1 "arith_reg_operand" "")))
10391 (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
10392 "TARGET_SH1 && REGNO (operands[1]) != REGNO (operands[0])"
10393 "mov.l @%1+,%0")
10394
10395 ;; See the comment on the dt combiner pattern above.
10396 (define_peephole
10397 [(set (match_operand:SI 0 "arith_reg_operand" "=r")
10398 (plus:SI (match_dup 0)
10399 (const_int -1)))
10400 (set (reg:SI T_REG)
10401 (eq:SI (match_dup 0) (const_int 0)))]
10402 "TARGET_SH2"
10403 "dt %0")
10404
10405 ;; The following peepholes fold load sequences for which reload was not
10406 ;; able to generate a displacement addressing move insn.
10407 ;; This can happen when reload has to transform a move insn
10408 ;; without displacement into one with displacement. Or when reload can't
10409 ;; fit a displacement into the insn's constraints. In the latter case, the
10410 ;; load destination reg remains at r0, which reload compensates by inserting
10411 ;; another mov insn.
10412
10413 ;; Fold sequence:
10414 ;; mov #54,r0
10415 ;; mov.{b,w} @(r0,r15),r0
10416 ;; mov r0,r3
10417 ;; into:
10418 ;; mov.{b,w} @(54,r15),r3
10419 ;;
10420 (define_peephole2
10421 [(set (match_operand:SI 0 "arith_reg_dest" "")
10422 (match_operand:SI 1 "const_int_operand" ""))
10423 (set (match_operand:SI 2 "arith_reg_dest" "")
10424 (sign_extend:SI
10425 (mem:QI (plus:SI (match_dup 0)
10426 (match_operand:SI 3 "arith_reg_operand" "")))))
10427 (set (match_operand:QI 4 "arith_reg_dest" "")
10428 (match_operand:QI 5 "arith_reg_operand" ""))]
10429 "TARGET_SH2A
10430 && sh_legitimate_index_p (QImode, operands[1], true, true)
10431 && REGNO (operands[2]) == REGNO (operands[5])
10432 && peep2_reg_dead_p (3, operands[5])"
10433 [(set (match_dup 4) (mem:QI (plus:SI (match_dup 3) (match_dup 1))))]
10434 "")
10435
10436 (define_peephole2
10437 [(set (match_operand:SI 0 "arith_reg_dest" "")
10438 (match_operand:SI 1 "const_int_operand" ""))
10439 (set (match_operand:SI 2 "arith_reg_dest" "")
10440 (sign_extend:SI
10441 (mem:HI (plus:SI (match_dup 0)
10442 (match_operand:SI 3 "arith_reg_operand" "")))))
10443 (set (match_operand:HI 4 "arith_reg_dest" "")
10444 (match_operand:HI 5 "arith_reg_operand" ""))]
10445 "TARGET_SH2A
10446 && sh_legitimate_index_p (HImode, operands[1], true, true)
10447 && REGNO (operands[2]) == REGNO (operands[5])
10448 && peep2_reg_dead_p (3, operands[5])"
10449 [(set (match_dup 4) (mem:HI (plus:SI (match_dup 3) (match_dup 1))))]
10450 "")
10451
10452 ;; Fold sequence:
10453 ;; mov #54,r0
10454 ;; mov.{b,w} @(r0,r15),r1
10455 ;; into:
10456 ;; mov.{b,w} @(54,r15),r1
10457 ;;
10458 (define_peephole2
10459 [(set (match_operand:SI 0 "arith_reg_dest" "")
10460 (match_operand:SI 1 "const_int_operand" ""))
10461 (set (match_operand:SI 2 "arith_reg_dest" "")
10462 (sign_extend:SI
10463 (mem:QI (plus:SI (match_dup 0)
10464 (match_operand:SI 3 "arith_reg_operand" "")))))]
10465 "TARGET_SH2A
10466 && sh_legitimate_index_p (QImode, operands[1], true, true)
10467 && (peep2_reg_dead_p (2, operands[0])
10468 || REGNO (operands[0]) == REGNO (operands[2]))"
10469 [(set (match_dup 2)
10470 (sign_extend:SI (mem:QI (plus:SI (match_dup 3) (match_dup 1)))))]
10471 "")
10472
10473 (define_peephole2
10474 [(set (match_operand:SI 0 "arith_reg_dest" "")
10475 (match_operand:SI 1 "const_int_operand" ""))
10476 (set (match_operand:SI 2 "arith_reg_dest" "")
10477 (sign_extend:SI
10478 (mem:HI (plus:SI (match_dup 0)
10479 (match_operand:SI 3 "arith_reg_operand" "")))))]
10480 "TARGET_SH2A
10481 && sh_legitimate_index_p (HImode, operands[1], true, true)
10482 && (peep2_reg_dead_p (2, operands[0])
10483 || REGNO (operands[0]) == REGNO (operands[2]))"
10484 [(set (match_dup 2)
10485 (sign_extend:SI (mem:HI (plus:SI (match_dup 3) (match_dup 1)))))]
10486 "")
10487
10488 ;; Fold sequence:
10489 ;; mov.{b,w} @(r0,r15),r0
10490 ;; mov r0,r3
10491 ;; into:
10492 ;; mov.{b,w} @(r0,r15),r3
10493 ;;
10494 ;; This can happen when initially a displacement address is picked, where
10495 ;; the destination reg is fixed to r0, and then the address is transformed
10496 ;; into 'r0 + reg'.
10497 (define_peephole2
10498 [(set (match_operand:SI 0 "arith_reg_dest" "")
10499 (sign_extend:SI
10500 (mem:QI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
10501 (match_operand:SI 2 "arith_reg_operand" "")))))
10502 (set (match_operand:QI 3 "arith_reg_dest" "")
10503 (match_operand:QI 4 "arith_reg_operand" ""))]
10504 "TARGET_SH1
10505 && REGNO (operands[0]) == REGNO (operands[4])
10506 && peep2_reg_dead_p (2, operands[0])"
10507 [(set (match_dup 3)
10508 (mem:QI (plus:SI (match_dup 1) (match_dup 2))))]
10509 "")
10510
10511 (define_peephole2
10512 [(set (match_operand:SI 0 "arith_reg_dest" "")
10513 (sign_extend:SI
10514 (mem:HI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
10515 (match_operand:SI 2 "arith_reg_operand" "")))))
10516 (set (match_operand:HI 3 "arith_reg_dest" "")
10517 (match_operand:HI 4 "arith_reg_operand" ""))]
10518 "TARGET_SH1
10519 && REGNO (operands[0]) == REGNO (operands[4])
10520 && peep2_reg_dead_p (2, operands[0])"
10521 [(set (match_dup 3)
10522 (mem:HI (plus:SI (match_dup 1) (match_dup 2))))]
10523 "")
10524
10525 ;; extu.bw a,b
10526 ;; mov b,c -> extu.bw a,c
10527 (define_peephole2
10528 [(set (match_operand:SI 0 "arith_reg_dest")
10529 (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand")))
10530 (set (match_operand:SI 2 "arith_reg_dest")
10531 (match_dup 0))]
10532 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10533 [(set (match_dup 2) (zero_extend:SI (match_dup 1)))])
10534
10535 ;; mov r0,r1
10536 ;; extu.bw r1,r1 -> extu.bw r0,r1
10537 (define_peephole2
10538 [(set (match_operand 0 "arith_reg_dest")
10539 (match_operand 1 "arith_reg_operand"))
10540 (set (match_operand:SI 2 "arith_reg_dest")
10541 (zero_extend:SI (match_operand:QIHI 3 "arith_reg_operand")))]
10542 "TARGET_SH1
10543 && REGNO (operands[0]) == REGNO (operands[3])
10544 && (REGNO (operands[0]) == REGNO (operands[2])
10545 || peep2_reg_dead_p (2, operands[0]))"
10546 [(set (match_dup 2) (zero_extend:SI (match_dup 1)))]
10547 {
10548 operands[1] = gen_rtx_REG (<MODE>mode, REGNO (operands[1]));
10549 })
10550
10551 ;; mov a,b
10552 ;; mov b,a -> < nop >
10553 (define_peephole2
10554 [(set (match_operand 0 "register_operand")
10555 (match_operand 1 "register_operand"))
10556 (set (match_operand 2 "register_operand")
10557 (match_operand 3 "register_operand"))]
10558 "TARGET_SH1
10559 && REGNO (operands[0]) == REGNO (operands[3])
10560 && REGNO (operands[1]) == REGNO (operands[2])
10561 && peep2_reg_dead_p (2, operands[3])"
10562 [(const_int 0)])
10563
10564 ;; mov #3,r4
10565 ;; and r4,r1 -> mov r1,r0
10566 ;; mov r1,r0 and #3,r0
10567 (define_code_iterator ANDIORXOR [and ior xor])
10568 (define_peephole2
10569 [(set (match_operand:SI 0 "register_operand")
10570 (match_operand:SI 1 "const_logical_operand"))
10571 (set (match_operand:SI 2) (ANDIORXOR:SI (match_dup 2) (match_dup 0)))
10572 (set (reg:SI R0_REG) (match_dup 2))]
10573 "TARGET_SH1
10574 && peep2_reg_dead_p (3, operands[0]) && peep2_reg_dead_p (3, operands[2])"
10575 [(set (reg:SI R0_REG) (match_dup 2))
10576 (set (reg:SI R0_REG) (ANDIORXOR:SI (reg:SI R0_REG) (match_dup 1)))])
10577
10578 ;; ... r2,r0 ... r2,r0
10579 ;; or r1,r0 -> or r0,r1
10580 ;; mov r0,r1
10581 ;; (r0 dead)
10582 (define_code_iterator ANDIORXORPLUS [and ior xor plus])
10583 (define_peephole2
10584 [(set (match_operand:SI 0 "arith_reg_dest")
10585 (ANDIORXORPLUS:SI (match_dup 0) (match_operand:SI 1 "arith_reg_dest")))
10586 (set (match_dup 1) (match_dup 0))]
10587 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10588 [(set (match_dup 1) (ANDIORXORPLUS:SI (match_dup 1) (match_dup 0)))])
10589
10590 ;; mov r12,r0
10591 ;; add #-48,r0 -> add #-48,r12
10592 ;; mov.l r0,@(4,r10) mov.l r12,@(4,r10)
10593 ;; (r12 dead)
10594 (define_peephole2
10595 [(set (match_operand:SI 0 "arith_reg_dest")
10596 (match_operand:SI 1 "arith_reg_dest"))
10597 (set (match_dup 0) (plus:SI (match_dup 0)
10598 (match_operand:SI 2 "const_int_operand")))
10599 (set (match_operand:SI 3 "general_movdst_operand") (match_dup 0))]
10600 "TARGET_SH1
10601 && peep2_reg_dead_p (2, operands[1]) && peep2_reg_dead_p (3, operands[0])"
10602 [(const_int 0)]
10603 {
10604 emit_insn (gen_addsi3 (operands[1], operands[1], operands[2]));
10605 sh_peephole_emit_move_insn (operands[3], operands[1]);
10606 })
10607
10608 ;; mov.l @(r0,r9),r1
10609 ;; mov r1,r0 -> mov @(r0,r9),r0
10610 (define_peephole2
10611 [(set (match_operand:SI 0 "arith_reg_dest")
10612 (match_operand:SI 1 "general_movsrc_operand"))
10613 (set (match_operand:SI 2 "arith_reg_dest")
10614 (match_dup 0))]
10615 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10616 [(const_int 0)]
10617 {
10618 sh_peephole_emit_move_insn (operands[2], operands[1]);
10619 })
10620
10621 (define_peephole2
10622 [(set (match_operand:QIHI 0 "register_operand")
10623 (match_operand:QIHI 1 "movsrc_no_disp_mem_operand"))
10624 (set (match_operand:QIHI 2 "register_operand")
10625 (match_dup 0))]
10626 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10627 [(const_int 0)]
10628 {
10629 sh_peephole_emit_move_insn (operands[2], operands[1]);
10630 })
10631
10632 (define_peephole2
10633 [(set (match_operand:SI 0 "arith_reg_dest")
10634 (sign_extend:SI (match_operand:QIHI 1 "movsrc_no_disp_mem_operand")))
10635 (set (match_operand:SI 2 "arith_reg_dest")
10636 (match_dup 0))]
10637 "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
10638 [(const_int 0)]
10639 {
10640 sh_check_add_incdec_notes (emit_insn (gen_extend<mode>si2 (operands[2],
10641 sh_remove_overlapping_post_inc (operands[2], operands[1]))));
10642 })
10643
10644 ;; mov.w @(18,r1),r0 (r0 = HImode)
10645 ;; mov r0,r1 (r0 = r1 = HImode) mov.w @(18,r1),r0
10646 ;; ... ..,r13 (r13 = SImode) -> ... ..,r13
10647 ;; tst r1,r13 tst r0,r13
10648 (define_peephole2
10649 [(set (match_operand 0 "arith_reg_dest")
10650 (match_operand 1 "arith_reg_dest"))
10651 (set (match_operand:SI 2 "arith_reg_dest")
10652 (match_operand:SI 3))
10653 (set (reg:SI T_REG)
10654 (eq:SI (and:SI (match_operand:SI 4 "arith_reg_operand")
10655 (match_operand:SI 5 "arith_reg_operand"))
10656 (const_int 0)))]
10657 "TARGET_SH1
10658 && peep2_reg_dead_p (3, operands[0])
10659 && !reg_overlap_mentioned_p (operands[0], operands[3])
10660 && (REGNO (operands[0]) == REGNO (operands[4])
10661 || REGNO (operands[0]) == REGNO (operands[5]))
10662 && (REGNO (operands[2]) == REGNO (operands[4])
10663 || REGNO (operands[2]) == REGNO (operands[5]))"
10664 [(const_int 0)]
10665 {
10666 if (REGNO (operands[1]) == REGNO (operands[2]))
10667 operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]));
10668
10669 // We don't know what the new set insn will be in detail. Just make sure
10670 // that it still can be recognized and the constraints are satisfied.
10671 rtx_insn* i = emit_insn (gen_rtx_SET (operands[2],
10672 sh_remove_overlapping_post_inc (operands[2], operands[3])));
10673
10674 recog_data_d prev_recog_data = recog_data;
10675 bool i_invalid = insn_invalid_p (i, false);
10676 recog_data = prev_recog_data;
10677
10678 if (i_invalid)
10679 FAIL;
10680
10681 sh_check_add_incdec_notes (i);
10682
10683 emit_insn (gen_tstsi_t (operands[2],
10684 gen_rtx_REG (SImode, (REGNO (operands[1])))));
10685 })
10686
10687 ;; mov.w @(18,r1),r0 (r0 = HImode)
10688 ;; ... ..,r13 (r13 = SImode) mov.w @(18,r1),r0
10689 ;; mov r0,r1 (r0 = r1 = HImode) -> ... ..,r13
10690 ;; tst r1,r13 tst r0,r13
10691 (define_peephole2
10692 [(set (match_operand:SI 2 "arith_reg_dest")
10693 (match_operand:SI 3))
10694 (set (match_operand 0 "arith_reg_dest")
10695 (match_operand 1 "arith_reg_operand"))
10696 (set (reg:SI T_REG)
10697 (eq:SI (and:SI (match_operand:SI 4 "arith_reg_operand")
10698 (match_operand:SI 5 "arith_reg_operand"))
10699 (const_int 0)))]
10700 "TARGET_SH1
10701 && peep2_reg_dead_p (3, operands[0])
10702 && !reg_overlap_mentioned_p (operands[0], operands[3])
10703 && (REGNO (operands[0]) == REGNO (operands[4])
10704 || REGNO (operands[0]) == REGNO (operands[5]))
10705 && (REGNO (operands[2]) == REGNO (operands[4])
10706 || REGNO (operands[2]) == REGNO (operands[5]))"
10707 [(const_int 0)]
10708 {
10709 // We don't know what the new set insn will be in detail. Just make sure
10710 // that it still can be recognized and the constraints are satisfied.
10711 rtx_insn* i = emit_insn (gen_rtx_SET (operands[2],
10712 sh_remove_overlapping_post_inc (operands[2], operands[3])));
10713
10714 recog_data_d prev_recog_data = recog_data;
10715 bool i_invalid = insn_invalid_p (i, false);
10716 recog_data = prev_recog_data;
10717
10718 if (i_invalid)
10719 FAIL;
10720
10721 sh_check_add_incdec_notes (i);
10722
10723 emit_insn (gen_tstsi_t (operands[2],
10724 gen_rtx_REG (SImode, (REGNO (operands[1])))));
10725 })
10726
10727 ;; This is not a peephole, but it's here because it's actually supposed
10728 ;; to be one. It tries to convert a sequence such as
10729 ;; movt r2 -> movt r2
10730 ;; movt r13 mov r2,r13
10731 ;; This gives the schduler a bit more freedom to hoist a following
10732 ;; comparison insn. Moreover, it the reg-reg mov insn is MT group which has
10733 ;; better chances for parallel execution.
10734 ;; We can do this with a peephole2 pattern, but then the cprop_hardreg
10735 ;; pass will revert the change. See also PR 64331.
10736 ;; Thus do it manually in one of the split passes after register allocation.
10737 ;; Sometimes the cprop_hardreg pass might also eliminate the reg-reg copy.
10738 (define_split
10739 [(set (match_operand:SI 0 "arith_reg_dest")
10740 (match_operand:SI 1 "t_reg_operand"))]
10741 "TARGET_SH1 && reload_completed"
10742 [(set (match_dup 0) (match_dup 1))]
10743 {
10744 rtx t_reg = get_t_reg_rtx ();
10745
10746 for (rtx_insn* i = prev_nonnote_insn_bb (curr_insn); i != NULL;
10747 i = prev_nonnote_insn_bb (i))
10748 {
10749 if (!INSN_P (i) || DEBUG_INSN_P (i))
10750 continue;
10751
10752 if (modified_in_p (t_reg, i) || BARRIER_P (i))
10753 FAIL;
10754
10755 if (sh_is_movt_insn (i))
10756 {
10757 rtx r = sh_movt_set_dest (i);
10758 if (!modified_between_p (r, i, curr_insn))
10759 {
10760 operands[1] = r;
10761 break;
10762 }
10763 }
10764 }
10765 })
10766
10767 (define_peephole
10768 [(set (match_operand:SI 0 "register_operand" "=r")
10769 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10770 (set (mem:SF (match_dup 0))
10771 (match_operand:SF 2 "general_movsrc_operand" ""))]
10772 "TARGET_SH1 && REGNO (operands[0]) == 0
10773 && ((REG_P (operands[2]) && REGNO (operands[2]) < 16)
10774 || (GET_CODE (operands[2]) == SUBREG
10775 && REGNO (SUBREG_REG (operands[2])) < 16))
10776 && reg_unused_after (operands[0], insn)"
10777 "mov.l %2,@(%0,%1)")
10778
10779 (define_peephole
10780 [(set (match_operand:SI 0 "register_operand" "=r")
10781 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10782 (set (match_operand:SF 2 "general_movdst_operand" "")
10783
10784 (mem:SF (match_dup 0)))]
10785 "TARGET_SH1 && REGNO (operands[0]) == 0
10786 && ((REG_P (operands[2]) && REGNO (operands[2]) < 16)
10787 || (GET_CODE (operands[2]) == SUBREG
10788 && REGNO (SUBREG_REG (operands[2])) < 16))
10789 && reg_unused_after (operands[0], insn)"
10790 "mov.l @(%0,%1),%2")
10791
10792 (define_peephole
10793 [(set (match_operand:SI 0 "register_operand" "=r")
10794 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10795 (set (mem:SF (match_dup 0))
10796 (match_operand:SF 2 "general_movsrc_operand" ""))]
10797 "TARGET_SH2E && REGNO (operands[0]) == 0
10798 && ((REG_P (operands[2])
10799 && FP_OR_XD_REGISTER_P (REGNO (operands[2])))
10800 || (GET_CODE (operands[2]) == SUBREG
10801 && FP_OR_XD_REGISTER_P (REGNO (SUBREG_REG (operands[2])))))
10802 && reg_unused_after (operands[0], insn)"
10803 "fmov{.s|} %2,@(%0,%1)")
10804
10805 (define_peephole
10806 [(set (match_operand:SI 0 "register_operand" "=r")
10807 (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
10808 (set (match_operand:SF 2 "general_movdst_operand" "")
10809
10810 (mem:SF (match_dup 0)))]
10811 "TARGET_SH2E && REGNO (operands[0]) == 0
10812 && ((REG_P (operands[2])
10813 && FP_OR_XD_REGISTER_P (REGNO (operands[2])))
10814 || (GET_CODE (operands[2]) == SUBREG
10815 && FP_OR_XD_REGISTER_P (REGNO (SUBREG_REG (operands[2])))))
10816 && reg_unused_after (operands[0], insn)"
10817 "fmov{.s|} @(%0,%1),%2")
10818
10819 ;; Switch to a new stack with its address in sp_switch (a SYMBOL_REF).
10820 (define_insn "sp_switch_1"
10821 [(set (reg:SI SP_REG) (unspec_volatile [(match_operand:SI 0 "" "")]
10822 UNSPECV_SP_SWITCH_B))]
10823 "TARGET_SH1"
10824 {
10825 return "mov.l r0,@-r15" "\n"
10826 " mov.l %0,r0" "\n"
10827 " mov.l @r0,r0" "\n"
10828 " mov.l r15,@-r0" "\n"
10829 " mov r0,r15";
10830 }
10831 [(set_attr "length" "10")])
10832
10833 ;; Switch back to the original stack for interrupt functions with the
10834 ;; sp_switch attribute.
10835 (define_insn "sp_switch_2"
10836 [(unspec_volatile [(const_int 0)]
10837 UNSPECV_SP_SWITCH_E)]
10838 "TARGET_SH1"
10839 {
10840 return "mov.l @r15,r15" "\n"
10841 " mov.l @r15+,r0";
10842 }
10843 [(set_attr "length" "4")])
10844
10845
10846 ;; In user mode, the "pref" instruction will raise a RADDERR exception
10847 ;; for accesses to [0x80000000,0xffffffff]. This makes it an unsuitable
10848 ;; implementation of __builtin_prefetch for VxWorks RTPs.
10849 (define_expand "prefetch"
10850 [(prefetch (match_operand 0 "address_operand" "")
10851 (match_operand:SI 1 "const_int_operand" "")
10852 (match_operand:SI 2 "const_int_operand" ""))]
10853 "(TARGET_SH2A || TARGET_SH3) && !TARGET_VXWORKS_RTP")
10854
10855 (define_insn "*prefetch"
10856 [(prefetch (match_operand:SI 0 "register_operand" "r")
10857 (match_operand:SI 1 "const_int_operand" "n")
10858 (match_operand:SI 2 "const_int_operand" "n"))]
10859 "(TARGET_SH2A || TARGET_SH3) && ! TARGET_VXWORKS_RTP"
10860 "pref @%0"
10861 [(set_attr "type" "other")])
10862
10863 ;; -------------------------------------------------------------------------
10864 ;; Stack Protector Patterns
10865 ;; -------------------------------------------------------------------------
10866
10867 (define_expand "stack_protect_set"
10868 [(set (match_operand 0 "memory_operand" "")
10869 (match_operand 1 "memory_operand" ""))]
10870 ""
10871 {
10872 emit_insn (gen_stack_protect_set_si (operands[0], operands[1]));
10873 DONE;
10874 })
10875
10876 (define_insn "stack_protect_set_si"
10877 [(set (match_operand:SI 0 "memory_operand" "=m")
10878 (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
10879 (set (match_scratch:SI 2 "=&r") (const_int 0))]
10880 ""
10881 {
10882 return "mov.l %1,%2" "\n"
10883 " mov.l %2,%0" "\n"
10884 " mov #0,%2";
10885 }
10886 [(set_attr "type" "other")
10887 (set_attr "length" "6")])
10888
10889 (define_expand "stack_protect_test"
10890 [(match_operand 0 "memory_operand" "")
10891 (match_operand 1 "memory_operand" "")
10892 (match_operand 2 "" "")]
10893 ""
10894 {
10895 emit_insn (gen_stack_protect_test_si (operands[0], operands[1]));
10896 emit_jump_insn (gen_branch_true (operands[2]));
10897 DONE;
10898 })
10899
10900 (define_insn "stack_protect_test_si"
10901 [(set (reg:SI T_REG)
10902 (unspec:SI [(match_operand:SI 0 "memory_operand" "m")
10903 (match_operand:SI 1 "memory_operand" "m")]
10904 UNSPEC_SP_TEST))
10905 (set (match_scratch:SI 2 "=&r") (const_int 0))
10906 (set (match_scratch:SI 3 "=&r") (const_int 0))]
10907 ""
10908 {
10909 return "mov.l %0,%2" "\n"
10910 " mov.l %1,%3" "\n"
10911 " cmp/eq %2,%3" "\n"
10912 " mov #0,%2" "\n"
10913 " mov #0,%3";
10914 }
10915 [(set_attr "type" "other")
10916 (set_attr "length" "10")])
10917
10918 ;; -------------------------------------------------------------------------
10919 ;; Atomic operations
10920 ;; -------------------------------------------------------------------------
10921
10922 (include "sync.md")