OSDN Git Service

2008-12-15 Wolfgang Gellerich <gellerich@de.ibm.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / s390 / s390.md
1 ;;- Machine description for GNU compiler -- S/390 / zSeries version.
2 ;;  Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 ;;  Free Software Foundation, Inc.
4 ;;  Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5 ;;                 Ulrich Weigand (uweigand@de.ibm.com) and
6 ;;                 Andreas Krebbel (Andreas.Krebbel@de.ibm.com)
7
8 ;; This file is part of GCC.
9
10 ;; GCC is free software; you can redistribute it and/or modify it under
11 ;; the terms of the GNU General Public License as published by the Free
12 ;; Software Foundation; either version 3, or (at your option) any later
13 ;; version.
14
15 ;; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 ;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18 ;; for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3.  If not see
22 ;; <http://www.gnu.org/licenses/>.
23
24 ;;
25 ;; See constraints.md for a description of constraints specific to s390.
26 ;;
27
28 ;; Special formats used for outputting 390 instructions.
29 ;;
30 ;;     %C: print opcode suffix for branch condition.
31 ;;     %D: print opcode suffix for inverse branch condition.
32 ;;     %J: print tls_load/tls_gdcall/tls_ldcall suffix
33 ;;     %G: print the size of the operand in bytes.
34 ;;     %O: print only the displacement of a memory reference.
35 ;;     %R: print only the base register of a memory reference.
36 ;;     %S: print S-type memory reference (base+displacement).
37 ;;     %N: print the second word of a DImode operand.
38 ;;     %M: print the second word of a TImode operand.
39 ;;     %Y: print shift count operand.
40 ;;  
41 ;;     %b: print integer X as if it's an unsigned byte.
42 ;;     %c: print integer X as if it's an signed byte.
43 ;;     %x: print integer X as if it's an unsigned halfword.
44 ;;     %h: print integer X as if it's a signed halfword.
45 ;;     %i: print the first nonzero HImode part of X.
46 ;;     %j: print the first HImode part unequal to -1 of X.
47 ;;     %k: print the first nonzero SImode part of X.
48 ;;     %m: print the first SImode part unequal to -1 of X.
49 ;;     %o: print integer X as if it's an unsigned 32bit word.
50 ;;
51 ;; We have a special constraint for pattern matching.
52 ;;
53 ;;   s_operand -- Matches a valid S operand in a RS, SI or SS type instruction.
54 ;;
55
56 ;;
57 ;; UNSPEC usage
58 ;;
59
60 (define_constants
61   [; Miscellaneous
62    (UNSPEC_ROUND                1)
63    (UNSPEC_CCU_TO_INT           2)
64    (UNSPEC_CCZ_TO_INT           3)
65    (UNSPEC_ICM                  10)
66    (UNSPEC_TIE                  11)
67
68    ; GOT/PLT and lt-relative accesses
69    (UNSPEC_LTREL_OFFSET         100)
70    (UNSPEC_LTREL_BASE           101)
71    (UNSPEC_POOL_OFFSET          102)
72    (UNSPEC_GOTENT               110)
73    (UNSPEC_GOT                  111)
74    (UNSPEC_GOTOFF               112)
75    (UNSPEC_PLT                  113)
76    (UNSPEC_PLTOFF               114)
77
78    ; Literal pool
79    (UNSPEC_RELOAD_BASE          210)
80    (UNSPEC_MAIN_BASE            211)
81    (UNSPEC_LTREF                212)
82    (UNSPEC_INSN                 213)
83    (UNSPEC_EXECUTE              214)
84
85    ; TLS relocation specifiers
86    (UNSPEC_TLSGD                500)
87    (UNSPEC_TLSLDM               501)
88    (UNSPEC_NTPOFF               502)
89    (UNSPEC_DTPOFF               503)
90    (UNSPEC_GOTNTPOFF            504)
91    (UNSPEC_INDNTPOFF            505)
92
93    ; TLS support
94    (UNSPEC_TLSLDM_NTPOFF        511)
95    (UNSPEC_TLS_LOAD             512)
96
97    ; String Functions
98    (UNSPEC_SRST                 600)
99    (UNSPEC_MVST                 601)
100
101    ; Stack Smashing Protector
102    (UNSPEC_SP_SET               700)
103    (UNSPEC_SP_TEST              701)
104
105    ; Copy sign instructions
106    (UNSPEC_COPYSIGN             800)
107
108    ; Test Data Class (TDC)
109    (UNSPEC_TDC_INSN             900)
110  ])
111
112 ;;
113 ;; UNSPEC_VOLATILE usage
114 ;;
115
116 (define_constants
117   [; Blockage
118    (UNSPECV_BLOCKAGE            0)
119
120    ; TPF Support
121    (UNSPECV_TPF_PROLOGUE        20)
122    (UNSPECV_TPF_EPILOGUE        21)
123
124    ; Literal pool
125    (UNSPECV_POOL                200)
126    (UNSPECV_POOL_SECTION        201)
127    (UNSPECV_POOL_ALIGN          202)
128    (UNSPECV_POOL_ENTRY          203)
129    (UNSPECV_MAIN_POOL           300)
130
131    ; TLS support
132    (UNSPECV_SET_TP              500)
133
134    ; Atomic Support
135    (UNSPECV_MB                  700)
136    (UNSPECV_CAS                 701)
137   ])
138
139 ;;
140 ;; Registers
141 ;;
142
143 ; Registers with special meaning
144
145 (define_constants
146   [
147    ; Sibling call register.
148    (SIBCALL_REGNUM               1)
149    ; Literal pool base register.
150    (BASE_REGNUM                 13)
151    ; Return address register.
152    (RETURN_REGNUM               14)
153    ; Condition code register.
154    (CC_REGNUM                   33)
155    ; Thread local storage pointer register. 
156    (TP_REGNUM                   36)
157   ])
158
159 ; Hardware register names
160
161 (define_constants
162   [
163    ; General purpose registers
164    (GPR0_REGNUM                  0)
165    ; Floating point registers.
166    (FPR0_REGNUM                 16)
167    (FPR2_REGNUM                 18)
168   ])
169
170 ;;
171 ;; PFPO GPR0 argument format
172 ;;
173
174 (define_constants
175   [
176    ; PFPO operation type
177    (PFPO_CONVERT          0x1000000)
178    ; PFPO operand types
179    (PFPO_OP_TYPE_SF             0x5)
180    (PFPO_OP_TYPE_DF             0x6)
181    (PFPO_OP_TYPE_TF             0x7)
182    (PFPO_OP_TYPE_SD             0x8)
183    (PFPO_OP_TYPE_DD             0x9)
184    (PFPO_OP_TYPE_TD             0xa)
185    ; Bitposition of operand types
186    (PFPO_OP0_TYPE_SHIFT          16)
187    (PFPO_OP1_TYPE_SHIFT           8)
188   ])
189
190
191 ;; Instruction operand type as used in the Principles of Operation.
192 ;; Used to determine defaults for length and other attribute values.
193
194 (define_attr "op_type"
195   "NN,E,RR,RRE,RX,RS,RSI,RI,SI,S,SS,SSE,RXE,RSE,RIL,RIE,RXY,RSY,SIY,RRF,RRR,SIL,RRS,RIS"
196   (const_string "NN"))
197
198 ;; Instruction type attribute used for scheduling.
199
200 (define_attr "type" "none,integer,load,lr,la,larl,lm,stm,
201                      cs,vs,store,sem,idiv,
202                      imulhi,imulsi,imuldi,
203                      branch,jsr,fsimptf,fsimpdf,fsimpsf,
204                      floadtf,floaddf,floadsf,fstoredf,fstoresf,
205                      fmultf,fmuldf,fmulsf,fdivtf,fdivdf,fdivsf,
206                      ftoi,fsqrttf,fsqrtdf,fsqrtsf,
207                      ftrunctf,ftruncdf, ftruncsd, ftruncdd,
208                      itoftf, itofdf, itofsf, itofdd, itoftd,
209                      fdivdd, fdivtd, floaddd, floadsd, fmuldd, fmultd,
210                      fsimpdd, fsimpsd, fsimptd, fstoredd, fstoresd,
211                      ftoidfp, other"
212   (cond [(eq_attr "op_type" "NN")  (const_string "other")
213          (eq_attr "op_type" "SS")  (const_string "cs")]
214     (const_string "integer")))
215
216 ;; Another attribute used for scheduling purposes:
217 ;;   agen: Instruction uses the address generation unit
218 ;;   reg: Instruction does not use the agen unit
219
220 (define_attr "atype" "agen,reg"
221   (if_then_else (eq_attr "op_type" "E,RR,RI,RRE")  
222                 (const_string "reg")
223                 (const_string "agen")))
224
225 ;; Properties concerning Z10 execution grouping and value forwarding.
226 ;; z10_super: instruction is superscalar.
227 ;; z10_super_c: instruction is superscalar and meets the condition of z10_c.
228 ;; z10_fwd: The instruction reads the value of an operand and stores it into a
229 ;;   target register.  It can forward this value to a second instruction that reads
230 ;;   the same register if that second instruction is issued in the same group.
231 ;; z10_rec: The instruction is in the T pipeline and reads a register. If the
232 ;;   instruction in the S pipe writes to the register, then the T instruction
233 ;;   can immediately read the new value.
234 ;; z10_fr: union of Z10_fwd and z10_rec.
235 ;; z10_c: second operand of instruction is a register and read with complemented bits.
236 ;; z10_cobra: its a compare and branch instruction
237 ;;
238 ;; An additional suffix A1, A3, or E1 indicates the respective AGI bypass.
239
240
241 (define_attr "z10prop" "none,
242                         z10_super, z10_super_E1, z10_super_A1, z10_super_c, z10_super_c_E1,
243                         z10_fwd, z10_fwd_A1, z10_fwd_A3, z10_fwd_E1,
244                         z10_rec,
245                         z10_fr, z10_fr_A3, z10_fr_E1,
246                         z10_c, z10_cobra"
247              (const_string "none"))
248
249
250 ;; Length in bytes.
251
252 (define_attr "length" ""
253   (cond [(eq_attr "op_type" "E,RR")                           (const_int 2)
254          (eq_attr "op_type" "RX,RI,RRE,RS,RSI,S,SI,RRF,RRR")  (const_int 4)]
255     (const_int 6)))
256
257
258 ;; Processor type.  This attribute must exactly match the processor_type
259 ;; enumeration in s390.h.  The current machine description does not
260 ;; distinguish between g5 and g6, but there are differences between the two
261 ;; CPUs could in theory be modeled.
262
263 (define_attr "cpu" "g5,g6,z900,z990,z9_109,z10"
264   (const (symbol_ref "s390_tune")))
265
266 (define_attr "cpu_facility" "standard,ieee,zarch,longdisp,extimm,dfp,z10"
267   (const_string "standard"))
268
269 (define_attr "enabled" ""
270   (cond [(eq_attr "cpu_facility" "standard")
271          (const_int 1)
272
273          (and (eq_attr "cpu_facility" "ieee")
274               (ne (symbol_ref "TARGET_CPU_IEEE_FLOAT") (const_int 0)))
275          (const_int 1)
276
277          (and (eq_attr "cpu_facility" "zarch")
278               (ne (symbol_ref "TARGET_ZARCH") (const_int 0)))
279          (const_int 1)
280
281          (and (eq_attr "cpu_facility" "longdisp")
282               (ne (symbol_ref "TARGET_LONG_DISPLACEMENT") (const_int 0)))
283          (const_int 1)
284
285          (and (eq_attr "cpu_facility" "extimm")
286               (ne (symbol_ref "TARGET_EXTIMM") (const_int 0)))
287          (const_int 1)
288
289          (and (eq_attr "cpu_facility" "dfp")
290               (ne (symbol_ref "TARGET_DFP") (const_int 0)))
291          (const_int 1)
292
293          (and (eq_attr "cpu_facility" "z10")
294               (ne (symbol_ref "TARGET_Z10") (const_int 0)))
295          (const_int 1)]
296         (const_int 0)))
297
298 ;; Pipeline description for z900.  For lack of anything better,
299 ;; this description is also used for the g5 and g6.
300 (include "2064.md")
301
302 ;; Pipeline description for z990, z9-109 and z9-ec.
303 (include "2084.md")
304
305 ;; Pipeline description for z10
306 (include "2097.md")
307
308 ;; Predicates
309 (include "predicates.md")
310
311 ;; Constraint definitions
312 (include "constraints.md")
313
314 ;; Other includes
315 (include "tpf.md")
316
317 ;; Iterators
318
319 ;; These mode iterators allow floating point patterns to be generated from the
320 ;; same template.
321 (define_mode_iterator FP_ALL [TF DF SF (TD "TARGET_HARD_DFP") (DD "TARGET_HARD_DFP") 
322                               (SD "TARGET_HARD_DFP")])
323 (define_mode_iterator FP [TF DF SF (TD "TARGET_HARD_DFP") (DD "TARGET_HARD_DFP")])
324 (define_mode_iterator FPALL [TF DF SF TD DD SD])
325 (define_mode_iterator BFP [TF DF SF])
326 (define_mode_iterator DFP [TD DD])
327 (define_mode_iterator DFP_ALL [TD DD SD])
328 (define_mode_iterator DSF [DF SF])
329 (define_mode_iterator SD_SF [SF SD])
330 (define_mode_iterator DD_DF [DF DD])
331 (define_mode_iterator TD_TF [TF TD])
332
333 ;; This mode iterator allows 31-bit and 64-bit TDSI patterns to be generated
334 ;; from the same template.
335 (define_mode_iterator TDSI [(TI "TARGET_64BIT") DI SI])
336
337 ;; These mode iterators allow 31-bit and 64-bit GPR patterns to be generated
338 ;; from the same template.
339 (define_mode_iterator GPR [(DI "TARGET_64BIT") SI])
340 (define_mode_iterator DSI [DI SI])
341
342 ;; These mode iterators allow :P to be used for patterns that operate on
343 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
344 (define_mode_iterator DP  [(TI "TARGET_64BIT") (DI "!TARGET_64BIT")])
345 (define_mode_iterator P [(DI "TARGET_64BIT") (SI "!TARGET_64BIT")])
346
347 ;; This mode iterator allows the QI and HI patterns to be defined from
348 ;; the same template.
349 (define_mode_iterator HQI [HI QI])
350
351 ;; This mode iterator allows the integer patterns to be defined from the
352 ;; same template.
353 (define_mode_iterator INT [(DI "TARGET_64BIT") SI HI QI])
354 (define_mode_iterator INTALL [TI DI SI HI QI])
355
356 ;; This iterator allows to unify all 'bCOND' expander patterns.
357 (define_code_iterator COMPARE [eq ne gt gtu lt ltu ge geu le leu unordered 
358                             ordered uneq unlt ungt unle unge ltgt])
359
360 ;; This iterator allows to unify all 'sCOND' patterns.
361 (define_code_iterator SCOND [ltu gtu leu geu])
362
363 ;; This iterator allows some 'ashift' and 'lshiftrt' pattern to be defined from
364 ;; the same template.
365 (define_code_iterator SHIFT [ashift lshiftrt])
366
367 ;; This iterator and attribute allow to combine most atomic operations.
368 (define_code_iterator ATOMIC [and ior xor plus minus mult])
369 (define_code_attr atomic [(and "and") (ior "ior") (xor "xor") 
370                           (plus "add") (minus "sub") (mult "nand")])
371
372 ;; In FP templates, a string like "lt<de>br" will expand to "ltxbr" in 
373 ;; TF/TDmode, "ltdbr" in DF/DDmode, and "ltebr" in SF/SDmode.
374 (define_mode_attr xde [(TF "x") (DF "d") (SF "e") (TD "x") (DD "d") (SD "e")])
375
376 ;; In FP templates, a <dee> in "m<dee><bt>r" will expand to "mx<bt>r" in 
377 ;; TF/TDmode, "md<bt>r" in DF/DDmode, "mee<bt>r" in SFmode and "me<bt>r in 
378 ;; SDmode.
379 (define_mode_attr xdee [(TF "x") (DF "d") (SF "ee") (TD "x") (DD "d") (SD "e")])
380
381 ;; In FP templates, "<RRe>" will expand to "RRE" in TFmode and "RR" otherwise.
382 ;; Likewise for "<RXe>".
383 (define_mode_attr RRe [(TF "RRE") (DF "RR") (SF "RR")])
384 (define_mode_attr RXe [(TF "RXE") (DF "RX") (SF "RX")])
385
386 ;; The decimal floating point variants of add, sub, div and mul support 3
387 ;; fp register operands.  The following attributes allow to merge the bfp and
388 ;; dfp variants in a single insn definition.
389
390 ;; This attribute is used to set op_type accordingly.
391 (define_mode_attr RRer [(TF "RRE") (DF "RRE") (SF "RRE") (TD "RRR") 
392                         (DD "RRR") (SD "RRR")])
393
394 ;; This attribute is used in the operand constraint list in order to have the 
395 ;; first and the second operand match for bfp modes.
396 (define_mode_attr f0 [(TF "0") (DF "0") (SF "0") (TD "f") (DD "f") (DD "f")])
397
398 ;; This attribute is used in the operand list of the instruction to have an 
399 ;; additional operand for the dfp instructions.
400 (define_mode_attr op1 [(TF "") (DF "") (SF "")
401                        (TD "%1,") (DD "%1,") (SD "%1,")])
402
403
404 ;; This attribute is used in the operand constraint list
405 ;; for instructions dealing with the sign bit of 32 or 64bit fp values.
406 ;; TFmode values are represented by a fp register pair.  Since the
407 ;; sign bit instructions only handle single source and target fp registers
408 ;; these instructions can only be used for TFmode values if the source and
409 ;; target operand uses the same fp register.
410 (define_mode_attr fT0 [(TF "0") (DF "f") (SF "f")])
411
412 ;; In FP templates, "<Rf>" will expand to "f" in TFmode and "R" otherwise.
413 ;; This is used to disable the memory alternative in TFmode patterns.
414 (define_mode_attr Rf [(TF "f") (DF "R") (SF "R") (TD "f") (DD "f") (SD "f")])
415
416 ;; This attribute adds b for bfp instructions and t for dfp instructions and is used
417 ;; within instruction mnemonics.
418 (define_mode_attr bt [(TF "b") (DF "b") (SF "b") (TD "t") (DD "t") (SD "t")])
419
420 ;; This attribute is used within instruction mnemonics.  It evaluates to d for dfp
421 ;; modes and to an empty string for bfp modes.
422 (define_mode_attr _d [(TF "") (DF "") (SF "") (TD "d") (DD "d") (SD "d")])
423
424 ;; In GPR and P templates, a constraint like "<d0>" will expand to "d" in DImode
425 ;; and "0" in SImode. This allows to combine instructions of which the 31bit
426 ;; version only operates on one register.
427 (define_mode_attr d0 [(DI "d") (SI "0")])
428
429 ;; In combination with d0 this allows to combine instructions of which the 31bit
430 ;; version only operates on one register. The DImode version needs an additional
431 ;; register for the assembler output.
432 (define_mode_attr 1 [(DI "%1,") (SI "")])
433
434 ;; In SHIFT templates, a string like "s<lr>dl" will expand to "sldl" in
435 ;; 'ashift' and "srdl" in 'lshiftrt'.
436 (define_code_attr lr [(ashift "l") (lshiftrt "r")])
437
438 ;; In SHIFT templates, this attribute holds the correct standard name for the
439 ;; pattern itself and the corresponding function calls.
440 (define_code_attr shift [(ashift "ashl") (lshiftrt "lshr")])
441
442 ;; This attribute handles differences in the instruction 'type' and will result
443 ;; in "RRE" for DImode and "RR" for SImode.
444 (define_mode_attr E [(DI "E") (SI "")])
445
446 ;; This attribute handles differences in the instruction 'type' and makes RX<Y>
447 ;; to result in "RXY" for DImode and "RX" for SImode.
448 (define_mode_attr Y [(DI "Y") (SI "")])
449
450 ;; This attribute handles differences in the instruction 'type' and will result
451 ;; in "RSE" for TImode and "RS" for DImode.
452 (define_mode_attr TE [(TI "E") (DI "")])
453
454 ;; In GPR templates, a string like "lc<g>r" will expand to "lcgr" in DImode
455 ;; and "lcr" in SImode.
456 (define_mode_attr g [(DI "g") (SI "")])
457
458 ;; In GPR templates, a string like "sl<y>" will expand to "slg" in DImode
459 ;; and "sly" in SImode. This is useful because on 64bit the ..g instructions
460 ;; were enhanced with long displacements whereas 31bit instructions got a ..y
461 ;; variant for long displacements.
462 (define_mode_attr y [(DI "g") (SI "y")])
463
464 ;; In DP templates, a string like "cds<g>" will expand to "cdsg" in TImode
465 ;; and "cds" in DImode.
466 (define_mode_attr tg [(TI "g") (DI "")])
467
468 ;; In GPR templates, a string like "c<gf>dbr" will expand to "cgdbr" in DImode
469 ;; and "cfdbr" in SImode.
470 (define_mode_attr gf [(DI "g") (SI "f")])
471
472 ;; ICM mask required to load MODE value into the lowest subreg
473 ;; of a SImode register.
474 (define_mode_attr icm_lo [(HI "3") (QI "1")])
475
476 ;; In HQI templates, a string like "llg<hc>" will expand to "llgh" in
477 ;; HImode and "llgc" in QImode.
478 (define_mode_attr hc [(HI "h") (QI "c")])
479
480 ;; In P templates, the mode <DBL> will expand to "TI" in DImode and "DI"
481 ;; in SImode.
482 (define_mode_attr DBL [(DI "TI") (SI "DI")])
483
484 ;; This attribute expands to DF for TFmode and to DD for TDmode .  It is
485 ;; used for Txmode splitters splitting a Txmode copy into 2 Dxmode copies.
486 (define_mode_attr HALF_TMODE [(TF "DF") (TD "DD")])
487
488 ;; Maximum unsigned integer that fits in MODE.
489 (define_mode_attr max_uint [(HI "65535") (QI "255")])
490
491 ;;
492 ;;- Compare instructions.
493 ;;
494
495 (define_expand "cmp<mode>"
496   [(set (reg:CC CC_REGNUM)
497         (compare:CC (match_operand:GPR 0 "register_operand" "")
498                     (match_operand:GPR 1 "general_operand" "")))]
499   ""
500 {
501   s390_compare_op0 = operands[0];
502   s390_compare_op1 = operands[1];
503   DONE;
504 })
505
506 (define_expand "cmp<mode>"
507   [(set (reg:CC CC_REGNUM)
508         (compare:CC (match_operand:FP 0 "register_operand" "")
509                     (match_operand:FP 1 "general_operand" "")))]
510   "TARGET_HARD_FLOAT"
511 {
512   s390_compare_op0 = operands[0];
513   s390_compare_op1 = operands[1];
514   DONE;
515 })
516
517
518 ; Test-under-Mask instructions
519
520 (define_insn "*tmqi_mem"
521   [(set (reg CC_REGNUM)
522         (compare (and:QI (match_operand:QI 0 "memory_operand" "Q,S")
523                          (match_operand:QI 1 "immediate_operand" "n,n"))
524                  (match_operand:QI 2 "immediate_operand" "n,n")))]
525   "s390_match_ccmode (insn, s390_tm_ccmode (operands[1], operands[2], false))"
526   "@
527    tm\t%S0,%b1
528    tmy\t%S0,%b1"
529   [(set_attr "op_type" "SI,SIY")
530    (set_attr "z10prop" "z10_super,z10_super")])
531
532 (define_insn "*tmdi_reg"
533   [(set (reg CC_REGNUM)
534         (compare (and:DI (match_operand:DI 0 "nonimmediate_operand" "d,d,d,d")
535                          (match_operand:DI 1 "immediate_operand"
536                                              "N0HD0,N1HD0,N2HD0,N3HD0"))
537                  (match_operand:DI 2 "immediate_operand" "n,n,n,n")))]
538   "TARGET_64BIT
539    && s390_match_ccmode (insn, s390_tm_ccmode (operands[1], operands[2], true))
540    && s390_single_part (operands[1], DImode, HImode, 0) >= 0"
541   "@
542    tmhh\t%0,%i1
543    tmhl\t%0,%i1
544    tmlh\t%0,%i1
545    tmll\t%0,%i1"
546   [(set_attr "op_type" "RI")
547    (set_attr "z10prop" "z10_super,z10_super,z10_super,z10_super")])
548
549 (define_insn "*tmsi_reg"
550   [(set (reg CC_REGNUM)
551         (compare (and:SI (match_operand:SI 0 "nonimmediate_operand" "d,d")
552                          (match_operand:SI 1 "immediate_operand" "N0HS0,N1HS0"))
553                  (match_operand:SI 2 "immediate_operand" "n,n")))]
554   "s390_match_ccmode (insn, s390_tm_ccmode (operands[1], operands[2], true))
555    && s390_single_part (operands[1], SImode, HImode, 0) >= 0"
556   "@
557    tmh\t%0,%i1
558    tml\t%0,%i1"
559   [(set_attr "op_type" "RI")])
560
561 (define_insn "*tm<mode>_full"
562   [(set (reg CC_REGNUM)
563         (compare (match_operand:HQI 0 "register_operand" "d")
564                  (match_operand:HQI 1 "immediate_operand" "n")))]
565   "s390_match_ccmode (insn, s390_tm_ccmode (constm1_rtx, operands[1], true))"
566   "tml\t%0,<max_uint>"
567   [(set_attr "op_type" "RI")])
568
569
570 ;
571 ; Load-and-Test instructions
572 ;
573
574 ; tst(di|si) instruction pattern(s).
575
576 (define_insn "*tstdi_sign"
577   [(set (reg CC_REGNUM)
578         (compare
579           (ashiftrt:DI
580             (ashift:DI
581               (subreg:DI (match_operand:SI 0 "nonimmediate_operand" "d,RT") 0)
582               (const_int 32)) (const_int 32))
583           (match_operand:DI 1 "const0_operand" "")))
584    (set (match_operand:DI 2 "register_operand" "=d,d")
585         (sign_extend:DI (match_dup 0)))]
586   "s390_match_ccmode(insn, CCSmode) && TARGET_64BIT"
587   "ltgfr\t%2,%0
588    ltgf\t%2,%0"
589   [(set_attr "op_type"      "RRE,RXY")
590    (set_attr "cpu_facility" "*,z10")
591    (set_attr "z10prop" "z10_super_E1,z10_super_E1") ])
592
593 ; ltr, lt, ltgr, ltg
594 (define_insn "*tst<mode>_extimm"
595   [(set (reg CC_REGNUM)
596         (compare (match_operand:GPR 0 "nonimmediate_operand" "d,RT")
597                  (match_operand:GPR 1 "const0_operand" "")))
598    (set (match_operand:GPR 2 "register_operand" "=d,d")
599         (match_dup 0))]
600   "s390_match_ccmode(insn, CCSmode) && TARGET_EXTIMM"
601   "@
602    lt<g>r\t%2,%0
603    lt<g>\t%2,%0"
604   [(set_attr "op_type" "RR<E>,RXY")
605    (set_attr "z10prop" "z10_fr_E1,z10_fr_A3") ])
606
607 ; ltr, lt, ltgr, ltg
608 (define_insn "*tst<mode>_cconly_extimm"
609   [(set (reg CC_REGNUM)
610         (compare (match_operand:GPR 0 "nonimmediate_operand" "d,RT")
611                  (match_operand:GPR 1 "const0_operand" "")))
612    (clobber (match_scratch:GPR 2 "=X,d"))]
613   "s390_match_ccmode(insn, CCSmode) && TARGET_EXTIMM"
614   "@
615    lt<g>r\t%0,%0
616    lt<g>\t%2,%0"
617   [(set_attr "op_type" "RR<E>,RXY")
618    (set_attr "z10prop" "z10_fr_E1,z10_fr_A3")])
619
620 (define_insn "*tstdi"
621   [(set (reg CC_REGNUM)
622         (compare (match_operand:DI 0 "register_operand" "d")
623                  (match_operand:DI 1 "const0_operand" "")))
624    (set (match_operand:DI 2 "register_operand" "=d")
625         (match_dup 0))]
626   "s390_match_ccmode(insn, CCSmode) && TARGET_64BIT && !TARGET_EXTIMM"
627   "ltgr\t%2,%0"
628   [(set_attr "op_type" "RRE")
629    (set_attr "z10prop" "z10_fr_E1")])
630
631 (define_insn "*tstsi"
632   [(set (reg CC_REGNUM)
633         (compare (match_operand:SI 0 "nonimmediate_operand" "d,Q,S")
634                  (match_operand:SI 1 "const0_operand" "")))
635    (set (match_operand:SI 2 "register_operand" "=d,d,d")
636         (match_dup 0))]
637   "s390_match_ccmode(insn, CCSmode) && !TARGET_EXTIMM"
638   "@
639    ltr\t%2,%0
640    icm\t%2,15,%S0
641    icmy\t%2,15,%S0"
642   [(set_attr "op_type" "RR,RS,RSY")
643    (set_attr "z10prop" "z10_fr_E1,z10_super_E1,z10_super_E1")])
644
645 (define_insn "*tstsi_cconly"
646   [(set (reg CC_REGNUM)
647         (compare (match_operand:SI 0 "nonimmediate_operand" "d,Q,S")
648                  (match_operand:SI 1 "const0_operand" "")))
649    (clobber (match_scratch:SI 2 "=X,d,d"))]
650   "s390_match_ccmode(insn, CCSmode)"
651   "@
652    ltr\t%0,%0
653    icm\t%2,15,%S0
654    icmy\t%2,15,%S0"
655   [(set_attr "op_type" "RR,RS,RSY")
656    (set_attr "z10prop" "z10_fr_E1,z10_super_E1,z10_super_E1")])
657
658 (define_insn "*tstdi_cconly_31"
659   [(set (reg CC_REGNUM)
660         (compare (match_operand:DI 0 "register_operand" "d")
661                  (match_operand:DI 1 "const0_operand" "")))]
662   "s390_match_ccmode(insn, CCSmode) && !TARGET_64BIT"
663   "srda\t%0,0"
664   [(set_attr "op_type" "RS")
665    (set_attr "atype"   "reg")])
666
667 ; ltr, ltgr
668 (define_insn "*tst<mode>_cconly2"
669   [(set (reg CC_REGNUM)
670         (compare (match_operand:GPR 0 "register_operand" "d")
671                  (match_operand:GPR 1 "const0_operand" "")))]
672   "s390_match_ccmode(insn, CCSmode)"
673   "lt<g>r\t%0,%0"
674   [(set_attr "op_type" "RR<E>")
675    (set_attr "z10prop" "z10_fr_E1")])
676
677 ; tst(hi|qi) instruction pattern(s).
678
679 (define_insn "*tst<mode>CCT"
680   [(set (reg CC_REGNUM)
681         (compare (match_operand:HQI 0 "nonimmediate_operand" "?Q,?S,d")
682                  (match_operand:HQI 1 "const0_operand" "")))
683    (set (match_operand:HQI 2 "register_operand" "=d,d,0")
684         (match_dup 0))]
685   "s390_match_ccmode(insn, CCTmode)"
686   "@
687    icm\t%2,<icm_lo>,%S0
688    icmy\t%2,<icm_lo>,%S0
689    tml\t%0,<max_uint>"
690   [(set_attr "op_type" "RS,RSY,RI")
691    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super")])
692
693 (define_insn "*tsthiCCT_cconly"
694   [(set (reg CC_REGNUM)
695         (compare (match_operand:HI 0 "nonimmediate_operand" "Q,S,d")
696                  (match_operand:HI 1 "const0_operand" "")))
697    (clobber (match_scratch:HI 2 "=d,d,X"))]
698   "s390_match_ccmode(insn, CCTmode)"
699   "@
700    icm\t%2,3,%S0
701    icmy\t%2,3,%S0
702    tml\t%0,65535"
703   [(set_attr "op_type" "RS,RSY,RI")
704    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super")])
705
706 (define_insn "*tstqiCCT_cconly"
707   [(set (reg CC_REGNUM)
708         (compare (match_operand:QI 0 "nonimmediate_operand" "?Q,?S,d")
709                  (match_operand:QI 1 "const0_operand" "")))]
710   "s390_match_ccmode(insn, CCTmode)"
711   "@
712    cli\t%S0,0
713    cliy\t%S0,0
714    tml\t%0,255"
715   [(set_attr "op_type" "SI,SIY,RI")
716    (set_attr "z10prop" "z10_super,z10_super,*")])
717
718 (define_insn "*tst<mode>"
719   [(set (reg CC_REGNUM)
720         (compare (match_operand:HQI 0 "s_operand" "Q,S")
721                  (match_operand:HQI 1 "const0_operand" "")))
722    (set (match_operand:HQI 2 "register_operand" "=d,d")
723         (match_dup 0))]
724   "s390_match_ccmode(insn, CCSmode)"
725   "@
726    icm\t%2,<icm_lo>,%S0
727    icmy\t%2,<icm_lo>,%S0"
728   [(set_attr "op_type" "RS,RSY")
729    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
730
731 (define_insn "*tst<mode>_cconly"
732   [(set (reg CC_REGNUM)
733         (compare (match_operand:HQI 0 "s_operand" "Q,S")
734                  (match_operand:HQI 1 "const0_operand" "")))
735    (clobber (match_scratch:HQI 2 "=d,d"))]
736   "s390_match_ccmode(insn, CCSmode)"
737   "@
738    icm\t%2,<icm_lo>,%S0
739    icmy\t%2,<icm_lo>,%S0"
740   [(set_attr "op_type" "RS,RSY")
741    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
742
743
744 ; Compare (equality) instructions
745
746 (define_insn "*cmpdi_cct"
747   [(set (reg CC_REGNUM)
748         (compare (match_operand:DI 0 "nonimmediate_operand" "%d,d,d,d,Q")
749                  (match_operand:DI 1 "general_operand" "d,K,Os,RT,BQ")))]
750   "s390_match_ccmode (insn, CCTmode) && TARGET_64BIT"
751   "@
752    cgr\t%0,%1
753    cghi\t%0,%h1
754    cgfi\t%0,%1
755    cg\t%0,%1
756    #"
757   [(set_attr "op_type" "RRE,RI,RIL,RXY,SS")
758    (set_attr "z10prop" "z10_super_c,z10_super,z10_super,z10_super,*")])
759
760 (define_insn "*cmpsi_cct"
761   [(set (reg CC_REGNUM)
762         (compare (match_operand:SI 0 "nonimmediate_operand" "%d,d,d,d,d,Q")
763                  (match_operand:SI 1 "general_operand" "d,K,Os,R,T,BQ")))]
764   "s390_match_ccmode (insn, CCTmode)"
765   "@
766    cr\t%0,%1
767    chi\t%0,%h1
768    cfi\t%0,%1
769    c\t%0,%1
770    cy\t%0,%1
771    #"
772   [(set_attr "op_type" "RR,RI,RIL,RX,RXY,SS")
773    (set_attr "z10prop" "z10_super,z10_super,z10_super,z10_super,z10_super,*")])
774
775 ; Compare (signed) instructions
776
777 (define_insn "*cmpdi_ccs_sign"
778   [(set (reg CC_REGNUM)
779         (compare (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand"
780                                                      "d,RT,b"))
781                  (match_operand:DI 0 "register_operand" "d, d,d")))]
782   "s390_match_ccmode(insn, CCSRmode) && TARGET_64BIT"
783   "@
784    cgfr\t%0,%1
785    cgf\t%0,%1
786    cgfrl\t%0,%1"
787   [(set_attr "op_type"      "RRE,RXY,RIL")
788    (set_attr "z10prop" "z10_c,*,*")
789    (set_attr "type"         "*,*,larl")])
790
791
792
793 (define_insn "*cmpsi_ccs_sign"
794   [(set (reg CC_REGNUM)
795         (compare (sign_extend:SI (match_operand:HI 1 "memory_operand" "R,T,b"))
796                  (match_operand:SI 0 "register_operand" "d,d,d")))]
797   "s390_match_ccmode(insn, CCSRmode)"
798   "@
799    ch\t%0,%1
800    chy\t%0,%1
801    chrl\t%0,%1"
802   [(set_attr "op_type"      "RX,RXY,RIL")
803    (set_attr "cpu_facility" "*,*,z10")
804    (set_attr "type"         "*,*,larl")])
805
806 (define_insn "*cmphi_ccs_z10"
807   [(set (reg CC_REGNUM)
808         (compare (match_operand:HI 0 "s_operand"         "Q")
809                  (match_operand:HI 1 "immediate_operand" "K")))]
810   "s390_match_ccmode(insn, CCSmode) && TARGET_Z10"
811   "chhsi\t%0,%1"
812   [(set_attr "op_type" "SIL")])
813
814 (define_insn "*cmpdi_ccs_signhi_rl"
815   [(set (reg CC_REGNUM)
816         (compare (sign_extend:DI (match_operand:HI 1 "memory_operand" "RT,b"))
817                  (match_operand:GPR 0 "register_operand"  "d,d")))]
818   "s390_match_ccmode(insn, CCSRmode) && TARGET_Z10"
819   "@
820    cgh\t%0,%1
821    cghrl\t%0,%1"
822   [(set_attr "op_type" "RXY,RIL")
823    (set_attr "type"    "*,larl")])
824
825 ; cr, chi, cfi, c, cy, cgr, cghi, cgfi, cg, chsi, cghsi, crl, cgrl
826 (define_insn "*cmp<mode>_ccs"
827   [(set (reg CC_REGNUM)
828         (compare (match_operand:GPR 0 "nonimmediate_operand"
829                                       "d,d,Q, d,d,d,d")
830                  (match_operand:GPR 1 "general_operand"
831                                       "d,K,K,Os,R,T,b")))]
832   "s390_match_ccmode(insn, CCSmode)"
833   "@
834    c<g>r\t%0,%1
835    c<g>hi\t%0,%h1
836    c<g>hsi\t%0,%h1
837    c<g>fi\t%0,%1
838    c<g>\t%0,%1
839    c<y>\t%0,%1
840    c<g>rl\t%0,%1"
841   [(set_attr "op_type" "RR<E>,RI,SIL,RIL,RX<Y>,RXY,RIL")
842    (set_attr "cpu_facility" "*,*,z10,extimm,*,*,z10")
843    (set_attr "type" "*,*,*,*,*,*,larl")
844    (set_attr "z10prop" "z10_super_c,z10_super,z10_super,z10_super,z10_super,z10_super,z10_super")])
845
846
847 ; Compare (unsigned) instructions
848
849 (define_insn "*cmpsi_ccu_zerohi_rlsi"
850   [(set (reg CC_REGNUM)
851         (compare (zero_extend:SI (mem:HI (match_operand:SI 1
852                                           "larl_operand" "X")))
853                  (match_operand:SI 0 "register_operand" "d")))]
854   "s390_match_ccmode(insn, CCURmode) && TARGET_Z10"
855   "clhrl\t%0,%1"
856   [(set_attr "op_type" "RIL")
857    (set_attr "type"    "larl")])
858
859 ; clhrl, clghrl
860 (define_insn "*cmp<GPR:mode>_ccu_zerohi_rldi"
861   [(set (reg CC_REGNUM)
862         (compare (zero_extend:GPR (mem:HI (match_operand:DI 1
863                                           "larl_operand" "X")))
864                  (match_operand:GPR 0 "register_operand" "d")))]
865   "s390_match_ccmode(insn, CCURmode) && TARGET_Z10"
866   "cl<g>hrl\t%0,%1"
867   [(set_attr "op_type" "RIL")
868    (set_attr "type"    "larl")
869    (set_attr "z10prop" "z10_super")])
870
871 (define_insn "*cmpdi_ccu_zero"
872   [(set (reg CC_REGNUM)
873         (compare (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand"
874                                                         "d,RT,b"))
875                  (match_operand:DI 0 "register_operand" "d, d,d")))]
876   "s390_match_ccmode (insn, CCURmode) && TARGET_64BIT"
877   "@
878    clgfr\t%0,%1
879    clgf\t%0,%1
880    clgfrl\t%0,%1"
881   [(set_attr "op_type"      "RRE,RXY,RIL")
882    (set_attr "cpu_facility" "*,*,z10")
883    (set_attr "type"         "*,*,larl")
884    (set_attr "z10prop" "z10_super_c,z10_super_E1,z10_super")])
885
886 (define_insn "*cmpdi_ccu"
887   [(set (reg CC_REGNUM)
888         (compare (match_operand:DI 0 "nonimmediate_operand"
889                                      "d, d,d,Q, d, Q,BQ")
890                  (match_operand:DI 1 "general_operand"
891                                      "d,Op,b,D,RT,BQ,Q")))]
892   "s390_match_ccmode (insn, CCUmode) && TARGET_64BIT"
893   "@
894    clgr\t%0,%1
895    clgfi\t%0,%1
896    clgrl\t%0,%1
897    clghsi\t%0,%x1
898    clg\t%0,%1
899    #
900    #"
901   [(set_attr "op_type" "RRE,RIL,RIL,SIL,RXY,SS,SS")
902    (set_attr "cpu_facility" "*,extimm,z10,z10,*,*,*")
903    (set_attr "type"         "*,*,larl,*,*,*,*")
904    (set_attr "z10prop" "z10_super_c,z10_super,z10_super,z10_super,z10_super,*,*")])
905
906 (define_insn "*cmpsi_ccu"
907   [(set (reg CC_REGNUM)
908         (compare (match_operand:SI 0 "nonimmediate_operand" "d, d,d,Q,d,d, Q,BQ")
909                  (match_operand:SI 1 "general_operand"      "d,Os,b,D,R,T,BQ, Q")))]
910   "s390_match_ccmode (insn, CCUmode)"
911   "@
912    clr\t%0,%1
913    clfi\t%0,%o1
914    clrl\t%0,%1
915    clfhsi\t%0,%x1
916    cl\t%0,%1
917    cly\t%0,%1
918    #
919    #"
920   [(set_attr "op_type" "RR,RIL,RIL,SIL,RX,RXY,SS,SS")
921    (set_attr "cpu_facility" "*,extimm,z10,z10,*,*,*,*")
922    (set_attr "type"         "*,*,larl,*,*,*,*,*")
923    (set_attr "z10prop" "z10_super_c,z10_super,z10_super,z10_super,z10_super,z10_super,*,*")])
924
925 (define_insn "*cmphi_ccu"
926   [(set (reg CC_REGNUM)
927         (compare (match_operand:HI 0 "nonimmediate_operand" "d,d,Q,Q,BQ")
928                  (match_operand:HI 1 "general_operand"      "Q,S,D,BQ,Q")))]
929   "s390_match_ccmode (insn, CCUmode)
930    && !register_operand (operands[1], HImode)"
931   "@
932    clm\t%0,3,%S1
933    clmy\t%0,3,%S1
934    clhhsi\t%0,%1
935    #
936    #"
937   [(set_attr "op_type" "RS,RSY,SIL,SS,SS")
938    (set_attr "cpu_facility" "*,*,z10,*,*")
939    (set_attr "z10prop" "*,*,z10_super,*,*")])
940
941 (define_insn "*cmpqi_ccu"
942   [(set (reg CC_REGNUM)
943         (compare (match_operand:QI 0 "nonimmediate_operand" "d,d,Q,S,Q,BQ")
944                  (match_operand:QI 1 "general_operand" "Q,S,n,n,BQ,Q")))]
945   "s390_match_ccmode (insn, CCUmode)
946    && !register_operand (operands[1], QImode)"
947   "@
948    clm\t%0,1,%S1
949    clmy\t%0,1,%S1
950    cli\t%S0,%b1
951    cliy\t%S0,%b1
952    #
953    #"
954   [(set_attr "op_type" "RS,RSY,SI,SIY,SS,SS")
955    (set_attr "z10prop" "*,*,z10_super,z10_super,*,*")])
956
957
958 ; Block compare (CLC) instruction patterns.
959
960 (define_insn "*clc"
961   [(set (reg CC_REGNUM)
962         (compare (match_operand:BLK 0 "memory_operand" "Q")
963                  (match_operand:BLK 1 "memory_operand" "Q")))
964    (use (match_operand 2 "const_int_operand" "n"))]
965   "s390_match_ccmode (insn, CCUmode)
966    && INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 256"
967   "clc\t%O0(%2,%R0),%S1"
968   [(set_attr "op_type" "SS")])
969
970 (define_split
971   [(set (reg CC_REGNUM)
972         (compare (match_operand 0 "memory_operand" "")
973                  (match_operand 1 "memory_operand" "")))]
974   "reload_completed
975    && s390_match_ccmode (insn, CCUmode)
976    && GET_MODE (operands[0]) == GET_MODE (operands[1])
977    && GET_MODE_SIZE (GET_MODE (operands[0])) > 0"
978   [(parallel
979     [(set (match_dup 0) (match_dup 1))
980      (use (match_dup 2))])]
981 {
982   operands[2] = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[0])));
983   operands[0] = adjust_address (operands[0], BLKmode, 0);
984   operands[1] = adjust_address (operands[1], BLKmode, 0);
985
986   operands[1] = gen_rtx_COMPARE (GET_MODE (SET_DEST (PATTERN (curr_insn))),
987                                  operands[0], operands[1]);
988   operands[0] = SET_DEST (PATTERN (curr_insn));
989 })
990
991
992 ; (TF|DF|SF|TD|DD|SD) instructions
993
994 ; ltxbr, ltdbr, ltebr, ltxtr, ltdtr
995 (define_insn "*cmp<mode>_ccs_0"
996   [(set (reg CC_REGNUM)
997         (compare (match_operand:FP 0 "register_operand" "f")
998                  (match_operand:FP 1 "const0_operand"   "")))]
999   "s390_match_ccmode(insn, CCSmode) && TARGET_HARD_FLOAT"
1000   "lt<xde><bt>r\t%0,%0"
1001    [(set_attr "op_type" "RRE")
1002     (set_attr "type"  "fsimp<mode>")])
1003
1004 ; cxtr, cxbr, cdbr, cebr, cxb, cdb, ceb, cxbtr, cdbtr
1005 (define_insn "*cmp<mode>_ccs"
1006   [(set (reg CC_REGNUM)
1007         (compare (match_operand:FP 0 "register_operand" "f,f")
1008                  (match_operand:FP 1 "general_operand"  "f,<Rf>")))]
1009   "s390_match_ccmode(insn, CCSmode) && TARGET_HARD_FLOAT"
1010   "@
1011    c<xde><bt>r\t%0,%1
1012    c<xde>b\t%0,%1"
1013    [(set_attr "op_type" "RRE,RXE")
1014     (set_attr "type"  "fsimp<mode>")])
1015
1016
1017 ; Compare and Branch instructions
1018
1019 ; cij, cgij, crj, cgrj, cfi, cgfi, cr, cgr
1020 ; The following instructions do a complementary access of their second
1021 ; operand (z01 only): crj_c, cgrjc, cr, cgr
1022 (define_insn "*cmp_and_br_signed_<mode>"
1023   [(set (pc)
1024         (if_then_else (match_operator 0 "s390_signed_integer_comparison"
1025                         [(match_operand:GPR 1 "register_operand"  "d,d")
1026                          (match_operand:GPR 2 "nonmemory_operand" "d,C")])
1027                       (label_ref (match_operand 3 "" ""))
1028                       (pc)))
1029    (clobber (reg:CC CC_REGNUM))]
1030   "TARGET_Z10"
1031 {
1032   if (get_attr_length (insn) == 6)
1033     return which_alternative ?
1034       "c<g>ij%C0\t%1,%c2,%l3" : "c<g>rj%C0\t%1,%2,%l3";
1035   else
1036     return which_alternative ?
1037       "c<g>fi\t%1,%c2\;jg%C0\t%l3" : "c<g>r\t%1,%2\;jg%C0\t%l3";
1038 }
1039   [(set_attr "op_type" "RIE")
1040    (set_attr "type"    "branch")
1041    (set_attr "z10prop" "z10_cobra,z10_super")
1042    (set (attr "length")
1043         (if_then_else (lt (abs (minus (pc) (match_dup 3))) (const_int 60000))
1044                       (const_int 6) (const_int 12)))]) ; 8 byte for cr/jg
1045                                                        ; 10 byte for cgr/jg
1046
1047 ; clij, clgij, clrj, clgrj, clfi, clgfi, clr, clgr
1048 ; The following instructions do a complementary access of their second
1049 ; operand (z10 only): clrj, clgrj, clr, clgr
1050 (define_insn "*cmp_and_br_unsigned_<mode>"
1051   [(set (pc)
1052         (if_then_else (match_operator 0 "s390_unsigned_integer_comparison"
1053                         [(match_operand:GPR 1 "register_operand"  "d,d")
1054                          (match_operand:GPR 2 "nonmemory_operand" "d,I")])
1055                       (label_ref (match_operand 3 "" ""))
1056                       (pc)))
1057    (clobber (reg:CC CC_REGNUM))]
1058   "TARGET_Z10"
1059 {
1060   if (get_attr_length (insn) == 6)
1061     return which_alternative ?
1062       "cl<g>ij%C0\t%1,%b2,%l3" : "cl<g>rj%C0\t%1,%2,%l3";
1063   else
1064     return which_alternative ?
1065       "cl<g>fi\t%1,%b2\;jg%C0\t%l3" : "cl<g>r\t%1,%2\;jg%C0\t%l3";
1066 }
1067   [(set_attr "op_type" "RIE")
1068    (set_attr "type"    "branch")
1069    (set_attr "z10prop" "z10_cobra,z10_super")
1070    (set (attr "length")
1071         (if_then_else (lt (abs (minus (pc) (match_dup 3))) (const_int 60000))
1072                       (const_int 6) (const_int 12)))]) ; 8 byte for clr/jg
1073                                                        ; 10 byte for clgr/jg
1074
1075 ;;
1076 ;;- Move instructions.
1077 ;;
1078
1079 ;
1080 ; movti instruction pattern(s).
1081 ;
1082
1083 (define_insn "movti"
1084   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,QS,d,o")
1085         (match_operand:TI 1 "general_operand" "QS,d,dPRT,d"))]
1086   "TARGET_64BIT"
1087   "@
1088    lmg\t%0,%N0,%S1
1089    stmg\t%1,%N1,%S0
1090    #
1091    #"
1092   [(set_attr "op_type" "RSY,RSY,*,*")
1093    (set_attr "type" "lm,stm,*,*")])
1094
1095 (define_split
1096   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1097         (match_operand:TI 1 "general_operand" ""))]
1098   "TARGET_64BIT && reload_completed
1099    && s390_split_ok_p (operands[0], operands[1], TImode, 0)"
1100   [(set (match_dup 2) (match_dup 4))
1101    (set (match_dup 3) (match_dup 5))]
1102 {
1103   operands[2] = operand_subword (operands[0], 0, 0, TImode);
1104   operands[3] = operand_subword (operands[0], 1, 0, TImode);
1105   operands[4] = operand_subword (operands[1], 0, 0, TImode);
1106   operands[5] = operand_subword (operands[1], 1, 0, TImode);
1107 })
1108
1109 (define_split
1110   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1111         (match_operand:TI 1 "general_operand" ""))]
1112   "TARGET_64BIT && reload_completed
1113    && s390_split_ok_p (operands[0], operands[1], TImode, 1)"
1114   [(set (match_dup 2) (match_dup 4))
1115    (set (match_dup 3) (match_dup 5))]
1116 {
1117   operands[2] = operand_subword (operands[0], 1, 0, TImode);
1118   operands[3] = operand_subword (operands[0], 0, 0, TImode);
1119   operands[4] = operand_subword (operands[1], 1, 0, TImode);
1120   operands[5] = operand_subword (operands[1], 0, 0, TImode);
1121 })
1122
1123 (define_split
1124   [(set (match_operand:TI 0 "register_operand" "")
1125         (match_operand:TI 1 "memory_operand" ""))]
1126   "TARGET_64BIT && reload_completed
1127    && !s_operand (operands[1], VOIDmode)"
1128   [(set (match_dup 0) (match_dup 1))]
1129 {
1130   rtx addr = operand_subword (operands[0], 1, 0, TImode);
1131   s390_load_address (addr, XEXP (operands[1], 0));
1132   operands[1] = replace_equiv_address (operands[1], addr);
1133 })
1134
1135
1136 ;
1137 ; Patterns used for secondary reloads
1138 ;
1139
1140 ; z10 provides move instructions accepting larl memory operands.
1141 ; Unfortunately there is no such variant for QI, TI and FP mode moves.
1142 ; These patterns are also used for unaligned SI and DI accesses.
1143
1144 (define_expand "reload<INTALL:mode><P:mode>_tomem_z10"
1145   [(parallel [(match_operand:INTALL 0 "memory_operand"   "")
1146               (match_operand:INTALL 1 "register_operand" "=d")
1147               (match_operand:P 2 "register_operand" "=&a")])]
1148   "TARGET_Z10"
1149 {
1150   s390_reload_symref_address (operands[1], operands[0], operands[2], 1);
1151   DONE;
1152 })
1153
1154 (define_expand "reload<INTALL:mode><P:mode>_toreg_z10"
1155   [(parallel [(match_operand:INTALL 0 "register_operand" "=d")
1156               (match_operand:INTALL 1 "memory_operand"   "")
1157               (match_operand:P 2 "register_operand" "=a")])]
1158   "TARGET_Z10"
1159 {
1160   s390_reload_symref_address (operands[0], operands[1], operands[2], 0);
1161   DONE;
1162 })
1163
1164 (define_expand "reload<FPALL:mode><P:mode>_tomem_z10"
1165   [(parallel [(match_operand:FPALL 0 "memory_operand"   "")
1166               (match_operand:FPALL 1 "register_operand" "=d")
1167               (match_operand:P 2 "register_operand" "=&a")])]
1168   "TARGET_Z10"
1169 {
1170   s390_reload_symref_address (operands[1], operands[0], operands[2], 1);
1171   DONE;
1172 })
1173
1174 (define_expand "reload<FPALL:mode><P:mode>_toreg_z10"
1175   [(parallel [(match_operand:FPALL 0 "register_operand" "=d")
1176               (match_operand:FPALL 1 "memory_operand"   "")
1177               (match_operand:P 2 "register_operand" "=a")])]
1178   "TARGET_Z10"
1179 {
1180   s390_reload_symref_address (operands[0], operands[1], operands[2], 0);
1181   DONE;
1182 })
1183
1184 (define_expand "reload<P:mode>_larl_odd_addend_z10"
1185   [(parallel [(match_operand:P 0 "register_operand" "=d")
1186               (match_operand:P 1 "larl_operand"     "")
1187               (match_operand:P 2 "register_operand" "=a")])]
1188   "TARGET_Z10"
1189 {
1190   s390_reload_larl_operand (operands[0], operands[1], operands[2]);
1191   DONE;
1192 })
1193
1194 ; Handles loading a PLUS (load address) expression
1195
1196 (define_expand "reload<mode>_plus"
1197   [(parallel [(match_operand:P 0 "register_operand"  "=a")
1198               (match_operand:P 1 "s390_plus_operand" "")
1199               (match_operand:P 2 "register_operand"  "=&a")])]
1200   ""
1201 {
1202   s390_expand_plus_operand (operands[0], operands[1], operands[2]);
1203   DONE;
1204 })
1205
1206 ; Handles assessing a non-offsetable memory address
1207
1208 (define_expand "reload<mode>_nonoffmem_in"
1209   [(parallel [(match_operand 0   "register_operand" "")
1210               (match_operand 1   "" "")
1211               (match_operand:P 2 "register_operand" "=&a")])]
1212   ""
1213 {
1214   gcc_assert (MEM_P (operands[1]));
1215   s390_load_address (operands[2], find_replacement (&XEXP (operands[1], 0)));
1216   operands[1] = replace_equiv_address (operands[1], operands[2]);
1217   emit_move_insn (operands[0], operands[1]);
1218   DONE;
1219 })
1220
1221 (define_expand "reload<mode>_nonoffmem_out"
1222   [(parallel [(match_operand   0 "" "")
1223               (match_operand   1 "register_operand" "")
1224               (match_operand:P 2 "register_operand" "=&a")])]
1225   ""
1226 {
1227   gcc_assert (MEM_P (operands[0]));
1228   s390_load_address (operands[2], find_replacement (&XEXP (operands[0], 0)));
1229   operands[0] = replace_equiv_address (operands[0], operands[2]);
1230   emit_move_insn (operands[0], operands[1]);
1231   DONE;
1232 })
1233
1234 (define_expand "reload<mode>_PIC_addr"
1235   [(parallel [(match_operand   0 "register_operand" "=d")
1236               (match_operand   1 "larl_operand"     "")
1237               (match_operand:P 2 "register_operand" "=a")])]
1238   ""
1239 {
1240   rtx new_rtx = legitimize_pic_address (operands[1], operands[2]);
1241   emit_move_insn (operands[0], new_rtx);
1242 })
1243
1244 ;
1245 ; movdi instruction pattern(s).
1246 ;
1247
1248 (define_expand "movdi"
1249   [(set (match_operand:DI 0 "general_operand" "")
1250         (match_operand:DI 1 "general_operand" ""))]
1251   ""
1252 {
1253   /* Handle symbolic constants.  */
1254   if (TARGET_64BIT
1255       && (SYMBOLIC_CONST (operands[1])
1256           || (GET_CODE (operands[1]) == PLUS
1257               && XEXP (operands[1], 0) == pic_offset_table_rtx
1258               && SYMBOLIC_CONST (XEXP (operands[1], 1)))))
1259     emit_symbolic_move (operands);
1260 })
1261
1262 (define_insn "*movdi_larl"
1263   [(set (match_operand:DI 0 "register_operand" "=d")
1264         (match_operand:DI 1 "larl_operand" "X"))]
1265   "TARGET_64BIT
1266    && !FP_REG_P (operands[0])"
1267   "larl\t%0,%1"
1268    [(set_attr "op_type" "RIL")
1269     (set_attr "type"    "larl")
1270     (set_attr "z10prop" "z10_super_A1")])
1271
1272 (define_insn "*movdi_64"
1273   [(set (match_operand:DI 0 "nonimmediate_operand"
1274                             "=d,d,d,d,d,d,d,d,f,d,d,d,d,d,
1275                              RT,!*f,!*f,!*f,!R,!T,b,Q,d,t,Q,t")
1276         (match_operand:DI 1 "general_operand"
1277                             "K,N0HD0,N1HD0,N2HD0,N3HD0,Os,N0SD0,N1SD0,d,f,L,b,d,RT,
1278                              d,*f,R,T,*f,*f,d,K,t,d,t,Q"))]
1279   "TARGET_64BIT"
1280   "@
1281    lghi\t%0,%h1
1282    llihh\t%0,%i1
1283    llihl\t%0,%i1
1284    llilh\t%0,%i1
1285    llill\t%0,%i1
1286    lgfi\t%0,%1
1287    llihf\t%0,%k1
1288    llilf\t%0,%k1
1289    ldgr\t%0,%1
1290    lgdr\t%0,%1
1291    lay\t%0,%a1
1292    lgrl\t%0,%1
1293    lgr\t%0,%1
1294    lg\t%0,%1
1295    stg\t%1,%0
1296    ldr\t%0,%1
1297    ld\t%0,%1
1298    ldy\t%0,%1
1299    std\t%1,%0
1300    stdy\t%1,%0
1301    stgrl\t%1,%0
1302    mvghi\t%0,%1
1303    #
1304    #
1305    stam\t%1,%N1,%S0
1306    lam\t%0,%N0,%S1"
1307   [(set_attr "op_type" "RI,RI,RI,RI,RI,RIL,RIL,RIL,RRE,RRE,RXY,RIL,RRE,RXY,
1308                         RXY,RR,RX,RXY,RX,RXY,RIL,SIL,*,*,RS,RS")
1309    (set_attr "type" "*,*,*,*,*,*,*,*,floaddf,floaddf,la,larl,lr,load,store,
1310                      floaddf,floaddf,floaddf,fstoredf,fstoredf,larl,*,*,*,
1311                      *,*")
1312    (set_attr "cpu_facility" "*,*,*,*,*,extimm,extimm,extimm,dfp,dfp,longdisp,
1313                              z10,*,*,*,*,*,longdisp,*,longdisp,
1314                              z10,z10,*,*,*,*")
1315    (set_attr "z10prop" "z10_fwd_A1,
1316                         z10_fwd_E1,
1317                         z10_fwd_E1,
1318                         z10_fwd_E1,
1319                         z10_fwd_E1,
1320                         z10_fwd_A1,
1321                         z10_fwd_E1,
1322                         z10_fwd_E1,
1323                         *,
1324                         *,
1325                         z10_fwd_A1,
1326                         z10_fwd_A3,
1327                         z10_fr_E1,
1328                         z10_fwd_A3,
1329                         z10_rec,
1330                         *,
1331                         *,
1332                         *,
1333                         *,
1334                         *,
1335                         z10_rec,
1336                         z10_super,
1337                         *,
1338                         *,
1339                         *,
1340                         *")
1341 ])
1342
1343 (define_split
1344   [(set (match_operand:DI 0 "register_operand" "")
1345         (match_operand:DI 1 "register_operand" ""))]
1346   "TARGET_64BIT && ACCESS_REG_P (operands[1])"
1347   [(set (match_dup 2) (match_dup 3))
1348    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
1349    (set (strict_low_part (match_dup 2)) (match_dup 4))]
1350   "operands[2] = gen_lowpart (SImode, operands[0]);
1351    s390_split_access_reg (operands[1], &operands[4], &operands[3]);")
1352
1353 (define_split
1354   [(set (match_operand:DI 0 "register_operand" "")
1355         (match_operand:DI 1 "register_operand" ""))]
1356   "TARGET_64BIT && ACCESS_REG_P (operands[0])
1357    && dead_or_set_p (insn, operands[1])"
1358   [(set (match_dup 3) (match_dup 2))
1359    (set (match_dup 1) (lshiftrt:DI (match_dup 1) (const_int 32)))
1360    (set (match_dup 4) (match_dup 2))]
1361   "operands[2] = gen_lowpart (SImode, operands[1]);
1362    s390_split_access_reg (operands[0], &operands[3], &operands[4]);")
1363
1364 (define_split
1365   [(set (match_operand:DI 0 "register_operand" "")
1366         (match_operand:DI 1 "register_operand" ""))]
1367   "TARGET_64BIT && ACCESS_REG_P (operands[0])
1368    && !dead_or_set_p (insn, operands[1])"
1369   [(set (match_dup 3) (match_dup 2))
1370    (set (match_dup 1) (rotate:DI (match_dup 1) (const_int 32)))
1371    (set (match_dup 4) (match_dup 2))
1372    (set (match_dup 1) (rotate:DI (match_dup 1) (const_int 32)))]
1373   "operands[2] = gen_lowpart (SImode, operands[1]);
1374    s390_split_access_reg (operands[0], &operands[3], &operands[4]);")
1375
1376 (define_insn "*movdi_31"
1377   [(set (match_operand:DI 0 "nonimmediate_operand"
1378                             "=d,d,Q,S,d   ,o,!*f,!*f,!*f,!R,!T,d")
1379         (match_operand:DI 1 "general_operand"
1380                             " Q,S,d,d,dPRT,d, *f,  R,  T,*f,*f,b"))]
1381   "!TARGET_64BIT"
1382   "@
1383    lm\t%0,%N0,%S1
1384    lmy\t%0,%N0,%S1
1385    stm\t%1,%N1,%S0
1386    stmy\t%1,%N1,%S0
1387    #
1388    #
1389    ldr\t%0,%1
1390    ld\t%0,%1
1391    ldy\t%0,%1
1392    std\t%1,%0
1393    stdy\t%1,%0
1394    #"
1395   [(set_attr "op_type" "RS,RSY,RS,RSY,*,*,RR,RX,RXY,RX,RXY,*")
1396    (set_attr "type" "lm,lm,stm,stm,*,*,floaddf,floaddf,floaddf,fstoredf,fstoredf,*")
1397    (set_attr "cpu_facility" "*,*,*,*,*,*,*,*,*,*,*,z10")])
1398
1399 ; For a load from a symbol ref we can use one of the target registers
1400 ; together with larl to load the address.
1401 (define_split
1402   [(set (match_operand:DI 0 "register_operand" "")
1403         (match_operand:DI 1 "memory_operand" ""))]
1404   "!TARGET_64BIT && reload_completed && TARGET_Z10
1405    && larl_operand (XEXP (operands[1], 0), SImode)"
1406   [(set (match_dup 2) (match_dup 3))
1407    (set (match_dup 0) (match_dup 1))]
1408 {
1409   operands[2] = operand_subword (operands[0], 1, 0, DImode);
1410   operands[3] = XEXP (operands[1], 0);
1411   operands[1] = replace_equiv_address (operands[1], operands[2]);
1412 })
1413
1414 (define_split
1415   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1416         (match_operand:DI 1 "general_operand" ""))]
1417   "!TARGET_64BIT && reload_completed
1418    && s390_split_ok_p (operands[0], operands[1], DImode, 0)"
1419   [(set (match_dup 2) (match_dup 4))
1420    (set (match_dup 3) (match_dup 5))]
1421 {
1422   operands[2] = operand_subword (operands[0], 0, 0, DImode);
1423   operands[3] = operand_subword (operands[0], 1, 0, DImode);
1424   operands[4] = operand_subword (operands[1], 0, 0, DImode);
1425   operands[5] = operand_subword (operands[1], 1, 0, DImode);
1426 })
1427
1428 (define_split
1429   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1430         (match_operand:DI 1 "general_operand" ""))]
1431   "!TARGET_64BIT && reload_completed
1432    && s390_split_ok_p (operands[0], operands[1], DImode, 1)"
1433   [(set (match_dup 2) (match_dup 4))
1434    (set (match_dup 3) (match_dup 5))]
1435 {
1436   operands[2] = operand_subword (operands[0], 1, 0, DImode);
1437   operands[3] = operand_subword (operands[0], 0, 0, DImode);
1438   operands[4] = operand_subword (operands[1], 1, 0, DImode);
1439   operands[5] = operand_subword (operands[1], 0, 0, DImode);
1440 })
1441
1442 (define_split
1443   [(set (match_operand:DI 0 "register_operand" "")
1444         (match_operand:DI 1 "memory_operand" ""))]
1445   "!TARGET_64BIT && reload_completed
1446    && !FP_REG_P (operands[0])
1447    && !s_operand (operands[1], VOIDmode)"
1448   [(set (match_dup 0) (match_dup 1))]
1449 {
1450   rtx addr = operand_subword (operands[0], 1, 0, DImode);
1451   s390_load_address (addr, XEXP (operands[1], 0));
1452   operands[1] = replace_equiv_address (operands[1], addr);
1453 })
1454
1455 (define_peephole2
1456   [(set (match_operand:DI 0 "register_operand" "")
1457         (mem:DI (match_operand 1 "address_operand" "")))]
1458   "TARGET_64BIT
1459    && !FP_REG_P (operands[0])
1460    && GET_CODE (operands[1]) == SYMBOL_REF
1461    && CONSTANT_POOL_ADDRESS_P (operands[1])
1462    && get_pool_mode (operands[1]) == DImode
1463    && legitimate_reload_constant_p (get_pool_constant (operands[1]))"
1464   [(set (match_dup 0) (match_dup 2))]
1465   "operands[2] = get_pool_constant (operands[1]);")
1466
1467 (define_insn "*la_64"
1468   [(set (match_operand:DI 0 "register_operand" "=d,d")
1469         (match_operand:QI 1 "address_operand" "U,W"))]
1470   "TARGET_64BIT"
1471   "@
1472    la\t%0,%a1
1473    lay\t%0,%a1"
1474   [(set_attr "op_type" "RX,RXY")
1475    (set_attr "type"    "la")
1476    (set_attr "z10prop" "z10_fwd_A1,z10_fwd_A1")])
1477
1478 (define_peephole2
1479   [(parallel
1480     [(set (match_operand:DI 0 "register_operand" "")
1481           (match_operand:QI 1 "address_operand" ""))
1482      (clobber (reg:CC CC_REGNUM))])]
1483   "TARGET_64BIT
1484    && preferred_la_operand_p (operands[1], const0_rtx)"
1485   [(set (match_dup 0) (match_dup 1))]
1486   "")
1487
1488 (define_peephole2
1489   [(set (match_operand:DI 0 "register_operand" "")
1490         (match_operand:DI 1 "register_operand" ""))
1491    (parallel
1492     [(set (match_dup 0)
1493           (plus:DI (match_dup 0)
1494                    (match_operand:DI 2 "nonmemory_operand" "")))
1495      (clobber (reg:CC CC_REGNUM))])]
1496   "TARGET_64BIT
1497    && !reg_overlap_mentioned_p (operands[0], operands[2])
1498    && preferred_la_operand_p (operands[1], operands[2])"
1499   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))]
1500   "")
1501
1502 ;
1503 ; movsi instruction pattern(s).
1504 ;
1505
1506 (define_expand "movsi"
1507   [(set (match_operand:SI 0 "general_operand" "")
1508         (match_operand:SI 1 "general_operand" ""))]
1509   ""
1510 {
1511   /* Handle symbolic constants.  */
1512   if (!TARGET_64BIT
1513       && (SYMBOLIC_CONST (operands[1])
1514           || (GET_CODE (operands[1]) == PLUS
1515               && XEXP (operands[1], 0) == pic_offset_table_rtx
1516               && SYMBOLIC_CONST (XEXP(operands[1], 1)))))
1517     emit_symbolic_move (operands);
1518 })
1519
1520 (define_insn "*movsi_larl"
1521   [(set (match_operand:SI 0 "register_operand" "=d")
1522         (match_operand:SI 1 "larl_operand" "X"))]
1523   "!TARGET_64BIT && TARGET_CPU_ZARCH
1524    && !FP_REG_P (operands[0])"
1525   "larl\t%0,%1"
1526    [(set_attr "op_type" "RIL")
1527     (set_attr "type"    "larl")
1528     (set_attr "z10prop" "z10_super_A1")])
1529
1530 (define_insn "*movsi_zarch"
1531   [(set (match_operand:SI 0 "nonimmediate_operand"
1532                             "=d,d,d,d,d,d,d,d,d,R,T,!*f,!*f,!*f,!R,!T,d,t,Q,b,Q,t")
1533         (match_operand:SI 1 "general_operand"
1534                             "K,N0HS0,N1HS0,Os,L,b,d,R,T,d,d,*f,R,T,*f,*f,t,d,t,d,K,Q"))]
1535   "TARGET_ZARCH"
1536   "@
1537    lhi\t%0,%h1
1538    llilh\t%0,%i1
1539    llill\t%0,%i1
1540    iilf\t%0,%o1
1541    lay\t%0,%a1
1542    lrl\t%0,%1
1543    lr\t%0,%1
1544    l\t%0,%1
1545    ly\t%0,%1
1546    st\t%1,%0
1547    sty\t%1,%0
1548    ler\t%0,%1
1549    le\t%0,%1
1550    ley\t%0,%1
1551    ste\t%1,%0
1552    stey\t%1,%0
1553    ear\t%0,%1
1554    sar\t%0,%1
1555    stam\t%1,%1,%S0
1556    strl\t%1,%0
1557    mvhi\t%0,%1
1558    lam\t%0,%0,%S1"
1559   [(set_attr "op_type" "RI,RI,RI,RIL,RXY,RIL,RR,RX,RXY,RX,RXY,
1560                         RR,RX,RXY,RX,RXY,RRE,RRE,RS,RIL,SIL,RS")
1561    (set_attr "type" "*,
1562                      *,
1563                      *,
1564                      *,
1565                      la,
1566                      larl,
1567                      lr,
1568                      load,
1569                      load,
1570                      store,
1571                      store,
1572                      floadsf,
1573                      floadsf,
1574                      floadsf,
1575                      fstoresf,
1576                      fstoresf,
1577                      *,
1578                      *,
1579                      *,
1580                      larl,
1581                      *,
1582                      *")
1583    (set_attr "cpu_facility" "*,*,*,extimm,longdisp,z10,*,*,longdisp,*,longdisp,
1584                              *,*,longdisp,*,longdisp,*,*,*,z10,z10,*")
1585    (set_attr "z10prop" "z10_fwd_A1,
1586                         z10_fwd_E1,
1587                         z10_fwd_E1,
1588                         z10_fwd_A1,
1589                         z10_fwd_A1,
1590                         z10_fwd_A3,
1591                         z10_fr_E1,
1592                         z10_fwd_A3,
1593                         z10_fwd_A3,
1594                         z10_super,
1595                         z10_rec,
1596                         *,
1597                         *,
1598                         *,
1599                         *,
1600                         *,
1601                         z10_super_E1,
1602                         z10_super,
1603                         *,
1604                         z10_rec,
1605                         z10_super,
1606                         *")])
1607
1608 (define_insn "*movsi_esa"
1609   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,R,!*f,!*f,!R,d,t,Q,t")
1610         (match_operand:SI 1 "general_operand" "K,d,R,d,*f,R,*f,t,d,t,Q"))]
1611   "!TARGET_ZARCH"
1612   "@
1613    lhi\t%0,%h1
1614    lr\t%0,%1
1615    l\t%0,%1
1616    st\t%1,%0
1617    ler\t%0,%1
1618    le\t%0,%1
1619    ste\t%1,%0
1620    ear\t%0,%1
1621    sar\t%0,%1
1622    stam\t%1,%1,%S0
1623    lam\t%0,%0,%S1"
1624   [(set_attr "op_type" "RI,RR,RX,RX,RR,RX,RX,RRE,RRE,RS,RS")
1625    (set_attr "type" "*,lr,load,store,floadsf,floadsf,fstoresf,*,*,*,*")
1626    (set_attr "z10prop" "z10_fwd_A1,
1627                         z10_fr_E1,
1628                         z10_fwd_A3,
1629                         z10_super,
1630                         *,
1631                         *,
1632                         *,
1633                         z10_super_E1,
1634                         z10_super,
1635                         *,
1636                         *")
1637 ])
1638
1639 (define_peephole2
1640   [(set (match_operand:SI 0 "register_operand" "")
1641         (mem:SI (match_operand 1 "address_operand" "")))]
1642   "!FP_REG_P (operands[0])
1643    && GET_CODE (operands[1]) == SYMBOL_REF
1644    && CONSTANT_POOL_ADDRESS_P (operands[1])
1645    && get_pool_mode (operands[1]) == SImode
1646    && legitimate_reload_constant_p (get_pool_constant (operands[1]))"
1647   [(set (match_dup 0) (match_dup 2))]
1648   "operands[2] = get_pool_constant (operands[1]);")
1649
1650 (define_insn "*la_31"
1651   [(set (match_operand:SI 0 "register_operand" "=d,d")
1652         (match_operand:QI 1 "address_operand" "U,W"))]
1653   "!TARGET_64BIT && legitimate_la_operand_p (operands[1])"
1654   "@
1655    la\t%0,%a1
1656    lay\t%0,%a1"
1657   [(set_attr "op_type"  "RX,RXY")
1658    (set_attr "type"     "la")
1659    (set_attr "z10prop" "z10_fwd_A1,z10_fwd_A1")])
1660
1661 (define_peephole2
1662   [(parallel
1663     [(set (match_operand:SI 0 "register_operand" "")
1664           (match_operand:QI 1 "address_operand" ""))
1665      (clobber (reg:CC CC_REGNUM))])]
1666   "!TARGET_64BIT
1667    && preferred_la_operand_p (operands[1], const0_rtx)"
1668   [(set (match_dup 0) (match_dup 1))]
1669   "")
1670
1671 (define_peephole2
1672   [(set (match_operand:SI 0 "register_operand" "")
1673         (match_operand:SI 1 "register_operand" ""))
1674    (parallel
1675     [(set (match_dup 0)
1676           (plus:SI (match_dup 0)
1677                    (match_operand:SI 2 "nonmemory_operand" "")))
1678      (clobber (reg:CC CC_REGNUM))])]
1679   "!TARGET_64BIT
1680    && !reg_overlap_mentioned_p (operands[0], operands[2])
1681    && preferred_la_operand_p (operands[1], operands[2])"
1682   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))]
1683   "")
1684
1685 (define_insn "*la_31_and"
1686   [(set (match_operand:SI 0 "register_operand" "=d,d")
1687         (and:SI (match_operand:QI 1 "address_operand" "U,W")
1688                 (const_int 2147483647)))]
1689   "!TARGET_64BIT"
1690   "@
1691    la\t%0,%a1
1692    lay\t%0,%a1"
1693   [(set_attr "op_type"  "RX,RXY")
1694    (set_attr "type"     "la")
1695    (set_attr "z10prop" "z10_fwd_A1,z10_fwd_A1")])
1696
1697 (define_insn_and_split "*la_31_and_cc"
1698   [(set (match_operand:SI 0 "register_operand" "=d")
1699         (and:SI (match_operand:QI 1 "address_operand" "p")
1700                 (const_int 2147483647)))
1701    (clobber (reg:CC CC_REGNUM))]
1702   "!TARGET_64BIT"
1703   "#"
1704   "&& reload_completed"
1705   [(set (match_dup 0)
1706         (and:SI (match_dup 1) (const_int 2147483647)))]
1707   ""
1708   [(set_attr "op_type"  "RX")
1709    (set_attr "type"     "la")])
1710
1711 (define_insn "force_la_31"
1712   [(set (match_operand:SI 0 "register_operand" "=d,d")
1713         (match_operand:QI 1 "address_operand" "U,W"))
1714    (use (const_int 0))]
1715   "!TARGET_64BIT"
1716   "@
1717    la\t%0,%a1
1718    lay\t%0,%a1"
1719   [(set_attr "op_type"  "RX")
1720    (set_attr "type"     "la")
1721    (set_attr "z10prop" "z10_fwd_A1,z10_fwd_A1")])
1722
1723 ;
1724 ; movhi instruction pattern(s).
1725 ;
1726
1727 (define_expand "movhi"
1728   [(set (match_operand:HI 0 "nonimmediate_operand" "")
1729         (match_operand:HI 1 "general_operand" ""))]
1730   ""
1731 {
1732   /* Make it explicit that loading a register from memory
1733      always sign-extends (at least) to SImode.  */
1734   if (optimize && can_create_pseudo_p ()
1735       && register_operand (operands[0], VOIDmode)
1736       && GET_CODE (operands[1]) == MEM)
1737     {
1738       rtx tmp = gen_reg_rtx (SImode);
1739       rtx ext = gen_rtx_SIGN_EXTEND (SImode, operands[1]);
1740       emit_insn (gen_rtx_SET (VOIDmode, tmp, ext));
1741       operands[1] = gen_lowpart (HImode, tmp);
1742     }
1743 })
1744
1745 (define_insn "*movhi"
1746   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,d,d,R,T,b,Q")
1747         (match_operand:HI 1 "general_operand"      " d,n,R,T,b,d,d,d,K"))]
1748   ""
1749   "@
1750    lr\t%0,%1
1751    lhi\t%0,%h1
1752    lh\t%0,%1
1753    lhy\t%0,%1
1754    lhrl\t%0,%1
1755    sth\t%1,%0
1756    sthy\t%1,%0
1757    sthrl\t%1,%0
1758    mvhhi\t%0,%1"
1759   [(set_attr "op_type"      "RR,RI,RX,RXY,RIL,RX,RXY,RIL,SIL")
1760    (set_attr "type"         "lr,*,*,*,larl,store,store,store,*")
1761    (set_attr "cpu_facility" "*,*,*,*,z10,*,*,z10,z10")
1762    (set_attr "z10prop" "z10_fr_E1,
1763                        z10_fwd_A1,
1764                        z10_super_E1,
1765                        z10_super_E1,
1766                        z10_super_E1,
1767                        z10_super,
1768                        z10_rec,
1769                        z10_rec,
1770                        z10_super")])
1771
1772 (define_peephole2
1773   [(set (match_operand:HI 0 "register_operand" "")
1774         (mem:HI (match_operand 1 "address_operand" "")))]
1775   "GET_CODE (operands[1]) == SYMBOL_REF
1776    && CONSTANT_POOL_ADDRESS_P (operands[1])
1777    && get_pool_mode (operands[1]) == HImode
1778    && GET_CODE (get_pool_constant (operands[1])) == CONST_INT"
1779   [(set (match_dup 0) (match_dup 2))]
1780   "operands[2] = get_pool_constant (operands[1]);")
1781
1782 ;
1783 ; movqi instruction pattern(s).
1784 ;
1785
1786 (define_expand "movqi"
1787   [(set (match_operand:QI 0 "nonimmediate_operand" "")
1788         (match_operand:QI 1 "general_operand" ""))]
1789   ""
1790 {
1791   /* On z/Architecture, zero-extending from memory to register
1792      is just as fast as a QImode load.  */
1793   if (TARGET_ZARCH && optimize && can_create_pseudo_p ()
1794       && register_operand (operands[0], VOIDmode)
1795       && GET_CODE (operands[1]) == MEM)
1796     {
1797       rtx tmp = gen_reg_rtx (word_mode);
1798       rtx ext = gen_rtx_ZERO_EXTEND (word_mode, operands[1]);
1799       emit_insn (gen_rtx_SET (VOIDmode, tmp, ext));
1800       operands[1] = gen_lowpart (QImode, tmp);
1801     }
1802 })
1803
1804 (define_insn "*movqi"
1805   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,d,R,T,Q,S")
1806         (match_operand:QI 1 "general_operand" "d,n,R,T,d,d,n,n"))]
1807   ""
1808   "@
1809    lr\t%0,%1
1810    lhi\t%0,%b1
1811    ic\t%0,%1
1812    icy\t%0,%1
1813    stc\t%1,%0
1814    stcy\t%1,%0
1815    mvi\t%S0,%b1
1816    mviy\t%S0,%b1"
1817   [(set_attr "op_type" "RR,RI,RX,RXY,RX,RXY,SI,SIY")
1818    (set_attr "type" "lr,*,*,*,store,store,store,store")
1819    (set_attr "z10prop" "z10_fr_E1,
1820                         z10_fwd_A1,
1821                         z10_super_E1,
1822                         z10_super_E1,
1823                         z10_super,
1824                         z10_rec,
1825                         z10_super,
1826                         z10_super")])
1827
1828 (define_peephole2
1829   [(set (match_operand:QI 0 "nonimmediate_operand" "")
1830         (mem:QI (match_operand 1 "address_operand" "")))]
1831   "GET_CODE (operands[1]) == SYMBOL_REF
1832    && CONSTANT_POOL_ADDRESS_P (operands[1])
1833    && get_pool_mode (operands[1]) == QImode
1834    && GET_CODE (get_pool_constant (operands[1])) == CONST_INT"
1835   [(set (match_dup 0) (match_dup 2))]
1836   "operands[2] = get_pool_constant (operands[1]);")
1837
1838 ;
1839 ; movstrictqi instruction pattern(s).
1840 ;
1841
1842 (define_insn "*movstrictqi"
1843   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d,d"))
1844                          (match_operand:QI 1 "memory_operand" "R,T"))]
1845   ""
1846   "@
1847    ic\t%0,%1
1848    icy\t%0,%1"
1849   [(set_attr "op_type"  "RX,RXY")
1850    (set_attr "z10prop" "z10_super_E1,z10_super")])
1851
1852 ;
1853 ; movstricthi instruction pattern(s).
1854 ;
1855
1856 (define_insn "*movstricthi"
1857   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d,d"))
1858                          (match_operand:HI 1 "memory_operand" "Q,S"))
1859    (clobber (reg:CC CC_REGNUM))]
1860   ""
1861   "@
1862    icm\t%0,3,%S1
1863    icmy\t%0,3,%S1"
1864   [(set_attr "op_type" "RS,RSY")
1865    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
1866
1867 ;
1868 ; movstrictsi instruction pattern(s).
1869 ;
1870
1871 (define_insn "movstrictsi"
1872   [(set (strict_low_part (match_operand:SI 0 "register_operand" "+d,d,d,d"))
1873                          (match_operand:SI 1 "general_operand" "d,R,T,t"))]
1874   "TARGET_64BIT"
1875   "@
1876    lr\t%0,%1
1877    l\t%0,%1
1878    ly\t%0,%1
1879    ear\t%0,%1"
1880   [(set_attr "op_type" "RR,RX,RXY,RRE")
1881    (set_attr "type" "lr,load,load,*")
1882    (set_attr "z10prop" "z10_fr_E1,z10_fwd_A3,z10_fwd_A3,z10_super_E1")])
1883
1884 ;
1885 ; mov(tf|td) instruction pattern(s).
1886 ;
1887
1888 (define_expand "mov<mode>"
1889   [(set (match_operand:TD_TF 0 "nonimmediate_operand" "")
1890         (match_operand:TD_TF 1 "general_operand"      ""))]
1891   ""
1892   "")
1893
1894 (define_insn "*mov<mode>_64"
1895   [(set (match_operand:TD_TF 0 "nonimmediate_operand" "=f,f,f,o, d,QS,  d,o")
1896         (match_operand:TD_TF 1 "general_operand"      " G,f,o,f,QS, d,dRT,d"))]
1897   "TARGET_64BIT"
1898   "@
1899    lzxr\t%0
1900    lxr\t%0,%1
1901    #
1902    #
1903    lmg\t%0,%N0,%S1
1904    stmg\t%1,%N1,%S0
1905    #
1906    #"
1907   [(set_attr "op_type" "RRE,RRE,*,*,RSY,RSY,*,*")
1908    (set_attr "type"    "fsimptf,fsimptf,*,*,lm,stm,*,*")])
1909
1910 (define_insn "*mov<mode>_31"
1911   [(set (match_operand:TD_TF 0 "nonimmediate_operand" "=f,f,f,o")
1912         (match_operand:TD_TF 1 "general_operand"      " G,f,o,f"))]
1913   "!TARGET_64BIT"
1914   "@
1915    lzxr\t%0
1916    lxr\t%0,%1
1917    #
1918    #"
1919   [(set_attr "op_type" "RRE,RRE,*,*")
1920    (set_attr "type"    "fsimptf,fsimptf,*,*")])
1921
1922 ; TFmode in GPRs splitters
1923
1924 (define_split
1925   [(set (match_operand:TD_TF 0 "nonimmediate_operand" "")
1926         (match_operand:TD_TF 1 "general_operand"      ""))]
1927   "TARGET_64BIT && reload_completed
1928    && s390_split_ok_p (operands[0], operands[1], <MODE>mode, 0)"
1929   [(set (match_dup 2) (match_dup 4))
1930    (set (match_dup 3) (match_dup 5))]
1931 {
1932   operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
1933   operands[3] = operand_subword (operands[0], 1, 0, <MODE>mode);
1934   operands[4] = operand_subword (operands[1], 0, 0, <MODE>mode);
1935   operands[5] = operand_subword (operands[1], 1, 0, <MODE>mode);
1936 })
1937
1938 (define_split
1939   [(set (match_operand:TD_TF 0 "nonimmediate_operand" "")
1940         (match_operand:TD_TF 1 "general_operand"      ""))]
1941   "TARGET_64BIT && reload_completed
1942    && s390_split_ok_p (operands[0], operands[1], <MODE>mode, 1)"
1943   [(set (match_dup 2) (match_dup 4))
1944    (set (match_dup 3) (match_dup 5))]
1945 {
1946   operands[2] = operand_subword (operands[0], 1, 0, <MODE>mode);
1947   operands[3] = operand_subword (operands[0], 0, 0, <MODE>mode);
1948   operands[4] = operand_subword (operands[1], 1, 0, <MODE>mode);
1949   operands[5] = operand_subword (operands[1], 0, 0, <MODE>mode);
1950 })
1951
1952 (define_split
1953   [(set (match_operand:TD_TF 0 "register_operand" "")
1954         (match_operand:TD_TF 1 "memory_operand"   ""))]
1955   "TARGET_64BIT && reload_completed
1956    && !FP_REG_P (operands[0])
1957    && !s_operand (operands[1], VOIDmode)"
1958   [(set (match_dup 0) (match_dup 1))]
1959 {
1960   rtx addr = operand_subword (operands[0], 1, 0, <MODE>mode);
1961   s390_load_address (addr, XEXP (operands[1], 0));
1962   operands[1] = replace_equiv_address (operands[1], addr);
1963 })
1964
1965 ; TFmode in BFPs splitters
1966
1967 (define_split
1968   [(set (match_operand:TD_TF 0 "register_operand" "")
1969         (match_operand:TD_TF 1 "memory_operand" ""))]
1970   "reload_completed && offsettable_memref_p (operands[1])
1971    && FP_REG_P (operands[0])"
1972   [(set (match_dup 2) (match_dup 4))
1973    (set (match_dup 3) (match_dup 5))]
1974 {
1975   operands[2] = simplify_gen_subreg (<HALF_TMODE>mode, operands[0],
1976                                      <MODE>mode, 0);
1977   operands[3] = simplify_gen_subreg (<HALF_TMODE>mode, operands[0],
1978                                      <MODE>mode, 8);
1979   operands[4] = adjust_address_nv (operands[1], <HALF_TMODE>mode, 0);
1980   operands[5] = adjust_address_nv (operands[1], <HALF_TMODE>mode, 8);
1981 })
1982
1983 (define_split
1984   [(set (match_operand:TD_TF 0 "memory_operand" "")
1985         (match_operand:TD_TF 1 "register_operand" ""))]
1986   "reload_completed && offsettable_memref_p (operands[0])
1987    && FP_REG_P (operands[1])"
1988   [(set (match_dup 2) (match_dup 4))
1989    (set (match_dup 3) (match_dup 5))]
1990 {
1991   operands[2] = adjust_address_nv (operands[0], <HALF_TMODE>mode, 0);
1992   operands[3] = adjust_address_nv (operands[0], <HALF_TMODE>mode, 8);
1993   operands[4] = simplify_gen_subreg (<HALF_TMODE>mode, operands[1],
1994                                      <MODE>mode, 0);
1995   operands[5] = simplify_gen_subreg (<HALF_TMODE>mode, operands[1],
1996                                      <MODE>mode, 8);
1997 })
1998
1999 ;
2000 ; mov(df|dd) instruction pattern(s).
2001 ;
2002
2003 (define_expand "mov<mode>"
2004   [(set (match_operand:DD_DF 0 "nonimmediate_operand" "")
2005         (match_operand:DD_DF 1 "general_operand"  ""))]
2006   ""
2007   "")
2008
2009 (define_insn "*mov<mode>_64dfp"
2010   [(set (match_operand:DD_DF 0 "nonimmediate_operand"
2011                                "=f,f,f,d,f,f,R,T,d, d,RT")
2012         (match_operand:DD_DF 1 "general_operand"
2013                                " G,f,d,f,R,T,f,f,d,RT, d"))]
2014   "TARGET_64BIT && TARGET_DFP"
2015   "@
2016    lzdr\t%0
2017    ldr\t%0,%1
2018    ldgr\t%0,%1
2019    lgdr\t%0,%1
2020    ld\t%0,%1
2021    ldy\t%0,%1
2022    std\t%1,%0
2023    stdy\t%1,%0
2024    lgr\t%0,%1
2025    lg\t%0,%1
2026    stg\t%1,%0"
2027   [(set_attr "op_type" "RRE,RR,RRE,RRE,RX,RXY,RX,RXY,RRE,RXY,RXY")
2028    (set_attr "type" "fsimpdf,floaddf,floaddf,floaddf,floaddf,floaddf,
2029                      fstoredf,fstoredf,lr,load,store")
2030    (set_attr "z10prop" "*,
2031                         *,
2032                         *,
2033                         *,
2034                         *,
2035                         *,
2036                         *,
2037                         *,
2038                         z10_fr_E1,
2039                         z10_fwd_A3,
2040                         z10_rec")
2041 ])
2042
2043 (define_insn "*mov<mode>_64"
2044   [(set (match_operand:DD_DF 0 "nonimmediate_operand" "=f,f,f,f,R,T,d, d,RT")
2045         (match_operand:DD_DF 1 "general_operand"       "G,f,R,T,f,f,d,RT, d"))]
2046   "TARGET_64BIT"
2047   "@
2048    lzdr\t%0
2049    ldr\t%0,%1
2050    ld\t%0,%1
2051    ldy\t%0,%1
2052    std\t%1,%0
2053    stdy\t%1,%0
2054    lgr\t%0,%1
2055    lg\t%0,%1
2056    stg\t%1,%0"
2057   [(set_attr "op_type" "RRE,RR,RX,RXY,RX,RXY,RRE,RXY,RXY")
2058    (set_attr "type" "fsimp<mode>,fload<mode>,fload<mode>,fload<mode>,
2059                      fstore<mode>,fstore<mode>,lr,load,store")
2060    (set_attr "z10prop" "*,
2061                         *,
2062                         *,
2063                         *,
2064                         *,
2065                         *,
2066                         z10_fr_E1,
2067                         z10_fwd_A3,
2068                         z10_rec")])
2069
2070 (define_insn "*mov<mode>_31"
2071   [(set (match_operand:DD_DF 0 "nonimmediate_operand"
2072                                "=f,f,f,f,R,T,d,d,Q,S,   d,o")
2073         (match_operand:DD_DF 1 "general_operand"
2074                                " G,f,R,T,f,f,Q,S,d,d,dPRT,d"))]
2075   "!TARGET_64BIT"
2076   "@
2077    lzdr\t%0
2078    ldr\t%0,%1
2079    ld\t%0,%1
2080    ldy\t%0,%1
2081    std\t%1,%0
2082    stdy\t%1,%0
2083    lm\t%0,%N0,%S1
2084    lmy\t%0,%N0,%S1
2085    stm\t%1,%N1,%S0
2086    stmy\t%1,%N1,%S0
2087    #
2088    #"
2089   [(set_attr "op_type" "RRE,RR,RX,RXY,RX,RXY,RS,RSY,RS,RSY,*,*")
2090    (set_attr "type" "fsimp<mode>,fload<mode>,fload<mode>,fload<mode>,
2091                      fstore<mode>,fstore<mode>,lm,lm,stm,stm,*,*")])
2092
2093 (define_split
2094   [(set (match_operand:DD_DF 0 "nonimmediate_operand" "")
2095         (match_operand:DD_DF 1 "general_operand" ""))]
2096   "!TARGET_64BIT && reload_completed
2097    && s390_split_ok_p (operands[0], operands[1], <MODE>mode, 0)"
2098   [(set (match_dup 2) (match_dup 4))
2099    (set (match_dup 3) (match_dup 5))]
2100 {
2101   operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
2102   operands[3] = operand_subword (operands[0], 1, 0, <MODE>mode);
2103   operands[4] = operand_subword (operands[1], 0, 0, <MODE>mode);
2104   operands[5] = operand_subword (operands[1], 1, 0, <MODE>mode);
2105 })
2106
2107 (define_split
2108   [(set (match_operand:DD_DF 0 "nonimmediate_operand" "")
2109         (match_operand:DD_DF 1 "general_operand" ""))]
2110   "!TARGET_64BIT && reload_completed
2111    && s390_split_ok_p (operands[0], operands[1], <MODE>mode, 1)"
2112   [(set (match_dup 2) (match_dup 4))
2113    (set (match_dup 3) (match_dup 5))]
2114 {
2115   operands[2] = operand_subword (operands[0], 1, 0, <MODE>mode);
2116   operands[3] = operand_subword (operands[0], 0, 0, <MODE>mode);
2117   operands[4] = operand_subword (operands[1], 1, 0, <MODE>mode);
2118   operands[5] = operand_subword (operands[1], 0, 0, <MODE>mode);
2119 })
2120
2121 (define_split
2122   [(set (match_operand:DD_DF 0 "register_operand" "")
2123         (match_operand:DD_DF 1 "memory_operand" ""))]
2124   "!TARGET_64BIT && reload_completed
2125    && !FP_REG_P (operands[0])
2126    && !s_operand (operands[1], VOIDmode)"
2127   [(set (match_dup 0) (match_dup 1))]
2128 {
2129   rtx addr = operand_subword (operands[0], 1, 0, <MODE>mode);
2130   s390_load_address (addr, XEXP (operands[1], 0));
2131   operands[1] = replace_equiv_address (operands[1], addr);
2132 })
2133
2134 ;
2135 ; mov(sf|sd) instruction pattern(s).
2136 ;
2137
2138 (define_insn "mov<mode>"
2139   [(set (match_operand:SD_SF 0 "nonimmediate_operand"
2140                                "=f,f,f,f,R,T,d,d,d,R,T")
2141         (match_operand:SD_SF 1 "general_operand"
2142                                " G,f,R,T,f,f,d,R,T,d,d"))]
2143   ""
2144   "@
2145    lzer\t%0
2146    ler\t%0,%1
2147    le\t%0,%1
2148    ley\t%0,%1
2149    ste\t%1,%0
2150    stey\t%1,%0
2151    lr\t%0,%1
2152    l\t%0,%1
2153    ly\t%0,%1
2154    st\t%1,%0
2155    sty\t%1,%0"
2156   [(set_attr "op_type" "RRE,RR,RX,RXY,RX,RXY,RR,RX,RXY,RX,RXY")
2157    (set_attr "type" "fsimp<mode>,fload<mode>,fload<mode>,fload<mode>,
2158                      fstore<mode>,fstore<mode>,lr,load,load,store,store")
2159    (set_attr "z10prop" "*,
2160                         *,
2161                         *,
2162                         *,
2163                         *,
2164                         *,
2165                         z10_fr_E1,
2166                         z10_fwd_A3,
2167                         z10_fwd_A3,
2168                         z10_super,
2169                         z10_rec")])
2170
2171 ;
2172 ; movcc instruction pattern
2173 ;
2174
2175 (define_insn "movcc"
2176   [(set (match_operand:CC 0 "nonimmediate_operand" "=d,c,d,d,d,R,T")
2177         (match_operand:CC 1 "nonimmediate_operand" "d,d,c,R,T,d,d"))]
2178   ""
2179   "@
2180    lr\t%0,%1
2181    tmh\t%1,12288
2182    ipm\t%0
2183    st\t%0,%1
2184    sty\t%0,%1
2185    l\t%1,%0
2186    ly\t%1,%0"
2187   [(set_attr "op_type" "RR,RI,RRE,RX,RXY,RX,RXY")
2188    (set_attr "type" "lr,*,*,store,store,load,load")
2189    (set_attr "z10prop" "z10_fr_E1,*,*,z10_super,z10_rec,z10_fwd_A3,z10_fwd_A3")])
2190
2191 ;
2192 ; Block move (MVC) patterns.
2193 ;
2194
2195 (define_insn "*mvc"
2196   [(set (match_operand:BLK 0 "memory_operand" "=Q")
2197         (match_operand:BLK 1 "memory_operand" "Q"))
2198    (use (match_operand 2 "const_int_operand" "n"))]
2199   "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 256"
2200   "mvc\t%O0(%2,%R0),%S1"
2201   [(set_attr "op_type" "SS")])
2202
2203 (define_peephole2
2204   [(parallel
2205     [(set (match_operand:BLK 0 "memory_operand" "")
2206           (match_operand:BLK 1 "memory_operand" ""))
2207      (use (match_operand 2 "const_int_operand" ""))])
2208    (parallel
2209     [(set (match_operand:BLK 3 "memory_operand" "")
2210           (match_operand:BLK 4 "memory_operand" ""))
2211      (use (match_operand 5 "const_int_operand" ""))])]
2212   "s390_offset_p (operands[0], operands[3], operands[2])
2213    && s390_offset_p (operands[1], operands[4], operands[2])
2214    && !s390_overlap_p (operands[0], operands[1],
2215                        INTVAL (operands[2]) + INTVAL (operands[5]))
2216    && INTVAL (operands[2]) + INTVAL (operands[5]) <= 256"
2217   [(parallel
2218     [(set (match_dup 6) (match_dup 7))
2219      (use (match_dup 8))])]
2220   "operands[6] = gen_rtx_MEM (BLKmode, XEXP (operands[0], 0));
2221    operands[7] = gen_rtx_MEM (BLKmode, XEXP (operands[1], 0));
2222    operands[8] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[5]));")
2223
2224
2225 ;
2226 ; load_multiple pattern(s).
2227 ;
2228 ; ??? Due to reload problems with replacing registers inside match_parallel
2229 ; we currently support load_multiple/store_multiple only after reload.
2230 ;
2231
2232 (define_expand "load_multiple"
2233   [(match_par_dup 3 [(set (match_operand 0 "" "")
2234                           (match_operand 1 "" ""))
2235                      (use (match_operand 2 "" ""))])]
2236   "reload_completed"
2237 {
2238   enum machine_mode mode;
2239   int regno;
2240   int count;
2241   rtx from;
2242   int i, off;
2243
2244   /* Support only loading a constant number of fixed-point registers from
2245      memory and only bother with this if more than two */
2246   if (GET_CODE (operands[2]) != CONST_INT
2247       || INTVAL (operands[2]) < 2
2248       || INTVAL (operands[2]) > 16
2249       || GET_CODE (operands[1]) != MEM
2250       || GET_CODE (operands[0]) != REG
2251       || REGNO (operands[0]) >= 16)
2252     FAIL;
2253
2254   count = INTVAL (operands[2]);
2255   regno = REGNO (operands[0]);
2256   mode = GET_MODE (operands[0]);
2257   if (mode != SImode && mode != word_mode)
2258     FAIL;
2259
2260   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
2261   if (!can_create_pseudo_p ())
2262     {
2263       if (GET_CODE (XEXP (operands[1], 0)) == REG)
2264         {
2265           from = XEXP (operands[1], 0);
2266           off = 0;
2267         }
2268       else if (GET_CODE (XEXP (operands[1], 0)) == PLUS
2269                && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == REG
2270                && GET_CODE (XEXP (XEXP (operands[1], 0), 1)) == CONST_INT)
2271         {
2272           from = XEXP (XEXP (operands[1], 0), 0);
2273           off = INTVAL (XEXP (XEXP (operands[1], 0), 1));
2274         }
2275       else
2276         FAIL;
2277     }
2278   else
2279     {
2280       from = force_reg (Pmode, XEXP (operands[1], 0));
2281       off = 0;
2282     }
2283
2284   for (i = 0; i < count; i++)
2285     XVECEXP (operands[3], 0, i)
2286       = gen_rtx_SET (VOIDmode, gen_rtx_REG (mode, regno + i),
2287                      change_address (operands[1], mode,
2288                        plus_constant (from, off + i * GET_MODE_SIZE (mode))));
2289 })
2290
2291 (define_insn "*load_multiple_di"
2292   [(match_parallel 0 "load_multiple_operation"
2293                    [(set (match_operand:DI 1 "register_operand" "=r")
2294                          (match_operand:DI 2 "s_operand" "QS"))])]
2295   "reload_completed && word_mode == DImode"
2296 {
2297   int words = XVECLEN (operands[0], 0);
2298   operands[0] = gen_rtx_REG (DImode, REGNO (operands[1]) + words - 1);
2299   return "lmg\t%1,%0,%S2";
2300 }
2301    [(set_attr "op_type" "RSY")
2302     (set_attr "type"    "lm")])
2303
2304 (define_insn "*load_multiple_si"
2305   [(match_parallel 0 "load_multiple_operation"
2306                    [(set (match_operand:SI 1 "register_operand" "=r,r")
2307                          (match_operand:SI 2 "s_operand" "Q,S"))])]
2308   "reload_completed"
2309 {
2310   int words = XVECLEN (operands[0], 0);
2311   operands[0] = gen_rtx_REG (SImode, REGNO (operands[1]) + words - 1);
2312   return which_alternative == 0 ? "lm\t%1,%0,%S2" : "lmy\t%1,%0,%S2";
2313 }
2314    [(set_attr "op_type" "RS,RSY")
2315     (set_attr "type"    "lm")])
2316
2317 ;
2318 ; store multiple pattern(s).
2319 ;
2320
2321 (define_expand "store_multiple"
2322   [(match_par_dup 3 [(set (match_operand 0 "" "")
2323                           (match_operand 1 "" ""))
2324                      (use (match_operand 2 "" ""))])]
2325   "reload_completed"
2326 {
2327   enum machine_mode mode;
2328   int regno;
2329   int count;
2330   rtx to;
2331   int i, off;
2332
2333   /* Support only storing a constant number of fixed-point registers to
2334      memory and only bother with this if more than two.  */
2335   if (GET_CODE (operands[2]) != CONST_INT
2336       || INTVAL (operands[2]) < 2
2337       || INTVAL (operands[2]) > 16
2338       || GET_CODE (operands[0]) != MEM
2339       || GET_CODE (operands[1]) != REG
2340       || REGNO (operands[1]) >= 16)
2341     FAIL;
2342
2343   count = INTVAL (operands[2]);
2344   regno = REGNO (operands[1]);
2345   mode = GET_MODE (operands[1]);
2346   if (mode != SImode && mode != word_mode)
2347     FAIL;
2348
2349   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
2350
2351   if (!can_create_pseudo_p ())
2352     {
2353       if (GET_CODE (XEXP (operands[0], 0)) == REG)
2354         {
2355           to = XEXP (operands[0], 0);
2356           off = 0;
2357         }
2358       else if (GET_CODE (XEXP (operands[0], 0)) == PLUS
2359                && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
2360                && GET_CODE (XEXP (XEXP (operands[0], 0), 1)) == CONST_INT)
2361         {
2362           to = XEXP (XEXP (operands[0], 0), 0);
2363           off = INTVAL (XEXP (XEXP (operands[0], 0), 1));
2364         }
2365       else
2366         FAIL;
2367     }
2368   else
2369     {
2370       to = force_reg (Pmode, XEXP (operands[0], 0));
2371       off = 0;
2372     }
2373
2374   for (i = 0; i < count; i++)
2375     XVECEXP (operands[3], 0, i)
2376       = gen_rtx_SET (VOIDmode,
2377                      change_address (operands[0], mode,
2378                        plus_constant (to, off + i * GET_MODE_SIZE (mode))),
2379                      gen_rtx_REG (mode, regno + i));
2380 })
2381
2382 (define_insn "*store_multiple_di"
2383   [(match_parallel 0 "store_multiple_operation"
2384                    [(set (match_operand:DI 1 "s_operand" "=QS")
2385                          (match_operand:DI 2 "register_operand" "r"))])]
2386   "reload_completed && word_mode == DImode"
2387 {
2388   int words = XVECLEN (operands[0], 0);
2389   operands[0] = gen_rtx_REG (DImode, REGNO (operands[2]) + words - 1);
2390   return "stmg\t%2,%0,%S1";
2391 }
2392    [(set_attr "op_type" "RSY")
2393     (set_attr "type"    "stm")])
2394
2395
2396 (define_insn "*store_multiple_si"
2397   [(match_parallel 0 "store_multiple_operation"
2398                    [(set (match_operand:SI 1 "s_operand" "=Q,S")
2399                          (match_operand:SI 2 "register_operand" "r,r"))])]
2400   "reload_completed"
2401 {
2402   int words = XVECLEN (operands[0], 0);
2403   operands[0] = gen_rtx_REG (SImode, REGNO (operands[2]) + words - 1);
2404   return which_alternative == 0 ? "stm\t%2,%0,%S1" : "stmy\t%2,%0,%S1";
2405 }
2406    [(set_attr "op_type" "RS,RSY")
2407     (set_attr "type"    "stm")])
2408
2409 ;;
2410 ;; String instructions.
2411 ;;
2412
2413 (define_insn "*execute_rl"
2414   [(match_parallel 0 ""
2415     [(unspec [(match_operand 1    "register_operand" "a")
2416               (match_operand 2    "" "")
2417               (match_operand:SI 3 "larl_operand" "X")] UNSPEC_EXECUTE)])]
2418   "TARGET_Z10 && GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
2419    && GET_MODE_SIZE (GET_MODE (operands[1])) <= UNITS_PER_WORD"
2420   "exrl\t%1,%3"
2421   [(set_attr "op_type" "RIL")
2422    (set_attr "type"    "cs")])
2423
2424 (define_insn "*execute"
2425   [(match_parallel 0 ""
2426     [(unspec [(match_operand 1 "register_operand" "a")
2427               (match_operand:BLK 2 "memory_operand" "R")
2428               (match_operand 3 "" "")] UNSPEC_EXECUTE)])]
2429   "GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
2430    && GET_MODE_SIZE (GET_MODE (operands[1])) <= UNITS_PER_WORD"
2431   "ex\t%1,%2"
2432   [(set_attr "op_type" "RX")
2433    (set_attr "type" "cs")])
2434
2435
2436 ;
2437 ; strlenM instruction pattern(s).
2438 ;
2439
2440 (define_expand "strlen<mode>"
2441   [(set (reg:SI 0) (match_operand:SI 2 "immediate_operand" ""))
2442    (parallel
2443     [(set (match_dup 4)
2444           (unspec:P [(const_int 0)
2445                       (match_operand:BLK 1 "memory_operand" "")
2446                       (reg:SI 0)
2447                       (match_operand 3 "immediate_operand" "")] UNSPEC_SRST))
2448      (clobber (scratch:P))
2449      (clobber (reg:CC CC_REGNUM))])
2450    (parallel
2451     [(set (match_operand:P 0 "register_operand" "")
2452           (minus:P (match_dup 4) (match_dup 5)))
2453      (clobber (reg:CC CC_REGNUM))])]
2454   ""
2455 {
2456   operands[4] = gen_reg_rtx (Pmode);
2457   operands[5] = gen_reg_rtx (Pmode);
2458   emit_move_insn (operands[5], force_operand (XEXP (operands[1], 0), NULL_RTX));
2459   operands[1] = replace_equiv_address (operands[1], operands[5]);
2460 })
2461
2462 (define_insn "*strlen<mode>"
2463   [(set (match_operand:P 0 "register_operand" "=a")
2464         (unspec:P [(match_operand:P 2 "general_operand" "0")
2465                     (mem:BLK (match_operand:P 3 "register_operand" "1"))
2466                     (reg:SI 0)
2467                     (match_operand 4 "immediate_operand" "")] UNSPEC_SRST))
2468    (clobber (match_scratch:P 1 "=a"))
2469    (clobber (reg:CC CC_REGNUM))]
2470   ""
2471   "srst\t%0,%1\;jo\t.-4"
2472   [(set_attr "length" "8")
2473    (set_attr "type" "vs")])
2474
2475 ;
2476 ; cmpstrM instruction pattern(s).
2477 ;
2478
2479 (define_expand "cmpstrsi"
2480   [(set (reg:SI 0) (const_int 0))
2481    (parallel
2482     [(clobber (match_operand 3 "" ""))
2483      (clobber (match_dup 4))
2484      (set (reg:CCU CC_REGNUM)
2485           (compare:CCU (match_operand:BLK 1 "memory_operand" "")
2486                        (match_operand:BLK 2 "memory_operand" "")))
2487      (use (reg:SI 0))])
2488    (parallel
2489     [(set (match_operand:SI 0 "register_operand" "=d")
2490           (unspec:SI [(reg:CCU CC_REGNUM)] UNSPEC_CCU_TO_INT))
2491      (clobber (reg:CC CC_REGNUM))])]
2492   ""
2493 {
2494   /* As the result of CMPINT is inverted compared to what we need,
2495      we have to swap the operands.  */
2496   rtx op1 = operands[2];
2497   rtx op2 = operands[1];
2498   rtx addr1 = gen_reg_rtx (Pmode);
2499   rtx addr2 = gen_reg_rtx (Pmode);
2500
2501   emit_move_insn (addr1, force_operand (XEXP (op1, 0), NULL_RTX));
2502   emit_move_insn (addr2, force_operand (XEXP (op2, 0), NULL_RTX));
2503   operands[1] = replace_equiv_address_nv (op1, addr1);
2504   operands[2] = replace_equiv_address_nv (op2, addr2);
2505   operands[3] = addr1;
2506   operands[4] = addr2;
2507 })
2508
2509 (define_insn "*cmpstr<mode>"
2510   [(clobber (match_operand:P 0 "register_operand" "=d"))
2511    (clobber (match_operand:P 1 "register_operand" "=d"))
2512    (set (reg:CCU CC_REGNUM)
2513         (compare:CCU (mem:BLK (match_operand:P 2 "register_operand" "0"))
2514                      (mem:BLK (match_operand:P 3 "register_operand" "1"))))
2515    (use (reg:SI 0))]
2516   ""
2517   "clst\t%0,%1\;jo\t.-4"
2518   [(set_attr "length" "8")
2519    (set_attr "type" "vs")])
2520
2521 ;
2522 ; movstr instruction pattern.
2523 ;
2524
2525 (define_expand "movstr"
2526   [(set (reg:SI 0) (const_int 0))
2527    (parallel
2528     [(clobber (match_dup 3))
2529      (set (match_operand:BLK 1 "memory_operand" "")
2530           (match_operand:BLK 2 "memory_operand" ""))
2531      (set (match_operand 0 "register_operand" "")
2532           (unspec [(match_dup 1)
2533                    (match_dup 2)
2534                    (reg:SI 0)] UNSPEC_MVST))
2535      (clobber (reg:CC CC_REGNUM))])]
2536   ""
2537 {
2538   rtx addr1 = gen_reg_rtx (Pmode);
2539   rtx addr2 = gen_reg_rtx (Pmode);
2540
2541   emit_move_insn (addr1, force_operand (XEXP (operands[1], 0), NULL_RTX));
2542   emit_move_insn (addr2, force_operand (XEXP (operands[2], 0), NULL_RTX));
2543   operands[1] = replace_equiv_address_nv (operands[1], addr1);
2544   operands[2] = replace_equiv_address_nv (operands[2], addr2);
2545   operands[3] = addr2;
2546 })
2547
2548 (define_insn "*movstr"
2549   [(clobber (match_operand:P 2 "register_operand" "=d"))
2550    (set (mem:BLK (match_operand:P 1 "register_operand" "0"))
2551         (mem:BLK (match_operand:P 3 "register_operand" "2")))
2552    (set (match_operand:P 0 "register_operand" "=d")
2553         (unspec [(mem:BLK (match_dup 1))
2554                  (mem:BLK (match_dup 3))
2555                  (reg:SI 0)] UNSPEC_MVST))
2556    (clobber (reg:CC CC_REGNUM))]
2557   ""
2558   "mvst\t%1,%2\;jo\t.-4"
2559   [(set_attr "length" "8")
2560    (set_attr "type" "vs")])
2561
2562
2563 ;
2564 ; movmemM instruction pattern(s).
2565 ;
2566
2567 (define_expand "movmem<mode>"
2568   [(set (match_operand:BLK 0 "memory_operand" "")   ; destination
2569         (match_operand:BLK 1 "memory_operand" ""))  ; source
2570    (use (match_operand:GPR 2 "general_operand" "")) ; count
2571    (match_operand 3 "" "")]
2572   ""
2573   "s390_expand_movmem (operands[0], operands[1], operands[2]); DONE;")
2574
2575 ; Move a block that is up to 256 bytes in length.
2576 ; The block length is taken as (operands[2] % 256) + 1.
2577
2578 (define_expand "movmem_short"
2579   [(parallel
2580     [(set (match_operand:BLK 0 "memory_operand" "")
2581           (match_operand:BLK 1 "memory_operand" ""))
2582      (use (match_operand 2 "nonmemory_operand" ""))
2583      (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2584      (clobber (match_dup 3))])]
2585   ""
2586   "operands[3] = gen_rtx_SCRATCH (Pmode);")
2587
2588 (define_insn "*movmem_short"
2589   [(set (match_operand:BLK 0 "memory_operand" "=Q,Q,Q,Q")
2590         (match_operand:BLK 1 "memory_operand" "Q,Q,Q,Q"))
2591    (use (match_operand 2 "nonmemory_operand" "n,a,a,a"))
2592    (use (match_operand 3 "immediate_operand" "X,R,X,X"))
2593    (clobber (match_scratch 4 "=X,X,X,&a"))]
2594   "(GET_MODE (operands[2]) == Pmode || GET_MODE (operands[2]) == VOIDmode)
2595    && GET_MODE (operands[4]) == Pmode"
2596   "#"
2597   [(set_attr "type"         "cs")
2598    (set_attr "cpu_facility" "*,*,z10,*")])
2599
2600 (define_split
2601   [(set (match_operand:BLK 0 "memory_operand" "")
2602         (match_operand:BLK 1 "memory_operand" ""))
2603    (use (match_operand 2 "const_int_operand" ""))
2604    (use (match_operand 3 "immediate_operand" ""))
2605    (clobber (scratch))]
2606   "reload_completed"
2607   [(parallel
2608     [(set (match_dup 0) (match_dup 1))
2609      (use (match_dup 2))])]
2610   "operands[2] = GEN_INT ((INTVAL (operands[2]) & 0xff) + 1);")
2611
2612 (define_split
2613   [(set (match_operand:BLK 0 "memory_operand" "")
2614         (match_operand:BLK 1 "memory_operand" ""))
2615    (use (match_operand 2 "register_operand" ""))
2616    (use (match_operand 3 "memory_operand" ""))
2617    (clobber (scratch))]
2618   "reload_completed"
2619   [(parallel
2620     [(unspec [(match_dup 2) (match_dup 3)
2621               (const_int 0)] UNSPEC_EXECUTE)
2622      (set (match_dup 0) (match_dup 1))
2623      (use (const_int 1))])]
2624   "")
2625
2626 (define_split
2627   [(set (match_operand:BLK 0 "memory_operand" "")
2628         (match_operand:BLK 1 "memory_operand" ""))
2629    (use (match_operand 2 "register_operand" ""))
2630    (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2631    (clobber (scratch))]
2632   "TARGET_Z10 && reload_completed"
2633   [(parallel
2634     [(unspec [(match_dup 2) (const_int 0)
2635               (label_ref (match_dup 3))] UNSPEC_EXECUTE)
2636      (set (match_dup 0) (match_dup 1))
2637      (use (const_int 1))])]
2638   "operands[3] = gen_label_rtx ();")
2639
2640 (define_split
2641   [(set (match_operand:BLK 0 "memory_operand" "")
2642         (match_operand:BLK 1 "memory_operand" ""))
2643    (use (match_operand 2 "register_operand" ""))
2644    (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2645    (clobber (match_operand 3 "register_operand" ""))]
2646   "reload_completed && TARGET_CPU_ZARCH"
2647   [(set (match_dup 3) (label_ref (match_dup 4)))
2648    (parallel
2649     [(unspec [(match_dup 2) (mem:BLK (match_dup 3))
2650               (label_ref (match_dup 4))] UNSPEC_EXECUTE)
2651      (set (match_dup 0) (match_dup 1))
2652      (use (const_int 1))])]
2653   "operands[4] = gen_label_rtx ();")
2654
2655 ; Move a block of arbitrary length.
2656
2657 (define_expand "movmem_long"
2658   [(parallel
2659     [(clobber (match_dup 2))
2660      (clobber (match_dup 3))
2661      (set (match_operand:BLK 0 "memory_operand" "")
2662           (match_operand:BLK 1 "memory_operand" ""))
2663      (use (match_operand 2 "general_operand" ""))
2664      (use (match_dup 3))
2665      (clobber (reg:CC CC_REGNUM))])]
2666   ""
2667 {
2668   enum machine_mode dword_mode = word_mode == DImode ? TImode : DImode;
2669   rtx reg0 = gen_reg_rtx (dword_mode);
2670   rtx reg1 = gen_reg_rtx (dword_mode);
2671   rtx addr0 = gen_lowpart (Pmode, gen_highpart (word_mode, reg0));
2672   rtx addr1 = gen_lowpart (Pmode, gen_highpart (word_mode, reg1));
2673   rtx len0 = gen_lowpart (Pmode, reg0);
2674   rtx len1 = gen_lowpart (Pmode, reg1);
2675
2676   emit_clobber (reg0);
2677   emit_move_insn (addr0, force_operand (XEXP (operands[0], 0), NULL_RTX));
2678   emit_move_insn (len0, operands[2]);
2679
2680   emit_clobber (reg1);
2681   emit_move_insn (addr1, force_operand (XEXP (operands[1], 0), NULL_RTX));
2682   emit_move_insn (len1, operands[2]);
2683
2684   operands[0] = replace_equiv_address_nv (operands[0], addr0);
2685   operands[1] = replace_equiv_address_nv (operands[1], addr1);
2686   operands[2] = reg0;
2687   operands[3] = reg1;
2688 })
2689
2690 (define_insn "*movmem_long"
2691   [(clobber (match_operand:<DBL> 0 "register_operand" "=d"))
2692    (clobber (match_operand:<DBL> 1 "register_operand" "=d"))
2693    (set (mem:BLK (subreg:P (match_operand:<DBL> 2 "register_operand" "0") 0))
2694         (mem:BLK (subreg:P (match_operand:<DBL> 3 "register_operand" "1") 0)))
2695    (use (match_dup 2))
2696    (use (match_dup 3))
2697    (clobber (reg:CC CC_REGNUM))]
2698   ""
2699   "mvcle\t%0,%1,0\;jo\t.-4"
2700   [(set_attr "length" "8")
2701    (set_attr "type" "vs")])
2702
2703
2704 ;
2705 ; Test data class.
2706 ;
2707
2708 (define_expand "signbit<mode>2"
2709   [(set (reg:CCZ CC_REGNUM)
2710         (unspec:CCZ [(match_operand:FP_ALL 1 "register_operand" "f")
2711                      (match_dup 2)]
2712                      UNSPEC_TDC_INSN))
2713    (set (match_operand:SI 0 "register_operand" "=d")
2714         (unspec:SI [(reg:CCZ CC_REGNUM)] UNSPEC_CCZ_TO_INT))]
2715   "TARGET_HARD_FLOAT"
2716 {
2717   operands[2] = GEN_INT (S390_TDC_SIGNBIT_SET);
2718 })
2719
2720 (define_expand "isinf<mode>2"
2721   [(set (reg:CCZ CC_REGNUM)
2722         (unspec:CCZ [(match_operand:FP_ALL 1 "register_operand" "f")
2723                      (match_dup 2)]
2724                      UNSPEC_TDC_INSN))
2725    (set (match_operand:SI 0 "register_operand" "=d")
2726         (unspec:SI [(reg:CCZ CC_REGNUM)] UNSPEC_CCZ_TO_INT))]
2727   "TARGET_HARD_FLOAT"
2728 {
2729   operands[2] = GEN_INT (S390_TDC_INFINITY);
2730 })
2731
2732 ; This insn is used to generate all variants of the Test Data Class
2733 ; instruction, namely tcxb, tcdb, and tceb.  The insn's first operand
2734 ; is the register to be tested and the second one is the bit mask
2735 ; specifying the required test(s).
2736 ;
2737 (define_insn "*TDC_insn_<mode>"
2738   [(set (reg:CCZ CC_REGNUM)
2739         (unspec:CCZ [(match_operand:FP_ALL 0 "register_operand" "f")
2740                      (match_operand:SI 1 "const_int_operand")] UNSPEC_TDC_INSN))]
2741   "TARGET_HARD_FLOAT"
2742   "t<_d>c<xde><bt>\t%0,%1"
2743    [(set_attr "op_type" "RXE")
2744     (set_attr "type"  "fsimp<mode>")])
2745
2746 (define_insn_and_split "*ccz_to_int"
2747   [(set (match_operand:SI 0 "register_operand" "=d")
2748         (unspec:SI [(match_operand:CCZ 1 "register_operand" "0")]
2749                    UNSPEC_CCZ_TO_INT))]
2750   ""
2751   "#"
2752   "reload_completed"
2753   [(set (match_dup 0) (lshiftrt:SI (match_dup 0) (const_int 28)))])
2754
2755
2756 ;
2757 ; setmemM instruction pattern(s).
2758 ;
2759
2760 (define_expand "setmem<mode>"
2761   [(set (match_operand:BLK 0 "memory_operand" "")
2762         (match_operand:QI 2 "general_operand" ""))
2763    (use (match_operand:GPR 1 "general_operand" ""))
2764    (match_operand 3 "" "")]
2765   ""
2766   "s390_expand_setmem (operands[0], operands[1], operands[2]); DONE;")
2767
2768 ; Clear a block that is up to 256 bytes in length.
2769 ; The block length is taken as (operands[1] % 256) + 1.
2770
2771 (define_expand "clrmem_short"
2772   [(parallel
2773     [(set (match_operand:BLK 0 "memory_operand" "")
2774           (const_int 0))
2775      (use (match_operand 1 "nonmemory_operand" ""))
2776      (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2777      (clobber (match_dup 2))
2778      (clobber (reg:CC CC_REGNUM))])]
2779   ""
2780   "operands[2] = gen_rtx_SCRATCH (Pmode);")
2781
2782 (define_insn "*clrmem_short"
2783   [(set (match_operand:BLK 0 "memory_operand" "=Q,Q,Q,Q")
2784         (const_int 0))
2785    (use (match_operand 1 "nonmemory_operand" "n,a,a,a"))
2786    (use (match_operand 2 "immediate_operand" "X,R,X,X"))
2787    (clobber (match_scratch 3 "=X,X,X,&a"))
2788    (clobber (reg:CC CC_REGNUM))]
2789   "(GET_MODE (operands[1]) == Pmode || GET_MODE (operands[1]) == VOIDmode)
2790    && GET_MODE (operands[3]) == Pmode"
2791   "#"
2792   [(set_attr "type" "cs")
2793    (set_attr "cpu_facility" "*,*,z10,*")])
2794
2795 (define_split
2796   [(set (match_operand:BLK 0 "memory_operand" "")
2797         (const_int 0))
2798    (use (match_operand 1 "const_int_operand" ""))
2799    (use (match_operand 2 "immediate_operand" ""))
2800    (clobber (scratch))
2801    (clobber (reg:CC CC_REGNUM))]
2802   "reload_completed"
2803   [(parallel
2804     [(set (match_dup 0) (const_int 0))
2805      (use (match_dup 1))
2806      (clobber (reg:CC CC_REGNUM))])]
2807   "operands[1] = GEN_INT ((INTVAL (operands[1]) & 0xff) + 1);")
2808
2809 (define_split
2810   [(set (match_operand:BLK 0 "memory_operand" "")
2811         (const_int 0))
2812    (use (match_operand 1 "register_operand" ""))
2813    (use (match_operand 2 "memory_operand" ""))
2814    (clobber (scratch))
2815    (clobber (reg:CC CC_REGNUM))]
2816   "reload_completed"
2817   [(parallel
2818     [(unspec [(match_dup 1) (match_dup 2)
2819               (const_int 0)] UNSPEC_EXECUTE)
2820      (set (match_dup 0) (const_int 0))
2821      (use (const_int 1))
2822      (clobber (reg:CC CC_REGNUM))])]
2823   "")
2824
2825 (define_split
2826   [(set (match_operand:BLK 0 "memory_operand" "")
2827         (const_int 0))
2828    (use (match_operand 1 "register_operand" ""))
2829    (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2830    (clobber (scratch))
2831    (clobber (reg:CC CC_REGNUM))]
2832   "TARGET_Z10 && reload_completed"
2833   [(parallel
2834     [(unspec [(match_dup 1) (const_int 0)
2835               (label_ref (match_dup 3))] UNSPEC_EXECUTE)
2836      (set (match_dup 0) (const_int 0))
2837      (use (const_int 1))
2838      (clobber (reg:CC CC_REGNUM))])]
2839   "operands[3] = gen_label_rtx ();")
2840
2841 (define_split
2842   [(set (match_operand:BLK 0 "memory_operand" "")
2843         (const_int 0))
2844    (use (match_operand 1 "register_operand" ""))
2845    (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2846    (clobber (match_operand 2 "register_operand" ""))
2847    (clobber (reg:CC CC_REGNUM))]
2848   "reload_completed && TARGET_CPU_ZARCH"
2849   [(set (match_dup 2) (label_ref (match_dup 3)))
2850    (parallel
2851     [(unspec [(match_dup 1) (mem:BLK (match_dup 2))
2852               (label_ref (match_dup 3))] UNSPEC_EXECUTE)
2853      (set (match_dup 0) (const_int 0))
2854      (use (const_int 1))
2855      (clobber (reg:CC CC_REGNUM))])]
2856   "operands[3] = gen_label_rtx ();")
2857
2858 ; Initialize a block of arbitrary length with (operands[2] % 256).
2859
2860 (define_expand "setmem_long"
2861   [(parallel
2862     [(clobber (match_dup 1))
2863      (set (match_operand:BLK 0 "memory_operand" "")
2864           (match_operand 2 "shift_count_or_setmem_operand" ""))
2865      (use (match_operand 1 "general_operand" ""))
2866      (use (match_dup 3))
2867      (clobber (reg:CC CC_REGNUM))])]
2868   ""
2869 {
2870   enum machine_mode dword_mode = word_mode == DImode ? TImode : DImode;
2871   rtx reg0 = gen_reg_rtx (dword_mode);
2872   rtx reg1 = gen_reg_rtx (dword_mode);
2873   rtx addr0 = gen_lowpart (Pmode, gen_highpart (word_mode, reg0));
2874   rtx len0 = gen_lowpart (Pmode, reg0);
2875
2876   emit_clobber (reg0);
2877   emit_move_insn (addr0, force_operand (XEXP (operands[0], 0), NULL_RTX));
2878   emit_move_insn (len0, operands[1]);
2879
2880   emit_move_insn (reg1, const0_rtx);
2881
2882   operands[0] = replace_equiv_address_nv (operands[0], addr0);
2883   operands[1] = reg0;
2884   operands[3] = reg1;
2885 })
2886
2887 (define_insn "*setmem_long"
2888   [(clobber (match_operand:<DBL> 0 "register_operand" "=d"))
2889    (set (mem:BLK (subreg:P (match_operand:<DBL> 3 "register_operand" "0") 0))
2890         (match_operand 2 "shift_count_or_setmem_operand" "Y"))
2891    (use (match_dup 3))
2892    (use (match_operand:<DBL> 1 "register_operand" "d"))
2893    (clobber (reg:CC CC_REGNUM))]
2894   ""
2895   "mvcle\t%0,%1,%Y2\;jo\t.-4"
2896   [(set_attr "length" "8")
2897    (set_attr "type" "vs")])
2898
2899 (define_insn "*setmem_long_and"
2900   [(clobber (match_operand:<DBL> 0 "register_operand" "=d"))
2901    (set (mem:BLK (subreg:P (match_operand:<DBL> 3 "register_operand" "0") 0))
2902         (and (match_operand 2 "shift_count_or_setmem_operand" "Y")
2903              (match_operand 4 "const_int_operand"             "n")))
2904    (use (match_dup 3))
2905    (use (match_operand:<DBL> 1 "register_operand" "d"))
2906    (clobber (reg:CC CC_REGNUM))]
2907   "(INTVAL (operands[4]) & 255) == 255"
2908   "mvcle\t%0,%1,%Y2\;jo\t.-4"
2909   [(set_attr "length" "8")
2910    (set_attr "type" "vs")])
2911 ;
2912 ; cmpmemM instruction pattern(s).
2913 ;
2914
2915 (define_expand "cmpmemsi"
2916   [(set (match_operand:SI 0 "register_operand" "")
2917         (compare:SI (match_operand:BLK 1 "memory_operand" "")
2918                     (match_operand:BLK 2 "memory_operand" "") ) )
2919    (use (match_operand:SI 3 "general_operand" ""))
2920    (use (match_operand:SI 4 "" ""))]
2921   ""
2922   "s390_expand_cmpmem (operands[0], operands[1],
2923                        operands[2], operands[3]); DONE;")
2924
2925 ; Compare a block that is up to 256 bytes in length.
2926 ; The block length is taken as (operands[2] % 256) + 1.
2927
2928 (define_expand "cmpmem_short"
2929   [(parallel
2930     [(set (reg:CCU CC_REGNUM)
2931           (compare:CCU (match_operand:BLK 0 "memory_operand" "")
2932                        (match_operand:BLK 1 "memory_operand" "")))
2933      (use (match_operand 2 "nonmemory_operand" ""))
2934      (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2935      (clobber (match_dup 3))])]
2936   ""
2937   "operands[3] = gen_rtx_SCRATCH (Pmode);")
2938
2939 (define_insn "*cmpmem_short"
2940   [(set (reg:CCU CC_REGNUM)
2941         (compare:CCU (match_operand:BLK 0 "memory_operand" "Q,Q,Q,Q")
2942                      (match_operand:BLK 1 "memory_operand" "Q,Q,Q,Q")))
2943    (use (match_operand 2 "nonmemory_operand" "n,a,a,a"))
2944    (use (match_operand 3 "immediate_operand" "X,R,X,X"))
2945    (clobber (match_scratch 4 "=X,X,X,&a"))]
2946   "(GET_MODE (operands[2]) == Pmode || GET_MODE (operands[2]) == VOIDmode)
2947    && GET_MODE (operands[4]) == Pmode"
2948   "#"
2949   [(set_attr "type" "cs")
2950    (set_attr "cpu_facility" "*,*,z10,*")])
2951
2952 (define_split
2953   [(set (reg:CCU CC_REGNUM)
2954         (compare:CCU (match_operand:BLK 0 "memory_operand" "")
2955                      (match_operand:BLK 1 "memory_operand" "")))
2956    (use (match_operand 2 "const_int_operand" ""))
2957    (use (match_operand 3 "immediate_operand" ""))
2958    (clobber (scratch))]
2959   "reload_completed"
2960   [(parallel
2961     [(set (reg:CCU CC_REGNUM) (compare:CCU (match_dup 0) (match_dup 1)))
2962      (use (match_dup 2))])]
2963   "operands[2] = GEN_INT ((INTVAL (operands[2]) & 0xff) + 1);")
2964
2965 (define_split
2966   [(set (reg:CCU CC_REGNUM)
2967         (compare:CCU (match_operand:BLK 0 "memory_operand" "")
2968                      (match_operand:BLK 1 "memory_operand" "")))
2969    (use (match_operand 2 "register_operand" ""))
2970    (use (match_operand 3 "memory_operand" ""))
2971    (clobber (scratch))]
2972   "reload_completed"
2973   [(parallel
2974     [(unspec [(match_dup 2) (match_dup 3)
2975               (const_int 0)] UNSPEC_EXECUTE)
2976      (set (reg:CCU CC_REGNUM) (compare:CCU (match_dup 0) (match_dup 1)))
2977      (use (const_int 1))])]
2978   "")
2979
2980 (define_split
2981   [(set (reg:CCU CC_REGNUM)
2982         (compare:CCU (match_operand:BLK 0 "memory_operand" "")
2983                      (match_operand:BLK 1 "memory_operand" "")))
2984    (use (match_operand 2 "register_operand" ""))
2985    (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
2986    (clobber (scratch))]
2987   "TARGET_Z10 && reload_completed"
2988   [(parallel
2989     [(unspec [(match_dup 2) (const_int 0)
2990               (label_ref (match_dup 4))] UNSPEC_EXECUTE)
2991      (set (reg:CCU CC_REGNUM) (compare:CCU (match_dup 0) (match_dup 1)))
2992      (use (const_int 1))])]
2993   "operands[4] = gen_label_rtx ();")
2994
2995 (define_split
2996   [(set (reg:CCU CC_REGNUM)
2997         (compare:CCU (match_operand:BLK 0 "memory_operand" "")
2998                      (match_operand:BLK 1 "memory_operand" "")))
2999    (use (match_operand 2 "register_operand" ""))
3000    (use (const:BLK (unspec:BLK [(const_int 0)] UNSPEC_INSN)))
3001    (clobber (match_operand 3 "register_operand" ""))]
3002   "reload_completed && TARGET_CPU_ZARCH"
3003   [(set (match_dup 3) (label_ref (match_dup 4)))
3004    (parallel
3005     [(unspec [(match_dup 2) (mem:BLK (match_dup 3))
3006               (label_ref (match_dup 4))] UNSPEC_EXECUTE)
3007      (set (reg:CCU CC_REGNUM) (compare:CCU (match_dup 0) (match_dup 1)))
3008      (use (const_int 1))])]
3009   "operands[4] = gen_label_rtx ();")
3010
3011 ; Compare a block of arbitrary length.
3012
3013 (define_expand "cmpmem_long"
3014   [(parallel
3015     [(clobber (match_dup 2))
3016      (clobber (match_dup 3))
3017      (set (reg:CCU CC_REGNUM)
3018           (compare:CCU (match_operand:BLK 0 "memory_operand" "")
3019                        (match_operand:BLK 1 "memory_operand" "")))
3020      (use (match_operand 2 "general_operand" ""))
3021      (use (match_dup 3))])]
3022   ""
3023 {
3024   enum machine_mode dword_mode = word_mode == DImode ? TImode : DImode;
3025   rtx reg0 = gen_reg_rtx (dword_mode);
3026   rtx reg1 = gen_reg_rtx (dword_mode);
3027   rtx addr0 = gen_lowpart (Pmode, gen_highpart (word_mode, reg0));
3028   rtx addr1 = gen_lowpart (Pmode, gen_highpart (word_mode, reg1));
3029   rtx len0 = gen_lowpart (Pmode, reg0);
3030   rtx len1 = gen_lowpart (Pmode, reg1);
3031
3032   emit_clobber (reg0);
3033   emit_move_insn (addr0, force_operand (XEXP (operands[0], 0), NULL_RTX));
3034   emit_move_insn (len0, operands[2]);
3035
3036   emit_clobber (reg1);
3037   emit_move_insn (addr1, force_operand (XEXP (operands[1], 0), NULL_RTX));
3038   emit_move_insn (len1, operands[2]);
3039
3040   operands[0] = replace_equiv_address_nv (operands[0], addr0);
3041   operands[1] = replace_equiv_address_nv (operands[1], addr1);
3042   operands[2] = reg0;
3043   operands[3] = reg1;
3044 })
3045
3046 (define_insn "*cmpmem_long"
3047   [(clobber (match_operand:<DBL> 0 "register_operand" "=d"))
3048    (clobber (match_operand:<DBL> 1 "register_operand" "=d"))
3049    (set (reg:CCU CC_REGNUM)
3050         (compare:CCU (mem:BLK (subreg:P (match_operand:<DBL> 2 "register_operand" "0") 0))
3051                      (mem:BLK (subreg:P (match_operand:<DBL> 3 "register_operand" "1") 0))))
3052    (use (match_dup 2))
3053    (use (match_dup 3))]
3054   ""
3055   "clcle\t%0,%1,0\;jo\t.-4"
3056   [(set_attr "length" "8")
3057    (set_attr "type" "vs")])
3058
3059 ; Convert CCUmode condition code to integer.
3060 ; Result is zero if EQ, positive if LTU, negative if GTU.
3061
3062 (define_insn_and_split "cmpint"
3063   [(set (match_operand:SI 0 "register_operand" "=d")
3064         (unspec:SI [(match_operand:CCU 1 "register_operand" "0")]
3065                    UNSPEC_CCU_TO_INT))
3066    (clobber (reg:CC CC_REGNUM))]
3067   ""
3068   "#"
3069   "reload_completed"
3070   [(set (match_dup 0) (ashift:SI (match_dup 0) (const_int 2)))
3071    (parallel
3072     [(set (match_dup 0) (ashiftrt:SI (match_dup 0) (const_int 30)))
3073      (clobber (reg:CC CC_REGNUM))])])
3074
3075 (define_insn_and_split "*cmpint_cc"
3076   [(set (reg CC_REGNUM)
3077         (compare (unspec:SI [(match_operand:CCU 1 "register_operand" "0")]
3078                             UNSPEC_CCU_TO_INT)
3079                  (const_int 0)))
3080    (set (match_operand:SI 0 "register_operand" "=d")
3081         (unspec:SI [(match_dup 1)] UNSPEC_CCU_TO_INT))]
3082   "s390_match_ccmode (insn, CCSmode)"
3083   "#"
3084   "&& reload_completed"
3085   [(set (match_dup 0) (ashift:SI (match_dup 0) (const_int 2)))
3086    (parallel
3087     [(set (match_dup 2) (match_dup 3))
3088      (set (match_dup 0) (ashiftrt:SI (match_dup 0) (const_int 30)))])]
3089 {
3090   rtx result = gen_rtx_ASHIFTRT (SImode, operands[0], GEN_INT (30));
3091   operands[2] = SET_DEST (XVECEXP (PATTERN (curr_insn), 0, 0));
3092   operands[3] = gen_rtx_COMPARE (GET_MODE (operands[2]), result, const0_rtx);
3093 })
3094
3095 (define_insn_and_split "*cmpint_sign"
3096   [(set (match_operand:DI 0 "register_operand" "=d")
3097         (sign_extend:DI (unspec:SI [(match_operand:CCU 1 "register_operand" "0")]
3098                                    UNSPEC_CCU_TO_INT)))
3099    (clobber (reg:CC CC_REGNUM))]
3100   "TARGET_64BIT"
3101   "#"
3102   "&& reload_completed"
3103   [(set (match_dup 0) (ashift:DI (match_dup 0) (const_int 34)))
3104    (parallel
3105     [(set (match_dup 0) (ashiftrt:DI (match_dup 0) (const_int 62)))
3106      (clobber (reg:CC CC_REGNUM))])])
3107
3108 (define_insn_and_split "*cmpint_sign_cc"
3109   [(set (reg CC_REGNUM)
3110         (compare (ashiftrt:DI (ashift:DI (subreg:DI
3111                    (unspec:SI [(match_operand:CCU 1 "register_operand" "0")]
3112                               UNSPEC_CCU_TO_INT) 0)
3113                    (const_int 32)) (const_int 32))
3114                  (const_int 0)))
3115    (set (match_operand:DI 0 "register_operand" "=d")
3116         (sign_extend:DI (unspec:SI [(match_dup 1)] UNSPEC_CCU_TO_INT)))]
3117   "s390_match_ccmode (insn, CCSmode) && TARGET_64BIT"
3118   "#"
3119   "&& reload_completed"
3120   [(set (match_dup 0) (ashift:DI (match_dup 0) (const_int 34)))
3121    (parallel
3122     [(set (match_dup 2) (match_dup 3))
3123      (set (match_dup 0) (ashiftrt:DI (match_dup 0) (const_int 62)))])]
3124 {
3125   rtx result = gen_rtx_ASHIFTRT (DImode, operands[0], GEN_INT (62));
3126   operands[2] = SET_DEST (XVECEXP (PATTERN (curr_insn), 0, 0));
3127   operands[3] = gen_rtx_COMPARE (GET_MODE (operands[2]), result, const0_rtx);
3128 })
3129
3130
3131 ;;
3132 ;;- Conversion instructions.
3133 ;;
3134
3135 (define_insn "*sethighpartsi"
3136   [(set (match_operand:SI 0 "register_operand" "=d,d")
3137         (unspec:SI [(match_operand:BLK 1 "s_operand" "Q,S")
3138                     (match_operand 2 "const_int_operand" "n,n")] UNSPEC_ICM))
3139    (clobber (reg:CC CC_REGNUM))]
3140   ""
3141   "@
3142    icm\t%0,%2,%S1
3143    icmy\t%0,%2,%S1"
3144   [(set_attr "op_type" "RS,RSY")
3145    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
3146
3147 (define_insn "*sethighpartdi_64"
3148   [(set (match_operand:DI 0 "register_operand" "=d")
3149         (unspec:DI [(match_operand:BLK 1 "s_operand" "QS")
3150                     (match_operand 2 "const_int_operand" "n")] UNSPEC_ICM))
3151    (clobber (reg:CC CC_REGNUM))]
3152   "TARGET_64BIT"
3153   "icmh\t%0,%2,%S1"
3154   [(set_attr "op_type" "RSY")])
3155
3156 (define_insn "*sethighpartdi_31"
3157   [(set (match_operand:DI 0 "register_operand" "=d,d")
3158         (unspec:DI [(match_operand:BLK 1 "s_operand" "Q,S")
3159                     (match_operand 2 "const_int_operand" "n,n")] UNSPEC_ICM))
3160    (clobber (reg:CC CC_REGNUM))]
3161   "!TARGET_64BIT"
3162   "@
3163    icm\t%0,%2,%S1
3164    icmy\t%0,%2,%S1"
3165   [(set_attr "op_type" "RS,RSY")
3166    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
3167
3168
3169 (define_insn_and_split "*extzv<mode>"
3170   [(set (match_operand:GPR 0 "register_operand" "=d")
3171         (zero_extract:GPR (match_operand:QI 1 "s_operand" "QS")
3172                           (match_operand 2 "const_int_operand" "n")
3173                           (const_int 0)))
3174    (clobber (reg:CC CC_REGNUM))]
3175   "INTVAL (operands[2]) > 0
3176    && INTVAL (operands[2]) <= GET_MODE_BITSIZE (SImode)"
3177   "#"
3178   "&& reload_completed"
3179   [(parallel
3180     [(set (match_dup 0) (unspec:GPR [(match_dup 1) (match_dup 3)] UNSPEC_ICM))
3181      (clobber (reg:CC CC_REGNUM))])
3182    (set (match_dup 0) (lshiftrt:GPR (match_dup 0) (match_dup 2)))]
3183 {
3184   int bitsize = INTVAL (operands[2]);
3185   int size = (bitsize - 1) / BITS_PER_UNIT + 1; /* round up */
3186   int mask = ((1ul << size) - 1) << (GET_MODE_SIZE (SImode) - size);
3187
3188   operands[1] = adjust_address (operands[1], BLKmode, 0);
3189   set_mem_size (operands[1], GEN_INT (size));
3190   operands[2] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - bitsize);
3191   operands[3] = GEN_INT (mask);
3192 })
3193
3194 (define_insn_and_split "*extv<mode>"
3195   [(set (match_operand:GPR 0 "register_operand" "=d")
3196         (sign_extract:GPR (match_operand:QI 1 "s_operand" "QS")
3197                           (match_operand 2 "const_int_operand" "n")
3198                           (const_int 0)))
3199    (clobber (reg:CC CC_REGNUM))]
3200   "INTVAL (operands[2]) > 0
3201    && INTVAL (operands[2]) <= GET_MODE_BITSIZE (SImode)"
3202   "#"
3203   "&& reload_completed"
3204   [(parallel
3205     [(set (match_dup 0) (unspec:GPR [(match_dup 1) (match_dup 3)] UNSPEC_ICM))
3206      (clobber (reg:CC CC_REGNUM))])
3207    (parallel
3208     [(set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))
3209      (clobber (reg:CC CC_REGNUM))])]
3210 {
3211   int bitsize = INTVAL (operands[2]);
3212   int size = (bitsize - 1) / BITS_PER_UNIT + 1; /* round up */
3213   int mask = ((1ul << size) - 1) << (GET_MODE_SIZE (SImode) - size);
3214
3215   operands[1] = adjust_address (operands[1], BLKmode, 0);
3216   set_mem_size (operands[1], GEN_INT (size));
3217   operands[2] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - bitsize);
3218   operands[3] = GEN_INT (mask);
3219 })
3220
3221 ;
3222 ; insv instruction patterns
3223 ;
3224
3225 (define_expand "insv"
3226   [(set (zero_extract (match_operand 0 "nonimmediate_operand" "")
3227                       (match_operand 1 "const_int_operand" "")
3228                       (match_operand 2 "const_int_operand" ""))
3229         (match_operand 3 "general_operand" ""))]
3230   ""
3231 {
3232   if (s390_expand_insv (operands[0], operands[1], operands[2], operands[3]))
3233     DONE;
3234   FAIL;
3235 })
3236
3237 (define_insn "*insv<mode>_z10"
3238   [(set (zero_extract:GPR (match_operand:GPR 0 "nonimmediate_operand" "+d")
3239                           (match_operand 1 "const_int_operand"    "I")
3240                           (match_operand 2 "const_int_operand"    "I"))
3241         (match_operand:GPR 3 "nonimmediate_operand" "d"))
3242    (clobber (reg:CC CC_REGNUM))]
3243   "TARGET_Z10
3244    && (INTVAL (operands[1]) + INTVAL (operands[2])) <=
3245       GET_MODE_BITSIZE (<MODE>mode)"
3246 {
3247   int start = INTVAL (operands[2]);
3248   int size = INTVAL (operands[1]);
3249   int offset = 64 - GET_MODE_BITSIZE (<MODE>mode);
3250
3251   operands[2] = GEN_INT (offset + start);              /* start bit position */
3252   operands[1] = GEN_INT (offset + start + size - 1);   /* end bit position */
3253   operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) -
3254                          start - size);       /* left shift count */
3255
3256   return "risbg\t%0,%3,%b2,%b1,%b4";
3257 }
3258   [(set_attr "op_type" "RIE")
3259    (set_attr "z10prop" "z10_super_E1")])
3260
3261 ; and op1 with a mask being 1 for the selected bits and 0 for the rest
3262 ; and op3=op0 with a mask being 0 for the selected bits and 1 for the rest
3263 (define_insn "*insv<mode>_z10_noshift"
3264   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d")
3265         (ior:GPR (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "d")
3266                           (match_operand 2 "const_int_operand" "n"))
3267                  (and:GPR (match_operand:GPR 3 "nonimmediate_operand" "0")
3268                           (match_operand 4 "const_int_operand" "n"))))
3269    (clobber (reg:CC CC_REGNUM))]
3270   "TARGET_Z10
3271    && s390_contiguous_bitmask_p (INTVAL (operands[2]),
3272                                  GET_MODE_BITSIZE (<MODE>mode), NULL, NULL)
3273    && INTVAL (operands[2]) == ~(INTVAL (operands[4]))"
3274
3275 {
3276   int start;
3277   int size;
3278
3279   s390_contiguous_bitmask_p (INTVAL (operands[2]),
3280                              GET_MODE_BITSIZE (<MODE>mode), &start, &size);
3281
3282   operands[5] = GEN_INT (64 - start - size); /* start bit position */
3283   operands[6] = GEN_INT (64 - 1 - start);    /* end bit position */
3284   operands[7] = const0_rtx;                  /* left shift count */
3285
3286   return "risbg\t%0,%1,%b5,%b6,%b7";
3287 }
3288   [(set_attr "op_type" "RIE")
3289    (set_attr "z10prop" "z10_super_E1")])
3290
3291 ; and op1 with a mask being 1 for the selected bits and 0 for the rest
3292 (define_insn "*insv<mode>_or_z10_noshift"
3293   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d")
3294         (ior:GPR (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "d")
3295                           (match_operand 2 "const_int_operand" "n"))
3296                 (match_operand:GPR 3 "nonimmediate_operand" "0")))
3297    (clobber (reg:CC CC_REGNUM))]
3298   "TARGET_Z10
3299    && s390_contiguous_bitmask_p (INTVAL (operands[2]),
3300                                  GET_MODE_BITSIZE (<MODE>mode), NULL, NULL)"
3301 {
3302   int start;
3303   int size;
3304
3305   s390_contiguous_bitmask_p (INTVAL (operands[2]),
3306                              GET_MODE_BITSIZE (<MODE>mode), &start, &size);
3307
3308   operands[4] = GEN_INT (64 - start - size); /* start bit position */
3309   operands[5] = GEN_INT (64 - 1 - start);    /* end bit position */
3310   operands[6] = const0_rtx;                  /* left shift count */
3311
3312   return "rosbg\t%0,%1,%b4,%b5,%b6";
3313 }
3314   [(set_attr "op_type" "RIE")])
3315
3316 (define_insn "*insv<mode>_mem_reg"
3317   [(set (zero_extract:P (match_operand:QI 0 "memory_operand" "+Q,S")
3318                         (match_operand 1 "const_int_operand" "n,n")
3319                         (const_int 0))
3320         (match_operand:P 2 "register_operand" "d,d"))]
3321   "INTVAL (operands[1]) > 0
3322    && INTVAL (operands[1]) <= GET_MODE_BITSIZE (SImode)
3323    && INTVAL (operands[1]) % BITS_PER_UNIT == 0"
3324 {
3325     int size = INTVAL (operands[1]) / BITS_PER_UNIT;
3326
3327     operands[1] = GEN_INT ((1ul << size) - 1);
3328     return (which_alternative == 0) ? "stcm\t%2,%1,%S0"
3329                                     : "stcmy\t%2,%1,%S0";
3330 }
3331   [(set_attr "op_type" "RS,RSY")
3332    (set_attr "z10prop" "z10_super,z10_super")])
3333
3334 (define_insn "*insvdi_mem_reghigh"
3335   [(set (zero_extract:DI (match_operand:QI 0 "memory_operand" "+QS")
3336                          (match_operand 1 "const_int_operand" "n")
3337                          (const_int 0))
3338         (lshiftrt:DI (match_operand:DI 2 "register_operand" "d")
3339                      (const_int 32)))]
3340   "TARGET_64BIT
3341    && INTVAL (operands[1]) > 0
3342    && INTVAL (operands[1]) <= GET_MODE_BITSIZE (SImode)
3343    && INTVAL (operands[1]) % BITS_PER_UNIT == 0"
3344 {
3345     int size = INTVAL (operands[1]) / BITS_PER_UNIT;
3346
3347     operands[1] = GEN_INT ((1ul << size) - 1);
3348     return "stcmh\t%2,%1,%S0";
3349 }
3350 [(set_attr "op_type" "RSY")
3351  (set_attr "z10prop" "z10_super")])
3352
3353 (define_insn "*insv<mode>_reg_imm"
3354   [(set (zero_extract:P (match_operand:P 0 "register_operand" "+d")
3355                         (const_int 16)
3356                         (match_operand 1 "const_int_operand" "n"))
3357         (match_operand:P 2 "const_int_operand" "n"))]
3358   "TARGET_ZARCH
3359    && INTVAL (operands[1]) >= 0
3360    && INTVAL (operands[1]) < BITS_PER_WORD
3361    && INTVAL (operands[1]) % 16 == 0"
3362 {
3363   switch (BITS_PER_WORD - INTVAL (operands[1]))
3364     {
3365       case 64: return "iihh\t%0,%x2"; break;
3366       case 48: return "iihl\t%0,%x2"; break;
3367       case 32: return "iilh\t%0,%x2"; break;
3368       case 16: return "iill\t%0,%x2"; break;
3369       default: gcc_unreachable();
3370     }
3371 }
3372   [(set_attr "op_type" "RI")
3373    (set_attr "z10prop" "z10_super_E1")])
3374
3375
3376 (define_insn "*insv<mode>_reg_extimm"
3377   [(set (zero_extract:P (match_operand:P 0 "register_operand" "+d")
3378                         (const_int 32)
3379                         (match_operand 1 "const_int_operand" "n"))
3380         (match_operand:P 2 "const_int_operand" "n"))]
3381   "TARGET_EXTIMM
3382    && INTVAL (operands[1]) >= 0
3383    && INTVAL (operands[1]) < BITS_PER_WORD
3384    && INTVAL (operands[1]) % 32 == 0"
3385 {
3386   switch (BITS_PER_WORD - INTVAL (operands[1]))
3387     {
3388       case 64: return "iihf\t%0,%o2"; break;
3389       case 32: return "iilf\t%0,%o2"; break;
3390       default: gcc_unreachable();
3391     }
3392 }
3393   [(set_attr "op_type" "RIL")
3394    (set_attr "z10prop" "z10_fwd_E1")])
3395
3396
3397 ;
3398 ; extendsidi2 instruction pattern(s).
3399 ;
3400
3401 (define_expand "extendsidi2"
3402   [(set (match_operand:DI 0 "register_operand" "")
3403         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
3404   ""
3405 {
3406   if (!TARGET_64BIT)
3407     {
3408       emit_clobber (operands[0]);
3409       emit_move_insn (gen_highpart (SImode, operands[0]), operands[1]);
3410       emit_move_insn (gen_lowpart (SImode, operands[0]), const0_rtx);
3411       emit_insn (gen_ashrdi3 (operands[0], operands[0], GEN_INT (32)));
3412       DONE;
3413     }
3414 })
3415
3416 (define_insn "*extendsidi2"
3417   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
3418         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,RT,b")))]
3419   "TARGET_64BIT"
3420   "@
3421    lgfr\t%0,%1
3422    lgf\t%0,%1
3423    lgfrl\t%0,%1"
3424   [(set_attr "op_type"      "RRE,RXY,RIL")
3425    (set_attr "type"         "*,*,larl")
3426    (set_attr "cpu_facility" "*,*,z10")
3427    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
3428
3429 ;
3430 ; extend(hi|qi)(si|di)2 instruction pattern(s).
3431 ;
3432
3433 (define_expand "extend<HQI:mode><DSI:mode>2"
3434   [(set (match_operand:DSI 0 "register_operand" "")
3435         (sign_extend:DSI (match_operand:HQI 1 "nonimmediate_operand" "")))]
3436   ""
3437 {
3438   if (<DSI:MODE>mode == DImode && !TARGET_64BIT)
3439     {
3440       rtx tmp = gen_reg_rtx (SImode);
3441       emit_insn (gen_extend<HQI:mode>si2 (tmp, operands[1]));
3442       emit_insn (gen_extendsidi2 (operands[0], tmp));
3443       DONE;
3444     }
3445   else if (!TARGET_EXTIMM)
3446     {
3447       rtx bitcount = GEN_INT (GET_MODE_BITSIZE (<DSI:MODE>mode) -
3448                               GET_MODE_BITSIZE (<HQI:MODE>mode));
3449
3450       operands[1] = gen_lowpart (<DSI:MODE>mode, operands[1]);
3451       emit_insn (gen_ashl<DSI:mode>3 (operands[0], operands[1], bitcount));
3452       emit_insn (gen_ashr<DSI:mode>3 (operands[0], operands[0], bitcount));
3453       DONE;
3454     }
3455 })
3456
3457 ;
3458 ; extendhidi2 instruction pattern(s).
3459 ;
3460
3461 (define_insn "*extendhidi2_extimm"
3462   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
3463         (sign_extend:DI (match_operand:HI 1 "general_operand" "d,RT,b")))]
3464   "TARGET_64BIT && TARGET_EXTIMM"
3465   "@
3466    lghr\t%0,%1
3467    lgh\t%0,%1
3468    lghrl\t%0,%1"
3469   [(set_attr "op_type"      "RRE,RXY,RIL")
3470    (set_attr "type"         "*,*,larl")
3471    (set_attr "cpu_facility" "extimm,extimm,z10")
3472    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
3473
3474 (define_insn "*extendhidi2"
3475   [(set (match_operand:DI 0 "register_operand" "=d")
3476         (sign_extend:DI (match_operand:HI 1 "memory_operand" "RT")))]
3477   "TARGET_64BIT"
3478   "lgh\t%0,%1"
3479   [(set_attr "op_type" "RXY")
3480    (set_attr "z10prop" "z10_super_E1")])
3481
3482 ;
3483 ; extendhisi2 instruction pattern(s).
3484 ;
3485
3486 (define_insn "*extendhisi2_extimm"
3487   [(set (match_operand:SI 0 "register_operand" "=d,d,d,d")
3488         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" " d,R,T,b")))]
3489   "TARGET_EXTIMM"
3490   "@
3491    lhr\t%0,%1
3492    lh\t%0,%1
3493    lhy\t%0,%1
3494    lhrl\t%0,%1"
3495   [(set_attr "op_type"      "RRE,RX,RXY,RIL")
3496    (set_attr "type"         "*,*,*,larl")
3497    (set_attr "cpu_facility" "extimm,extimm,extimm,z10")
3498    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
3499
3500 (define_insn "*extendhisi2"
3501   [(set (match_operand:SI 0 "register_operand" "=d,d")
3502         (sign_extend:SI (match_operand:HI 1 "memory_operand" "R,T")))]
3503   "!TARGET_EXTIMM"
3504   "@
3505    lh\t%0,%1
3506    lhy\t%0,%1"
3507   [(set_attr "op_type" "RX,RXY")
3508    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
3509
3510 ;
3511 ; extendqi(si|di)2 instruction pattern(s).
3512 ;
3513
3514 ; lbr, lgbr, lb, lgb
3515 (define_insn "*extendqi<mode>2_extimm"
3516   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3517         (sign_extend:GPR (match_operand:QI 1 "nonimmediate_operand" "d,RT")))]
3518   "TARGET_EXTIMM"
3519   "@
3520    l<g>br\t%0,%1
3521    l<g>b\t%0,%1"
3522   [(set_attr "op_type" "RRE,RXY")
3523    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
3524
3525 ; lb, lgb
3526 (define_insn "*extendqi<mode>2"
3527   [(set (match_operand:GPR 0 "register_operand" "=d")
3528         (sign_extend:GPR (match_operand:QI 1 "memory_operand" "RT")))]
3529   "!TARGET_EXTIMM && TARGET_LONG_DISPLACEMENT"
3530   "l<g>b\t%0,%1"
3531   [(set_attr "op_type" "RXY")
3532    (set_attr "z10prop" "z10_super_E1")])
3533
3534 (define_insn_and_split "*extendqi<mode>2_short_displ"
3535   [(set (match_operand:GPR 0 "register_operand" "=d")
3536         (sign_extend:GPR (match_operand:QI 1 "s_operand" "Q")))
3537    (clobber (reg:CC CC_REGNUM))]
3538   "!TARGET_EXTIMM && !TARGET_LONG_DISPLACEMENT"
3539   "#"
3540   "&& reload_completed"
3541   [(parallel
3542     [(set (match_dup 0) (unspec:GPR [(match_dup 1) (const_int 8)] UNSPEC_ICM))
3543      (clobber (reg:CC CC_REGNUM))])
3544    (parallel
3545     [(set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))
3546      (clobber (reg:CC CC_REGNUM))])]
3547 {
3548   operands[1] = adjust_address (operands[1], BLKmode, 0);
3549   set_mem_size (operands[1], GEN_INT (GET_MODE_SIZE (QImode)));
3550   operands[2] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)
3551                          - GET_MODE_BITSIZE (QImode));
3552 })
3553
3554 ;
3555 ; zero_extendsidi2 instruction pattern(s).
3556 ;
3557
3558 (define_expand "zero_extendsidi2"
3559   [(set (match_operand:DI 0 "register_operand" "")
3560         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
3561   ""
3562 {
3563   if (!TARGET_64BIT)
3564     {
3565       emit_clobber (operands[0]);
3566       emit_move_insn (gen_lowpart (SImode, operands[0]), operands[1]);
3567       emit_move_insn (gen_highpart (SImode, operands[0]), const0_rtx);
3568       DONE;
3569     }
3570 })
3571
3572 (define_insn "*zero_extendsidi2"
3573   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
3574         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,RT,b")))]
3575   "TARGET_64BIT"
3576   "@
3577    llgfr\t%0,%1
3578    llgf\t%0,%1
3579    llgfrl\t%0,%1"
3580   [(set_attr "op_type"      "RRE,RXY,RIL")
3581    (set_attr "type"         "*,*,larl")
3582    (set_attr "cpu_facility" "*,*,z10")
3583    (set_attr "z10prop" "z10_fwd_E1,z10_fwd_A3,z10_fwd_A3")])
3584
3585 ;
3586 ; LLGT-type instructions (zero-extend from 31 bit to 64 bit).
3587 ;
3588
3589 (define_insn "*llgt_sidi"
3590   [(set (match_operand:DI 0 "register_operand" "=d")
3591         (and:DI (subreg:DI (match_operand:SI 1 "memory_operand" "RT") 0)
3592                 (const_int 2147483647)))]
3593   "TARGET_64BIT"
3594   "llgt\t%0,%1"
3595   [(set_attr "op_type"  "RXE")
3596    (set_attr "z10prop" "z10_super_E1")])
3597
3598 (define_insn_and_split "*llgt_sidi_split"
3599   [(set (match_operand:DI 0 "register_operand" "=d")
3600         (and:DI (subreg:DI (match_operand:SI 1 "memory_operand" "RT") 0)
3601                 (const_int 2147483647)))
3602    (clobber (reg:CC CC_REGNUM))]
3603   "TARGET_64BIT"
3604   "#"
3605   "&& reload_completed"
3606   [(set (match_dup 0)
3607         (and:DI (subreg:DI (match_dup 1) 0)
3608                 (const_int 2147483647)))]
3609   "")
3610
3611 (define_insn "*llgt_sisi"
3612   [(set (match_operand:SI 0 "register_operand" "=d,d")
3613         (and:SI (match_operand:SI 1 "nonimmediate_operand" "d,RT")
3614                 (const_int 2147483647)))]
3615   "TARGET_ZARCH"
3616   "@
3617    llgtr\t%0,%1
3618    llgt\t%0,%1"
3619   [(set_attr "op_type"  "RRE,RXE")
3620    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
3621
3622 (define_insn "*llgt_didi"
3623   [(set (match_operand:DI 0 "register_operand" "=d,d")
3624         (and:DI (match_operand:DI 1 "nonimmediate_operand" "d,o")
3625                 (const_int 2147483647)))]
3626   "TARGET_64BIT"
3627   "@
3628    llgtr\t%0,%1
3629    llgt\t%0,%N1"
3630   [(set_attr "op_type"  "RRE,RXE")
3631    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
3632
3633 (define_split
3634   [(set (match_operand:GPR 0 "register_operand" "")
3635         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "")
3636                  (const_int 2147483647)))
3637    (clobber (reg:CC CC_REGNUM))]
3638   "TARGET_ZARCH && reload_completed"
3639   [(set (match_dup 0)
3640         (and:GPR (match_dup 1)
3641                  (const_int 2147483647)))]
3642   "")
3643
3644 ;
3645 ; zero_extend(hi|qi)(si|di)2 instruction pattern(s).
3646 ;
3647
3648 (define_expand "zero_extend<mode>di2"
3649   [(set (match_operand:DI 0 "register_operand" "")
3650         (zero_extend:DI (match_operand:HQI 1 "nonimmediate_operand" "")))]
3651   ""
3652 {
3653   if (!TARGET_64BIT)
3654     {
3655       rtx tmp = gen_reg_rtx (SImode);
3656       emit_insn (gen_zero_extend<mode>si2 (tmp, operands[1]));
3657       emit_insn (gen_zero_extendsidi2 (operands[0], tmp));
3658       DONE;
3659     }
3660   else if (!TARGET_EXTIMM)
3661     {
3662       rtx bitcount = GEN_INT (GET_MODE_BITSIZE(DImode) -
3663                               GET_MODE_BITSIZE(<MODE>mode));
3664       operands[1] = gen_lowpart (DImode, operands[1]);
3665       emit_insn (gen_ashldi3 (operands[0], operands[1], bitcount));
3666       emit_insn (gen_lshrdi3 (operands[0], operands[0], bitcount));
3667       DONE;
3668     }
3669 })
3670
3671 (define_expand "zero_extend<mode>si2"
3672   [(set (match_operand:SI 0 "register_operand" "")
3673         (zero_extend:SI (match_operand:HQI 1 "nonimmediate_operand" "")))]
3674   ""
3675 {
3676   if (!TARGET_EXTIMM)
3677     {
3678       operands[1] = gen_lowpart (SImode, operands[1]);
3679       emit_insn (gen_andsi3 (operands[0], operands[1],
3680                    GEN_INT ((1 << GET_MODE_BITSIZE(<MODE>mode)) - 1)));
3681       DONE;
3682     }
3683 })
3684
3685 ; llhrl, llghrl
3686 (define_insn "*zero_extendhi<mode>2_z10"
3687   [(set (match_operand:GPR 0 "register_operand" "=d,d,d")
3688         (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" "d,RT,b")))]
3689   "TARGET_Z10"
3690   "@
3691    ll<g>hr\t%0,%1
3692    ll<g>h\t%0,%1
3693    ll<g>hrl\t%0,%1"
3694   [(set_attr "op_type"      "RXY,RRE,RIL")
3695    (set_attr "type"         "*,*,larl")
3696    (set_attr "cpu_facility" "*,*,z10")
3697    (set_attr "z10prop" "z10_fwd_A3")])
3698
3699 ; llhr, llcr, llghr, llgcr, llh, llc, llgh, llgc
3700 (define_insn "*zero_extend<HQI:mode><GPR:mode>2_extimm"
3701   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3702         (zero_extend:GPR (match_operand:HQI 1 "nonimmediate_operand" "d,RT")))]
3703   "TARGET_EXTIMM"
3704   "@
3705    ll<g><hc>r\t%0,%1
3706    ll<g><hc>\t%0,%1"
3707   [(set_attr "op_type" "RRE,RXY")
3708    (set_attr "z10prop" "z10_super_E1,z10_fwd_A3")])
3709
3710 ; llgh, llgc
3711 (define_insn "*zero_extend<HQI:mode><GPR:mode>2"
3712   [(set (match_operand:GPR 0 "register_operand" "=d")
3713         (zero_extend:GPR (match_operand:HQI 1 "memory_operand" "RT")))]
3714   "TARGET_ZARCH && !TARGET_EXTIMM"
3715   "llg<hc>\t%0,%1"
3716   [(set_attr "op_type" "RXY")
3717    (set_attr "z10prop" "z10_fwd_A3")])
3718
3719 (define_insn_and_split "*zero_extendhisi2_31"
3720   [(set (match_operand:SI 0 "register_operand" "=&d")
3721         (zero_extend:SI (match_operand:HI 1 "s_operand" "QS")))
3722    (clobber (reg:CC CC_REGNUM))]
3723   "!TARGET_ZARCH"
3724   "#"
3725   "&& reload_completed"
3726   [(set (match_dup 0) (const_int 0))
3727    (parallel
3728     [(set (strict_low_part (match_dup 2)) (match_dup 1))
3729      (clobber (reg:CC CC_REGNUM))])]
3730   "operands[2] = gen_lowpart (HImode, operands[0]);")
3731
3732 (define_insn_and_split "*zero_extendqisi2_31"
3733   [(set (match_operand:SI 0 "register_operand" "=&d")
3734         (zero_extend:SI (match_operand:QI 1 "memory_operand" "RT")))]
3735   "!TARGET_ZARCH"
3736   "#"
3737   "&& reload_completed"
3738   [(set (match_dup 0) (const_int 0))
3739    (set (strict_low_part (match_dup 2)) (match_dup 1))]
3740   "operands[2] = gen_lowpart (QImode, operands[0]);")
3741
3742 ;
3743 ; zero_extendqihi2 instruction pattern(s).
3744 ;
3745
3746 (define_expand "zero_extendqihi2"
3747   [(set (match_operand:HI 0 "register_operand" "")
3748         (zero_extend:HI (match_operand:QI 1 "register_operand" "")))]
3749   "TARGET_ZARCH && !TARGET_EXTIMM"
3750 {
3751   operands[1] = gen_lowpart (HImode, operands[1]);
3752   emit_insn (gen_andhi3 (operands[0], operands[1], GEN_INT (0xff)));
3753   DONE;
3754 })
3755
3756 (define_insn "*zero_extendqihi2_64"
3757   [(set (match_operand:HI 0 "register_operand" "=d")
3758         (zero_extend:HI (match_operand:QI 1 "memory_operand" "RT")))]
3759   "TARGET_ZARCH && !TARGET_EXTIMM"
3760   "llgc\t%0,%1"
3761   [(set_attr "op_type" "RXY")
3762    (set_attr "z10prop" "z10_fwd_A3")])
3763
3764 (define_insn_and_split "*zero_extendqihi2_31"
3765   [(set (match_operand:HI 0 "register_operand" "=&d")
3766         (zero_extend:HI (match_operand:QI 1 "memory_operand" "RT")))]
3767   "!TARGET_ZARCH"
3768   "#"
3769   "&& reload_completed"
3770   [(set (match_dup 0) (const_int 0))
3771    (set (strict_low_part (match_dup 2)) (match_dup 1))]
3772   "operands[2] = gen_lowpart (QImode, operands[0]);")
3773
3774 ;
3775 ; fixuns_trunc(dd|td)di2 instruction pattern(s).
3776 ;
3777
3778 (define_expand "fixuns_truncdddi2"
3779   [(parallel
3780     [(set (match_operand:DI 0 "register_operand" "")
3781           (unsigned_fix:DI (match_operand:DD 1 "register_operand" "")))
3782      (clobber (match_scratch:TD 2 "=f"))])]
3783
3784   "TARGET_HARD_DFP"
3785 {
3786   rtx label1 = gen_label_rtx ();
3787   rtx label2 = gen_label_rtx ();
3788   rtx temp = gen_reg_rtx (TDmode);
3789   REAL_VALUE_TYPE cmp, sub;
3790
3791   decimal_real_from_string (&cmp, "9223372036854775808.0");  /* 2^63 */
3792   decimal_real_from_string (&sub, "18446744073709551616.0"); /* 2^64 */
3793
3794   /* 2^63 can't be represented as 64bit DFP number with full precision.  The
3795      solution is doing the check and the subtraction in TD mode and using a
3796      TD -> DI convert afterwards.  */
3797   emit_insn (gen_extendddtd2 (temp, operands[1]));
3798   temp = force_reg (TDmode, temp);
3799   emit_insn (gen_cmptd (temp,
3800         CONST_DOUBLE_FROM_REAL_VALUE (cmp, TDmode)));
3801   emit_jump_insn (gen_blt (label1));
3802   emit_insn (gen_subtd3 (temp, temp,
3803         CONST_DOUBLE_FROM_REAL_VALUE (sub, TDmode)));
3804   emit_insn (gen_fix_trunctddi2_dfp (operands[0], temp, GEN_INT (11)));
3805   emit_jump (label2);
3806
3807   emit_label (label1);
3808   emit_insn (gen_fix_truncdddi2_dfp (operands[0], operands[1], GEN_INT (9)));
3809   emit_label (label2);
3810   DONE;
3811 })
3812
3813 (define_expand "fixuns_trunctddi2"
3814   [(set (match_operand:DI 0 "register_operand" "")
3815         (unsigned_fix:DI (match_operand:TD 1 "register_operand" "")))]
3816   "TARGET_HARD_DFP"
3817 {
3818   rtx label1 = gen_label_rtx ();
3819   rtx label2 = gen_label_rtx ();
3820   rtx temp = gen_reg_rtx (TDmode);
3821   REAL_VALUE_TYPE cmp, sub;
3822
3823   operands[1] = force_reg (TDmode, operands[1]);
3824   decimal_real_from_string (&cmp, "9223372036854775808.0");  /* 2^63 */
3825   decimal_real_from_string (&sub, "18446744073709551616.0"); /* 2^64 */
3826
3827   emit_insn (gen_cmptd (operands[1],
3828         CONST_DOUBLE_FROM_REAL_VALUE (cmp, TDmode)));
3829   emit_jump_insn (gen_blt (label1));
3830   emit_insn (gen_subtd3 (temp, operands[1],
3831         CONST_DOUBLE_FROM_REAL_VALUE (sub, TDmode)));
3832   emit_insn (gen_fix_trunctddi2_dfp (operands[0], temp, GEN_INT (11)));
3833   emit_jump (label2);
3834
3835   emit_label (label1);
3836   emit_insn (gen_fix_trunctddi2_dfp (operands[0], operands[1], GEN_INT (9)));
3837   emit_label (label2);
3838   DONE;
3839 })
3840
3841 ;
3842 ; fixuns_trunc(sf|df)(si|di)2 and fix_trunc(sf|df)(si|di)2
3843 ; instruction pattern(s).
3844 ;
3845
3846 (define_expand "fixuns_trunc<BFP:mode><GPR:mode>2"
3847   [(set (match_operand:GPR 0 "register_operand" "")
3848         (unsigned_fix:GPR (match_operand:BFP 1 "register_operand" "")))]
3849   "TARGET_HARD_FLOAT"
3850 {
3851   rtx label1 = gen_label_rtx ();
3852   rtx label2 = gen_label_rtx ();
3853   rtx temp = gen_reg_rtx (<BFP:MODE>mode);
3854   REAL_VALUE_TYPE cmp, sub;
3855
3856   operands[1] = force_reg (<BFP:MODE>mode, operands[1]);
3857   real_2expN (&cmp, GET_MODE_BITSIZE(<GPR:MODE>mode) - 1, <BFP:MODE>mode);
3858   real_2expN (&sub, GET_MODE_BITSIZE(<GPR:MODE>mode), <BFP:MODE>mode);
3859
3860   emit_insn (gen_cmp<BFP:mode> (operands[1],
3861         CONST_DOUBLE_FROM_REAL_VALUE (cmp, <BFP:MODE>mode)));
3862   emit_jump_insn (gen_blt (label1));
3863   emit_insn (gen_sub<BFP:mode>3 (temp, operands[1],
3864         CONST_DOUBLE_FROM_REAL_VALUE (sub, <BFP:MODE>mode)));
3865   emit_insn (gen_fix_trunc<BFP:mode><GPR:mode>2_bfp (operands[0], temp,
3866         GEN_INT (7)));
3867   emit_jump (label2);
3868
3869   emit_label (label1);
3870   emit_insn (gen_fix_trunc<BFP:mode><GPR:mode>2_bfp (operands[0],
3871         operands[1], GEN_INT (5)));
3872   emit_label (label2);
3873   DONE;
3874 })
3875
3876 (define_expand "fix_trunc<DSF:mode><GPR:mode>2"
3877   [(set (match_operand:GPR 0 "register_operand" "")
3878         (fix:GPR (match_operand:DSF 1 "register_operand" "")))]
3879   "TARGET_HARD_FLOAT"
3880 {
3881   emit_insn (gen_fix_trunc<DSF:mode><GPR:mode>2_bfp (operands[0], operands[1],
3882              GEN_INT (5)));
3883   DONE;
3884 })
3885
3886 ; cgxbr, cgdbr, cgebr, cfxbr, cfdbr, cfebr
3887 (define_insn "fix_trunc<BFP:mode><GPR:mode>2_bfp"
3888   [(set (match_operand:GPR 0 "register_operand" "=d")
3889         (fix:GPR (match_operand:BFP 1 "register_operand" "f")))
3890    (unspec:GPR [(match_operand:GPR 2 "immediate_operand" "K")] UNSPEC_ROUND)
3891    (clobber (reg:CC CC_REGNUM))]
3892   "TARGET_HARD_FLOAT"
3893   "c<GPR:gf><BFP:xde>br\t%0,%h2,%1"
3894   [(set_attr "op_type" "RRE")
3895    (set_attr "type"    "ftoi")])
3896
3897
3898 ;
3899 ; fix_trunc(td|dd)di2 instruction pattern(s).
3900 ;
3901
3902 (define_expand "fix_trunc<mode>di2"
3903   [(set (match_operand:DI 0 "register_operand" "")
3904         (fix:DI (match_operand:DFP 1 "nonimmediate_operand" "")))]
3905   "TARGET_64BIT && TARGET_HARD_DFP"
3906 {
3907   operands[1] = force_reg (<MODE>mode, operands[1]);
3908   emit_insn (gen_fix_trunc<mode>di2_dfp (operands[0], operands[1],
3909       GEN_INT (9)));
3910   DONE;
3911 })
3912
3913 ; cgxtr, cgdtr
3914 (define_insn "fix_trunc<DFP:mode>di2_dfp"
3915   [(set (match_operand:DI 0 "register_operand" "=d")
3916         (fix:DI (match_operand:DFP 1 "register_operand" "f")))
3917    (unspec:DI [(match_operand:DI 2 "immediate_operand" "K")] UNSPEC_ROUND)
3918    (clobber (reg:CC CC_REGNUM))]
3919   "TARGET_64BIT && TARGET_HARD_DFP"
3920   "cg<DFP:xde>tr\t%0,%h2,%1"
3921   [(set_attr "op_type" "RRF")
3922    (set_attr "type"    "ftoidfp")])
3923
3924
3925 ;
3926 ; fix_trunctf(si|di)2 instruction pattern(s).
3927 ;
3928
3929 (define_expand "fix_trunctf<mode>2"
3930   [(parallel [(set (match_operand:GPR 0 "register_operand" "")
3931                    (fix:GPR (match_operand:TF 1 "register_operand" "")))
3932               (unspec:GPR [(const_int 5)] UNSPEC_ROUND)
3933               (clobber (reg:CC CC_REGNUM))])]
3934   "TARGET_HARD_FLOAT"
3935   "")
3936
3937
3938 ;
3939 ; float(si|di)(tf|df|sf|td|dd)2 instruction pattern(s).
3940 ;
3941
3942 ; cxgbr, cdgbr, cegbr, cxgtr, cdgtr
3943 (define_insn "floatdi<mode>2"
3944   [(set (match_operand:FP 0 "register_operand" "=f")
3945         (float:FP (match_operand:DI 1 "register_operand" "d")))]
3946   "TARGET_64BIT && TARGET_HARD_FLOAT"
3947   "c<xde>g<bt>r\t%0,%1"
3948   [(set_attr "op_type" "RRE")
3949    (set_attr "type"    "itof<mode>" )])
3950
3951 ; cxfbr, cdfbr, cefbr
3952 (define_insn "floatsi<mode>2"
3953   [(set (match_operand:BFP 0 "register_operand" "=f")
3954         (float:BFP (match_operand:SI 1 "register_operand" "d")))]
3955   "TARGET_HARD_FLOAT"
3956   "c<xde>fbr\t%0,%1"
3957   [(set_attr "op_type" "RRE")
3958    (set_attr "type"   "itof<mode>" )])
3959
3960
3961 ;
3962 ; truncdfsf2 instruction pattern(s).
3963 ;
3964
3965 (define_insn "truncdfsf2"
3966   [(set (match_operand:SF 0 "register_operand" "=f")
3967         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3968   "TARGET_HARD_FLOAT"
3969   "ledbr\t%0,%1"
3970   [(set_attr "op_type"  "RRE")
3971    (set_attr "type"   "ftruncdf")])
3972
3973 ;
3974 ; trunctf(df|sf)2 instruction pattern(s).
3975 ;
3976
3977 ; ldxbr, lexbr
3978 (define_insn "trunctf<mode>2"
3979   [(set (match_operand:DSF 0 "register_operand" "=f")
3980         (float_truncate:DSF (match_operand:TF 1 "register_operand" "f")))
3981    (clobber (match_scratch:TF 2 "=f"))]
3982   "TARGET_HARD_FLOAT"
3983   "l<xde>xbr\t%2,%1\;l<xde>r\t%0,%2"
3984   [(set_attr "length" "6")
3985    (set_attr "type"   "ftrunctf")])
3986
3987 ;
3988 ; trunctddd2 and truncddsd2 instruction pattern(s).
3989 ;
3990
3991 (define_insn "trunctddd2"
3992   [(set (match_operand:DD 0 "register_operand" "=f")
3993         (float_truncate:DD (match_operand:TD 1 "register_operand" "f")))
3994    (clobber (match_scratch:TD 2 "=f"))]
3995   "TARGET_HARD_DFP"
3996   "ldxtr\t%2,0,%1,0\;ldr\t%0,%2"
3997   [(set_attr "length"  "6")
3998    (set_attr "type"    "ftruncdd")])
3999
4000 (define_insn "truncddsd2"
4001   [(set (match_operand:SD 0 "register_operand" "=f")
4002         (float_truncate:SD (match_operand:DD 1 "register_operand" "f")))]
4003   "TARGET_HARD_DFP"
4004   "ledtr\t%0,0,%1,0"
4005   [(set_attr "op_type" "RRF")
4006    (set_attr "type"    "ftruncsd")])
4007
4008 ;
4009 ; extend(sf|df)(df|tf)2 instruction pattern(s).
4010 ;
4011
4012 ; ldebr, ldeb, lxdbr, lxdb, lxebr, lxeb
4013 (define_insn "extend<DSF:mode><BFP:mode>2"
4014   [(set (match_operand:BFP 0 "register_operand" "=f,f")
4015         (float_extend:BFP (match_operand:DSF 1 "nonimmediate_operand"  "f,R")))]
4016   "TARGET_HARD_FLOAT
4017    && GET_MODE_SIZE (<BFP:MODE>mode) > GET_MODE_SIZE (<DSF:MODE>mode)"
4018   "@
4019    l<BFP:xde><DSF:xde>br\t%0,%1
4020    l<BFP:xde><DSF:xde>b\t%0,%1"
4021   [(set_attr "op_type"  "RRE,RXE")
4022    (set_attr "type"   "fsimp<BFP:mode>, fload<BFP:mode>")])
4023
4024 ;
4025 ; extendddtd2 and extendsddd2 instruction pattern(s).
4026 ;
4027
4028 (define_insn "extendddtd2"
4029   [(set (match_operand:TD 0 "register_operand" "=f")
4030         (float_extend:TD (match_operand:DD 1 "register_operand" "f")))]
4031   "TARGET_HARD_DFP"
4032   "lxdtr\t%0,%1,0"
4033   [(set_attr "op_type" "RRF")
4034    (set_attr "type"    "fsimptf")])
4035
4036 (define_insn "extendsddd2"
4037   [(set (match_operand:DD 0 "register_operand" "=f")
4038         (float_extend:DD (match_operand:SD 1 "register_operand" "f")))]
4039   "TARGET_HARD_DFP"
4040   "ldetr\t%0,%1,0"
4041   [(set_attr "op_type" "RRF")
4042    (set_attr "type"    "fsimptf")])
4043
4044 ; Binary <-> Decimal floating point trunc patterns
4045 ;
4046
4047 (define_insn "*trunc<BFP:mode><DFP_ALL:mode>2"
4048   [(set (reg:DFP_ALL FPR0_REGNUM)
4049         (float_truncate:DFP_ALL (reg:BFP FPR2_REGNUM)))
4050    (use (reg:SI GPR0_REGNUM))
4051    (clobber (reg:CC CC_REGNUM))]
4052   "TARGET_HARD_DFP"
4053   "pfpo")
4054
4055 (define_insn "*trunc<DFP_ALL:mode><BFP:mode>2"
4056   [(set (reg:BFP FPR0_REGNUM)
4057         (float_truncate:BFP (reg:DFP_ALL FPR2_REGNUM)))
4058    (use (reg:SI GPR0_REGNUM))
4059    (clobber (reg:CC CC_REGNUM))]
4060   "TARGET_HARD_DFP"
4061   "pfpo")
4062
4063 (define_expand "trunc<BFP:mode><DFP_ALL:mode>2"
4064   [(set (reg:BFP FPR2_REGNUM) (match_operand:BFP 1 "nonimmediate_operand" ""))
4065    (set (reg:SI GPR0_REGNUM) (match_dup 2))
4066    (parallel
4067     [(set (reg:DFP_ALL FPR0_REGNUM)
4068           (float_truncate:DFP_ALL (reg:BFP FPR2_REGNUM)))
4069      (use (reg:SI GPR0_REGNUM))
4070      (clobber (reg:CC CC_REGNUM))])
4071    (set (match_operand:DFP_ALL 0 "nonimmediate_operand" "")
4072         (reg:DFP_ALL FPR0_REGNUM))]
4073   "TARGET_HARD_DFP
4074    && GET_MODE_SIZE (<BFP:MODE>mode) > GET_MODE_SIZE (<DFP_ALL:MODE>mode)"
4075 {
4076   HOST_WIDE_INT flags;
4077
4078   flags = (PFPO_CONVERT |
4079            PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP0_TYPE_SHIFT |
4080            PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP1_TYPE_SHIFT);
4081
4082   operands[2] = GEN_INT (flags);
4083 })
4084
4085 (define_expand "trunc<DFP_ALL:mode><BFP:mode>2"
4086   [(set (reg:DFP_ALL FPR2_REGNUM)
4087         (match_operand:DFP_ALL 1 "nonimmediate_operand" ""))
4088    (set (reg:SI GPR0_REGNUM) (match_dup 2))
4089    (parallel
4090     [(set (reg:BFP FPR0_REGNUM) (float_truncate:BFP (reg:DFP_ALL FPR2_REGNUM)))
4091      (use (reg:SI GPR0_REGNUM))
4092      (clobber (reg:CC CC_REGNUM))])
4093    (set (match_operand:BFP 0 "nonimmediate_operand" "") (reg:BFP FPR0_REGNUM))]
4094   "TARGET_HARD_DFP
4095    && GET_MODE_SIZE (<DFP_ALL:MODE>mode) >= GET_MODE_SIZE (<BFP:MODE>mode)"
4096 {
4097   HOST_WIDE_INT flags;
4098
4099   flags = (PFPO_CONVERT |
4100            PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP0_TYPE_SHIFT |
4101            PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP1_TYPE_SHIFT);
4102
4103   operands[2] = GEN_INT (flags);
4104 })
4105
4106 ;
4107 ; Binary <-> Decimal floating point extend patterns
4108 ;
4109
4110 (define_insn "*extend<BFP:mode><DFP_ALL:mode>2"
4111   [(set (reg:DFP_ALL FPR0_REGNUM) (float_extend:DFP_ALL (reg:BFP FPR2_REGNUM)))
4112    (use (reg:SI GPR0_REGNUM))
4113    (clobber (reg:CC CC_REGNUM))]
4114   "TARGET_HARD_DFP"
4115   "pfpo")
4116
4117 (define_insn "*extend<DFP_ALL:mode><BFP:mode>2"
4118   [(set (reg:BFP FPR0_REGNUM) (float_extend:BFP (reg:DFP_ALL FPR2_REGNUM)))
4119    (use (reg:SI GPR0_REGNUM))
4120    (clobber (reg:CC CC_REGNUM))]
4121   "TARGET_HARD_DFP"
4122   "pfpo")
4123
4124 (define_expand "extend<BFP:mode><DFP_ALL:mode>2"
4125   [(set (reg:BFP FPR2_REGNUM) (match_operand:BFP 1 "nonimmediate_operand" ""))
4126    (set (reg:SI GPR0_REGNUM) (match_dup 2))
4127    (parallel
4128     [(set (reg:DFP_ALL FPR0_REGNUM)
4129           (float_extend:DFP_ALL (reg:BFP FPR2_REGNUM)))
4130      (use (reg:SI GPR0_REGNUM))
4131      (clobber (reg:CC CC_REGNUM))])
4132    (set (match_operand:DFP_ALL 0 "nonimmediate_operand" "")
4133         (reg:DFP_ALL FPR0_REGNUM))]
4134   "TARGET_HARD_DFP
4135    && GET_MODE_SIZE (<BFP:MODE>mode) <= GET_MODE_SIZE (<DFP_ALL:MODE>mode)"
4136 {
4137   HOST_WIDE_INT flags;
4138
4139   flags = (PFPO_CONVERT |
4140            PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP0_TYPE_SHIFT |
4141            PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP1_TYPE_SHIFT);
4142
4143   operands[2] = GEN_INT (flags);
4144 })
4145
4146 (define_expand "extend<DFP_ALL:mode><BFP:mode>2"
4147   [(set (reg:DFP_ALL FPR2_REGNUM)
4148         (match_operand:DFP_ALL 1 "nonimmediate_operand" ""))
4149    (set (reg:SI GPR0_REGNUM) (match_dup 2))
4150    (parallel
4151     [(set (reg:BFP FPR0_REGNUM) (float_extend:BFP (reg:DFP_ALL FPR2_REGNUM)))
4152      (use (reg:SI GPR0_REGNUM))
4153      (clobber (reg:CC CC_REGNUM))])
4154    (set (match_operand:BFP 0 "nonimmediate_operand" "") (reg:BFP FPR0_REGNUM))]
4155   "TARGET_HARD_DFP
4156    && GET_MODE_SIZE (<DFP_ALL:MODE>mode) < GET_MODE_SIZE (<BFP:MODE>mode)"
4157 {
4158   HOST_WIDE_INT flags;
4159
4160   flags = (PFPO_CONVERT |
4161            PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP0_TYPE_SHIFT |
4162            PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP1_TYPE_SHIFT);
4163
4164   operands[2] = GEN_INT (flags);
4165 })
4166
4167
4168 ;;
4169 ;; ARITHMETIC OPERATIONS
4170 ;;
4171 ;  arithmetic operations set the ConditionCode,
4172 ;  because of unpredictable Bits in Register for Halfword and Byte
4173 ;  the ConditionCode can be set wrong in operations for Halfword and Byte
4174
4175 ;;
4176 ;;- Add instructions.
4177 ;;
4178
4179 ;
4180 ; addti3 instruction pattern(s).
4181 ;
4182
4183 (define_insn_and_split "addti3"
4184   [(set (match_operand:TI 0 "register_operand" "=&d")
4185         (plus:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
4186                  (match_operand:TI 2 "general_operand" "do") ) )
4187    (clobber (reg:CC CC_REGNUM))]
4188   "TARGET_64BIT"
4189   "#"
4190   "&& reload_completed"
4191   [(parallel
4192     [(set (reg:CCL1 CC_REGNUM)
4193           (compare:CCL1 (plus:DI (match_dup 7) (match_dup 8))
4194                         (match_dup 7)))
4195      (set (match_dup 6) (plus:DI (match_dup 7) (match_dup 8)))])
4196    (parallel
4197     [(set (match_dup 3) (plus:DI
4198                           (plus:DI (ltu:DI (reg:CCL1 CC_REGNUM) (const_int 0))
4199                                    (match_dup 4)) (match_dup 5)))
4200      (clobber (reg:CC CC_REGNUM))])]
4201   "operands[3] = operand_subword (operands[0], 0, 0, TImode);
4202    operands[4] = operand_subword (operands[1], 0, 0, TImode);
4203    operands[5] = operand_subword (operands[2], 0, 0, TImode);
4204    operands[6] = operand_subword (operands[0], 1, 0, TImode);
4205    operands[7] = operand_subword (operands[1], 1, 0, TImode);
4206    operands[8] = operand_subword (operands[2], 1, 0, TImode);")
4207
4208 ;
4209 ; adddi3 instruction pattern(s).
4210 ;
4211
4212 (define_expand "adddi3"
4213   [(parallel
4214     [(set (match_operand:DI 0 "nonimmediate_operand" "")
4215           (plus:DI (match_operand:DI 1 "nonimmediate_operand" "")
4216                    (match_operand:DI 2 "general_operand" "")))
4217      (clobber (reg:CC CC_REGNUM))])]
4218   ""
4219   "")
4220
4221 (define_insn "*adddi3_sign"
4222   [(set (match_operand:DI 0 "register_operand" "=d,d")
4223         (plus:DI (sign_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))
4224                  (match_operand:DI 1 "register_operand" "0,0")))
4225    (clobber (reg:CC CC_REGNUM))]
4226   "TARGET_64BIT"
4227   "@
4228    agfr\t%0,%2
4229    agf\t%0,%2"
4230   [(set_attr "op_type"  "RRE,RXY")])
4231
4232 (define_insn "*adddi3_zero_cc"
4233   [(set (reg CC_REGNUM)
4234         (compare (plus:DI (zero_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))
4235                           (match_operand:DI 1 "register_operand" "0,0"))
4236                  (const_int 0)))
4237    (set (match_operand:DI 0 "register_operand" "=d,d")
4238         (plus:DI (zero_extend:DI (match_dup 2)) (match_dup 1)))]
4239   "s390_match_ccmode (insn, CCLmode) && TARGET_64BIT"
4240   "@
4241    algfr\t%0,%2
4242    algf\t%0,%2"
4243   [(set_attr "op_type"  "RRE,RXY")
4244    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
4245
4246 (define_insn "*adddi3_zero_cconly"
4247   [(set (reg CC_REGNUM)
4248         (compare (plus:DI (zero_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))
4249                           (match_operand:DI 1 "register_operand" "0,0"))
4250                  (const_int 0)))
4251    (clobber (match_scratch:DI 0 "=d,d"))]
4252   "s390_match_ccmode (insn, CCLmode) && TARGET_64BIT"
4253   "@
4254    algfr\t%0,%2
4255    algf\t%0,%2"
4256   [(set_attr "op_type"  "RRE,RXY")
4257    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
4258
4259 (define_insn "*adddi3_zero"
4260   [(set (match_operand:DI 0 "register_operand" "=d,d")
4261         (plus:DI (zero_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))
4262                  (match_operand:DI 1 "register_operand" "0,0")))
4263    (clobber (reg:CC CC_REGNUM))]
4264   "TARGET_64BIT"
4265   "@
4266    algfr\t%0,%2
4267    algf\t%0,%2"
4268   [(set_attr "op_type"  "RRE,RXY")
4269    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
4270
4271 (define_insn_and_split "*adddi3_31z"
4272   [(set (match_operand:DI 0 "nonimmediate_operand" "=&d")
4273         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
4274                  (match_operand:DI 2 "general_operand" "do") ) )
4275    (clobber (reg:CC CC_REGNUM))]
4276   "!TARGET_64BIT && TARGET_CPU_ZARCH"
4277   "#"
4278   "&& reload_completed"
4279   [(parallel
4280     [(set (reg:CCL1 CC_REGNUM)
4281           (compare:CCL1 (plus:SI (match_dup 7) (match_dup 8))
4282                         (match_dup 7)))
4283      (set (match_dup 6) (plus:SI (match_dup 7) (match_dup 8)))])
4284    (parallel
4285     [(set (match_dup 3) (plus:SI
4286                           (plus:SI (ltu:SI (reg:CCL1 CC_REGNUM) (const_int 0))
4287                                    (match_dup 4)) (match_dup 5)))
4288      (clobber (reg:CC CC_REGNUM))])]
4289   "operands[3] = operand_subword (operands[0], 0, 0, DImode);
4290    operands[4] = operand_subword (operands[1], 0, 0, DImode);
4291    operands[5] = operand_subword (operands[2], 0, 0, DImode);
4292    operands[6] = operand_subword (operands[0], 1, 0, DImode);
4293    operands[7] = operand_subword (operands[1], 1, 0, DImode);
4294    operands[8] = operand_subword (operands[2], 1, 0, DImode);")
4295
4296 (define_insn_and_split "*adddi3_31"
4297   [(set (match_operand:DI 0 "nonimmediate_operand" "=&d")
4298         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
4299                  (match_operand:DI 2 "general_operand" "do") ) )
4300    (clobber (reg:CC CC_REGNUM))]
4301   "!TARGET_CPU_ZARCH"
4302   "#"
4303   "&& reload_completed"
4304   [(parallel
4305     [(set (match_dup 3) (plus:SI (match_dup 4) (match_dup 5)))
4306      (clobber (reg:CC CC_REGNUM))])
4307    (parallel
4308     [(set (reg:CCL1 CC_REGNUM)
4309           (compare:CCL1 (plus:SI (match_dup 7) (match_dup 8))
4310                         (match_dup 7)))
4311      (set (match_dup 6) (plus:SI (match_dup 7) (match_dup 8)))])
4312    (set (pc)
4313         (if_then_else (ltu (reg:CCL1 CC_REGNUM) (const_int 0))
4314                       (pc)
4315                       (label_ref (match_dup 9))))
4316    (parallel
4317     [(set (match_dup 3) (plus:SI (match_dup 3) (const_int 1)))
4318      (clobber (reg:CC CC_REGNUM))])
4319    (match_dup 9)]
4320   "operands[3] = operand_subword (operands[0], 0, 0, DImode);
4321    operands[4] = operand_subword (operands[1], 0, 0, DImode);
4322    operands[5] = operand_subword (operands[2], 0, 0, DImode);
4323    operands[6] = operand_subword (operands[0], 1, 0, DImode);
4324    operands[7] = operand_subword (operands[1], 1, 0, DImode);
4325    operands[8] = operand_subword (operands[2], 1, 0, DImode);
4326    operands[9] = gen_label_rtx ();")
4327
4328 ;
4329 ; addsi3 instruction pattern(s).
4330 ;
4331
4332 (define_expand "addsi3"
4333   [(parallel
4334     [(set (match_operand:SI 0 "nonimmediate_operand" "")
4335           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "")
4336                    (match_operand:SI 2 "general_operand" "")))
4337      (clobber (reg:CC CC_REGNUM))])]
4338   ""
4339   "")
4340
4341 (define_insn "*addsi3_sign"
4342   [(set (match_operand:SI 0 "register_operand" "=d,d")
4343         (plus:SI (sign_extend:SI (match_operand:HI 2 "memory_operand" "R,T"))
4344                  (match_operand:SI 1 "register_operand" "0,0")))
4345    (clobber (reg:CC CC_REGNUM))]
4346   ""
4347   "@
4348    ah\t%0,%2
4349    ahy\t%0,%2"
4350   [(set_attr "op_type"  "RX,RXY")])
4351
4352 ;
4353 ; add(di|si)3 instruction pattern(s).
4354 ;
4355
4356 ; ar, ahi, alfi, slfi, a, ay, agr, aghi, algfi, slgfi, ag, asi, agsi
4357 (define_insn "*add<mode>3"
4358   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,d,d,d,d,d,QS")
4359         (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0,0,0,0,0")
4360                   (match_operand:GPR 2 "general_operand" "d,K,Op,On,R,T,C") ) )
4361    (clobber (reg:CC CC_REGNUM))]
4362   ""
4363   "@
4364    a<g>r\t%0,%2
4365    a<g>hi\t%0,%h2
4366    al<g>fi\t%0,%2
4367    sl<g>fi\t%0,%n2
4368    a<g>\t%0,%2
4369    a<y>\t%0,%2
4370    a<g>si\t%0,%c2"
4371   [(set_attr "op_type"  "RR<E>,RI,RIL,RIL,RX<Y>,RXY,SIY")
4372    (set_attr "cpu_facility" "*,*,extimm,extimm,*,*,z10")
4373    (set_attr "z10prop" "z10_super_E1,
4374                         z10_super_E1,
4375                         z10_super_E1,
4376                         z10_super_E1,
4377                         z10_super_E1,
4378                         z10_super_E1,
4379                         z10_super_E1")])
4380
4381 ; alr, alfi, slfi, al, aly, algr, algfi, slgfi, alg, alsi, algsi
4382 (define_insn "*add<mode>3_carry1_cc"
4383   [(set (reg CC_REGNUM)
4384         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0,0,0,0")
4385                            (match_operand:GPR 2 "general_operand" "d,Op,On,R,T,C"))
4386                  (match_dup 1)))
4387    (set (match_operand:GPR 0 "nonimmediate_operand" "=d,d,d,d,d,d")
4388         (plus:GPR (match_dup 1) (match_dup 2)))]
4389   "s390_match_ccmode (insn, CCL1mode)"
4390   "@
4391    al<g>r\t%0,%2
4392    al<g>fi\t%0,%2
4393    sl<g>fi\t%0,%n2
4394    al<g>\t%0,%2
4395    al<y>\t%0,%2
4396    al<g>si\t%0,%c2"
4397   [(set_attr "op_type"      "RR<E>,RIL,RIL,RX<Y>,RXY,SIY")
4398    (set_attr "cpu_facility" "*,extimm,extimm,*,*,z10")
4399    (set_attr "z10prop" "z10_super_E1,
4400                         z10_super_E1,
4401                         z10_super_E1,
4402                         z10_super_E1,
4403                         z10_super_E1,
4404                         z10_super_E1")])
4405
4406 ; alr, al, aly, algr, alg
4407 (define_insn "*add<mode>3_carry1_cconly"
4408   [(set (reg CC_REGNUM)
4409         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0")
4410                            (match_operand:GPR 2 "general_operand" "d,R,T"))
4411                  (match_dup 1)))
4412    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4413   "s390_match_ccmode (insn, CCL1mode)"
4414   "@
4415    al<g>r\t%0,%2
4416    al<g>\t%0,%2
4417    al<y>\t%0,%2"
4418   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4419    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
4420
4421 ; alr, alfi, slfi, al, aly, algr, algfi, slgfi, alg, alsi, algsi
4422 (define_insn "*add<mode>3_carry2_cc"
4423   [(set (reg CC_REGNUM)
4424         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0,0,0,0")
4425                            (match_operand:GPR 2 "general_operand" "d,Op,On,R,T,C"))
4426                  (match_dup 2)))
4427    (set (match_operand:GPR 0 "nonimmediate_operand" "=d,d,d,d,d,RS")
4428         (plus:GPR (match_dup 1) (match_dup 2)))]
4429   "s390_match_ccmode (insn, CCL1mode)"
4430   "@
4431    al<g>r\t%0,%2
4432    al<g>fi\t%0,%2
4433    sl<g>fi\t%0,%n2
4434    al<g>\t%0,%2
4435    al<y>\t%0,%2
4436    al<g>si\t%0,%c2"
4437   [(set_attr "op_type"  "RR<E>,RIL,RIL,RX<Y>,RXY,SIY")
4438    (set_attr "cpu_facility" "*,extimm,extimm,*,*,z10")
4439    (set_attr "z10prop" "z10_super_E1,
4440                         z10_super_E1,
4441                         z10_super_E1,
4442                         z10_super_E1,
4443                         z10_super_E1,
4444                         z10_super_E1")])
4445
4446 ; alr, al, aly, algr, alg
4447 (define_insn "*add<mode>3_carry2_cconly"
4448   [(set (reg CC_REGNUM)
4449         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0")
4450                            (match_operand:GPR 2 "general_operand" "d,R,T"))
4451                  (match_dup 2)))
4452    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4453   "s390_match_ccmode (insn, CCL1mode)"
4454   "@
4455    al<g>r\t%0,%2
4456    al<g>\t%0,%2
4457    al<y>\t%0,%2"
4458   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4459    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
4460
4461 ; alr, alfi, slfi, al, aly, algr, algfi, slgfi, alg, alsi, algsi
4462 (define_insn "*add<mode>3_cc"
4463   [(set (reg CC_REGNUM)
4464         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0,0,0,0")
4465                            (match_operand:GPR 2 "general_operand" "d,Op,On,R,T,C"))
4466                  (const_int 0)))
4467    (set (match_operand:GPR 0 "nonimmediate_operand" "=d,d,d,d,d,RS")
4468         (plus:GPR (match_dup 1) (match_dup 2)))]
4469   "s390_match_ccmode (insn, CCLmode)"
4470   "@
4471    al<g>r\t%0,%2
4472    al<g>fi\t%0,%2
4473    sl<g>fi\t%0,%n2
4474    al<g>\t%0,%2
4475    al<y>\t%0,%2
4476    al<g>si\t%0,%c2"
4477   [(set_attr "op_type"  "RR<E>,RIL,RIL,RX<Y>,RXY,SIY")
4478    (set_attr "cpu_facility" "*,extimm,extimm,*,*,z10")
4479    (set_attr "z10prop" "z10_super_E1,
4480                         z10_super_E1,
4481                         z10_super_E1,
4482                         z10_super_E1,
4483                         z10_super_E1,
4484                         z10_super_E1")])
4485
4486 ; alr, al, aly, algr, alg
4487 (define_insn "*add<mode>3_cconly"
4488   [(set (reg CC_REGNUM)
4489         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0")
4490                            (match_operand:GPR 2 "general_operand" "d,R,T"))
4491                  (const_int 0)))
4492    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4493   "s390_match_ccmode (insn, CCLmode)"
4494   "@
4495    al<g>r\t%0,%2
4496    al<g>\t%0,%2
4497    al<y>\t%0,%2"
4498   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4499    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
4500
4501 ; alr, al, aly, algr, alg
4502 (define_insn "*add<mode>3_cconly2"
4503   [(set (reg CC_REGNUM)
4504         (compare (match_operand:GPR 1 "nonimmediate_operand" "%0,0,0")
4505                  (neg:GPR (match_operand:GPR 2 "general_operand" "d,R,T"))))
4506    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4507   "s390_match_ccmode(insn, CCLmode)"
4508   "@
4509    al<g>r\t%0,%2
4510    al<g>\t%0,%2
4511    al<y>\t%0,%2"
4512   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4513    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
4514
4515 ; ahi, afi, aghi, agfi, asi, agsi
4516 (define_insn "*add<mode>3_imm_cc"
4517   [(set (reg CC_REGNUM)
4518         (compare (plus:GPR (match_operand:GPR 1 "nonimmediate_operand" "0,0,0")
4519                            (match_operand:GPR 2 "const_int_operand" "K,Os,C"))
4520                  (const_int 0)))
4521    (set (match_operand:GPR 0 "nonimmediate_operand" "=d,d,QS")
4522         (plus:GPR (match_dup 1) (match_dup 2)))]
4523   "s390_match_ccmode (insn, CCAmode)
4524    && (CONST_OK_FOR_CONSTRAINT_P (INTVAL (operands[2]), 'K', \"K\")
4525        || CONST_OK_FOR_CONSTRAINT_P (INTVAL (operands[2]), 'O', \"Os\")
4526        || CONST_OK_FOR_CONSTRAINT_P (INTVAL (operands[2]), 'C', \"C\"))
4527    && INTVAL (operands[2]) != -((HOST_WIDE_INT)1 << (GET_MODE_BITSIZE(<MODE>mode) - 1))"
4528   "@
4529    a<g>hi\t%0,%h2
4530    a<g>fi\t%0,%2
4531    a<g>si\t%0,%c2"
4532   [(set_attr "op_type"      "RI,RIL,SIY")
4533    (set_attr "cpu_facility" "*,extimm,z10")
4534    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1")])
4535
4536 ;
4537 ; add(tf|df|sf|td|dd)3 instruction pattern(s).
4538 ;
4539
4540 ; axbr, adbr, aebr, axb, adb, aeb, adtr, axtr
4541 (define_insn "add<mode>3"
4542   [(set (match_operand:FP 0 "register_operand"              "=f,   f")
4543         (plus:FP (match_operand:FP 1 "nonimmediate_operand" "%<f0>,0")
4544                  (match_operand:FP 2 "general_operand"      " f,<Rf>")))
4545    (clobber (reg:CC CC_REGNUM))]
4546   "TARGET_HARD_FLOAT"
4547   "@
4548    a<xde><bt>r\t%0,<op1>%2
4549    a<xde>b\t%0,%2"
4550   [(set_attr "op_type"  "<RRer>,RXE")
4551    (set_attr "type"     "fsimp<mode>")])
4552
4553 ; axbr, adbr, aebr, axb, adb, aeb, adtr, axtr
4554 (define_insn "*add<mode>3_cc"
4555   [(set (reg CC_REGNUM)
4556         (compare (plus:FP (match_operand:FP 1 "nonimmediate_operand" "%<f0>,0")
4557                           (match_operand:FP 2 "general_operand"      " f,<Rf>"))
4558                  (match_operand:FP 3 "const0_operand" "")))
4559    (set (match_operand:FP 0 "register_operand" "=f,f")
4560         (plus:FP (match_dup 1) (match_dup 2)))]
4561   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
4562   "@
4563    a<xde><bt>r\t%0,<op1>%2
4564    a<xde>b\t%0,%2"
4565   [(set_attr "op_type"  "<RRer>,RXE")
4566    (set_attr "type"     "fsimp<mode>")])
4567
4568 ; axbr, adbr, aebr, axb, adb, aeb, adtr, axtr
4569 (define_insn "*add<mode>3_cconly"
4570   [(set (reg CC_REGNUM)
4571         (compare (plus:FP (match_operand:FP 1 "nonimmediate_operand" "%<f0>,0")
4572                            (match_operand:FP 2 "general_operand"      " f,<Rf>"))
4573                  (match_operand:FP 3 "const0_operand" "")))
4574    (clobber (match_scratch:FP 0 "=f,f"))]
4575   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
4576   "@
4577    a<xde><bt>r\t%0,<op1>%2
4578    a<xde>b\t%0,%2"
4579   [(set_attr "op_type"  "<RRer>,RXE")
4580    (set_attr "type"     "fsimp<mode>")])
4581
4582
4583 ;;
4584 ;;- Subtract instructions.
4585 ;;
4586
4587 ;
4588 ; subti3 instruction pattern(s).
4589 ;
4590
4591 (define_insn_and_split "subti3"
4592   [(set (match_operand:TI 0 "register_operand" "=&d")
4593         (minus:TI (match_operand:TI 1 "register_operand" "0")
4594                   (match_operand:TI 2 "general_operand" "do") ) )
4595    (clobber (reg:CC CC_REGNUM))]
4596   "TARGET_64BIT"
4597   "#"
4598   "&& reload_completed"
4599   [(parallel
4600     [(set (reg:CCL2 CC_REGNUM)
4601           (compare:CCL2 (minus:DI (match_dup 7) (match_dup 8))
4602                         (match_dup 7)))
4603      (set (match_dup 6) (minus:DI (match_dup 7) (match_dup 8)))])
4604    (parallel
4605     [(set (match_dup 3) (minus:DI (minus:DI (match_dup 4) (match_dup 5))
4606                                   (gtu:DI (reg:CCL2 CC_REGNUM) (const_int 0))))
4607      (clobber (reg:CC CC_REGNUM))])]
4608   "operands[3] = operand_subword (operands[0], 0, 0, TImode);
4609    operands[4] = operand_subword (operands[1], 0, 0, TImode);
4610    operands[5] = operand_subword (operands[2], 0, 0, TImode);
4611    operands[6] = operand_subword (operands[0], 1, 0, TImode);
4612    operands[7] = operand_subword (operands[1], 1, 0, TImode);
4613    operands[8] = operand_subword (operands[2], 1, 0, TImode);")
4614
4615 ;
4616 ; subdi3 instruction pattern(s).
4617 ;
4618
4619 (define_expand "subdi3"
4620   [(parallel
4621     [(set (match_operand:DI 0 "register_operand" "")
4622           (minus:DI (match_operand:DI 1 "register_operand" "")
4623                     (match_operand:DI 2 "general_operand" "")))
4624      (clobber (reg:CC CC_REGNUM))])]
4625   ""
4626   "")
4627
4628 (define_insn "*subdi3_sign"
4629   [(set (match_operand:DI 0 "register_operand" "=d,d")
4630         (minus:DI (match_operand:DI 1 "register_operand" "0,0")
4631                   (sign_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))))
4632    (clobber (reg:CC CC_REGNUM))]
4633   "TARGET_64BIT"
4634   "@
4635    sgfr\t%0,%2
4636    sgf\t%0,%2"
4637   [(set_attr "op_type"  "RRE,RXY")
4638    (set_attr "z10prop" "z10_c,*")])
4639
4640 (define_insn "*subdi3_zero_cc"
4641   [(set (reg CC_REGNUM)
4642         (compare (minus:DI (match_operand:DI 1 "register_operand" "0,0")
4643                            (zero_extend:DI (match_operand:SI 2 "general_operand" "d,RT")))
4644                  (const_int 0)))
4645    (set (match_operand:DI 0 "register_operand" "=d,d")
4646         (minus:DI (match_dup 1) (zero_extend:DI (match_dup 2))))]
4647   "s390_match_ccmode (insn, CCLmode) && TARGET_64BIT"
4648   "@
4649    slgfr\t%0,%2
4650    slgf\t%0,%2"
4651   [(set_attr "op_type"  "RRE,RXY")
4652    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1")])
4653
4654 (define_insn "*subdi3_zero_cconly"
4655   [(set (reg CC_REGNUM)
4656         (compare (minus:DI (match_operand:DI 1 "register_operand" "0,0")
4657                            (zero_extend:DI (match_operand:SI 2 "general_operand" "d,RT")))
4658                  (const_int 0)))
4659    (clobber (match_scratch:DI 0 "=d,d"))]
4660   "s390_match_ccmode (insn, CCLmode) && TARGET_64BIT"
4661   "@
4662    slgfr\t%0,%2
4663    slgf\t%0,%2"
4664   [(set_attr "op_type"  "RRE,RXY")
4665    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1")])
4666
4667 (define_insn "*subdi3_zero"
4668   [(set (match_operand:DI 0 "register_operand" "=d,d")
4669         (minus:DI (match_operand:DI 1 "register_operand" "0,0")
4670                   (zero_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))))
4671    (clobber (reg:CC CC_REGNUM))]
4672   "TARGET_64BIT"
4673   "@
4674    slgfr\t%0,%2
4675    slgf\t%0,%2"
4676   [(set_attr "op_type"  "RRE,RXY")
4677    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1")])
4678
4679 (define_insn_and_split "*subdi3_31z"
4680   [(set (match_operand:DI 0 "register_operand" "=&d")
4681         (minus:DI (match_operand:DI 1 "register_operand" "0")
4682                   (match_operand:DI 2 "general_operand" "do") ) )
4683    (clobber (reg:CC CC_REGNUM))]
4684   "!TARGET_64BIT && TARGET_CPU_ZARCH"
4685   "#"
4686   "&& reload_completed"
4687   [(parallel
4688     [(set (reg:CCL2 CC_REGNUM)
4689           (compare:CCL2 (minus:SI (match_dup 7) (match_dup 8))
4690                         (match_dup 7)))
4691      (set (match_dup 6) (minus:SI (match_dup 7) (match_dup 8)))])
4692    (parallel
4693     [(set (match_dup 3) (minus:SI (minus:SI (match_dup 4) (match_dup 5))
4694                                   (gtu:SI (reg:CCL2 CC_REGNUM) (const_int 0))))
4695      (clobber (reg:CC CC_REGNUM))])]
4696   "operands[3] = operand_subword (operands[0], 0, 0, DImode);
4697    operands[4] = operand_subword (operands[1], 0, 0, DImode);
4698    operands[5] = operand_subword (operands[2], 0, 0, DImode);
4699    operands[6] = operand_subword (operands[0], 1, 0, DImode);
4700    operands[7] = operand_subword (operands[1], 1, 0, DImode);
4701    operands[8] = operand_subword (operands[2], 1, 0, DImode);")
4702
4703 (define_insn_and_split "*subdi3_31"
4704   [(set (match_operand:DI 0 "register_operand" "=&d")
4705         (minus:DI (match_operand:DI 1 "register_operand" "0")
4706                   (match_operand:DI 2 "general_operand" "do") ) )
4707    (clobber (reg:CC CC_REGNUM))]
4708   "!TARGET_CPU_ZARCH"
4709   "#"
4710   "&& reload_completed"
4711   [(parallel
4712     [(set (match_dup 3) (minus:SI (match_dup 4) (match_dup 5)))
4713      (clobber (reg:CC CC_REGNUM))])
4714    (parallel
4715     [(set (reg:CCL2 CC_REGNUM)
4716           (compare:CCL2 (minus:SI (match_dup 7) (match_dup 8))
4717                         (match_dup 7)))
4718      (set (match_dup 6) (minus:SI (match_dup 7) (match_dup 8)))])
4719    (set (pc)
4720         (if_then_else (gtu (reg:CCL2 CC_REGNUM) (const_int 0))
4721                       (pc)
4722                       (label_ref (match_dup 9))))
4723    (parallel
4724     [(set (match_dup 3) (plus:SI (match_dup 3) (const_int -1)))
4725      (clobber (reg:CC CC_REGNUM))])
4726    (match_dup 9)]
4727   "operands[3] = operand_subword (operands[0], 0, 0, DImode);
4728    operands[4] = operand_subword (operands[1], 0, 0, DImode);
4729    operands[5] = operand_subword (operands[2], 0, 0, DImode);
4730    operands[6] = operand_subword (operands[0], 1, 0, DImode);
4731    operands[7] = operand_subword (operands[1], 1, 0, DImode);
4732    operands[8] = operand_subword (operands[2], 1, 0, DImode);
4733    operands[9] = gen_label_rtx ();")
4734
4735 ;
4736 ; subsi3 instruction pattern(s).
4737 ;
4738
4739 (define_expand "subsi3"
4740   [(parallel
4741     [(set (match_operand:SI 0 "register_operand" "")
4742           (minus:SI (match_operand:SI 1 "register_operand" "")
4743                     (match_operand:SI 2 "general_operand" "")))
4744      (clobber (reg:CC CC_REGNUM))])]
4745   ""
4746   "")
4747
4748 (define_insn "*subsi3_sign"
4749   [(set (match_operand:SI 0 "register_operand" "=d,d")
4750         (minus:SI (match_operand:SI 1 "register_operand" "0,0")
4751                   (sign_extend:SI (match_operand:HI 2 "memory_operand" "R,T"))))
4752    (clobber (reg:CC CC_REGNUM))]
4753   ""
4754   "@
4755    sh\t%0,%2
4756    shy\t%0,%2"
4757   [(set_attr "op_type"  "RX,RXY")])
4758
4759 ;
4760 ; sub(di|si)3 instruction pattern(s).
4761 ;
4762
4763 ; sr, s, sy, sgr, sg
4764 (define_insn "*sub<mode>3"
4765   [(set (match_operand:GPR 0 "register_operand" "=d,d,d")
4766         (minus:GPR (match_operand:GPR 1 "register_operand" "0,0,0")
4767                    (match_operand:GPR 2 "general_operand" "d,R,T") ) )
4768    (clobber (reg:CC CC_REGNUM))]
4769   ""
4770   "@
4771    s<g>r\t%0,%2
4772    s<g>\t%0,%2
4773    s<y>\t%0,%2"
4774   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4775    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4776
4777 ; slr, sl, sly, slgr, slg
4778 (define_insn "*sub<mode>3_borrow_cc"
4779   [(set (reg CC_REGNUM)
4780         (compare (minus:GPR (match_operand:GPR 1 "register_operand" "0,0,0")
4781                             (match_operand:GPR 2 "general_operand" "d,R,T"))
4782                  (match_dup 1)))
4783    (set (match_operand:GPR 0 "register_operand" "=d,d,d")
4784         (minus:GPR (match_dup 1) (match_dup 2)))]
4785   "s390_match_ccmode (insn, CCL2mode)"
4786   "@
4787    sl<g>r\t%0,%2
4788    sl<g>\t%0,%2
4789    sl<y>\t%0,%2"
4790   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4791    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4792
4793 ; slr, sl, sly, slgr, slg
4794 (define_insn "*sub<mode>3_borrow_cconly"
4795   [(set (reg CC_REGNUM)
4796         (compare (minus:GPR (match_operand:GPR 1 "register_operand" "0,0,0")
4797                             (match_operand:GPR 2 "general_operand" "d,R,T"))
4798                  (match_dup 1)))
4799    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4800   "s390_match_ccmode (insn, CCL2mode)"
4801   "@
4802    sl<g>r\t%0,%2
4803    sl<g>\t%0,%2
4804    sl<y>\t%0,%2"
4805   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4806    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4807
4808 ; slr, sl, sly, slgr, slg
4809 (define_insn "*sub<mode>3_cc"
4810   [(set (reg CC_REGNUM)
4811         (compare (minus:GPR (match_operand:GPR 1 "register_operand" "0,0,0")
4812                             (match_operand:GPR 2 "general_operand" "d,R,T"))
4813                  (const_int 0)))
4814    (set (match_operand:GPR 0 "register_operand" "=d,d,d")
4815         (minus:GPR (match_dup 1) (match_dup 2)))]
4816   "s390_match_ccmode (insn, CCLmode)"
4817   "@
4818    sl<g>r\t%0,%2
4819    sl<g>\t%0,%2
4820    sl<y>\t%0,%2"
4821   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4822    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4823
4824 ; slr, sl, sly, slgr, slg
4825 (define_insn "*sub<mode>3_cc2"
4826   [(set (reg CC_REGNUM)
4827         (compare (match_operand:GPR 1 "register_operand" "0,0,0")
4828                  (match_operand:GPR 2 "general_operand" "d,R,T")))
4829    (set (match_operand:GPR 0 "register_operand" "=d,d,d")
4830         (minus:GPR (match_dup 1) (match_dup 2)))]
4831   "s390_match_ccmode (insn, CCL3mode)"
4832   "@
4833    sl<g>r\t%0,%2
4834    sl<g>\t%0,%2
4835    sl<y>\t%0,%2"
4836   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4837    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4838
4839 ; slr, sl, sly, slgr, slg
4840 (define_insn "*sub<mode>3_cconly"
4841   [(set (reg CC_REGNUM)
4842         (compare (minus:GPR (match_operand:GPR 1 "register_operand" "0,0,0")
4843                             (match_operand:GPR 2 "general_operand" "d,R,T"))
4844                  (const_int 0)))
4845    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4846   "s390_match_ccmode (insn, CCLmode)"
4847   "@
4848    sl<g>r\t%0,%2
4849    sl<g>\t%0,%2
4850    sl<y>\t%0,%2"
4851   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4852    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4853
4854
4855 ; slr, sl, sly, slgr, slg
4856 (define_insn "*sub<mode>3_cconly2"
4857   [(set (reg CC_REGNUM)
4858         (compare (match_operand:GPR 1 "register_operand" "0,0,0")
4859                  (match_operand:GPR 2 "general_operand" "d,R,T")))
4860    (clobber (match_scratch:GPR 0 "=d,d,d"))]
4861   "s390_match_ccmode (insn, CCL3mode)"
4862   "@
4863    sl<g>r\t%0,%2
4864    sl<g>\t%0,%2
4865    sl<y>\t%0,%2"
4866   [(set_attr "op_type"  "RR<E>,RX<Y>,RXY")
4867    (set_attr "z10prop" "z10_super_c_E1,z10_super_E1,z10_super_E1")])
4868
4869
4870 ;
4871 ; sub(tf|df|sf|td|dd)3 instruction pattern(s).
4872 ;
4873
4874 ; sxbr, sdbr, sebr, sxb, sdb, seb, sxtr, sdtr
4875 (define_insn "sub<mode>3"
4876   [(set (match_operand:FP 0 "register_operand"            "=f,  f")
4877         (minus:FP (match_operand:FP 1 "register_operand" "<f0>,0")
4878                   (match_operand:FP 2 "general_operand"  "f,<Rf>")))
4879    (clobber (reg:CC CC_REGNUM))]
4880   "TARGET_HARD_FLOAT"
4881   "@
4882    s<xde><bt>r\t%0,<op1>%2
4883    s<xde>b\t%0,%2"
4884   [(set_attr "op_type"  "<RRer>,RXE")
4885    (set_attr "type"     "fsimp<mode>")])
4886
4887 ; sxbr, sdbr, sebr, sxb, sdb, seb, sxtr, sdtr
4888 (define_insn "*sub<mode>3_cc"
4889   [(set (reg CC_REGNUM)
4890         (compare (minus:FP (match_operand:FP 1 "nonimmediate_operand" "<f0>,0")
4891                            (match_operand:FP 2 "general_operand"      "f,<Rf>"))
4892                  (match_operand:FP 3 "const0_operand" "")))
4893    (set (match_operand:FP 0 "register_operand" "=f,f")
4894         (minus:FP (match_dup 1) (match_dup 2)))]
4895   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
4896   "@
4897    s<xde><bt>r\t%0,<op1>%2
4898    s<xde>b\t%0,%2"
4899   [(set_attr "op_type"  "<RRer>,RXE")
4900    (set_attr "type"     "fsimp<mode>")])
4901
4902 ; sxbr, sdbr, sebr, sxb, sdb, seb, sxtr, sdtr
4903 (define_insn "*sub<mode>3_cconly"
4904   [(set (reg CC_REGNUM)
4905         (compare (minus:FP (match_operand:FP 1 "nonimmediate_operand" "<f0>,0")
4906                            (match_operand:FP 2 "general_operand"      "f,<Rf>"))
4907                  (match_operand:FP 3 "const0_operand" "")))
4908    (clobber (match_scratch:FP 0 "=f,f"))]
4909   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
4910   "@
4911    s<xde><bt>r\t%0,<op1>%2
4912    s<xde>b\t%0,%2"
4913   [(set_attr "op_type"  "<RRer>,RXE")
4914    (set_attr "type"     "fsimp<mode>")])
4915
4916
4917 ;;
4918 ;;- Conditional add/subtract instructions.
4919 ;;
4920
4921 ;
4922 ; add(di|si)cc instruction pattern(s).
4923 ;
4924
4925 ; the following 4 patterns are used when the result of an add with
4926 ; carry is checked for an overflow condition
4927
4928 ; op1 + op2 + c < op1
4929
4930 ; alcr, alc, alcgr, alcg
4931 (define_insn "*add<mode>3_alc_carry1_cc"
4932   [(set (reg CC_REGNUM)
4933         (compare
4934           (plus:GPR (plus:GPR (match_operand:GPR 3 "s390_alc_comparison" "")
4935                               (match_operand:GPR 1 "nonimmediate_operand" "%0,0"))
4936                     (match_operand:GPR 2 "general_operand" "d,RT"))
4937           (match_dup 1)))
4938    (set (match_operand:GPR 0 "register_operand" "=d,d")
4939         (plus:GPR (plus:GPR (match_dup 3) (match_dup 1)) (match_dup 2)))]
4940   "s390_match_ccmode (insn, CCL1mode) && TARGET_CPU_ZARCH"
4941   "@
4942    alc<g>r\t%0,%2
4943    alc<g>\t%0,%2"
4944   [(set_attr "op_type"  "RRE,RXY")])
4945
4946 ; alcr, alc, alcgr, alcg
4947 (define_insn "*add<mode>3_alc_carry1_cconly"
4948   [(set (reg CC_REGNUM)
4949         (compare
4950           (plus:GPR (plus:GPR (match_operand:GPR 3 "s390_alc_comparison" "")
4951                               (match_operand:GPR 1 "nonimmediate_operand" "%0,0"))
4952                     (match_operand:GPR 2 "general_operand" "d,RT"))
4953           (match_dup 1)))
4954    (clobber (match_scratch:GPR 0 "=d,d"))]
4955   "s390_match_ccmode (insn, CCL1mode) && TARGET_CPU_ZARCH"
4956   "@
4957    alc<g>r\t%0,%2
4958    alc<g>\t%0,%2"
4959   [(set_attr "op_type"  "RRE,RXY")])
4960
4961 ; op1 + op2 + c < op2
4962
4963 ; alcr, alc, alcgr, alcg
4964 (define_insn "*add<mode>3_alc_carry2_cc"
4965   [(set (reg CC_REGNUM)
4966         (compare
4967           (plus:GPR (plus:GPR (match_operand:GPR 3 "s390_alc_comparison" "")
4968                               (match_operand:GPR 1 "nonimmediate_operand" "%0,0"))
4969                     (match_operand:GPR 2 "general_operand" "d,RT"))
4970           (match_dup 2)))
4971    (set (match_operand:GPR 0 "register_operand" "=d,d")
4972         (plus:GPR (plus:GPR (match_dup 3) (match_dup 1)) (match_dup 2)))]
4973   "s390_match_ccmode (insn, CCL1mode) && TARGET_CPU_ZARCH"
4974   "@
4975    alc<g>r\t%0,%2
4976    alc<g>\t%0,%2"
4977   [(set_attr "op_type"  "RRE,RXY")])
4978
4979 ; alcr, alc, alcgr, alcg
4980 (define_insn "*add<mode>3_alc_carry2_cconly"
4981   [(set (reg CC_REGNUM)
4982         (compare
4983           (plus:GPR (plus:GPR (match_operand:GPR 3 "s390_alc_comparison" "")
4984                               (match_operand:GPR 1 "nonimmediate_operand" "%0,0"))
4985                     (match_operand:GPR 2 "general_operand" "d,RT"))
4986           (match_dup 2)))
4987    (clobber (match_scratch:GPR 0 "=d,d"))]
4988   "s390_match_ccmode (insn, CCL1mode) && TARGET_CPU_ZARCH"
4989   "@
4990    alc<g>r\t%0,%2
4991    alc<g>\t%0,%2"
4992   [(set_attr "op_type"  "RRE,RXY")])
4993
4994 ; alcr, alc, alcgr, alcg
4995 (define_insn "*add<mode>3_alc_cc"
4996   [(set (reg CC_REGNUM)
4997         (compare
4998           (plus:GPR (plus:GPR (match_operand:GPR 3 "s390_alc_comparison" "")
4999                               (match_operand:GPR 1 "nonimmediate_operand" "%0,0"))
5000                     (match_operand:GPR 2 "general_operand" "d,RT"))
5001           (const_int 0)))
5002    (set (match_operand:GPR 0 "register_operand" "=d,d")
5003         (plus:GPR (plus:GPR (match_dup 3) (match_dup 1)) (match_dup 2)))]
5004   "s390_match_ccmode (insn, CCLmode) && TARGET_CPU_ZARCH"
5005   "@
5006    alc<g>r\t%0,%2
5007    alc<g>\t%0,%2"
5008   [(set_attr "op_type"  "RRE,RXY")])
5009
5010 ; alcr, alc, alcgr, alcg
5011 (define_insn "*add<mode>3_alc"
5012   [(set (match_operand:GPR 0 "register_operand" "=d,d")
5013         (plus:GPR (plus:GPR (match_operand:GPR 3 "s390_alc_comparison" "")
5014                             (match_operand:GPR 1 "nonimmediate_operand" "%0,0"))
5015                   (match_operand:GPR 2 "general_operand" "d,RT")))
5016    (clobber (reg:CC CC_REGNUM))]
5017   "TARGET_CPU_ZARCH"
5018   "@
5019    alc<g>r\t%0,%2
5020    alc<g>\t%0,%2"
5021   [(set_attr "op_type"  "RRE,RXY")])
5022
5023 ; slbr, slb, slbgr, slbg
5024 (define_insn "*sub<mode>3_slb_cc"
5025   [(set (reg CC_REGNUM)
5026         (compare
5027           (minus:GPR (minus:GPR (match_operand:GPR 1 "nonimmediate_operand" "0,0")
5028                                 (match_operand:GPR 2 "general_operand" "d,RT"))
5029                      (match_operand:GPR 3 "s390_slb_comparison" ""))
5030           (const_int 0)))
5031    (set (match_operand:GPR 0 "register_operand" "=d,d")
5032         (minus:GPR (minus:GPR (match_dup 1) (match_dup 2)) (match_dup 3)))]
5033   "s390_match_ccmode (insn, CCLmode) && TARGET_CPU_ZARCH"
5034   "@
5035    slb<g>r\t%0,%2
5036    slb<g>\t%0,%2"
5037   [(set_attr "op_type"  "RRE,RXY")
5038    (set_attr "z10prop" "z10_c,*")])
5039
5040 ; slbr, slb, slbgr, slbg
5041 (define_insn "*sub<mode>3_slb"
5042   [(set (match_operand:GPR 0 "register_operand" "=d,d")
5043         (minus:GPR (minus:GPR (match_operand:GPR 1 "nonimmediate_operand" "0,0")
5044                               (match_operand:GPR 2 "general_operand" "d,RT"))
5045                    (match_operand:GPR 3 "s390_slb_comparison" "")))
5046    (clobber (reg:CC CC_REGNUM))]
5047   "TARGET_CPU_ZARCH"
5048   "@
5049    slb<g>r\t%0,%2
5050    slb<g>\t%0,%2"
5051   [(set_attr "op_type"  "RRE,RXY")
5052    (set_attr "z10prop" "z10_c,*")])
5053
5054 (define_expand "add<mode>cc"
5055   [(match_operand:GPR 0 "register_operand" "")
5056    (match_operand 1 "comparison_operator" "")
5057    (match_operand:GPR 2 "register_operand" "")
5058    (match_operand:GPR 3 "const_int_operand" "")]
5059   "TARGET_CPU_ZARCH"
5060   "if (!s390_expand_addcc (GET_CODE (operands[1]),
5061                            s390_compare_op0, s390_compare_op1,
5062                            operands[0], operands[2],
5063                            operands[3])) FAIL; DONE;")
5064
5065 ;
5066 ; scond instruction pattern(s).
5067 ;
5068
5069 (define_insn_and_split "*scond<mode>"
5070   [(set (match_operand:GPR 0 "register_operand" "=&d")
5071         (match_operand:GPR 1 "s390_alc_comparison" ""))
5072    (clobber (reg:CC CC_REGNUM))]
5073   "TARGET_CPU_ZARCH"
5074   "#"
5075   "&& reload_completed"
5076   [(set (match_dup 0) (const_int 0))
5077    (parallel
5078     [(set (match_dup 0) (plus:GPR (plus:GPR (match_dup 1) (match_dup 0))
5079                                   (match_dup 0)))
5080      (clobber (reg:CC CC_REGNUM))])]
5081   "")
5082
5083 (define_insn_and_split "*scond<mode>_neg"
5084   [(set (match_operand:GPR 0 "register_operand" "=&d")
5085         (match_operand:GPR 1 "s390_slb_comparison" ""))
5086    (clobber (reg:CC CC_REGNUM))]
5087   "TARGET_CPU_ZARCH"
5088   "#"
5089   "&& reload_completed"
5090   [(set (match_dup 0) (const_int 0))
5091    (parallel
5092     [(set (match_dup 0) (minus:GPR (minus:GPR (match_dup 0) (match_dup 0))
5093                                    (match_dup 1)))
5094      (clobber (reg:CC CC_REGNUM))])
5095    (parallel
5096     [(set (match_dup 0) (neg:GPR (match_dup 0)))
5097      (clobber (reg:CC CC_REGNUM))])]
5098   "")
5099
5100
5101 (define_expand "s<code>"
5102   [(set (match_operand:SI 0 "register_operand" "")
5103         (SCOND (match_dup 0)
5104                (match_dup 0)))]
5105   "TARGET_CPU_ZARCH"
5106   "if (!s390_expand_addcc (<CODE>, s390_compare_op0, s390_compare_op1,
5107                            operands[0], const0_rtx, const1_rtx)) FAIL; DONE;")
5108
5109 (define_expand "seq"
5110   [(parallel
5111     [(set (match_operand:SI 0 "register_operand" "=d")
5112           (match_dup 1))
5113      (clobber (reg:CC CC_REGNUM))])
5114    (parallel
5115     [(set (match_dup 0) (xor:SI (match_dup 0) (const_int 1)))
5116      (clobber (reg:CC CC_REGNUM))])]
5117   ""
5118 {
5119   if (!s390_compare_emitted || GET_MODE (s390_compare_emitted) != CCZ1mode)
5120     FAIL;
5121   operands[1] = s390_emit_compare (NE, s390_compare_op0, s390_compare_op1);
5122   PUT_MODE (operands[1], SImode);
5123 })
5124
5125 (define_insn_and_split "*sne"
5126   [(set (match_operand:SI 0 "register_operand" "=d")
5127         (ne:SI (match_operand:CCZ1 1 "register_operand" "0")
5128                (const_int 0)))
5129    (clobber (reg:CC CC_REGNUM))]
5130   ""
5131   "#"
5132   "reload_completed"
5133   [(parallel
5134     [(set (match_dup 0) (ashiftrt:SI (match_dup 0) (const_int 28)))
5135      (clobber (reg:CC CC_REGNUM))])])
5136
5137
5138 ;;
5139 ;;- Multiply instructions.
5140 ;;
5141
5142 ;
5143 ; muldi3 instruction pattern(s).
5144 ;
5145
5146 (define_insn "*muldi3_sign"
5147   [(set (match_operand:DI 0 "register_operand" "=d,d")
5148         (mult:DI (sign_extend:DI (match_operand:SI 2 "general_operand" "d,RT"))
5149                  (match_operand:DI 1 "register_operand" "0,0")))]
5150   "TARGET_64BIT"
5151   "@
5152    msgfr\t%0,%2
5153    msgf\t%0,%2"
5154   [(set_attr "op_type"      "RRE,RXY")
5155    (set_attr "type"         "imuldi")])
5156
5157 (define_insn "muldi3"
5158   [(set (match_operand:DI 0 "register_operand" "=d,d,d,d")
5159         (mult:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,0")
5160                  (match_operand:DI 2 "general_operand" "d,K,RT,Os")))]
5161   "TARGET_64BIT"
5162   "@
5163    msgr\t%0,%2
5164    mghi\t%0,%h2
5165    msg\t%0,%2
5166    msgfi\t%0,%2"
5167   [(set_attr "op_type"      "RRE,RI,RXY,RIL")
5168    (set_attr "type"         "imuldi")
5169    (set_attr "cpu_facility" "*,*,*,z10")])
5170
5171 ;
5172 ; mulsi3 instruction pattern(s).
5173 ;
5174
5175 (define_insn "*mulsi3_sign"
5176   [(set (match_operand:SI 0 "register_operand" "=d,d")
5177         (mult:SI (sign_extend:SI (match_operand:HI 2 "memory_operand" "R,T"))
5178                  (match_operand:SI 1 "register_operand" "0,0")))]
5179   ""
5180   "@
5181    mh\t%0,%2
5182    mhy\t%0,%2"
5183   [(set_attr "op_type"      "RX,RXY")
5184    (set_attr "type"         "imulhi")
5185    (set_attr "cpu_facility" "*,z10")])
5186
5187 (define_insn "mulsi3"
5188   [(set (match_operand:SI 0 "register_operand" "=d,d,d,d,d")
5189         (mult:SI  (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0")
5190                   (match_operand:SI 2 "general_operand" "d,K,R,T,Os")))]
5191   ""
5192   "@
5193    msr\t%0,%2
5194    mhi\t%0,%h2
5195    ms\t%0,%2
5196    msy\t%0,%2
5197    msfi\t%0,%2"
5198   [(set_attr "op_type"      "RRE,RI,RX,RXY,RIL")
5199    (set_attr "type"         "imulsi,imulhi,imulsi,imulsi,imulsi")
5200    (set_attr "cpu_facility" "*,*,*,*,z10")])
5201
5202 ;
5203 ; mulsidi3 instruction pattern(s).
5204 ;
5205
5206 (define_insn "mulsidi3"
5207   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5208         (mult:DI (sign_extend:DI
5209                    (match_operand:SI 1 "register_operand" "%0,0,0"))
5210                  (sign_extend:DI
5211                    (match_operand:SI 2 "nonimmediate_operand" "d,R,T"))))]
5212   "!TARGET_64BIT"
5213   "@
5214    mr\t%0,%2
5215    m\t%0,%2
5216    mfy\t%0,%2"
5217   [(set_attr "op_type"      "RR,RX,RXY")
5218    (set_attr "type"         "imulsi")
5219    (set_attr "cpu_facility" "*,*,z10")])
5220
5221 ;
5222 ; umulsidi3 instruction pattern(s).
5223 ;
5224
5225 (define_insn "umulsidi3"
5226   [(set (match_operand:DI 0 "register_operand" "=d,d")
5227         (mult:DI (zero_extend:DI
5228                    (match_operand:SI 1 "register_operand" "%0,0"))
5229                  (zero_extend:DI
5230                    (match_operand:SI 2 "nonimmediate_operand" "d,RT"))))]
5231   "!TARGET_64BIT && TARGET_CPU_ZARCH"
5232   "@
5233    mlr\t%0,%2
5234    ml\t%0,%2"
5235   [(set_attr "op_type"  "RRE,RXY")
5236    (set_attr "type"     "imulsi")])
5237
5238 ;
5239 ; mul(tf|df|sf|td|dd)3 instruction pattern(s).
5240 ;
5241
5242 ; mxbr, mdbr, meebr, mxb, mxb, meeb, mdtr, mxtr
5243 (define_insn "mul<mode>3"
5244   [(set (match_operand:FP 0 "register_operand"              "=f,f")
5245         (mult:FP (match_operand:FP 1 "nonimmediate_operand" "%<f0>,0")
5246                  (match_operand:FP 2 "general_operand"      "f,<Rf>")))]
5247   "TARGET_HARD_FLOAT"
5248   "@
5249    m<xdee><bt>r\t%0,<op1>%2
5250    m<xdee>b\t%0,%2"
5251   [(set_attr "op_type"  "<RRer>,RXE")
5252    (set_attr "type"     "fmul<mode>")])
5253
5254 ; madbr, maebr, maxb, madb, maeb
5255 (define_insn "*fmadd<mode>"
5256   [(set (match_operand:DSF 0 "register_operand" "=f,f")
5257         (plus:DSF (mult:DSF (match_operand:DSF 1 "register_operand" "%f,f")
5258                             (match_operand:DSF 2 "nonimmediate_operand"  "f,R"))
5259                  (match_operand:DSF 3 "register_operand" "0,0")))]
5260   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
5261   "@
5262    ma<xde>br\t%0,%1,%2
5263    ma<xde>b\t%0,%1,%2"
5264   [(set_attr "op_type"  "RRE,RXE")
5265    (set_attr "type"     "fmul<mode>")])
5266
5267 ; msxbr, msdbr, msebr, msxb, msdb, mseb
5268 (define_insn "*fmsub<mode>"
5269   [(set (match_operand:DSF 0 "register_operand" "=f,f")
5270         (minus:DSF (mult:DSF (match_operand:DSF 1 "register_operand" "f,f")
5271                              (match_operand:DSF 2 "nonimmediate_operand"  "f,R"))
5272                  (match_operand:DSF 3 "register_operand" "0,0")))]
5273   "TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
5274   "@
5275    ms<xde>br\t%0,%1,%2
5276    ms<xde>b\t%0,%1,%2"
5277   [(set_attr "op_type"  "RRE,RXE")
5278    (set_attr "type"     "fmul<mode>")])
5279
5280 ;;
5281 ;;- Divide and modulo instructions.
5282 ;;
5283
5284 ;
5285 ; divmoddi4 instruction pattern(s).
5286 ;
5287
5288 (define_expand "divmoddi4"
5289   [(parallel [(set (match_operand:DI 0 "general_operand" "")
5290                    (div:DI (match_operand:DI 1 "register_operand" "")
5291                            (match_operand:DI 2 "general_operand" "")))
5292               (set (match_operand:DI 3 "general_operand" "")
5293                    (mod:DI (match_dup 1) (match_dup 2)))])
5294    (clobber (match_dup 4))]
5295   "TARGET_64BIT"
5296 {
5297   rtx insn, div_equal, mod_equal;
5298
5299   div_equal = gen_rtx_DIV (DImode, operands[1], operands[2]);
5300   mod_equal = gen_rtx_MOD (DImode, operands[1], operands[2]);
5301
5302   operands[4] = gen_reg_rtx(TImode);
5303   emit_insn (gen_divmodtidi3 (operands[4], operands[1], operands[2]));
5304
5305   insn = emit_move_insn (operands[0], gen_lowpart (DImode, operands[4]));
5306   set_unique_reg_note (insn, REG_EQUAL, div_equal);
5307
5308   insn = emit_move_insn (operands[3], gen_highpart (DImode, operands[4]));
5309   set_unique_reg_note (insn, REG_EQUAL, mod_equal);
5310
5311   DONE;
5312 })
5313
5314 (define_insn "divmodtidi3"
5315   [(set (match_operand:TI 0 "register_operand" "=d,d")
5316         (ior:TI
5317           (ashift:TI
5318             (zero_extend:TI
5319               (mod:DI (match_operand:DI 1 "register_operand" "0,0")
5320                       (match_operand:DI 2 "general_operand" "d,RT")))
5321             (const_int 64))
5322           (zero_extend:TI (div:DI (match_dup 1) (match_dup 2)))))]
5323   "TARGET_64BIT"
5324   "@
5325    dsgr\t%0,%2
5326    dsg\t%0,%2"
5327   [(set_attr "op_type"  "RRE,RXY")
5328    (set_attr "type"     "idiv")])
5329
5330 (define_insn "divmodtisi3"
5331   [(set (match_operand:TI 0 "register_operand" "=d,d")
5332         (ior:TI
5333           (ashift:TI
5334             (zero_extend:TI
5335               (mod:DI (match_operand:DI 1 "register_operand" "0,0")
5336                       (sign_extend:DI
5337                         (match_operand:SI 2 "nonimmediate_operand" "d,RT"))))
5338             (const_int 64))
5339           (zero_extend:TI
5340             (div:DI (match_dup 1) (sign_extend:DI (match_dup 2))))))]
5341   "TARGET_64BIT"
5342   "@
5343    dsgfr\t%0,%2
5344    dsgf\t%0,%2"
5345   [(set_attr "op_type"  "RRE,RXY")
5346    (set_attr "type"     "idiv")])
5347
5348 ;
5349 ; udivmoddi4 instruction pattern(s).
5350 ;
5351
5352 (define_expand "udivmoddi4"
5353   [(parallel [(set (match_operand:DI 0 "general_operand" "")
5354                    (udiv:DI (match_operand:DI 1 "general_operand" "")
5355                             (match_operand:DI 2 "nonimmediate_operand" "")))
5356               (set (match_operand:DI 3 "general_operand" "")
5357                    (umod:DI (match_dup 1) (match_dup 2)))])
5358    (clobber (match_dup 4))]
5359   "TARGET_64BIT"
5360 {
5361   rtx insn, div_equal, mod_equal, equal;
5362
5363   div_equal = gen_rtx_UDIV (DImode, operands[1], operands[2]);
5364   mod_equal = gen_rtx_UMOD (DImode, operands[1], operands[2]);
5365   equal = gen_rtx_IOR (TImode,
5366                        gen_rtx_ASHIFT (TImode,
5367                                        gen_rtx_ZERO_EXTEND (TImode, mod_equal),
5368                                        GEN_INT (64)),
5369                        gen_rtx_ZERO_EXTEND (TImode, div_equal));
5370
5371   operands[4] = gen_reg_rtx(TImode);
5372   emit_clobber (operands[4]);
5373   emit_move_insn (gen_lowpart (DImode, operands[4]), operands[1]);
5374   emit_move_insn (gen_highpart (DImode, operands[4]), const0_rtx);
5375
5376   insn = emit_insn (gen_udivmodtidi3 (operands[4], operands[4], operands[2]));
5377   set_unique_reg_note (insn, REG_EQUAL, equal);
5378
5379   insn = emit_move_insn (operands[0], gen_lowpart (DImode, operands[4]));
5380   set_unique_reg_note (insn, REG_EQUAL, div_equal);
5381
5382   insn = emit_move_insn (operands[3], gen_highpart (DImode, operands[4]));
5383   set_unique_reg_note (insn, REG_EQUAL, mod_equal);
5384
5385   DONE;
5386 })
5387
5388 (define_insn "udivmodtidi3"
5389   [(set (match_operand:TI 0 "register_operand" "=d,d")
5390         (ior:TI
5391           (ashift:TI
5392             (zero_extend:TI
5393               (truncate:DI
5394                 (umod:TI (match_operand:TI 1 "register_operand" "0,0")
5395                          (zero_extend:TI
5396                            (match_operand:DI 2 "nonimmediate_operand" "d,RT")))))
5397             (const_int 64))
5398           (zero_extend:TI
5399             (truncate:DI
5400               (udiv:TI (match_dup 1) (zero_extend:TI (match_dup 2)))))))]
5401   "TARGET_64BIT"
5402   "@
5403    dlgr\t%0,%2
5404    dlg\t%0,%2"
5405   [(set_attr "op_type"  "RRE,RXY")
5406    (set_attr "type"     "idiv")])
5407
5408 ;
5409 ; divmodsi4 instruction pattern(s).
5410 ;
5411
5412 (define_expand "divmodsi4"
5413   [(parallel [(set (match_operand:SI 0 "general_operand" "")
5414                    (div:SI (match_operand:SI 1 "general_operand" "")
5415                            (match_operand:SI 2 "nonimmediate_operand" "")))
5416               (set (match_operand:SI 3 "general_operand" "")
5417                    (mod:SI (match_dup 1) (match_dup 2)))])
5418    (clobber (match_dup 4))]
5419   "!TARGET_64BIT"
5420 {
5421   rtx insn, div_equal, mod_equal, equal;
5422
5423   div_equal = gen_rtx_DIV (SImode, operands[1], operands[2]);
5424   mod_equal = gen_rtx_MOD (SImode, operands[1], operands[2]);
5425   equal = gen_rtx_IOR (DImode,
5426                        gen_rtx_ASHIFT (DImode,
5427                                        gen_rtx_ZERO_EXTEND (DImode, mod_equal),
5428                                        GEN_INT (32)),
5429                        gen_rtx_ZERO_EXTEND (DImode, div_equal));
5430
5431   operands[4] = gen_reg_rtx(DImode);
5432   emit_insn (gen_extendsidi2 (operands[4], operands[1]));
5433
5434   insn = emit_insn (gen_divmoddisi3 (operands[4], operands[4], operands[2]));
5435   set_unique_reg_note (insn, REG_EQUAL, equal);
5436
5437   insn = emit_move_insn (operands[0], gen_lowpart (SImode, operands[4]));
5438   set_unique_reg_note (insn, REG_EQUAL, div_equal);
5439
5440   insn = emit_move_insn (operands[3], gen_highpart (SImode, operands[4]));
5441   set_unique_reg_note (insn, REG_EQUAL, mod_equal);
5442
5443   DONE;
5444 })
5445
5446 (define_insn "divmoddisi3"
5447   [(set (match_operand:DI 0 "register_operand" "=d,d")
5448         (ior:DI
5449           (ashift:DI
5450             (zero_extend:DI
5451               (truncate:SI
5452                 (mod:DI (match_operand:DI 1 "register_operand" "0,0")
5453                         (sign_extend:DI
5454                           (match_operand:SI 2 "nonimmediate_operand" "d,R")))))
5455             (const_int 32))
5456           (zero_extend:DI
5457             (truncate:SI
5458               (div:DI (match_dup 1) (sign_extend:DI (match_dup 2)))))))]
5459   "!TARGET_64BIT"
5460   "@
5461    dr\t%0,%2
5462    d\t%0,%2"
5463   [(set_attr "op_type"  "RR,RX")
5464    (set_attr "type"     "idiv")])
5465
5466 ;
5467 ; udivsi3 and umodsi3 instruction pattern(s).
5468 ;
5469
5470 (define_expand "udivmodsi4"
5471   [(parallel [(set (match_operand:SI 0 "general_operand" "")
5472                    (udiv:SI (match_operand:SI 1 "general_operand" "")
5473                             (match_operand:SI 2 "nonimmediate_operand" "")))
5474               (set (match_operand:SI 3 "general_operand" "")
5475                    (umod:SI (match_dup 1) (match_dup 2)))])
5476    (clobber (match_dup 4))]
5477   "!TARGET_64BIT && TARGET_CPU_ZARCH"
5478 {
5479   rtx insn, div_equal, mod_equal, equal;
5480
5481   div_equal = gen_rtx_UDIV (SImode, operands[1], operands[2]);
5482   mod_equal = gen_rtx_UMOD (SImode, operands[1], operands[2]);
5483   equal = gen_rtx_IOR (DImode,
5484                        gen_rtx_ASHIFT (DImode,
5485                                        gen_rtx_ZERO_EXTEND (DImode, mod_equal),
5486                                        GEN_INT (32)),
5487                        gen_rtx_ZERO_EXTEND (DImode, div_equal));
5488
5489   operands[4] = gen_reg_rtx(DImode);
5490   emit_clobber (operands[4]);
5491   emit_move_insn (gen_lowpart (SImode, operands[4]), operands[1]);
5492   emit_move_insn (gen_highpart (SImode, operands[4]), const0_rtx);
5493
5494   insn = emit_insn (gen_udivmoddisi3 (operands[4], operands[4], operands[2]));
5495   set_unique_reg_note (insn, REG_EQUAL, equal);
5496
5497   insn = emit_move_insn (operands[0], gen_lowpart (SImode, operands[4]));
5498   set_unique_reg_note (insn, REG_EQUAL, div_equal);
5499
5500   insn = emit_move_insn (operands[3], gen_highpart (SImode, operands[4]));
5501   set_unique_reg_note (insn, REG_EQUAL, mod_equal);
5502
5503   DONE;
5504 })
5505
5506 (define_insn "udivmoddisi3"
5507   [(set (match_operand:DI 0 "register_operand" "=d,d")
5508         (ior:DI
5509           (ashift:DI
5510             (zero_extend:DI
5511               (truncate:SI
5512                 (umod:DI (match_operand:DI 1 "register_operand" "0,0")
5513                          (zero_extend:DI
5514                            (match_operand:SI 2 "nonimmediate_operand" "d,RT")))))
5515             (const_int 32))
5516           (zero_extend:DI
5517             (truncate:SI
5518               (udiv:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))))]
5519   "!TARGET_64BIT && TARGET_CPU_ZARCH"
5520   "@
5521    dlr\t%0,%2
5522    dl\t%0,%2"
5523   [(set_attr "op_type"  "RRE,RXY")
5524    (set_attr "type"     "idiv")])
5525
5526 (define_expand "udivsi3"
5527   [(set (match_operand:SI 0 "register_operand" "=d")
5528         (udiv:SI (match_operand:SI 1 "general_operand" "")
5529                  (match_operand:SI 2 "general_operand" "")))
5530    (clobber (match_dup 3))]
5531   "!TARGET_64BIT && !TARGET_CPU_ZARCH"
5532 {
5533   rtx insn, udiv_equal, umod_equal, equal;
5534
5535   udiv_equal = gen_rtx_UDIV (SImode, operands[1], operands[2]);
5536   umod_equal = gen_rtx_UMOD (SImode, operands[1], operands[2]);
5537   equal = gen_rtx_IOR (DImode,
5538                        gen_rtx_ASHIFT (DImode,
5539                                        gen_rtx_ZERO_EXTEND (DImode, umod_equal),
5540                                        GEN_INT (32)),
5541                        gen_rtx_ZERO_EXTEND (DImode, udiv_equal));
5542
5543   operands[3] = gen_reg_rtx (DImode);
5544
5545   if (CONSTANT_P (operands[2]))
5546     {
5547       if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
5548         {
5549           rtx label1 = gen_label_rtx ();
5550
5551           operands[1] = make_safe_from (operands[1], operands[0]);
5552           emit_move_insn (operands[0], const0_rtx);
5553           emit_insn (gen_cmpsi (operands[1], operands[2]));
5554           emit_jump_insn (gen_bltu (label1));
5555           emit_move_insn (operands[0], const1_rtx);
5556           emit_label (label1);
5557         }
5558       else
5559         {
5560           operands[2] = force_reg (SImode, operands[2]);
5561           operands[2] = make_safe_from (operands[2], operands[0]);
5562
5563           emit_insn (gen_zero_extendsidi2 (operands[3], operands[1]));
5564           insn = emit_insn (gen_divmoddisi3 (operands[3], operands[3],
5565                                              operands[2]));
5566           set_unique_reg_note (insn, REG_EQUAL, equal);
5567
5568           insn = emit_move_insn (operands[0],
5569                                  gen_lowpart (SImode, operands[3]));
5570           set_unique_reg_note (insn, REG_EQUAL, udiv_equal);
5571         }
5572     }
5573   else
5574     {
5575       rtx label1 = gen_label_rtx ();
5576       rtx label2 = gen_label_rtx ();
5577       rtx label3 = gen_label_rtx ();
5578
5579       operands[1] = force_reg (SImode, operands[1]);
5580       operands[1] = make_safe_from (operands[1], operands[0]);
5581       operands[2] = force_reg (SImode, operands[2]);
5582       operands[2] = make_safe_from (operands[2], operands[0]);
5583
5584       emit_move_insn (operands[0], const0_rtx);
5585       emit_insn (gen_cmpsi (operands[2], operands[1]));
5586       emit_jump_insn (gen_bgtu (label3));
5587       emit_insn (gen_cmpsi (operands[2], const0_rtx));
5588       emit_jump_insn (gen_blt (label2));
5589       emit_insn (gen_cmpsi (operands[2], const1_rtx));
5590       emit_jump_insn (gen_beq (label1));
5591       emit_insn (gen_zero_extendsidi2 (operands[3], operands[1]));
5592       insn = emit_insn (gen_divmoddisi3 (operands[3], operands[3],
5593                                          operands[2]));
5594       set_unique_reg_note (insn, REG_EQUAL, equal);
5595
5596       insn = emit_move_insn (operands[0],
5597                              gen_lowpart (SImode, operands[3]));
5598       set_unique_reg_note (insn, REG_EQUAL, udiv_equal);
5599
5600       emit_jump (label3);
5601       emit_label (label1);
5602       emit_move_insn (operands[0], operands[1]);
5603       emit_jump (label3);
5604       emit_label (label2);
5605       emit_move_insn (operands[0], const1_rtx);
5606       emit_label (label3);
5607     }
5608   emit_move_insn (operands[0], operands[0]);
5609   DONE;
5610 })
5611
5612 (define_expand "umodsi3"
5613   [(set (match_operand:SI 0 "register_operand" "=d")
5614         (umod:SI (match_operand:SI 1 "nonimmediate_operand" "")
5615                  (match_operand:SI 2 "nonimmediate_operand" "")))
5616    (clobber (match_dup 3))]
5617   "!TARGET_64BIT && !TARGET_CPU_ZARCH"
5618 {
5619   rtx insn, udiv_equal, umod_equal, equal;
5620
5621   udiv_equal = gen_rtx_UDIV (SImode, operands[1], operands[2]);
5622   umod_equal = gen_rtx_UMOD (SImode, operands[1], operands[2]);
5623   equal = gen_rtx_IOR (DImode,
5624                        gen_rtx_ASHIFT (DImode,
5625                                        gen_rtx_ZERO_EXTEND (DImode, umod_equal),
5626                                        GEN_INT (32)),
5627                        gen_rtx_ZERO_EXTEND (DImode, udiv_equal));
5628
5629   operands[3] = gen_reg_rtx (DImode);
5630
5631   if (CONSTANT_P (operands[2]))
5632     {
5633       if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) <= 0)
5634         {
5635           rtx label1 = gen_label_rtx ();
5636
5637           operands[1] = make_safe_from (operands[1], operands[0]);
5638           emit_move_insn (operands[0], operands[1]);
5639           emit_insn (gen_cmpsi (operands[0], operands[2]));
5640           emit_jump_insn (gen_bltu (label1));
5641           emit_insn (gen_abssi2 (operands[0], operands[2]));
5642           emit_insn (gen_addsi3 (operands[0], operands[0], operands[1]));
5643           emit_label (label1);
5644         }
5645       else
5646         {
5647           operands[2] = force_reg (SImode, operands[2]);
5648           operands[2] = make_safe_from (operands[2], operands[0]);
5649
5650           emit_insn (gen_zero_extendsidi2 (operands[3], operands[1]));
5651           insn = emit_insn (gen_divmoddisi3 (operands[3], operands[3],
5652                                              operands[2]));
5653           set_unique_reg_note (insn, REG_EQUAL, equal);
5654
5655           insn = emit_move_insn (operands[0],
5656                                  gen_highpart (SImode, operands[3]));
5657           set_unique_reg_note (insn, REG_EQUAL, umod_equal);
5658         }
5659     }
5660   else
5661     {
5662       rtx label1 = gen_label_rtx ();
5663       rtx label2 = gen_label_rtx ();
5664       rtx label3 = gen_label_rtx ();
5665
5666       operands[1] = force_reg (SImode, operands[1]);
5667       operands[1] = make_safe_from (operands[1], operands[0]);
5668       operands[2] = force_reg (SImode, operands[2]);
5669       operands[2] = make_safe_from (operands[2], operands[0]);
5670
5671       emit_move_insn(operands[0], operands[1]);
5672       emit_insn (gen_cmpsi (operands[2], operands[1]));
5673       emit_jump_insn (gen_bgtu (label3));
5674       emit_insn (gen_cmpsi (operands[2], const0_rtx));
5675       emit_jump_insn (gen_blt (label2));
5676       emit_insn (gen_cmpsi (operands[2], const1_rtx));
5677       emit_jump_insn (gen_beq (label1));
5678       emit_insn (gen_zero_extendsidi2 (operands[3], operands[1]));
5679       insn = emit_insn (gen_divmoddisi3 (operands[3], operands[3],
5680                                          operands[2]));
5681       set_unique_reg_note (insn, REG_EQUAL, equal);
5682
5683       insn = emit_move_insn (operands[0],
5684                              gen_highpart (SImode, operands[3]));
5685       set_unique_reg_note (insn, REG_EQUAL, umod_equal);
5686
5687       emit_jump (label3);
5688       emit_label (label1);
5689       emit_move_insn (operands[0], const0_rtx);
5690       emit_jump (label3);
5691       emit_label (label2);
5692       emit_insn (gen_subsi3 (operands[0], operands[0], operands[2]));
5693       emit_label (label3);
5694     }
5695   DONE;
5696 })
5697
5698 ;
5699 ; div(df|sf)3 instruction pattern(s).
5700 ;
5701
5702 ; dxbr, ddbr, debr, dxb, ddb, deb, ddtr, dxtr
5703 (define_insn "div<mode>3"
5704   [(set (match_operand:FP 0 "register_operand"          "=f,f")
5705         (div:FP (match_operand:FP 1 "register_operand" "<f0>,0")
5706                  (match_operand:FP 2 "general_operand"  "f,<Rf>")))]
5707   "TARGET_HARD_FLOAT"
5708   "@
5709    d<xde><bt>r\t%0,<op1>%2
5710    d<xde>b\t%0,%2"
5711   [(set_attr "op_type"  "<RRer>,RXE")
5712    (set_attr "type"     "fdiv<mode>")])
5713
5714
5715 ;;
5716 ;;- And instructions.
5717 ;;
5718
5719 (define_expand "and<mode>3"
5720   [(set (match_operand:INT 0 "nonimmediate_operand" "")
5721         (and:INT (match_operand:INT 1 "nonimmediate_operand" "")
5722                  (match_operand:INT 2 "general_operand" "")))
5723    (clobber (reg:CC CC_REGNUM))]
5724   ""
5725   "s390_expand_logical_operator (AND, <MODE>mode, operands); DONE;")
5726
5727 ;
5728 ; anddi3 instruction pattern(s).
5729 ;
5730
5731 (define_insn "*anddi3_cc"
5732   [(set (reg CC_REGNUM)
5733         (compare (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
5734                          (match_operand:DI 2 "general_operand" "d,RT"))
5735                  (const_int 0)))
5736    (set (match_operand:DI 0 "register_operand" "=d,d")
5737         (and:DI (match_dup 1) (match_dup 2)))]
5738   "s390_match_ccmode(insn, CCTmode) && TARGET_64BIT"
5739   "@
5740    ngr\t%0,%2
5741    ng\t%0,%2"
5742   [(set_attr "op_type"  "RRE,RXY")
5743    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
5744
5745 (define_insn "*anddi3_cconly"
5746   [(set (reg CC_REGNUM)
5747         (compare (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
5748                          (match_operand:DI 2 "general_operand" "d,RT"))
5749                  (const_int 0)))
5750    (clobber (match_scratch:DI 0 "=d,d"))]
5751   "s390_match_ccmode(insn, CCTmode) && TARGET_64BIT
5752    /* Do not steal TM patterns.  */
5753    && s390_single_part (operands[2], DImode, HImode, 0) < 0"
5754   "@
5755    ngr\t%0,%2
5756    ng\t%0,%2"
5757   [(set_attr "op_type"  "RRE,RXY")
5758    (set_attr "z10prop" "z10_super_E1, z10_super_E1")])
5759
5760 (define_insn "*anddi3"
5761   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,d,d,d,AQ,Q")
5762         (and:DI (match_operand:DI 1 "nonimmediate_operand"
5763                                     "%d,o,0,0,0,0,0,0,0,0,0,0")
5764                 (match_operand:DI 2 "general_operand"
5765                                     "M,M,N0HDF,N1HDF,N2HDF,N3HDF,N0SDF,N1SDF,d,RT,NxQDF,Q")))
5766    (clobber (reg:CC CC_REGNUM))]
5767   "TARGET_64BIT && s390_logical_operator_ok_p (operands)"
5768   "@
5769    #
5770    #
5771    nihh\t%0,%j2
5772    nihl\t%0,%j2
5773    nilh\t%0,%j2
5774    nill\t%0,%j2
5775    nihf\t%0,%m2
5776    nilf\t%0,%m2
5777    ngr\t%0,%2
5778    ng\t%0,%2
5779    #
5780    #"
5781   [(set_attr "op_type" "RRE,RXE,RI,RI,RI,RI,RIL,RIL,RRE,RXY,SI,SS")
5782    (set_attr "cpu_facility" "*,*,*,*,*,*,extimm,extimm,*,*,*,*")
5783    (set_attr "z10prop" "*,
5784                         *,
5785                         z10_super_E1,
5786                         z10_super_E1,
5787                         z10_super_E1,
5788                         z10_super_E1,
5789                         z10_super_E1,
5790                         z10_super_E1,
5791                         z10_super_E1,
5792                         z10_super_E1,
5793                         *,
5794                         *")])
5795
5796 (define_split
5797   [(set (match_operand:DI 0 "s_operand" "")
5798         (and:DI (match_dup 0) (match_operand:DI 1 "immediate_operand" "")))
5799    (clobber (reg:CC CC_REGNUM))]
5800   "reload_completed"
5801   [(parallel
5802     [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
5803      (clobber (reg:CC CC_REGNUM))])]
5804   "s390_narrow_logical_operator (AND, &operands[0], &operands[1]);")
5805
5806
5807 ;
5808 ; andsi3 instruction pattern(s).
5809 ;
5810
5811 (define_insn "*andsi3_cc"
5812   [(set (reg CC_REGNUM)
5813         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
5814                          (match_operand:SI 2 "general_operand" "Os,d,R,T"))
5815                  (const_int 0)))
5816    (set (match_operand:SI 0 "register_operand" "=d,d,d,d")
5817         (and:SI (match_dup 1) (match_dup 2)))]
5818   "s390_match_ccmode(insn, CCTmode)"
5819   "@
5820    nilf\t%0,%o2
5821    nr\t%0,%2
5822    n\t%0,%2
5823    ny\t%0,%2"
5824   [(set_attr "op_type"  "RIL,RR,RX,RXY")
5825    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
5826
5827 (define_insn "*andsi3_cconly"
5828   [(set (reg CC_REGNUM)
5829         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
5830                          (match_operand:SI 2 "general_operand" "Os,d,R,T"))
5831                  (const_int 0)))
5832    (clobber (match_scratch:SI 0 "=d,d,d,d"))]
5833   "s390_match_ccmode(insn, CCTmode)
5834    /* Do not steal TM patterns.  */
5835    && s390_single_part (operands[2], SImode, HImode, 0) < 0"
5836   "@
5837    nilf\t%0,%o2
5838    nr\t%0,%2
5839    n\t%0,%2
5840    ny\t%0,%2"
5841   [(set_attr "op_type"  "RIL,RR,RX,RXY")
5842    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
5843
5844 (define_insn "*andsi3_zarch"
5845   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,d,AQ,Q")
5846         (and:SI (match_operand:SI 1 "nonimmediate_operand"
5847                                     "%d,o,0,0,0,0,0,0,0,0")
5848                 (match_operand:SI 2 "general_operand"
5849                                     "M,M,N0HSF,N1HSF,Os,d,R,T,NxQSF,Q")))
5850    (clobber (reg:CC CC_REGNUM))]
5851   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
5852   "@
5853    #
5854    #
5855    nilh\t%0,%j2
5856    nill\t%0,%j2
5857    nilf\t%0,%o2
5858    nr\t%0,%2
5859    n\t%0,%2
5860    ny\t%0,%2
5861    #
5862    #"
5863   [(set_attr "op_type"  "RRE,RXE,RI,RI,RIL,RR,RX,RXY,SI,SS")
5864    (set_attr "z10prop" "*,
5865                         *,
5866                         z10_super_E1,
5867                         z10_super_E1,
5868                         z10_super_E1,
5869                         z10_super_E1,
5870                         z10_super_E1,
5871                         z10_super_E1,
5872                         *,
5873                         *")])
5874
5875 (define_insn "*andsi3_esa"
5876   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,AQ,Q")
5877         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
5878                 (match_operand:SI 2 "general_operand" "d,R,NxQSF,Q")))
5879    (clobber (reg:CC CC_REGNUM))]
5880   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
5881   "@
5882    nr\t%0,%2
5883    n\t%0,%2
5884    #
5885    #"
5886   [(set_attr "op_type"  "RR,RX,SI,SS")
5887    (set_attr "z10prop" "z10_super_E1,z10_super_E1,*,*")])
5888
5889
5890 (define_split
5891   [(set (match_operand:SI 0 "s_operand" "")
5892         (and:SI (match_dup 0) (match_operand:SI 1 "immediate_operand" "")))
5893    (clobber (reg:CC CC_REGNUM))]
5894   "reload_completed"
5895   [(parallel
5896     [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
5897      (clobber (reg:CC CC_REGNUM))])]
5898   "s390_narrow_logical_operator (AND, &operands[0], &operands[1]);")
5899
5900 ;
5901 ; andhi3 instruction pattern(s).
5902 ;
5903
5904 (define_insn "*andhi3_zarch"
5905   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,AQ,Q")
5906         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0,0")
5907                 (match_operand:HI 2 "general_operand" "d,n,NxQHF,Q")))
5908    (clobber (reg:CC CC_REGNUM))]
5909   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
5910   "@
5911    nr\t%0,%2
5912    nill\t%0,%x2
5913    #
5914    #"
5915   [(set_attr "op_type"  "RR,RI,SI,SS")
5916    (set_attr "z10prop" "z10_super_E1,z10_super_E1,*,*")
5917 ])
5918
5919 (define_insn "*andhi3_esa"
5920   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,AQ,Q")
5921         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
5922                 (match_operand:HI 2 "general_operand" "d,NxQHF,Q")))
5923    (clobber (reg:CC CC_REGNUM))]
5924   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
5925   "@
5926    nr\t%0,%2
5927    #
5928    #"
5929   [(set_attr "op_type"  "RR,SI,SS")
5930    (set_attr "z10prop" "z10_super_E1,*,*")
5931 ])
5932
5933 (define_split
5934   [(set (match_operand:HI 0 "s_operand" "")
5935         (and:HI (match_dup 0) (match_operand:HI 1 "immediate_operand" "")))
5936    (clobber (reg:CC CC_REGNUM))]
5937   "reload_completed"
5938   [(parallel
5939     [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
5940      (clobber (reg:CC CC_REGNUM))])]
5941   "s390_narrow_logical_operator (AND, &operands[0], &operands[1]);")
5942
5943 ;
5944 ; andqi3 instruction pattern(s).
5945 ;
5946
5947 (define_insn "*andqi3_zarch"
5948   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,Q,S,Q")
5949         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,0,0")
5950                 (match_operand:QI 2 "general_operand" "d,n,n,n,Q")))
5951    (clobber (reg:CC CC_REGNUM))]
5952   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
5953   "@
5954    nr\t%0,%2
5955    nill\t%0,%b2
5956    ni\t%S0,%b2
5957    niy\t%S0,%b2
5958    #"
5959   [(set_attr "op_type"  "RR,RI,SI,SIY,SS")
5960    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super,z10_super,*")])
5961
5962 (define_insn "*andqi3_esa"
5963   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,Q,Q")
5964         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
5965                 (match_operand:QI 2 "general_operand" "d,n,Q")))
5966    (clobber (reg:CC CC_REGNUM))]
5967   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
5968   "@
5969    nr\t%0,%2
5970    ni\t%S0,%b2
5971    #"
5972   [(set_attr "op_type"  "RR,SI,SS")
5973    (set_attr "z10prop" "z10_super_E1,z10_super,*")])
5974
5975 ;
5976 ; Block and (NC) patterns.
5977 ;
5978
5979 (define_insn "*nc"
5980   [(set (match_operand:BLK 0 "memory_operand" "=Q")
5981         (and:BLK (match_dup 0)
5982                  (match_operand:BLK 1 "memory_operand" "Q")))
5983    (use (match_operand 2 "const_int_operand" "n"))
5984    (clobber (reg:CC CC_REGNUM))]
5985   "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 256"
5986   "nc\t%O0(%2,%R0),%S1"
5987   [(set_attr "op_type" "SS")])
5988
5989 (define_split
5990   [(set (match_operand 0 "memory_operand" "")
5991         (and (match_dup 0)
5992              (match_operand 1 "memory_operand" "")))
5993    (clobber (reg:CC CC_REGNUM))]
5994   "reload_completed
5995    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5996    && GET_MODE_SIZE (GET_MODE (operands[0])) > 0"
5997   [(parallel
5998     [(set (match_dup 0) (and:BLK (match_dup 0) (match_dup 1)))
5999      (use (match_dup 2))
6000      (clobber (reg:CC CC_REGNUM))])]
6001 {
6002   operands[2] = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[0])));
6003   operands[0] = adjust_address (operands[0], BLKmode, 0);
6004   operands[1] = adjust_address (operands[1], BLKmode, 0);
6005 })
6006
6007 (define_peephole2
6008   [(parallel
6009     [(set (match_operand:BLK 0 "memory_operand" "")
6010           (and:BLK (match_dup 0)
6011                    (match_operand:BLK 1 "memory_operand" "")))
6012      (use (match_operand 2 "const_int_operand" ""))
6013      (clobber (reg:CC CC_REGNUM))])
6014    (parallel
6015     [(set (match_operand:BLK 3 "memory_operand" "")
6016           (and:BLK (match_dup 3)
6017                    (match_operand:BLK 4 "memory_operand" "")))
6018      (use (match_operand 5 "const_int_operand" ""))
6019      (clobber (reg:CC CC_REGNUM))])]
6020   "s390_offset_p (operands[0], operands[3], operands[2])
6021    && s390_offset_p (operands[1], operands[4], operands[2])
6022    && !s390_overlap_p (operands[0], operands[1],
6023                        INTVAL (operands[2]) + INTVAL (operands[5]))
6024    && INTVAL (operands[2]) + INTVAL (operands[5]) <= 256"
6025   [(parallel
6026     [(set (match_dup 6) (and:BLK (match_dup 6) (match_dup 7)))
6027      (use (match_dup 8))
6028      (clobber (reg:CC CC_REGNUM))])]
6029   "operands[6] = gen_rtx_MEM (BLKmode, XEXP (operands[0], 0));
6030    operands[7] = gen_rtx_MEM (BLKmode, XEXP (operands[1], 0));
6031    operands[8] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[5]));")
6032
6033
6034 ;;
6035 ;;- Bit set (inclusive or) instructions.
6036 ;;
6037
6038 (define_expand "ior<mode>3"
6039   [(set (match_operand:INT 0 "nonimmediate_operand" "")
6040         (ior:INT (match_operand:INT 1 "nonimmediate_operand" "")
6041                  (match_operand:INT 2 "general_operand" "")))
6042    (clobber (reg:CC CC_REGNUM))]
6043   ""
6044   "s390_expand_logical_operator (IOR, <MODE>mode, operands); DONE;")
6045
6046 ;
6047 ; iordi3 instruction pattern(s).
6048 ;
6049
6050 (define_insn "*iordi3_cc"
6051   [(set (reg CC_REGNUM)
6052         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
6053                          (match_operand:DI 2 "general_operand" "d,RT"))
6054                  (const_int 0)))
6055    (set (match_operand:DI 0 "register_operand" "=d,d")
6056         (ior:DI (match_dup 1) (match_dup 2)))]
6057   "s390_match_ccmode(insn, CCTmode) && TARGET_64BIT"
6058   "@
6059    ogr\t%0,%2
6060    og\t%0,%2"
6061   [(set_attr "op_type"  "RRE,RXY")
6062    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
6063
6064 (define_insn "*iordi3_cconly"
6065   [(set (reg CC_REGNUM)
6066         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
6067                          (match_operand:DI 2 "general_operand" "d,RT"))
6068                  (const_int 0)))
6069    (clobber (match_scratch:DI 0 "=d,d"))]
6070   "s390_match_ccmode(insn, CCTmode) && TARGET_64BIT"
6071   "@
6072    ogr\t%0,%2
6073    og\t%0,%2"
6074   [(set_attr "op_type"  "RRE,RXY")
6075    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
6076
6077 (define_insn "*iordi3"
6078   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,d,AQ,Q")
6079         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,0,0,0,0,0,0,0")
6080                 (match_operand:DI 2 "general_operand"
6081                                     "N0HD0,N1HD0,N2HD0,N3HD0,N0SD0,N1SD0,d,RT,NxQD0,Q")))
6082    (clobber (reg:CC CC_REGNUM))]
6083   "TARGET_64BIT && s390_logical_operator_ok_p (operands)"
6084   "@
6085    oihh\t%0,%i2
6086    oihl\t%0,%i2
6087    oilh\t%0,%i2
6088    oill\t%0,%i2
6089    oihf\t%0,%k2
6090    oilf\t%0,%k2
6091    ogr\t%0,%2
6092    og\t%0,%2
6093    #
6094    #"
6095   [(set_attr "op_type"  "RI,RI,RI,RI,RIL,RIL,RRE,RXY,SI,SS")
6096    (set_attr "cpu_facility" "*,*,*,*,extimm,extimm,*,*,*,*")
6097    (set_attr "z10prop" "z10_super_E1,
6098                         z10_super_E1,
6099                         z10_super_E1,
6100                         z10_super_E1,
6101                         z10_super_E1,
6102                         z10_super_E1,
6103                         z10_super_E1,
6104                         z10_super_E1,
6105                         *,
6106                         *")])
6107
6108 (define_split
6109   [(set (match_operand:DI 0 "s_operand" "")
6110         (ior:DI (match_dup 0) (match_operand:DI 1 "immediate_operand" "")))
6111    (clobber (reg:CC CC_REGNUM))]
6112   "reload_completed"
6113   [(parallel
6114     [(set (match_dup 0) (ior:QI (match_dup 0) (match_dup 1)))
6115      (clobber (reg:CC CC_REGNUM))])]
6116   "s390_narrow_logical_operator (IOR, &operands[0], &operands[1]);")
6117
6118 ;
6119 ; iorsi3 instruction pattern(s).
6120 ;
6121
6122 (define_insn "*iorsi3_cc"
6123   [(set (reg CC_REGNUM)
6124         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
6125                          (match_operand:SI 2 "general_operand" "Os,d,R,T"))
6126                  (const_int 0)))
6127    (set (match_operand:SI 0 "register_operand" "=d,d,d,d")
6128         (ior:SI (match_dup 1) (match_dup 2)))]
6129   "s390_match_ccmode(insn, CCTmode)"
6130   "@
6131    oilf\t%0,%o2
6132    or\t%0,%2
6133    o\t%0,%2
6134    oy\t%0,%2"
6135   [(set_attr "op_type"  "RIL,RR,RX,RXY")
6136    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
6137
6138 (define_insn "*iorsi3_cconly"
6139   [(set (reg CC_REGNUM)
6140         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
6141                          (match_operand:SI 2 "general_operand" "Os,d,R,T"))
6142                  (const_int 0)))
6143    (clobber (match_scratch:SI 0 "=d,d,d,d"))]
6144   "s390_match_ccmode(insn, CCTmode)"
6145   "@
6146    oilf\t%0,%o2
6147    or\t%0,%2
6148    o\t%0,%2
6149    oy\t%0,%2"
6150   [(set_attr "op_type"  "RIL,RR,RX,RXY")
6151    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
6152
6153 (define_insn "*iorsi3_zarch"
6154   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,d,d,AQ,Q")
6155         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0,0,0,0")
6156                 (match_operand:SI 2 "general_operand" "N0HS0,N1HS0,Os,d,R,T,NxQS0,Q")))
6157    (clobber (reg:CC CC_REGNUM))]
6158   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
6159   "@
6160    oilh\t%0,%i2
6161    oill\t%0,%i2
6162    oilf\t%0,%o2
6163    or\t%0,%2
6164    o\t%0,%2
6165    oy\t%0,%2
6166    #
6167    #"
6168   [(set_attr "op_type"  "RI,RI,RIL,RR,RX,RXY,SI,SS")
6169    (set_attr "z10prop" "z10_super_E1,
6170                         z10_super_E1,
6171                         z10_super_E1,
6172                         z10_super_E1,
6173                         z10_super_E1,
6174                         z10_super_E1,
6175                         *,
6176                         *")])
6177
6178 (define_insn "*iorsi3_esa"
6179   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,AQ,Q")
6180         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
6181                 (match_operand:SI 2 "general_operand" "d,R,NxQS0,Q")))
6182    (clobber (reg:CC CC_REGNUM))]
6183   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
6184   "@
6185    or\t%0,%2
6186    o\t%0,%2
6187    #
6188    #"
6189   [(set_attr "op_type"  "RR,RX,SI,SS")
6190    (set_attr "z10prop" "z10_super_E1,z10_super_E1,*,*")])
6191
6192 (define_split
6193   [(set (match_operand:SI 0 "s_operand" "")
6194         (ior:SI (match_dup 0) (match_operand:SI 1 "immediate_operand" "")))
6195    (clobber (reg:CC CC_REGNUM))]
6196   "reload_completed"
6197   [(parallel
6198     [(set (match_dup 0) (ior:QI (match_dup 0) (match_dup 1)))
6199      (clobber (reg:CC CC_REGNUM))])]
6200   "s390_narrow_logical_operator (IOR, &operands[0], &operands[1]);")
6201
6202 ;
6203 ; iorhi3 instruction pattern(s).
6204 ;
6205
6206 (define_insn "*iorhi3_zarch"
6207   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,AQ,Q")
6208         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0,0")
6209                 (match_operand:HI 2 "general_operand" "d,n,NxQH0,Q")))
6210    (clobber (reg:CC CC_REGNUM))]
6211   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
6212   "@
6213    or\t%0,%2
6214    oill\t%0,%x2
6215    #
6216    #"
6217   [(set_attr "op_type"  "RR,RI,SI,SS")
6218    (set_attr "z10prop" "z10_super_E1,z10_super_E1,*,*")])
6219
6220 (define_insn "*iorhi3_esa"
6221   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,AQ,Q")
6222         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
6223                 (match_operand:HI 2 "general_operand" "d,NxQH0,Q")))
6224    (clobber (reg:CC CC_REGNUM))]
6225   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
6226   "@
6227    or\t%0,%2
6228    #
6229    #"
6230   [(set_attr "op_type"  "RR,SI,SS")
6231    (set_attr "z10prop" "z10_super_E1,*,*")])
6232
6233 (define_split
6234   [(set (match_operand:HI 0 "s_operand" "")
6235         (ior:HI (match_dup 0) (match_operand:HI 1 "immediate_operand" "")))
6236    (clobber (reg:CC CC_REGNUM))]
6237   "reload_completed"
6238   [(parallel
6239     [(set (match_dup 0) (ior:QI (match_dup 0) (match_dup 1)))
6240      (clobber (reg:CC CC_REGNUM))])]
6241   "s390_narrow_logical_operator (IOR, &operands[0], &operands[1]);")
6242
6243 ;
6244 ; iorqi3 instruction pattern(s).
6245 ;
6246
6247 (define_insn "*iorqi3_zarch"
6248   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,Q,S,Q")
6249         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,0,0")
6250                 (match_operand:QI 2 "general_operand" "d,n,n,n,Q")))
6251    (clobber (reg:CC CC_REGNUM))]
6252   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
6253   "@
6254    or\t%0,%2
6255    oill\t%0,%b2
6256    oi\t%S0,%b2
6257    oiy\t%S0,%b2
6258    #"
6259   [(set_attr "op_type"  "RR,RI,SI,SIY,SS")
6260    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super,z10_super,*")])
6261
6262 (define_insn "*iorqi3_esa"
6263   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,Q,Q")
6264         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
6265                 (match_operand:QI 2 "general_operand" "d,n,Q")))
6266    (clobber (reg:CC CC_REGNUM))]
6267   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
6268   "@
6269    or\t%0,%2
6270    oi\t%S0,%b2
6271    #"
6272   [(set_attr "op_type"  "RR,SI,SS")
6273    (set_attr "z10prop" "z10_super_E1,z10_super,*")])
6274
6275 ;
6276 ; Block inclusive or (OC) patterns.
6277 ;
6278
6279 (define_insn "*oc"
6280   [(set (match_operand:BLK 0 "memory_operand" "=Q")
6281         (ior:BLK (match_dup 0)
6282                  (match_operand:BLK 1 "memory_operand" "Q")))
6283    (use (match_operand 2 "const_int_operand" "n"))
6284    (clobber (reg:CC CC_REGNUM))]
6285   "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 256"
6286   "oc\t%O0(%2,%R0),%S1"
6287   [(set_attr "op_type" "SS")])
6288
6289 (define_split
6290   [(set (match_operand 0 "memory_operand" "")
6291         (ior (match_dup 0)
6292              (match_operand 1 "memory_operand" "")))
6293    (clobber (reg:CC CC_REGNUM))]
6294   "reload_completed
6295    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6296    && GET_MODE_SIZE (GET_MODE (operands[0])) > 0"
6297   [(parallel
6298     [(set (match_dup 0) (ior:BLK (match_dup 0) (match_dup 1)))
6299      (use (match_dup 2))
6300      (clobber (reg:CC CC_REGNUM))])]
6301 {
6302   operands[2] = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[0])));
6303   operands[0] = adjust_address (operands[0], BLKmode, 0);
6304   operands[1] = adjust_address (operands[1], BLKmode, 0);
6305 })
6306
6307 (define_peephole2
6308   [(parallel
6309     [(set (match_operand:BLK 0 "memory_operand" "")
6310           (ior:BLK (match_dup 0)
6311                    (match_operand:BLK 1 "memory_operand" "")))
6312      (use (match_operand 2 "const_int_operand" ""))
6313      (clobber (reg:CC CC_REGNUM))])
6314    (parallel
6315     [(set (match_operand:BLK 3 "memory_operand" "")
6316           (ior:BLK (match_dup 3)
6317                    (match_operand:BLK 4 "memory_operand" "")))
6318      (use (match_operand 5 "const_int_operand" ""))
6319      (clobber (reg:CC CC_REGNUM))])]
6320   "s390_offset_p (operands[0], operands[3], operands[2])
6321    && s390_offset_p (operands[1], operands[4], operands[2])
6322    && !s390_overlap_p (operands[0], operands[1],
6323                        INTVAL (operands[2]) + INTVAL (operands[5]))
6324    && INTVAL (operands[2]) + INTVAL (operands[5]) <= 256"
6325   [(parallel
6326     [(set (match_dup 6) (ior:BLK (match_dup 6) (match_dup 7)))
6327      (use (match_dup 8))
6328      (clobber (reg:CC CC_REGNUM))])]
6329   "operands[6] = gen_rtx_MEM (BLKmode, XEXP (operands[0], 0));
6330    operands[7] = gen_rtx_MEM (BLKmode, XEXP (operands[1], 0));
6331    operands[8] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[5]));")
6332
6333
6334 ;;
6335 ;;- Xor instructions.
6336 ;;
6337
6338 (define_expand "xor<mode>3"
6339   [(set (match_operand:INT 0 "nonimmediate_operand" "")
6340         (xor:INT (match_operand:INT 1 "nonimmediate_operand" "")
6341                  (match_operand:INT 2 "general_operand" "")))
6342    (clobber (reg:CC CC_REGNUM))]
6343   ""
6344   "s390_expand_logical_operator (XOR, <MODE>mode, operands); DONE;")
6345
6346 ;
6347 ; xordi3 instruction pattern(s).
6348 ;
6349
6350 (define_insn "*xordi3_cc"
6351   [(set (reg CC_REGNUM)
6352         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
6353                          (match_operand:DI 2 "general_operand" "d,RT"))
6354                  (const_int 0)))
6355    (set (match_operand:DI 0 "register_operand" "=d,d")
6356         (xor:DI (match_dup 1) (match_dup 2)))]
6357   "s390_match_ccmode(insn, CCTmode) && TARGET_64BIT"
6358   "@
6359    xgr\t%0,%2
6360    xg\t%0,%2"
6361   [(set_attr "op_type"  "RRE,RXY")
6362    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
6363
6364 (define_insn "*xordi3_cconly"
6365   [(set (reg CC_REGNUM)
6366         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
6367                          (match_operand:DI 2 "general_operand" "d,RT"))
6368                  (const_int 0)))
6369    (clobber (match_scratch:DI 0 "=d,d"))]
6370   "s390_match_ccmode(insn, CCTmode) && TARGET_64BIT"
6371   "@
6372    xgr\t%0,%2
6373    xg\t%0,%2"
6374   [(set_attr "op_type"  "RRE,RXY")
6375    (set_attr "z10prop" "z10_super_E1,z10_super_E1")])
6376
6377 (define_insn "*xordi3"
6378   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,AQ,Q")
6379         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,0,0,0")
6380                 (match_operand:DI 2 "general_operand" "N0SD0,N1SD0,d,RT,NxQD0,Q")))
6381    (clobber (reg:CC CC_REGNUM))]
6382   "TARGET_64BIT && s390_logical_operator_ok_p (operands)"
6383   "@
6384    xihf\t%0,%k2
6385    xilf\t%0,%k2
6386    xgr\t%0,%2
6387    xg\t%0,%2
6388    #
6389    #"
6390   [(set_attr "op_type"  "RIL,RIL,RRE,RXY,SI,SS")
6391    (set_attr "cpu_facility" "extimm,extimm,*,*,*,*")
6392    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1,*,*")])
6393
6394 (define_split
6395   [(set (match_operand:DI 0 "s_operand" "")
6396         (xor:DI (match_dup 0) (match_operand:DI 1 "immediate_operand" "")))
6397    (clobber (reg:CC CC_REGNUM))]
6398   "reload_completed"
6399   [(parallel
6400     [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
6401      (clobber (reg:CC CC_REGNUM))])]
6402   "s390_narrow_logical_operator (XOR, &operands[0], &operands[1]);")
6403
6404 ;
6405 ; xorsi3 instruction pattern(s).
6406 ;
6407
6408 (define_insn "*xorsi3_cc"
6409   [(set (reg CC_REGNUM)
6410         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
6411                          (match_operand:SI 2 "general_operand" "Os,d,R,T"))
6412                  (const_int 0)))
6413    (set (match_operand:SI 0 "register_operand" "=d,d,d,d")
6414         (xor:SI (match_dup 1) (match_dup 2)))]
6415   "s390_match_ccmode(insn, CCTmode)"
6416   "@
6417    xilf\t%0,%o2
6418    xr\t%0,%2
6419    x\t%0,%2
6420    xy\t%0,%2"
6421   [(set_attr "op_type"  "RIL,RR,RX,RXY")
6422    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
6423
6424 (define_insn "*xorsi3_cconly"
6425   [(set (reg CC_REGNUM)
6426         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
6427                          (match_operand:SI 2 "general_operand" "Os,d,R,T"))
6428                  (const_int 0)))
6429    (clobber (match_scratch:SI 0 "=d,d,d,d"))]
6430   "s390_match_ccmode(insn, CCTmode)"
6431   "@
6432    xilf\t%0,%o2
6433    xr\t%0,%2
6434    x\t%0,%2
6435    xy\t%0,%2"
6436   [(set_attr "op_type"  "RIL,RR,RX,RXY")
6437    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1")])
6438
6439 (define_insn "*xorsi3"
6440   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,AQ,Q")
6441         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0,0")
6442                 (match_operand:SI 2 "general_operand" "Os,d,R,T,NxQS0,Q")))
6443    (clobber (reg:CC CC_REGNUM))]
6444   "s390_logical_operator_ok_p (operands)"
6445   "@
6446    xilf\t%0,%o2
6447    xr\t%0,%2
6448    x\t%0,%2
6449    xy\t%0,%2
6450    #
6451    #"
6452   [(set_attr "op_type"  "RIL,RR,RX,RXY,SI,SS")
6453    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super_E1,z10_super_E1,*,*")])
6454
6455 (define_split
6456   [(set (match_operand:SI 0 "s_operand" "")
6457         (xor:SI (match_dup 0) (match_operand:SI 1 "immediate_operand" "")))
6458    (clobber (reg:CC CC_REGNUM))]
6459   "reload_completed"
6460   [(parallel
6461     [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
6462      (clobber (reg:CC CC_REGNUM))])]
6463   "s390_narrow_logical_operator (XOR, &operands[0], &operands[1]);")
6464
6465 ;
6466 ; xorhi3 instruction pattern(s).
6467 ;
6468
6469 (define_insn "*xorhi3"
6470   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,AQ,Q")
6471         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0,0")
6472                 (match_operand:HI 2 "general_operand" "Os,d,NxQH0,Q")))
6473    (clobber (reg:CC CC_REGNUM))]
6474   "s390_logical_operator_ok_p (operands)"
6475   "@
6476    xilf\t%0,%x2
6477    xr\t%0,%2
6478    #
6479    #"
6480   [(set_attr "op_type"  "RIL,RR,SI,SS")
6481    (set_attr "z10prop" "z10_super_E1,z10_super_E1,*,*")])
6482
6483 (define_split
6484   [(set (match_operand:HI 0 "s_operand" "")
6485         (xor:HI (match_dup 0) (match_operand:HI 1 "immediate_operand" "")))
6486    (clobber (reg:CC CC_REGNUM))]
6487   "reload_completed"
6488   [(parallel
6489     [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
6490      (clobber (reg:CC CC_REGNUM))])]
6491   "s390_narrow_logical_operator (XOR, &operands[0], &operands[1]);")
6492
6493 ;
6494 ; xorqi3 instruction pattern(s).
6495 ;
6496
6497 (define_insn "*xorqi3"
6498   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,Q,S,Q")
6499         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,0,0")
6500                 (match_operand:QI 2 "general_operand" "Os,d,n,n,Q")))
6501    (clobber (reg:CC CC_REGNUM))]
6502   "s390_logical_operator_ok_p (operands)"
6503   "@
6504    xilf\t%0,%b2
6505    xr\t%0,%2
6506    xi\t%S0,%b2
6507    xiy\t%S0,%b2
6508    #"
6509   [(set_attr "op_type"  "RIL,RR,SI,SIY,SS")
6510    (set_attr "z10prop" "z10_super_E1,z10_super_E1,z10_super,z10_super,*")])
6511
6512
6513 ;
6514 ; Block exclusive or (XC) patterns.
6515 ;
6516
6517 (define_insn "*xc"
6518   [(set (match_operand:BLK 0 "memory_operand" "=Q")
6519         (xor:BLK (match_dup 0)
6520                  (match_operand:BLK 1 "memory_operand" "Q")))
6521    (use (match_operand 2 "const_int_operand" "n"))
6522    (clobber (reg:CC CC_REGNUM))]
6523   "INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 256"
6524   "xc\t%O0(%2,%R0),%S1"
6525   [(set_attr "op_type" "SS")])
6526
6527 (define_split
6528   [(set (match_operand 0 "memory_operand" "")
6529         (xor (match_dup 0)
6530              (match_operand 1 "memory_operand" "")))
6531    (clobber (reg:CC CC_REGNUM))]
6532   "reload_completed
6533    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6534    && GET_MODE_SIZE (GET_MODE (operands[0])) > 0"
6535   [(parallel
6536     [(set (match_dup 0) (xor:BLK (match_dup 0) (match_dup 1)))
6537      (use (match_dup 2))
6538      (clobber (reg:CC CC_REGNUM))])]
6539 {
6540   operands[2] = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[0])));
6541   operands[0] = adjust_address (operands[0], BLKmode, 0);
6542   operands[1] = adjust_address (operands[1], BLKmode, 0);
6543 })
6544
6545 (define_peephole2
6546   [(parallel
6547     [(set (match_operand:BLK 0 "memory_operand" "")
6548           (xor:BLK (match_dup 0)
6549                    (match_operand:BLK 1 "memory_operand" "")))
6550      (use (match_operand 2 "const_int_operand" ""))
6551      (clobber (reg:CC CC_REGNUM))])
6552    (parallel
6553     [(set (match_operand:BLK 3 "memory_operand" "")
6554           (xor:BLK (match_dup 3)
6555                    (match_operand:BLK 4 "memory_operand" "")))
6556      (use (match_operand 5 "const_int_operand" ""))
6557      (clobber (reg:CC CC_REGNUM))])]
6558   "s390_offset_p (operands[0], operands[3], operands[2])
6559    && s390_offset_p (operands[1], operands[4], operands[2])
6560    && !s390_overlap_p (operands[0], operands[1],
6561                        INTVAL (operands[2]) + INTVAL (operands[5]))
6562    && INTVAL (operands[2]) + INTVAL (operands[5]) <= 256"
6563   [(parallel
6564     [(set (match_dup 6) (xor:BLK (match_dup 6) (match_dup 7)))
6565      (use (match_dup 8))
6566      (clobber (reg:CC CC_REGNUM))])]
6567   "operands[6] = gen_rtx_MEM (BLKmode, XEXP (operands[0], 0));
6568    operands[7] = gen_rtx_MEM (BLKmode, XEXP (operands[1], 0));
6569    operands[8] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[5]));")
6570
6571 ;
6572 ; Block xor (XC) patterns with src == dest.
6573 ;
6574
6575 (define_insn "*xc_zero"
6576   [(set (match_operand:BLK 0 "memory_operand" "=Q")
6577         (const_int 0))
6578    (use (match_operand 1 "const_int_operand" "n"))
6579    (clobber (reg:CC CC_REGNUM))]
6580   "INTVAL (operands[1]) >= 1 && INTVAL (operands[1]) <= 256"
6581   "xc\t%O0(%1,%R0),%S0"
6582   [(set_attr "op_type" "SS")])
6583
6584 (define_peephole2
6585   [(parallel
6586     [(set (match_operand:BLK 0 "memory_operand" "")
6587           (const_int 0))
6588      (use (match_operand 1 "const_int_operand" ""))
6589      (clobber (reg:CC CC_REGNUM))])
6590    (parallel
6591     [(set (match_operand:BLK 2 "memory_operand" "")
6592           (const_int 0))
6593      (use (match_operand 3 "const_int_operand" ""))
6594      (clobber (reg:CC CC_REGNUM))])]
6595   "s390_offset_p (operands[0], operands[2], operands[1])
6596    && INTVAL (operands[1]) + INTVAL (operands[3]) <= 256"
6597   [(parallel
6598     [(set (match_dup 4) (const_int 0))
6599      (use (match_dup 5))
6600      (clobber (reg:CC CC_REGNUM))])]
6601   "operands[4] = gen_rtx_MEM (BLKmode, XEXP (operands[0], 0));
6602    operands[5] = GEN_INT (INTVAL (operands[1]) + INTVAL (operands[3]));")
6603
6604
6605 ;;
6606 ;;- Negate instructions.
6607 ;;
6608
6609 ;
6610 ; neg(di|si)2 instruction pattern(s).
6611 ;
6612
6613 (define_expand "neg<mode>2"
6614   [(parallel
6615     [(set (match_operand:DSI 0 "register_operand" "=d")
6616           (neg:DSI (match_operand:DSI 1 "register_operand" "d")))
6617      (clobber (reg:CC CC_REGNUM))])]
6618   ""
6619   "")
6620
6621 (define_insn "*negdi2_sign_cc"
6622   [(set (reg CC_REGNUM)
6623         (compare (neg:DI (ashiftrt:DI (ashift:DI (subreg:DI
6624                            (match_operand:SI 1 "register_operand" "d") 0)
6625                            (const_int 32)) (const_int 32)))
6626                  (const_int 0)))
6627    (set (match_operand:DI 0 "register_operand" "=d")
6628         (neg:DI (sign_extend:DI (match_dup 1))))]
6629   "TARGET_64BIT && s390_match_ccmode (insn, CCAmode)"
6630   "lcgfr\t%0,%1"
6631   [(set_attr "op_type"  "RRE")])
6632
6633 (define_insn "*negdi2_sign"
6634   [(set (match_operand:DI 0 "register_operand" "=d")
6635         (neg:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))))
6636    (clobber (reg:CC CC_REGNUM))]
6637   "TARGET_64BIT"
6638   "lcgfr\t%0,%1"
6639   [(set_attr "op_type"  "RRE")])
6640
6641 ; lcr, lcgr
6642 (define_insn "*neg<mode>2_cc"
6643   [(set (reg CC_REGNUM)
6644         (compare (neg:GPR (match_operand:GPR 1 "register_operand" "d"))
6645                  (const_int 0)))
6646    (set (match_operand:GPR 0 "register_operand" "=d")
6647         (neg:GPR (match_dup 1)))]
6648   "s390_match_ccmode (insn, CCAmode)"
6649   "lc<g>r\t%0,%1"
6650   [(set_attr "op_type"  "RR<E>")
6651    (set_attr "z10prop" "z10_super_c_E1")])
6652
6653 ; lcr, lcgr
6654 (define_insn "*neg<mode>2_cconly"
6655   [(set (reg CC_REGNUM)
6656         (compare (neg:GPR (match_operand:GPR 1 "register_operand" "d"))
6657                  (const_int 0)))
6658    (clobber (match_scratch:GPR 0 "=d"))]
6659   "s390_match_ccmode (insn, CCAmode)"
6660   "lc<g>r\t%0,%1"
6661   [(set_attr "op_type"  "RR<E>")
6662    (set_attr "z10prop" "z10_super_c_E1")])
6663
6664 ; lcr, lcgr
6665 (define_insn "*neg<mode>2"
6666   [(set (match_operand:GPR 0 "register_operand" "=d")
6667         (neg:GPR (match_operand:GPR 1 "register_operand" "d")))
6668    (clobber (reg:CC CC_REGNUM))]
6669   ""
6670   "lc<g>r\t%0,%1"
6671   [(set_attr "op_type"  "RR<E>")
6672    (set_attr "z10prop" "z10_super_c_E1")])
6673
6674 (define_insn_and_split "*negdi2_31"
6675   [(set (match_operand:DI 0 "register_operand" "=d")
6676         (neg:DI (match_operand:DI 1 "register_operand" "d")))
6677    (clobber (reg:CC CC_REGNUM))]
6678   "!TARGET_64BIT"
6679   "#"
6680   "&& reload_completed"
6681   [(parallel
6682     [(set (match_dup 2) (neg:SI (match_dup 3)))
6683      (clobber (reg:CC CC_REGNUM))])
6684    (parallel
6685     [(set (reg:CCAP CC_REGNUM)
6686           (compare:CCAP (neg:SI (match_dup 5)) (const_int 0)))
6687      (set (match_dup 4) (neg:SI (match_dup 5)))])
6688    (set (pc)
6689         (if_then_else (ne (reg:CCAP CC_REGNUM) (const_int 0))
6690                       (pc)
6691                       (label_ref (match_dup 6))))
6692    (parallel
6693     [(set (match_dup 2) (plus:SI (match_dup 2) (const_int -1)))
6694      (clobber (reg:CC CC_REGNUM))])
6695    (match_dup 6)]
6696   "operands[2] = operand_subword (operands[0], 0, 0, DImode);
6697    operands[3] = operand_subword (operands[1], 0, 0, DImode);
6698    operands[4] = operand_subword (operands[0], 1, 0, DImode);
6699    operands[5] = operand_subword (operands[1], 1, 0, DImode);
6700    operands[6] = gen_label_rtx ();")
6701
6702 ;
6703 ; neg(df|sf)2 instruction pattern(s).
6704 ;
6705
6706 (define_expand "neg<mode>2"
6707   [(parallel
6708     [(set (match_operand:BFP 0 "register_operand" "=f")
6709           (neg:BFP (match_operand:BFP 1 "register_operand" "f")))
6710      (clobber (reg:CC CC_REGNUM))])]
6711   "TARGET_HARD_FLOAT"
6712   "")
6713
6714 ; lcxbr, lcdbr, lcebr
6715 (define_insn "*neg<mode>2_cc"
6716   [(set (reg CC_REGNUM)
6717         (compare (neg:BFP (match_operand:BFP 1 "register_operand" "f"))
6718                  (match_operand:BFP 2 "const0_operand" "")))
6719    (set (match_operand:BFP 0 "register_operand" "=f")
6720         (neg:BFP (match_dup 1)))]
6721   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
6722   "lc<xde>br\t%0,%1"
6723   [(set_attr "op_type"  "RRE")
6724    (set_attr "type"     "fsimp<mode>")])
6725
6726 ; lcxbr, lcdbr, lcebr
6727 (define_insn "*neg<mode>2_cconly"
6728   [(set (reg CC_REGNUM)
6729         (compare (neg:BFP (match_operand:BFP 1 "register_operand" "f"))
6730                  (match_operand:BFP 2 "const0_operand" "")))
6731    (clobber (match_scratch:BFP 0 "=f"))]
6732   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
6733   "lc<xde>br\t%0,%1"
6734   [(set_attr "op_type"  "RRE")
6735    (set_attr "type"     "fsimp<mode>")])
6736
6737 ; lcdfr
6738 (define_insn "*neg<mode>2_nocc"
6739   [(set (match_operand:FP 0 "register_operand"         "=f")
6740         (neg:FP (match_operand:FP 1 "register_operand" "<fT0>")))]
6741   "TARGET_DFP"
6742   "lcdfr\t%0,%1"
6743   [(set_attr "op_type"  "RRE")
6744    (set_attr "type"     "fsimp<mode>")])
6745
6746 ; lcxbr, lcdbr, lcebr
6747 (define_insn "*neg<mode>2"
6748   [(set (match_operand:BFP 0 "register_operand" "=f")
6749         (neg:BFP (match_operand:BFP 1 "register_operand" "f")))
6750    (clobber (reg:CC CC_REGNUM))]
6751   "TARGET_HARD_FLOAT"
6752   "lc<xde>br\t%0,%1"
6753   [(set_attr "op_type"  "RRE")
6754    (set_attr "type"     "fsimp<mode>")])
6755
6756
6757 ;;
6758 ;;- Absolute value instructions.
6759 ;;
6760
6761 ;
6762 ; abs(di|si)2 instruction pattern(s).
6763 ;
6764
6765 (define_insn "*absdi2_sign_cc"
6766   [(set (reg CC_REGNUM)
6767         (compare (abs:DI (ashiftrt:DI (ashift:DI (subreg:DI
6768                            (match_operand:SI 1 "register_operand" "d") 0)
6769                            (const_int 32)) (const_int 32)))
6770                  (const_int 0)))
6771    (set (match_operand:DI 0 "register_operand" "=d")
6772         (abs:DI (sign_extend:DI (match_dup 1))))]
6773   "TARGET_64BIT && s390_match_ccmode (insn, CCAmode)"
6774   "lpgfr\t%0,%1"
6775   [(set_attr "op_type"  "RRE")])
6776
6777 (define_insn "*absdi2_sign"
6778   [(set (match_operand:DI 0 "register_operand" "=d")
6779         (abs:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))))
6780    (clobber (reg:CC CC_REGNUM))]
6781   "TARGET_64BIT"
6782   "lpgfr\t%0,%1"
6783   [(set_attr "op_type"  "RRE")])
6784
6785 ; lpr, lpgr
6786 (define_insn "*abs<mode>2_cc"
6787   [(set (reg CC_REGNUM)
6788         (compare (abs:GPR (match_operand:DI 1 "register_operand" "d"))
6789                  (const_int 0)))
6790    (set (match_operand:GPR 0 "register_operand" "=d")
6791         (abs:GPR (match_dup 1)))]
6792   "s390_match_ccmode (insn, CCAmode)"
6793   "lp<g>r\t%0,%1"
6794   [(set_attr "op_type"  "RR<E>")
6795    (set_attr "z10prop" "z10_c")])
6796
6797 ; lpr, lpgr
6798 (define_insn "*abs<mode>2_cconly"
6799   [(set (reg CC_REGNUM)
6800         (compare (abs:GPR (match_operand:GPR 1 "register_operand" "d"))
6801                  (const_int 0)))
6802    (clobber (match_scratch:GPR 0 "=d"))]
6803   "s390_match_ccmode (insn, CCAmode)"
6804   "lp<g>r\t%0,%1"
6805   [(set_attr "op_type"  "RR<E>")
6806    (set_attr "z10prop" "z10_c")])
6807
6808 ; lpr, lpgr
6809 (define_insn "abs<mode>2"
6810   [(set (match_operand:GPR 0 "register_operand" "=d")
6811         (abs:GPR (match_operand:GPR 1 "register_operand" "d")))
6812    (clobber (reg:CC CC_REGNUM))]
6813   ""
6814   "lp<g>r\t%0,%1"
6815   [(set_attr "op_type"  "RR<E>")
6816    (set_attr "z10prop" "z10_c")])
6817
6818 ;
6819 ; abs(df|sf)2 instruction pattern(s).
6820 ;
6821
6822 (define_expand "abs<mode>2"
6823   [(parallel
6824     [(set (match_operand:BFP 0 "register_operand" "=f")
6825           (abs:BFP (match_operand:BFP 1 "register_operand" "f")))
6826      (clobber (reg:CC CC_REGNUM))])]
6827   "TARGET_HARD_FLOAT"
6828   "")
6829
6830 ; lpxbr, lpdbr, lpebr
6831 (define_insn "*abs<mode>2_cc"
6832   [(set (reg CC_REGNUM)
6833         (compare (abs:BFP (match_operand:BFP 1 "register_operand" "f"))
6834                  (match_operand:BFP 2 "const0_operand" "")))
6835    (set (match_operand:BFP 0 "register_operand" "=f")
6836         (abs:BFP (match_dup 1)))]
6837   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
6838   "lp<xde>br\t%0,%1"
6839   [(set_attr "op_type"  "RRE")
6840    (set_attr "type"     "fsimp<mode>")])
6841
6842 ; lpxbr, lpdbr, lpebr
6843 (define_insn "*abs<mode>2_cconly"
6844   [(set (reg CC_REGNUM)
6845         (compare (abs:BFP (match_operand:BFP 1 "register_operand" "f"))
6846                  (match_operand:BFP 2 "const0_operand" "")))
6847    (clobber (match_scratch:BFP 0 "=f"))]
6848   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
6849   "lp<xde>br\t%0,%1"
6850   [(set_attr "op_type"  "RRE")
6851    (set_attr "type"     "fsimp<mode>")])
6852
6853 ; lpdfr
6854 (define_insn "*abs<mode>2_nocc"
6855   [(set (match_operand:FP 0 "register_operand"         "=f")
6856         (abs:FP (match_operand:FP 1 "register_operand" "<fT0>")))]
6857   "TARGET_DFP"
6858   "lpdfr\t%0,%1"
6859   [(set_attr "op_type"  "RRE")
6860    (set_attr "type"     "fsimp<mode>")])
6861
6862 ; lpxbr, lpdbr, lpebr
6863 (define_insn "*abs<mode>2"
6864   [(set (match_operand:BFP 0 "register_operand" "=f")
6865         (abs:BFP (match_operand:BFP 1 "register_operand" "f")))
6866    (clobber (reg:CC CC_REGNUM))]
6867   "TARGET_HARD_FLOAT"
6868   "lp<xde>br\t%0,%1"
6869   [(set_attr "op_type"  "RRE")
6870    (set_attr "type"     "fsimp<mode>")])
6871
6872
6873 ;;
6874 ;;- Negated absolute value instructions
6875 ;;
6876
6877 ;
6878 ; Integer
6879 ;
6880
6881 (define_insn "*negabsdi2_sign_cc"
6882   [(set (reg CC_REGNUM)
6883         (compare (neg:DI (abs:DI (ashiftrt:DI (ashift:DI (subreg:DI
6884                            (match_operand:SI 1 "register_operand" "d") 0)
6885                            (const_int 32)) (const_int 32))))
6886                  (const_int 0)))
6887    (set (match_operand:DI 0 "register_operand" "=d")
6888         (neg:DI (abs:DI (sign_extend:DI (match_dup 1)))))]
6889   "TARGET_64BIT && s390_match_ccmode (insn, CCAmode)"
6890   "lngfr\t%0,%1"
6891   [(set_attr "op_type"  "RRE")])
6892
6893 (define_insn "*negabsdi2_sign"
6894   [(set (match_operand:DI 0 "register_operand" "=d")
6895         (neg:DI (abs:DI (sign_extend:DI
6896                           (match_operand:SI 1 "register_operand" "d")))))
6897    (clobber (reg:CC CC_REGNUM))]
6898   "TARGET_64BIT"
6899   "lngfr\t%0,%1"
6900   [(set_attr "op_type" "RRE")])
6901
6902 ; lnr, lngr
6903 (define_insn "*negabs<mode>2_cc"
6904   [(set (reg CC_REGNUM)
6905         (compare (neg:GPR (abs:GPR (match_operand:GPR 1 "register_operand" "d")))
6906                  (const_int 0)))
6907    (set (match_operand:GPR 0 "register_operand" "=d")
6908         (neg:GPR (abs:GPR (match_dup 1))))]
6909   "s390_match_ccmode (insn, CCAmode)"
6910   "ln<g>r\t%0,%1"
6911   [(set_attr "op_type"  "RR<E>")
6912    (set_attr "z10prop" "z10_c")])
6913
6914 ; lnr, lngr
6915 (define_insn "*negabs<mode>2_cconly"
6916   [(set (reg CC_REGNUM)
6917         (compare (neg:GPR (abs:GPR (match_operand:GPR 1 "register_operand" "d")))
6918                  (const_int 0)))
6919    (clobber (match_scratch:GPR 0 "=d"))]
6920   "s390_match_ccmode (insn, CCAmode)"
6921   "ln<g>r\t%0,%1"
6922   [(set_attr "op_type"  "RR<E>")
6923    (set_attr "z10prop" "z10_c")])
6924
6925 ; lnr, lngr
6926 (define_insn "*negabs<mode>2"
6927   [(set (match_operand:GPR 0 "register_operand" "=d")
6928         (neg:GPR (abs:GPR (match_operand:GPR 1 "register_operand" "d"))))
6929    (clobber (reg:CC CC_REGNUM))]
6930   ""
6931   "ln<g>r\t%0,%1"
6932   [(set_attr "op_type" "RR<E>")
6933    (set_attr "z10prop" "z10_c")])
6934
6935 ;
6936 ; Floating point
6937 ;
6938
6939 ; lnxbr, lndbr, lnebr
6940 (define_insn "*negabs<mode>2_cc"
6941   [(set (reg CC_REGNUM)
6942         (compare (neg:BFP (abs:BFP (match_operand:BFP 1 "register_operand" "f")))
6943                  (match_operand:BFP 2 "const0_operand" "")))
6944    (set (match_operand:BFP 0 "register_operand" "=f")
6945         (neg:BFP (abs:BFP (match_dup 1))))]
6946   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
6947   "ln<xde>br\t%0,%1"
6948   [(set_attr "op_type"  "RRE")
6949    (set_attr "type"     "fsimp<mode>")])
6950
6951 ; lnxbr, lndbr, lnebr
6952 (define_insn "*negabs<mode>2_cconly"
6953   [(set (reg CC_REGNUM)
6954         (compare (neg:BFP (abs:BFP (match_operand:BFP 1 "register_operand" "f")))
6955                  (match_operand:BFP 2 "const0_operand" "")))
6956    (clobber (match_scratch:BFP 0 "=f"))]
6957   "s390_match_ccmode (insn, CCSmode) && TARGET_HARD_FLOAT"
6958   "ln<xde>br\t%0,%1"
6959   [(set_attr "op_type"  "RRE")
6960    (set_attr "type"     "fsimp<mode>")])
6961
6962 ; lndfr
6963 (define_insn "*negabs<mode>2_nocc"
6964   [(set (match_operand:FP 0 "register_operand"                  "=f")
6965         (neg:FP (abs:FP (match_operand:BFP 1 "register_operand" "<fT0>"))))]
6966   "TARGET_DFP"
6967   "lndfr\t%0,%1"
6968   [(set_attr "op_type"  "RRE")
6969    (set_attr "type"     "fsimp<mode>")])
6970
6971 ; lnxbr, lndbr, lnebr
6972 (define_insn "*negabs<mode>2"
6973   [(set (match_operand:BFP 0 "register_operand" "=f")
6974         (neg:BFP (abs:BFP (match_operand:BFP 1 "register_operand" "f"))))
6975    (clobber (reg:CC CC_REGNUM))]
6976   "TARGET_HARD_FLOAT"
6977   "ln<xde>br\t%0,%1"
6978   [(set_attr "op_type"  "RRE")
6979    (set_attr "type"     "fsimp<mode>")])
6980
6981 ;;
6982 ;;- Copy sign instructions
6983 ;;
6984
6985 ; cpsdr
6986 (define_insn "copysign<mode>3"
6987   [(set (match_operand:FP 0 "register_operand" "=f")
6988         (unspec:FP [(match_operand:FP 1 "register_operand" "<fT0>")
6989                     (match_operand:FP 2 "register_operand" "f")]
6990                     UNSPEC_COPYSIGN))]
6991   "TARGET_DFP"
6992   "cpsdr\t%0,%2,%1"
6993   [(set_attr "op_type"  "RRF")
6994    (set_attr "type"     "fsimp<mode>")])
6995
6996 ;;
6997 ;;- Square root instructions.
6998 ;;
6999
7000 ;
7001 ; sqrt(df|sf)2 instruction pattern(s).
7002 ;
7003
7004 ; sqxbr, sqdbr, sqebr, sqdb, sqeb
7005 (define_insn "sqrt<mode>2"
7006   [(set (match_operand:BFP 0 "register_operand" "=f,f")
7007         (sqrt:BFP (match_operand:BFP 1 "general_operand" "f,<Rf>")))]
7008   "TARGET_HARD_FLOAT"
7009   "@
7010    sq<xde>br\t%0,%1
7011    sq<xde>b\t%0,%1"
7012   [(set_attr "op_type" "RRE,RXE")
7013    (set_attr "type" "fsqrt<mode>")])
7014
7015
7016 ;;
7017 ;;- One complement instructions.
7018 ;;
7019
7020 ;
7021 ; one_cmpl(di|si|hi|qi)2 instruction pattern(s).
7022 ;
7023
7024 (define_expand "one_cmpl<mode>2"
7025   [(parallel
7026     [(set (match_operand:INT 0 "register_operand" "")
7027           (xor:INT (match_operand:INT 1 "register_operand" "")
7028                    (const_int -1)))
7029      (clobber (reg:CC CC_REGNUM))])]
7030   ""
7031   "")
7032
7033
7034 ;;
7035 ;; Find leftmost bit instructions.
7036 ;;
7037
7038 (define_expand "clzdi2"
7039   [(set (match_operand:DI 0 "register_operand" "=d")
7040         (clz:DI (match_operand:DI 1 "register_operand" "d")))]
7041   "TARGET_EXTIMM && TARGET_64BIT"
7042 {
7043   rtx insn, clz_equal;
7044   rtx wide_reg = gen_reg_rtx (TImode);
7045   rtx msb = gen_rtx_CONST_INT (DImode, (unsigned HOST_WIDE_INT) 1 << 63);
7046
7047   clz_equal = gen_rtx_CLZ (DImode, operands[1]);
7048
7049   emit_insn (gen_clztidi2 (wide_reg, operands[1], msb));
7050
7051   insn = emit_move_insn (operands[0], gen_highpart (DImode, wide_reg));
7052   set_unique_reg_note (insn, REG_EQUAL, clz_equal);
7053
7054   DONE;
7055 })
7056
7057 (define_insn "clztidi2"
7058   [(set (match_operand:TI 0 "register_operand" "=d")
7059         (ior:TI
7060           (ashift:TI
7061             (zero_extend:TI
7062               (xor:DI (match_operand:DI 1 "register_operand" "d")
7063                       (lshiftrt (match_operand:DI 2 "const_int_operand" "")
7064                                 (subreg:SI (clz:DI (match_dup 1)) 4))))
7065
7066             (const_int 64))
7067           (zero_extend:TI (clz:DI (match_dup 1)))))
7068    (clobber (reg:CC CC_REGNUM))]
7069   "(unsigned HOST_WIDE_INT) INTVAL (operands[2])
7070    == (unsigned HOST_WIDE_INT) 1 << 63
7071    && TARGET_EXTIMM && TARGET_64BIT"
7072   "flogr\t%0,%1"
7073   [(set_attr "op_type"  "RRE")])
7074
7075
7076 ;;
7077 ;;- Rotate instructions.
7078 ;;
7079
7080 ;
7081 ; rotl(di|si)3 instruction pattern(s).
7082 ;
7083
7084 ; rll, rllg
7085 (define_insn "rotl<mode>3"
7086   [(set (match_operand:GPR 0 "register_operand" "=d")
7087         (rotate:GPR (match_operand:GPR 1 "register_operand" "d")
7088                     (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")))]
7089   "TARGET_CPU_ZARCH"
7090   "rll<g>\t%0,%1,%Y2"
7091   [(set_attr "op_type"  "RSE")
7092    (set_attr "atype"    "reg")
7093    (set_attr "z10prop" "z10_super_E1")])
7094
7095 ; rll, rllg
7096 (define_insn "*rotl<mode>3_and"
7097   [(set (match_operand:GPR 0 "register_operand" "=d")
7098         (rotate:GPR (match_operand:GPR 1 "register_operand" "d")
7099                     (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7100                             (match_operand:SI 3 "const_int_operand"   "n"))))]
7101   "TARGET_CPU_ZARCH && (INTVAL (operands[3]) & 63) == 63"
7102   "rll<g>\t%0,%1,%Y2"
7103   [(set_attr "op_type"  "RSE")
7104    (set_attr "atype"    "reg")
7105    (set_attr "z10prop" "z10_super_E1")])
7106
7107
7108 ;;
7109 ;;- Shift instructions.
7110 ;;
7111
7112 ;
7113 ; (ashl|lshr)(di|si)3 instruction pattern(s).
7114 ;
7115
7116 (define_expand "<shift><mode>3"
7117   [(set (match_operand:DSI 0 "register_operand" "")
7118         (SHIFT:DSI (match_operand:DSI 1 "register_operand" "")
7119                    (match_operand:SI 2 "shift_count_or_setmem_operand" "")))]
7120   ""
7121   "")
7122
7123 ; sldl, srdl
7124 (define_insn "*<shift>di3_31"
7125   [(set (match_operand:DI 0 "register_operand" "=d")
7126         (SHIFT:DI (match_operand:DI 1 "register_operand" "0")
7127                   (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")))]
7128   "!TARGET_64BIT"
7129   "s<lr>dl\t%0,%Y2"
7130   [(set_attr "op_type"  "RS")
7131    (set_attr "atype"    "reg")])
7132
7133 ; sll, srl, sllg, srlg
7134 (define_insn "*<shift><mode>3"
7135   [(set (match_operand:GPR 0 "register_operand" "=d")
7136         (SHIFT:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7137                    (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")))]
7138   ""
7139   "s<lr>l<g>\t%0,<1>%Y2"
7140   [(set_attr "op_type"  "RS<E>")
7141    (set_attr "atype"    "reg")
7142    (set_attr "z10prop" "z10_super_E1")])
7143
7144 ; sldl, srdl
7145 (define_insn "*<shift>di3_31_and"
7146   [(set (match_operand:DI 0 "register_operand" "=d")
7147         (SHIFT:DI (match_operand:DI 1 "register_operand" "0")
7148                   (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7149                           (match_operand:SI 3 "const_int_operand"   "n"))))]
7150   "!TARGET_64BIT && (INTVAL (operands[3]) & 63) == 63"
7151   "s<lr>dl\t%0,%Y2"
7152   [(set_attr "op_type"  "RS")
7153    (set_attr "atype"    "reg")])
7154
7155 ; sll, srl, sllg, srlg
7156 (define_insn "*<shift><mode>3_and"
7157   [(set (match_operand:GPR 0 "register_operand" "=d")
7158         (SHIFT:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7159                    (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7160                            (match_operand:SI 3 "const_int_operand"   "n"))))]
7161   "(INTVAL (operands[3]) & 63) == 63"
7162   "s<lr>l<g>\t%0,<1>%Y2"
7163   [(set_attr "op_type"  "RS<E>")
7164    (set_attr "atype"    "reg")
7165    (set_attr "z10prop" "z10_super_E1")])
7166
7167 ;
7168 ; ashr(di|si)3 instruction pattern(s).
7169 ;
7170
7171 (define_expand "ashr<mode>3"
7172   [(parallel
7173     [(set (match_operand:DSI 0 "register_operand" "")
7174           (ashiftrt:DSI (match_operand:DSI 1 "register_operand" "")
7175                         (match_operand:SI 2 "shift_count_or_setmem_operand" "")))
7176      (clobber (reg:CC CC_REGNUM))])]
7177   ""
7178   "")
7179
7180 (define_insn "*ashrdi3_cc_31"
7181   [(set (reg CC_REGNUM)
7182         (compare (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
7183                               (match_operand:SI 2 "shift_count_or_setmem_operand" "Y"))
7184                  (const_int 0)))
7185    (set (match_operand:DI 0 "register_operand" "=d")
7186         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7187   "!TARGET_64BIT && s390_match_ccmode(insn, CCSmode)"
7188   "srda\t%0,%Y2"
7189   [(set_attr "op_type"  "RS")
7190    (set_attr "atype"    "reg")])
7191
7192 (define_insn "*ashrdi3_cconly_31"
7193   [(set (reg CC_REGNUM)
7194         (compare (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
7195                               (match_operand:SI 2 "shift_count_or_setmem_operand" "Y"))
7196                  (const_int 0)))
7197    (clobber (match_scratch:DI 0 "=d"))]
7198   "!TARGET_64BIT && s390_match_ccmode(insn, CCSmode)"
7199   "srda\t%0,%Y2"
7200   [(set_attr "op_type"  "RS")
7201    (set_attr "atype"    "reg")])
7202
7203 (define_insn "*ashrdi3_31"
7204   [(set (match_operand:DI 0 "register_operand" "=d")
7205         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
7206                      (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")))
7207    (clobber (reg:CC CC_REGNUM))]
7208   "!TARGET_64BIT"
7209   "srda\t%0,%Y2"
7210   [(set_attr "op_type"  "RS")
7211    (set_attr "atype"    "reg")])
7212
7213 ; sra, srag
7214 (define_insn "*ashr<mode>3_cc"
7215   [(set (reg CC_REGNUM)
7216         (compare (ashiftrt:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7217                                (match_operand:SI 2 "shift_count_or_setmem_operand" "Y"))
7218                  (const_int 0)))
7219    (set (match_operand:GPR 0 "register_operand" "=d")
7220         (ashiftrt:GPR (match_dup 1) (match_dup 2)))]
7221   "s390_match_ccmode(insn, CCSmode)"
7222   "sra<g>\t%0,<1>%Y2"
7223   [(set_attr "op_type"  "RS<E>")
7224    (set_attr "atype"    "reg")
7225    (set_attr "z10prop" "z10_super_E1")])
7226
7227 ; sra, srag
7228 (define_insn "*ashr<mode>3_cconly"
7229   [(set (reg CC_REGNUM)
7230         (compare (ashiftrt:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7231                                (match_operand:SI 2 "shift_count_or_setmem_operand" "Y"))
7232                  (const_int 0)))
7233    (clobber (match_scratch:GPR 0 "=d"))]
7234   "s390_match_ccmode(insn, CCSmode)"
7235   "sra<g>\t%0,<1>%Y2"
7236   [(set_attr "op_type"  "RS<E>")
7237    (set_attr "atype"    "reg")
7238    (set_attr "z10prop" "z10_super_E1")])
7239
7240 ; sra, srag
7241 (define_insn "*ashr<mode>3"
7242   [(set (match_operand:GPR 0 "register_operand" "=d")
7243         (ashiftrt:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7244                       (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")))
7245    (clobber (reg:CC CC_REGNUM))]
7246   ""
7247   "sra<g>\t%0,<1>%Y2"
7248   [(set_attr "op_type"  "RS<E>")
7249    (set_attr "atype"    "reg")
7250    (set_attr "z10prop" "z10_super_E1")])
7251
7252
7253 ; shift pattern with implicit ANDs
7254
7255 (define_insn "*ashrdi3_cc_31_and"
7256   [(set (reg CC_REGNUM)
7257         (compare (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
7258                               (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7259                                       (match_operand:SI 3 "const_int_operand"   "n")))
7260                  (const_int 0)))
7261    (set (match_operand:DI 0 "register_operand" "=d")
7262         (ashiftrt:DI (match_dup 1) (and:SI (match_dup 2) (match_dup 3))))]
7263   "!TARGET_64BIT && s390_match_ccmode(insn, CCSmode)
7264    && (INTVAL (operands[3]) & 63) == 63"
7265   "srda\t%0,%Y2"
7266   [(set_attr "op_type"  "RS")
7267    (set_attr "atype"    "reg")])
7268
7269 (define_insn "*ashrdi3_cconly_31_and"
7270   [(set (reg CC_REGNUM)
7271         (compare (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
7272                               (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7273                                       (match_operand:SI 3 "const_int_operand"   "n")))
7274                  (const_int 0)))
7275    (clobber (match_scratch:DI 0 "=d"))]
7276   "!TARGET_64BIT && s390_match_ccmode(insn, CCSmode)
7277    && (INTVAL (operands[3]) & 63) == 63"
7278   "srda\t%0,%Y2"
7279   [(set_attr "op_type"  "RS")
7280    (set_attr "atype"    "reg")])
7281
7282 (define_insn "*ashrdi3_31_and"
7283   [(set (match_operand:DI 0 "register_operand" "=d")
7284         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
7285                      (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7286                              (match_operand:SI 3 "const_int_operand"   "n"))))
7287    (clobber (reg:CC CC_REGNUM))]
7288   "!TARGET_64BIT && (INTVAL (operands[3]) & 63) == 63"
7289   "srda\t%0,%Y2"
7290   [(set_attr "op_type"  "RS")
7291    (set_attr "atype"    "reg")])
7292
7293 ; sra, srag
7294 (define_insn "*ashr<mode>3_cc_and"
7295   [(set (reg CC_REGNUM)
7296         (compare (ashiftrt:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7297                                (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7298                                        (match_operand:SI 3 "const_int_operand"   "n")))
7299                  (const_int 0)))
7300    (set (match_operand:GPR 0 "register_operand" "=d")
7301         (ashiftrt:GPR (match_dup 1) (and:SI (match_dup 2) (match_dup 3))))]
7302   "s390_match_ccmode(insn, CCSmode) && (INTVAL (operands[3]) & 63) == 63"
7303   "sra<g>\t%0,<1>%Y2"
7304   [(set_attr "op_type"  "RS<E>")
7305    (set_attr "atype"    "reg")
7306    (set_attr "z10prop" "z10_super_E1")])
7307
7308 ; sra, srag
7309 (define_insn "*ashr<mode>3_cconly_and"
7310   [(set (reg CC_REGNUM)
7311         (compare (ashiftrt:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7312                                (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7313                                        (match_operand:SI 3 "const_int_operand"   "n")))
7314                  (const_int 0)))
7315    (clobber (match_scratch:GPR 0 "=d"))]
7316   "s390_match_ccmode(insn, CCSmode) && (INTVAL (operands[3]) & 63) == 63"
7317   "sra<g>\t%0,<1>%Y2"
7318   [(set_attr "op_type"  "RS<E>")
7319    (set_attr "atype"    "reg")
7320    (set_attr "z10prop" "z10_super_E1")])
7321
7322 ; sra, srag
7323 (define_insn "*ashr<mode>3_and"
7324   [(set (match_operand:GPR 0 "register_operand" "=d")
7325         (ashiftrt:GPR (match_operand:GPR 1 "register_operand" "<d0>")
7326                       (and:SI (match_operand:SI 2 "shift_count_or_setmem_operand" "Y")
7327                               (match_operand:SI 3 "const_int_operand"   "n"))))
7328    (clobber (reg:CC CC_REGNUM))]
7329   "(INTVAL (operands[3]) & 63) == 63"
7330   "sra<g>\t%0,<1>%Y2"
7331   [(set_attr "op_type"  "RS<E>")
7332    (set_attr "atype"    "reg")
7333    (set_attr "z10prop" "z10_super_E1")])
7334
7335
7336 ;;
7337 ;; Branch instruction patterns.
7338 ;;
7339
7340 (define_expand "b<code>"
7341   [(set (pc)
7342         (if_then_else (COMPARE (match_operand 0 "" "")
7343                                (const_int 0))
7344                       (match_dup 0)
7345                       (pc)))]
7346   ""
7347   "s390_emit_jump (operands[0],
7348     s390_emit_compare (<CODE>, s390_compare_op0, s390_compare_op1)); DONE;")
7349
7350
7351 ;;
7352 ;;- Conditional jump instructions.
7353 ;;
7354
7355 (define_insn "*cjump_64"
7356   [(set (pc)
7357         (if_then_else
7358           (match_operator 1 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7359           (label_ref (match_operand 0 "" ""))
7360           (pc)))]
7361   "TARGET_CPU_ZARCH"
7362 {
7363   if (get_attr_length (insn) == 4)
7364     return "j%C1\t%l0";
7365   else
7366     return "jg%C1\t%l0";
7367 }
7368   [(set_attr "op_type" "RI")
7369    (set_attr "type"    "branch")
7370    (set (attr "length")
7371         (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7372                       (const_int 4) (const_int 6)))])
7373
7374 (define_insn "*cjump_31"
7375   [(set (pc)
7376         (if_then_else
7377           (match_operator 1 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7378           (label_ref (match_operand 0 "" ""))
7379           (pc)))]
7380   "!TARGET_CPU_ZARCH"
7381 {
7382   gcc_assert (get_attr_length (insn) == 4);
7383   return "j%C1\t%l0";
7384 }
7385   [(set_attr "op_type" "RI")
7386    (set_attr "type"    "branch")
7387    (set (attr "length")
7388         (if_then_else (eq (symbol_ref "flag_pic") (const_int 0))
7389           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7390                         (const_int 4) (const_int 6))
7391           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7392                         (const_int 4) (const_int 8))))])
7393
7394 (define_insn "*cjump_long"
7395   [(set (pc)
7396         (if_then_else
7397           (match_operator 1 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7398           (match_operand 0 "address_operand" "U")
7399           (pc)))]
7400   ""
7401 {
7402   if (get_attr_op_type (insn) == OP_TYPE_RR)
7403     return "b%C1r\t%0";
7404   else
7405     return "b%C1\t%a0";
7406 }
7407   [(set (attr "op_type")
7408         (if_then_else (match_operand 0 "register_operand" "")
7409                       (const_string "RR") (const_string "RX")))
7410    (set_attr "type"  "branch")
7411    (set_attr "atype" "agen")])
7412
7413
7414 ;;
7415 ;;- Negated conditional jump instructions.
7416 ;;
7417
7418 (define_insn "*icjump_64"
7419   [(set (pc)
7420         (if_then_else
7421           (match_operator 1 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7422           (pc)
7423           (label_ref (match_operand 0 "" ""))))]
7424   "TARGET_CPU_ZARCH"
7425 {
7426   if (get_attr_length (insn) == 4)
7427     return "j%D1\t%l0";
7428   else
7429     return "jg%D1\t%l0";
7430 }
7431   [(set_attr "op_type" "RI")
7432    (set_attr "type"    "branch")
7433    (set (attr "length")
7434         (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7435                       (const_int 4) (const_int 6)))])
7436
7437 (define_insn "*icjump_31"
7438   [(set (pc)
7439         (if_then_else
7440           (match_operator 1 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7441           (pc)
7442           (label_ref (match_operand 0 "" ""))))]
7443   "!TARGET_CPU_ZARCH"
7444 {
7445   gcc_assert (get_attr_length (insn) == 4);
7446   return "j%D1\t%l0";
7447 }
7448   [(set_attr "op_type" "RI")
7449    (set_attr "type"    "branch")
7450    (set (attr "length")
7451         (if_then_else (eq (symbol_ref "flag_pic") (const_int 0))
7452           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7453                         (const_int 4) (const_int 6))
7454           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7455                         (const_int 4) (const_int 8))))])
7456
7457 (define_insn "*icjump_long"
7458   [(set (pc)
7459         (if_then_else
7460           (match_operator 1 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7461           (pc)
7462           (match_operand 0 "address_operand" "U")))]
7463   ""
7464 {
7465   if (get_attr_op_type (insn) == OP_TYPE_RR)
7466     return "b%D1r\t%0";
7467   else
7468     return "b%D1\t%a0";
7469 }
7470   [(set (attr "op_type")
7471         (if_then_else (match_operand 0 "register_operand" "")
7472                       (const_string "RR") (const_string "RX")))
7473    (set_attr "type"  "branch")
7474    (set_attr "atype" "agen")])
7475
7476 ;;
7477 ;;- Trap instructions.
7478 ;;
7479
7480 (define_insn "trap"
7481   [(trap_if (const_int 1) (const_int 0))]
7482   ""
7483   "j\t.+2"
7484   [(set_attr "op_type" "RI")
7485    (set_attr "type"  "branch")])
7486
7487 (define_expand "conditional_trap"
7488   [(trap_if (match_operand 0 "comparison_operator" "")
7489             (match_operand 1 "general_operand" ""))]
7490   ""
7491 {
7492   if (operands[1] != const0_rtx) FAIL;
7493   operands[0] = s390_emit_compare (GET_CODE (operands[0]),
7494                                    s390_compare_op0, s390_compare_op1);
7495 })
7496
7497 (define_insn "*trap"
7498   [(trap_if (match_operator 0 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
7499             (const_int 0))]
7500   ""
7501   "j%C0\t.+2";
7502   [(set_attr "op_type" "RI")
7503    (set_attr "type"  "branch")])
7504
7505 ; crt, cgrt, cit, cgit
7506 (define_insn "*cmp_and_trap_signed_int<mode>"
7507   [(trap_if (match_operator 0 "s390_signed_integer_comparison"
7508                [(match_operand:GPR 1 "register_operand"  "d,d")
7509                 (match_operand:GPR 2 "nonmemory_operand" "d,K")])
7510             (const_int 0))]
7511   "TARGET_Z10"
7512   "@
7513    c<g>rt%C0\t%1,%2
7514    c<g>it%C0\t%1,%h2"
7515   [(set_attr "op_type" "RRF,RIE")
7516    (set_attr "type"    "branch")
7517    (set_attr "z10prop" "z10_c,*")])
7518
7519 ; clrt, clgrt, clfit, clgit
7520 (define_insn "*cmp_and_trap_unsigned_int<mode>"
7521   [(trap_if (match_operator 0 "s390_unsigned_integer_comparison"
7522                [(match_operand:GPR 1 "register_operand"  "d,d")
7523                 (match_operand:GPR 2 "nonmemory_operand" "d,D")])
7524             (const_int 0))]
7525   "TARGET_Z10"
7526   "@
7527    cl<g>rt%C0\t%1,%2
7528    cl<gf>it%C0\t%1,%x2"
7529   [(set_attr "op_type" "RRF,RIE")
7530    (set_attr "type"    "branch")
7531    (set_attr "z10prop" "z10_c,*")])
7532
7533 ;;
7534 ;;- Loop instructions.
7535 ;;
7536 ;;  This is all complicated by the fact that since this is a jump insn
7537 ;;  we must handle our own output reloads.
7538
7539 (define_expand "doloop_end"
7540   [(use (match_operand 0 "" ""))        ; loop pseudo
7541    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
7542    (use (match_operand 2 "" ""))        ; max iterations
7543    (use (match_operand 3 "" ""))        ; loop level
7544    (use (match_operand 4 "" ""))]       ; label
7545   ""
7546 {
7547   if (GET_MODE (operands[0]) == SImode && !TARGET_CPU_ZARCH)
7548     emit_jump_insn (gen_doloop_si31 (operands[4], operands[0], operands[0]));
7549   else if (GET_MODE (operands[0]) == SImode && TARGET_CPU_ZARCH)
7550     emit_jump_insn (gen_doloop_si64 (operands[4], operands[0], operands[0]));
7551   else if (GET_MODE (operands[0]) == DImode && TARGET_64BIT)
7552     emit_jump_insn (gen_doloop_di (operands[4], operands[0], operands[0]));
7553   else
7554     FAIL;
7555
7556   DONE;
7557 })
7558
7559 (define_insn_and_split "doloop_si64"
7560   [(set (pc)
7561         (if_then_else
7562           (ne (match_operand:SI 1 "register_operand" "d,d,d")
7563               (const_int 1))
7564           (label_ref (match_operand 0 "" ""))
7565           (pc)))
7566    (set (match_operand:SI 2 "nonimmediate_operand" "=1,?X,?X")
7567         (plus:SI (match_dup 1) (const_int -1)))
7568    (clobber (match_scratch:SI 3 "=X,&1,&?d"))
7569    (clobber (reg:CC CC_REGNUM))]
7570   "TARGET_CPU_ZARCH"
7571 {
7572   if (which_alternative != 0)
7573     return "#";
7574   else if (get_attr_length (insn) == 4)
7575     return "brct\t%1,%l0";
7576   else
7577     return "ahi\t%1,-1\;jgne\t%l0";
7578 }
7579   "&& reload_completed
7580    && (! REG_P (operands[2])
7581        || ! rtx_equal_p (operands[1], operands[2]))"
7582   [(set (match_dup 3) (match_dup 1))
7583    (parallel [(set (reg:CCAN CC_REGNUM)
7584                    (compare:CCAN (plus:SI (match_dup 3) (const_int -1))
7585                                  (const_int 0)))
7586               (set (match_dup 3) (plus:SI (match_dup 3) (const_int -1)))])
7587    (set (match_dup 2) (match_dup 3))
7588    (set (pc) (if_then_else (ne (reg:CCAN CC_REGNUM) (const_int 0))
7589                            (label_ref (match_dup 0))
7590                            (pc)))]
7591   ""
7592   [(set_attr "op_type"  "RI")
7593    ; Strictly speaking, the z10 properties are valid for brct only, however, it does not
7594    ; hurt us in the (rare) case of ahi.
7595    (set_attr "z10prop"  "z10_super")
7596    (set_attr "type"  "branch")
7597    (set (attr "length")
7598         (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7599                       (const_int 4) (const_int 10)))])
7600
7601 (define_insn_and_split "doloop_si31"
7602   [(set (pc)
7603         (if_then_else
7604           (ne (match_operand:SI 1 "register_operand" "d,d,d")
7605               (const_int 1))
7606           (label_ref (match_operand 0 "" ""))
7607           (pc)))
7608    (set (match_operand:SI 2 "nonimmediate_operand" "=1,?X,?X")
7609         (plus:SI (match_dup 1) (const_int -1)))
7610    (clobber (match_scratch:SI 3 "=X,&1,&?d"))
7611    (clobber (reg:CC CC_REGNUM))]
7612   "!TARGET_CPU_ZARCH"
7613 {
7614   if (which_alternative != 0)
7615     return "#";
7616   else if (get_attr_length (insn) == 4)
7617     return "brct\t%1,%l0";
7618   else
7619     gcc_unreachable ();
7620 }
7621   "&& reload_completed
7622    && (! REG_P (operands[2])
7623        || ! rtx_equal_p (operands[1], operands[2]))"
7624   [(set (match_dup 3) (match_dup 1))
7625    (parallel [(set (reg:CCAN CC_REGNUM)
7626                    (compare:CCAN (plus:SI (match_dup 3) (const_int -1))
7627                                  (const_int 0)))
7628               (set (match_dup 3) (plus:SI (match_dup 3) (const_int -1)))])
7629    (set (match_dup 2) (match_dup 3))
7630    (set (pc) (if_then_else (ne (reg:CCAN CC_REGNUM) (const_int 0))
7631                            (label_ref (match_dup 0))
7632                            (pc)))]
7633   ""
7634   [(set_attr "op_type"  "RI")
7635    ; Strictly speaking, the z10 properties are valid for brct only, however, it does not
7636    ; hurt us in the (rare) case of ahi.
7637    (set_attr "z10prop"  "z10_super")
7638    (set_attr "type"  "branch")
7639    (set (attr "length")
7640         (if_then_else (eq (symbol_ref "flag_pic") (const_int 0))
7641           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7642                         (const_int 4) (const_int 6))
7643           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7644                         (const_int 4) (const_int 8))))])
7645
7646 (define_insn "*doloop_si_long"
7647   [(set (pc)
7648         (if_then_else
7649           (ne (match_operand:SI 1 "register_operand" "d")
7650               (const_int 1))
7651           (match_operand 0 "address_operand" "U")
7652           (pc)))
7653    (set (match_operand:SI 2 "register_operand" "=1")
7654         (plus:SI (match_dup 1) (const_int -1)))
7655    (clobber (match_scratch:SI 3 "=X"))
7656    (clobber (reg:CC CC_REGNUM))]
7657   "!TARGET_CPU_ZARCH"
7658 {
7659   if (get_attr_op_type (insn) == OP_TYPE_RR)
7660     return "bctr\t%1,%0";
7661   else
7662     return "bct\t%1,%a0";
7663 }
7664   [(set (attr "op_type")
7665         (if_then_else (match_operand 0 "register_operand" "")
7666                       (const_string "RR") (const_string "RX")))
7667    (set_attr "type"  "branch")
7668    (set_attr "atype" "agen")])
7669
7670 (define_insn_and_split "doloop_di"
7671   [(set (pc)
7672         (if_then_else
7673           (ne (match_operand:DI 1 "register_operand" "d,d,d")
7674               (const_int 1))
7675           (label_ref (match_operand 0 "" ""))
7676           (pc)))
7677    (set (match_operand:DI 2 "nonimmediate_operand" "=1,?X,?X")
7678         (plus:DI (match_dup 1) (const_int -1)))
7679    (clobber (match_scratch:DI 3 "=X,&1,&?d"))
7680    (clobber (reg:CC CC_REGNUM))]
7681   "TARGET_64BIT"
7682 {
7683   if (which_alternative != 0)
7684     return "#";
7685   else if (get_attr_length (insn) == 4)
7686     return "brctg\t%1,%l0";
7687   else
7688     return "aghi\t%1,-1\;jgne\t%l0";
7689 }
7690   "&& reload_completed
7691    && (! REG_P (operands[2])
7692        || ! rtx_equal_p (operands[1], operands[2]))"
7693   [(set (match_dup 3) (match_dup 1))
7694    (parallel [(set (reg:CCAN CC_REGNUM)
7695                    (compare:CCAN (plus:DI (match_dup 3) (const_int -1))
7696                                  (const_int 0)))
7697               (set (match_dup 3) (plus:DI (match_dup 3) (const_int -1)))])
7698    (set (match_dup 2) (match_dup 3))
7699    (set (pc) (if_then_else (ne (reg:CCAN CC_REGNUM) (const_int 0))
7700                            (label_ref (match_dup 0))
7701                            (pc)))]
7702   ""
7703   [(set_attr "op_type"  "RI")
7704    ; Strictly speaking, the z10 properties are valid for brct only, however, it does not
7705    ; hurt us in the (rare) case of ahi.
7706    (set_attr "z10prop"  "z10_super")
7707    (set_attr "type"  "branch")
7708    (set (attr "length")
7709         (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7710                       (const_int 4) (const_int 10)))])
7711
7712 ;;
7713 ;;- Unconditional jump instructions.
7714 ;;
7715
7716 ;
7717 ; jump instruction pattern(s).
7718 ;
7719
7720 (define_expand "jump"
7721   [(match_operand 0 "" "")]
7722   ""
7723   "s390_emit_jump (operands[0], NULL_RTX); DONE;")
7724
7725 (define_insn "*jump64"
7726   [(set (pc) (label_ref (match_operand 0 "" "")))]
7727   "TARGET_CPU_ZARCH"
7728 {
7729   if (get_attr_length (insn) == 4)
7730     return "j\t%l0";
7731   else
7732     return "jg\t%l0";
7733 }
7734   [(set_attr "op_type" "RI")
7735    (set_attr "type"  "branch")
7736    (set (attr "length")
7737         (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7738                       (const_int 4) (const_int 6)))])
7739
7740 (define_insn "*jump31"
7741   [(set (pc) (label_ref (match_operand 0 "" "")))]
7742   "!TARGET_CPU_ZARCH"
7743 {
7744   gcc_assert (get_attr_length (insn) == 4);
7745   return "j\t%l0";
7746 }
7747   [(set_attr "op_type" "RI")
7748    (set_attr "type"  "branch")
7749    (set (attr "length")
7750         (if_then_else (eq (symbol_ref "flag_pic") (const_int 0))
7751           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7752                         (const_int 4) (const_int 6))
7753           (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 60000))
7754                         (const_int 4) (const_int 8))))])
7755
7756 ;
7757 ; indirect-jump instruction pattern(s).
7758 ;
7759
7760 (define_insn "indirect_jump"
7761  [(set (pc) (match_operand 0 "address_operand" "U"))]
7762   ""
7763 {
7764   if (get_attr_op_type (insn) == OP_TYPE_RR)
7765     return "br\t%0";
7766   else
7767     return "b\t%a0";
7768 }
7769   [(set (attr "op_type")
7770         (if_then_else (match_operand 0 "register_operand" "")
7771                       (const_string "RR") (const_string "RX")))
7772    (set_attr "type"  "branch")
7773    (set_attr "atype" "agen")
7774    (set_attr "z10prop" "z10_super")])
7775
7776 ;
7777 ; casesi instruction pattern(s).
7778 ;
7779
7780 (define_insn "casesi_jump"
7781  [(set (pc) (match_operand 0 "address_operand" "U"))
7782    (use (label_ref (match_operand 1 "" "")))]
7783   ""
7784 {
7785   if (get_attr_op_type (insn) == OP_TYPE_RR)
7786     return "br\t%0";
7787   else
7788     return "b\t%a0";
7789 }
7790   [(set (attr "op_type")
7791         (if_then_else (match_operand 0 "register_operand" "")
7792                       (const_string "RR") (const_string "RX")))
7793    (set_attr "type"  "branch")
7794    (set_attr "atype" "agen")])
7795
7796 (define_expand "casesi"
7797   [(match_operand:SI 0 "general_operand" "")
7798    (match_operand:SI 1 "general_operand" "")
7799    (match_operand:SI 2 "general_operand" "")
7800    (label_ref (match_operand 3 "" ""))
7801    (label_ref (match_operand 4 "" ""))]
7802   ""
7803 {
7804    rtx index  = gen_reg_rtx (SImode);
7805    rtx base   = gen_reg_rtx (Pmode);
7806    rtx target = gen_reg_rtx (Pmode);
7807
7808    emit_move_insn (index, operands[0]);
7809    emit_insn (gen_subsi3 (index, index, operands[1]));
7810    emit_cmp_and_jump_insns (index, operands[2], GTU, NULL_RTX, SImode, 1,
7811                             operands[4]);
7812
7813    if (Pmode != SImode)
7814      index = convert_to_mode (Pmode, index, 1);
7815    if (GET_CODE (index) != REG)
7816      index = copy_to_mode_reg (Pmode, index);
7817
7818    if (TARGET_64BIT)
7819        emit_insn (gen_ashldi3 (index, index, GEN_INT (3)));
7820    else
7821        emit_insn (gen_ashlsi3 (index, index, const2_rtx));
7822
7823    emit_move_insn (base, gen_rtx_LABEL_REF (Pmode, operands[3]));
7824
7825    index = gen_const_mem (Pmode, gen_rtx_PLUS (Pmode, base, index));
7826    emit_move_insn (target, index);
7827
7828    if (flag_pic)
7829      target = gen_rtx_PLUS (Pmode, base, target);
7830    emit_jump_insn (gen_casesi_jump (target, operands[3]));
7831
7832    DONE;
7833 })
7834
7835
7836 ;;
7837 ;;- Jump to subroutine.
7838 ;;
7839 ;;
7840
7841 ;
7842 ; untyped call instruction pattern(s).
7843 ;
7844
7845 ;; Call subroutine returning any type.
7846 (define_expand "untyped_call"
7847   [(parallel [(call (match_operand 0 "" "")
7848                     (const_int 0))
7849               (match_operand 1 "" "")
7850               (match_operand 2 "" "")])]
7851   ""
7852 {
7853   int i;
7854
7855   emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
7856
7857   for (i = 0; i < XVECLEN (operands[2], 0); i++)
7858     {
7859       rtx set = XVECEXP (operands[2], 0, i);
7860       emit_move_insn (SET_DEST (set), SET_SRC (set));
7861     }
7862
7863   /* The optimizer does not know that the call sets the function value
7864      registers we stored in the result block.  We avoid problems by
7865      claiming that all hard registers are used and clobbered at this
7866      point.  */
7867   emit_insn (gen_blockage ());
7868
7869   DONE;
7870 })
7871
7872 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
7873 ;; all of memory.  This blocks insns from being moved across this point.
7874
7875 (define_insn "blockage"
7876   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
7877   ""
7878   ""
7879   [(set_attr "type"    "none")
7880    (set_attr "length"  "0")])
7881
7882 ;
7883 ; sibcall patterns
7884 ;
7885
7886 (define_expand "sibcall"
7887   [(call (match_operand 0 "" "")
7888          (match_operand 1 "" ""))]
7889   ""
7890 {
7891   s390_emit_call (XEXP (operands[0], 0), NULL_RTX, NULL_RTX, NULL_RTX);
7892   DONE;
7893 })
7894
7895 (define_insn "*sibcall_br"
7896   [(call (mem:QI (reg SIBCALL_REGNUM))
7897          (match_operand 0 "const_int_operand" "n"))]
7898   "SIBLING_CALL_P (insn)
7899    && GET_MODE (XEXP (XEXP (PATTERN (insn), 0), 0)) == Pmode"
7900   "br\t%%r1"
7901   [(set_attr "op_type" "RR")
7902    (set_attr "type"  "branch")
7903    (set_attr "atype" "agen")])
7904
7905 (define_insn "*sibcall_brc"
7906   [(call (mem:QI (match_operand 0 "bras_sym_operand" "X"))
7907          (match_operand 1 "const_int_operand" "n"))]
7908   "SIBLING_CALL_P (insn) && TARGET_SMALL_EXEC"
7909   "j\t%0"
7910   [(set_attr "op_type" "RI")
7911    (set_attr "type"    "branch")])
7912
7913 (define_insn "*sibcall_brcl"
7914   [(call (mem:QI (match_operand 0 "bras_sym_operand" "X"))
7915          (match_operand 1 "const_int_operand" "n"))]
7916   "SIBLING_CALL_P (insn) && TARGET_CPU_ZARCH"
7917   "jg\t%0"
7918   [(set_attr "op_type" "RIL")
7919    (set_attr "type"    "branch")])
7920
7921 ;
7922 ; sibcall_value patterns
7923 ;
7924
7925 (define_expand "sibcall_value"
7926   [(set (match_operand 0 "" "")
7927         (call (match_operand 1 "" "")
7928               (match_operand 2 "" "")))]
7929   ""
7930 {
7931   s390_emit_call (XEXP (operands[1], 0), NULL_RTX, operands[0], NULL_RTX);
7932   DONE;
7933 })
7934
7935 (define_insn "*sibcall_value_br"
7936   [(set (match_operand 0 "" "")
7937         (call (mem:QI (reg SIBCALL_REGNUM))
7938               (match_operand 1 "const_int_operand" "n")))]
7939   "SIBLING_CALL_P (insn)
7940    && GET_MODE (XEXP (XEXP (XEXP (PATTERN (insn), 1), 0), 0)) == Pmode"
7941   "br\t%%r1"
7942   [(set_attr "op_type" "RR")
7943    (set_attr "type"  "branch")
7944    (set_attr "atype" "agen")])
7945
7946 (define_insn "*sibcall_value_brc"
7947   [(set (match_operand 0 "" "")
7948         (call (mem:QI (match_operand 1 "bras_sym_operand" "X"))
7949               (match_operand 2 "const_int_operand" "n")))]
7950   "SIBLING_CALL_P (insn) && TARGET_SMALL_EXEC"
7951   "j\t%1"
7952   [(set_attr "op_type" "RI")
7953    (set_attr "type"    "branch")])
7954
7955 (define_insn "*sibcall_value_brcl"
7956   [(set (match_operand 0 "" "")
7957         (call (mem:QI (match_operand 1 "bras_sym_operand" "X"))
7958               (match_operand 2 "const_int_operand" "n")))]
7959   "SIBLING_CALL_P (insn) && TARGET_CPU_ZARCH"
7960   "jg\t%1"
7961   [(set_attr "op_type" "RIL")
7962    (set_attr "type"    "branch")])
7963
7964
7965 ;
7966 ; call instruction pattern(s).
7967 ;
7968
7969 (define_expand "call"
7970   [(call (match_operand 0 "" "")
7971          (match_operand 1 "" ""))
7972    (use (match_operand 2 "" ""))]
7973   ""
7974 {
7975   s390_emit_call (XEXP (operands[0], 0), NULL_RTX, NULL_RTX,
7976                   gen_rtx_REG (Pmode, RETURN_REGNUM));
7977   DONE;
7978 })
7979
7980 (define_insn "*bras"
7981   [(call (mem:QI (match_operand 0 "bras_sym_operand" "X"))
7982          (match_operand 1 "const_int_operand" "n"))
7983    (clobber (match_operand 2 "register_operand" "=r"))]
7984   "!SIBLING_CALL_P (insn)
7985    && TARGET_SMALL_EXEC
7986    && GET_MODE (operands[2]) == Pmode"
7987   "bras\t%2,%0"
7988   [(set_attr "op_type" "RI")
7989    (set_attr "type"    "jsr")])
7990
7991 (define_insn "*brasl"
7992   [(call (mem:QI (match_operand 0 "bras_sym_operand" "X"))
7993          (match_operand 1 "const_int_operand" "n"))
7994    (clobber (match_operand 2 "register_operand" "=r"))]
7995   "!SIBLING_CALL_P (insn)
7996    && TARGET_CPU_ZARCH
7997    && GET_MODE (operands[2]) == Pmode"
7998   "brasl\t%2,%0"
7999   [(set_attr "op_type" "RIL")
8000    (set_attr "type"    "jsr")])
8001
8002 (define_insn "*basr"
8003   [(call (mem:QI (match_operand 0 "address_operand" "U"))
8004          (match_operand 1 "const_int_operand" "n"))
8005    (clobber (match_operand 2 "register_operand" "=r"))]
8006   "!SIBLING_CALL_P (insn) && GET_MODE (operands[2]) == Pmode"
8007 {
8008   if (get_attr_op_type (insn) == OP_TYPE_RR)
8009     return "basr\t%2,%0";
8010   else
8011     return "bas\t%2,%a0";
8012 }
8013   [(set (attr "op_type")
8014         (if_then_else (match_operand 0 "register_operand" "")
8015                       (const_string "RR") (const_string "RX")))
8016    (set_attr "type"  "jsr")
8017    (set_attr "atype" "agen")])
8018
8019 ;
8020 ; call_value instruction pattern(s).
8021 ;
8022
8023 (define_expand "call_value"
8024   [(set (match_operand 0 "" "")
8025         (call (match_operand 1 "" "")
8026               (match_operand 2 "" "")))
8027    (use (match_operand 3 "" ""))]
8028   ""
8029 {
8030   s390_emit_call (XEXP (operands[1], 0), NULL_RTX, operands[0],
8031                   gen_rtx_REG (Pmode, RETURN_REGNUM));
8032   DONE;
8033 })
8034
8035 (define_insn "*bras_r"
8036   [(set (match_operand 0 "" "")
8037         (call (mem:QI (match_operand 1 "bras_sym_operand" "X"))
8038               (match_operand:SI 2 "const_int_operand" "n")))
8039    (clobber (match_operand 3 "register_operand" "=r"))]
8040   "!SIBLING_CALL_P (insn)
8041    && TARGET_SMALL_EXEC
8042    && GET_MODE (operands[3]) == Pmode"
8043   "bras\t%3,%1"
8044   [(set_attr "op_type" "RI")
8045    (set_attr "type"    "jsr")])
8046
8047 (define_insn "*brasl_r"
8048   [(set (match_operand 0 "" "")
8049         (call (mem:QI (match_operand 1 "bras_sym_operand" "X"))
8050               (match_operand 2 "const_int_operand" "n")))
8051    (clobber (match_operand 3 "register_operand" "=r"))]
8052   "!SIBLING_CALL_P (insn)
8053    && TARGET_CPU_ZARCH
8054    && GET_MODE (operands[3]) == Pmode"
8055   "brasl\t%3,%1"
8056   [(set_attr "op_type" "RIL")
8057    (set_attr "type"    "jsr")])
8058
8059 (define_insn "*basr_r"
8060   [(set (match_operand 0 "" "")
8061         (call (mem:QI (match_operand 1 "address_operand" "U"))
8062               (match_operand 2 "const_int_operand" "n")))
8063    (clobber (match_operand 3 "register_operand" "=r"))]
8064   "!SIBLING_CALL_P (insn) && GET_MODE (operands[3]) == Pmode"
8065 {
8066   if (get_attr_op_type (insn) == OP_TYPE_RR)
8067     return "basr\t%3,%1";
8068   else
8069     return "bas\t%3,%a1";
8070 }
8071   [(set (attr "op_type")
8072         (if_then_else (match_operand 1 "register_operand" "")
8073                       (const_string "RR") (const_string "RX")))
8074    (set_attr "type"  "jsr")
8075    (set_attr "atype" "agen")])
8076
8077 ;;
8078 ;;- Thread-local storage support.
8079 ;;
8080
8081 (define_expand "get_tp_64"
8082   [(set (match_operand:DI 0 "nonimmediate_operand" "") (reg:DI TP_REGNUM))]
8083   "TARGET_64BIT"
8084   "")
8085
8086 (define_expand "get_tp_31"
8087   [(set (match_operand:SI 0 "nonimmediate_operand" "") (reg:SI TP_REGNUM))]
8088   "!TARGET_64BIT"
8089   "")
8090
8091 (define_expand "set_tp_64"
8092   [(set (reg:DI TP_REGNUM) (match_operand:DI 0 "nonimmediate_operand" ""))
8093    (set (reg:DI TP_REGNUM) (unspec_volatile:DI [(reg:DI TP_REGNUM)] UNSPECV_SET_TP))]
8094   "TARGET_64BIT"
8095   "")
8096
8097 (define_expand "set_tp_31"
8098   [(set (reg:SI TP_REGNUM) (match_operand:SI 0 "nonimmediate_operand" ""))
8099    (set (reg:SI TP_REGNUM) (unspec_volatile:SI [(reg:SI TP_REGNUM)] UNSPECV_SET_TP))]
8100   "!TARGET_64BIT"
8101   "")
8102
8103 (define_insn "*set_tp"
8104   [(set (reg TP_REGNUM) (unspec_volatile [(reg TP_REGNUM)] UNSPECV_SET_TP))]
8105   ""
8106   ""
8107   [(set_attr "type" "none")
8108    (set_attr "length" "0")])
8109
8110 (define_insn "*tls_load_64"
8111   [(set (match_operand:DI 0 "register_operand" "=d")
8112         (unspec:DI [(match_operand:DI 1 "memory_operand" "RT")
8113                     (match_operand:DI 2 "" "")]
8114                    UNSPEC_TLS_LOAD))]
8115   "TARGET_64BIT"
8116   "lg\t%0,%1%J2"
8117   [(set_attr "op_type" "RXE")
8118    (set_attr "z10prop" "z10_fwd_A3")])
8119
8120 (define_insn "*tls_load_31"
8121   [(set (match_operand:SI 0 "register_operand" "=d,d")
8122         (unspec:SI [(match_operand:SI 1 "memory_operand" "R,T")
8123                     (match_operand:SI 2 "" "")]
8124                    UNSPEC_TLS_LOAD))]
8125   "!TARGET_64BIT"
8126   "@
8127    l\t%0,%1%J2
8128    ly\t%0,%1%J2"
8129   [(set_attr "op_type" "RX,RXY")
8130    (set_attr "z10prop" "z10_fwd_A3,z10_fwd_A3")])
8131
8132 (define_insn "*bras_tls"
8133   [(set (match_operand 0 "" "")
8134         (call (mem:QI (match_operand 1 "bras_sym_operand" "X"))
8135               (match_operand 2 "const_int_operand" "n")))
8136    (clobber (match_operand 3 "register_operand" "=r"))
8137    (use (match_operand 4 "" ""))]
8138   "!SIBLING_CALL_P (insn)
8139    && TARGET_SMALL_EXEC
8140    && GET_MODE (operands[3]) == Pmode"
8141   "bras\t%3,%1%J4"
8142   [(set_attr "op_type" "RI")
8143    (set_attr "type"    "jsr")])
8144
8145 (define_insn "*brasl_tls"
8146   [(set (match_operand 0 "" "")
8147         (call (mem:QI (match_operand 1 "bras_sym_operand" "X"))
8148               (match_operand 2 "const_int_operand" "n")))
8149    (clobber (match_operand 3 "register_operand" "=r"))
8150    (use (match_operand 4 "" ""))]
8151   "!SIBLING_CALL_P (insn)
8152    && TARGET_CPU_ZARCH
8153    && GET_MODE (operands[3]) == Pmode"
8154   "brasl\t%3,%1%J4"
8155   [(set_attr "op_type" "RIL")
8156    (set_attr "type"    "jsr")])
8157
8158 (define_insn "*basr_tls"
8159   [(set (match_operand 0 "" "")
8160         (call (mem:QI (match_operand 1 "address_operand" "U"))
8161               (match_operand 2 "const_int_operand" "n")))
8162    (clobber (match_operand 3 "register_operand" "=r"))
8163    (use (match_operand 4 "" ""))]
8164   "!SIBLING_CALL_P (insn) && GET_MODE (operands[3]) == Pmode"
8165 {
8166   if (get_attr_op_type (insn) == OP_TYPE_RR)
8167     return "basr\t%3,%1%J4";
8168   else
8169     return "bas\t%3,%a1%J4";
8170 }
8171   [(set (attr "op_type")
8172         (if_then_else (match_operand 1 "register_operand" "")
8173                       (const_string "RR") (const_string "RX")))
8174    (set_attr "type"  "jsr")
8175    (set_attr "atype" "agen")])
8176
8177 ;;
8178 ;;- Atomic operations
8179 ;;
8180
8181 ;
8182 ; memory barrier pattern.
8183 ;
8184
8185 (define_expand "memory_barrier"
8186   [(set (mem:BLK (match_dup 0))
8187         (unspec_volatile:BLK [(mem:BLK (match_dup 0))] UNSPECV_MB))]
8188   ""
8189 {
8190   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (DImode));
8191   MEM_VOLATILE_P (operands[0]) = 1;
8192 })
8193
8194 (define_insn "*memory_barrier"
8195   [(set (match_operand:BLK 0 "" "")
8196         (unspec_volatile:BLK [(match_operand:BLK 1 "" "")] UNSPECV_MB))]
8197   ""
8198   "bcr\t15,0"
8199   [(set_attr "op_type" "RR")])
8200 ; Although bcr is superscalar on Z10, this variant will never become part of
8201 ; an execution group.
8202
8203 ;
8204 ; compare and swap patterns.
8205 ;
8206
8207 (define_expand "sync_compare_and_swap<mode>"
8208   [(parallel
8209     [(set (match_operand:TDSI 0 "register_operand" "")
8210           (match_operand:TDSI 1 "memory_operand" ""))
8211      (set (match_dup 1)
8212           (unspec_volatile:TDSI
8213             [(match_dup 1)
8214              (match_operand:TDSI 2 "register_operand" "")
8215              (match_operand:TDSI 3 "register_operand" "")]
8216             UNSPECV_CAS))
8217      (set (reg:CCZ1 CC_REGNUM)
8218           (compare:CCZ1 (match_dup 1) (match_dup 2)))])]
8219   "")
8220
8221 (define_expand "sync_compare_and_swap<mode>"
8222   [(parallel
8223     [(set (match_operand:HQI 0 "register_operand" "")
8224           (match_operand:HQI 1 "memory_operand" ""))
8225      (set (match_dup 1)
8226           (unspec_volatile:HQI
8227             [(match_dup 1)
8228              (match_operand:HQI 2 "general_operand" "")
8229              (match_operand:HQI 3 "general_operand" "")]
8230             UNSPECV_CAS))
8231      (set (reg:CCZ1 CC_REGNUM)
8232           (compare:CCZ1 (match_dup 1) (match_dup 2)))])]
8233   ""
8234   "s390_expand_cs_hqi (<MODE>mode, operands[0], operands[1],
8235                        operands[2], operands[3]); DONE;")
8236
8237 (define_expand "sync_compare_and_swap_cc<mode>"
8238   [(parallel
8239     [(set (match_operand:TDSI 0 "register_operand" "")
8240           (match_operand:TDSI 1 "memory_operand" ""))
8241      (set (match_dup 1)
8242           (unspec_volatile:TDSI
8243             [(match_dup 1)
8244              (match_operand:TDSI 2 "register_operand" "")
8245              (match_operand:TDSI 3 "register_operand" "")]
8246             UNSPECV_CAS))
8247      (set (match_dup 4)
8248           (compare:CCZ1 (match_dup 1) (match_dup 2)))])]
8249   ""
8250 {
8251   /* Emulate compare.  */
8252   operands[4] = gen_rtx_REG (CCZ1mode, CC_REGNUM);
8253   s390_compare_op0 = operands[1];
8254   s390_compare_op1 = operands[2];
8255   s390_compare_emitted = operands[4];
8256 })
8257
8258 ; cds, cdsg
8259 (define_insn "*sync_compare_and_swap<mode>"
8260   [(set (match_operand:DP 0 "register_operand" "=r")
8261         (match_operand:DP 1 "memory_operand" "+Q"))
8262    (set (match_dup 1)
8263         (unspec_volatile:DP
8264           [(match_dup 1)
8265            (match_operand:DP 2 "register_operand" "0")
8266            (match_operand:DP 3 "register_operand" "r")]
8267           UNSPECV_CAS))
8268    (set (reg:CCZ1 CC_REGNUM)
8269         (compare:CCZ1 (match_dup 1) (match_dup 2)))]
8270   ""
8271   "cds<tg>\t%0,%3,%S1"
8272   [(set_attr "op_type" "RS<TE>")
8273    (set_attr "type"   "sem")])
8274
8275 ; cs, csg
8276 (define_insn "*sync_compare_and_swap<mode>"
8277   [(set (match_operand:GPR 0 "register_operand" "=r")
8278         (match_operand:GPR 1 "memory_operand" "+Q"))
8279    (set (match_dup 1)
8280         (unspec_volatile:GPR
8281           [(match_dup 1)
8282            (match_operand:GPR 2 "register_operand" "0")
8283            (match_operand:GPR 3 "register_operand" "r")]
8284           UNSPECV_CAS))
8285    (set (reg:CCZ1 CC_REGNUM)
8286         (compare:CCZ1 (match_dup 1) (match_dup 2)))]
8287   ""
8288   "cs<g>\t%0,%3,%S1"
8289   [(set_attr "op_type" "RS<E>")
8290    (set_attr "type"   "sem")])
8291
8292
8293 ;
8294 ; Other atomic instruction patterns.
8295 ;
8296
8297 (define_expand "sync_lock_test_and_set<mode>"
8298   [(match_operand:HQI 0 "register_operand")
8299    (match_operand:HQI 1 "memory_operand")
8300    (match_operand:HQI 2 "general_operand")]
8301   ""
8302   "s390_expand_atomic (<MODE>mode, SET, operands[0], operands[1],
8303                        operands[2], false); DONE;")
8304
8305 (define_expand "sync_<atomic><mode>"
8306   [(set (match_operand:HQI 0 "memory_operand")
8307         (ATOMIC:HQI (match_dup 0)
8308                     (match_operand:HQI 1 "general_operand")))]
8309   ""
8310   "s390_expand_atomic (<MODE>mode, <CODE>, NULL_RTX, operands[0],
8311                        operands[1], false); DONE;")
8312
8313 (define_expand "sync_old_<atomic><mode>"
8314   [(set (match_operand:HQI 0 "register_operand")
8315         (match_operand:HQI 1 "memory_operand"))
8316    (set (match_dup 1)
8317         (ATOMIC:HQI (match_dup 1)
8318                     (match_operand:HQI 2 "general_operand")))]
8319   ""
8320   "s390_expand_atomic (<MODE>mode, <CODE>, operands[0], operands[1],
8321                        operands[2], false); DONE;")
8322
8323 (define_expand "sync_new_<atomic><mode>"
8324   [(set (match_operand:HQI 0 "register_operand")
8325         (ATOMIC:HQI (match_operand:HQI 1 "memory_operand")
8326                     (match_operand:HQI 2 "general_operand")))
8327    (set (match_dup 1) (ATOMIC:HQI (match_dup 1) (match_dup 2)))]
8328   ""
8329   "s390_expand_atomic (<MODE>mode, <CODE>, operands[0], operands[1],
8330                        operands[2], true); DONE;")
8331
8332 ;;
8333 ;;- Miscellaneous instructions.
8334 ;;
8335
8336 ;
8337 ; allocate stack instruction pattern(s).
8338 ;
8339
8340 (define_expand "allocate_stack"
8341   [(match_operand 0 "general_operand" "")
8342    (match_operand 1 "general_operand" "")]
8343  "TARGET_BACKCHAIN"
8344 {
8345   rtx temp = gen_reg_rtx (Pmode);
8346
8347   emit_move_insn (temp, s390_back_chain_rtx ());
8348   anti_adjust_stack (operands[1]);
8349   emit_move_insn (s390_back_chain_rtx (), temp);
8350
8351   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
8352   DONE;
8353 })
8354
8355
8356 ;
8357 ; setjmp instruction pattern.
8358 ;
8359
8360 (define_expand "builtin_setjmp_receiver"
8361   [(match_operand 0 "" "")]
8362   "flag_pic"
8363 {
8364   emit_insn (s390_load_got ());
8365   emit_use (pic_offset_table_rtx);
8366   DONE;
8367 })
8368
8369 ;; These patterns say how to save and restore the stack pointer.  We need not
8370 ;; save the stack pointer at function level since we are careful to
8371 ;; preserve the backchain.  At block level, we have to restore the backchain
8372 ;; when we restore the stack pointer.
8373 ;;
8374 ;; For nonlocal gotos, we must save both the stack pointer and its
8375 ;; backchain and restore both.  Note that in the nonlocal case, the
8376 ;; save area is a memory location.
8377
8378 (define_expand "save_stack_function"
8379   [(match_operand 0 "general_operand" "")
8380    (match_operand 1 "general_operand" "")]
8381   ""
8382   "DONE;")
8383
8384 (define_expand "restore_stack_function"
8385   [(match_operand 0 "general_operand" "")
8386    (match_operand 1 "general_operand" "")]
8387   ""
8388   "DONE;")
8389
8390 (define_expand "restore_stack_block"
8391   [(match_operand 0 "register_operand" "")
8392    (match_operand 1 "register_operand" "")]
8393   "TARGET_BACKCHAIN"
8394 {
8395   rtx temp = gen_reg_rtx (Pmode);
8396
8397   emit_move_insn (temp, s390_back_chain_rtx ());
8398   emit_move_insn (operands[0], operands[1]);
8399   emit_move_insn (s390_back_chain_rtx (), temp);
8400
8401   DONE;
8402 })
8403
8404 (define_expand "save_stack_nonlocal"
8405   [(match_operand 0 "memory_operand" "")
8406    (match_operand 1 "register_operand" "")]
8407   ""
8408 {
8409   enum machine_mode mode = TARGET_64BIT ? OImode : TImode;
8410   rtx base = gen_rtx_REG (Pmode, BASE_REGNUM);
8411
8412   /* Copy the backchain to the first word, sp to the second and the
8413      literal pool base to the third.  */
8414
8415   if (TARGET_BACKCHAIN)
8416     {
8417       rtx temp = force_reg (Pmode, s390_back_chain_rtx ());
8418       emit_move_insn (operand_subword (operands[0], 0, 0, mode), temp);
8419     }
8420
8421   emit_move_insn (operand_subword (operands[0], 1, 0, mode), operands[1]);
8422   emit_move_insn (operand_subword (operands[0], 2, 0, mode), base);
8423
8424   DONE;
8425 })
8426
8427 (define_expand "restore_stack_nonlocal"
8428   [(match_operand 0 "register_operand" "")
8429    (match_operand 1 "memory_operand" "")]
8430   ""
8431 {
8432   enum machine_mode mode = TARGET_64BIT ? OImode : TImode;
8433   rtx base = gen_rtx_REG (Pmode, BASE_REGNUM);
8434   rtx temp = NULL_RTX;
8435
8436   /* Restore the backchain from the first word, sp from the second and the
8437      literal pool base from the third.  */
8438
8439   if (TARGET_BACKCHAIN)
8440     temp = force_reg (Pmode, operand_subword (operands[1], 0, 0, mode));
8441
8442   emit_move_insn (base, operand_subword (operands[1], 2, 0, mode));
8443   emit_move_insn (operands[0], operand_subword (operands[1], 1, 0, mode));
8444
8445   if (temp)
8446     emit_move_insn (s390_back_chain_rtx (), temp);
8447
8448   emit_use (base);
8449   DONE;
8450 })
8451
8452 (define_expand "exception_receiver"
8453   [(const_int 0)]
8454   ""
8455 {
8456   s390_set_has_landing_pad_p (true);
8457   DONE;
8458 })
8459
8460 ;
8461 ; nop instruction pattern(s).
8462 ;
8463
8464 (define_insn "nop"
8465   [(const_int 0)]
8466   ""
8467   "lr\t0,0"
8468   [(set_attr "op_type" "RR")])
8469
8470 (define_insn "nop1"
8471   [(const_int 1)]
8472   ""
8473   "lr\t1,1"
8474   [(set_attr "op_type" "RR")])
8475
8476
8477 ;
8478 ; Special literal pool access instruction pattern(s).
8479 ;
8480
8481 (define_insn "*pool_entry"
8482   [(unspec_volatile [(match_operand 0 "consttable_operand" "X")]
8483                     UNSPECV_POOL_ENTRY)]
8484   ""
8485 {
8486   enum machine_mode mode = GET_MODE (PATTERN (insn));
8487   unsigned int align = GET_MODE_BITSIZE (mode);
8488   s390_output_pool_entry (operands[0], mode, align);
8489   return "";
8490 }
8491   [(set (attr "length")
8492         (symbol_ref "GET_MODE_SIZE (GET_MODE (PATTERN (insn)))"))])
8493
8494 (define_insn "pool_align"
8495   [(unspec_volatile [(match_operand 0 "const_int_operand" "n")]
8496                     UNSPECV_POOL_ALIGN)]
8497   ""
8498   ".align\t%0"
8499   [(set (attr "length") (symbol_ref "INTVAL (operands[0])"))])
8500
8501 (define_insn "pool_section_start"
8502   [(unspec_volatile [(const_int 1)] UNSPECV_POOL_SECTION)]
8503   ""
8504   ".section\t.rodata"
8505   [(set_attr "length" "0")])
8506
8507 (define_insn "pool_section_end"
8508   [(unspec_volatile [(const_int 0)] UNSPECV_POOL_SECTION)]
8509   ""
8510   ".previous"
8511   [(set_attr "length" "0")])
8512
8513 (define_insn "main_base_31_small"
8514   [(set (match_operand 0 "register_operand" "=a")
8515         (unspec [(label_ref (match_operand 1 "" ""))] UNSPEC_MAIN_BASE))]
8516   "!TARGET_CPU_ZARCH && GET_MODE (operands[0]) == Pmode"
8517   "basr\t%0,0"
8518   [(set_attr "op_type" "RR")
8519    (set_attr "type"    "la")])
8520
8521 (define_insn "main_base_31_large"
8522   [(set (match_operand 0 "register_operand" "=a")
8523         (unspec [(label_ref (match_operand 1 "" ""))] UNSPEC_MAIN_BASE))
8524    (set (pc) (label_ref (match_operand 2 "" "")))]
8525   "!TARGET_CPU_ZARCH && GET_MODE (operands[0]) == Pmode"
8526   "bras\t%0,%2"
8527   [(set_attr "op_type" "RI")])
8528
8529 (define_insn "main_base_64"
8530   [(set (match_operand 0 "register_operand" "=a")
8531         (unspec [(label_ref (match_operand 1 "" ""))] UNSPEC_MAIN_BASE))]
8532   "TARGET_CPU_ZARCH && GET_MODE (operands[0]) == Pmode"
8533   "larl\t%0,%1"
8534   [(set_attr "op_type" "RIL")
8535    (set_attr "type"    "larl")
8536    (set_attr "z10prop" "z10_super_A1")])
8537
8538 (define_insn "main_pool"
8539   [(set (match_operand 0 "register_operand" "=a")
8540         (unspec_volatile [(const_int 0)] UNSPECV_MAIN_POOL))]
8541   "GET_MODE (operands[0]) == Pmode"
8542 {
8543   gcc_unreachable ();
8544 }
8545   [(set (attr "type")
8546         (if_then_else (ne (symbol_ref "TARGET_CPU_ZARCH") (const_int 0))
8547                       (const_string "larl") (const_string "la")))])
8548
8549 (define_insn "reload_base_31"
8550   [(set (match_operand 0 "register_operand" "=a")
8551         (unspec [(label_ref (match_operand 1 "" ""))] UNSPEC_RELOAD_BASE))]
8552   "!TARGET_CPU_ZARCH && GET_MODE (operands[0]) == Pmode"
8553   "basr\t%0,0\;la\t%0,%1-.(%0)"
8554   [(set_attr "length" "6")
8555    (set_attr "type" "la")])
8556
8557 (define_insn "reload_base_64"
8558   [(set (match_operand 0 "register_operand" "=a")
8559         (unspec [(label_ref (match_operand 1 "" ""))] UNSPEC_RELOAD_BASE))]
8560   "TARGET_CPU_ZARCH && GET_MODE (operands[0]) == Pmode"
8561   "larl\t%0,%1"
8562   [(set_attr "op_type" "RIL")
8563    (set_attr "type"    "larl")
8564    (set_attr "z10prop" "z10_super_A1")])
8565
8566 (define_insn "pool"
8567   [(unspec_volatile [(match_operand 0 "const_int_operand" "n")] UNSPECV_POOL)]
8568   ""
8569 {
8570   gcc_unreachable ();
8571 }
8572   [(set (attr "length") (symbol_ref "INTVAL (operands[0])"))])
8573
8574 ;;
8575 ;; Insns related to generating the function prologue and epilogue.
8576 ;;
8577
8578
8579 (define_expand "prologue"
8580   [(use (const_int 0))]
8581   ""
8582   "s390_emit_prologue (); DONE;")
8583
8584 (define_expand "epilogue"
8585   [(use (const_int 1))]
8586   ""
8587   "s390_emit_epilogue (false); DONE;")
8588
8589 (define_expand "sibcall_epilogue"
8590   [(use (const_int 0))]
8591   ""
8592   "s390_emit_epilogue (true); DONE;")
8593
8594 (define_insn "*return"
8595   [(return)
8596    (use (match_operand 0 "register_operand" "a"))]
8597   "GET_MODE (operands[0]) == Pmode"
8598   "br\t%0"
8599   [(set_attr "op_type" "RR")
8600    (set_attr "type"    "jsr")
8601    (set_attr "atype"   "agen")])
8602
8603
8604 ;; Instruction definition to extend a 31-bit pointer into a 64-bit
8605 ;; pointer. This is used for compatibility.
8606
8607 (define_expand "ptr_extend"
8608   [(set (match_operand:DI 0 "register_operand" "=r")
8609         (match_operand:SI 1 "register_operand" "r"))]
8610   "TARGET_64BIT"
8611 {
8612   emit_insn (gen_anddi3 (operands[0],
8613                          gen_lowpart (DImode, operands[1]),
8614                          GEN_INT (0x7fffffff)));
8615   DONE;
8616 })
8617
8618 ;; Instruction definition to expand eh_return macro to support
8619 ;; swapping in special linkage return addresses.
8620
8621 (define_expand "eh_return"
8622   [(use (match_operand 0 "register_operand" ""))]
8623   "TARGET_TPF"
8624 {
8625   s390_emit_tpf_eh_return (operands[0]);
8626   DONE;
8627 })
8628
8629 ;
8630 ; Stack Protector Patterns
8631 ;
8632
8633 (define_expand "stack_protect_set"
8634   [(set (match_operand 0 "memory_operand" "")
8635         (match_operand 1 "memory_operand" ""))]
8636   ""
8637 {
8638 #ifdef TARGET_THREAD_SSP_OFFSET
8639   operands[1]
8640     = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, s390_get_thread_pointer (),
8641                                         GEN_INT (TARGET_THREAD_SSP_OFFSET)));
8642 #endif
8643   if (TARGET_64BIT)
8644     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
8645   else
8646     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
8647
8648   DONE;
8649 })
8650
8651 (define_insn "stack_protect_set<mode>"
8652   [(set (match_operand:DSI 0 "memory_operand" "=Q")
8653         (unspec:DSI [(match_operand:DSI 1 "memory_operand" "Q")] UNSPEC_SP_SET))]
8654   ""
8655   "mvc\t%O0(%G0,%R0),%S1"
8656   [(set_attr "op_type" "SS")])
8657
8658 (define_expand "stack_protect_test"
8659   [(set (reg:CC CC_REGNUM)
8660         (compare (match_operand 0 "memory_operand" "")
8661                  (match_operand 1 "memory_operand" "")))
8662    (match_operand 2 "" "")]
8663   ""
8664 {
8665 #ifdef TARGET_THREAD_SSP_OFFSET
8666   operands[1]
8667     = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, s390_get_thread_pointer (),
8668                                         GEN_INT (TARGET_THREAD_SSP_OFFSET)));
8669 #endif
8670   s390_compare_op0 = operands[0];
8671   s390_compare_op1 = operands[1];
8672   s390_compare_emitted = gen_rtx_REG (CCZmode, CC_REGNUM);
8673
8674   if (TARGET_64BIT)
8675     emit_insn (gen_stack_protect_testdi (operands[0], operands[1]));
8676   else
8677     emit_insn (gen_stack_protect_testsi (operands[0], operands[1]));
8678
8679   emit_jump_insn (gen_beq (operands[2]));
8680
8681   DONE;
8682 })
8683
8684 (define_insn "stack_protect_test<mode>"
8685   [(set (reg:CCZ CC_REGNUM)
8686         (unspec:CCZ [(match_operand:DSI 0 "memory_operand" "Q")
8687                      (match_operand:DSI 1 "memory_operand" "Q")] UNSPEC_SP_TEST))]
8688   ""
8689   "clc\t%O0(%G0,%R0),%S1"
8690   [(set_attr "op_type" "SS")])
8691
8692 ; This is used in s390_emit_prologue in order to prevent insns
8693 ; adjusting the stack pointer to be moved over insns writing stack
8694 ; slots using a copy of the stack pointer in a different register.
8695 (define_insn "stack_tie"
8696   [(set (match_operand:BLK 0 "memory_operand" "+m")
8697         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
8698   ""
8699   ""
8700   [(set_attr "length" "0")])
8701
8702
8703 ;
8704 ; Data prefetch patterns
8705 ;
8706
8707 (define_insn "prefetch"
8708   [(prefetch (match_operand 0 "address_operand" "UW,X")
8709              (match_operand:SI 1 "const_int_operand" "n,n")
8710              (match_operand:SI 2 "const_int_operand" "n,n"))]
8711   "TARGET_Z10"
8712 {
8713   if (larl_operand (operands[0], Pmode))
8714     return INTVAL (operands[1]) == 1 ? "pfdrl\t2,%a0" : "pfdrl\t1,%a0";
8715
8716   if (s390_mem_constraint ("W", operands[0])
8717       || s390_mem_constraint ("U", operands[0]))
8718     return INTVAL (operands[1]) == 1 ? "pfd\t2,%a0" : "pfd\t1,%a0";
8719
8720   /* This point might be reached if op0 is a larl operand with an
8721      uneven addend.  In this case we simply omit issuing a prefetch
8722      instruction.  */
8723
8724   return "";
8725 }
8726   [(set_attr "type" "load,larl")
8727    (set_attr "op_type" "RXY,RIL")
8728    (set_attr "z10prop" "z10_super")])