1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2008, 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).
8 This file is part of GCC.
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
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
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/>. */
26 #include "coretypes.h"
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
45 #include "basic-block.h"
46 #include "integrate.h"
49 #include "target-def.h"
51 #include "langhooks.h"
58 /* Define the specific costs for a given cpu. */
60 struct processor_costs
63 const int m; /* cost of an M instruction. */
64 const int mghi; /* cost of an MGHI instruction. */
65 const int mh; /* cost of an MH instruction. */
66 const int mhi; /* cost of an MHI instruction. */
67 const int ml; /* cost of an ML instruction. */
68 const int mr; /* cost of an MR instruction. */
69 const int ms; /* cost of an MS instruction. */
70 const int msg; /* cost of an MSG instruction. */
71 const int msgf; /* cost of an MSGF instruction. */
72 const int msgfr; /* cost of an MSGFR instruction. */
73 const int msgr; /* cost of an MSGR instruction. */
74 const int msr; /* cost of an MSR instruction. */
75 const int mult_df; /* cost of multiplication in DFmode. */
78 const int sqxbr; /* cost of square root in TFmode. */
79 const int sqdbr; /* cost of square root in DFmode. */
80 const int sqebr; /* cost of square root in SFmode. */
81 /* multiply and add */
82 const int madbr; /* cost of multiply and add in DFmode. */
83 const int maebr; /* cost of multiply and add in SFmode. */
95 const struct processor_costs *s390_cost;
98 struct processor_costs z900_cost =
100 COSTS_N_INSNS (5), /* M */
101 COSTS_N_INSNS (10), /* MGHI */
102 COSTS_N_INSNS (5), /* MH */
103 COSTS_N_INSNS (4), /* MHI */
104 COSTS_N_INSNS (5), /* ML */
105 COSTS_N_INSNS (5), /* MR */
106 COSTS_N_INSNS (4), /* MS */
107 COSTS_N_INSNS (15), /* MSG */
108 COSTS_N_INSNS (7), /* MSGF */
109 COSTS_N_INSNS (7), /* MSGFR */
110 COSTS_N_INSNS (10), /* MSGR */
111 COSTS_N_INSNS (4), /* MSR */
112 COSTS_N_INSNS (7), /* multiplication in DFmode */
113 COSTS_N_INSNS (13), /* MXBR */
114 COSTS_N_INSNS (136), /* SQXBR */
115 COSTS_N_INSNS (44), /* SQDBR */
116 COSTS_N_INSNS (35), /* SQEBR */
117 COSTS_N_INSNS (18), /* MADBR */
118 COSTS_N_INSNS (13), /* MAEBR */
119 COSTS_N_INSNS (134), /* DXBR */
120 COSTS_N_INSNS (30), /* DDBR */
121 COSTS_N_INSNS (27), /* DEBR */
122 COSTS_N_INSNS (220), /* DLGR */
123 COSTS_N_INSNS (34), /* DLR */
124 COSTS_N_INSNS (34), /* DR */
125 COSTS_N_INSNS (32), /* DSGFR */
126 COSTS_N_INSNS (32), /* DSGR */
130 struct processor_costs z990_cost =
132 COSTS_N_INSNS (4), /* M */
133 COSTS_N_INSNS (2), /* MGHI */
134 COSTS_N_INSNS (2), /* MH */
135 COSTS_N_INSNS (2), /* MHI */
136 COSTS_N_INSNS (4), /* ML */
137 COSTS_N_INSNS (4), /* MR */
138 COSTS_N_INSNS (5), /* MS */
139 COSTS_N_INSNS (6), /* MSG */
140 COSTS_N_INSNS (4), /* MSGF */
141 COSTS_N_INSNS (4), /* MSGFR */
142 COSTS_N_INSNS (4), /* MSGR */
143 COSTS_N_INSNS (4), /* MSR */
144 COSTS_N_INSNS (1), /* multiplication in DFmode */
145 COSTS_N_INSNS (28), /* MXBR */
146 COSTS_N_INSNS (130), /* SQXBR */
147 COSTS_N_INSNS (66), /* SQDBR */
148 COSTS_N_INSNS (38), /* SQEBR */
149 COSTS_N_INSNS (1), /* MADBR */
150 COSTS_N_INSNS (1), /* MAEBR */
151 COSTS_N_INSNS (60), /* DXBR */
152 COSTS_N_INSNS (40), /* DDBR */
153 COSTS_N_INSNS (26), /* DEBR */
154 COSTS_N_INSNS (176), /* DLGR */
155 COSTS_N_INSNS (31), /* DLR */
156 COSTS_N_INSNS (31), /* DR */
157 COSTS_N_INSNS (31), /* DSGFR */
158 COSTS_N_INSNS (31), /* DSGR */
162 struct processor_costs z9_109_cost =
164 COSTS_N_INSNS (4), /* M */
165 COSTS_N_INSNS (2), /* MGHI */
166 COSTS_N_INSNS (2), /* MH */
167 COSTS_N_INSNS (2), /* MHI */
168 COSTS_N_INSNS (4), /* ML */
169 COSTS_N_INSNS (4), /* MR */
170 COSTS_N_INSNS (5), /* MS */
171 COSTS_N_INSNS (6), /* MSG */
172 COSTS_N_INSNS (4), /* MSGF */
173 COSTS_N_INSNS (4), /* MSGFR */
174 COSTS_N_INSNS (4), /* MSGR */
175 COSTS_N_INSNS (4), /* MSR */
176 COSTS_N_INSNS (1), /* multiplication in DFmode */
177 COSTS_N_INSNS (28), /* MXBR */
178 COSTS_N_INSNS (130), /* SQXBR */
179 COSTS_N_INSNS (66), /* SQDBR */
180 COSTS_N_INSNS (38), /* SQEBR */
181 COSTS_N_INSNS (1), /* MADBR */
182 COSTS_N_INSNS (1), /* MAEBR */
183 COSTS_N_INSNS (60), /* DXBR */
184 COSTS_N_INSNS (40), /* DDBR */
185 COSTS_N_INSNS (26), /* DEBR */
186 COSTS_N_INSNS (30), /* DLGR */
187 COSTS_N_INSNS (23), /* DLR */
188 COSTS_N_INSNS (23), /* DR */
189 COSTS_N_INSNS (24), /* DSGFR */
190 COSTS_N_INSNS (24), /* DSGR */
194 struct processor_costs z10_cost =
196 COSTS_N_INSNS (10), /* M */
197 COSTS_N_INSNS (10), /* MGHI */
198 COSTS_N_INSNS (10), /* MH */
199 COSTS_N_INSNS (10), /* MHI */
200 COSTS_N_INSNS (10), /* ML */
201 COSTS_N_INSNS (10), /* MR */
202 COSTS_N_INSNS (10), /* MS */
203 COSTS_N_INSNS (10), /* MSG */
204 COSTS_N_INSNS (10), /* MSGF */
205 COSTS_N_INSNS (10), /* MSGFR */
206 COSTS_N_INSNS (10), /* MSGR */
207 COSTS_N_INSNS (10), /* MSR */
208 COSTS_N_INSNS (1) , /* multiplication in DFmode */
209 COSTS_N_INSNS (50), /* MXBR */
210 COSTS_N_INSNS (120), /* SQXBR */
211 COSTS_N_INSNS (52), /* SQDBR */
212 COSTS_N_INSNS (38), /* SQEBR */
213 COSTS_N_INSNS (1), /* MADBR */
214 COSTS_N_INSNS (1), /* MAEBR */
215 COSTS_N_INSNS (111), /* DXBR */
216 COSTS_N_INSNS (39), /* DDBR */
217 COSTS_N_INSNS (32), /* DEBR */
218 COSTS_N_INSNS (160), /* DLGR */
219 COSTS_N_INSNS (71), /* DLR */
220 COSTS_N_INSNS (71), /* DR */
221 COSTS_N_INSNS (71), /* DSGFR */
222 COSTS_N_INSNS (71), /* DSGR */
225 extern int reload_completed;
227 /* Kept up to date using the SCHED_VARIABLE_ISSUE hook. */
228 static rtx last_scheduled_insn;
230 /* Structure used to hold the components of a S/390 memory
231 address. A legitimate address on S/390 is of the general
233 base + index + displacement
234 where any of the components is optional.
236 base and index are registers of the class ADDR_REGS,
237 displacement is an unsigned 12-bit immediate constant. */
248 /* Which cpu are we tuning for. */
249 enum processor_type s390_tune = PROCESSOR_max;
251 /* Which instruction set architecture to use. */
252 enum processor_type s390_arch;
255 HOST_WIDE_INT s390_warn_framesize = 0;
256 HOST_WIDE_INT s390_stack_size = 0;
257 HOST_WIDE_INT s390_stack_guard = 0;
259 /* The following structure is embedded in the machine
260 specific part of struct function. */
262 struct GTY (()) s390_frame_layout
264 /* Offset within stack frame. */
265 HOST_WIDE_INT gprs_offset;
266 HOST_WIDE_INT f0_offset;
267 HOST_WIDE_INT f4_offset;
268 HOST_WIDE_INT f8_offset;
269 HOST_WIDE_INT backchain_offset;
271 /* Number of first and last gpr where slots in the register
272 save area are reserved for. */
273 int first_save_gpr_slot;
274 int last_save_gpr_slot;
276 /* Number of first and last gpr to be saved, restored. */
278 int first_restore_gpr;
280 int last_restore_gpr;
282 /* Bits standing for floating point registers. Set, if the
283 respective register has to be saved. Starting with reg 16 (f0)
284 at the rightmost bit.
285 Bit 15 - 8 7 6 5 4 3 2 1 0
286 fpr 15 - 8 7 5 3 1 6 4 2 0
287 reg 31 - 24 23 22 21 20 19 18 17 16 */
288 unsigned int fpr_bitmap;
290 /* Number of floating point registers f8-f15 which must be saved. */
293 /* Set if return address needs to be saved.
294 This flag is set by s390_return_addr_rtx if it could not use
295 the initial value of r14 and therefore depends on r14 saved
297 bool save_return_addr_p;
299 /* Size of stack frame. */
300 HOST_WIDE_INT frame_size;
303 /* Define the structure for the machine field in struct function. */
305 struct GTY(()) machine_function
307 struct s390_frame_layout frame_layout;
309 /* Literal pool base register. */
312 /* True if we may need to perform branch splitting. */
313 bool split_branches_pending_p;
315 /* Some local-dynamic TLS symbol name. */
316 const char *some_ld_name;
318 bool has_landing_pad_p;
321 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
323 #define cfun_frame_layout (cfun->machine->frame_layout)
324 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
325 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
326 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_WORD)
327 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
329 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
332 /* Number of GPRs and FPRs used for argument passing. */
333 #define GP_ARG_NUM_REG 5
334 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
336 /* A couple of shortcuts. */
337 #define CONST_OK_FOR_J(x) \
338 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
339 #define CONST_OK_FOR_K(x) \
340 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
341 #define CONST_OK_FOR_Os(x) \
342 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
343 #define CONST_OK_FOR_Op(x) \
344 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
345 #define CONST_OK_FOR_On(x) \
346 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
348 #define REGNO_PAIR_OK(REGNO, MODE) \
349 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
351 /* That's the read ahead of the dynamic branch prediction unit in
352 bytes on a z10 CPU. */
353 #define Z10_PREDICT_DISTANCE 384
355 static enum machine_mode
356 s390_libgcc_cmp_return_mode (void)
358 return TARGET_64BIT ? DImode : SImode;
361 static enum machine_mode
362 s390_libgcc_shift_count_mode (void)
364 return TARGET_64BIT ? DImode : SImode;
367 /* Return true if the back end supports mode MODE. */
369 s390_scalar_mode_supported_p (enum machine_mode mode)
371 if (DECIMAL_FLOAT_MODE_P (mode))
372 return default_decimal_float_supported_p ();
374 return default_scalar_mode_supported_p (mode);
377 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
380 s390_set_has_landing_pad_p (bool value)
382 cfun->machine->has_landing_pad_p = value;
385 /* If two condition code modes are compatible, return a condition code
386 mode which is compatible with both. Otherwise, return
389 static enum machine_mode
390 s390_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
398 if (m2 == CCUmode || m2 == CCTmode || m2 == CCZ1mode
399 || m2 == CCSmode || m2 == CCSRmode || m2 == CCURmode)
420 /* Return true if SET either doesn't set the CC register, or else
421 the source and destination have matching CC modes and that
422 CC mode is at least as constrained as REQ_MODE. */
425 s390_match_ccmode_set (rtx set, enum machine_mode req_mode)
427 enum machine_mode set_mode;
429 gcc_assert (GET_CODE (set) == SET);
431 if (GET_CODE (SET_DEST (set)) != REG || !CC_REGNO_P (REGNO (SET_DEST (set))))
434 set_mode = GET_MODE (SET_DEST (set));
448 if (req_mode != set_mode)
453 if (req_mode != CCSmode && req_mode != CCUmode && req_mode != CCTmode
454 && req_mode != CCSRmode && req_mode != CCURmode)
460 if (req_mode != CCAmode)
468 return (GET_MODE (SET_SRC (set)) == set_mode);
471 /* Return true if every SET in INSN that sets the CC register
472 has source and destination with matching CC modes and that
473 CC mode is at least as constrained as REQ_MODE.
474 If REQ_MODE is VOIDmode, always return false. */
477 s390_match_ccmode (rtx insn, enum machine_mode req_mode)
481 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
482 if (req_mode == VOIDmode)
485 if (GET_CODE (PATTERN (insn)) == SET)
486 return s390_match_ccmode_set (PATTERN (insn), req_mode);
488 if (GET_CODE (PATTERN (insn)) == PARALLEL)
489 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
491 rtx set = XVECEXP (PATTERN (insn), 0, i);
492 if (GET_CODE (set) == SET)
493 if (!s390_match_ccmode_set (set, req_mode))
500 /* If a test-under-mask instruction can be used to implement
501 (compare (and ... OP1) OP2), return the CC mode required
502 to do that. Otherwise, return VOIDmode.
503 MIXED is true if the instruction can distinguish between
504 CC1 and CC2 for mixed selected bits (TMxx), it is false
505 if the instruction cannot (TM). */
508 s390_tm_ccmode (rtx op1, rtx op2, bool mixed)
512 /* ??? Fixme: should work on CONST_DOUBLE as well. */
513 if (GET_CODE (op1) != CONST_INT || GET_CODE (op2) != CONST_INT)
516 /* Selected bits all zero: CC0.
517 e.g.: int a; if ((a & (16 + 128)) == 0) */
518 if (INTVAL (op2) == 0)
521 /* Selected bits all one: CC3.
522 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
523 if (INTVAL (op2) == INTVAL (op1))
526 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
528 if ((a & (16 + 128)) == 16) -> CCT1
529 if ((a & (16 + 128)) == 128) -> CCT2 */
532 bit1 = exact_log2 (INTVAL (op2));
533 bit0 = exact_log2 (INTVAL (op1) ^ INTVAL (op2));
534 if (bit0 != -1 && bit1 != -1)
535 return bit0 > bit1 ? CCT1mode : CCT2mode;
541 /* Given a comparison code OP (EQ, NE, etc.) and the operands
542 OP0 and OP1 of a COMPARE, return the mode to be used for the
546 s390_select_ccmode (enum rtx_code code, rtx op0, rtx op1)
552 if ((GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
553 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
555 if (GET_CODE (op0) == PLUS && GET_CODE (XEXP (op0, 1)) == CONST_INT
556 && CONST_OK_FOR_K (INTVAL (XEXP (op0, 1))))
558 if ((GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS
559 || GET_CODE (op1) == NEG)
560 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
563 if (GET_CODE (op0) == AND)
565 /* Check whether we can potentially do it via TM. */
566 enum machine_mode ccmode;
567 ccmode = s390_tm_ccmode (XEXP (op0, 1), op1, 1);
568 if (ccmode != VOIDmode)
570 /* Relax CCTmode to CCZmode to allow fall-back to AND
571 if that turns out to be beneficial. */
572 return ccmode == CCTmode ? CCZmode : ccmode;
576 if (register_operand (op0, HImode)
577 && GET_CODE (op1) == CONST_INT
578 && (INTVAL (op1) == -1 || INTVAL (op1) == 65535))
580 if (register_operand (op0, QImode)
581 && GET_CODE (op1) == CONST_INT
582 && (INTVAL (op1) == -1 || INTVAL (op1) == 255))
591 /* The only overflow condition of NEG and ABS happens when
592 -INT_MAX is used as parameter, which stays negative. So
593 we have an overflow from a positive value to a negative.
594 Using CCAP mode the resulting cc can be used for comparisons. */
595 if ((GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
596 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
599 /* If constants are involved in an add instruction it is possible to use
600 the resulting cc for comparisons with zero. Knowing the sign of the
601 constant the overflow behavior gets predictable. e.g.:
602 int a, b; if ((b = a + c) > 0)
603 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
604 if (GET_CODE (op0) == PLUS && GET_CODE (XEXP (op0, 1)) == CONST_INT
605 && CONST_OK_FOR_K (INTVAL (XEXP (op0, 1))))
607 if (INTVAL (XEXP((op0), 1)) < 0)
621 if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
622 && GET_CODE (op1) != CONST_INT)
628 if (GET_CODE (op0) == PLUS
629 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
632 if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
633 && GET_CODE (op1) != CONST_INT)
639 if (GET_CODE (op0) == MINUS
640 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
643 if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
644 && GET_CODE (op1) != CONST_INT)
653 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
654 that we can implement more efficiently. */
657 s390_canonicalize_comparison (enum rtx_code *code, rtx *op0, rtx *op1)
659 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
660 if ((*code == EQ || *code == NE)
661 && *op1 == const0_rtx
662 && GET_CODE (*op0) == ZERO_EXTRACT
663 && GET_CODE (XEXP (*op0, 1)) == CONST_INT
664 && GET_CODE (XEXP (*op0, 2)) == CONST_INT
665 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0, 0))))
667 rtx inner = XEXP (*op0, 0);
668 HOST_WIDE_INT modesize = GET_MODE_BITSIZE (GET_MODE (inner));
669 HOST_WIDE_INT len = INTVAL (XEXP (*op0, 1));
670 HOST_WIDE_INT pos = INTVAL (XEXP (*op0, 2));
672 if (len > 0 && len < modesize
673 && pos >= 0 && pos + len <= modesize
674 && modesize <= HOST_BITS_PER_WIDE_INT)
676 unsigned HOST_WIDE_INT block;
677 block = ((unsigned HOST_WIDE_INT) 1 << len) - 1;
678 block <<= modesize - pos - len;
680 *op0 = gen_rtx_AND (GET_MODE (inner), inner,
681 gen_int_mode (block, GET_MODE (inner)));
685 /* Narrow AND of memory against immediate to enable TM. */
686 if ((*code == EQ || *code == NE)
687 && *op1 == const0_rtx
688 && GET_CODE (*op0) == AND
689 && GET_CODE (XEXP (*op0, 1)) == CONST_INT
690 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0, 0))))
692 rtx inner = XEXP (*op0, 0);
693 rtx mask = XEXP (*op0, 1);
695 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
696 if (GET_CODE (inner) == SUBREG
697 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner)))
698 && (GET_MODE_SIZE (GET_MODE (inner))
699 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner))))
701 & GET_MODE_MASK (GET_MODE (inner))
702 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner))))
704 inner = SUBREG_REG (inner);
706 /* Do not change volatile MEMs. */
707 if (MEM_P (inner) && !MEM_VOLATILE_P (inner))
709 int part = s390_single_part (XEXP (*op0, 1),
710 GET_MODE (inner), QImode, 0);
713 mask = gen_int_mode (s390_extract_part (mask, QImode, 0), QImode);
714 inner = adjust_address_nv (inner, QImode, part);
715 *op0 = gen_rtx_AND (QImode, inner, mask);
720 /* Narrow comparisons against 0xffff to HImode if possible. */
721 if ((*code == EQ || *code == NE)
722 && GET_CODE (*op1) == CONST_INT
723 && INTVAL (*op1) == 0xffff
724 && SCALAR_INT_MODE_P (GET_MODE (*op0))
725 && (nonzero_bits (*op0, GET_MODE (*op0))
726 & ~(unsigned HOST_WIDE_INT) 0xffff) == 0)
728 *op0 = gen_lowpart (HImode, *op0);
732 /* Remove redundant UNSPEC_CCU_TO_INT conversions if possible. */
733 if (GET_CODE (*op0) == UNSPEC
734 && XINT (*op0, 1) == UNSPEC_CCU_TO_INT
735 && XVECLEN (*op0, 0) == 1
736 && GET_MODE (XVECEXP (*op0, 0, 0)) == CCUmode
737 && GET_CODE (XVECEXP (*op0, 0, 0)) == REG
738 && REGNO (XVECEXP (*op0, 0, 0)) == CC_REGNUM
739 && *op1 == const0_rtx)
741 enum rtx_code new_code = UNKNOWN;
744 case EQ: new_code = EQ; break;
745 case NE: new_code = NE; break;
746 case LT: new_code = GTU; break;
747 case GT: new_code = LTU; break;
748 case LE: new_code = GEU; break;
749 case GE: new_code = LEU; break;
753 if (new_code != UNKNOWN)
755 *op0 = XVECEXP (*op0, 0, 0);
760 /* Remove redundant UNSPEC_CCZ_TO_INT conversions if possible. */
761 if (GET_CODE (*op0) == UNSPEC
762 && XINT (*op0, 1) == UNSPEC_CCZ_TO_INT
763 && XVECLEN (*op0, 0) == 1
764 && GET_MODE (XVECEXP (*op0, 0, 0)) == CCZmode
765 && GET_CODE (XVECEXP (*op0, 0, 0)) == REG
766 && REGNO (XVECEXP (*op0, 0, 0)) == CC_REGNUM
767 && *op1 == const0_rtx)
769 enum rtx_code new_code = UNKNOWN;
772 case EQ: new_code = EQ; break;
773 case NE: new_code = NE; break;
777 if (new_code != UNKNOWN)
779 *op0 = XVECEXP (*op0, 0, 0);
784 /* Simplify cascaded EQ, NE with const0_rtx. */
785 if ((*code == NE || *code == EQ)
786 && (GET_CODE (*op0) == EQ || GET_CODE (*op0) == NE)
787 && GET_MODE (*op0) == SImode
788 && GET_MODE (XEXP (*op0, 0)) == CCZ1mode
789 && REG_P (XEXP (*op0, 0))
790 && XEXP (*op0, 1) == const0_rtx
791 && *op1 == const0_rtx)
793 if ((*code == EQ && GET_CODE (*op0) == NE)
794 || (*code == NE && GET_CODE (*op0) == EQ))
798 *op0 = XEXP (*op0, 0);
801 /* Prefer register over memory as first operand. */
802 if (MEM_P (*op0) && REG_P (*op1))
804 rtx tem = *op0; *op0 = *op1; *op1 = tem;
805 *code = swap_condition (*code);
809 /* Emit a compare instruction suitable to implement the comparison
810 OP0 CODE OP1. Return the correct condition RTL to be placed in
811 the IF_THEN_ELSE of the conditional branch testing the result. */
814 s390_emit_compare (enum rtx_code code, rtx op0, rtx op1)
816 enum machine_mode mode = s390_select_ccmode (code, op0, op1);
819 /* Do not output a redundant compare instruction if a compare_and_swap
820 pattern already computed the result and the machine modes are compatible. */
821 if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
823 gcc_assert (s390_cc_modes_compatible (GET_MODE (op0), mode)
829 cc = gen_rtx_REG (mode, CC_REGNUM);
830 emit_insn (gen_rtx_SET (VOIDmode, cc, gen_rtx_COMPARE (mode, op0, op1)));
833 return gen_rtx_fmt_ee (code, VOIDmode, cc, const0_rtx);
836 /* Emit a SImode compare and swap instruction setting MEM to NEW_RTX if OLD
838 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
839 conditional branch testing the result. */
842 s390_emit_compare_and_swap (enum rtx_code code, rtx old, rtx mem, rtx cmp, rtx new_rtx)
844 emit_insn (gen_sync_compare_and_swapsi (old, mem, cmp, new_rtx));
845 return s390_emit_compare (code, gen_rtx_REG (CCZ1mode, CC_REGNUM), const0_rtx);
848 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
849 unconditional jump, else a conditional jump under condition COND. */
852 s390_emit_jump (rtx target, rtx cond)
856 target = gen_rtx_LABEL_REF (VOIDmode, target);
858 target = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, target, pc_rtx);
860 insn = gen_rtx_SET (VOIDmode, pc_rtx, target);
861 emit_jump_insn (insn);
864 /* Return branch condition mask to implement a branch
865 specified by CODE. Return -1 for invalid comparisons. */
868 s390_branch_condition_mask (rtx code)
870 const int CC0 = 1 << 3;
871 const int CC1 = 1 << 2;
872 const int CC2 = 1 << 1;
873 const int CC3 = 1 << 0;
875 gcc_assert (GET_CODE (XEXP (code, 0)) == REG);
876 gcc_assert (REGNO (XEXP (code, 0)) == CC_REGNUM);
877 gcc_assert (XEXP (code, 1) == const0_rtx);
879 switch (GET_MODE (XEXP (code, 0)))
883 switch (GET_CODE (code))
886 case NE: return CC1 | CC2 | CC3;
892 switch (GET_CODE (code))
895 case NE: return CC0 | CC2 | CC3;
901 switch (GET_CODE (code))
904 case NE: return CC0 | CC1 | CC3;
910 switch (GET_CODE (code))
913 case NE: return CC0 | CC1 | CC2;
919 switch (GET_CODE (code))
921 case EQ: return CC0 | CC2;
922 case NE: return CC1 | CC3;
928 switch (GET_CODE (code))
930 case LTU: return CC2 | CC3; /* carry */
931 case GEU: return CC0 | CC1; /* no carry */
937 switch (GET_CODE (code))
939 case GTU: return CC0 | CC1; /* borrow */
940 case LEU: return CC2 | CC3; /* no borrow */
946 switch (GET_CODE (code))
948 case EQ: return CC0 | CC2;
949 case NE: return CC1 | CC3;
950 case LTU: return CC1;
951 case GTU: return CC3;
952 case LEU: return CC1 | CC2;
953 case GEU: return CC2 | CC3;
958 switch (GET_CODE (code))
961 case NE: return CC1 | CC2 | CC3;
962 case LTU: return CC1;
963 case GTU: return CC2;
964 case LEU: return CC0 | CC1;
965 case GEU: return CC0 | CC2;
971 switch (GET_CODE (code))
974 case NE: return CC2 | CC1 | CC3;
975 case LTU: return CC2;
976 case GTU: return CC1;
977 case LEU: return CC0 | CC2;
978 case GEU: return CC0 | CC1;
984 switch (GET_CODE (code))
987 case NE: return CC1 | CC2 | CC3;
988 case LT: return CC1 | CC3;
990 case LE: return CC0 | CC1 | CC3;
991 case GE: return CC0 | CC2;
997 switch (GET_CODE (code))
1000 case NE: return CC1 | CC2 | CC3;
1001 case LT: return CC1;
1002 case GT: return CC2 | CC3;
1003 case LE: return CC0 | CC1;
1004 case GE: return CC0 | CC2 | CC3;
1010 switch (GET_CODE (code))
1012 case EQ: return CC0;
1013 case NE: return CC1 | CC2 | CC3;
1014 case LT: return CC1;
1015 case GT: return CC2;
1016 case LE: return CC0 | CC1;
1017 case GE: return CC0 | CC2;
1018 case UNORDERED: return CC3;
1019 case ORDERED: return CC0 | CC1 | CC2;
1020 case UNEQ: return CC0 | CC3;
1021 case UNLT: return CC1 | CC3;
1022 case UNGT: return CC2 | CC3;
1023 case UNLE: return CC0 | CC1 | CC3;
1024 case UNGE: return CC0 | CC2 | CC3;
1025 case LTGT: return CC1 | CC2;
1031 switch (GET_CODE (code))
1033 case EQ: return CC0;
1034 case NE: return CC2 | CC1 | CC3;
1035 case LT: return CC2;
1036 case GT: return CC1;
1037 case LE: return CC0 | CC2;
1038 case GE: return CC0 | CC1;
1039 case UNORDERED: return CC3;
1040 case ORDERED: return CC0 | CC2 | CC1;
1041 case UNEQ: return CC0 | CC3;
1042 case UNLT: return CC2 | CC3;
1043 case UNGT: return CC1 | CC3;
1044 case UNLE: return CC0 | CC2 | CC3;
1045 case UNGE: return CC0 | CC1 | CC3;
1046 case LTGT: return CC2 | CC1;
1057 /* Return branch condition mask to implement a compare and branch
1058 specified by CODE. Return -1 for invalid comparisons. */
1061 s390_compare_and_branch_condition_mask (rtx code)
1063 const int CC0 = 1 << 3;
1064 const int CC1 = 1 << 2;
1065 const int CC2 = 1 << 1;
1067 switch (GET_CODE (code))
1091 /* If INV is false, return assembler mnemonic string to implement
1092 a branch specified by CODE. If INV is true, return mnemonic
1093 for the corresponding inverted branch. */
1096 s390_branch_condition_mnemonic (rtx code, int inv)
1100 static const char *const mnemonic[16] =
1102 NULL, "o", "h", "nle",
1103 "l", "nhe", "lh", "ne",
1104 "e", "nlh", "he", "nl",
1105 "le", "nh", "no", NULL
1108 if (GET_CODE (XEXP (code, 0)) == REG
1109 && REGNO (XEXP (code, 0)) == CC_REGNUM
1110 && XEXP (code, 1) == const0_rtx)
1111 mask = s390_branch_condition_mask (code);
1113 mask = s390_compare_and_branch_condition_mask (code);
1115 gcc_assert (mask >= 0);
1120 gcc_assert (mask >= 1 && mask <= 14);
1122 return mnemonic[mask];
1125 /* Return the part of op which has a value different from def.
1126 The size of the part is determined by mode.
1127 Use this function only if you already know that op really
1128 contains such a part. */
1130 unsigned HOST_WIDE_INT
1131 s390_extract_part (rtx op, enum machine_mode mode, int def)
1133 unsigned HOST_WIDE_INT value = 0;
1134 int max_parts = HOST_BITS_PER_WIDE_INT / GET_MODE_BITSIZE (mode);
1135 int part_bits = GET_MODE_BITSIZE (mode);
1136 unsigned HOST_WIDE_INT part_mask
1137 = ((unsigned HOST_WIDE_INT)1 << part_bits) - 1;
1140 for (i = 0; i < max_parts; i++)
1143 value = (unsigned HOST_WIDE_INT) INTVAL (op);
1145 value >>= part_bits;
1147 if ((value & part_mask) != (def & part_mask))
1148 return value & part_mask;
1154 /* If OP is an integer constant of mode MODE with exactly one
1155 part of mode PART_MODE unequal to DEF, return the number of that
1156 part. Otherwise, return -1. */
1159 s390_single_part (rtx op,
1160 enum machine_mode mode,
1161 enum machine_mode part_mode,
1164 unsigned HOST_WIDE_INT value = 0;
1165 int n_parts = GET_MODE_SIZE (mode) / GET_MODE_SIZE (part_mode);
1166 unsigned HOST_WIDE_INT part_mask
1167 = ((unsigned HOST_WIDE_INT)1 << GET_MODE_BITSIZE (part_mode)) - 1;
1170 if (GET_CODE (op) != CONST_INT)
1173 for (i = 0; i < n_parts; i++)
1176 value = (unsigned HOST_WIDE_INT) INTVAL (op);
1178 value >>= GET_MODE_BITSIZE (part_mode);
1180 if ((value & part_mask) != (def & part_mask))
1188 return part == -1 ? -1 : n_parts - 1 - part;
1191 /* Return true if IN contains a contiguous bitfield in the lower SIZE
1192 bits and no other bits are set in IN. POS and LENGTH can be used
1193 to obtain the start position and the length of the bitfield.
1195 POS gives the position of the first bit of the bitfield counting
1196 from the lowest order bit starting with zero. In order to use this
1197 value for S/390 instructions this has to be converted to "bits big
1201 s390_contiguous_bitmask_p (unsigned HOST_WIDE_INT in, int size,
1202 int *pos, int *length)
1207 unsigned HOST_WIDE_INT mask = 1ULL;
1208 bool contiguous = false;
1210 for (i = 0; i < size; mask <<= 1, i++)
1234 /* Calculate a mask for all bits beyond the contiguous bits. */
1235 mask = (-1LL & ~(((1ULL << (tmp_length + tmp_pos - 1)) << 1) - 1));
1240 if (tmp_length + tmp_pos - 1 > size)
1244 *length = tmp_length;
1252 /* Check whether we can (and want to) split a double-word
1253 move in mode MODE from SRC to DST into two single-word
1254 moves, moving the subword FIRST_SUBWORD first. */
1257 s390_split_ok_p (rtx dst, rtx src, enum machine_mode mode, int first_subword)
1259 /* Floating point registers cannot be split. */
1260 if (FP_REG_P (src) || FP_REG_P (dst))
1263 /* We don't need to split if operands are directly accessible. */
1264 if (s_operand (src, mode) || s_operand (dst, mode))
1267 /* Non-offsettable memory references cannot be split. */
1268 if ((GET_CODE (src) == MEM && !offsettable_memref_p (src))
1269 || (GET_CODE (dst) == MEM && !offsettable_memref_p (dst)))
1272 /* Moving the first subword must not clobber a register
1273 needed to move the second subword. */
1274 if (register_operand (dst, mode))
1276 rtx subreg = operand_subword (dst, first_subword, 0, mode);
1277 if (reg_overlap_mentioned_p (subreg, src))
1284 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1285 and [MEM2, MEM2 + SIZE] do overlap and false
1289 s390_overlap_p (rtx mem1, rtx mem2, HOST_WIDE_INT size)
1291 rtx addr1, addr2, addr_delta;
1292 HOST_WIDE_INT delta;
1294 if (GET_CODE (mem1) != MEM || GET_CODE (mem2) != MEM)
1300 addr1 = XEXP (mem1, 0);
1301 addr2 = XEXP (mem2, 0);
1303 addr_delta = simplify_binary_operation (MINUS, Pmode, addr2, addr1);
1305 /* This overlapping check is used by peepholes merging memory block operations.
1306 Overlapping operations would otherwise be recognized by the S/390 hardware
1307 and would fall back to a slower implementation. Allowing overlapping
1308 operations would lead to slow code but not to wrong code. Therefore we are
1309 somewhat optimistic if we cannot prove that the memory blocks are
1311 That's why we return false here although this may accept operations on
1312 overlapping memory areas. */
1313 if (!addr_delta || GET_CODE (addr_delta) != CONST_INT)
1316 delta = INTVAL (addr_delta);
1319 || (delta > 0 && delta < size)
1320 || (delta < 0 && -delta < size))
1326 /* Check whether the address of memory reference MEM2 equals exactly
1327 the address of memory reference MEM1 plus DELTA. Return true if
1328 we can prove this to be the case, false otherwise. */
1331 s390_offset_p (rtx mem1, rtx mem2, rtx delta)
1333 rtx addr1, addr2, addr_delta;
1335 if (GET_CODE (mem1) != MEM || GET_CODE (mem2) != MEM)
1338 addr1 = XEXP (mem1, 0);
1339 addr2 = XEXP (mem2, 0);
1341 addr_delta = simplify_binary_operation (MINUS, Pmode, addr2, addr1);
1342 if (!addr_delta || !rtx_equal_p (addr_delta, delta))
1348 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1351 s390_expand_logical_operator (enum rtx_code code, enum machine_mode mode,
1354 enum machine_mode wmode = mode;
1355 rtx dst = operands[0];
1356 rtx src1 = operands[1];
1357 rtx src2 = operands[2];
1360 /* If we cannot handle the operation directly, use a temp register. */
1361 if (!s390_logical_operator_ok_p (operands))
1362 dst = gen_reg_rtx (mode);
1364 /* QImode and HImode patterns make sense only if we have a destination
1365 in memory. Otherwise perform the operation in SImode. */
1366 if ((mode == QImode || mode == HImode) && GET_CODE (dst) != MEM)
1369 /* Widen operands if required. */
1372 if (GET_CODE (dst) == SUBREG
1373 && (tem = simplify_subreg (wmode, dst, mode, 0)) != 0)
1375 else if (REG_P (dst))
1376 dst = gen_rtx_SUBREG (wmode, dst, 0);
1378 dst = gen_reg_rtx (wmode);
1380 if (GET_CODE (src1) == SUBREG
1381 && (tem = simplify_subreg (wmode, src1, mode, 0)) != 0)
1383 else if (GET_MODE (src1) != VOIDmode)
1384 src1 = gen_rtx_SUBREG (wmode, force_reg (mode, src1), 0);
1386 if (GET_CODE (src2) == SUBREG
1387 && (tem = simplify_subreg (wmode, src2, mode, 0)) != 0)
1389 else if (GET_MODE (src2) != VOIDmode)
1390 src2 = gen_rtx_SUBREG (wmode, force_reg (mode, src2), 0);
1393 /* Emit the instruction. */
1394 op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, wmode, src1, src2));
1395 clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, CC_REGNUM));
1396 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
1398 /* Fix up the destination if needed. */
1399 if (dst != operands[0])
1400 emit_move_insn (operands[0], gen_lowpart (mode, dst));
1403 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1406 s390_logical_operator_ok_p (rtx *operands)
1408 /* If the destination operand is in memory, it needs to coincide
1409 with one of the source operands. After reload, it has to be
1410 the first source operand. */
1411 if (GET_CODE (operands[0]) == MEM)
1412 return rtx_equal_p (operands[0], operands[1])
1413 || (!reload_completed && rtx_equal_p (operands[0], operands[2]));
1418 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1419 operand IMMOP to switch from SS to SI type instructions. */
1422 s390_narrow_logical_operator (enum rtx_code code, rtx *memop, rtx *immop)
1424 int def = code == AND ? -1 : 0;
1428 gcc_assert (GET_CODE (*memop) == MEM);
1429 gcc_assert (!MEM_VOLATILE_P (*memop));
1431 mask = s390_extract_part (*immop, QImode, def);
1432 part = s390_single_part (*immop, GET_MODE (*memop), QImode, def);
1433 gcc_assert (part >= 0);
1435 *memop = adjust_address (*memop, QImode, part);
1436 *immop = gen_int_mode (mask, QImode);
1440 /* How to allocate a 'struct machine_function'. */
1442 static struct machine_function *
1443 s390_init_machine_status (void)
1445 return GGC_CNEW (struct machine_function);
1448 /* Change optimizations to be performed, depending on the
1451 LEVEL is the optimization level specified; 2 if `-O2' is
1452 specified, 1 if `-O' is specified, and 0 if neither is specified.
1454 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1457 optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
1459 /* ??? There are apparently still problems with -fcaller-saves. */
1460 flag_caller_saves = 0;
1462 /* By default, always emit DWARF-2 unwind info. This allows debugging
1463 without maintaining a stack frame back-chain. */
1464 flag_asynchronous_unwind_tables = 1;
1466 /* Use MVCLE instructions to decrease code size if requested. */
1468 target_flags |= MASK_MVCLE;
1471 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1472 to the associated processor_type and processor_flags if so. */
1475 s390_handle_arch_option (const char *arg,
1476 enum processor_type *type,
1481 const char *const name; /* processor name or nickname. */
1482 const enum processor_type processor;
1483 const int flags; /* From enum processor_flags. */
1485 const processor_alias_table[] =
1487 {"g5", PROCESSOR_9672_G5, PF_IEEE_FLOAT},
1488 {"g6", PROCESSOR_9672_G6, PF_IEEE_FLOAT},
1489 {"z900", PROCESSOR_2064_Z900, PF_IEEE_FLOAT | PF_ZARCH},
1490 {"z990", PROCESSOR_2084_Z990, PF_IEEE_FLOAT | PF_ZARCH
1491 | PF_LONG_DISPLACEMENT},
1492 {"z9-109", PROCESSOR_2094_Z9_109, PF_IEEE_FLOAT | PF_ZARCH
1493 | PF_LONG_DISPLACEMENT | PF_EXTIMM},
1494 {"z9-ec", PROCESSOR_2094_Z9_109, PF_IEEE_FLOAT | PF_ZARCH
1495 | PF_LONG_DISPLACEMENT | PF_EXTIMM | PF_DFP },
1496 {"z10", PROCESSOR_2097_Z10, PF_IEEE_FLOAT | PF_ZARCH
1497 | PF_LONG_DISPLACEMENT | PF_EXTIMM | PF_DFP | PF_Z10},
1501 for (i = 0; i < ARRAY_SIZE (processor_alias_table); i++)
1502 if (strcmp (arg, processor_alias_table[i].name) == 0)
1504 *type = processor_alias_table[i].processor;
1505 *flags = processor_alias_table[i].flags;
1511 /* Implement TARGET_HANDLE_OPTION. */
1514 s390_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
1519 return s390_handle_arch_option (arg, &s390_arch, &s390_arch_flags);
1521 case OPT_mstack_guard_:
1522 if (sscanf (arg, HOST_WIDE_INT_PRINT_DEC, &s390_stack_guard) != 1)
1524 if (exact_log2 (s390_stack_guard) == -1)
1525 error ("stack guard value must be an exact power of 2");
1528 case OPT_mstack_size_:
1529 if (sscanf (arg, HOST_WIDE_INT_PRINT_DEC, &s390_stack_size) != 1)
1531 if (exact_log2 (s390_stack_size) == -1)
1532 error ("stack size must be an exact power of 2");
1536 return s390_handle_arch_option (arg, &s390_tune, &s390_tune_flags);
1538 case OPT_mwarn_framesize_:
1539 return sscanf (arg, HOST_WIDE_INT_PRINT_DEC, &s390_warn_framesize) == 1;
1547 override_options (void)
1549 /* Set up function hooks. */
1550 init_machine_status = s390_init_machine_status;
1552 /* Architecture mode defaults according to ABI. */
1553 if (!(target_flags_explicit & MASK_ZARCH))
1556 target_flags |= MASK_ZARCH;
1558 target_flags &= ~MASK_ZARCH;
1561 /* Determine processor architectural level. */
1562 if (!s390_arch_string)
1564 s390_arch_string = TARGET_ZARCH? "z900" : "g5";
1565 s390_handle_arch_option (s390_arch_string, &s390_arch, &s390_arch_flags);
1568 /* Determine processor to tune for. */
1569 if (s390_tune == PROCESSOR_max)
1571 s390_tune = s390_arch;
1572 s390_tune_flags = s390_arch_flags;
1575 /* Sanity checks. */
1576 if (TARGET_ZARCH && !TARGET_CPU_ZARCH)
1577 error ("z/Architecture mode not supported on %s", s390_arch_string);
1578 if (TARGET_64BIT && !TARGET_ZARCH)
1579 error ("64-bit ABI not supported in ESA/390 mode");
1581 if (TARGET_HARD_DFP && !TARGET_DFP)
1583 if (target_flags_explicit & MASK_HARD_DFP)
1585 if (!TARGET_CPU_DFP)
1586 error ("Hardware decimal floating point instructions"
1587 " not available on %s", s390_arch_string);
1589 error ("Hardware decimal floating point instructions"
1590 " not available in ESA/390 mode");
1593 target_flags &= ~MASK_HARD_DFP;
1596 if ((target_flags_explicit & MASK_SOFT_FLOAT) && TARGET_SOFT_FLOAT)
1598 if ((target_flags_explicit & MASK_HARD_DFP) && TARGET_HARD_DFP)
1599 error ("-mhard-dfp can't be used in conjunction with -msoft-float");
1601 target_flags &= ~MASK_HARD_DFP;
1604 /* Set processor cost function. */
1607 case PROCESSOR_2084_Z990:
1608 s390_cost = &z990_cost;
1610 case PROCESSOR_2094_Z9_109:
1611 s390_cost = &z9_109_cost;
1613 case PROCESSOR_2097_Z10:
1614 s390_cost = &z10_cost;
1617 s390_cost = &z900_cost;
1620 if (TARGET_BACKCHAIN && TARGET_PACKED_STACK && TARGET_HARD_FLOAT)
1621 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1624 if (s390_stack_size)
1626 if (s390_stack_guard >= s390_stack_size)
1627 error ("stack size must be greater than the stack guard value");
1628 else if (s390_stack_size > 1 << 16)
1629 error ("stack size must not be greater than 64k");
1631 else if (s390_stack_guard)
1632 error ("-mstack-guard implies use of -mstack-size");
1634 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1635 if (!(target_flags_explicit & MASK_LONG_DOUBLE_128))
1636 target_flags |= MASK_LONG_DOUBLE_128;
1639 if (s390_tune == PROCESSOR_2097_Z10)
1641 if (!PARAM_SET_P (PARAM_MAX_UNROLLED_INSNS))
1642 set_param_value ("max-unrolled-insns", 100);
1643 if (!PARAM_SET_P (PARAM_MAX_UNROLL_TIMES))
1644 set_param_value ("max-unroll-times", 32);
1645 if (!PARAM_SET_P (PARAM_MAX_COMPLETELY_PEELED_INSNS))
1646 set_param_value ("max-completely-peeled-insns", 800);
1647 if (!PARAM_SET_P (PARAM_MAX_COMPLETELY_PEEL_TIMES))
1648 set_param_value ("max-completely-peel-times", 64);
1651 set_param_value ("max-pending-list-length", 256);
1654 /* Map for smallest class containing reg regno. */
1656 const enum reg_class regclass_map[FIRST_PSEUDO_REGISTER] =
1657 { GENERAL_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1658 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1659 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1660 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1661 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1662 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1663 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1664 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1665 ADDR_REGS, CC_REGS, ADDR_REGS, ADDR_REGS,
1666 ACCESS_REGS, ACCESS_REGS
1669 /* Return attribute type of insn. */
1671 static enum attr_type
1672 s390_safe_attr_type (rtx insn)
1674 if (recog_memoized (insn) >= 0)
1675 return get_attr_type (insn);
1680 /* Return true if DISP is a valid short displacement. */
1683 s390_short_displacement (rtx disp)
1685 /* No displacement is OK. */
1689 /* Without the long displacement facility we don't need to
1690 distingiush between long and short displacement. */
1691 if (!TARGET_LONG_DISPLACEMENT)
1694 /* Integer displacement in range. */
1695 if (GET_CODE (disp) == CONST_INT)
1696 return INTVAL (disp) >= 0 && INTVAL (disp) < 4096;
1698 /* GOT offset is not OK, the GOT can be large. */
1699 if (GET_CODE (disp) == CONST
1700 && GET_CODE (XEXP (disp, 0)) == UNSPEC
1701 && (XINT (XEXP (disp, 0), 1) == UNSPEC_GOT
1702 || XINT (XEXP (disp, 0), 1) == UNSPEC_GOTNTPOFF))
1705 /* All other symbolic constants are literal pool references,
1706 which are OK as the literal pool must be small. */
1707 if (GET_CODE (disp) == CONST)
1713 /* Decompose a RTL expression ADDR for a memory address into
1714 its components, returned in OUT.
1716 Returns false if ADDR is not a valid memory address, true
1717 otherwise. If OUT is NULL, don't return the components,
1718 but check for validity only.
1720 Note: Only addresses in canonical form are recognized.
1721 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1722 canonical form so that they will be recognized. */
1725 s390_decompose_address (rtx addr, struct s390_address *out)
1727 HOST_WIDE_INT offset = 0;
1728 rtx base = NULL_RTX;
1729 rtx indx = NULL_RTX;
1730 rtx disp = NULL_RTX;
1732 bool pointer = false;
1733 bool base_ptr = false;
1734 bool indx_ptr = false;
1735 bool literal_pool = false;
1737 /* We may need to substitute the literal pool base register into the address
1738 below. However, at this point we do not know which register is going to
1739 be used as base, so we substitute the arg pointer register. This is going
1740 to be treated as holding a pointer below -- it shouldn't be used for any
1742 rtx fake_pool_base = gen_rtx_REG (Pmode, ARG_POINTER_REGNUM);
1744 /* Decompose address into base + index + displacement. */
1746 if (GET_CODE (addr) == REG || GET_CODE (addr) == UNSPEC)
1749 else if (GET_CODE (addr) == PLUS)
1751 rtx op0 = XEXP (addr, 0);
1752 rtx op1 = XEXP (addr, 1);
1753 enum rtx_code code0 = GET_CODE (op0);
1754 enum rtx_code code1 = GET_CODE (op1);
1756 if (code0 == REG || code0 == UNSPEC)
1758 if (code1 == REG || code1 == UNSPEC)
1760 indx = op0; /* index + base */
1766 base = op0; /* base + displacement */
1771 else if (code0 == PLUS)
1773 indx = XEXP (op0, 0); /* index + base + disp */
1774 base = XEXP (op0, 1);
1785 disp = addr; /* displacement */
1787 /* Extract integer part of displacement. */
1791 if (GET_CODE (disp) == CONST_INT)
1793 offset = INTVAL (disp);
1796 else if (GET_CODE (disp) == CONST
1797 && GET_CODE (XEXP (disp, 0)) == PLUS
1798 && GET_CODE (XEXP (XEXP (disp, 0), 1)) == CONST_INT)
1800 offset = INTVAL (XEXP (XEXP (disp, 0), 1));
1801 disp = XEXP (XEXP (disp, 0), 0);
1805 /* Strip off CONST here to avoid special case tests later. */
1806 if (disp && GET_CODE (disp) == CONST)
1807 disp = XEXP (disp, 0);
1809 /* We can convert literal pool addresses to
1810 displacements by basing them off the base register. */
1811 if (disp && GET_CODE (disp) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (disp))
1813 /* Either base or index must be free to hold the base register. */
1815 base = fake_pool_base, literal_pool = true;
1817 indx = fake_pool_base, literal_pool = true;
1821 /* Mark up the displacement. */
1822 disp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, disp),
1823 UNSPEC_LTREL_OFFSET);
1826 /* Validate base register. */
1829 if (GET_CODE (base) == UNSPEC)
1830 switch (XINT (base, 1))
1834 disp = gen_rtx_UNSPEC (Pmode,
1835 gen_rtvec (1, XVECEXP (base, 0, 0)),
1836 UNSPEC_LTREL_OFFSET);
1840 base = XVECEXP (base, 0, 1);
1843 case UNSPEC_LTREL_BASE:
1844 if (XVECLEN (base, 0) == 1)
1845 base = fake_pool_base, literal_pool = true;
1847 base = XVECEXP (base, 0, 1);
1855 || (GET_MODE (base) != SImode
1856 && GET_MODE (base) != Pmode))
1859 if (REGNO (base) == STACK_POINTER_REGNUM
1860 || REGNO (base) == FRAME_POINTER_REGNUM
1861 || ((reload_completed || reload_in_progress)
1862 && frame_pointer_needed
1863 && REGNO (base) == HARD_FRAME_POINTER_REGNUM)
1864 || REGNO (base) == ARG_POINTER_REGNUM
1866 && REGNO (base) == PIC_OFFSET_TABLE_REGNUM))
1867 pointer = base_ptr = true;
1869 if ((reload_completed || reload_in_progress)
1870 && base == cfun->machine->base_reg)
1871 pointer = base_ptr = literal_pool = true;
1874 /* Validate index register. */
1877 if (GET_CODE (indx) == UNSPEC)
1878 switch (XINT (indx, 1))
1882 disp = gen_rtx_UNSPEC (Pmode,
1883 gen_rtvec (1, XVECEXP (indx, 0, 0)),
1884 UNSPEC_LTREL_OFFSET);
1888 indx = XVECEXP (indx, 0, 1);
1891 case UNSPEC_LTREL_BASE:
1892 if (XVECLEN (indx, 0) == 1)
1893 indx = fake_pool_base, literal_pool = true;
1895 indx = XVECEXP (indx, 0, 1);
1903 || (GET_MODE (indx) != SImode
1904 && GET_MODE (indx) != Pmode))
1907 if (REGNO (indx) == STACK_POINTER_REGNUM
1908 || REGNO (indx) == FRAME_POINTER_REGNUM
1909 || ((reload_completed || reload_in_progress)
1910 && frame_pointer_needed
1911 && REGNO (indx) == HARD_FRAME_POINTER_REGNUM)
1912 || REGNO (indx) == ARG_POINTER_REGNUM
1914 && REGNO (indx) == PIC_OFFSET_TABLE_REGNUM))
1915 pointer = indx_ptr = true;
1917 if ((reload_completed || reload_in_progress)
1918 && indx == cfun->machine->base_reg)
1919 pointer = indx_ptr = literal_pool = true;
1922 /* Prefer to use pointer as base, not index. */
1923 if (base && indx && !base_ptr
1924 && (indx_ptr || (!REG_POINTER (base) && REG_POINTER (indx))))
1931 /* Validate displacement. */
1934 /* If virtual registers are involved, the displacement will change later
1935 anyway as the virtual registers get eliminated. This could make a
1936 valid displacement invalid, but it is more likely to make an invalid
1937 displacement valid, because we sometimes access the register save area
1938 via negative offsets to one of those registers.
1939 Thus we don't check the displacement for validity here. If after
1940 elimination the displacement turns out to be invalid after all,
1941 this is fixed up by reload in any case. */
1942 if (base != arg_pointer_rtx
1943 && indx != arg_pointer_rtx
1944 && base != return_address_pointer_rtx
1945 && indx != return_address_pointer_rtx
1946 && base != frame_pointer_rtx
1947 && indx != frame_pointer_rtx
1948 && base != virtual_stack_vars_rtx
1949 && indx != virtual_stack_vars_rtx)
1950 if (!DISP_IN_RANGE (offset))
1955 /* All the special cases are pointers. */
1958 /* In the small-PIC case, the linker converts @GOT
1959 and @GOTNTPOFF offsets to possible displacements. */
1960 if (GET_CODE (disp) == UNSPEC
1961 && (XINT (disp, 1) == UNSPEC_GOT
1962 || XINT (disp, 1) == UNSPEC_GOTNTPOFF)
1968 /* Accept pool label offsets. */
1969 else if (GET_CODE (disp) == UNSPEC
1970 && XINT (disp, 1) == UNSPEC_POOL_OFFSET)
1973 /* Accept literal pool references. */
1974 else if (GET_CODE (disp) == UNSPEC
1975 && XINT (disp, 1) == UNSPEC_LTREL_OFFSET)
1977 orig_disp = gen_rtx_CONST (Pmode, disp);
1980 /* If we have an offset, make sure it does not
1981 exceed the size of the constant pool entry. */
1982 rtx sym = XVECEXP (disp, 0, 0);
1983 if (offset >= GET_MODE_SIZE (get_pool_mode (sym)))
1986 orig_disp = plus_constant (orig_disp, offset);
2001 out->disp = orig_disp;
2002 out->pointer = pointer;
2003 out->literal_pool = literal_pool;
2009 /* Decompose a RTL expression OP for a shift count into its components,
2010 and return the base register in BASE and the offset in OFFSET.
2012 Return true if OP is a valid shift count, false if not. */
2015 s390_decompose_shift_count (rtx op, rtx *base, HOST_WIDE_INT *offset)
2017 HOST_WIDE_INT off = 0;
2019 /* We can have an integer constant, an address register,
2020 or a sum of the two. */
2021 if (GET_CODE (op) == CONST_INT)
2026 if (op && GET_CODE (op) == PLUS && GET_CODE (XEXP (op, 1)) == CONST_INT)
2028 off = INTVAL (XEXP (op, 1));
2031 while (op && GET_CODE (op) == SUBREG)
2032 op = SUBREG_REG (op);
2034 if (op && GET_CODE (op) != REG)
2046 /* Return true if CODE is a valid address without index. */
2049 s390_legitimate_address_without_index_p (rtx op)
2051 struct s390_address addr;
2053 if (!s390_decompose_address (XEXP (op, 0), &addr))
2062 /* Return true if ADDR is of kind symbol_ref or symbol_ref + const_int
2063 and return these parts in SYMREF and ADDEND. You can pass NULL in
2064 SYMREF and/or ADDEND if you are not interested in these values. */
2067 s390_symref_operand_p (rtx addr, rtx *symref, HOST_WIDE_INT *addend)
2069 HOST_WIDE_INT tmpaddend = 0;
2071 if (GET_CODE (addr) == CONST)
2072 addr = XEXP (addr, 0);
2074 if (GET_CODE (addr) == PLUS)
2076 if (GET_CODE (XEXP (addr, 0)) == SYMBOL_REF
2077 && CONST_INT_P (XEXP (addr, 1)))
2079 tmpaddend = INTVAL (XEXP (addr, 1));
2080 addr = XEXP (addr, 0);
2086 if (GET_CODE (addr) != SYMBOL_REF)
2092 *addend = tmpaddend;
2098 /* Return true if the address in OP is valid for constraint letter C
2099 if wrapped in a MEM rtx. Set LIT_POOL_OK to true if it literal
2100 pool MEMs should be accepted. Only the Q, R, S, T constraint
2101 letters are allowed for C. */
2104 s390_check_qrst_address (char c, rtx op, bool lit_pool_ok)
2106 struct s390_address addr;
2107 bool decomposed = false;
2109 /* This check makes sure that no symbolic address (except literal
2110 pool references) are accepted by the R or T constraints. */
2111 if (s390_symref_operand_p (op, NULL, NULL))
2115 if (!s390_decompose_address (op, &addr))
2117 if (!addr.literal_pool)
2124 case 'Q': /* no index short displacement */
2125 if (!decomposed && !s390_decompose_address (op, &addr))
2129 if (!s390_short_displacement (addr.disp))
2133 case 'R': /* with index short displacement */
2134 if (TARGET_LONG_DISPLACEMENT)
2136 if (!decomposed && !s390_decompose_address (op, &addr))
2138 if (!s390_short_displacement (addr.disp))
2141 /* Any invalid address here will be fixed up by reload,
2142 so accept it for the most generic constraint. */
2145 case 'S': /* no index long displacement */
2146 if (!TARGET_LONG_DISPLACEMENT)
2148 if (!decomposed && !s390_decompose_address (op, &addr))
2152 if (s390_short_displacement (addr.disp))
2156 case 'T': /* with index long displacement */
2157 if (!TARGET_LONG_DISPLACEMENT)
2159 /* Any invalid address here will be fixed up by reload,
2160 so accept it for the most generic constraint. */
2161 if ((decomposed || s390_decompose_address (op, &addr))
2162 && s390_short_displacement (addr.disp))
2172 /* Evaluates constraint strings described by the regular expression
2173 ([A|B|Z](Q|R|S|T))|U|W|Y and returns 1 if OP is a valid operand for
2174 the constraint given in STR, or 0 else. */
2177 s390_mem_constraint (const char *str, rtx op)
2184 /* Check for offsettable variants of memory constraints. */
2185 if (!MEM_P (op) || MEM_VOLATILE_P (op))
2187 if ((reload_completed || reload_in_progress)
2188 ? !offsettable_memref_p (op) : !offsettable_nonstrict_memref_p (op))
2190 return s390_check_qrst_address (str[1], XEXP (op, 0), true);
2192 /* Check for non-literal-pool variants of memory constraints. */
2195 return s390_check_qrst_address (str[1], XEXP (op, 0), false);
2200 if (GET_CODE (op) != MEM)
2202 return s390_check_qrst_address (c, XEXP (op, 0), true);
2204 return (s390_check_qrst_address ('Q', op, true)
2205 || s390_check_qrst_address ('R', op, true));
2207 return (s390_check_qrst_address ('S', op, true)
2208 || s390_check_qrst_address ('T', op, true));
2210 /* Simply check for the basic form of a shift count. Reload will
2211 take care of making sure we have a proper base register. */
2212 if (!s390_decompose_shift_count (op, NULL, NULL))
2216 return s390_check_qrst_address (str[1], op, true);
2224 /* Evaluates constraint strings starting with letter O. Input
2225 parameter C is the second letter following the "O" in the constraint
2226 string. Returns 1 if VALUE meets the respective constraint and 0
2230 s390_O_constraint_str (const char c, HOST_WIDE_INT value)
2238 return trunc_int_for_mode (value, SImode) == value;
2242 || s390_single_part (GEN_INT (value), DImode, SImode, 0) == 1;
2245 return s390_single_part (GEN_INT (value - 1), DImode, SImode, -1) == 1;
2253 /* Evaluates constraint strings starting with letter N. Parameter STR
2254 contains the letters following letter "N" in the constraint string.
2255 Returns true if VALUE matches the constraint. */
2258 s390_N_constraint_str (const char *str, HOST_WIDE_INT value)
2260 enum machine_mode mode, part_mode;
2262 int part, part_goal;
2268 part_goal = str[0] - '0';
2312 if (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (part_mode))
2315 part = s390_single_part (GEN_INT (value), mode, part_mode, def);
2318 if (part_goal != -1 && part_goal != part)
2325 /* Returns true if the input parameter VALUE is a float zero. */
2328 s390_float_const_zero_p (rtx value)
2330 return (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT
2331 && value == CONST0_RTX (GET_MODE (value)));
2335 /* Compute a (partial) cost for rtx X. Return true if the complete
2336 cost has been computed, and false if subexpressions should be
2337 scanned. In either case, *TOTAL contains the cost result.
2338 CODE contains GET_CODE (x), OUTER_CODE contains the code
2339 of the superexpression of x. */
2342 s390_rtx_costs (rtx x, int code, int outer_code, int *total,
2343 bool speed ATTRIBUTE_UNUSED)
2366 *total = COSTS_N_INSNS (1);
2371 /* Check for multiply and add. */
2372 if ((GET_MODE (x) == DFmode || GET_MODE (x) == SFmode)
2373 && GET_CODE (XEXP (x, 0)) == MULT
2374 && TARGET_HARD_FLOAT && TARGET_FUSED_MADD)
2376 /* This is the multiply and add case. */
2377 if (GET_MODE (x) == DFmode)
2378 *total = s390_cost->madbr;
2380 *total = s390_cost->maebr;
2381 *total += (rtx_cost (XEXP (XEXP (x, 0), 0), MULT, speed)
2382 + rtx_cost (XEXP (XEXP (x, 0), 1), MULT, speed)
2383 + rtx_cost (XEXP (x, 1), (enum rtx_code) code, speed));
2384 return true; /* Do not do an additional recursive descent. */
2386 *total = COSTS_N_INSNS (1);
2390 switch (GET_MODE (x))
2394 rtx left = XEXP (x, 0);
2395 rtx right = XEXP (x, 1);
2396 if (GET_CODE (right) == CONST_INT
2397 && CONST_OK_FOR_K (INTVAL (right)))
2398 *total = s390_cost->mhi;
2399 else if (GET_CODE (left) == SIGN_EXTEND)
2400 *total = s390_cost->mh;
2402 *total = s390_cost->ms; /* msr, ms, msy */
2407 rtx left = XEXP (x, 0);
2408 rtx right = XEXP (x, 1);
2411 if (GET_CODE (right) == CONST_INT
2412 && CONST_OK_FOR_K (INTVAL (right)))
2413 *total = s390_cost->mghi;
2414 else if (GET_CODE (left) == SIGN_EXTEND)
2415 *total = s390_cost->msgf;
2417 *total = s390_cost->msg; /* msgr, msg */
2419 else /* TARGET_31BIT */
2421 if (GET_CODE (left) == SIGN_EXTEND
2422 && GET_CODE (right) == SIGN_EXTEND)
2423 /* mulsidi case: mr, m */
2424 *total = s390_cost->m;
2425 else if (GET_CODE (left) == ZERO_EXTEND
2426 && GET_CODE (right) == ZERO_EXTEND
2427 && TARGET_CPU_ZARCH)
2428 /* umulsidi case: ml, mlr */
2429 *total = s390_cost->ml;
2431 /* Complex calculation is required. */
2432 *total = COSTS_N_INSNS (40);
2438 *total = s390_cost->mult_df;
2441 *total = s390_cost->mxbr;
2450 if (GET_MODE (x) == TImode) /* 128 bit division */
2451 *total = s390_cost->dlgr;
2452 else if (GET_MODE (x) == DImode)
2454 rtx right = XEXP (x, 1);
2455 if (GET_CODE (right) == ZERO_EXTEND) /* 64 by 32 bit division */
2456 *total = s390_cost->dlr;
2457 else /* 64 by 64 bit division */
2458 *total = s390_cost->dlgr;
2460 else if (GET_MODE (x) == SImode) /* 32 bit division */
2461 *total = s390_cost->dlr;
2466 if (GET_MODE (x) == DImode)
2468 rtx right = XEXP (x, 1);
2469 if (GET_CODE (right) == ZERO_EXTEND) /* 64 by 32 bit division */
2471 *total = s390_cost->dsgfr;
2473 *total = s390_cost->dr;
2474 else /* 64 by 64 bit division */
2475 *total = s390_cost->dsgr;
2477 else if (GET_MODE (x) == SImode) /* 32 bit division */
2478 *total = s390_cost->dlr;
2479 else if (GET_MODE (x) == SFmode)
2481 *total = s390_cost->debr;
2483 else if (GET_MODE (x) == DFmode)
2485 *total = s390_cost->ddbr;
2487 else if (GET_MODE (x) == TFmode)
2489 *total = s390_cost->dxbr;
2494 if (GET_MODE (x) == SFmode)
2495 *total = s390_cost->sqebr;
2496 else if (GET_MODE (x) == DFmode)
2497 *total = s390_cost->sqdbr;
2499 *total = s390_cost->sqxbr;
2504 if (outer_code == MULT || outer_code == DIV || outer_code == MOD
2505 || outer_code == PLUS || outer_code == MINUS
2506 || outer_code == COMPARE)
2511 *total = COSTS_N_INSNS (1);
2512 if (GET_CODE (XEXP (x, 0)) == AND
2513 && GET_CODE (XEXP (x, 1)) == CONST_INT
2514 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
2516 rtx op0 = XEXP (XEXP (x, 0), 0);
2517 rtx op1 = XEXP (XEXP (x, 0), 1);
2518 rtx op2 = XEXP (x, 1);
2520 if (memory_operand (op0, GET_MODE (op0))
2521 && s390_tm_ccmode (op1, op2, 0) != VOIDmode)
2523 if (register_operand (op0, GET_MODE (op0))
2524 && s390_tm_ccmode (op1, op2, 1) != VOIDmode)
2534 /* Return the cost of an address rtx ADDR. */
2537 s390_address_cost (rtx addr, bool speed ATTRIBUTE_UNUSED)
2539 struct s390_address ad;
2540 if (!s390_decompose_address (addr, &ad))
2543 return ad.indx? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2546 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2547 otherwise return 0. */
2550 tls_symbolic_operand (rtx op)
2552 if (GET_CODE (op) != SYMBOL_REF)
2554 return SYMBOL_REF_TLS_MODEL (op);
2557 /* Split DImode access register reference REG (on 64-bit) into its constituent
2558 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2559 gen_highpart cannot be used as they assume all registers are word-sized,
2560 while our access registers have only half that size. */
2563 s390_split_access_reg (rtx reg, rtx *lo, rtx *hi)
2565 gcc_assert (TARGET_64BIT);
2566 gcc_assert (ACCESS_REG_P (reg));
2567 gcc_assert (GET_MODE (reg) == DImode);
2568 gcc_assert (!(REGNO (reg) & 1));
2570 *lo = gen_rtx_REG (SImode, REGNO (reg) + 1);
2571 *hi = gen_rtx_REG (SImode, REGNO (reg));
2574 /* Return true if OP contains a symbol reference */
2577 symbolic_reference_mentioned_p (rtx op)
2582 if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
2585 fmt = GET_RTX_FORMAT (GET_CODE (op));
2586 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
2592 for (j = XVECLEN (op, i) - 1; j >= 0; j--)
2593 if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
2597 else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
2604 /* Return true if OP contains a reference to a thread-local symbol. */
2607 tls_symbolic_reference_mentioned_p (rtx op)
2612 if (GET_CODE (op) == SYMBOL_REF)
2613 return tls_symbolic_operand (op);
2615 fmt = GET_RTX_FORMAT (GET_CODE (op));
2616 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
2622 for (j = XVECLEN (op, i) - 1; j >= 0; j--)
2623 if (tls_symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
2627 else if (fmt[i] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op, i)))
2635 /* Return true if OP is a legitimate general operand when
2636 generating PIC code. It is given that flag_pic is on
2637 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2640 legitimate_pic_operand_p (rtx op)
2642 /* Accept all non-symbolic constants. */
2643 if (!SYMBOLIC_CONST (op))
2646 /* Reject everything else; must be handled
2647 via emit_symbolic_move. */
2651 /* Returns true if the constant value OP is a legitimate general operand.
2652 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2655 legitimate_constant_p (rtx op)
2657 /* Accept all non-symbolic constants. */
2658 if (!SYMBOLIC_CONST (op))
2661 /* Accept immediate LARL operands. */
2662 if (TARGET_CPU_ZARCH && larl_operand (op, VOIDmode))
2665 /* Thread-local symbols are never legal constants. This is
2666 so that emit_call knows that computing such addresses
2667 might require a function call. */
2668 if (TLS_SYMBOLIC_CONST (op))
2671 /* In the PIC case, symbolic constants must *not* be
2672 forced into the literal pool. We accept them here,
2673 so that they will be handled by emit_symbolic_move. */
2677 /* All remaining non-PIC symbolic constants are
2678 forced into the literal pool. */
2682 /* Determine if it's legal to put X into the constant pool. This
2683 is not possible if X contains the address of a symbol that is
2684 not constant (TLS) or not known at final link time (PIC). */
2687 s390_cannot_force_const_mem (rtx x)
2689 switch (GET_CODE (x))
2693 /* Accept all non-symbolic constants. */
2697 /* Labels are OK iff we are non-PIC. */
2698 return flag_pic != 0;
2701 /* 'Naked' TLS symbol references are never OK,
2702 non-TLS symbols are OK iff we are non-PIC. */
2703 if (tls_symbolic_operand (x))
2706 return flag_pic != 0;
2709 return s390_cannot_force_const_mem (XEXP (x, 0));
2712 return s390_cannot_force_const_mem (XEXP (x, 0))
2713 || s390_cannot_force_const_mem (XEXP (x, 1));
2716 switch (XINT (x, 1))
2718 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2719 case UNSPEC_LTREL_OFFSET:
2727 case UNSPEC_GOTNTPOFF:
2728 case UNSPEC_INDNTPOFF:
2731 /* If the literal pool shares the code section, be put
2732 execute template placeholders into the pool as well. */
2734 return TARGET_CPU_ZARCH;
2746 /* Returns true if the constant value OP is a legitimate general
2747 operand during and after reload. The difference to
2748 legitimate_constant_p is that this function will not accept
2749 a constant that would need to be forced to the literal pool
2750 before it can be used as operand. */
2753 legitimate_reload_constant_p (rtx op)
2755 /* Accept la(y) operands. */
2756 if (GET_CODE (op) == CONST_INT
2757 && DISP_IN_RANGE (INTVAL (op)))
2760 /* Accept l(g)hi/l(g)fi operands. */
2761 if (GET_CODE (op) == CONST_INT
2762 && (CONST_OK_FOR_K (INTVAL (op)) || CONST_OK_FOR_Os (INTVAL (op))))
2765 /* Accept lliXX operands. */
2767 && GET_CODE (op) == CONST_INT
2768 && trunc_int_for_mode (INTVAL (op), word_mode) == INTVAL (op)
2769 && s390_single_part (op, word_mode, HImode, 0) >= 0)
2773 && GET_CODE (op) == CONST_INT
2774 && trunc_int_for_mode (INTVAL (op), word_mode) == INTVAL (op)
2775 && s390_single_part (op, word_mode, SImode, 0) >= 0)
2778 /* Accept larl operands. */
2779 if (TARGET_CPU_ZARCH
2780 && larl_operand (op, VOIDmode))
2783 /* Accept lzXX operands. */
2784 if (GET_CODE (op) == CONST_DOUBLE
2785 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', "G"))
2788 /* Accept double-word operands that can be split. */
2789 if (GET_CODE (op) == CONST_INT
2790 && trunc_int_for_mode (INTVAL (op), word_mode) != INTVAL (op))
2792 enum machine_mode dword_mode = word_mode == SImode ? DImode : TImode;
2793 rtx hi = operand_subword (op, 0, 0, dword_mode);
2794 rtx lo = operand_subword (op, 1, 0, dword_mode);
2795 return legitimate_reload_constant_p (hi)
2796 && legitimate_reload_constant_p (lo);
2799 /* Everything else cannot be handled without reload. */
2803 /* Given an rtx OP being reloaded into a reg required to be in class RCLASS,
2804 return the class of reg to actually use. */
2807 s390_preferred_reload_class (rtx op, enum reg_class rclass)
2809 switch (GET_CODE (op))
2811 /* Constants we cannot reload must be forced into the
2816 if (legitimate_reload_constant_p (op))
2821 /* If a symbolic constant or a PLUS is reloaded,
2822 it is most likely being used as an address, so
2823 prefer ADDR_REGS. If 'class' is not a superset
2824 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2829 if (reg_class_subset_p (ADDR_REGS, rclass))
2841 /* Return true if ADDR is SYMBOL_REF + addend with addend being a
2842 multiple of ALIGNMENT and the SYMBOL_REF being naturally
2846 s390_check_symref_alignment (rtx addr, HOST_WIDE_INT alignment)
2848 HOST_WIDE_INT addend;
2851 if (!s390_symref_operand_p (addr, &symref, &addend))
2854 return (!SYMBOL_REF_NOT_NATURALLY_ALIGNED_P (symref)
2855 && !(addend & (alignment - 1)));
2858 /* ADDR is moved into REG using larl. If ADDR isn't a valid larl
2859 operand SCRATCH is used to reload the even part of the address and
2863 s390_reload_larl_operand (rtx reg, rtx addr, rtx scratch)
2865 HOST_WIDE_INT addend;
2868 if (!s390_symref_operand_p (addr, &symref, &addend))
2872 /* Easy case. The addend is even so larl will do fine. */
2873 emit_move_insn (reg, addr);
2876 /* We can leave the scratch register untouched if the target
2877 register is a valid base register. */
2878 if (REGNO (reg) < FIRST_PSEUDO_REGISTER
2879 && REGNO_REG_CLASS (REGNO (reg)) == ADDR_REGS)
2882 gcc_assert (REGNO (scratch) < FIRST_PSEUDO_REGISTER);
2883 gcc_assert (REGNO_REG_CLASS (REGNO (scratch)) == ADDR_REGS);
2886 emit_move_insn (scratch,
2887 gen_rtx_CONST (Pmode,
2888 gen_rtx_PLUS (Pmode, symref,
2889 GEN_INT (addend - 1))));
2891 emit_move_insn (scratch, symref);
2893 /* Increment the address using la in order to avoid clobbering cc. */
2894 emit_move_insn (reg, gen_rtx_PLUS (Pmode, scratch, const1_rtx));
2898 /* Generate what is necessary to move between REG and MEM using
2899 SCRATCH. The direction is given by TOMEM. */
2902 s390_reload_symref_address (rtx reg, rtx mem, rtx scratch, bool tomem)
2904 /* Reload might have pulled a constant out of the literal pool.
2905 Force it back in. */
2906 if (CONST_INT_P (mem) || GET_CODE (mem) == CONST_DOUBLE
2907 || GET_CODE (mem) == CONST)
2908 mem = force_const_mem (GET_MODE (reg), mem);
2910 gcc_assert (MEM_P (mem));
2912 /* For a load from memory we can leave the scratch register
2913 untouched if the target register is a valid base register. */
2915 && REGNO (reg) < FIRST_PSEUDO_REGISTER
2916 && REGNO_REG_CLASS (REGNO (reg)) == ADDR_REGS
2917 && GET_MODE (reg) == GET_MODE (scratch))
2920 /* Load address into scratch register. Since we can't have a
2921 secondary reload for a secondary reload we have to cover the case
2922 where larl would need a secondary reload here as well. */
2923 s390_reload_larl_operand (scratch, XEXP (mem, 0), scratch);
2925 /* Now we can use a standard load/store to do the move. */
2927 emit_move_insn (replace_equiv_address (mem, scratch), reg);
2929 emit_move_insn (reg, replace_equiv_address (mem, scratch));
2932 /* Inform reload about cases where moving X with a mode MODE to a register in
2933 RCLASS requires an extra scratch or immediate register. Return the class
2934 needed for the immediate register. */
2936 static enum reg_class
2937 s390_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
2938 enum machine_mode mode, secondary_reload_info *sri)
2940 /* Intermediate register needed. */
2941 if (reg_classes_intersect_p (CC_REGS, rclass))
2942 return GENERAL_REGS;
2946 /* On z10 several optimizer steps may generate larl operands with
2949 && s390_symref_operand_p (x, NULL, NULL)
2951 && !s390_check_symref_alignment (x, 2))
2952 sri->icode = ((mode == DImode) ? CODE_FOR_reloaddi_larl_odd_addend_z10
2953 : CODE_FOR_reloadsi_larl_odd_addend_z10);
2955 /* On z10 we need a scratch register when moving QI, TI or floating
2956 point mode values from or to a memory location with a SYMBOL_REF
2957 or if the symref addend of a SI or DI move is not aligned to the
2958 width of the access. */
2960 && s390_symref_operand_p (XEXP (x, 0), NULL, NULL)
2961 && (mode == QImode || mode == TImode || FLOAT_MODE_P (mode)
2962 || (!TARGET_64BIT && mode == DImode)
2963 || ((mode == HImode || mode == SImode || mode == DImode)
2964 && (!s390_check_symref_alignment (XEXP (x, 0),
2965 GET_MODE_SIZE (mode))))))
2967 #define __SECONDARY_RELOAD_CASE(M,m) \
2970 sri->icode = in_p ? CODE_FOR_reload##m##di_toreg_z10 : \
2971 CODE_FOR_reload##m##di_tomem_z10; \
2973 sri->icode = in_p ? CODE_FOR_reload##m##si_toreg_z10 : \
2974 CODE_FOR_reload##m##si_tomem_z10; \
2977 switch (GET_MODE (x))
2979 __SECONDARY_RELOAD_CASE (QI, qi);
2980 __SECONDARY_RELOAD_CASE (HI, hi);
2981 __SECONDARY_RELOAD_CASE (SI, si);
2982 __SECONDARY_RELOAD_CASE (DI, di);
2983 __SECONDARY_RELOAD_CASE (TI, ti);
2984 __SECONDARY_RELOAD_CASE (SF, sf);
2985 __SECONDARY_RELOAD_CASE (DF, df);
2986 __SECONDARY_RELOAD_CASE (TF, tf);
2987 __SECONDARY_RELOAD_CASE (SD, sd);
2988 __SECONDARY_RELOAD_CASE (DD, dd);
2989 __SECONDARY_RELOAD_CASE (TD, td);
2994 #undef __SECONDARY_RELOAD_CASE
2998 /* We need a scratch register when loading a PLUS expression which
2999 is not a legitimate operand of the LOAD ADDRESS instruction. */
3000 if (in_p && s390_plus_operand (x, mode))
3001 sri->icode = (TARGET_64BIT ?
3002 CODE_FOR_reloaddi_plus : CODE_FOR_reloadsi_plus);
3004 /* Performing a multiword move from or to memory we have to make sure the
3005 second chunk in memory is addressable without causing a displacement
3006 overflow. If that would be the case we calculate the address in
3007 a scratch register. */
3009 && GET_CODE (XEXP (x, 0)) == PLUS
3010 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3011 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x, 0), 1))
3012 + GET_MODE_SIZE (mode) - 1))
3014 /* For GENERAL_REGS a displacement overflow is no problem if occurring
3015 in a s_operand address since we may fallback to lm/stm. So we only
3016 have to care about overflows in the b+i+d case. */
3017 if ((reg_classes_intersect_p (GENERAL_REGS, rclass)
3018 && s390_class_max_nregs (GENERAL_REGS, mode) > 1
3019 && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS)
3020 /* For FP_REGS no lm/stm is available so this check is triggered
3021 for displacement overflows in b+i+d and b+d like addresses. */
3022 || (reg_classes_intersect_p (FP_REGS, rclass)
3023 && s390_class_max_nregs (FP_REGS, mode) > 1))
3026 sri->icode = (TARGET_64BIT ?
3027 CODE_FOR_reloaddi_nonoffmem_in :
3028 CODE_FOR_reloadsi_nonoffmem_in);
3030 sri->icode = (TARGET_64BIT ?
3031 CODE_FOR_reloaddi_nonoffmem_out :
3032 CODE_FOR_reloadsi_nonoffmem_out);
3036 /* A scratch address register is needed when a symbolic constant is
3037 copied to r0 compiling with -fPIC. In other cases the target
3038 register might be used as temporary (see legitimize_pic_address). */
3039 if (in_p && SYMBOLIC_CONST (x) && flag_pic == 2 && rclass != ADDR_REGS)
3040 sri->icode = (TARGET_64BIT ?
3041 CODE_FOR_reloaddi_PIC_addr :
3042 CODE_FOR_reloadsi_PIC_addr);
3044 /* Either scratch or no register needed. */
3048 /* Generate code to load SRC, which is PLUS that is not a
3049 legitimate operand for the LA instruction, into TARGET.
3050 SCRATCH may be used as scratch register. */
3053 s390_expand_plus_operand (rtx target, rtx src,
3057 struct s390_address ad;
3059 /* src must be a PLUS; get its two operands. */
3060 gcc_assert (GET_CODE (src) == PLUS);
3061 gcc_assert (GET_MODE (src) == Pmode);
3063 /* Check if any of the two operands is already scheduled
3064 for replacement by reload. This can happen e.g. when
3065 float registers occur in an address. */
3066 sum1 = find_replacement (&XEXP (src, 0));
3067 sum2 = find_replacement (&XEXP (src, 1));
3068 src = gen_rtx_PLUS (Pmode, sum1, sum2);
3070 /* If the address is already strictly valid, there's nothing to do. */
3071 if (!s390_decompose_address (src, &ad)
3072 || (ad.base && !REGNO_OK_FOR_BASE_P (REGNO (ad.base)))
3073 || (ad.indx && !REGNO_OK_FOR_INDEX_P (REGNO (ad.indx))))
3075 /* Otherwise, one of the operands cannot be an address register;
3076 we reload its value into the scratch register. */
3077 if (true_regnum (sum1) < 1 || true_regnum (sum1) > 15)
3079 emit_move_insn (scratch, sum1);
3082 if (true_regnum (sum2) < 1 || true_regnum (sum2) > 15)
3084 emit_move_insn (scratch, sum2);
3088 /* According to the way these invalid addresses are generated
3089 in reload.c, it should never happen (at least on s390) that
3090 *neither* of the PLUS components, after find_replacements
3091 was applied, is an address register. */
3092 if (sum1 == scratch && sum2 == scratch)
3098 src = gen_rtx_PLUS (Pmode, sum1, sum2);
3101 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
3102 is only ever performed on addresses, so we can mark the
3103 sum as legitimate for LA in any case. */
3104 s390_load_address (target, src);
3108 /* Return true if ADDR is a valid memory address.
3109 STRICT specifies whether strict register checking applies. */
3112 s390_legitimate_address_p (enum machine_mode mode, rtx addr, bool strict)
3114 struct s390_address ad;
3117 && larl_operand (addr, VOIDmode)
3118 && (mode == VOIDmode
3119 || s390_check_symref_alignment (addr, GET_MODE_SIZE (mode))))
3122 if (!s390_decompose_address (addr, &ad))
3127 if (ad.base && !REGNO_OK_FOR_BASE_P (REGNO (ad.base)))
3130 if (ad.indx && !REGNO_OK_FOR_INDEX_P (REGNO (ad.indx)))
3136 && !(REGNO (ad.base) >= FIRST_PSEUDO_REGISTER
3137 || REGNO_REG_CLASS (REGNO (ad.base)) == ADDR_REGS))
3141 && !(REGNO (ad.indx) >= FIRST_PSEUDO_REGISTER
3142 || REGNO_REG_CLASS (REGNO (ad.indx)) == ADDR_REGS))
3148 /* Return true if OP is a valid operand for the LA instruction.
3149 In 31-bit, we need to prove that the result is used as an
3150 address, as LA performs only a 31-bit addition. */
3153 legitimate_la_operand_p (rtx op)
3155 struct s390_address addr;
3156 if (!s390_decompose_address (op, &addr))
3159 return (TARGET_64BIT || addr.pointer);
3162 /* Return true if it is valid *and* preferable to use LA to
3163 compute the sum of OP1 and OP2. */
3166 preferred_la_operand_p (rtx op1, rtx op2)
3168 struct s390_address addr;
3170 if (op2 != const0_rtx)
3171 op1 = gen_rtx_PLUS (Pmode, op1, op2);
3173 if (!s390_decompose_address (op1, &addr))
3175 if (addr.base && !REGNO_OK_FOR_BASE_P (REGNO (addr.base)))
3177 if (addr.indx && !REGNO_OK_FOR_INDEX_P (REGNO (addr.indx)))
3180 if (!TARGET_64BIT && !addr.pointer)
3186 if ((addr.base && REG_P (addr.base) && REG_POINTER (addr.base))
3187 || (addr.indx && REG_P (addr.indx) && REG_POINTER (addr.indx)))
3193 /* Emit a forced load-address operation to load SRC into DST.
3194 This will use the LOAD ADDRESS instruction even in situations
3195 where legitimate_la_operand_p (SRC) returns false. */
3198 s390_load_address (rtx dst, rtx src)
3201 emit_move_insn (dst, src);
3203 emit_insn (gen_force_la_31 (dst, src));
3206 /* Return a legitimate reference for ORIG (an address) using the
3207 register REG. If REG is 0, a new pseudo is generated.
3209 There are two types of references that must be handled:
3211 1. Global data references must load the address from the GOT, via
3212 the PIC reg. An insn is emitted to do this load, and the reg is
3215 2. Static data references, constant pool addresses, and code labels
3216 compute the address as an offset from the GOT, whose base is in
3217 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
3218 differentiate them from global data objects. The returned
3219 address is the PIC reg + an unspec constant.
3221 TARGET_LEGITIMIZE_ADDRESS_P rejects symbolic references unless the PIC
3222 reg also appears in the address. */
3225 legitimize_pic_address (rtx orig, rtx reg)
3231 gcc_assert (!TLS_SYMBOLIC_CONST (addr));
3233 if (GET_CODE (addr) == LABEL_REF
3234 || (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (addr)))
3236 /* This is a local symbol. */
3237 if (TARGET_CPU_ZARCH && larl_operand (addr, VOIDmode))
3239 /* Access local symbols PC-relative via LARL.
3240 This is the same as in the non-PIC case, so it is
3241 handled automatically ... */
3245 /* Access local symbols relative to the GOT. */
3247 rtx temp = reg? reg : gen_reg_rtx (Pmode);
3249 if (reload_in_progress || reload_completed)
3250 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3252 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
3253 addr = gen_rtx_CONST (Pmode, addr);
3254 addr = force_const_mem (Pmode, addr);
3255 emit_move_insn (temp, addr);
3257 new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
3260 s390_load_address (reg, new_rtx);
3265 else if (GET_CODE (addr) == SYMBOL_REF)
3268 reg = gen_reg_rtx (Pmode);
3272 /* Assume GOT offset < 4k. This is handled the same way
3273 in both 31- and 64-bit code (@GOT). */
3275 if (reload_in_progress || reload_completed)
3276 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3278 new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
3279 new_rtx = gen_rtx_CONST (Pmode, new_rtx);
3280 new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
3281 new_rtx = gen_const_mem (Pmode, new_rtx);
3282 emit_move_insn (reg, new_rtx);
3285 else if (TARGET_CPU_ZARCH)
3287 /* If the GOT offset might be >= 4k, we determine the position
3288 of the GOT entry via a PC-relative LARL (@GOTENT). */
3290 rtx temp = reg ? reg : gen_reg_rtx (Pmode);
3292 gcc_assert (REGNO (temp) >= FIRST_PSEUDO_REGISTER
3293 || REGNO_REG_CLASS (REGNO (temp)) == ADDR_REGS);
3295 new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTENT);
3296 new_rtx = gen_rtx_CONST (Pmode, new_rtx);
3297 emit_move_insn (temp, new_rtx);
3299 new_rtx = gen_const_mem (Pmode, temp);
3300 emit_move_insn (reg, new_rtx);
3305 /* If the GOT offset might be >= 4k, we have to load it
3306 from the literal pool (@GOT). */
3308 rtx temp = reg ? reg : gen_reg_rtx (Pmode);
3310 gcc_assert (REGNO (temp) >= FIRST_PSEUDO_REGISTER
3311 || REGNO_REG_CLASS (REGNO (temp)) == ADDR_REGS);
3313 if (reload_in_progress || reload_completed)
3314 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3316 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
3317 addr = gen_rtx_CONST (Pmode, addr);
3318 addr = force_const_mem (Pmode, addr);
3319 emit_move_insn (temp, addr);
3321 new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
3322 new_rtx = gen_const_mem (Pmode, new_rtx);
3323 emit_move_insn (reg, new_rtx);
3329 if (GET_CODE (addr) == CONST)
3331 addr = XEXP (addr, 0);
3332 if (GET_CODE (addr) == UNSPEC)
3334 gcc_assert (XVECLEN (addr, 0) == 1);
3335 switch (XINT (addr, 1))
3337 /* If someone moved a GOT-relative UNSPEC
3338 out of the literal pool, force them back in. */
3341 new_rtx = force_const_mem (Pmode, orig);
3344 /* @GOT is OK as is if small. */
3347 new_rtx = force_const_mem (Pmode, orig);
3350 /* @GOTENT is OK as is. */
3354 /* @PLT is OK as is on 64-bit, must be converted to
3355 GOT-relative @PLTOFF on 31-bit. */
3357 if (!TARGET_CPU_ZARCH)
3359 rtx temp = reg? reg : gen_reg_rtx (Pmode);
3361 if (reload_in_progress || reload_completed)
3362 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3364 addr = XVECEXP (addr, 0, 0);
3365 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
3367 addr = gen_rtx_CONST (Pmode, addr);
3368 addr = force_const_mem (Pmode, addr);
3369 emit_move_insn (temp, addr);
3371 new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
3374 s390_load_address (reg, new_rtx);
3380 /* Everything else cannot happen. */
3386 gcc_assert (GET_CODE (addr) == PLUS);
3388 if (GET_CODE (addr) == PLUS)
3390 rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
3392 gcc_assert (!TLS_SYMBOLIC_CONST (op0));
3393 gcc_assert (!TLS_SYMBOLIC_CONST (op1));
3395 /* Check first to see if this is a constant offset
3396 from a local symbol reference. */
3397 if ((GET_CODE (op0) == LABEL_REF
3398 || (GET_CODE (op0) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (op0)))
3399 && GET_CODE (op1) == CONST_INT)
3401 if (TARGET_CPU_ZARCH
3402 && larl_operand (op0, VOIDmode)
3403 && INTVAL (op1) < (HOST_WIDE_INT)1 << 31
3404 && INTVAL (op1) >= -((HOST_WIDE_INT)1 << 31))
3406 if (INTVAL (op1) & 1)
3408 /* LARL can't handle odd offsets, so emit a
3409 pair of LARL and LA. */
3410 rtx temp = reg? reg : gen_reg_rtx (Pmode);
3412 if (!DISP_IN_RANGE (INTVAL (op1)))
3414 HOST_WIDE_INT even = INTVAL (op1) - 1;
3415 op0 = gen_rtx_PLUS (Pmode, op0, GEN_INT (even));
3416 op0 = gen_rtx_CONST (Pmode, op0);
3420 emit_move_insn (temp, op0);
3421 new_rtx = gen_rtx_PLUS (Pmode, temp, op1);
3425 s390_load_address (reg, new_rtx);
3431 /* If the offset is even, we can just use LARL.
3432 This will happen automatically. */
3437 /* Access local symbols relative to the GOT. */
3439 rtx temp = reg? reg : gen_reg_rtx (Pmode);
3441 if (reload_in_progress || reload_completed)
3442 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3444 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
3446 addr = gen_rtx_PLUS (Pmode, addr, op1);
3447 addr = gen_rtx_CONST (Pmode, addr);
3448 addr = force_const_mem (Pmode, addr);
3449 emit_move_insn (temp, addr);
3451 new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
3454 s390_load_address (reg, new_rtx);
3460 /* Now, check whether it is a GOT relative symbol plus offset
3461 that was pulled out of the literal pool. Force it back in. */
3463 else if (GET_CODE (op0) == UNSPEC
3464 && GET_CODE (op1) == CONST_INT
3465 && XINT (op0, 1) == UNSPEC_GOTOFF)
3467 gcc_assert (XVECLEN (op0, 0) == 1);
3469 new_rtx = force_const_mem (Pmode, orig);
3472 /* Otherwise, compute the sum. */
3475 base = legitimize_pic_address (XEXP (addr, 0), reg);
3476 new_rtx = legitimize_pic_address (XEXP (addr, 1),
3477 base == reg ? NULL_RTX : reg);
3478 if (GET_CODE (new_rtx) == CONST_INT)