Merged r158229 through r158464 into branch.
[official-gcc.git] / gcc / config / arm / thumb2.md
blob3e2c3daea3b32fbaafdac232709c4faaf5e59aa2
1 ;; ARM Thumb-2 Machine Description
2 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 ;; Written by CodeSourcery, LLC.
4 ;;
5 ;; This file is part of GCC.
6 ;;
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)
10 ;; any later version.
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 (define_insn "*thumb2_incscc"
28   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
29         (plus:SI (match_operator:SI 2 "arm_comparison_operator"
30                     [(match_operand:CC 3 "cc_register" "") (const_int 0)])
31                  (match_operand:SI 1 "s_register_operand" "0,?r")))]
32   "TARGET_THUMB2"
33   "@
34   it\\t%d2\;add%d2\\t%0, %1, #1
35   ite\\t%D2\;mov%D2\\t%0, %1\;add%d2\\t%0, %1, #1"
36   [(set_attr "conds" "use")
37    (set_attr "length" "6,10")]
40 (define_insn "*thumb2_decscc"
41   [(set (match_operand:SI            0 "s_register_operand" "=r,r")
42         (minus:SI (match_operand:SI  1 "s_register_operand" "0,?r")
43                   (match_operator:SI 2 "arm_comparison_operator"
44                    [(match_operand   3 "cc_register" "") (const_int 0)])))]
45   "TARGET_THUMB2"
46   "@
47    it\\t%d2\;sub%d2\\t%0, %1, #1
48    ite\\t%D2\;mov%D2\\t%0, %1\;sub%d2\\t%0, %1, #1"
49   [(set_attr "conds" "use")
50    (set_attr "length" "6,10")]
53 ;; Thumb-2 only allows shift by constant on data processing instructions 
54 (define_insn "*thumb_andsi_not_shiftsi_si"
55   [(set (match_operand:SI 0 "s_register_operand" "=r")
56         (and:SI (not:SI (match_operator:SI 4 "shift_operator"
57                          [(match_operand:SI 2 "s_register_operand" "r")
58                           (match_operand:SI 3 "const_int_operand" "M")]))
59                 (match_operand:SI 1 "s_register_operand" "r")))]
60   "TARGET_THUMB2"
61   "bic%?\\t%0, %1, %2%S4"
62   [(set_attr "predicable" "yes")
63    (set_attr "shift" "2")
64    (set_attr "type" "alu_shift")]
67 (define_insn "*thumb2_smaxsi3"
68   [(set (match_operand:SI          0 "s_register_operand" "=r,r,r")
69         (smax:SI (match_operand:SI 1 "s_register_operand"  "0,r,?r")
70                  (match_operand:SI 2 "arm_rhs_operand"    "rI,0,rI")))
71    (clobber (reg:CC CC_REGNUM))]
72   "TARGET_THUMB2"
73   "@
74    cmp\\t%1, %2\;it\\tlt\;movlt\\t%0, %2
75    cmp\\t%1, %2\;it\\tge\;movge\\t%0, %1
76    cmp\\t%1, %2\;ite\\tge\;movge\\t%0, %1\;movlt\\t%0, %2"
77   [(set_attr "conds" "clob")
78    (set_attr "length" "10,10,14")]
81 (define_insn "*thumb2_sminsi3"
82   [(set (match_operand:SI 0 "s_register_operand" "=r,r,r")
83         (smin:SI (match_operand:SI 1 "s_register_operand" "0,r,?r")
84                  (match_operand:SI 2 "arm_rhs_operand" "rI,0,rI")))
85    (clobber (reg:CC CC_REGNUM))]
86   "TARGET_THUMB2"
87   "@
88    cmp\\t%1, %2\;it\\tge\;movge\\t%0, %2
89    cmp\\t%1, %2\;it\\tlt\;movlt\\t%0, %1
90    cmp\\t%1, %2\;ite\\tlt\;movlt\\t%0, %1\;movge\\t%0, %2"
91   [(set_attr "conds" "clob")
92    (set_attr "length" "10,10,14")]
95 (define_insn "*thumb32_umaxsi3"
96   [(set (match_operand:SI 0 "s_register_operand" "=r,r,r")
97         (umax:SI (match_operand:SI 1 "s_register_operand" "0,r,?r")
98                  (match_operand:SI 2 "arm_rhs_operand" "rI,0,rI")))
99    (clobber (reg:CC CC_REGNUM))]
100   "TARGET_THUMB2"
101   "@
102    cmp\\t%1, %2\;it\\tcc\;movcc\\t%0, %2
103    cmp\\t%1, %2\;it\\tcs\;movcs\\t%0, %1
104    cmp\\t%1, %2\;ite\\tcs\;movcs\\t%0, %1\;movcc\\t%0, %2"
105   [(set_attr "conds" "clob")
106    (set_attr "length" "10,10,14")]
109 (define_insn "*thumb2_uminsi3"
110   [(set (match_operand:SI 0 "s_register_operand" "=r,r,r")
111         (umin:SI (match_operand:SI 1 "s_register_operand" "0,r,?r")
112                  (match_operand:SI 2 "arm_rhs_operand" "rI,0,rI")))
113    (clobber (reg:CC CC_REGNUM))]
114   "TARGET_THUMB2"
115   "@
116    cmp\\t%1, %2\;it\\tcs\;movcs\\t%0, %2
117    cmp\\t%1, %2\;it\\tcc\;movcc\\t%0, %1
118    cmp\\t%1, %2\;ite\\tcc\;movcc\\t%0, %1\;movcs\\t%0, %2"
119   [(set_attr "conds" "clob")
120    (set_attr "length" "10,10,14")]
123 (define_insn "*thumb2_notsi_shiftsi"
124   [(set (match_operand:SI 0 "s_register_operand" "=r")
125         (not:SI (match_operator:SI 3 "shift_operator"
126                  [(match_operand:SI 1 "s_register_operand" "r")
127                   (match_operand:SI 2 "const_int_operand"  "M")])))]
128   "TARGET_THUMB2"
129   "mvn%?\\t%0, %1%S3"
130   [(set_attr "predicable" "yes")
131    (set_attr "shift" "1")
132    (set_attr "type" "alu_shift")]
135 (define_insn "*thumb2_notsi_shiftsi_compare0"
136   [(set (reg:CC_NOOV CC_REGNUM)
137         (compare:CC_NOOV (not:SI (match_operator:SI 3 "shift_operator"
138                           [(match_operand:SI 1 "s_register_operand" "r")
139                            (match_operand:SI 2 "const_int_operand"  "M")]))
140                          (const_int 0)))
141    (set (match_operand:SI 0 "s_register_operand" "=r")
142         (not:SI (match_op_dup 3 [(match_dup 1) (match_dup 2)])))]
143   "TARGET_THUMB2"
144   "mvn%.\\t%0, %1%S3"
145   [(set_attr "conds" "set")
146    (set_attr "shift" "1")
147    (set_attr "type" "alu_shift")]
150 (define_insn "*thumb2_not_shiftsi_compare0_scratch"
151   [(set (reg:CC_NOOV CC_REGNUM)
152         (compare:CC_NOOV (not:SI (match_operator:SI 3 "shift_operator"
153                           [(match_operand:SI 1 "s_register_operand" "r")
154                            (match_operand:SI 2 "const_int_operand"  "M")]))
155                          (const_int 0)))
156    (clobber (match_scratch:SI 0 "=r"))]
157   "TARGET_THUMB2"
158   "mvn%.\\t%0, %1%S3"
159   [(set_attr "conds" "set")
160    (set_attr "shift" "1")
161    (set_attr "type" "alu_shift")]
164 ;; Thumb-2 does not have rsc, so use a clever trick with shifter operands.
165 (define_insn "*thumb2_negdi2"
166   [(set (match_operand:DI         0 "s_register_operand" "=&r,r")
167         (neg:DI (match_operand:DI 1 "s_register_operand"  "?r,0")))
168    (clobber (reg:CC CC_REGNUM))]
169   "TARGET_THUMB2"
170   "negs\\t%Q0, %Q1\;sbc\\t%R0, %R1, %R1, lsl #1"
171   [(set_attr "conds" "clob")
172    (set_attr "length" "8")]
175 (define_insn "*thumb2_abssi2"
176   [(set (match_operand:SI         0 "s_register_operand" "=r,&r")
177         (abs:SI (match_operand:SI 1 "s_register_operand" "0,r")))
178    (clobber (reg:CC CC_REGNUM))]
179   "TARGET_THUMB2"
180   "@
181    cmp\\t%0, #0\;it\tlt\;rsblt\\t%0, %0, #0
182    eor%?\\t%0, %1, %1, asr #31\;sub%?\\t%0, %0, %1, asr #31"
183   [(set_attr "conds" "clob,*")
184    (set_attr "shift" "1")
185    ;; predicable can't be set based on the variant, so left as no
186    (set_attr "length" "10,8")]
189 (define_insn "*thumb2_neg_abssi2"
190   [(set (match_operand:SI 0 "s_register_operand" "=r,&r")
191         (neg:SI (abs:SI (match_operand:SI 1 "s_register_operand" "0,r"))))
192    (clobber (reg:CC CC_REGNUM))]
193   "TARGET_THUMB2"
194   "@
195    cmp\\t%0, #0\;it\\tgt\;rsbgt\\t%0, %0, #0
196    eor%?\\t%0, %1, %1, asr #31\;rsb%?\\t%0, %0, %1, asr #31"
197   [(set_attr "conds" "clob,*")
198    (set_attr "shift" "1")
199    ;; predicable can't be set based on the variant, so left as no
200    (set_attr "length" "10,8")]
203 (define_insn "*thumb2_movdi"
204   [(set (match_operand:DI 0 "nonimmediate_di_operand" "=r, r, r, r, m")
205         (match_operand:DI 1 "di_operand"              "rDa,Db,Dc,mi,r"))]
206   "TARGET_THUMB2
207   && !(TARGET_HARD_FLOAT && (TARGET_MAVERICK || TARGET_VFP))
208   && !TARGET_IWMMXT"
209   "*
210   switch (which_alternative)
211     {
212     case 0:
213     case 1:
214     case 2:
215       return \"#\";
216     default:
217       return output_move_double (operands);
218     }
219   "
220   [(set_attr "length" "8,12,16,8,8")
221    (set_attr "type" "*,*,*,load2,store2")
222    (set_attr "pool_range" "*,*,*,4096,*")
223    (set_attr "neg_pool_range" "*,*,*,0,*")]
226 ;; We have two alternatives here for memory loads (and similarly for stores)
227 ;; to reflect the fact that the permissible constant pool ranges differ
228 ;; between ldr instructions taking low regs and ldr instructions taking high
229 ;; regs.  The high register alternatives are not taken into account when
230 ;; choosing register preferences in order to reflect their expense.
231 (define_insn "*thumb2_movsi_insn"
232   [(set (match_operand:SI 0 "nonimmediate_operand" "=rk,r,r,r,l ,*hk,m,*m")
233         (match_operand:SI 1 "general_operand"      "rk ,I,K,j,mi,*mi,l,*hk"))]
234   "TARGET_THUMB2 && ! TARGET_IWMMXT
235    && !(TARGET_HARD_FLOAT && TARGET_VFP)
236    && (   register_operand (operands[0], SImode)
237        || register_operand (operands[1], SImode))"
238   "@
239    mov%?\\t%0, %1
240    mov%?\\t%0, %1
241    mvn%?\\t%0, #%B1
242    movw%?\\t%0, %1
243    ldr%?\\t%0, %1
244    ldr%?\\t%0, %1
245    str%?\\t%1, %0
246    str%?\\t%1, %0"
247   [(set_attr "type" "*,*,*,*,load1,load1,store1,store1")
248    (set_attr "predicable" "yes")
249    (set_attr "pool_range" "*,*,*,*,1020,4096,*,*")
250    (set_attr "neg_pool_range" "*,*,*,*,0,0,*,*")]
253 (define_insn "tls_load_dot_plus_four"
254   [(set (match_operand:SI 0 "register_operand" "=l,l,r,r")
255         (mem:SI (unspec:SI [(match_operand:SI 2 "register_operand" "0,1,0,1")
256                             (const_int 4)
257                             (match_operand 3 "" "")]
258                            UNSPEC_PIC_BASE)))
259    (clobber (match_scratch:SI 1 "=X,l,X,r"))]
260   "TARGET_THUMB2"
261   "*
262   (*targetm.asm_out.internal_label) (asm_out_file, \"LPIC\",
263                              INTVAL (operands[3]));
264   return \"add\\t%2, %|pc\;ldr%?\\t%0, [%2]\";
265   "
266   [(set_attr "length" "4,4,6,6")]
269 ;; Thumb-2 always has load/store halfword instructions, so we can avoid a lot
270 ;; of the messiness associated with the ARM patterns.
271 (define_insn "*thumb2_movhi_insn"
272   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r")    
273         (match_operand:HI 1 "general_operand"      "rI,n,r,m"))]
274   "TARGET_THUMB2"
275   "@
276    mov%?\\t%0, %1\\t%@ movhi
277    movw%?\\t%0, %L1\\t%@ movhi
278    str%(h%)\\t%1, %0\\t%@ movhi
279    ldr%(h%)\\t%0, %1\\t%@ movhi"
280   [(set_attr "type" "*,*,store1,load1")
281    (set_attr "predicable" "yes")
282    (set_attr "pool_range" "*,*,*,4096")
283    (set_attr "neg_pool_range" "*,*,*,250")]
286 (define_insn "*thumb2_movsf_soft_insn"
287   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m")
288         (match_operand:SF 1 "general_operand"  "r,mE,r"))]
289   "TARGET_THUMB2
290    && TARGET_SOFT_FLOAT
291    && (GET_CODE (operands[0]) != MEM
292        || register_operand (operands[1], SFmode))"
293   "@
294    mov%?\\t%0, %1
295    ldr%?\\t%0, %1\\t%@ float
296    str%?\\t%1, %0\\t%@ float"
297   [(set_attr "predicable" "yes")
298    (set_attr "type" "*,load1,store1")
299    (set_attr "pool_range" "*,4096,*")
300    (set_attr "neg_pool_range" "*,0,*")]
303 (define_insn "*thumb2_movdf_soft_insn"
304   [(set (match_operand:DF 0 "nonimmediate_soft_df_operand" "=r,r,r,r,m")
305         (match_operand:DF 1 "soft_df_operand" "rDa,Db,Dc,mF,r"))]
306   "TARGET_THUMB2 && TARGET_SOFT_FLOAT
307    && (   register_operand (operands[0], DFmode)
308        || register_operand (operands[1], DFmode))"
309   "*
310   switch (which_alternative)
311     {
312     case 0:
313     case 1:
314     case 2:
315       return \"#\";
316     default:
317       return output_move_double (operands);
318     }
319   "
320   [(set_attr "length" "8,12,16,8,8")
321    (set_attr "type" "*,*,*,load2,store2")
322    (set_attr "pool_range" "1020")
323    (set_attr "neg_pool_range" "0")]
326 (define_insn "*thumb2_cmpsi_shiftsi"
327   [(set (reg:CC CC_REGNUM)
328         (compare:CC (match_operand:SI   0 "s_register_operand" "r")
329                     (match_operator:SI  3 "shift_operator"
330                      [(match_operand:SI 1 "s_register_operand" "r")
331                       (match_operand:SI 2 "const_int_operand"  "M")])))]
332   "TARGET_THUMB2"
333   "cmp%?\\t%0, %1%S3"
334   [(set_attr "conds" "set")
335    (set_attr "shift" "1")
336    (set_attr "type" "alu_shift")]
339 (define_insn "*thumb2_cmpsi_shiftsi_swp"
340   [(set (reg:CC_SWP CC_REGNUM)
341         (compare:CC_SWP (match_operator:SI 3 "shift_operator"
342                          [(match_operand:SI 1 "s_register_operand" "r")
343                           (match_operand:SI 2 "const_int_operand" "M")])
344                         (match_operand:SI 0 "s_register_operand" "r")))]
345   "TARGET_THUMB2"
346   "cmp%?\\t%0, %1%S3"
347   [(set_attr "conds" "set")
348    (set_attr "shift" "1")
349    (set_attr "type" "alu_shift")]
352 (define_insn "*thumb2_cmpsi_neg_shiftsi"
353   [(set (reg:CC CC_REGNUM)
354         (compare:CC (match_operand:SI 0 "s_register_operand" "r")
355                     (neg:SI (match_operator:SI 3 "shift_operator"
356                              [(match_operand:SI 1 "s_register_operand" "r")
357                               (match_operand:SI 2 "const_int_operand" "M")]))))]
358   "TARGET_THUMB2"
359   "cmn%?\\t%0, %1%S3"
360   [(set_attr "conds" "set")
361    (set_attr "shift" "1")
362    (set_attr "type" "alu_shift")]
365 (define_insn "*thumb2_mov_scc"
366   [(set (match_operand:SI 0 "s_register_operand" "=r")
367         (match_operator:SI 1 "arm_comparison_operator"
368          [(match_operand 2 "cc_register" "") (const_int 0)]))]
369   "TARGET_THUMB2"
370   "ite\\t%D1\;mov%D1\\t%0, #0\;mov%d1\\t%0, #1"
371   [(set_attr "conds" "use")
372    (set_attr "length" "10")]
375 (define_insn "*thumb2_mov_negscc"
376   [(set (match_operand:SI 0 "s_register_operand" "=r")
377         (neg:SI (match_operator:SI 1 "arm_comparison_operator"
378                  [(match_operand 2 "cc_register" "") (const_int 0)])))]
379   "TARGET_THUMB2"
380   "ite\\t%D1\;mov%D1\\t%0, #0\;mvn%d1\\t%0, #0"
381   [(set_attr "conds" "use")
382    (set_attr "length" "10")]
385 (define_insn "*thumb2_mov_notscc"
386   [(set (match_operand:SI 0 "s_register_operand" "=r")
387         (not:SI (match_operator:SI 1 "arm_comparison_operator"
388                  [(match_operand 2 "cc_register" "") (const_int 0)])))]
389   "TARGET_THUMB2"
390   "ite\\t%D1\;mov%D1\\t%0, #0\;mvn%d1\\t%0, #1"
391   [(set_attr "conds" "use")
392    (set_attr "length" "10")]
395 (define_insn "*thumb2_movsicc_insn"
396   [(set (match_operand:SI 0 "s_register_operand" "=r,r,r,r,r,r,r,r")
397         (if_then_else:SI
398          (match_operator 3 "arm_comparison_operator"
399           [(match_operand 4 "cc_register" "") (const_int 0)])
400          (match_operand:SI 1 "arm_not_operand" "0,0,rI,K,rI,rI,K,K")
401          (match_operand:SI 2 "arm_not_operand" "rI,K,0,0,rI,K,rI,K")))]
402   "TARGET_THUMB2"
403   "@
404    it\\t%D3\;mov%D3\\t%0, %2
405    it\\t%D3\;mvn%D3\\t%0, #%B2
406    it\\t%d3\;mov%d3\\t%0, %1
407    it\\t%d3\;mvn%d3\\t%0, #%B1
408    ite\\t%d3\;mov%d3\\t%0, %1\;mov%D3\\t%0, %2
409    ite\\t%d3\;mov%d3\\t%0, %1\;mvn%D3\\t%0, #%B2
410    ite\\t%d3\;mvn%d3\\t%0, #%B1\;mov%D3\\t%0, %2
411    ite\\t%d3\;mvn%d3\\t%0, #%B1\;mvn%D3\\t%0, #%B2"
412   [(set_attr "length" "6,6,6,6,10,10,10,10")
413    (set_attr "conds" "use")]
416 (define_insn "*thumb2_movsfcc_soft_insn"
417   [(set (match_operand:SF 0 "s_register_operand" "=r,r")
418         (if_then_else:SF (match_operator 3 "arm_comparison_operator"
419                           [(match_operand 4 "cc_register" "") (const_int 0)])
420                          (match_operand:SF 1 "s_register_operand" "0,r")
421                          (match_operand:SF 2 "s_register_operand" "r,0")))]
422   "TARGET_THUMB2 && TARGET_SOFT_FLOAT"
423   "@
424    it\\t%D3\;mov%D3\\t%0, %2
425    it\\t%d3\;mov%d3\\t%0, %1"
426   [(set_attr "length" "6,6")
427    (set_attr "conds" "use")]
430 (define_insn "*call_reg_thumb2"
431   [(call (mem:SI (match_operand:SI 0 "s_register_operand" "r"))
432          (match_operand 1 "" ""))
433    (use (match_operand 2 "" ""))
434    (clobber (reg:SI LR_REGNUM))]
435   "TARGET_THUMB2"
436   "blx%?\\t%0"
437   [(set_attr "type" "call")]
440 (define_insn "*call_value_reg_thumb2"
441   [(set (match_operand 0 "" "")
442         (call (mem:SI (match_operand:SI 1 "register_operand" "l*r"))
443               (match_operand 2 "" "")))
444    (use (match_operand 3 "" ""))
445    (clobber (reg:SI LR_REGNUM))]
446   "TARGET_THUMB2"
447   "blx\\t%1"
448   [(set_attr "type" "call")]
451 (define_insn "*thumb2_indirect_jump"
452   [(set (pc)
453         (match_operand:SI 0 "register_operand" "l*r"))]
454   "TARGET_THUMB2"
455   "bx\\t%0"
456   [(set_attr "conds" "clob")]
458 ;; Don't define thumb2_load_indirect_jump because we can't guarantee label
459 ;; addresses will have the thumb bit set correctly. 
462 ;; Patterns to allow combination of arithmetic, cond code and shifts
464 (define_insn "*thumb2_arith_shiftsi"
465   [(set (match_operand:SI 0 "s_register_operand" "=r")
466         (match_operator:SI 1 "shiftable_operator"
467           [(match_operator:SI 3 "shift_operator"
468              [(match_operand:SI 4 "s_register_operand" "r")
469               (match_operand:SI 5 "const_int_operand" "M")])
470            (match_operand:SI 2 "s_register_operand" "r")]))]
471   "TARGET_THUMB2"
472   "%i1%?\\t%0, %2, %4%S3"
473   [(set_attr "predicable" "yes")
474    (set_attr "shift" "4")
475    (set_attr "type" "alu_shift")]
478 ;; ??? What does this splitter do?  Copied from the ARM version
479 (define_split
480   [(set (match_operand:SI 0 "s_register_operand" "")
481         (match_operator:SI 1 "shiftable_operator"
482          [(match_operator:SI 2 "shiftable_operator"
483            [(match_operator:SI 3 "shift_operator"
484              [(match_operand:SI 4 "s_register_operand" "")
485               (match_operand:SI 5 "const_int_operand" "")])
486             (match_operand:SI 6 "s_register_operand" "")])
487           (match_operand:SI 7 "arm_rhs_operand" "")]))
488    (clobber (match_operand:SI 8 "s_register_operand" ""))]
489   "TARGET_32BIT"
490   [(set (match_dup 8)
491         (match_op_dup 2 [(match_op_dup 3 [(match_dup 4) (match_dup 5)])
492                          (match_dup 6)]))
493    (set (match_dup 0)
494         (match_op_dup 1 [(match_dup 8) (match_dup 7)]))]
495   "")
497 (define_insn "*thumb2_arith_shiftsi_compare0"
498   [(set (reg:CC_NOOV CC_REGNUM)
499         (compare:CC_NOOV (match_operator:SI 1 "shiftable_operator"
500                           [(match_operator:SI 3 "shift_operator"
501                             [(match_operand:SI 4 "s_register_operand" "r")
502                              (match_operand:SI 5 "const_int_operand" "M")])
503                            (match_operand:SI 2 "s_register_operand" "r")])
504                          (const_int 0)))
505    (set (match_operand:SI 0 "s_register_operand" "=r")
506         (match_op_dup 1 [(match_op_dup 3 [(match_dup 4) (match_dup 5)])
507                          (match_dup 2)]))]
508   "TARGET_32BIT"
509   "%i1%.\\t%0, %2, %4%S3"
510   [(set_attr "conds" "set")
511    (set_attr "shift" "4")
512    (set_attr "type" "alu_shift")]
515 (define_insn "*thumb2_arith_shiftsi_compare0_scratch"
516   [(set (reg:CC_NOOV CC_REGNUM)
517         (compare:CC_NOOV (match_operator:SI 1 "shiftable_operator"
518                           [(match_operator:SI 3 "shift_operator"
519                             [(match_operand:SI 4 "s_register_operand" "r")
520                              (match_operand:SI 5 "const_int_operand" "M")])
521                            (match_operand:SI 2 "s_register_operand" "r")])
522                          (const_int 0)))
523    (clobber (match_scratch:SI 0 "=r"))]
524   "TARGET_THUMB2"
525   "%i1%.\\t%0, %2, %4%S3"
526   [(set_attr "conds" "set")
527    (set_attr "shift" "4")
528    (set_attr "type" "alu_shift")]
531 (define_insn "*thumb2_sub_shiftsi"
532   [(set (match_operand:SI 0 "s_register_operand" "=r")
533         (minus:SI (match_operand:SI 1 "s_register_operand" "r")
534                   (match_operator:SI 2 "shift_operator"
535                    [(match_operand:SI 3 "s_register_operand" "r")
536                     (match_operand:SI 4 "const_int_operand" "M")])))]
537   "TARGET_THUMB2"
538   "sub%?\\t%0, %1, %3%S2"
539   [(set_attr "predicable" "yes")
540    (set_attr "shift" "3")
541    (set_attr "type" "alu_shift")]
544 (define_insn "*thumb2_sub_shiftsi_compare0"
545   [(set (reg:CC_NOOV CC_REGNUM)
546         (compare:CC_NOOV
547          (minus:SI (match_operand:SI 1 "s_register_operand" "r")
548                    (match_operator:SI 2 "shift_operator"
549                     [(match_operand:SI 3 "s_register_operand" "r")
550                      (match_operand:SI 4 "const_int_operand" "M")]))
551          (const_int 0)))
552    (set (match_operand:SI 0 "s_register_operand" "=r")
553         (minus:SI (match_dup 1) (match_op_dup 2 [(match_dup 3)
554                                                  (match_dup 4)])))]
555   "TARGET_THUMB2"
556   "sub%.\\t%0, %1, %3%S2"
557   [(set_attr "conds" "set")
558    (set_attr "shift" "3")
559    (set_attr "type" "alu_shift")]
562 (define_insn "*thumb2_sub_shiftsi_compare0_scratch"
563   [(set (reg:CC_NOOV CC_REGNUM)
564         (compare:CC_NOOV
565          (minus:SI (match_operand:SI 1 "s_register_operand" "r")
566                    (match_operator:SI 2 "shift_operator"
567                     [(match_operand:SI 3 "s_register_operand" "r")
568                      (match_operand:SI 4 "const_int_operand" "M")]))
569          (const_int 0)))
570    (clobber (match_scratch:SI 0 "=r"))]
571   "TARGET_THUMB2"
572   "sub%.\\t%0, %1, %3%S2"
573   [(set_attr "conds" "set")
574    (set_attr "shift" "3")
575    (set_attr "type" "alu_shift")]
578 (define_insn "*thumb2_and_scc"
579   [(set (match_operand:SI 0 "s_register_operand" "=r")
580         (and:SI (match_operator:SI 1 "arm_comparison_operator"
581                  [(match_operand 3 "cc_register" "") (const_int 0)])
582                 (match_operand:SI 2 "s_register_operand" "r")))]
583   "TARGET_THUMB2"
584   "ite\\t%D1\;mov%D1\\t%0, #0\;and%d1\\t%0, %2, #1"
585   [(set_attr "conds" "use")
586    (set_attr "length" "10")]
589 (define_insn "*thumb2_ior_scc"
590   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
591         (ior:SI (match_operator:SI 2 "arm_comparison_operator"
592                  [(match_operand 3 "cc_register" "") (const_int 0)])
593                 (match_operand:SI 1 "s_register_operand" "0,?r")))]
594   "TARGET_THUMB2"
595   "@
596    it\\t%d2\;orr%d2\\t%0, %1, #1
597    ite\\t%D2\;mov%D2\\t%0, %1\;orr%d2\\t%0, %1, #1"
598   [(set_attr "conds" "use")
599    (set_attr "length" "6,10")]
602 (define_insn "*thumb2_compare_scc"
603   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
604         (match_operator:SI 1 "arm_comparison_operator"
605          [(match_operand:SI 2 "s_register_operand" "r,r")
606           (match_operand:SI 3 "arm_add_operand" "rI,L")]))
607    (clobber (reg:CC CC_REGNUM))]
608   "TARGET_THUMB2"
609   "*
610     if (operands[3] == const0_rtx)
611       {
612         if (GET_CODE (operands[1]) == LT)
613           return \"lsr\\t%0, %2, #31\";
615         if (GET_CODE (operands[1]) == GE)
616           return \"mvn\\t%0, %2\;lsr\\t%0, %0, #31\";
618         if (GET_CODE (operands[1]) == EQ)
619           return \"rsbs\\t%0, %2, #1\;it\\tcc\;movcc\\t%0, #0\";
620       }
622     if (GET_CODE (operands[1]) == NE)
623       {
624         if (which_alternative == 1)
625           return \"adds\\t%0, %2, #%n3\;it\\tne\;movne\\t%0, #1\";
626         return \"subs\\t%0, %2, %3\;it\\tne\;movne\\t%0, #1\";
627       }
628     if (which_alternative == 1)
629       output_asm_insn (\"cmn\\t%2, #%n3\", operands);
630     else
631       output_asm_insn (\"cmp\\t%2, %3\", operands);
632     return \"ite\\t%D1\;mov%D1\\t%0, #0\;mov%d1\\t%0, #1\";
633   "
634   [(set_attr "conds" "clob")
635    (set_attr "length" "14")]
638 (define_insn "*thumb2_cond_move"
639   [(set (match_operand:SI 0 "s_register_operand" "=r,r,r")
640         (if_then_else:SI (match_operator 3 "equality_operator"
641                           [(match_operator 4 "arm_comparison_operator"
642                             [(match_operand 5 "cc_register" "") (const_int 0)])
643                            (const_int 0)])
644                          (match_operand:SI 1 "arm_rhs_operand" "0,rI,?rI")
645                          (match_operand:SI 2 "arm_rhs_operand" "rI,0,rI")))]
646   "TARGET_THUMB2"
647   "*
648     if (GET_CODE (operands[3]) == NE)
649       {
650         if (which_alternative != 1)
651           output_asm_insn (\"it\\t%D4\;mov%D4\\t%0, %2\", operands);
652         if (which_alternative != 0)
653           output_asm_insn (\"it\\t%d4\;mov%d4\\t%0, %1\", operands);
654         return \"\";
655       }
656     switch (which_alternative)
657       {
658       case 0:
659         output_asm_insn (\"it\\t%d4\", operands);
660         break;
661       case 1:
662         output_asm_insn (\"it\\t%D4\", operands);
663         break;
664       case 2:
665         output_asm_insn (\"ite\\t%D4\", operands);
666         break;
667       default:
668         abort();
669       }
670     if (which_alternative != 0)
671       output_asm_insn (\"mov%D4\\t%0, %1\", operands);
672     if (which_alternative != 1)
673       output_asm_insn (\"mov%d4\\t%0, %2\", operands);
674     return \"\";
675   "
676   [(set_attr "conds" "use")
677    (set_attr "length" "6,6,10")]
680 (define_insn "*thumb2_cond_arith"
681   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
682         (match_operator:SI 5 "shiftable_operator" 
683          [(match_operator:SI 4 "arm_comparison_operator"
684            [(match_operand:SI 2 "s_register_operand" "r,r")
685             (match_operand:SI 3 "arm_rhs_operand" "rI,rI")])
686           (match_operand:SI 1 "s_register_operand" "0,?r")]))
687    (clobber (reg:CC CC_REGNUM))]
688   "TARGET_THUMB2"
689   "*
690     if (GET_CODE (operands[4]) == LT && operands[3] == const0_rtx)
691       return \"%i5\\t%0, %1, %2, lsr #31\";
693     output_asm_insn (\"cmp\\t%2, %3\", operands);
694     if (GET_CODE (operands[5]) == AND)
695       {
696         output_asm_insn (\"ite\\t%D4\", operands);
697         output_asm_insn (\"mov%D4\\t%0, #0\", operands);
698       }
699     else if (GET_CODE (operands[5]) == MINUS)
700       {
701         output_asm_insn (\"ite\\t%D4\", operands);
702         output_asm_insn (\"rsb%D4\\t%0, %1, #0\", operands);
703       }
704     else if (which_alternative != 0)
705       {
706         output_asm_insn (\"ite\\t%D4\", operands);
707         output_asm_insn (\"mov%D4\\t%0, %1\", operands);
708       }
709     else
710       output_asm_insn (\"it\\t%d4\", operands);
711     return \"%i5%d4\\t%0, %1, #1\";
712   "
713   [(set_attr "conds" "clob")
714    (set_attr "length" "14")]
717 (define_insn "*thumb2_cond_sub"
718   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
719         (minus:SI (match_operand:SI 1 "s_register_operand" "0,?r")
720                   (match_operator:SI 4 "arm_comparison_operator"
721                    [(match_operand:SI 2 "s_register_operand" "r,r")
722                     (match_operand:SI 3 "arm_rhs_operand" "rI,rI")])))
723    (clobber (reg:CC CC_REGNUM))]
724   "TARGET_THUMB2"
725   "*
726     output_asm_insn (\"cmp\\t%2, %3\", operands);
727     if (which_alternative != 0)
728       {
729         output_asm_insn (\"ite\\t%D4\", operands);
730         output_asm_insn (\"mov%D4\\t%0, %1\", operands);
731       }
732     else
733       output_asm_insn (\"it\\t%d4\", operands);
734     return \"sub%d4\\t%0, %1, #1\";
735   "
736   [(set_attr "conds" "clob")
737    (set_attr "length" "10,14")]
740 (define_insn "*thumb2_negscc"
741   [(set (match_operand:SI 0 "s_register_operand" "=r")
742         (neg:SI (match_operator 3 "arm_comparison_operator"
743                  [(match_operand:SI 1 "s_register_operand" "r")
744                   (match_operand:SI 2 "arm_rhs_operand" "rI")])))
745    (clobber (reg:CC CC_REGNUM))]
746   "TARGET_THUMB2"
747   "*
748   if (GET_CODE (operands[3]) == LT && operands[2] == const0_rtx)
749     return \"asr\\t%0, %1, #31\";
751   if (GET_CODE (operands[3]) == NE)
752     return \"subs\\t%0, %1, %2\;it\\tne\;mvnne\\t%0, #0\";
754   output_asm_insn (\"cmp\\t%1, %2\", operands);
755   output_asm_insn (\"ite\\t%D3\", operands);
756   output_asm_insn (\"mov%D3\\t%0, #0\", operands);
757   return \"mvn%d3\\t%0, #0\";
758   "
759   [(set_attr "conds" "clob")
760    (set_attr "length" "14")]
763 (define_insn "*thumb2_movcond"
764   [(set (match_operand:SI 0 "s_register_operand" "=r,r,r")
765         (if_then_else:SI
766          (match_operator 5 "arm_comparison_operator"
767           [(match_operand:SI 3 "s_register_operand" "r,r,r")
768            (match_operand:SI 4 "arm_add_operand" "rIL,rIL,rIL")])
769          (match_operand:SI 1 "arm_rhs_operand" "0,rI,?rI")
770          (match_operand:SI 2 "arm_rhs_operand" "rI,0,rI")))
771    (clobber (reg:CC CC_REGNUM))]
772   "TARGET_THUMB2"
773   "*
774   if (GET_CODE (operands[5]) == LT
775       && (operands[4] == const0_rtx))
776     {
777       if (which_alternative != 1 && GET_CODE (operands[1]) == REG)
778         {
779           if (operands[2] == const0_rtx)
780             return \"and\\t%0, %1, %3, asr #31\";
781           return \"ands\\t%0, %1, %3, asr #32\;it\\tcc\;movcc\\t%0, %2\";
782         }
783       else if (which_alternative != 0 && GET_CODE (operands[2]) == REG)
784         {
785           if (operands[1] == const0_rtx)
786             return \"bic\\t%0, %2, %3, asr #31\";
787           return \"bics\\t%0, %2, %3, asr #32\;it\\tcs\;movcs\\t%0, %1\";
788         }
789       /* The only case that falls through to here is when both ops 1 & 2
790          are constants.  */
791     }
793   if (GET_CODE (operands[5]) == GE
794       && (operands[4] == const0_rtx))
795     {
796       if (which_alternative != 1 && GET_CODE (operands[1]) == REG)
797         {
798           if (operands[2] == const0_rtx)
799             return \"bic\\t%0, %1, %3, asr #31\";
800           return \"bics\\t%0, %1, %3, asr #32\;it\\tcs\;movcs\\t%0, %2\";
801         }
802       else if (which_alternative != 0 && GET_CODE (operands[2]) == REG)
803         {
804           if (operands[1] == const0_rtx)
805             return \"and\\t%0, %2, %3, asr #31\";
806           return \"ands\\t%0, %2, %3, asr #32\;it\tcc\;movcc\\t%0, %1\";
807         }
808       /* The only case that falls through to here is when both ops 1 & 2
809          are constants.  */
810     }
811   if (GET_CODE (operands[4]) == CONST_INT
812       && !const_ok_for_arm (INTVAL (operands[4])))
813     output_asm_insn (\"cmn\\t%3, #%n4\", operands);
814   else
815     output_asm_insn (\"cmp\\t%3, %4\", operands);
816   switch (which_alternative)
817     {
818     case 0:
819       output_asm_insn (\"it\\t%D5\", operands);
820       break;
821     case 1:
822       output_asm_insn (\"it\\t%d5\", operands);
823       break;
824     case 2:
825       output_asm_insn (\"ite\\t%d5\", operands);
826       break;
827     default:
828       abort();
829     }
830   if (which_alternative != 0)
831     output_asm_insn (\"mov%d5\\t%0, %1\", operands);
832   if (which_alternative != 1)
833     output_asm_insn (\"mov%D5\\t%0, %2\", operands);
834   return \"\";
835   "
836   [(set_attr "conds" "clob")
837    (set_attr "length" "10,10,14")]
840 ;; Zero and sign extension instructions.
842 (define_insn_and_split "*thumb2_zero_extendsidi2"
843   [(set (match_operand:DI 0 "s_register_operand" "=r")
844         (zero_extend:DI (match_operand:SI 1 "s_register_operand" "r")))]
845   "TARGET_THUMB2"
846   "mov%?\\t%Q0, %1\;mov%?\\t%R0, #0"
847   "&& reload_completed"
848   [(set (match_dup 0) (match_dup 1))]
849   "
850   {
851     rtx lo_part = gen_lowpart (SImode, operands[0]);
852     if (!REG_P (lo_part) || REGNO (lo_part) != REGNO (operands[1]))
853       emit_move_insn (lo_part, operands[1]);
854     operands[0] = gen_highpart (SImode, operands[0]);
855     operands[1] = const0_rtx;
856   }
857   "
858   [(set_attr "length" "8")
859    (set_attr "ce_count" "2")
860    (set_attr "predicable" "yes")]
863 (define_insn_and_split "*thumb2_zero_extendhidi2"
864   [(set (match_operand:DI                 0 "s_register_operand"  "=r,r")
865         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
866   "TARGET_THUMB2"
867   "@
868    uxth%?\\t%Q0, %1\;mov%?\\t%R0, #0
869    ldr%(h%)\\t%Q0, %1\;mov%?\\t%R0, #0"
870   "&& reload_completed"
871   [(set (match_dup 0) (zero_extend:SI (match_dup 1)))
872    (set (match_dup 2) (match_dup 3))]
873   "
874   {
875     operands[2] = gen_highpart (SImode, operands[0]);
876     operands[0] = gen_lowpart (SImode, operands[0]);
877     operands[3] = const0_rtx;
878   }
879   "
880   [(set_attr "length" "8")
881    (set_attr "ce_count" "2")
882    (set_attr "predicable" "yes")
883    (set_attr "type" "*,load_byte")
884    (set_attr "pool_range" "*,4092")
885    (set_attr "neg_pool_range" "*,250")]
888 (define_insn_and_split "*thumb2_zero_extendqidi2"
889   [(set (match_operand:DI                 0 "s_register_operand"  "=r,r")
890         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
891   "TARGET_THUMB2"
892   "@
893    uxtb%?\\t%Q0, %1\;mov%?\\t%R0, #0
894    ldr%(b%)\\t%Q0, %1\;mov%?\\t%R0, #0"
895   "&& reload_completed"
896   [(set (match_dup 0) (zero_extend:SI (match_dup 1)))
897    (set (match_dup 2) (match_dup 3))]
898   "
899   {
900     operands[2] = gen_highpart (SImode, operands[0]);
901     operands[0] = gen_lowpart (SImode, operands[0]);
902     operands[3] = const0_rtx;
903   }
904   "
905   [(set_attr "length" "8")
906    (set_attr "ce_count" "2")
907    (set_attr "predicable" "yes")
908    (set_attr "type" "*,load_byte")
909    (set_attr "pool_range" "*,4092")
910    (set_attr "neg_pool_range" "*,250")]
913 (define_insn_and_split "*thumb2_extendsidi2"
914   [(set (match_operand:DI 0 "s_register_operand" "=r")
915         (sign_extend:DI (match_operand:SI 1 "s_register_operand" "r")))]
916   "TARGET_THUMB2"
917   "mov%?\\t%Q0, %1\;asr?\\t%R0, %1, #31"
918   "&& reload_completed"
919   [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (const_int 31)))]
920   {
921     rtx lo_part = gen_lowpart (SImode, operands[0]);
923     if (!REG_P (lo_part) || REGNO (lo_part) != REGNO (operands[1]))
924       emit_move_insn (lo_part, operands[1]);
925     operands[0] = gen_highpart (SImode, operands[0]);
926   }
927   [(set_attr "length" "8")
928    (set_attr "ce_count" "2")
929    (set_attr "shift" "1")
930    (set_attr "predicable" "yes")]
933 (define_insn_and_split "*thumb2_extendhidi2"
934   [(set (match_operand:DI                 0 "s_register_operand"  "=r,r")
935         (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
936   "TARGET_THUMB2"
937   "@
938    sxth%?\\t%Q0, %1\;asr%?\\t%R0, %Q0, #31
939    ldrsh%?\\t%Q0, %1\;asr%?\\t%R0, %Q0, #31"
940   "&& reload_completed"
941   [(set (match_dup 0) (sign_extend:SI (match_dup 1)))
942    (set (match_dup 2) (ashiftrt:SI (match_dup 0) (const_int 31)))]
943   "
944   {
945     operands[2] = gen_highpart (SImode, operands[0]);
946     operands[0] = gen_lowpart (SImode, operands[0]);
947   }
948   "
949   [(set_attr "length" "8")
950    (set_attr "ce_count" "2")
951    (set_attr "predicable" "yes")
952    (set_attr "type" "*,load_byte")
953    (set_attr "pool_range" "*,4092")
954    (set_attr "neg_pool_range" "*,250")]
957 (define_insn_and_split "*thumb2_extendqidi2"
958   [(set (match_operand:DI                 0 "s_register_operand"  "=r,r")
959         (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
960   "TARGET_THUMB2"
961   "@
962    sxtb%?\\t%Q0, %1\;asr%?\\t%R0, %Q0, #31
963    ldrsb%?\\t%Q0, %1\;asr%?\\t%R0, %Q0, #31"
964   "&& reload_completed"
965   [(set (match_dup 0) (sign_extend:SI (match_dup 1)))
966    (set (match_dup 2) (ashiftrt:SI (match_dup 0) (const_int 31)))]
967   "
968   {
969     operands[2] = gen_highpart (SImode, operands[0]);
970     operands[0] = gen_lowpart (SImode, operands[0]);
971   }
972   "
973   [(set_attr "length" "8")
974    (set_attr "ce_count" "2")
975    (set_attr "predicable" "yes")
976    (set_attr "type" "*,load_byte")
977    (set_attr "pool_range" "*,4092")
978    (set_attr "neg_pool_range" "*,250")]
981 ;; All supported Thumb2 implementations are armv6, so only that case is
982 ;; provided.
983 (define_insn "*thumb2_extendqisi_v6"
984   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
985         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
986   "TARGET_THUMB2 && arm_arch6"
987   "@
988    sxtb%?\\t%0, %1
989    ldr%(sb%)\\t%0, %1"
990   [(set_attr "type" "alu_shift,load_byte")
991    (set_attr "predicable" "yes")
992    (set_attr "pool_range" "*,4096")
993    (set_attr "neg_pool_range" "*,250")]
996 (define_insn "*thumb2_zero_extendhisi2_v6"
997   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
998         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
999   "TARGET_THUMB2 && arm_arch6"
1000   "@
1001    uxth%?\\t%0, %1
1002    ldr%(h%)\\t%0, %1"
1003   [(set_attr "type" "alu_shift,load_byte")
1004    (set_attr "predicable" "yes")
1005    (set_attr "pool_range" "*,4096")
1006    (set_attr "neg_pool_range" "*,250")]
1009 (define_insn "*thumb2_zero_extendqisi2_v6"
1010   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
1011         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
1012   "TARGET_THUMB2 && arm_arch6"
1013   "@
1014    uxtb%(%)\\t%0, %1
1015    ldr%(b%)\\t%0, %1\\t%@ zero_extendqisi2"
1016   [(set_attr "type" "alu_shift,load_byte")
1017    (set_attr "predicable" "yes")
1018    (set_attr "pool_range" "*,4096")
1019    (set_attr "neg_pool_range" "*,250")]
1022 (define_insn "thumb2_casesi_internal"
1023   [(parallel [(set (pc)
1024                (if_then_else
1025                 (leu (match_operand:SI 0 "s_register_operand" "r")
1026                      (match_operand:SI 1 "arm_rhs_operand" "rI"))
1027                 (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
1028                                  (label_ref (match_operand 2 "" ""))))
1029                 (label_ref (match_operand 3 "" ""))))
1030               (clobber (reg:CC CC_REGNUM))
1031               (clobber (match_scratch:SI 4 "=&r"))
1032               (use (label_ref (match_dup 2)))])]
1033   "TARGET_THUMB2 && !flag_pic"
1034   "* return thumb2_output_casesi(operands);"
1035   [(set_attr "conds" "clob")
1036    (set_attr "length" "16")]
1039 (define_insn "thumb2_casesi_internal_pic"
1040   [(parallel [(set (pc)
1041                (if_then_else
1042                 (leu (match_operand:SI 0 "s_register_operand" "r")
1043                      (match_operand:SI 1 "arm_rhs_operand" "rI"))
1044                 (mem:SI (plus:SI (mult:SI (match_dup 0) (const_int 4))
1045                                  (label_ref (match_operand 2 "" ""))))
1046                 (label_ref (match_operand 3 "" ""))))
1047               (clobber (reg:CC CC_REGNUM))
1048               (clobber (match_scratch:SI 4 "=&r"))
1049               (clobber (match_scratch:SI 5 "=r"))
1050               (use (label_ref (match_dup 2)))])]
1051   "TARGET_THUMB2 && flag_pic"
1052   "* return thumb2_output_casesi(operands);"
1053   [(set_attr "conds" "clob")
1054    (set_attr "length" "20")]
1057 (define_insn_and_split "thumb2_eh_return"
1058   [(unspec_volatile [(match_operand:SI 0 "s_register_operand" "r")]
1059                     VUNSPEC_EH_RETURN)
1060    (clobber (match_scratch:SI 1 "=&r"))]
1061   "TARGET_THUMB2"
1062   "#"
1063   "&& reload_completed"
1064   [(const_int 0)]
1065   "
1066   {
1067     thumb_set_return_address (operands[0], operands[1]);
1068     DONE;
1069   }"
1072 ;; Peepholes and insns for 16-bit flag clobbering instructions.
1073 ;; The conditional forms of these instructions do not clobber CC.
1074 ;; However by the time peepholes are run it is probably too late to do
1075 ;; anything useful with this information.
1076 (define_peephole2
1077   [(set (match_operand:SI          0 "low_register_operand" "")
1078         (match_operator:SI 3 "thumb_16bit_operator"
1079          [(match_operand:SI 1  "low_register_operand" "")
1080           (match_operand:SI 2 "low_register_operand" "")]))]
1081   "TARGET_THUMB2
1082    && (rtx_equal_p(operands[0], operands[1])
1083        || GET_CODE(operands[3]) == PLUS
1084        || GET_CODE(operands[3]) == MINUS)
1085    && peep2_regno_dead_p(0, CC_REGNUM)"
1086   [(parallel
1087     [(set (match_dup 0)
1088           (match_op_dup 3
1089            [(match_dup 1)
1090             (match_dup 2)]))
1091      (clobber (reg:CC CC_REGNUM))])]
1092   ""
1095 (define_insn "*thumb2_alusi3_short"
1096   [(set (match_operand:SI          0 "s_register_operand" "=l")
1097         (match_operator:SI 3 "thumb_16bit_operator"
1098          [(match_operand:SI 1 "s_register_operand" "0")
1099           (match_operand:SI 2 "s_register_operand" "l")]))
1100    (clobber (reg:CC CC_REGNUM))]
1101   "TARGET_THUMB2 && reload_completed
1102    && GET_CODE(operands[3]) != PLUS
1103    && GET_CODE(operands[3]) != MINUS"
1104   "%I3%!\\t%0, %1, %2"
1105   [(set_attr "predicable" "yes")
1106    (set_attr "length" "2")]
1109 ;; Similarly for 16-bit shift instructions
1110 ;; There is no 16-bit rotate by immediate instruction.
1111 (define_peephole2
1112   [(set (match_operand:SI   0 "low_register_operand" "")
1113         (match_operator:SI  3 "shift_operator"
1114          [(match_operand:SI 1 "low_register_operand" "")
1115           (match_operand:SI 2 "low_reg_or_int_operand" "")]))]
1116   "TARGET_THUMB2
1117    && peep2_regno_dead_p(0, CC_REGNUM)
1118    && ((GET_CODE(operands[3]) != ROTATE && GET_CODE(operands[3]) != ROTATERT)
1119        || REG_P(operands[2]))"
1120   [(parallel
1121     [(set (match_dup 0)
1122           (match_op_dup 3
1123            [(match_dup 1)
1124             (match_dup 2)]))
1125      (clobber (reg:CC CC_REGNUM))])]
1126   ""
1129 (define_insn "*thumb2_shiftsi3_short"
1130   [(set (match_operand:SI   0 "low_register_operand" "=l")
1131         (match_operator:SI  3 "shift_operator"
1132          [(match_operand:SI 1 "low_register_operand"  "l")
1133           (match_operand:SI 2 "low_reg_or_int_operand" "lM")]))
1134    (clobber (reg:CC CC_REGNUM))]
1135   "TARGET_THUMB2 && reload_completed
1136    && ((GET_CODE(operands[3]) != ROTATE && GET_CODE(operands[3]) != ROTATERT)
1137        || REG_P(operands[2]))"
1138   "* return arm_output_shift(operands, 2);"
1139   [(set_attr "predicable" "yes")
1140    (set_attr "shift" "1")
1141    (set_attr "length" "2")
1142    (set (attr "type") (if_then_else (match_operand 2 "const_int_operand" "")
1143                       (const_string "alu_shift")
1144                       (const_string "alu_shift_reg")))]
1147 ;; 16-bit load immediate
1148 (define_peephole2
1149   [(set (match_operand:QHSI 0 "low_register_operand" "")
1150         (match_operand:QHSI 1 "const_int_operand" ""))]
1151   "TARGET_THUMB2
1152    && peep2_regno_dead_p(0, CC_REGNUM)
1153    && (unsigned HOST_WIDE_INT) INTVAL(operands[1]) < 256"
1154   [(parallel
1155     [(set (match_dup 0)
1156           (match_dup 1))
1157      (clobber (reg:CC CC_REGNUM))])]
1158   ""
1161 (define_insn "*thumb2_mov<mode>_shortim"
1162   [(set (match_operand:QHSI 0 "low_register_operand" "=l")
1163         (match_operand:QHSI 1 "const_int_operand" "I"))
1164    (clobber (reg:CC CC_REGNUM))]
1165   "TARGET_THUMB2 && reload_completed"
1166   "mov%!\t%0, %1"
1167   [(set_attr "predicable" "yes")
1168    (set_attr "length" "2")]
1171 ;; 16-bit add/sub immediate
1172 (define_peephole2
1173   [(set (match_operand:SI 0 "low_register_operand" "")
1174         (plus:SI (match_operand:SI 1 "low_register_operand" "")
1175                  (match_operand:SI 2 "const_int_operand" "")))]
1176   "TARGET_THUMB2
1177    && peep2_regno_dead_p(0, CC_REGNUM)
1178    && ((rtx_equal_p(operands[0], operands[1])
1179         && INTVAL(operands[2]) > -256 && INTVAL(operands[2]) < 256)
1180        || (INTVAL(operands[2]) > -8 && INTVAL(operands[2]) < 8))"
1181   [(parallel
1182     [(set (match_dup 0)
1183           (plus:SI (match_dup 1)
1184                    (match_dup 2)))
1185      (clobber (reg:CC CC_REGNUM))])]
1186   ""
1189 (define_insn "*thumb2_addsi_short"
1190   [(set (match_operand:SI 0 "low_register_operand" "=l,l")
1191         (plus:SI (match_operand:SI 1 "low_register_operand" "l,0")
1192                  (match_operand:SI 2 "low_reg_or_int_operand" "lPt,Ps")))
1193    (clobber (reg:CC CC_REGNUM))]
1194   "TARGET_THUMB2 && reload_completed"
1195   "*
1196     HOST_WIDE_INT val;
1198     if (GET_CODE (operands[2]) == CONST_INT)
1199       val = INTVAL(operands[2]);
1200     else
1201       val = 0;
1203     /* We prefer eg. subs rn, rn, #1 over adds rn, rn, #0xffffffff.  */
1204     if (val < 0 && const_ok_for_arm(ARM_SIGN_EXTEND (-val)))
1205       return \"sub%!\\t%0, %1, #%n2\";
1206     else
1207       return \"add%!\\t%0, %1, %2\";
1208   "
1209   [(set_attr "predicable" "yes")
1210    (set_attr "length" "2")]
1213 (define_insn "divsi3"
1214   [(set (match_operand:SI         0 "s_register_operand" "=r")
1215         (div:SI (match_operand:SI 1 "s_register_operand"  "r")
1216                 (match_operand:SI 2 "s_register_operand"  "r")))]
1217   "TARGET_THUMB2 && arm_arch_hwdiv"
1218   "sdiv%?\t%0, %1, %2"
1219   [(set_attr "predicable" "yes")
1220    (set_attr "insn" "sdiv")]
1223 (define_insn "udivsi3"
1224   [(set (match_operand:SI          0 "s_register_operand" "=r")
1225         (udiv:SI (match_operand:SI 1 "s_register_operand"  "r")
1226                  (match_operand:SI 2 "s_register_operand"  "r")))]
1227   "TARGET_THUMB2 && arm_arch_hwdiv"
1228   "udiv%?\t%0, %1, %2"
1229   [(set_attr "predicable" "yes")
1230    (set_attr "insn" "udiv")]
1233 (define_insn "*thumb2_subsi_short"
1234   [(set (match_operand:SI 0 "low_register_operand" "=l")
1235         (minus:SI (match_operand:SI 1 "low_register_operand" "l")
1236                   (match_operand:SI 2 "low_register_operand" "l")))
1237    (clobber (reg:CC CC_REGNUM))]
1238   "TARGET_THUMB2 && reload_completed"
1239   "sub%!\\t%0, %1, %2"
1240   [(set_attr "predicable" "yes")
1241    (set_attr "length" "2")]
1244 ;; 16-bit encodings of "muls" and "mul<c>".  We only use these when
1245 ;; optimizing for size since "muls" is slow on all known
1246 ;; implementations and since "mul<c>" will be generated by
1247 ;; "*arm_mulsi3_v6" anyhow.  The assembler will use a 16-bit encoding
1248 ;; for "mul<c>" whenever possible anyhow.
1249 (define_peephole2
1250   [(set (match_operand:SI 0 "low_register_operand" "")
1251         (mult:SI (match_operand:SI 1 "low_register_operand" "")
1252                  (match_dup 0)))]
1253   "TARGET_THUMB2 && optimize_size && peep2_regno_dead_p (0, CC_REGNUM)"
1254   [(parallel
1255     [(set (match_dup 0)
1256            (mult:SI (match_dup 0) (match_dup 1)))
1257      (clobber (reg:CC CC_REGNUM))])]
1258   ""
1261 (define_peephole2
1262   [(set (match_operand:SI 0 "low_register_operand" "")
1263         (mult:SI (match_dup 0)
1264                  (match_operand:SI 1 "low_register_operand" "")))]
1265   "TARGET_THUMB2 && optimize_size && peep2_regno_dead_p (0, CC_REGNUM)"
1266   [(parallel
1267     [(set (match_dup 0)
1268            (mult:SI (match_dup 0) (match_dup 1)))
1269      (clobber (reg:CC CC_REGNUM))])]
1270   ""
1273 (define_insn "*thumb2_mulsi_short"
1274   [(set (match_operand:SI 0 "low_register_operand" "=l")
1275         (mult:SI (match_operand:SI 1 "low_register_operand" "%0")
1276                  (match_operand:SI 2 "low_register_operand" "l")))
1277    (clobber (reg:CC CC_REGNUM))]
1278   "TARGET_THUMB2 && optimize_size && reload_completed"
1279   "mul%!\\t%0, %2, %0"
1280   [(set_attr "predicable" "yes")
1281    (set_attr "length" "2")
1282    (set_attr "insn" "muls")])
1284 (define_insn "*thumb2_mulsi_short_compare0"
1285   [(set (reg:CC_NOOV CC_REGNUM)
1286         (compare:CC_NOOV
1287          (mult:SI (match_operand:SI 1 "register_operand" "%0")
1288                   (match_operand:SI 2 "register_operand" "l"))
1289          (const_int 0)))
1290    (set (match_operand:SI 0 "register_operand" "=l")
1291         (mult:SI (match_dup 1) (match_dup 2)))]
1292   "TARGET_THUMB2 && optimize_size"
1293   "muls\\t%0, %2, %0"
1294   [(set_attr "length" "2")
1295    (set_attr "insn" "muls")])
1297 (define_insn "*thumb2_mulsi_short_compare0_scratch"
1298   [(set (reg:CC_NOOV CC_REGNUM)
1299         (compare:CC_NOOV
1300          (mult:SI (match_operand:SI 1 "register_operand" "%0")
1301                   (match_operand:SI 2 "register_operand" "l"))
1302          (const_int 0)))
1303    (clobber (match_scratch:SI 0 "=l"))]
1304   "TARGET_THUMB2 && optimize_size"
1305   "muls\\t%0, %2, %0"
1306   [(set_attr "length" "2")
1307    (set_attr "insn" "muls")])
1309 (define_insn "*thumb2_cbz"
1310   [(set (pc) (if_then_else
1311               (eq (match_operand:SI 0 "s_register_operand" "l,?r")
1312                   (const_int 0))
1313               (label_ref (match_operand 1 "" ""))
1314               (pc)))
1315    (clobber (reg:CC CC_REGNUM))]
1316   "TARGET_THUMB2"
1317   "*
1318   if (get_attr_length (insn) == 2)
1319     return \"cbz\\t%0, %l1\";
1320   else
1321     return \"cmp\\t%0, #0\;beq\\t%l1\";
1322   "
1323   [(set (attr "length") 
1324         (if_then_else
1325             (and (ge (minus (match_dup 1) (pc)) (const_int 2))
1326                  (le (minus (match_dup 1) (pc)) (const_int 128))
1327                  (eq (symbol_ref ("which_alternative")) (const_int 0)))
1328             (const_int 2)
1329             (const_int 8)))]
1332 (define_insn "*thumb2_cbnz"
1333   [(set (pc) (if_then_else
1334               (ne (match_operand:SI 0 "s_register_operand" "l,?r")
1335                   (const_int 0))
1336               (label_ref (match_operand 1 "" ""))
1337               (pc)))
1338    (clobber (reg:CC CC_REGNUM))]
1339   "TARGET_THUMB2"
1340   "*
1341   if (get_attr_length (insn) == 2)
1342     return \"cbnz\\t%0, %l1\";
1343   else
1344     return \"cmp\\t%0, #0\;bne\\t%l1\";
1345   "
1346   [(set (attr "length") 
1347         (if_then_else
1348             (and (ge (minus (match_dup 1) (pc)) (const_int 2))
1349                  (le (minus (match_dup 1) (pc)) (const_int 128))
1350                  (eq (symbol_ref ("which_alternative")) (const_int 0)))
1351             (const_int 2)
1352             (const_int 8)))]
1355 ;; 16-bit complement
1356 (define_peephole2
1357   [(set (match_operand:SI 0 "low_register_operand" "")
1358         (not:SI (match_operand:SI 1 "low_register_operand" "")))]
1359   "TARGET_THUMB2
1360    && peep2_regno_dead_p(0, CC_REGNUM)"
1361   [(parallel
1362     [(set (match_dup 0)
1363           (not:SI (match_dup 1)))
1364      (clobber (reg:CC CC_REGNUM))])]
1365   ""
1368 (define_insn "*thumb2_one_cmplsi2_short"
1369   [(set (match_operand:SI 0 "low_register_operand" "=l")
1370         (not:SI (match_operand:SI 1 "low_register_operand" "l")))
1371    (clobber (reg:CC CC_REGNUM))]
1372   "TARGET_THUMB2 && reload_completed"
1373   "mvn%!\t%0, %1"
1374   [(set_attr "predicable" "yes")
1375    (set_attr "length" "2")]
1378 ;; 16-bit negate
1379 (define_peephole2
1380   [(set (match_operand:SI 0 "low_register_operand" "")
1381         (neg:SI (match_operand:SI 1 "low_register_operand" "")))]
1382   "TARGET_THUMB2
1383    && peep2_regno_dead_p(0, CC_REGNUM)"
1384   [(parallel
1385     [(set (match_dup 0)
1386           (neg:SI (match_dup 1)))
1387      (clobber (reg:CC CC_REGNUM))])]
1388   ""
1391 (define_insn "*thumb2_negsi2_short"
1392   [(set (match_operand:SI 0 "low_register_operand" "=l")
1393         (neg:SI (match_operand:SI 1 "low_register_operand" "l")))
1394    (clobber (reg:CC CC_REGNUM))]
1395   "TARGET_THUMB2 && reload_completed"
1396   "neg%!\t%0, %1"
1397   [(set_attr "predicable" "yes")
1398    (set_attr "length" "2")]
1401 (define_insn "orsi_notsi_si"
1402   [(set (match_operand:SI 0 "s_register_operand" "=r")
1403         (ior:SI (not:SI (match_operand:SI 2 "s_register_operand" "r"))
1404                 (match_operand:SI 1 "s_register_operand" "r")))]
1405   "TARGET_THUMB2"
1406   "orn%?\\t%0, %1, %2"
1407   [(set_attr "predicable" "yes")]
1410 (define_insn "*thumb_orsi_not_shiftsi_si"
1411   [(set (match_operand:SI 0 "s_register_operand" "=r")
1412         (ior:SI (not:SI (match_operator:SI 4 "shift_operator"
1413                          [(match_operand:SI 2 "s_register_operand" "r")
1414                           (match_operand:SI 3 "const_int_operand" "M")]))
1415                 (match_operand:SI 1 "s_register_operand" "r")))]
1416   "TARGET_THUMB2"
1417   "orn%?\\t%0, %1, %2%S4"
1418   [(set_attr "predicable" "yes")
1419    (set_attr "shift" "2")
1420    (set_attr "type" "alu_shift")]
1423 (define_insn_and_split "*thumb2_iorsi3"
1424   [(set (match_operand:SI         0 "s_register_operand" "=r,r,r")
1425         (ior:SI (match_operand:SI 1 "s_register_operand" "r,r,r")
1426                 (match_operand:SI 2 "reg_or_int_operand" "rI,K,?n")))]
1427   "TARGET_THUMB2"
1428   "@
1429    orr%?\\t%0, %1, %2
1430    orn%?\\t%0, %1, #%B2
1431    #"
1432   "TARGET_THUMB2
1433    && GET_CODE (operands[2]) == CONST_INT
1434    && !(const_ok_for_arm (INTVAL (operands[2]))
1435         || const_ok_for_arm (~INTVAL (operands[2])))"
1436   [(clobber (const_int 0))]
1437   "
1438   arm_split_constant  (IOR, SImode, curr_insn, 
1439                        INTVAL (operands[2]), operands[0], operands[1], 0);
1440   DONE;
1441   "
1442   [(set_attr "length" "4,4,16")
1443    (set_attr "predicable" "yes")]