1 ;; ARM Thumb-2 Machine Description
2 ;; Copyright (C) 2007-2019 Free Software Foundation, Inc.
3 ;; Written by CodeSourcery, LLC.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>. */
21 ;; Note: Thumb-2 is the variant of the Thumb architecture that adds
22 ;; 32-bit encodings of [almost all of] the Arm instruction set.
23 ;; Some old documents refer to the relatively minor interworking
24 ;; changes made in armv5t as "thumb2". These are considered part
25 ;; the 16-bit Thumb-1 instruction set.
27 ;; Thumb-2 only allows shift by constant on data processing instructions
28 (define_insn "*thumb_andsi_not_shiftsi_si"
29 [(set (match_operand:SI 0 "s_register_operand" "=r")
30 (and:SI (not:SI (match_operator:SI 4 "shift_operator"
31 [(match_operand:SI 2 "s_register_operand" "r")
32 (match_operand:SI 3 "const_int_operand" "M")]))
33 (match_operand:SI 1 "s_register_operand" "r")))]
35 "bic%?\\t%0, %1, %2%S4"
36 [(set_attr "predicable" "yes")
37 (set_attr "shift" "2")
38 (set_attr "type" "alu_shift_imm")]
41 ;; We use the '0' constraint for operand 1 because reload should
42 ;; be smart enough to generate an appropriate move for the r/r/r case.
43 (define_insn_and_split "*thumb2_smaxsi3"
44 [(set (match_operand:SI 0 "s_register_operand" "=r,l,r")
45 (smax:SI (match_operand:SI 1 "s_register_operand" "%0,0,0")
46 (match_operand:SI 2 "arm_rhs_operand" "r,Py,I")))
47 (clobber (reg:CC CC_REGNUM))]
50 ; cmp\\t%1, %2\;it\\tlt\;movlt\\t%0, %2
51 "TARGET_THUMB2 && reload_completed"
52 [(set (reg:CC CC_REGNUM)
53 (compare:CC (match_dup 1) (match_dup 2)))
54 (cond_exec (lt:SI (reg:CC CC_REGNUM) (const_int 0))
58 [(set_attr "conds" "clob")
59 (set_attr "enabled_for_short_it" "yes,yes,no")
60 (set_attr "length" "6,6,10")
61 (set_attr "type" "multiple")]
64 (define_insn_and_split "*thumb2_sminsi3"
65 [(set (match_operand:SI 0 "s_register_operand" "=r,l,r")
66 (smin:SI (match_operand:SI 1 "s_register_operand" "%0,0,0")
67 (match_operand:SI 2 "arm_rhs_operand" "r,Py,I")))
68 (clobber (reg:CC CC_REGNUM))]
71 ; cmp\\t%1, %2\;it\\tge\;movge\\t%0, %2
72 "TARGET_THUMB2 && reload_completed"
73 [(set (reg:CC CC_REGNUM)
74 (compare:CC (match_dup 1) (match_dup 2)))
75 (cond_exec (ge:SI (reg:CC CC_REGNUM) (const_int 0))
79 [(set_attr "conds" "clob")
80 (set_attr "enabled_for_short_it" "yes,yes,no")
81 (set_attr "length" "6,6,10")
82 (set_attr "type" "multiple")]
85 (define_insn_and_split "*thumb32_umaxsi3"
86 [(set (match_operand:SI 0 "s_register_operand" "=r,l,r")
87 (umax:SI (match_operand:SI 1 "s_register_operand" "%0,0,0")
88 (match_operand:SI 2 "arm_rhs_operand" "r,Py,I")))
89 (clobber (reg:CC CC_REGNUM))]
92 ; cmp\\t%1, %2\;it\\tcc\;movcc\\t%0, %2
93 "TARGET_THUMB2 && reload_completed"
94 [(set (reg:CC CC_REGNUM)
95 (compare:CC (match_dup 1) (match_dup 2)))
96 (cond_exec (ltu:SI (reg:CC CC_REGNUM) (const_int 0))
100 [(set_attr "conds" "clob")
101 (set_attr "length" "6,6,10")
102 (set_attr "enabled_for_short_it" "yes,yes,no")
103 (set_attr "type" "multiple")]
106 (define_insn_and_split "*thumb2_uminsi3"
107 [(set (match_operand:SI 0 "s_register_operand" "=r,l,r")
108 (umin:SI (match_operand:SI 1 "s_register_operand" "%0,0,0")
109 (match_operand:SI 2 "arm_rhs_operand" "r,Py,I")))
110 (clobber (reg:CC CC_REGNUM))]
113 ; cmp\\t%1, %2\;it\\tcs\;movcs\\t%0, %2
114 "TARGET_THUMB2 && reload_completed"
115 [(set (reg:CC CC_REGNUM)
116 (compare:CC (match_dup 1) (match_dup 2)))
117 (cond_exec (geu:SI (reg:CC CC_REGNUM) (const_int 0))
121 [(set_attr "conds" "clob")
122 (set_attr "length" "6,6,10")
123 (set_attr "enabled_for_short_it" "yes,yes,no")
124 (set_attr "type" "multiple")]
127 (define_insn_and_split "*thumb2_abssi2"
128 [(set (match_operand:SI 0 "s_register_operand" "=&r,l,r")
129 (abs:SI (match_operand:SI 1 "s_register_operand" "r,0,0")))
130 (clobber (reg:CC CC_REGNUM))]
133 ; eor%?\\t%0, %1, %1, asr #31\;sub%?\\t%0, %0, %1, asr #31
134 ; cmp\\t%0, #0\;it\tlt\;rsblt\\t%0, %0, #0
135 ; cmp\\t%0, #0\;it\tlt\;rsblt\\t%0, %0, #0
136 "&& reload_completed"
139 if (REGNO(operands[0]) == REGNO(operands[1]))
141 rtx cc_reg = gen_rtx_REG (CCmode, CC_REGNUM);
143 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (CCmode, operands[0],
145 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
149 (gen_rtx_SET (operands[0],
150 (gen_rtx_MINUS (SImode,
156 emit_insn (gen_rtx_SET (operands[0],
158 gen_rtx_ASHIFTRT (SImode,
162 emit_insn (gen_rtx_SET (operands[0],
163 gen_rtx_MINUS (SImode,
165 gen_rtx_ASHIFTRT (SImode,
171 [(set_attr "conds" "*,clob,clob")
172 (set_attr "shift" "1")
173 (set_attr "predicable" "yes,no,no")
174 (set_attr "enabled_for_short_it" "yes,yes,no")
175 (set_attr "ce_count" "2")
176 (set_attr "length" "8,6,10")
177 (set_attr "type" "multiple")]
180 (define_insn_and_split "*thumb2_neg_abssi2"
181 [(set (match_operand:SI 0 "s_register_operand" "=&r,l,r")
182 (neg:SI (abs:SI (match_operand:SI 1 "s_register_operand" "r,0,0"))))
183 (clobber (reg:CC CC_REGNUM))]
186 ; eor%?\\t%0, %1, %1, asr #31\;rsb%?\\t%0, %0, %1, asr #31
187 ; cmp\\t%0, #0\;it\\tgt\;rsbgt\\t%0, %0, #0
188 ; cmp\\t%0, #0\;it\\tgt\;rsbgt\\t%0, %0, #0
189 "&& reload_completed"
192 if (REGNO(operands[0]) == REGNO(operands[1]))
194 rtx cc_reg = gen_rtx_REG (CCmode, CC_REGNUM);
196 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (CCmode, operands[0],
198 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
202 (gen_rtx_SET (operands[0],
203 (gen_rtx_MINUS (SImode,
209 emit_insn (gen_rtx_SET (operands[0],
211 gen_rtx_ASHIFTRT (SImode,
215 emit_insn (gen_rtx_SET (operands[0],
216 gen_rtx_MINUS (SImode,
217 gen_rtx_ASHIFTRT (SImode,
224 [(set_attr "conds" "*,clob,clob")
225 (set_attr "shift" "1")
226 (set_attr "predicable" "yes,no,no")
227 (set_attr "enabled_for_short_it" "yes,yes,no")
228 (set_attr "ce_count" "2")
229 (set_attr "length" "8,6,10")
230 (set_attr "type" "multiple")]
233 ;; Pop a single register as its size is preferred over a post-incremental load
234 (define_insn "*thumb2_pop_single"
235 [(set (match_operand:SI 0 "low_register_operand" "=r")
236 (mem:SI (post_inc:SI (reg:SI SP_REGNUM))))]
237 "TARGET_THUMB2 && (reload_in_progress || reload_completed)"
239 [(set_attr "type" "load_4")
240 (set_attr "length" "2")
241 (set_attr "predicable" "yes")]
244 ;; We have two alternatives here for memory loads (and similarly for stores)
245 ;; to reflect the fact that the permissible constant pool ranges differ
246 ;; between ldr instructions taking low regs and ldr instructions taking high
247 ;; regs. The high register alternatives are not taken into account when
248 ;; choosing register preferences in order to reflect their expense.
249 (define_insn "*thumb2_movsi_insn"
250 [(set (match_operand:SI 0 "nonimmediate_operand" "=rk,r,l,r,r,lk*r,m")
251 (match_operand:SI 1 "general_operand" "rk,I,Py,K,j,mi,lk*r"))]
252 "TARGET_THUMB2 && !TARGET_IWMMXT && !TARGET_HARD_FLOAT
253 && ( register_operand (operands[0], SImode)
254 || register_operand (operands[1], SImode))"
256 switch (which_alternative)
261 return \"mov%?\\t%0, %1\";
262 case 3: return \"mvn%?\\t%0, #%B1\";
263 case 4: return \"movw%?\\t%0, %1\";
265 /* Cannot load it directly, split to load it via MOV / MOVT. */
266 if (!MEM_P (operands[1]) && arm_disable_literal_pool)
268 return \"ldr%?\\t%0, %1\";
269 case 6: return \"str%?\\t%1, %0\";
270 default: gcc_unreachable ();
273 [(set_attr "type" "mov_reg,mov_imm,mov_imm,mvn_imm,mov_imm,load_4,store_4")
274 (set_attr "length" "2,4,2,4,4,4,4")
275 (set_attr "predicable" "yes")
276 (set_attr "predicable_short_it" "yes,no,yes,no,no,no,no")
277 (set_attr "pool_range" "*,*,*,*,*,1018,*")
278 (set_attr "neg_pool_range" "*,*,*,*,*,0,*")]
281 (define_insn "tls_load_dot_plus_four"
282 [(set (match_operand:SI 0 "register_operand" "=l,l,r,r")
283 (mem:SI (unspec:SI [(match_operand:SI 2 "register_operand" "0,1,0,1")
285 (match_operand 3 "" "")]
287 (clobber (match_scratch:SI 1 "=X,l,X,r"))]
290 (*targetm.asm_out.internal_label) (asm_out_file, \"LPIC\",
291 INTVAL (operands[3]));
292 return \"add\\t%2, %|pc\;ldr%?\\t%0, [%2]\";
294 [(set_attr "length" "4,4,6,6")
295 (set_attr "type" "multiple")]
298 ;; Thumb-2 always has load/store halfword instructions, so we can avoid a lot
299 ;; of the messiness associated with the ARM patterns.
300 (define_insn "*thumb2_movhi_insn"
301 [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,l,r,m,r")
302 (match_operand:HI 1 "general_operand" "rk,I,Py,n,r,m"))]
304 && (register_operand (operands[0], HImode)
305 || register_operand (operands[1], HImode))"
307 mov%?\\t%0, %1\\t%@ movhi
308 mov%?\\t%0, %1\\t%@ movhi
309 mov%?\\t%0, %1\\t%@ movhi
310 movw%?\\t%0, %L1\\t%@ movhi
311 strh%?\\t%1, %0\\t%@ movhi
312 ldrh%?\\t%0, %1\\t%@ movhi"
313 [(set_attr "type" "mov_reg,mov_imm,mov_imm,mov_imm,store_4,load_4")
314 (set_attr "predicable" "yes")
315 (set_attr "predicable_short_it" "yes,no,yes,no,no,no")
316 (set_attr "length" "2,4,2,4,4,4")
317 (set_attr "pool_range" "*,*,*,*,*,4094")
318 (set_attr "neg_pool_range" "*,*,*,*,*,250")]
321 (define_insn "*thumb2_storewb_pairsi"
322 [(set (match_operand:SI 0 "register_operand" "=&kr")
323 (plus:SI (match_operand:SI 1 "register_operand" "0")
324 (match_operand:SI 2 "const_int_operand" "n")))
325 (set (mem:SI (plus:SI (match_dup 0) (match_dup 2)))
326 (match_operand:SI 3 "register_operand" "r"))
327 (set (mem:SI (plus:SI (match_dup 0)
328 (match_operand:SI 5 "const_int_operand" "n")))
329 (match_operand:SI 4 "register_operand" "r"))]
331 && INTVAL (operands[5]) == INTVAL (operands[2]) + 4"
332 "strd\\t%3, %4, [%0, %2]!"
333 [(set_attr "type" "store_8")]
336 (define_insn "*thumb2_cmpsi_neg_shiftsi"
337 [(set (reg:CC CC_REGNUM)
338 (compare:CC (match_operand:SI 0 "s_register_operand" "r")
339 (neg:SI (match_operator:SI 3 "shift_operator"
340 [(match_operand:SI 1 "s_register_operand" "r")
341 (match_operand:SI 2 "const_int_operand" "M")]))))]
344 [(set_attr "conds" "set")
345 (set_attr "shift" "1")
346 (set_attr "type" "alus_shift_imm")]
349 (define_insn_and_split "*thumb2_mov_scc"
350 [(set (match_operand:SI 0 "s_register_operand" "=l,r")
351 (match_operator:SI 1 "arm_comparison_operator_mode"
352 [(match_operand 2 "cc_register" "") (const_int 0)]))]
354 "#" ; "ite\\t%D1\;mov%D1\\t%0, #0\;mov%d1\\t%0, #1"
357 (if_then_else:SI (match_dup 1)
361 [(set_attr "conds" "use")
362 (set_attr "enabled_for_short_it" "yes,no")
363 (set_attr "length" "8,10")
364 (set_attr "type" "multiple")]
367 (define_insn_and_split "*thumb2_mov_negscc"
368 [(set (match_operand:SI 0 "s_register_operand" "=r")
369 (neg:SI (match_operator:SI 1 "arm_comparison_operator_mode"
370 [(match_operand 2 "cc_register" "") (const_int 0)])))]
371 "TARGET_THUMB2 && !arm_restrict_it"
372 "#" ; "ite\\t%D1\;mov%D1\\t%0, #0\;mvn%d1\\t%0, #0"
375 (if_then_else:SI (match_dup 1)
379 operands[3] = GEN_INT (~0);
381 [(set_attr "conds" "use")
382 (set_attr "length" "10")
383 (set_attr "type" "multiple")]
386 (define_insn_and_split "*thumb2_mov_negscc_strict_it"
387 [(set (match_operand:SI 0 "low_register_operand" "=l")
388 (neg:SI (match_operator:SI 1 "arm_comparison_operator_mode"
389 [(match_operand 2 "cc_register" "") (const_int 0)])))]
390 "TARGET_THUMB2 && arm_restrict_it"
391 "#" ; ";mvn\\t%0, #0 ;it\\t%D1\;mov%D1\\t%0, #0\"
392 "&& reload_completed"
395 (cond_exec (match_dup 4)
399 operands[3] = GEN_INT (~0);
400 machine_mode mode = GET_MODE (operands[2]);
401 enum rtx_code rc = GET_CODE (operands[1]);
403 if (mode == CCFPmode || mode == CCFPEmode)
404 rc = reverse_condition_maybe_unordered (rc);
406 rc = reverse_condition (rc);
407 operands[4] = gen_rtx_fmt_ee (rc, VOIDmode, operands[2], const0_rtx);
410 [(set_attr "conds" "use")
411 (set_attr "length" "8")
412 (set_attr "type" "multiple")]
415 (define_insn_and_split "*thumb2_mov_notscc"
416 [(set (match_operand:SI 0 "s_register_operand" "=r")
417 (not:SI (match_operator:SI 1 "arm_comparison_operator_mode"
418 [(match_operand 2 "cc_register" "") (const_int 0)])))]
419 "TARGET_THUMB2 && !arm_restrict_it"
420 "#" ; "ite\\t%D1\;mvn%D1\\t%0, #0\;mvn%d1\\t%0, #1"
423 (if_then_else:SI (match_dup 1)
427 operands[3] = GEN_INT (~1);
428 operands[4] = GEN_INT (~0);
430 [(set_attr "conds" "use")
431 (set_attr "length" "10")
432 (set_attr "type" "multiple")]
435 (define_insn_and_split "*thumb2_mov_notscc_strict_it"
436 [(set (match_operand:SI 0 "low_register_operand" "=l")
437 (not:SI (match_operator:SI 1 "arm_comparison_operator_mode"
438 [(match_operand 2 "cc_register" "") (const_int 0)])))]
439 "TARGET_THUMB2 && arm_restrict_it"
440 "#" ; "mvn %0, #0 ; it%d1 ; lsl%d1 %0, %0, #1"
441 "&& reload_completed"
444 (cond_exec (match_dup 4)
446 (ashift:SI (match_dup 0)
449 operands[3] = GEN_INT (~0);
450 operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
451 VOIDmode, operands[2], const0_rtx);
453 [(set_attr "conds" "use")
454 (set_attr "length" "8")
455 (set_attr "type" "multiple")]
458 (define_insn_and_split "*thumb2_movsicc_insn"
459 [(set (match_operand:SI 0 "s_register_operand" "=l,l,r,r,r,r,r,r,r,r,r,r")
461 (match_operator 3 "arm_comparison_operator"
462 [(match_operand 4 "cc_register" "") (const_int 0)])
463 (match_operand:SI 1 "arm_not_operand" "0 ,lPy,0 ,0,rI,K,I ,r,rI,K ,K,r")
464 (match_operand:SI 2 "arm_not_operand" "lPy,0 ,rI,K,0 ,0,rI,I,K ,rI,K,r")))]
467 it\\t%D3\;mov%D3\\t%0, %2
468 it\\t%d3\;mov%d3\\t%0, %1
469 it\\t%D3\;mov%D3\\t%0, %2
470 it\\t%D3\;mvn%D3\\t%0, #%B2
471 it\\t%d3\;mov%d3\\t%0, %1
472 it\\t%d3\;mvn%d3\\t%0, #%B1
479 ; alt 6: ite\\t%d3\;mov%d3\\t%0, %1\;mov%D3\\t%0, %2
480 ; alt 7: ite\\t%d3\;mov%d3\\t%0, %1\;mov%D3\\t%0, %2
481 ; alt 8: ite\\t%d3\;mov%d3\\t%0, %1\;mvn%D3\\t%0, #%B2
482 ; alt 9: ite\\t%d3\;mvn%d3\\t%0, #%B1\;mov%D3\\t%0, %2
483 ; alt 10: ite\\t%d3\;mvn%d3\\t%0, #%B1\;mvn%D3\\t%0, #%B2
484 ; alt 11: ite\\t%d3\;mov%d3\\t%0, %1\;mov%D3\\t%0, %2
485 "&& reload_completed"
488 enum rtx_code rev_code;
492 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
494 gen_rtx_SET (operands[0], operands[1])));
495 rev_code = GET_CODE (operands[3]);
496 mode = GET_MODE (operands[4]);
497 if (mode == CCFPmode || mode == CCFPEmode)
498 rev_code = reverse_condition_maybe_unordered (rev_code);
500 rev_code = reverse_condition (rev_code);
502 rev_cond = gen_rtx_fmt_ee (rev_code,
504 gen_rtx_REG (mode, CC_REGNUM),
506 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
508 gen_rtx_SET (operands[0], operands[2])));
511 [(set_attr "length" "4,4,6,6,6,6,10,8,10,10,10,6")
512 (set_attr "enabled_for_short_it" "yes,yes,no,no,no,no,no,no,no,no,no,yes")
513 (set_attr "conds" "use")
514 (set_attr_alternative "type"
515 [(if_then_else (match_operand 2 "const_int_operand" "")
516 (const_string "mov_imm")
517 (const_string "mov_reg"))
518 (if_then_else (match_operand 1 "const_int_operand" "")
519 (const_string "mov_imm")
520 (const_string "mov_reg"))
521 (if_then_else (match_operand 2 "const_int_operand" "")
522 (const_string "mov_imm")
523 (const_string "mov_reg"))
524 (const_string "mvn_imm")
525 (if_then_else (match_operand 1 "const_int_operand" "")
526 (const_string "mov_imm")
527 (const_string "mov_reg"))
528 (const_string "mvn_imm")
529 (const_string "multiple")
530 (const_string "multiple")
531 (const_string "multiple")
532 (const_string "multiple")
533 (const_string "multiple")
534 (const_string "multiple")])]
537 (define_insn "*thumb2_movsfcc_soft_insn"
538 [(set (match_operand:SF 0 "s_register_operand" "=r,r")
539 (if_then_else:SF (match_operator 3 "arm_comparison_operator"
540 [(match_operand 4 "cc_register" "") (const_int 0)])
541 (match_operand:SF 1 "s_register_operand" "0,r")
542 (match_operand:SF 2 "s_register_operand" "r,0")))]
543 "TARGET_THUMB2 && TARGET_SOFT_FLOAT"
545 it\\t%D3\;mov%D3\\t%0, %2
546 it\\t%d3\;mov%d3\\t%0, %1"
547 [(set_attr "length" "6,6")
548 (set_attr "conds" "use")
549 (set_attr "type" "multiple")]
552 (define_insn "*call_reg_thumb2"
553 [(call (mem:SI (match_operand:SI 0 "s_register_operand" "r"))
554 (match_operand 1 "" ""))
555 (use (match_operand 2 "" ""))
556 (clobber (reg:SI LR_REGNUM))]
559 [(set_attr "type" "call")]
562 (define_insn "*nonsecure_call_reg_thumb2"
563 [(call (unspec:SI [(mem:SI (reg:SI R4_REGNUM))]
564 UNSPEC_NONSECURE_MEM)
565 (match_operand 0 "" ""))
566 (use (match_operand 1 "" ""))
567 (clobber (reg:SI LR_REGNUM))]
568 "TARGET_THUMB2 && use_cmse"
569 "bl\\t__gnu_cmse_nonsecure_call"
570 [(set_attr "length" "4")
571 (set_attr "type" "call")]
574 (define_insn "*call_value_reg_thumb2"
575 [(set (match_operand 0 "" "")
576 (call (mem:SI (match_operand:SI 1 "register_operand" "l*r"))
577 (match_operand 2 "" "")))
578 (use (match_operand 3 "" ""))
579 (clobber (reg:SI LR_REGNUM))]
582 [(set_attr "type" "call")]
585 (define_insn "*nonsecure_call_value_reg_thumb2"
586 [(set (match_operand 0 "" "")
588 (unspec:SI [(mem:SI (reg:SI R4_REGNUM))]
589 UNSPEC_NONSECURE_MEM)
590 (match_operand 1 "" "")))
591 (use (match_operand 2 "" ""))
592 (clobber (reg:SI LR_REGNUM))]
593 "TARGET_THUMB2 && use_cmse"
594 "bl\t__gnu_cmse_nonsecure_call"
595 [(set_attr "length" "4")
596 (set_attr "type" "call")]
599 (define_insn "*thumb2_indirect_jump"
601 (match_operand:SI 0 "register_operand" "l*r"))]
604 [(set_attr "conds" "clob")
605 (set_attr "type" "branch")]
607 ;; Don't define thumb2_load_indirect_jump because we can't guarantee label
608 ;; addresses will have the thumb bit set correctly.
611 (define_insn_and_split "*thumb2_and_scc"
612 [(set (match_operand:SI 0 "s_register_operand" "=Ts")
613 (and:SI (match_operator:SI 1 "arm_comparison_operator"
614 [(match_operand 2 "cc_register" "") (const_int 0)])
615 (match_operand:SI 3 "s_register_operand" "r")))]
617 "#" ; "and\\t%0, %3, #1\;it\\t%D1\;mov%D1\\t%0, #0"
618 "&& reload_completed"
620 (and:SI (match_dup 3) (const_int 1)))
621 (cond_exec (match_dup 4) (set (match_dup 0) (const_int 0)))]
623 machine_mode mode = GET_MODE (operands[2]);
624 enum rtx_code rc = GET_CODE (operands[1]);
626 if (mode == CCFPmode || mode == CCFPEmode)
627 rc = reverse_condition_maybe_unordered (rc);
629 rc = reverse_condition (rc);
630 operands[4] = gen_rtx_fmt_ee (rc, VOIDmode, operands[2], const0_rtx);
632 [(set_attr "conds" "use")
633 (set_attr "type" "multiple")
634 (set (attr "length") (if_then_else (match_test "arm_restrict_it")
639 (define_insn_and_split "*thumb2_ior_scc"
640 [(set (match_operand:SI 0 "s_register_operand" "=r,r")
641 (ior:SI (match_operator:SI 1 "arm_comparison_operator"
642 [(match_operand 2 "cc_register" "") (const_int 0)])
643 (match_operand:SI 3 "s_register_operand" "0,?r")))]
644 "TARGET_THUMB2 && !arm_restrict_it"
646 it\\t%d1\;orr%d1\\t%0, %3, #1
648 ; alt 1: ite\\t%D1\;mov%D1\\t%0, %3\;orr%d1\\t%0, %3, #1
650 && REGNO (operands [0]) != REGNO (operands[3])"
651 [(cond_exec (match_dup 5) (set (match_dup 0) (match_dup 3)))
652 (cond_exec (match_dup 4) (set (match_dup 0)
653 (ior:SI (match_dup 3) (const_int 1))))]
655 machine_mode mode = GET_MODE (operands[2]);
656 enum rtx_code rc = GET_CODE (operands[1]);
658 operands[4] = gen_rtx_fmt_ee (rc, VOIDmode, operands[2], const0_rtx);
659 if (mode == CCFPmode || mode == CCFPEmode)
660 rc = reverse_condition_maybe_unordered (rc);
662 rc = reverse_condition (rc);
663 operands[5] = gen_rtx_fmt_ee (rc, VOIDmode, operands[2], const0_rtx);
665 [(set_attr "conds" "use")
666 (set_attr "length" "6,10")
667 (set_attr "type" "multiple")]
670 (define_insn_and_split "*thumb2_ior_scc_strict_it"
671 [(set (match_operand:SI 0 "s_register_operand" "=&r")
672 (ior:SI (match_operator:SI 2 "arm_comparison_operator"
673 [(match_operand 3 "cc_register" "") (const_int 0)])
674 (match_operand:SI 1 "s_register_operand" "r")))]
675 "TARGET_THUMB2 && arm_restrict_it"
676 "#" ; orr\\t%0, %1, #1\;it\\t%D2\;mov%D2\\t%0, %1
677 "&& reload_completed"
678 [(set (match_dup 0) (ior:SI (match_dup 1) (const_int 1)))
679 (cond_exec (match_dup 4)
680 (set (match_dup 0) (match_dup 1)))]
682 machine_mode mode = GET_MODE (operands[3]);
683 rtx_code rc = GET_CODE (operands[2]);
685 if (mode == CCFPmode || mode == CCFPEmode)
686 rc = reverse_condition_maybe_unordered (rc);
688 rc = reverse_condition (rc);
689 operands[4] = gen_rtx_fmt_ee (rc, VOIDmode, operands[3], const0_rtx);
691 [(set_attr "conds" "use")
692 (set_attr "length" "8")
693 (set_attr "type" "multiple")]
696 (define_insn "*thumb2_cond_move"
697 [(set (match_operand:SI 0 "s_register_operand" "=r,r,r")
698 (if_then_else:SI (match_operator 3 "equality_operator"
699 [(match_operator 4 "arm_comparison_operator"
700 [(match_operand 5 "cc_register" "") (const_int 0)])
702 (match_operand:SI 1 "arm_rhs_operand" "0,rI,?rI")
703 (match_operand:SI 2 "arm_rhs_operand" "rI,0,rI")))]
706 if (GET_CODE (operands[3]) == NE)
708 if (which_alternative != 1)
709 output_asm_insn (\"it\\t%D4\;mov%D4\\t%0, %2\", operands);
710 if (which_alternative != 0)
711 output_asm_insn (\"it\\t%d4\;mov%d4\\t%0, %1\", operands);
714 switch (which_alternative)
717 output_asm_insn (\"it\\t%d4\", operands);
720 output_asm_insn (\"it\\t%D4\", operands);
724 output_asm_insn (\"it\\t%D4\", operands);
726 output_asm_insn (\"ite\\t%D4\", operands);
731 if (which_alternative != 0)
733 output_asm_insn (\"mov%D4\\t%0, %1\", operands);
734 if (arm_restrict_it && which_alternative == 2)
735 output_asm_insn (\"it\\t%d4\", operands);
737 if (which_alternative != 1)
738 output_asm_insn (\"mov%d4\\t%0, %2\", operands);
741 [(set_attr "conds" "use")
742 (set_attr "length" "6,6,10")
743 (set_attr "type" "multiple")]
746 (define_insn "*thumb2_cond_arith"
747 [(set (match_operand:SI 0 "s_register_operand" "=r,r")
748 (match_operator:SI 5 "shiftable_operator"
749 [(match_operator:SI 4 "arm_comparison_operator"
750 [(match_operand:SI 2 "s_register_operand" "r,r")
751 (match_operand:SI 3 "arm_rhs_operand" "rI,rI")])
752 (match_operand:SI 1 "s_register_operand" "0,?r")]))
753 (clobber (reg:CC CC_REGNUM))]
754 "TARGET_THUMB2 && !arm_restrict_it"
756 if (GET_CODE (operands[4]) == LT && operands[3] == const0_rtx)
757 return \"%i5\\t%0, %1, %2, lsr #31\";
759 output_asm_insn (\"cmp\\t%2, %3\", operands);
760 if (GET_CODE (operands[5]) == AND)
762 output_asm_insn (\"ite\\t%D4\", operands);
763 output_asm_insn (\"mov%D4\\t%0, #0\", operands);
765 else if (GET_CODE (operands[5]) == MINUS)
767 output_asm_insn (\"ite\\t%D4\", operands);
768 output_asm_insn (\"rsb%D4\\t%0, %1, #0\", operands);
770 else if (which_alternative != 0)
772 output_asm_insn (\"ite\\t%D4\", operands);
773 output_asm_insn (\"mov%D4\\t%0, %1\", operands);
776 output_asm_insn (\"it\\t%d4\", operands);
777 return \"%i5%d4\\t%0, %1, #1\";
779 [(set_attr "conds" "clob")
780 (set_attr "length" "14")
781 (set_attr "type" "multiple")]
784 (define_insn_and_split "*thumb2_cond_arith_strict_it"
785 [(set (match_operand:SI 0 "s_register_operand" "=l")
786 (match_operator:SI 5 "shiftable_operator_strict_it"
787 [(match_operator:SI 4 "arm_comparison_operator"
788 [(match_operand:SI 2 "s_register_operand" "r")
789 (match_operand:SI 3 "arm_rhs_operand" "rI")])
790 (match_operand:SI 1 "s_register_operand" "0")]))
791 (clobber (reg:CC CC_REGNUM))]
792 "TARGET_THUMB2 && arm_restrict_it"
794 "&& reload_completed"
797 if (GET_CODE (operands[4]) == LT && operands[3] == const0_rtx)
799 /* %i5 %0, %1, %2, lsr #31 */
800 rtx shifted_op = gen_rtx_LSHIFTRT (SImode, operands[2], GEN_INT (31));
803 switch (GET_CODE (operands[5]))
806 op = gen_rtx_AND (SImode, shifted_op, operands[1]);
809 op = gen_rtx_PLUS (SImode, shifted_op, operands[1]);
811 default: gcc_unreachable ();
813 emit_insn (gen_rtx_SET (operands[0], op));
818 emit_insn (gen_rtx_SET (gen_rtx_REG (CCmode, CC_REGNUM),
819 gen_rtx_COMPARE (CCmode, operands[2],
822 if (GET_CODE (operands[5]) == AND)
827 enum rtx_code rc = reverse_condition (GET_CODE (operands[4]));
828 emit_insn (gen_rtx_SET (operands[0], gen_rtx_AND (SImode, operands[1],
830 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
831 gen_rtx_fmt_ee (rc, VOIDmode, gen_rtx_REG (CCmode, CC_REGNUM), const0_rtx),
832 gen_rtx_SET (operands[0], const0_rtx)));
838 %i5%d4\\t%0, %1, #1 */
839 emit_insn (gen_rtx_COND_EXEC (VOIDmode, gen_rtx_fmt_ee (GET_CODE (operands[4]),
841 gen_rtx_REG (CCmode, CC_REGNUM), const0_rtx),
842 gen_rtx_SET (operands[0],
843 gen_rtx_PLUS (SImode,
850 [(set_attr "conds" "clob")
851 (set_attr "length" "12")
852 (set_attr "type" "multiple")]
855 (define_insn "*thumb2_cond_sub"
856 [(set (match_operand:SI 0 "s_register_operand" "=Ts,Ts")
857 (minus:SI (match_operand:SI 1 "s_register_operand" "0,?Ts")
858 (match_operator:SI 4 "arm_comparison_operator"
859 [(match_operand:SI 2 "s_register_operand" "r,r")
860 (match_operand:SI 3 "arm_rhs_operand" "rI,rI")])))
861 (clobber (reg:CC CC_REGNUM))]
864 output_asm_insn (\"cmp\\t%2, %3\", operands);
865 if (which_alternative != 0)
869 output_asm_insn (\"mov\\t%0, %1\", operands);
870 output_asm_insn (\"it\\t%d4\", operands);
874 output_asm_insn (\"ite\\t%D4\", operands);
875 output_asm_insn (\"mov%D4\\t%0, %1\", operands);
879 output_asm_insn (\"it\\t%d4\", operands);
880 return \"sub%d4\\t%0, %1, #1\";
882 [(set_attr "conds" "clob")
883 (set_attr "length" "10,14")
884 (set_attr "type" "multiple")]
887 (define_insn_and_split "*thumb2_negscc"
888 [(set (match_operand:SI 0 "s_register_operand" "=Ts")
889 (neg:SI (match_operator 3 "arm_comparison_operator"
890 [(match_operand:SI 1 "s_register_operand" "r")
891 (match_operand:SI 2 "arm_rhs_operand" "rI")])))
892 (clobber (reg:CC CC_REGNUM))]
895 "&& reload_completed"
898 rtx cc_reg = gen_rtx_REG (CCmode, CC_REGNUM);
900 if (GET_CODE (operands[3]) == LT && operands[2] == const0_rtx)
902 /* Emit asr\\t%0, %1, #31 */
903 emit_insn (gen_rtx_SET (operands[0],
904 gen_rtx_ASHIFTRT (SImode,
909 else if (GET_CODE (operands[3]) == NE && !arm_restrict_it)
911 /* Emit subs\\t%0, %1, %2\;it\\tne\;mvnne\\t%0, #0 */
912 if (CONST_INT_P (operands[2]))
913 emit_insn (gen_cmpsi2_addneg (operands[0], operands[1], operands[2],
914 gen_int_mode (-INTVAL (operands[2]),
917 emit_insn (gen_subsi3_compare (operands[0], operands[1], operands[2]));
919 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
923 gen_rtx_SET (operands[0],
929 /* Emit: cmp\\t%1, %2\;mvn\\t%0, #0\;it\\t%D3\;mov%D3\\t%0, #0\;*/
930 enum rtx_code rc = reverse_condition (GET_CODE (operands[3]));
931 machine_mode mode = SELECT_CC_MODE (rc, operands[1], operands[2]);
932 rtx tmp1 = gen_rtx_REG (mode, CC_REGNUM);
934 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (CCmode, operands[1],
937 emit_insn (gen_rtx_SET (operands[0], GEN_INT (~0)));
939 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
944 gen_rtx_SET (operands[0], const0_rtx)));
949 [(set_attr "conds" "clob")
950 (set_attr "length" "14")
951 (set_attr "type" "multiple")]
954 (define_insn "*thumb2_movcond"
955 [(set (match_operand:SI 0 "s_register_operand" "=Ts,Ts,Ts")
957 (match_operator 5 "arm_comparison_operator"
958 [(match_operand:SI 3 "s_register_operand" "r,r,r")
959 (match_operand:SI 4 "arm_add_operand" "rIL,rIL,rIL")])
960 (match_operand:SI 1 "arm_rhs_operand" "0,TsI,?TsI")
961 (match_operand:SI 2 "arm_rhs_operand" "TsI,0,TsI")))
962 (clobber (reg:CC CC_REGNUM))]
965 if (GET_CODE (operands[5]) == LT
966 && (operands[4] == const0_rtx))
968 if (which_alternative != 1 && REG_P (operands[1]))
970 if (operands[2] == const0_rtx)
971 return \"and\\t%0, %1, %3, asr #31\";
972 return \"ands\\t%0, %1, %3, asr #32\;it\\tcc\;movcc\\t%0, %2\";
974 else if (which_alternative != 0 && REG_P (operands[2]))
976 if (operands[1] == const0_rtx)
977 return \"bic\\t%0, %2, %3, asr #31\";
978 return \"bics\\t%0, %2, %3, asr #32\;it\\tcs\;movcs\\t%0, %1\";
980 /* The only case that falls through to here is when both ops 1 & 2
984 if (GET_CODE (operands[5]) == GE
985 && (operands[4] == const0_rtx))
987 if (which_alternative != 1 && REG_P (operands[1]))
989 if (operands[2] == const0_rtx)
990 return \"bic\\t%0, %1, %3, asr #31\";
991 return \"bics\\t%0, %1, %3, asr #32\;it\\tcs\;movcs\\t%0, %2\";
993 else if (which_alternative != 0 && REG_P (operands[2]))
995 if (operands[1] == const0_rtx)
996 return \"and\\t%0, %2, %3, asr #31\";
997 return \"ands\\t%0, %2, %3, asr #32\;it\tcc\;movcc\\t%0, %1\";
999 /* The only case that falls through to here is when both ops 1 & 2
1002 if (CONST_INT_P (operands[4])
1003 && !const_ok_for_arm (INTVAL (operands[4])))
1004 output_asm_insn (\"cmn\\t%3, #%n4\", operands);
1006 output_asm_insn (\"cmp\\t%3, %4\", operands);
1007 switch (which_alternative)
1010 output_asm_insn (\"it\\t%D5\", operands);
1013 output_asm_insn (\"it\\t%d5\", operands);
1016 if (arm_restrict_it)
1018 output_asm_insn (\"mov\\t%0, %1\", operands);
1019 output_asm_insn (\"it\\t%D5\", operands);
1022 output_asm_insn (\"ite\\t%d5\", operands);
1027 if (which_alternative != 0 && !(arm_restrict_it && which_alternative == 2))
1028 output_asm_insn (\"mov%d5\\t%0, %1\", operands);
1029 if (which_alternative != 1)
1030 output_asm_insn (\"mov%D5\\t%0, %2\", operands);
1033 [(set_attr "conds" "clob")
1034 (set_attr "length" "10,10,14")
1035 (set_attr "type" "multiple")]
1038 ;; Zero and sign extension instructions.
1040 ;; All supported Thumb2 implementations are armv6, so only that case is
1042 (define_insn "*thumb2_extendqisi_v6"
1043 [(set (match_operand:SI 0 "s_register_operand" "=r,r")
1044 (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1045 "TARGET_THUMB2 && arm_arch6"
1049 [(set_attr "type" "extend,load_byte")
1050 (set_attr "predicable" "yes")
1051 (set_attr "pool_range" "*,4094")
1052 (set_attr "neg_pool_range" "*,250")]
1055 (define_insn "*thumb2_zero_extendhisi2_v6"
1056 [(set (match_operand:SI 0 "s_register_operand" "=r,r")
1057 (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
1058 "TARGET_THUMB2 && arm_arch6"
1062 [(set_attr "type" "extend,load_byte")
1063 (set_attr "predicable" "yes")
1064 (set_attr "pool_range" "*,4094")
1065 (set_attr "neg_pool_range" "*,250")]
1068 (define_insn "thumb2_zero_extendqisi2_v6"
1069 [(set (match_operand:SI 0 "s_register_operand" "=r,r")
1070 (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1071 "TARGET_THUMB2 && arm_arch6"
1074 ldrb%?\\t%0, %1\\t%@ zero_extendqisi2"
1075 [(set_attr "type" "extend,load_byte")
1076 (set_attr "predicable" "yes")
1077 (set_attr "pool_range" "*,4094")
1078 (set_attr "neg_pool_range" "*,250")]
1081 (define_expand "thumb2_casesi_internal"
1082 [(parallel [(set (pc)
1084 (leu (match_operand:SI 0 "s_register_operand")
1085 (match_operand:SI 1 "arm_rhs_operand"))
1087 (label_ref:SI (match_operand 3 ""))))
1088 (clobber (reg:CC CC_REGNUM))
1089 (clobber (match_scratch:SI 5))
1090 (use (label_ref:SI (match_operand 2 "")))])]
1091 "TARGET_THUMB2 && !flag_pic"
1093 operands[4] = gen_rtx_MULT (SImode, operands[0], GEN_INT (4));
1094 operands[4] = gen_rtx_PLUS (SImode, operands[4],
1095 gen_rtx_LABEL_REF (SImode, operands[2]));
1096 operands[4] = gen_rtx_MEM (SImode, operands[4]);
1097 MEM_READONLY_P (operands[4]) = 1;
1098 MEM_NOTRAP_P (operands[4]) = 1;
1101 (define_insn "*thumb2_casesi_internal"
1102 [(parallel [(set (pc)
1104 (leu (match_operand:SI 0 "s_register_operand" "r")
1105 (match_operand:SI 1 "arm_rhs_operand" "rI"))
1106 (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
1107 (label_ref:SI (match_operand 2 "" ""))))
1108 (label_ref:SI (match_operand 3 "" ""))))
1109 (clobber (reg:CC CC_REGNUM))
1110 (clobber (match_scratch:SI 4 "=&r"))
1111 (use (label_ref:SI (match_dup 2)))])]
1112 "TARGET_THUMB2 && !flag_pic"
1113 "* return thumb2_output_casesi(operands);"
1114 [(set_attr "conds" "clob")
1115 (set_attr "length" "16")
1116 (set_attr "type" "multiple")]
1119 (define_expand "thumb2_casesi_internal_pic"
1120 [(parallel [(set (pc)
1122 (leu (match_operand:SI 0 "s_register_operand")
1123 (match_operand:SI 1 "arm_rhs_operand"))
1125 (label_ref:SI (match_operand 3 ""))))
1126 (clobber (reg:CC CC_REGNUM))
1127 (clobber (match_scratch:SI 5))
1128 (clobber (match_scratch:SI 6))
1129 (use (label_ref:SI (match_operand 2 "")))])]
1130 "TARGET_THUMB2 && flag_pic"
1132 operands[4] = gen_rtx_MULT (SImode, operands[0], GEN_INT (4));
1133 operands[4] = gen_rtx_PLUS (SImode, operands[4],
1134 gen_rtx_LABEL_REF (SImode, operands[2]));
1135 operands[4] = gen_rtx_MEM (SImode, operands[4]);
1136 MEM_READONLY_P (operands[4]) = 1;
1137 MEM_NOTRAP_P (operands[4]) = 1;
1140 (define_insn "*thumb2_casesi_internal_pic"
1141 [(parallel [(set (pc)
1143 (leu (match_operand:SI 0 "s_register_operand" "r")
1144 (match_operand:SI 1 "arm_rhs_operand" "rI"))
1145 (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
1146 (label_ref:SI (match_operand 2 "" ""))))
1147 (label_ref:SI (match_operand 3 "" ""))))
1148 (clobber (reg:CC CC_REGNUM))
1149 (clobber (match_scratch:SI 4 "=&r"))
1150 (clobber (match_scratch:SI 5 "=r"))
1151 (use (label_ref:SI (match_dup 2)))])]
1152 "TARGET_THUMB2 && flag_pic"
1153 "* return thumb2_output_casesi(operands);"
1154 [(set_attr "conds" "clob")
1155 (set_attr "length" "20")
1156 (set_attr "type" "multiple")]
1159 (define_insn "*thumb2_return"
1161 "TARGET_THUMB2 && !IS_CMSE_ENTRY (arm_current_func_type ())"
1162 "* return output_return_instruction (const_true_rtx, true, false, true);"
1163 [(set_attr "type" "branch")
1164 (set_attr "length" "4")]
1167 (define_insn "*thumb2_cmse_entry_return"
1169 "TARGET_THUMB2 && IS_CMSE_ENTRY (arm_current_func_type ())"
1170 "* return output_return_instruction (const_true_rtx, true, false, true);"
1171 [(set_attr "type" "branch")
1172 ; This is a return from a cmse_nonsecure_entry function so code will be
1173 ; added to clear the APSR and potentially the FPSCR if VFP is available, so
1174 ; we adapt the length accordingly.
1175 (set (attr "length")
1176 (if_then_else (match_test "TARGET_HARD_FLOAT")
1179 ; We do not support predicate execution of returns from cmse_nonsecure_entry
1180 ; functions because we need to clear the APSR. Since predicable has to be
1181 ; a constant, we had to duplicate the thumb2_return pattern for CMSE entry
1183 (set_attr "predicable" "no")]
1186 (define_insn_and_split "thumb2_eh_return"
1187 [(unspec_volatile [(match_operand:SI 0 "s_register_operand" "r")]
1189 (clobber (match_scratch:SI 1 "=&r"))]
1192 "&& reload_completed"
1196 thumb_set_return_address (operands[0], operands[1]);
1201 (define_insn "*thumb2_alusi3_short"
1202 [(set (match_operand:SI 0 "s_register_operand" "=l")
1203 (match_operator:SI 3 "thumb_16bit_operator"
1204 [(match_operand:SI 1 "s_register_operand" "0")
1205 (match_operand:SI 2 "s_register_operand" "l")]))
1206 (clobber (reg:CC CC_REGNUM))]
1207 "TARGET_THUMB2 && reload_completed
1208 && GET_CODE(operands[3]) != PLUS
1209 && GET_CODE(operands[3]) != MINUS"
1210 "%I3%!\\t%0, %1, %2"
1211 [(set_attr "predicable" "yes")
1212 (set_attr "length" "2")
1213 (set_attr "type" "alu_sreg")]
1216 (define_insn "*thumb2_shiftsi3_short"
1217 [(set (match_operand:SI 0 "low_register_operand" "=l,l")
1218 (match_operator:SI 3 "shift_operator"
1219 [(match_operand:SI 1 "low_register_operand" "0,l")
1220 (match_operand:SI 2 "low_reg_or_int_operand" "l,M")]))
1221 (clobber (reg:CC CC_REGNUM))]
1222 "TARGET_THUMB2 && reload_completed
1223 && ((GET_CODE(operands[3]) != ROTATE && GET_CODE(operands[3]) != ROTATERT)
1224 || REG_P (operands[2]))"
1225 "* return arm_output_shift(operands, 2);"
1226 [(set_attr "predicable" "yes")
1227 (set_attr "shift" "1")
1228 (set_attr "length" "2")
1229 (set (attr "type") (if_then_else (match_operand 2 "const_int_operand" "")
1230 (const_string "alu_shift_imm")
1231 (const_string "alu_shift_reg")))]
1234 (define_insn "*thumb2_mov<mode>_shortim"
1235 [(set (match_operand:QHSI 0 "low_register_operand" "=l")
1236 (match_operand:QHSI 1 "const_int_operand" "I"))
1237 (clobber (reg:CC CC_REGNUM))]
1238 "TARGET_THUMB2 && reload_completed"
1240 [(set_attr "predicable" "yes")
1241 (set_attr "length" "2")
1242 (set_attr "type" "mov_imm")]
1245 (define_insn "*thumb2_addsi_short"
1246 [(set (match_operand:SI 0 "low_register_operand" "=l,l")
1247 (plus:SI (match_operand:SI 1 "low_register_operand" "l,0")
1248 (match_operand:SI 2 "low_reg_or_int_operand" "lPt,Ps")))
1249 (clobber (reg:CC CC_REGNUM))]
1250 "TARGET_THUMB2 && reload_completed"
1254 if (CONST_INT_P (operands[2]))
1255 val = INTVAL(operands[2]);
1259 /* We prefer eg. subs rn, rn, #1 over adds rn, rn, #0xffffffff. */
1260 if (val < 0 && const_ok_for_arm(ARM_SIGN_EXTEND (-val)))
1261 return \"sub%!\\t%0, %1, #%n2\";
1263 return \"add%!\\t%0, %1, %2\";
1265 [(set_attr "predicable" "yes")
1266 (set_attr "length" "2")
1267 (set_attr_alternative "type"
1268 [(if_then_else (match_operand 2 "const_int_operand" "")
1269 (const_string "alu_imm")
1270 (const_string "alu_sreg"))
1271 (const_string "alu_imm")])]
1274 (define_insn "*thumb2_subsi_short"
1275 [(set (match_operand:SI 0 "low_register_operand" "=l")
1276 (minus:SI (match_operand:SI 1 "low_register_operand" "l")
1277 (match_operand:SI 2 "low_register_operand" "l")))
1278 (clobber (reg:CC CC_REGNUM))]
1279 "TARGET_THUMB2 && reload_completed"
1280 "sub%!\\t%0, %1, %2"
1281 [(set_attr "predicable" "yes")
1282 (set_attr "length" "2")
1283 (set_attr "type" "alu_sreg")]
1287 [(set (match_operand:CC 0 "cc_register" "")
1288 (compare:CC (match_operand:SI 1 "low_register_operand" "")
1289 (match_operand:SI 2 "const_int_operand" "")))]
1291 && peep2_reg_dead_p (1, operands[1])
1292 && satisfies_constraint_Pw (operands[2])"
1294 [(set (match_dup 0) (compare:CC (match_dup 1) (match_dup 2)))
1295 (set (match_dup 1) (plus:SI (match_dup 1) (match_dup 3)))])]
1296 "operands[3] = GEN_INT (- INTVAL (operands[2]));"
1300 [(match_scratch:SI 3 "l")
1301 (set (match_operand:CC 0 "cc_register" "")
1302 (compare:CC (match_operand:SI 1 "low_register_operand" "")
1303 (match_operand:SI 2 "const_int_operand" "")))]
1305 && satisfies_constraint_Px (operands[2])"
1307 [(set (match_dup 0) (compare:CC (match_dup 1) (match_dup 2)))
1308 (set (match_dup 3) (plus:SI (match_dup 1) (match_dup 4)))])]
1309 "operands[4] = GEN_INT (- INTVAL (operands[2]));"
1312 (define_insn "thumb2_addsi3_compare0"
1313 [(set (reg:CC_NOOV CC_REGNUM)
1315 (plus:SI (match_operand:SI 1 "s_register_operand" "l, 0, r")
1316 (match_operand:SI 2 "arm_add_operand" "lPt,Ps,rIL"))
1318 (set (match_operand:SI 0 "s_register_operand" "=l,l,r")
1319 (plus:SI (match_dup 1) (match_dup 2)))]
1324 if (CONST_INT_P (operands[2]))
1325 val = INTVAL (operands[2]);
1329 if (val < 0 && const_ok_for_arm (ARM_SIGN_EXTEND (-val)))
1330 return \"subs\\t%0, %1, #%n2\";
1332 return \"adds\\t%0, %1, %2\";
1334 [(set_attr "conds" "set")
1335 (set_attr "length" "2,2,4")
1336 (set_attr_alternative "type"
1337 [(if_then_else (match_operand 2 "const_int_operand" "")
1338 (const_string "alus_imm")
1339 (const_string "alus_sreg"))
1340 (const_string "alus_imm")
1341 (if_then_else (match_operand 2 "const_int_operand" "")
1342 (const_string "alus_imm")
1343 (const_string "alus_sreg"))])]
1346 (define_insn "*thumb2_addsi3_compare0_scratch"
1347 [(set (reg:CC_NOOV CC_REGNUM)
1349 (plus:SI (match_operand:SI 0 "s_register_operand" "l, r")
1350 (match_operand:SI 1 "arm_add_operand" "lPv,rIL"))
1356 if (CONST_INT_P (operands[1]))
1357 val = INTVAL (operands[1]);
1361 if (val < 0 && const_ok_for_arm (ARM_SIGN_EXTEND (-val)))
1362 return \"cmp\\t%0, #%n1\";
1364 return \"cmn\\t%0, %1\";
1366 [(set_attr "conds" "set")
1367 (set_attr "length" "2,4")
1368 (set (attr "type") (if_then_else (match_operand 1 "const_int_operand" "")
1369 (const_string "alus_imm")
1370 (const_string "alus_sreg")))]
1373 (define_insn "*thumb2_mulsi_short"
1374 [(set (match_operand:SI 0 "low_register_operand" "=l")
1375 (mult:SI (match_operand:SI 1 "low_register_operand" "%0")
1376 (match_operand:SI 2 "low_register_operand" "l")))
1377 (clobber (reg:CC CC_REGNUM))]
1378 "TARGET_THUMB2 && optimize_size && reload_completed"
1379 "mul%!\\t%0, %2, %0"
1380 [(set_attr "predicable" "yes")
1381 (set_attr "length" "2")
1382 (set_attr "type" "muls")])
1384 (define_insn "*thumb2_mulsi_short_compare0"
1385 [(set (reg:CC_NOOV CC_REGNUM)
1387 (mult:SI (match_operand:SI 1 "register_operand" "%0")
1388 (match_operand:SI 2 "register_operand" "l"))
1390 (set (match_operand:SI 0 "register_operand" "=l")
1391 (mult:SI (match_dup 1) (match_dup 2)))]
1392 "TARGET_THUMB2 && optimize_size"
1394 [(set_attr "length" "2")
1395 (set_attr "type" "muls")])
1397 (define_insn "*thumb2_mulsi_short_compare0_scratch"
1398 [(set (reg:CC_NOOV CC_REGNUM)
1400 (mult:SI (match_operand:SI 1 "register_operand" "%0")
1401 (match_operand:SI 2 "register_operand" "l"))
1403 (clobber (match_scratch:SI 0 "=l"))]
1404 "TARGET_THUMB2 && optimize_size"
1406 [(set_attr "length" "2")
1407 (set_attr "type" "muls")])
1409 (define_insn "*thumb2_cbz"
1410 [(set (pc) (if_then_else
1411 (eq (match_operand:SI 0 "s_register_operand" "l,?r")
1413 (label_ref (match_operand 1 "" ""))
1415 (clobber (reg:CC CC_REGNUM))]
1418 if (get_attr_length (insn) == 2)
1419 return \"cbz\\t%0, %l1\";
1421 return \"cmp\\t%0, #0\;beq\\t%l1\";
1423 [(set (attr "length")
1425 (and (ge (minus (match_dup 1) (pc)) (const_int 2))
1426 (le (minus (match_dup 1) (pc)) (const_int 128))
1427 (not (match_test "which_alternative")))
1430 (set_attr "type" "branch,multiple")]
1433 (define_insn "*thumb2_cbnz"
1434 [(set (pc) (if_then_else
1435 (ne (match_operand:SI 0 "s_register_operand" "l,?r")
1437 (label_ref (match_operand 1 "" ""))
1439 (clobber (reg:CC CC_REGNUM))]
1442 if (get_attr_length (insn) == 2)
1443 return \"cbnz\\t%0, %l1\";
1445 return \"cmp\\t%0, #0\;bne\\t%l1\";
1447 [(set (attr "length")
1449 (and (ge (minus (match_dup 1) (pc)) (const_int 2))
1450 (le (minus (match_dup 1) (pc)) (const_int 128))
1451 (not (match_test "which_alternative")))
1454 (set_attr "type" "branch,multiple")]
1457 (define_insn "*thumb2_one_cmplsi2_short"
1458 [(set (match_operand:SI 0 "low_register_operand" "=l")
1459 (not:SI (match_operand:SI 1 "low_register_operand" "l")))
1460 (clobber (reg:CC CC_REGNUM))]
1461 "TARGET_THUMB2 && reload_completed"
1463 [(set_attr "predicable" "yes")
1464 (set_attr "length" "2")
1465 (set_attr "type" "mvn_reg")]
1468 (define_insn "*thumb2_negsi2_short"
1469 [(set (match_operand:SI 0 "low_register_operand" "=l")
1470 (neg:SI (match_operand:SI 1 "low_register_operand" "l")))
1471 (clobber (reg:CC CC_REGNUM))]
1472 "TARGET_THUMB2 && reload_completed"
1474 [(set_attr "predicable" "yes")
1475 (set_attr "length" "2")
1476 (set_attr "type" "alu_sreg")]
1479 ; Constants for op 2 will never be given to these patterns.
1480 (define_insn_and_split "*iordi_notdi_di"
1481 [(set (match_operand:DI 0 "s_register_operand" "=&r,&r")
1482 (ior:DI (not:DI (match_operand:DI 1 "s_register_operand" "0,r"))
1483 (match_operand:DI 2 "s_register_operand" "r,0")))]
1486 "TARGET_THUMB2 && reload_completed"
1487 [(set (match_dup 0) (ior:SI (not:SI (match_dup 1)) (match_dup 2)))
1488 (set (match_dup 3) (ior:SI (not:SI (match_dup 4)) (match_dup 5)))]
1491 operands[3] = gen_highpart (SImode, operands[0]);
1492 operands[0] = gen_lowpart (SImode, operands[0]);
1493 operands[4] = gen_highpart (SImode, operands[1]);
1494 operands[1] = gen_lowpart (SImode, operands[1]);
1495 operands[5] = gen_highpart (SImode, operands[2]);
1496 operands[2] = gen_lowpart (SImode, operands[2]);
1498 [(set_attr "length" "8")
1499 (set_attr "predicable" "yes")
1500 (set_attr "predicable_short_it" "no")
1501 (set_attr "type" "multiple")]
1504 (define_insn_and_split "*iordi_notzesidi_di"
1505 [(set (match_operand:DI 0 "s_register_operand" "=&r,&r")
1506 (ior:DI (not:DI (zero_extend:DI
1507 (match_operand:SI 2 "s_register_operand" "r,r")))
1508 (match_operand:DI 1 "s_register_operand" "0,?r")))]
1511 ; (not (zero_extend...)) means operand0 will always be 0xffffffff
1512 "TARGET_THUMB2 && reload_completed"
1513 [(set (match_dup 0) (ior:SI (not:SI (match_dup 2)) (match_dup 1)))
1514 (set (match_dup 3) (const_int -1))]
1517 operands[3] = gen_highpart (SImode, operands[0]);
1518 operands[0] = gen_lowpart (SImode, operands[0]);
1519 operands[1] = gen_lowpart (SImode, operands[1]);
1521 [(set_attr "length" "4,8")
1522 (set_attr "predicable" "yes")
1523 (set_attr "predicable_short_it" "no")
1524 (set_attr "type" "multiple")]
1527 (define_insn_and_split "*iordi_notdi_zesidi"
1528 [(set (match_operand:DI 0 "s_register_operand" "=&r,&r")
1529 (ior:DI (not:DI (match_operand:DI 2 "s_register_operand" "0,?r"))
1531 (match_operand:SI 1 "s_register_operand" "r,r"))))]
1534 "TARGET_THUMB2 && reload_completed"
1535 [(set (match_dup 0) (ior:SI (not:SI (match_dup 2)) (match_dup 1)))
1536 (set (match_dup 3) (not:SI (match_dup 4)))]
1539 operands[3] = gen_highpart (SImode, operands[0]);
1540 operands[0] = gen_lowpart (SImode, operands[0]);
1541 operands[1] = gen_lowpart (SImode, operands[1]);
1542 operands[4] = gen_highpart (SImode, operands[2]);
1543 operands[2] = gen_lowpart (SImode, operands[2]);
1545 [(set_attr "length" "8")
1546 (set_attr "predicable" "yes")
1547 (set_attr "predicable_short_it" "no")
1548 (set_attr "type" "multiple")]
1551 (define_insn_and_split "*iordi_notsesidi_di"
1552 [(set (match_operand:DI 0 "s_register_operand" "=&r,&r")
1553 (ior:DI (not:DI (sign_extend:DI
1554 (match_operand:SI 2 "s_register_operand" "r,r")))
1555 (match_operand:DI 1 "s_register_operand" "0,r")))]
1558 "TARGET_THUMB2 && reload_completed"
1559 [(set (match_dup 0) (ior:SI (not:SI (match_dup 2)) (match_dup 1)))
1560 (set (match_dup 3) (ior:SI (not:SI
1561 (ashiftrt:SI (match_dup 2) (const_int 31)))
1565 operands[3] = gen_highpart (SImode, operands[0]);
1566 operands[0] = gen_lowpart (SImode, operands[0]);
1567 operands[4] = gen_highpart (SImode, operands[1]);
1568 operands[1] = gen_lowpart (SImode, operands[1]);
1570 [(set_attr "length" "8")
1571 (set_attr "predicable" "yes")
1572 (set_attr "predicable_short_it" "no")
1573 (set_attr "type" "multiple")]
1576 (define_insn "*orsi_notsi_si"
1577 [(set (match_operand:SI 0 "s_register_operand" "=r")
1578 (ior:SI (not:SI (match_operand:SI 2 "s_register_operand" "r"))
1579 (match_operand:SI 1 "s_register_operand" "r")))]
1581 "orn%?\\t%0, %1, %2"
1582 [(set_attr "predicable" "yes")
1583 (set_attr "type" "logic_reg")]
1586 (define_insn "*orsi_not_shiftsi_si"
1587 [(set (match_operand:SI 0 "s_register_operand" "=r")
1588 (ior:SI (not:SI (match_operator:SI 4 "shift_operator"
1589 [(match_operand:SI 2 "s_register_operand" "r")
1590 (match_operand:SI 3 "const_int_operand" "M")]))
1591 (match_operand:SI 1 "s_register_operand" "r")))]
1593 "orn%?\\t%0, %1, %2%S4"
1594 [(set_attr "predicable" "yes")
1595 (set_attr "shift" "2")
1596 (set_attr "type" "alu_shift_imm")]
1600 [(set (match_operand:CC_NOOV 0 "cc_register" "")
1601 (compare:CC_NOOV (zero_extract:SI
1602 (match_operand:SI 1 "low_register_operand" "")
1604 (match_operand:SI 2 "const_int_operand" ""))
1606 (match_scratch:SI 3 "l")
1608 (if_then_else (match_operator:CC_NOOV 4 "equality_operator"
1609 [(match_dup 0) (const_int 0)])
1610 (match_operand 5 "" "")
1611 (match_operand 6 "" "")))]
1613 && (INTVAL (operands[2]) >= 0 && INTVAL (operands[2]) < 32)
1614 && peep2_reg_dead_p (2, operands[0])"
1615 [(parallel [(set (match_dup 0)
1616 (compare:CC_NOOV (ashift:SI (match_dup 1) (match_dup 2))
1618 (clobber (match_dup 3))])
1620 (if_then_else (match_op_dup 4 [(match_dup 0) (const_int 0)])
1621 (match_dup 5) (match_dup 6)))]
1623 operands[2] = GEN_INT (31 - INTVAL (operands[2]));
1624 operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[4]) == NE ? LT : GE,
1625 VOIDmode, operands[0], const0_rtx);
1629 [(set (match_operand:CC_NOOV 0 "cc_register" "")
1630 (compare:CC_NOOV (zero_extract:SI
1631 (match_operand:SI 1 "low_register_operand" "")
1632 (match_operand:SI 2 "const_int_operand" "")
1635 (match_scratch:SI 3 "l")
1637 (if_then_else (match_operator:CC_NOOV 4 "equality_operator"
1638 [(match_dup 0) (const_int 0)])
1639 (match_operand 5 "" "")
1640 (match_operand 6 "" "")))]
1642 && (INTVAL (operands[2]) > 0 && INTVAL (operands[2]) < 32)
1643 && peep2_reg_dead_p (2, operands[0])"
1644 [(parallel [(set (match_dup 0)
1645 (compare:CC_NOOV (ashift:SI (match_dup 1) (match_dup 2))
1647 (clobber (match_dup 3))])
1649 (if_then_else (match_op_dup 4 [(match_dup 0) (const_int 0)])
1650 (match_dup 5) (match_dup 6)))]
1652 operands[2] = GEN_INT (32 - INTVAL (operands[2]));
1655 ;; Define the subtract-one-and-jump insns so loop.c
1656 ;; knows what to generate.
1657 (define_expand "doloop_end"
1658 [(use (match_operand 0 "" "")) ; loop pseudo
1659 (use (match_operand 1 "" ""))] ; label
1663 /* Currently SMS relies on the do-loop pattern to recognize loops
1664 where (1) the control part consists of all insns defining and/or
1665 using a certain 'count' register and (2) the loop count can be
1666 adjusted by modifying this register prior to the loop.
1667 ??? The possible introduction of a new block to initialize the
1668 new IV can potentially affect branch optimizations. */
1669 if (optimize > 0 && flag_modulo_sched)
1678 if (GET_MODE (operands[0]) != SImode)
1683 insn = emit_insn (gen_thumb2_addsi3_compare0 (s0, s0, GEN_INT (-1)));
1685 insn = emit_insn (gen_addsi3_compare0 (s0, s0, GEN_INT (-1)));
1687 cmp = XVECEXP (PATTERN (insn), 0, 0);
1688 cc_reg = SET_DEST (cmp);
1689 bcomp = gen_rtx_NE (VOIDmode, cc_reg, const0_rtx);
1690 loc_ref = gen_rtx_LABEL_REF (VOIDmode, operands [1]);
1691 emit_jump_insn (gen_rtx_SET (pc_rtx,
1692 gen_rtx_IF_THEN_ELSE (VOIDmode, bcomp,