OSDN Git Service

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