1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5 Ulrich Weigand (uweigand@de.ibm.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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"
53 #include "tree-gimple.h"
56 /* Define the specific costs for a given cpu. */
58 struct processor_costs
61 const int m; /* cost of an M instruction. */
62 const int mghi; /* cost of an MGHI instruction. */
63 const int mh; /* cost of an MH instruction. */
64 const int mhi; /* cost of an MHI instruction. */
65 const int ml; /* cost of an ML instruction. */
66 const int mr; /* cost of an MR instruction. */
67 const int ms; /* cost of an MS instruction. */
68 const int msg; /* cost of an MSG instruction. */
69 const int msgf; /* cost of an MSGF instruction. */
70 const int msgfr; /* cost of an MSGFR instruction. */
71 const int msgr; /* cost of an MSGR instruction. */
72 const int msr; /* cost of an MSR instruction. */
73 const int mult_df; /* cost of multiplication in DFmode. */
75 const int sqdbr; /* cost of square root in DFmode. */
76 const int sqebr; /* cost of square root in SFmode. */
77 /* multiply and add */
78 const int madbr; /* cost of multiply and add in DFmode. */
79 const int maebr; /* cost of multiply and add in SFmode. */
92 const struct processor_costs *s390_cost;
95 struct processor_costs z900_cost =
97 COSTS_N_INSNS (5), /* M */
98 COSTS_N_INSNS (10), /* MGHI */
99 COSTS_N_INSNS (5), /* MH */
100 COSTS_N_INSNS (4), /* MHI */
101 COSTS_N_INSNS (5), /* ML */
102 COSTS_N_INSNS (5), /* MR */
103 COSTS_N_INSNS (4), /* MS */
104 COSTS_N_INSNS (15), /* MSG */
105 COSTS_N_INSNS (7), /* MSGF */
106 COSTS_N_INSNS (7), /* MSGFR */
107 COSTS_N_INSNS (10), /* MSGR */
108 COSTS_N_INSNS (4), /* MSR */
109 COSTS_N_INSNS (7), /* multiplication in DFmode */
110 COSTS_N_INSNS (44), /* SQDBR */
111 COSTS_N_INSNS (35), /* SQEBR */
112 COSTS_N_INSNS (18), /* MADBR */
113 COSTS_N_INSNS (13), /* MAEBR */
114 COSTS_N_INSNS (30), /* DDBR */
115 COSTS_N_INSNS (30), /* DDR */
116 COSTS_N_INSNS (27), /* DEBR */
117 COSTS_N_INSNS (26), /* DER */
118 COSTS_N_INSNS (220), /* DLGR */
119 COSTS_N_INSNS (34), /* DLR */
120 COSTS_N_INSNS (34), /* DR */
121 COSTS_N_INSNS (32), /* DSGFR */
122 COSTS_N_INSNS (32), /* DSGR */
126 struct processor_costs z990_cost =
128 COSTS_N_INSNS (4), /* M */
129 COSTS_N_INSNS (2), /* MGHI */
130 COSTS_N_INSNS (2), /* MH */
131 COSTS_N_INSNS (2), /* MHI */
132 COSTS_N_INSNS (4), /* ML */
133 COSTS_N_INSNS (4), /* MR */
134 COSTS_N_INSNS (5), /* MS */
135 COSTS_N_INSNS (6), /* MSG */
136 COSTS_N_INSNS (4), /* MSGF */
137 COSTS_N_INSNS (4), /* MSGFR */
138 COSTS_N_INSNS (4), /* MSGR */
139 COSTS_N_INSNS (4), /* MSR */
140 COSTS_N_INSNS (1), /* multiplication in DFmode */
141 COSTS_N_INSNS (66), /* SQDBR */
142 COSTS_N_INSNS (38), /* SQEBR */
143 COSTS_N_INSNS (1), /* MADBR */
144 COSTS_N_INSNS (1), /* MAEBR */
145 COSTS_N_INSNS (40), /* DDBR */
146 COSTS_N_INSNS (44), /* DDR */
147 COSTS_N_INSNS (26), /* DDBR */
148 COSTS_N_INSNS (28), /* DER */
149 COSTS_N_INSNS (176), /* DLGR */
150 COSTS_N_INSNS (31), /* DLR */
151 COSTS_N_INSNS (31), /* DR */
152 COSTS_N_INSNS (31), /* DSGFR */
153 COSTS_N_INSNS (31), /* DSGR */
157 struct processor_costs z9_109_cost =
159 COSTS_N_INSNS (4), /* M */
160 COSTS_N_INSNS (2), /* MGHI */
161 COSTS_N_INSNS (2), /* MH */
162 COSTS_N_INSNS (2), /* MHI */
163 COSTS_N_INSNS (4), /* ML */
164 COSTS_N_INSNS (4), /* MR */
165 COSTS_N_INSNS (5), /* MS */
166 COSTS_N_INSNS (6), /* MSG */
167 COSTS_N_INSNS (4), /* MSGF */
168 COSTS_N_INSNS (4), /* MSGFR */
169 COSTS_N_INSNS (4), /* MSGR */
170 COSTS_N_INSNS (4), /* MSR */
171 COSTS_N_INSNS (1), /* multiplication in DFmode */
172 COSTS_N_INSNS (66), /* SQDBR */
173 COSTS_N_INSNS (38), /* SQEBR */
174 COSTS_N_INSNS (1), /* MADBR */
175 COSTS_N_INSNS (1), /* MAEBR */
176 COSTS_N_INSNS (40), /* DDBR */
177 COSTS_N_INSNS (37), /* DDR */
178 COSTS_N_INSNS (26), /* DDBR */
179 COSTS_N_INSNS (28), /* DER */
180 COSTS_N_INSNS (30), /* DLGR */
181 COSTS_N_INSNS (23), /* DLR */
182 COSTS_N_INSNS (23), /* DR */
183 COSTS_N_INSNS (24), /* DSGFR */
184 COSTS_N_INSNS (24), /* DSGR */
187 extern int reload_completed;
189 /* Save information from a "cmpxx" operation until the branch or scc is
191 rtx s390_compare_op0, s390_compare_op1;
193 /* Save the result of a compare_and_swap until the branch or scc is
195 rtx s390_compare_emitted = NULL_RTX;
197 /* Structure used to hold the components of a S/390 memory
198 address. A legitimate address on S/390 is of the general
200 base + index + displacement
201 where any of the components is optional.
203 base and index are registers of the class ADDR_REGS,
204 displacement is an unsigned 12-bit immediate constant. */
214 /* Which cpu are we tuning for. */
215 enum processor_type s390_tune = PROCESSOR_max;
216 enum processor_flags s390_tune_flags;
217 /* Which instruction set architecture to use. */
218 enum processor_type s390_arch;
219 enum processor_flags s390_arch_flags;
221 HOST_WIDE_INT s390_warn_framesize = 0;
222 HOST_WIDE_INT s390_stack_size = 0;
223 HOST_WIDE_INT s390_stack_guard = 0;
225 /* The following structure is embedded in the machine
226 specific part of struct function. */
228 struct s390_frame_layout GTY (())
230 /* Offset within stack frame. */
231 HOST_WIDE_INT gprs_offset;
232 HOST_WIDE_INT f0_offset;
233 HOST_WIDE_INT f4_offset;
234 HOST_WIDE_INT f8_offset;
235 HOST_WIDE_INT backchain_offset;
237 /* Number of first and last gpr where slots in the register
238 save area are reserved for. */
239 int first_save_gpr_slot;
240 int last_save_gpr_slot;
242 /* Number of first and last gpr to be saved, restored. */
244 int first_restore_gpr;
246 int last_restore_gpr;
248 /* Bits standing for floating point registers. Set, if the
249 respective register has to be saved. Starting with reg 16 (f0)
250 at the rightmost bit.
251 Bit 15 - 8 7 6 5 4 3 2 1 0
252 fpr 15 - 8 7 5 3 1 6 4 2 0
253 reg 31 - 24 23 22 21 20 19 18 17 16 */
254 unsigned int fpr_bitmap;
256 /* Number of floating point registers f8-f15 which must be saved. */
259 /* Set if return address needs to be saved.
260 This flag is set by s390_return_addr_rtx if it could not use
261 the initial value of r14 and therefore depends on r14 saved
263 bool save_return_addr_p;
265 /* Size of stack frame. */
266 HOST_WIDE_INT frame_size;
269 /* Define the structure for the machine field in struct function. */
271 struct machine_function GTY(())
273 struct s390_frame_layout frame_layout;
275 /* Literal pool base register. */
278 /* True if we may need to perform branch splitting. */
279 bool split_branches_pending_p;
281 /* Some local-dynamic TLS symbol name. */
282 const char *some_ld_name;
284 bool has_landing_pad_p;
287 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
289 #define cfun_frame_layout (cfun->machine->frame_layout)
290 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
291 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
292 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_WORD)
293 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
295 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
298 /* Number of GPRs and FPRs used for argument passing. */
299 #define GP_ARG_NUM_REG 5
300 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
302 /* A couple of shortcuts. */
303 #define CONST_OK_FOR_J(x) \
304 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
305 #define CONST_OK_FOR_K(x) \
306 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
307 #define CONST_OK_FOR_Os(x) \
308 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
309 #define CONST_OK_FOR_Op(x) \
310 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
311 #define CONST_OK_FOR_On(x) \
312 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
314 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
317 s390_set_has_landing_pad_p (bool value)
319 cfun->machine->has_landing_pad_p = value;
322 /* If two condition code modes are compatible, return a condition code
323 mode which is compatible with both. Otherwise, return
326 static enum machine_mode
327 s390_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
335 if (m2 == CCUmode || m2 == CCTmode || m2 == CCZ1mode
336 || m2 == CCSmode || m2 == CCSRmode || m2 == CCURmode)
357 /* Return true if SET either doesn't set the CC register, or else
358 the source and destination have matching CC modes and that
359 CC mode is at least as constrained as REQ_MODE. */
362 s390_match_ccmode_set (rtx set, enum machine_mode req_mode)
364 enum machine_mode set_mode;
366 gcc_assert (GET_CODE (set) == SET);
368 if (GET_CODE (SET_DEST (set)) != REG || !CC_REGNO_P (REGNO (SET_DEST (set))))
371 set_mode = GET_MODE (SET_DEST (set));
385 if (req_mode != set_mode)
390 if (req_mode != CCSmode && req_mode != CCUmode && req_mode != CCTmode
391 && req_mode != CCSRmode && req_mode != CCURmode)
397 if (req_mode != CCAmode)
405 return (GET_MODE (SET_SRC (set)) == set_mode);
408 /* Return true if every SET in INSN that sets the CC register
409 has source and destination with matching CC modes and that
410 CC mode is at least as constrained as REQ_MODE.
411 If REQ_MODE is VOIDmode, always return false. */
414 s390_match_ccmode (rtx insn, enum machine_mode req_mode)
418 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
419 if (req_mode == VOIDmode)
422 if (GET_CODE (PATTERN (insn)) == SET)
423 return s390_match_ccmode_set (PATTERN (insn), req_mode);
425 if (GET_CODE (PATTERN (insn)) == PARALLEL)
426 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
428 rtx set = XVECEXP (PATTERN (insn), 0, i);
429 if (GET_CODE (set) == SET)
430 if (!s390_match_ccmode_set (set, req_mode))
437 /* If a test-under-mask instruction can be used to implement
438 (compare (and ... OP1) OP2), return the CC mode required
439 to do that. Otherwise, return VOIDmode.
440 MIXED is true if the instruction can distinguish between
441 CC1 and CC2 for mixed selected bits (TMxx), it is false
442 if the instruction cannot (TM). */
445 s390_tm_ccmode (rtx op1, rtx op2, bool mixed)
449 /* ??? Fixme: should work on CONST_DOUBLE as well. */
450 if (GET_CODE (op1) != CONST_INT || GET_CODE (op2) != CONST_INT)
453 /* Selected bits all zero: CC0.
454 e.g.: int a; if ((a & (16 + 128)) == 0) */
455 if (INTVAL (op2) == 0)
458 /* Selected bits all one: CC3.
459 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
460 if (INTVAL (op2) == INTVAL (op1))
463 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
465 if ((a & (16 + 128)) == 16) -> CCT1
466 if ((a & (16 + 128)) == 128) -> CCT2 */
469 bit1 = exact_log2 (INTVAL (op2));
470 bit0 = exact_log2 (INTVAL (op1) ^ INTVAL (op2));
471 if (bit0 != -1 && bit1 != -1)
472 return bit0 > bit1 ? CCT1mode : CCT2mode;
478 /* Given a comparison code OP (EQ, NE, etc.) and the operands
479 OP0 and OP1 of a COMPARE, return the mode to be used for the
483 s390_select_ccmode (enum rtx_code code, rtx op0, rtx op1)
489 if ((GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
490 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
492 if (GET_CODE (op0) == PLUS && GET_CODE (XEXP (op0, 1)) == CONST_INT
493 && CONST_OK_FOR_K (INTVAL (XEXP (op0, 1))))
495 if ((GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS
496 || GET_CODE (op1) == NEG)
497 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
500 if (GET_CODE (op0) == AND)
502 /* Check whether we can potentially do it via TM. */
503 enum machine_mode ccmode;
504 ccmode = s390_tm_ccmode (XEXP (op0, 1), op1, 1);
505 if (ccmode != VOIDmode)
507 /* Relax CCTmode to CCZmode to allow fall-back to AND
508 if that turns out to be beneficial. */
509 return ccmode == CCTmode ? CCZmode : ccmode;
513 if (register_operand (op0, HImode)
514 && GET_CODE (op1) == CONST_INT
515 && (INTVAL (op1) == -1 || INTVAL (op1) == 65535))
517 if (register_operand (op0, QImode)
518 && GET_CODE (op1) == CONST_INT
519 && (INTVAL (op1) == -1 || INTVAL (op1) == 255))
528 /* The only overflow condition of NEG and ABS happens when
529 -INT_MAX is used as parameter, which stays negative. So
530 we have an overflow from a positive value to a negative.
531 Using CCAP mode the resulting cc can be used for comparisons. */
532 if ((GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
533 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
536 /* If constants are involved in an add instruction it is possible to use
537 the resulting cc for comparisons with zero. Knowing the sign of the
538 constant the overflow behavior gets predictable. e.g.:
539 int a, b; if ((b = a + c) > 0)
540 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
541 if (GET_CODE (op0) == PLUS && GET_CODE (XEXP (op0, 1)) == CONST_INT
542 && CONST_OK_FOR_K (INTVAL (XEXP (op0, 1))))
544 if (INTVAL (XEXP((op0), 1)) < 0)
558 if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
559 && GET_CODE (op1) != CONST_INT)
565 if (GET_CODE (op0) == PLUS
566 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
569 if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
570 && GET_CODE (op1) != CONST_INT)
576 if (GET_CODE (op0) == MINUS
577 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
580 if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
581 && GET_CODE (op1) != CONST_INT)
590 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
591 that we can implement more efficiently. */
594 s390_canonicalize_comparison (enum rtx_code *code, rtx *op0, rtx *op1)
596 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
597 if ((*code == EQ || *code == NE)
598 && *op1 == const0_rtx
599 && GET_CODE (*op0) == ZERO_EXTRACT
600 && GET_CODE (XEXP (*op0, 1)) == CONST_INT
601 && GET_CODE (XEXP (*op0, 2)) == CONST_INT
602 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0, 0))))
604 rtx inner = XEXP (*op0, 0);
605 HOST_WIDE_INT modesize = GET_MODE_BITSIZE (GET_MODE (inner));
606 HOST_WIDE_INT len = INTVAL (XEXP (*op0, 1));
607 HOST_WIDE_INT pos = INTVAL (XEXP (*op0, 2));
609 if (len > 0 && len < modesize
610 && pos >= 0 && pos + len <= modesize
611 && modesize <= HOST_BITS_PER_WIDE_INT)
613 unsigned HOST_WIDE_INT block;
614 block = ((unsigned HOST_WIDE_INT) 1 << len) - 1;
615 block <<= modesize - pos - len;
617 *op0 = gen_rtx_AND (GET_MODE (inner), inner,
618 gen_int_mode (block, GET_MODE (inner)));
622 /* Narrow AND of memory against immediate to enable TM. */
623 if ((*code == EQ || *code == NE)
624 && *op1 == const0_rtx
625 && GET_CODE (*op0) == AND
626 && GET_CODE (XEXP (*op0, 1)) == CONST_INT
627 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0, 0))))
629 rtx inner = XEXP (*op0, 0);
630 rtx mask = XEXP (*op0, 1);
632 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
633 if (GET_CODE (inner) == SUBREG
634 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner)))
635 && (GET_MODE_SIZE (GET_MODE (inner))
636 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner))))
638 & GET_MODE_MASK (GET_MODE (inner))
639 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner))))
641 inner = SUBREG_REG (inner);
643 /* Do not change volatile MEMs. */
644 if (MEM_P (inner) && !MEM_VOLATILE_P (inner))
646 int part = s390_single_part (XEXP (*op0, 1),
647 GET_MODE (inner), QImode, 0);
650 mask = gen_int_mode (s390_extract_part (mask, QImode, 0), QImode);
651 inner = adjust_address_nv (inner, QImode, part);
652 *op0 = gen_rtx_AND (QImode, inner, mask);
657 /* Narrow comparisons against 0xffff to HImode if possible. */
658 if ((*code == EQ || *code == NE)
659 && GET_CODE (*op1) == CONST_INT
660 && INTVAL (*op1) == 0xffff
661 && SCALAR_INT_MODE_P (GET_MODE (*op0))
662 && (nonzero_bits (*op0, GET_MODE (*op0))
663 & ~(unsigned HOST_WIDE_INT) 0xffff) == 0)
665 *op0 = gen_lowpart (HImode, *op0);
670 /* Remove redundant UNSPEC_CMPINT conversions if possible. */
671 if (GET_CODE (*op0) == UNSPEC
672 && XINT (*op0, 1) == UNSPEC_CMPINT
673 && XVECLEN (*op0, 0) == 1
674 && GET_MODE (XVECEXP (*op0, 0, 0)) == CCUmode
675 && GET_CODE (XVECEXP (*op0, 0, 0)) == REG
676 && REGNO (XVECEXP (*op0, 0, 0)) == CC_REGNUM
677 && *op1 == const0_rtx)
679 enum rtx_code new_code = UNKNOWN;
682 case EQ: new_code = EQ; break;
683 case NE: new_code = NE; break;
684 case LT: new_code = GTU; break;
685 case GT: new_code = LTU; break;
686 case LE: new_code = GEU; break;
687 case GE: new_code = LEU; break;
691 if (new_code != UNKNOWN)
693 *op0 = XVECEXP (*op0, 0, 0);
698 /* Simplify cascaded EQ, NE with const0_rtx. */
699 if ((*code == NE || *code == EQ)
700 && (GET_CODE (*op0) == EQ || GET_CODE (*op0) == NE)
701 && GET_MODE (*op0) == SImode
702 && GET_MODE (XEXP (*op0, 0)) == CCZ1mode
703 && REG_P (XEXP (*op0, 0))
704 && XEXP (*op0, 1) == const0_rtx
705 && *op1 == const0_rtx)
707 if ((*code == EQ && GET_CODE (*op0) == NE)
708 || (*code == NE && GET_CODE (*op0) == EQ))
712 *op0 = XEXP (*op0, 0);
715 /* Prefer register over memory as first operand. */
716 if (MEM_P (*op0) && REG_P (*op1))
718 rtx tem = *op0; *op0 = *op1; *op1 = tem;
719 *code = swap_condition (*code);
723 /* Emit a compare instruction suitable to implement the comparison
724 OP0 CODE OP1. Return the correct condition RTL to be placed in
725 the IF_THEN_ELSE of the conditional branch testing the result. */
728 s390_emit_compare (enum rtx_code code, rtx op0, rtx op1)
730 enum machine_mode mode = s390_select_ccmode (code, op0, op1);
733 /* Do not output a redundant compare instruction if a compare_and_swap
734 pattern already computed the result and the machine modes are compatible. */
735 if (s390_compare_emitted
736 && (s390_cc_modes_compatible (GET_MODE (s390_compare_emitted), mode)
737 == GET_MODE (s390_compare_emitted)))
738 ret = gen_rtx_fmt_ee (code, VOIDmode, s390_compare_emitted, const0_rtx);
741 rtx cc = gen_rtx_REG (mode, CC_REGNUM);
743 emit_insn (gen_rtx_SET (VOIDmode, cc, gen_rtx_COMPARE (mode, op0, op1)));
744 ret = gen_rtx_fmt_ee (code, VOIDmode, cc, const0_rtx);
746 s390_compare_emitted = NULL_RTX;
750 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
751 unconditional jump, else a conditional jump under condition COND. */
754 s390_emit_jump (rtx target, rtx cond)
758 target = gen_rtx_LABEL_REF (VOIDmode, target);
760 target = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, target, pc_rtx);
762 insn = gen_rtx_SET (VOIDmode, pc_rtx, target);
763 emit_jump_insn (insn);
766 /* Return branch condition mask to implement a branch
767 specified by CODE. Return -1 for invalid comparisons. */
770 s390_branch_condition_mask (rtx code)
772 const int CC0 = 1 << 3;
773 const int CC1 = 1 << 2;
774 const int CC2 = 1 << 1;
775 const int CC3 = 1 << 0;
777 gcc_assert (GET_CODE (XEXP (code, 0)) == REG);
778 gcc_assert (REGNO (XEXP (code, 0)) == CC_REGNUM);
779 gcc_assert (XEXP (code, 1) == const0_rtx);
781 switch (GET_MODE (XEXP (code, 0)))
785 switch (GET_CODE (code))
788 case NE: return CC1 | CC2 | CC3;
794 switch (GET_CODE (code))
797 case NE: return CC0 | CC2 | CC3;
803 switch (GET_CODE (code))
806 case NE: return CC0 | CC1 | CC3;
812 switch (GET_CODE (code))
815 case NE: return CC0 | CC1 | CC2;
821 switch (GET_CODE (code))
823 case EQ: return CC0 | CC2;
824 case NE: return CC1 | CC3;
830 switch (GET_CODE (code))
832 case LTU: return CC2 | CC3; /* carry */
833 case GEU: return CC0 | CC1; /* no carry */
839 switch (GET_CODE (code))
841 case GTU: return CC0 | CC1; /* borrow */
842 case LEU: return CC2 | CC3; /* no borrow */
848 switch (GET_CODE (code))
850 case EQ: return CC0 | CC2;
851 case NE: return CC1 | CC3;
852 case LTU: return CC1;
853 case GTU: return CC3;
854 case LEU: return CC1 | CC2;
855 case GEU: return CC2 | CC3;
860 switch (GET_CODE (code))
863 case NE: return CC1 | CC2 | CC3;
864 case LTU: return CC1;
865 case GTU: return CC2;
866 case LEU: return CC0 | CC1;
867 case GEU: return CC0 | CC2;
873 switch (GET_CODE (code))
876 case NE: return CC2 | CC1 | CC3;
877 case LTU: return CC2;
878 case GTU: return CC1;
879 case LEU: return CC0 | CC2;
880 case GEU: return CC0 | CC1;
886 switch (GET_CODE (code))
889 case NE: return CC1 | CC2 | CC3;
890 case LT: return CC1 | CC3;
892 case LE: return CC0 | CC1 | CC3;
893 case GE: return CC0 | CC2;
899 switch (GET_CODE (code))
902 case NE: return CC1 | CC2 | CC3;
904 case GT: return CC2 | CC3;
905 case LE: return CC0 | CC1;
906 case GE: return CC0 | CC2 | CC3;
912 switch (GET_CODE (code))
915 case NE: return CC1 | CC2 | CC3;
918 case LE: return CC0 | CC1;
919 case GE: return CC0 | CC2;
920 case UNORDERED: return CC3;
921 case ORDERED: return CC0 | CC1 | CC2;
922 case UNEQ: return CC0 | CC3;
923 case UNLT: return CC1 | CC3;
924 case UNGT: return CC2 | CC3;
925 case UNLE: return CC0 | CC1 | CC3;
926 case UNGE: return CC0 | CC2 | CC3;
927 case LTGT: return CC1 | CC2;
933 switch (GET_CODE (code))
936 case NE: return CC2 | CC1 | CC3;
939 case LE: return CC0 | CC2;
940 case GE: return CC0 | CC1;
941 case UNORDERED: return CC3;
942 case ORDERED: return CC0 | CC2 | CC1;
943 case UNEQ: return CC0 | CC3;
944 case UNLT: return CC2 | CC3;
945 case UNGT: return CC1 | CC3;
946 case UNLE: return CC0 | CC2 | CC3;
947 case UNGE: return CC0 | CC1 | CC3;
948 case LTGT: return CC2 | CC1;
958 /* If INV is false, return assembler mnemonic string to implement
959 a branch specified by CODE. If INV is true, return mnemonic
960 for the corresponding inverted branch. */
963 s390_branch_condition_mnemonic (rtx code, int inv)
965 static const char *const mnemonic[16] =
967 NULL, "o", "h", "nle",
968 "l", "nhe", "lh", "ne",
969 "e", "nlh", "he", "nl",
970 "le", "nh", "no", NULL
973 int mask = s390_branch_condition_mask (code);
974 gcc_assert (mask >= 0);
979 gcc_assert (mask >= 1 && mask <= 14);
981 return mnemonic[mask];
984 /* Return the part of op which has a value different from def.
985 The size of the part is determined by mode.
986 Use this function only if you already know that op really
987 contains such a part. */
989 unsigned HOST_WIDE_INT
990 s390_extract_part (rtx op, enum machine_mode mode, int def)
992 unsigned HOST_WIDE_INT value = 0;
993 int max_parts = HOST_BITS_PER_WIDE_INT / GET_MODE_BITSIZE (mode);
994 int part_bits = GET_MODE_BITSIZE (mode);
995 unsigned HOST_WIDE_INT part_mask
996 = ((unsigned HOST_WIDE_INT)1 << part_bits) - 1;
999 for (i = 0; i < max_parts; i++)
1002 value = (unsigned HOST_WIDE_INT) INTVAL (op);
1004 value >>= part_bits;
1006 if ((value & part_mask) != (def & part_mask))
1007 return value & part_mask;
1013 /* If OP is an integer constant of mode MODE with exactly one
1014 part of mode PART_MODE unequal to DEF, return the number of that
1015 part. Otherwise, return -1. */
1018 s390_single_part (rtx op,
1019 enum machine_mode mode,
1020 enum machine_mode part_mode,
1023 unsigned HOST_WIDE_INT value = 0;
1024 int n_parts = GET_MODE_SIZE (mode) / GET_MODE_SIZE (part_mode);
1025 unsigned HOST_WIDE_INT part_mask
1026 = ((unsigned HOST_WIDE_INT)1 << GET_MODE_BITSIZE (part_mode)) - 1;
1029 if (GET_CODE (op) != CONST_INT)
1032 for (i = 0; i < n_parts; i++)
1035 value = (unsigned HOST_WIDE_INT) INTVAL (op);
1037 value >>= GET_MODE_BITSIZE (part_mode);
1039 if ((value & part_mask) != (def & part_mask))
1047 return part == -1 ? -1 : n_parts - 1 - part;
1050 /* Check whether we can (and want to) split a double-word
1051 move in mode MODE from SRC to DST into two single-word
1052 moves, moving the subword FIRST_SUBWORD first. */
1055 s390_split_ok_p (rtx dst, rtx src, enum machine_mode mode, int first_subword)
1057 /* Floating point registers cannot be split. */
1058 if (FP_REG_P (src) || FP_REG_P (dst))
1061 /* We don't need to split if operands are directly accessible. */
1062 if (s_operand (src, mode) || s_operand (dst, mode))
1065 /* Non-offsettable memory references cannot be split. */
1066 if ((GET_CODE (src) == MEM && !offsettable_memref_p (src))
1067 || (GET_CODE (dst) == MEM && !offsettable_memref_p (dst)))
1070 /* Moving the first subword must not clobber a register
1071 needed to move the second subword. */
1072 if (register_operand (dst, mode))
1074 rtx subreg = operand_subword (dst, first_subword, 0, mode);
1075 if (reg_overlap_mentioned_p (subreg, src))
1082 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1083 and [MEM2, MEM2 + SIZE] do overlap and false
1087 s390_overlap_p (rtx mem1, rtx mem2, HOST_WIDE_INT size)
1089 rtx addr1, addr2, addr_delta;
1090 HOST_WIDE_INT delta;
1092 if (GET_CODE (mem1) != MEM || GET_CODE (mem2) != MEM)
1098 addr1 = XEXP (mem1, 0);
1099 addr2 = XEXP (mem2, 0);
1101 addr_delta = simplify_binary_operation (MINUS, Pmode, addr2, addr1);
1103 /* This overlapping check is used by peepholes merging memory block operations.
1104 Overlapping operations would otherwise be recognized by the S/390 hardware
1105 and would fall back to a slower implementation. Allowing overlapping
1106 operations would lead to slow code but not to wrong code. Therefore we are
1107 somewhat optimistic if we cannot prove that the memory blocks are
1109 That's why we return false here although this may accept operations on
1110 overlapping memory areas. */
1111 if (!addr_delta || GET_CODE (addr_delta) != CONST_INT)
1114 delta = INTVAL (addr_delta);
1117 || (delta > 0 && delta < size)
1118 || (delta < 0 && -delta < size))
1124 /* Check whether the address of memory reference MEM2 equals exactly
1125 the address of memory reference MEM1 plus DELTA. Return true if
1126 we can prove this to be the case, false otherwise. */
1129 s390_offset_p (rtx mem1, rtx mem2, rtx delta)
1131 rtx addr1, addr2, addr_delta;
1133 if (GET_CODE (mem1) != MEM || GET_CODE (mem2) != MEM)
1136 addr1 = XEXP (mem1, 0);
1137 addr2 = XEXP (mem2, 0);
1139 addr_delta = simplify_binary_operation (MINUS, Pmode, addr2, addr1);
1140 if (!addr_delta || !rtx_equal_p (addr_delta, delta))
1146 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1149 s390_expand_logical_operator (enum rtx_code code, enum machine_mode mode,
1152 enum machine_mode wmode = mode;
1153 rtx dst = operands[0];
1154 rtx src1 = operands[1];
1155 rtx src2 = operands[2];
1158 /* If we cannot handle the operation directly, use a temp register. */
1159 if (!s390_logical_operator_ok_p (operands))
1160 dst = gen_reg_rtx (mode);
1162 /* QImode and HImode patterns make sense only if we have a destination
1163 in memory. Otherwise perform the operation in SImode. */
1164 if ((mode == QImode || mode == HImode) && GET_CODE (dst) != MEM)
1167 /* Widen operands if required. */
1170 if (GET_CODE (dst) == SUBREG
1171 && (tem = simplify_subreg (wmode, dst, mode, 0)) != 0)
1173 else if (REG_P (dst))
1174 dst = gen_rtx_SUBREG (wmode, dst, 0);
1176 dst = gen_reg_rtx (wmode);
1178 if (GET_CODE (src1) == SUBREG
1179 && (tem = simplify_subreg (wmode, src1, mode, 0)) != 0)
1181 else if (GET_MODE (src1) != VOIDmode)
1182 src1 = gen_rtx_SUBREG (wmode, force_reg (mode, src1), 0);
1184 if (GET_CODE (src2) == SUBREG
1185 && (tem = simplify_subreg (wmode, src2, mode, 0)) != 0)
1187 else if (GET_MODE (src2) != VOIDmode)
1188 src2 = gen_rtx_SUBREG (wmode, force_reg (mode, src2), 0);
1191 /* Emit the instruction. */
1192 op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, wmode, src1, src2));
1193 clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, CC_REGNUM));
1194 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
1196 /* Fix up the destination if needed. */
1197 if (dst != operands[0])
1198 emit_move_insn (operands[0], gen_lowpart (mode, dst));
1201 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1204 s390_logical_operator_ok_p (rtx *operands)
1206 /* If the destination operand is in memory, it needs to coincide
1207 with one of the source operands. After reload, it has to be
1208 the first source operand. */
1209 if (GET_CODE (operands[0]) == MEM)
1210 return rtx_equal_p (operands[0], operands[1])
1211 || (!reload_completed && rtx_equal_p (operands[0], operands[2]));
1216 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1217 operand IMMOP to switch from SS to SI type instructions. */
1220 s390_narrow_logical_operator (enum rtx_code code, rtx *memop, rtx *immop)
1222 int def = code == AND ? -1 : 0;
1226 gcc_assert (GET_CODE (*memop) == MEM);
1227 gcc_assert (!MEM_VOLATILE_P (*memop));
1229 mask = s390_extract_part (*immop, QImode, def);
1230 part = s390_single_part (*immop, GET_MODE (*memop), QImode, def);
1231 gcc_assert (part >= 0);
1233 *memop = adjust_address (*memop, QImode, part);
1234 *immop = gen_int_mode (mask, QImode);
1238 /* How to allocate a 'struct machine_function'. */
1240 static struct machine_function *
1241 s390_init_machine_status (void)
1243 return ggc_alloc_cleared (sizeof (struct machine_function));
1246 /* Change optimizations to be performed, depending on the
1249 LEVEL is the optimization level specified; 2 if `-O2' is
1250 specified, 1 if `-O' is specified, and 0 if neither is specified.
1252 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1255 optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
1257 /* ??? There are apparently still problems with -fcaller-saves. */
1258 flag_caller_saves = 0;
1260 /* By default, always emit DWARF-2 unwind info. This allows debugging
1261 without maintaining a stack frame back-chain. */
1262 flag_asynchronous_unwind_tables = 1;
1264 /* Use MVCLE instructions to decrease code size if requested. */
1266 target_flags |= MASK_MVCLE;
1269 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1270 to the associated processor_type and processor_flags if so. */
1273 s390_handle_arch_option (const char *arg,
1274 enum processor_type *type,
1275 enum processor_flags *flags)
1279 const char *const name; /* processor name or nickname. */
1280 const enum processor_type processor;
1281 const enum processor_flags flags;
1283 const processor_alias_table[] =
1285 {"g5", PROCESSOR_9672_G5, PF_IEEE_FLOAT},
1286 {"g6", PROCESSOR_9672_G6, PF_IEEE_FLOAT},
1287 {"z900", PROCESSOR_2064_Z900, PF_IEEE_FLOAT | PF_ZARCH},
1288 {"z990", PROCESSOR_2084_Z990, PF_IEEE_FLOAT | PF_ZARCH
1289 | PF_LONG_DISPLACEMENT},
1290 {"z9-109", PROCESSOR_2094_Z9_109, PF_IEEE_FLOAT | PF_ZARCH
1291 | PF_LONG_DISPLACEMENT | PF_EXTIMM},
1295 for (i = 0; i < ARRAY_SIZE (processor_alias_table); i++)
1296 if (strcmp (arg, processor_alias_table[i].name) == 0)
1298 *type = processor_alias_table[i].processor;
1299 *flags = processor_alias_table[i].flags;
1305 /* Implement TARGET_HANDLE_OPTION. */
1308 s390_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
1313 return s390_handle_arch_option (arg, &s390_arch, &s390_arch_flags);
1315 case OPT_mstack_guard_:
1316 if (sscanf (arg, HOST_WIDE_INT_PRINT_DEC, &s390_stack_guard) != 1)
1318 if (exact_log2 (s390_stack_guard) == -1)
1319 error ("stack guard value must be an exact power of 2");
1322 case OPT_mstack_size_:
1323 if (sscanf (arg, HOST_WIDE_INT_PRINT_DEC, &s390_stack_size) != 1)
1325 if (exact_log2 (s390_stack_size) == -1)
1326 error ("stack size must be an exact power of 2");
1330 return s390_handle_arch_option (arg, &s390_tune, &s390_tune_flags);
1332 case OPT_mwarn_framesize_:
1333 return sscanf (arg, HOST_WIDE_INT_PRINT_DEC, &s390_warn_framesize) == 1;
1341 override_options (void)
1343 /* Set up function hooks. */
1344 init_machine_status = s390_init_machine_status;
1346 /* Architecture mode defaults according to ABI. */
1347 if (!(target_flags_explicit & MASK_ZARCH))
1350 target_flags |= MASK_ZARCH;
1352 target_flags &= ~MASK_ZARCH;
1355 /* Determine processor architectural level. */
1356 if (!s390_arch_string)
1358 s390_arch_string = TARGET_ZARCH? "z900" : "g5";
1359 s390_handle_arch_option (s390_arch_string, &s390_arch, &s390_arch_flags);
1362 /* Determine processor to tune for. */
1363 if (s390_tune == PROCESSOR_max)
1365 s390_tune = s390_arch;
1366 s390_tune_flags = s390_arch_flags;
1369 /* Sanity checks. */
1370 if (TARGET_ZARCH && !(s390_arch_flags & PF_ZARCH))
1371 error ("z/Architecture mode not supported on %s", s390_arch_string);
1372 if (TARGET_64BIT && !TARGET_ZARCH)
1373 error ("64-bit ABI not supported in ESA/390 mode");
1375 /* Set processor cost function. */
1376 if (s390_tune == PROCESSOR_2094_Z9_109)
1377 s390_cost = &z9_109_cost;
1378 else if (s390_tune == PROCESSOR_2084_Z990)
1379 s390_cost = &z990_cost;
1381 s390_cost = &z900_cost;
1383 if (TARGET_BACKCHAIN && TARGET_PACKED_STACK && TARGET_HARD_FLOAT)
1384 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1387 if (s390_stack_size)
1389 if (!s390_stack_guard)
1390 error ("-mstack-size implies use of -mstack-guard");
1391 else if (s390_stack_guard >= s390_stack_size)
1392 error ("stack size must be greater than the stack guard value");
1393 else if (s390_stack_size > 1 << 16)
1394 error ("stack size must not be greater than 64k");
1396 else if (s390_stack_guard)
1397 error ("-mstack-guard implies use of -mstack-size");
1400 /* Map for smallest class containing reg regno. */
1402 const enum reg_class regclass_map[FIRST_PSEUDO_REGISTER] =
1403 { GENERAL_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1404 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1405 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1406 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
1407 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1408 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1409 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1410 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
1411 ADDR_REGS, CC_REGS, ADDR_REGS, ADDR_REGS,
1412 ACCESS_REGS, ACCESS_REGS
1415 /* Return attribute type of insn. */
1417 static enum attr_type
1418 s390_safe_attr_type (rtx insn)
1420 if (recog_memoized (insn) >= 0)
1421 return get_attr_type (insn);
1426 /* Return true if DISP is a valid short displacement. */
1429 s390_short_displacement (rtx disp)
1431 /* No displacement is OK. */
1435 /* Integer displacement in range. */
1436 if (GET_CODE (disp) == CONST_INT)
1437 return INTVAL (disp) >= 0 && INTVAL (disp) < 4096;
1439 /* GOT offset is not OK, the GOT can be large. */
1440 if (GET_CODE (disp) == CONST
1441 && GET_CODE (XEXP (disp, 0)) == UNSPEC
1442 && (XINT (XEXP (disp, 0), 1) == UNSPEC_GOT
1443 || XINT (XEXP (disp, 0), 1) == UNSPEC_GOTNTPOFF))
1446 /* All other symbolic constants are literal pool references,
1447 which are OK as the literal pool must be small. */
1448 if (GET_CODE (disp) == CONST)
1454 /* Decompose a RTL expression ADDR for a memory address into
1455 its components, returned in OUT.
1457 Returns false if ADDR is not a valid memory address, true
1458 otherwise. If OUT is NULL, don't return the components,
1459 but check for validity only.
1461 Note: Only addresses in canonical form are recognized.
1462 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1463 canonical form so that they will be recognized. */
1466 s390_decompose_address (rtx addr, struct s390_address *out)
1468 HOST_WIDE_INT offset = 0;
1469 rtx base = NULL_RTX;
1470 rtx indx = NULL_RTX;
1471 rtx disp = NULL_RTX;
1473 bool pointer = false;
1474 bool base_ptr = false;
1475 bool indx_ptr = false;
1477 /* Decompose address into base + index + displacement. */
1479 if (GET_CODE (addr) == REG || GET_CODE (addr) == UNSPEC)
1482 else if (GET_CODE (addr) == PLUS)
1484 rtx op0 = XEXP (addr, 0);
1485 rtx op1 = XEXP (addr, 1);
1486 enum rtx_code code0 = GET_CODE (op0);
1487 enum rtx_code code1 = GET_CODE (op1);
1489 if (code0 == REG || code0 == UNSPEC)
1491 if (code1 == REG || code1 == UNSPEC)
1493 indx = op0; /* index + base */
1499 base = op0; /* base + displacement */
1504 else if (code0 == PLUS)
1506 indx = XEXP (op0, 0); /* index + base + disp */
1507 base = XEXP (op0, 1);
1518 disp = addr; /* displacement */
1520 /* Extract integer part of displacement. */
1524 if (GET_CODE (disp) == CONST_INT)
1526 offset = INTVAL (disp);
1529 else if (GET_CODE (disp) == CONST
1530 && GET_CODE (XEXP (disp, 0)) == PLUS
1531 && GET_CODE (XEXP (XEXP (disp, 0), 1)) == CONST_INT)
1533 offset = INTVAL (XEXP (XEXP (disp, 0), 1));
1534 disp = XEXP (XEXP (disp, 0), 0);
1538 /* Strip off CONST here to avoid special case tests later. */
1539 if (disp && GET_CODE (disp) == CONST)
1540 disp = XEXP (disp, 0);
1542 /* We can convert literal pool addresses to
1543 displacements by basing them off the base register. */
1544 if (disp && GET_CODE (disp) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (disp))
1546 /* Either base or index must be free to hold the base register. */
1548 base = gen_rtx_REG (Pmode, BASE_REGNUM);
1550 indx = gen_rtx_REG (Pmode, BASE_REGNUM);
1554 /* Mark up the displacement. */
1555 disp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, disp),
1556 UNSPEC_LTREL_OFFSET);
1559 /* Validate base register. */
1562 if (GET_CODE (base) == UNSPEC)
1563 switch (XINT (base, 1))
1567 disp = gen_rtx_UNSPEC (Pmode,
1568 gen_rtvec (1, XVECEXP (base, 0, 0)),
1569 UNSPEC_LTREL_OFFSET);
1573 base = gen_rtx_REG (Pmode, BASE_REGNUM);
1576 case UNSPEC_LTREL_BASE:
1577 base = gen_rtx_REG (Pmode, BASE_REGNUM);
1584 if (GET_CODE (base) != REG || GET_MODE (base) != Pmode)
1587 if (REGNO (base) == BASE_REGNUM
1588 || REGNO (base) == STACK_POINTER_REGNUM
1589 || REGNO (base) == FRAME_POINTER_REGNUM
1590 || ((reload_completed || reload_in_progress)
1591 && frame_pointer_needed
1592 && REGNO (base) == HARD_FRAME_POINTER_REGNUM)
1593 || REGNO (base) == ARG_POINTER_REGNUM
1595 && REGNO (base) == PIC_OFFSET_TABLE_REGNUM))
1596 pointer = base_ptr = true;
1599 /* Validate index register. */
1602 if (GET_CODE (indx) == UNSPEC)
1603 switch (XINT (indx, 1))
1607 disp = gen_rtx_UNSPEC (Pmode,
1608 gen_rtvec (1, XVECEXP (indx, 0, 0)),
1609 UNSPEC_LTREL_OFFSET);
1613 indx = gen_rtx_REG (Pmode, BASE_REGNUM);
1616 case UNSPEC_LTREL_BASE:
1617 indx = gen_rtx_REG (Pmode, BASE_REGNUM);
1624 if (GET_CODE (indx) != REG || GET_MODE (indx) != Pmode)
1627 if (REGNO (indx) == BASE_REGNUM
1628 || REGNO (indx) == STACK_POINTER_REGNUM
1629 || REGNO (indx) == FRAME_POINTER_REGNUM
1630 || ((reload_completed || reload_in_progress)
1631 && frame_pointer_needed
1632 && REGNO (indx) == HARD_FRAME_POINTER_REGNUM)
1633 || REGNO (indx) == ARG_POINTER_REGNUM
1635 && REGNO (indx) == PIC_OFFSET_TABLE_REGNUM))
1636 pointer = indx_ptr = true;
1639 /* Prefer to use pointer as base, not index. */
1640 if (base && indx && !base_ptr
1641 && (indx_ptr || (!REG_POINTER (base) && REG_POINTER (indx))))
1648 /* Validate displacement. */
1651 /* If virtual registers are involved, the displacement will change later
1652 anyway as the virtual registers get eliminated. This could make a
1653 valid displacement invalid, but it is more likely to make an invalid
1654 displacement valid, because we sometimes access the register save area
1655 via negative offsets to one of those registers.
1656 Thus we don't check the displacement for validity here. If after
1657 elimination the displacement turns out to be invalid after all,
1658 this is fixed up by reload in any case. */
1659 if (base != arg_pointer_rtx
1660 && indx != arg_pointer_rtx
1661 && base != return_address_pointer_rtx
1662 && indx != return_address_pointer_rtx
1663 && base != frame_pointer_rtx
1664 && indx != frame_pointer_rtx
1665 && base != virtual_stack_vars_rtx
1666 && indx != virtual_stack_vars_rtx)
1667 if (!DISP_IN_RANGE (offset))
1672 /* All the special cases are pointers. */
1675 /* In the small-PIC case, the linker converts @GOT
1676 and @GOTNTPOFF offsets to possible displacements. */
1677 if (GET_CODE (disp) == UNSPEC
1678 && (XINT (disp, 1) == UNSPEC_GOT
1679 || XINT (disp, 1) == UNSPEC_GOTNTPOFF)
1686 /* Accept chunkified literal pool symbol references. */
1687 else if (GET_CODE (disp) == MINUS
1688 && GET_CODE (XEXP (disp, 0)) == LABEL_REF
1689 && GET_CODE (XEXP (disp, 1)) == LABEL_REF)
1694 /* Accept literal pool references. */
1695 else if (GET_CODE (disp) == UNSPEC
1696 && XINT (disp, 1) == UNSPEC_LTREL_OFFSET)
1698 orig_disp = gen_rtx_CONST (Pmode, disp);
1701 /* If we have an offset, make sure it does not
1702 exceed the size of the constant pool entry. */
1703 rtx sym = XVECEXP (disp, 0, 0);
1704 if (offset >= GET_MODE_SIZE (get_pool_mode (sym)))
1707 orig_disp = plus_constant (orig_disp, offset);
1722 out->disp = orig_disp;
1723 out->pointer = pointer;
1729 /* Decompose a RTL expression OP for a shift count into its components,
1730 and return the base register in BASE and the offset in OFFSET.
1732 If BITS is non-zero, the expression is used in a context where only
1733 that number to low-order bits is significant. We then allow OP to
1734 contain and outer AND that does not affect significant bits. If BITS
1735 is zero, we allow OP to contain any outer AND with a constant.
1737 Return true if OP is a valid shift count, false if not. */
1740 s390_decompose_shift_count (rtx op, rtx *base, HOST_WIDE_INT *offset, int bits)
1742 HOST_WIDE_INT off = 0;
1744 /* Drop outer ANDs. */
1745 if (GET_CODE (op) == AND && GET_CODE (XEXP (op, 1)) == CONST_INT)
1747 HOST_WIDE_INT mask = ((HOST_WIDE_INT)1 << bits) - 1;
1748 if ((INTVAL (XEXP (op, 1)) & mask) != mask)
1754 /* We can have an integer constant, an address register,
1755 or a sum of the two. */
1756 if (GET_CODE (op) == CONST_INT)
1761 if (op && GET_CODE (op) == PLUS && GET_CODE (XEXP (op, 1)) == CONST_INT)
1763 off = INTVAL (XEXP (op, 1));
1766 while (op && GET_CODE (op) == SUBREG)
1767 op = SUBREG_REG (op);
1769 if (op && GET_CODE (op) != REG)
1781 /* Return true if CODE is a valid address without index. */
1784 s390_legitimate_address_without_index_p (rtx op)
1786 struct s390_address addr;
1788 if (!s390_decompose_address (XEXP (op, 0), &addr))
1796 /* Return 1 if OP is a valid operand for a C constraint, 0 else. */
1799 s390_extra_constraint_str (rtx op, int c, const char * str)
1801 struct s390_address addr;
1803 gcc_assert (c == str[0]);
1805 /* Check for offsettable variants of memory constraints. */
1808 /* Only accept non-volatile MEMs. */
1809 if (!MEM_P (op) || MEM_VOLATILE_P (op))
1812 if ((reload_completed || reload_in_progress)
1813 ? !offsettable_memref_p (op)
1814 : !offsettable_nonstrict_memref_p (op))
1820 /* Check for non-literal-pool variants of memory constraints. */
1823 if (GET_CODE (op) != MEM)
1825 if (!s390_decompose_address (XEXP (op, 0), &addr))
1827 if (addr.base && REG_P (addr.base) && REGNO (addr.base) == BASE_REGNUM)
1829 if (addr.indx && REG_P (addr.indx) && REGNO (addr.indx) == BASE_REGNUM)
1838 if (GET_CODE (op) != MEM)
1840 if (!s390_decompose_address (XEXP (op, 0), &addr))
1845 if (TARGET_LONG_DISPLACEMENT)
1847 if (!s390_short_displacement (addr.disp))
1853 if (GET_CODE (op) != MEM)
1856 if (TARGET_LONG_DISPLACEMENT)
1858 if (!s390_decompose_address (XEXP (op, 0), &addr))
1860 if (!s390_short_displacement (addr.disp))
1866 if (!TARGET_LONG_DISPLACEMENT)
1868 if (GET_CODE (op) != MEM)
1870 if (!s390_decompose_address (XEXP (op, 0), &addr))
1874 if (s390_short_displacement (addr.disp))
1879 if (!TARGET_LONG_DISPLACEMENT)
1881 if (GET_CODE (op) != MEM)
1883 /* Any invalid address here will be fixed up by reload,
1884 so accept it for the most generic constraint. */
1885 if (s390_decompose_address (XEXP (op, 0), &addr)
1886 && s390_short_displacement (addr.disp))
1891 if (TARGET_LONG_DISPLACEMENT)
1893 if (!s390_decompose_address (op, &addr))
1895 if (!s390_short_displacement (addr.disp))
1901 if (!TARGET_LONG_DISPLACEMENT)
1903 /* Any invalid address here will be fixed up by reload,
1904 so accept it for the most generic constraint. */
1905 if (s390_decompose_address (op, &addr)
1906 && s390_short_displacement (addr.disp))
1911 /* Simply check for the basic form of a shift count. Reload will
1912 take care of making sure we have a proper base register. */
1913 if (!s390_decompose_shift_count (op, NULL, NULL, 0))
1924 /* Return true if VALUE matches the constraint STR. */
1927 s390_const_double_ok_for_constraint_p (rtx value,
1931 gcc_assert (c == str[0]);
1936 /* The floating point zero constant. */
1937 return (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT
1938 && value == CONST0_RTX (GET_MODE (value)));
1945 /* Return true if VALUE matches the constraint STR. */
1948 s390_const_ok_for_constraint_p (HOST_WIDE_INT value,
1952 enum machine_mode mode, part_mode;
1954 int part, part_goal;
1956 gcc_assert (c == str[0]);
1961 return (unsigned int)value < 256;
1964 return (unsigned int)value < 4096;
1967 return value >= -32768 && value < 32768;
1970 return (TARGET_LONG_DISPLACEMENT ?
1971 (value >= -524288 && value <= 524287)
1972 : (value >= 0 && value <= 4095));
1974 return value == 2147483647;
1980 part_goal = str[1] - '0';
1984 case 'Q': part_mode = QImode; break;
1985 case 'H': part_mode = HImode; break;
1986 case 'S': part_mode = SImode; break;
1992 case 'H': mode = HImode; break;
1993 case 'S': mode = SImode; break;
1994 case 'D': mode = DImode; break;
2000 case '0': def = 0; break;
2001 case 'F': def = -1; break;
2005 if (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (part_mode))
2008 part = s390_single_part (GEN_INT (value), mode, part_mode, def);
2011 if (part_goal != -1 && part_goal != part)
2023 return trunc_int_for_mode (value, SImode) == value;
2027 || s390_single_part (GEN_INT (value), DImode, SImode, 0) == 1;
2031 || s390_single_part (GEN_INT (value), DImode, SImode, -1) == 1;
2039 return legitimate_reload_constant_p (GEN_INT (value));
2048 /* Compute a (partial) cost for rtx X. Return true if the complete
2049 cost has been computed, and false if subexpressions should be
2050 scanned. In either case, *TOTAL contains the cost result.
2051 CODE contains GET_CODE (x), OUTER_CODE contains the code
2052 of the superexpression of x. */
2055 s390_rtx_costs (rtx x, int code, int outer_code, int *total)
2078 *total = COSTS_N_INSNS (1);
2083 /* Check for multiply and add. */
2084 if ((GET_MODE (x) == DFmode || GET_MODE (x) == SFmode)
2085 && GET_CODE (XEXP (x, 0)) == MULT
2086 && TARGET_HARD_FLOAT && TARGET_IEEE_FLOAT && TARGET_FUSED_MADD)
2088 /* This is the multiply and add case. */
2089 if (GET_MODE (x) == DFmode)
2090 *total = s390_cost->madbr;
2092 *total = s390_cost->maebr;
2093 *total += rtx_cost (XEXP (XEXP (x, 0), 0), MULT)
2094 + rtx_cost (XEXP (XEXP (x, 0), 1), MULT)
2095 + rtx_cost (XEXP (x, 1), code);
2096 return true; /* Do not do an additional recursive descent. */
2098 *total = COSTS_N_INSNS (1);
2102 switch (GET_MODE (x))
2106 rtx left = XEXP (x, 0);
2107 rtx right = XEXP (x, 1);
2108 if (GET_CODE (right) == CONST_INT
2109 && CONST_OK_FOR_K (INTVAL (right)))
2110 *total = s390_cost->mhi;
2111 else if (GET_CODE (left) == SIGN_EXTEND)
2112 *total = s390_cost->mh;
2114 *total = s390_cost->ms; /* msr, ms, msy */
2119 rtx left = XEXP (x, 0);
2120 rtx right = XEXP (x, 1);
2123 if (GET_CODE (right) == CONST_INT
2124 && CONST_OK_FOR_K (INTVAL (right)))
2125 *total = s390_cost->mghi;
2126 else if (GET_CODE (left) == SIGN_EXTEND)
2127 *total = s390_cost->msgf;
2129 *total = s390_cost->msg; /* msgr, msg */
2131 else /* TARGET_31BIT */
2133 if (GET_CODE (left) == SIGN_EXTEND
2134 && GET_CODE (right) == SIGN_EXTEND)
2135 /* mulsidi case: mr, m */
2136 *total = s390_cost->m;
2137 else if (GET_CODE (left) == ZERO_EXTEND
2138 && GET_CODE (right) == ZERO_EXTEND
2139 && TARGET_CPU_ZARCH)
2140 /* umulsidi case: ml, mlr */
2141 *total = s390_cost->ml;
2143 /* Complex calculation is required. */
2144 *total = COSTS_N_INSNS (40);
2150 *total = s390_cost->mult_df;
2159 if (GET_MODE (x) == TImode) /* 128 bit division */
2160 *total = s390_cost->dlgr;
2161 else if (GET_MODE (x) == DImode)
2163 rtx right = XEXP (x, 1);
2164 if (GET_CODE (right) == ZERO_EXTEND) /* 64 by 32 bit division */
2165 *total = s390_cost->dlr;
2166 else /* 64 by 64 bit division */
2167 *total = s390_cost->dlgr;
2169 else if (GET_MODE (x) == SImode) /* 32 bit division */
2170 *total = s390_cost->dlr;
2175 if (GET_MODE (x) == DImode)
2177 rtx right = XEXP (x, 1);
2178 if (GET_CODE (right) == ZERO_EXTEND) /* 64 by 32 bit division */
2180 *total = s390_cost->dsgfr;
2182 *total = s390_cost->dr;
2183 else /* 64 by 64 bit division */
2184 *total = s390_cost->dsgr;
2186 else if (GET_MODE (x) == SImode) /* 32 bit division */
2187 *total = s390_cost->dlr;
2188 else if (GET_MODE (x) == SFmode)
2190 if (TARGET_IEEE_FLOAT)
2191 *total = s390_cost->debr;
2192 else /* TARGET_IBM_FLOAT */
2193 *total = s390_cost->der;
2195 else if (GET_MODE (x) == DFmode)
2197 if (TARGET_IEEE_FLOAT)
2198 *total = s390_cost->ddbr;
2199 else /* TARGET_IBM_FLOAT */
2200 *total = s390_cost->ddr;
2205 if (GET_MODE (x) == SFmode)
2206 *total = s390_cost->sqebr;
2208 *total = s390_cost->sqdbr;
2213 if (outer_code == MULT || outer_code == DIV || outer_code == MOD
2214 || outer_code == PLUS || outer_code == MINUS
2215 || outer_code == COMPARE)
2220 *total = COSTS_N_INSNS (1);
2221 if (GET_CODE (XEXP (x, 0)) == AND
2222 && GET_CODE (XEXP (x, 1)) == CONST_INT
2223 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
2225 rtx op0 = XEXP (XEXP (x, 0), 0);
2226 rtx op1 = XEXP (XEXP (x, 0), 1);
2227 rtx op2 = XEXP (x, 1);
2229 if (memory_operand (op0, GET_MODE (op0))
2230 && s390_tm_ccmode (op1, op2, 0) != VOIDmode)
2232 if (register_operand (op0, GET_MODE (op0))
2233 && s390_tm_ccmode (op1, op2, 1) != VOIDmode)
2243 /* Return the cost of an address rtx ADDR. */
2246 s390_address_cost (rtx addr)
2248 struct s390_address ad;
2249 if (!s390_decompose_address (addr, &ad))
2252 return ad.indx? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2255 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2256 otherwise return 0. */
2259 tls_symbolic_operand (rtx op)
2261 if (GET_CODE (op) != SYMBOL_REF)
2263 return SYMBOL_REF_TLS_MODEL (op);
2266 /* Split DImode access register reference REG (on 64-bit) into its constituent
2267 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2268 gen_highpart cannot be used as they assume all registers are word-sized,
2269 while our access registers have only half that size. */
2272 s390_split_access_reg (rtx reg, rtx *lo, rtx *hi)
2274 gcc_assert (TARGET_64BIT);
2275 gcc_assert (ACCESS_REG_P (reg));
2276 gcc_assert (GET_MODE (reg) == DImode);
2277 gcc_assert (!(REGNO (reg) & 1));
2279 *lo = gen_rtx_REG (SImode, REGNO (reg) + 1);
2280 *hi = gen_rtx_REG (SImode, REGNO (reg));
2283 /* Return true if OP contains a symbol reference */
2286 symbolic_reference_mentioned_p (rtx op)
2291 if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
2294 fmt = GET_RTX_FORMAT (GET_CODE (op));
2295 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
2301 for (j = XVECLEN (op, i) - 1; j >= 0; j--)
2302 if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
2306 else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
2313 /* Return true if OP contains a reference to a thread-local symbol. */
2316 tls_symbolic_reference_mentioned_p (rtx op)
2321 if (GET_CODE (op) == SYMBOL_REF)
2322 return tls_symbolic_operand (op);
2324 fmt = GET_RTX_FORMAT (GET_CODE (op));
2325 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
2331 for (j = XVECLEN (op, i) - 1; j >= 0; j--)
2332 if (tls_symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
2336 else if (fmt[i] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op, i)))
2344 /* Return true if OP is a legitimate general operand when
2345 generating PIC code. It is given that flag_pic is on
2346 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2349 legitimate_pic_operand_p (rtx op)
2351 /* Accept all non-symbolic constants. */
2352 if (!SYMBOLIC_CONST (op))
2355 /* Reject everything else; must be handled
2356 via emit_symbolic_move. */
2360 /* Returns true if the constant value OP is a legitimate general operand.
2361 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2364 legitimate_constant_p (rtx op)
2366 /* Accept all non-symbolic constants. */
2367 if (!SYMBOLIC_CONST (op))
2370 /* Accept immediate LARL operands. */
2371 if (TARGET_CPU_ZARCH && larl_operand (op, VOIDmode))
2374 /* Thread-local symbols are never legal constants. This is
2375 so that emit_call knows that computing such addresses
2376 might require a function call. */
2377 if (TLS_SYMBOLIC_CONST (op))
2380 /* In the PIC case, symbolic constants must *not* be
2381 forced into the literal pool. We accept them here,
2382 so that they will be handled by emit_symbolic_move. */
2386 /* All remaining non-PIC symbolic constants are
2387 forced into the literal pool. */
2391 /* Determine if it's legal to put X into the constant pool. This
2392 is not possible if X contains the address of a symbol that is
2393 not constant (TLS) or not known at final link time (PIC). */
2396 s390_cannot_force_const_mem (rtx x)
2398 switch (GET_CODE (x))
2402 /* Accept all non-symbolic constants. */
2406 /* Labels are OK iff we are non-PIC. */
2407 return flag_pic != 0;
2410 /* 'Naked' TLS symbol references are never OK,
2411 non-TLS symbols are OK iff we are non-PIC. */
2412 if (tls_symbolic_operand (x))
2415 return flag_pic != 0;
2418 return s390_cannot_force_const_mem (XEXP (x, 0));
2421 return s390_cannot_force_const_mem (XEXP (x, 0))
2422 || s390_cannot_force_const_mem (XEXP (x, 1));
2425 switch (XINT (x, 1))
2427 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2428 case UNSPEC_LTREL_OFFSET:
2436 case UNSPEC_GOTNTPOFF:
2437 case UNSPEC_INDNTPOFF:
2440 /* If the literal pool shares the code section, be put
2441 execute template placeholders into the pool as well. */
2443 return TARGET_CPU_ZARCH;
2455 /* Returns true if the constant value OP is a legitimate general
2456 operand during and after reload. The difference to
2457 legitimate_constant_p is that this function will not accept
2458 a constant that would need to be forced to the literal pool
2459 before it can be used as operand. */
2462 legitimate_reload_constant_p (rtx op)
2464 /* Accept la(y) operands. */
2465 if (GET_CODE (op) == CONST_INT
2466 && DISP_IN_RANGE (INTVAL (op)))
2469 /* Accept l(g)hi/l(g)fi operands. */
2470 if (GET_CODE (op) == CONST_INT
2471 && (CONST_OK_FOR_K (INTVAL (op)) || CONST_OK_FOR_Os (INTVAL (op))))
2474 /* Accept lliXX operands. */
2476 && GET_CODE (op) == CONST_INT
2477 && trunc_int_for_mode (INTVAL (op), word_mode) == INTVAL (op)
2478 && s390_single_part (op, word_mode, HImode, 0) >= 0)
2482 && GET_CODE (op) == CONST_INT
2483 && trunc_int_for_mode (INTVAL (op), word_mode) == INTVAL (op)
2484 && s390_single_part (op, word_mode, SImode, 0) >= 0)
2487 /* Accept larl operands. */
2488 if (TARGET_CPU_ZARCH
2489 && larl_operand (op, VOIDmode))
2492 /* Accept lzXX operands. */
2493 if (GET_CODE (op) == CONST_DOUBLE
2494 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', "G"))
2497 /* Accept double-word operands that can be split. */
2498 if (GET_CODE (op) == CONST_INT
2499 && trunc_int_for_mode (INTVAL (op), word_mode) != INTVAL (op))
2501 enum machine_mode dword_mode = word_mode == SImode ? DImode : TImode;
2502 rtx hi = operand_subword (op, 0, 0, dword_mode);
2503 rtx lo = operand_subword (op, 1, 0, dword_mode);
2504 return legitimate_reload_constant_p (hi)
2505 && legitimate_reload_constant_p (lo);
2508 /* Everything else cannot be handled without reload. */
2512 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2513 return the class of reg to actually use. */
2516 s390_preferred_reload_class (rtx op, enum reg_class class)
2518 switch (GET_CODE (op))
2520 /* Constants we cannot reload must be forced into the
2525 if (legitimate_reload_constant_p (op))
2530 /* If a symbolic constant or a PLUS is reloaded,
2531 it is most likely being used as an address, so
2532 prefer ADDR_REGS. If 'class' is not a superset
2533 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2538 if (reg_class_subset_p (ADDR_REGS, class))
2550 /* Return the register class of a scratch register needed to
2551 load IN into a register of class CLASS in MODE.
2553 We need a temporary when loading a PLUS expression which
2554 is not a legitimate operand of the LOAD ADDRESS instruction. */
2557 s390_secondary_input_reload_class (enum reg_class class,
2558 enum machine_mode mode, rtx in)
2560 if (s390_plus_operand (in, mode))
2563 if (reg_classes_intersect_p (CC_REGS, class))
2564 return GENERAL_REGS;
2569 /* Return the register class of a scratch register needed to
2570 store a register of class CLASS in MODE into OUT:
2572 We need a temporary when storing a double-word to a
2573 non-offsettable memory address. */
2576 s390_secondary_output_reload_class (enum reg_class class,
2577 enum machine_mode mode, rtx out)
2579 if ((TARGET_64BIT ? mode == TImode
2580 : (mode == DImode || mode == DFmode))
2581 && reg_classes_intersect_p (GENERAL_REGS, class)
2582 && GET_CODE (out) == MEM
2583 && GET_CODE (XEXP (out, 0)) == PLUS
2584 && GET_CODE (XEXP (XEXP (out, 0), 0)) == PLUS
2585 && GET_CODE (XEXP (XEXP (out, 0), 1)) == CONST_INT
2586 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out, 0), 1))
2587 + GET_MODE_SIZE (mode) - 1))
2590 if (reg_classes_intersect_p (CC_REGS, class))
2591 return GENERAL_REGS;
2596 /* Generate code to load SRC, which is PLUS that is not a
2597 legitimate operand for the LA instruction, into TARGET.
2598 SCRATCH may be used as scratch register. */
2601 s390_expand_plus_operand (rtx target, rtx src,
2605 struct s390_address ad;
2607 /* src must be a PLUS; get its two operands. */
2608 gcc_assert (GET_CODE (src) == PLUS);
2609 gcc_assert (GET_MODE (src) == Pmode);
2611 /* Check if any of the two operands is already scheduled
2612 for replacement by reload. This can happen e.g. when
2613 float registers occur in an address. */
2614 sum1 = find_replacement (&XEXP (src, 0));
2615 sum2 = find_replacement (&XEXP (src, 1));
2616 src = gen_rtx_PLUS (Pmode, sum1, sum2);
2618 /* If the address is already strictly valid, there's nothing to do. */
2619 if (!s390_decompose_address (src, &ad)
2620 || (ad.base && !REG_OK_FOR_BASE_STRICT_P (ad.base))
2621 || (ad.indx && !REG_OK_FOR_INDEX_STRICT_P (ad.indx)))
2623 /* Otherwise, one of the operands cannot be an address register;
2624 we reload its value into the scratch register. */
2625 if (true_regnum (sum1) < 1 || true_regnum (sum1) > 15)
2627 emit_move_insn (scratch, sum1);
2630 if (true_regnum (sum2) < 1 || true_regnum (sum2) > 15)
2632 emit_move_insn (scratch, sum2);
2636 /* According to the way these invalid addresses are generated
2637 in reload.c, it should never happen (at least on s390) that
2638 *neither* of the PLUS components, after find_replacements
2639 was applied, is an address register. */
2640 if (sum1 == scratch && sum2 == scratch)
2646 src = gen_rtx_PLUS (Pmode, sum1, sum2);
2649 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2650 is only ever performed on addresses, so we can mark the
2651 sum as legitimate for LA in any case. */
2652 s390_load_address (target, src);
2656 /* Return true if ADDR is a valid memory address.
2657 STRICT specifies whether strict register checking applies. */
2660 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
2661 rtx addr, int strict)
2663 struct s390_address ad;
2664 if (!s390_decompose_address (addr, &ad))
2669 if (ad.base && !REG_OK_FOR_BASE_STRICT_P (ad.base))
2671 if (ad.indx && !REG_OK_FOR_INDEX_STRICT_P (ad.indx))
2676 if (ad.base && !REG_OK_FOR_BASE_NONSTRICT_P (ad.base))
2678 if (ad.indx && !REG_OK_FOR_INDEX_NONSTRICT_P (ad.indx))
2685 /* Return true if OP is a valid operand for the LA instruction.
2686 In 31-bit, we need to prove that the result is used as an
2687 address, as LA performs only a 31-bit addition. */
2690 legitimate_la_operand_p (rtx op)
2692 struct s390_address addr;
2693 if (!s390_decompose_address (op, &addr))
2696 return (TARGET_64BIT || addr.pointer);
2699 /* Return true if it is valid *and* preferable to use LA to
2700 compute the sum of OP1 and OP2. */
2703 preferred_la_operand_p (rtx op1, rtx op2)
2705 struct s390_address addr;
2707 if (op2 != const0_rtx)
2708 op1 = gen_rtx_PLUS (Pmode, op1, op2);
2710 if (!s390_decompose_address (op1, &addr))
2712 if (addr.base && !REG_OK_FOR_BASE_STRICT_P (addr.base))
2714 if (addr.indx && !REG_OK_FOR_INDEX_STRICT_P (addr.indx))
2717 if (!TARGET_64BIT && !addr.pointer)
2723 if ((addr.base && REG_P (addr.base) && REG_POINTER (addr.base))
2724 || (addr.indx && REG_P (addr.indx) && REG_POINTER (addr.indx)))
2730 /* Emit a forced load-address operation to load SRC into DST.
2731 This will use the LOAD ADDRESS instruction even in situations
2732 where legitimate_la_operand_p (SRC) returns false. */
2735 s390_load_address (rtx dst, rtx src)
2738 emit_move_insn (dst, src);
2740 emit_insn (gen_force_la_31 (dst, src));
2743 /* Return a legitimate reference for ORIG (an address) using the
2744 register REG. If REG is 0, a new pseudo is generated.
2746 There are two types of references that must be handled:
2748 1. Global data references must load the address from the GOT, via
2749 the PIC reg. An insn is emitted to do this load, and the reg is
2752 2. Static data references, constant pool addresses, and code labels
2753 compute the address as an offset from the GOT, whose base is in
2754 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2755 differentiate them from global data objects. The returned
2756 address is the PIC reg + an unspec constant.
2758 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2759 reg also appears in the address. */
2762 legitimize_pic_address (rtx orig, rtx reg)
2768 if (GET_CODE (addr) == LABEL_REF
2769 || (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (addr)))
2771 /* This is a local symbol. */
2772 if (TARGET_CPU_ZARCH && larl_operand (addr, VOIDmode))
2774 /* Access local symbols PC-relative via LARL.
2775 This is the same as in the non-PIC case, so it is
2776 handled automatically ... */
2780 /* Access local symbols relative to the GOT. */
2782 rtx temp = reg? reg : gen_reg_rtx (Pmode);
2784 if (reload_in_progress || reload_completed)
2785 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
2787 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
2788 addr = gen_rtx_CONST (Pmode, addr);
2789 addr = force_const_mem (Pmode, addr);
2790 emit_move_insn (temp, addr);
2792 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
2795 s390_load_address (reg, new);
2800 else if (GET_CODE (addr) == SYMBOL_REF)
2803 reg = gen_reg_rtx (Pmode);
2807 /* Assume GOT offset < 4k. This is handled the same way
2808 in both 31- and 64-bit code (@GOT). */
2810 if (reload_in_progress || reload_completed)
2811 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
2813 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
2814 new = gen_rtx_CONST (Pmode, new);
2815 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
2816 new = gen_const_mem (Pmode, new);
2817 emit_move_insn (reg, new);
2820 else if (TARGET_CPU_ZARCH)
2822 /* If the GOT offset might be >= 4k, we determine the position
2823 of the GOT entry via a PC-relative LARL (@GOTENT). */
2825 rtx temp = gen_reg_rtx (Pmode);
2827 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTENT);
2828 new = gen_rtx_CONST (Pmode, new);
2829 emit_move_insn (temp, new);
2831 new = gen_const_mem (Pmode, temp);
2832 emit_move_insn (reg, new);
2837 /* If the GOT offset might be >= 4k, we have to load it
2838 from the literal pool (@GOT). */
2840 rtx temp = gen_reg_rtx (Pmode);
2842 if (reload_in_progress || reload_completed)
2843 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
2845 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
2846 addr = gen_rtx_CONST (Pmode, addr);
2847 addr = force_const_mem (Pmode, addr);
2848 emit_move_insn (temp, addr);
2850 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
2851 new = gen_const_mem (Pmode, new);
2852 emit_move_insn (reg, new);
2858 if (GET_CODE (addr) == CONST)
2860 addr = XEXP (addr, 0);
2861 if (GET_CODE (addr) == UNSPEC)
2863 gcc_assert (XVECLEN (addr, 0) == 1);
2864 switch (XINT (addr, 1))
2866 /* If someone moved a GOT-relative UNSPEC
2867 out of the literal pool, force them back in. */
2870 new = force_const_mem (Pmode, orig);
2873 /* @GOT is OK as is if small. */
2876 new = force_const_mem (Pmode, orig);
2879 /* @GOTENT is OK as is. */
2883 /* @PLT is OK as is on 64-bit, must be converted to
2884 GOT-relative @PLTOFF on 31-bit. */
2886 if (!TARGET_CPU_ZARCH)
2888 rtx temp = reg? reg : gen_reg_rtx (Pmode);
2890 if (reload_in_progress || reload_completed)
2891 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
2893 addr = XVECEXP (addr, 0, 0);
2894 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
2896 addr = gen_rtx_CONST (Pmode, addr);
2897 addr = force_const_mem (Pmode, addr);
2898 emit_move_insn (temp, addr);
2900 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
2903 s390_load_address (reg, new);
2909 /* Everything else cannot happen. */
2915 gcc_assert (GET_CODE (addr) == PLUS);
2917 if (GET_CODE (addr) == PLUS)
2919 rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
2920 /* Check first to see if this is a constant offset
2921 from a local symbol reference. */
2922 if ((GET_CODE (op0) == LABEL_REF
2923 || (GET_CODE (op0) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (op0)))
2924 && GET_CODE (op1) == CONST_INT)
2926 if (TARGET_CPU_ZARCH && larl_operand (op0, VOIDmode))
2928 if (INTVAL (op1) & 1)
2930 /* LARL can't handle odd offsets, so emit a
2931 pair of LARL and LA. */
2932 rtx temp = reg? reg : gen_reg_rtx (Pmode);
2934 if (!DISP_IN_RANGE (INTVAL (op1)))
2936 int even = INTVAL (op1) - 1;
2937 op0 = gen_rtx_PLUS (Pmode, op0, GEN_INT (even));
2938 op0 = gen_rtx_CONST (Pmode, op0);
2942 emit_move_insn (temp, op0);
2943 new = gen_rtx_PLUS (Pmode, temp, op1);
2947 s390_load_address (reg, new);
2953 /* If the offset is even, we can just use LARL.
2954 This will happen automatically. */
2959 /* Access local symbols relative to the GOT. */
2961 rtx temp = reg? reg : gen_reg_rtx (Pmode);
2963 if (reload_in_progress || reload_completed)
2964 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
2966 addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
2968 addr = gen_rtx_PLUS (Pmode, addr, op1);
2969 addr = gen_rtx_CONST (Pmode, addr);
2970 addr = force_const_mem (Pmode, addr);
2971 emit_move_insn (temp, addr);
2973 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
2976 s390_load_address (reg, new);
2982 /* Now, check whether it is a GOT relative symbol plus offset
2983 that was pulled out of the literal pool. Force it back in. */
2985 else if (GET_CODE (op0) == UNSPEC
2986 && GET_CODE (op1) == CONST_INT
2987 && XINT (op0, 1) == UNSPEC_GOTOFF)
2989 gcc_assert (XVECLEN (op0, 0) == 1);
2991 new = force_const_mem (Pmode, orig);
2994 /* Otherwise, compute the sum. */
2997 base = legitimize_pic_address (XEXP (addr, 0), reg);
2998 new = legitimize_pic_address (XEXP (addr, 1),
2999 base == reg ? NULL_RTX : reg);
3000 if (GET_CODE (new) == CONST_INT)
3001 new = plus_constant (base, INTVAL (new));
3004 if (GET_CODE (new) == PLUS && CONSTANT_P (XEXP (new, 1)))
3006 base = gen_rtx_PLUS (Pmode, base, XEXP (new, 0));
3007 new = XEXP (new, 1);
3009 new = gen_rtx_PLUS (Pmode, base, new);
3012 if (GET_CODE (new) == CONST)
3013 new = XEXP (new, 0);
3014 new = force_operand (new, 0);
3021 /* Load the thread pointer into a register. */
3024 s390_get_thread_pointer (void)
3026 rtx tp = gen_reg_rtx (Pmode);
3028 emit_move_insn (tp, gen_rtx_REG (Pmode, TP_REGNUM));
3029 mark_reg_pointer (tp, BITS_PER_WORD);
3034 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3035 in s390_tls_symbol which always refers to __tls_get_offset.
3036 The returned offset is written to RESULT_REG and an USE rtx is
3037 generated for TLS_CALL. */
3039 static GTY(()) rtx s390_tls_symbol;
3042 s390_emit_tls_call_insn (rtx result_reg, rtx tls_call)
3046 gcc_assert (flag_pic);
3048 if (!s390_tls_symbol)
3049 s390_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_offset");
3051 insn = s390_emit_call (s390_tls_symbol, tls_call, result_reg,
3052 gen_rtx_REG (Pmode, RETURN_REGNUM));
3054 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), result_reg);
3055 CONST_OR_PURE_CALL_P (insn) = 1;
3058 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3059 this (thread-local) address. REG may be used as temporary. */
3062 legitimize_tls_address (rtx addr, rtx reg)
3064 rtx new, tls_call, temp, base, r2, insn;
3066 if (GET_CODE (addr) == SYMBOL_REF)
3067 switch (tls_symbolic_operand (addr))
3069 case TLS_MODEL_GLOBAL_DYNAMIC:
3071 r2 = gen_rtx_REG (Pmode, 2);
3072 tls_call = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_TLSGD);
3073 new = gen_rtx_CONST (Pmode, tls_call);
3074 new = force_const_mem (Pmode, new);
3075 emit_move_insn (r2, new);
3076 s390_emit_tls_call_insn (r2, tls_call);
3077 insn = get_insns ();
3080 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_NTPOFF);
3081 temp = gen_reg_rtx (Pmode);
3082 emit_libcall_block (insn, temp, r2, new);
3084 new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
3087 s390_load_address (reg, new);
3092 case TLS_MODEL_LOCAL_DYNAMIC:
3094 r2 = gen_rtx_REG (Pmode, 2);
3095 tls_call = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TLSLDM);
3096 new = gen_rtx_CONST (Pmode, tls_call);
3097 new = force_const_mem (Pmode, new);
3098 emit_move_insn (r2, new);
3099 s390_emit_tls_call_insn (r2, tls_call);
3100 insn = get_insns ();
3103 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TLSLDM_NTPOFF);
3104 temp = gen_reg_rtx (Pmode);
3105 emit_libcall_block (insn, temp, r2, new);
3107 new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
3108 base = gen_reg_rtx (Pmode);
3109 s390_load_address (base, new);
3111 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_DTPOFF);
3112 new = gen_rtx_CONST (Pmode, new);
3113 new = force_const_mem (Pmode, new);
3114 temp = gen_reg_rtx (Pmode);
3115 emit_move_insn (temp, new);
3117 new = gen_rtx_PLUS (Pmode, base, temp);
3120 s390_load_address (reg, new);
3125 case TLS_MODEL_INITIAL_EXEC:
3128 /* Assume GOT offset < 4k. This is handled the same way
3129 in both 31- and 64-bit code. */
3131 if (reload_in_progress || reload_completed)
3132 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
3134 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTNTPOFF);
3135 new = gen_rtx_CONST (Pmode, new);
3136 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new);
3137 new = gen_const_mem (Pmode, new);
3138 temp = gen_reg_rtx (Pmode);
3139 emit_move_insn (temp, new);
3141 else if (TARGET_CPU_ZARCH)
3143 /* If the GOT offset might be >= 4k, we determine the position
3144 of the GOT entry via a PC-relative LARL. */
3146 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_INDNTPOFF);
3147 new = gen_rtx_CONST (Pmode, new);
3148 temp = gen_reg_rtx (Pmode);
3149 emit_move_insn (temp, new);
3151 new = gen_const_mem (Pmode, temp);
3152 temp = gen_reg_rtx (Pmode);
3153 emit_move_insn (temp, new);
3157 /* If the GOT offset might be >= 4k, we have to load it
3158 from the literal pool. */
3160 if (reload_in_progress || reload_completed)
3161 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
3163 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTNTPOFF);
3164 new = gen_rtx_CONST (Pmode, new);
3165 new = force_const_mem (Pmode, new);
3166 temp = gen_reg_rtx (Pmode);
3167 emit_move_insn (temp, new);
3169 new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, temp);
3170 new = gen_const_mem (Pmode, new);
3172 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, new, addr), UNSPEC_TLS_LOAD);
3173 temp = gen_reg_rtx (Pmode);
3174 emit_insn (gen_rtx_SET (Pmode, temp, new));
3178 /* In position-dependent code, load the absolute address of
3179 the GOT entry from the literal pool. */
3181 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_INDNTPOFF);
3182 new = gen_rtx_CONST (Pmode, new);
3183 new = force_const_mem (Pmode, new);
3184 temp = gen_reg_rtx (Pmode);
3185 emit_move_insn (temp, new);
3188 new = gen_const_mem (Pmode, new);
3189 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, new, addr), UNSPEC_TLS_LOAD);
3190 temp = gen_reg_rtx (Pmode);
3191 emit_insn (gen_rtx_SET (Pmode, temp, new));
3194 new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
3197 s390_load_address (reg, new);
3202 case TLS_MODEL_LOCAL_EXEC:
3203 new = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_NTPOFF);
3204 new = gen_rtx_CONST (Pmode, new);
3205 new = force_const_mem (Pmode, new);
3206 temp = gen_reg_rtx (Pmode);
3207 emit_move_insn (temp, new);
3209 new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
3212 s390_load_address (reg, new);
3221 else if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == UNSPEC)
3223 switch (XINT (XEXP (addr, 0), 1))
3225 case UNSPEC_INDNTPOFF:
3226 gcc_assert (TARGET_CPU_ZARCH);
3235 else if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
3236 && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST_INT)
3238 new = XEXP (XEXP (addr, 0), 0);
3239 if (GET_CODE (new) != SYMBOL_REF)
3240 new = gen_rtx_CONST (Pmode, new);
3242 new = legitimize_tls_address (new, reg);
3243 new = plus_constant (new, INTVAL (XEXP (XEXP (addr, 0), 1)));
3244 new = force_operand (new, 0);
3248 gcc_unreachable (); /* for now ... */
3253 /* Emit insns to move operands[1] into operands[0]. */
3256 emit_symbolic_move (rtx *operands)
3258 rtx temp = no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode);
3260 if (GET_CODE (operands[0]) == MEM)
3261 operands[1] = force_reg (Pmode, operands[1]);
3262 else if (TLS_SYMBOLIC_CONST (operands[1]))
3263 operands[1] = legitimize_tls_address (operands[1], temp);
3265 operands[1] = legitimize_pic_address (operands[1], temp);
3268 /* Try machine-dependent ways of modifying an illegitimate address X
3269 to be legitimate. If we find one, return the new, valid address.
3271 OLDX is the address as it was before break_out_memory_refs was called.
3272 In some cases it is useful to look at this to decide what needs to be done.
3274 MODE is the mode of the operand pointed to by X.
3276 When -fpic is used, special handling is needed for symbolic references.
3277 See comments by legitimize_pic_address for details. */
3280 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3281 enum machine_mode mode ATTRIBUTE_UNUSED)
3283 rtx constant_term = const0_rtx;
3285 if (TLS_SYMBOLIC_CONST (x))
3287 x = legitimize_tls_address (x, 0);
3289 if (legitimate_address_p (mode, x, FALSE))
3294 if (SYMBOLIC_CONST (x)
3295 || (GET_CODE (x) == PLUS
3296 && (SYMBOLIC_CONST (XEXP (x, 0))
3297 || SYMBOLIC_CONST (XEXP (x, 1)))))
3298 x = legitimize_pic_address (x, 0);
3300 if (legitimate_address_p (mode, x, FALSE))
3304 x = eliminate_constant_term (x, &constant_term);
3306 /* Optimize loading of large displacements by splitting them
3307 into the multiple of 4K and the rest; this allows the
3308 former to be CSE'd if possible.
3310 Don't do this if the displacement is added to a register
3311 pointing into the stack frame, as the offsets will
3312 change later anyway. */
3314 if (GET_CODE (constant_term) == CONST_INT
3315 && !TARGET_LONG_DISPLACEMENT
3316 && !DISP_IN_RANGE (INTVAL (constant_term))
3317 && !(REG_P (x) && REGNO_PTR_FRAME_P (REGNO (x))))
3319 HOST_WIDE_INT lower = INTVAL (constant_term) & 0xfff;
3320 HOST_WIDE_INT upper = INTVAL (constant_term) ^ lower;
3322 rtx temp = gen_reg_rtx (Pmode);
3323 rtx val = force_operand (GEN_INT (upper), temp);
3325 emit_move_insn (temp, val);
3327 x = gen_rtx_PLUS (Pmode, x, temp);
3328 constant_term = GEN_INT (lower);
3331 if (GET_CODE (x) == PLUS)
3333 if (GET_CODE (XEXP (x, 0)) == REG)
3335 rtx temp = gen_reg_rtx (Pmode);
3336 rtx val = force_operand (XEXP (x, 1), temp);
3338 emit_move_insn (temp, val);
3340 x = gen_rtx_PLUS (Pmode, XEXP (x, 0), temp);
3343 else if (GET_CODE (XEXP (x, 1)) == REG)
3345 rtx temp = gen_reg_rtx (Pmode);
3346 rtx val = force_operand (XEXP (x, 0), temp);
3348 emit_move_insn (temp, val);
3350 x = gen_rtx_PLUS (Pmode, temp, XEXP (x, 1));
3354 if (constant_term != const0_rtx)
3355 x = gen_rtx_PLUS (Pmode, x, constant_term);
3360 /* Try a machine-dependent way of reloading an illegitimate address AD
3361 operand. If we find one, push the reload and and return the new address.
3363 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3364 and TYPE is the reload type of the current reload. */
3367 legitimize_reload_address (rtx ad, enum machine_mode mode ATTRIBUTE_UNUSED,
3368 int opnum, int type)
3370 if (!optimize || TARGET_LONG_DISPLACEMENT)
3373 if (GET_CODE (ad) == PLUS)
3375 rtx tem = simplify_binary_operation (PLUS, Pmode,
3376 XEXP (ad, 0), XEXP (ad, 1));
3381 if (GET_CODE (ad) == PLUS
3382 && GET_CODE (XEXP (ad, 0)) == REG
3383 && GET_CODE (XEXP (ad, 1)) == CONST_INT
3384 && !DISP_IN_RANGE (INTVAL (XEXP (ad, 1))))
3386 HOST_WIDE_INT lower = INTVAL (XEXP (ad, 1)) & 0xfff;
3387 HOST_WIDE_INT upper = INTVAL (XEXP (ad, 1)) ^ lower;
3390 cst = GEN_INT (upper);
3391 if (!legitimate_reload_constant_p (cst))
3392 cst = force_const_mem (Pmode, cst);
3394 tem = gen_rtx_PLUS (Pmode, XEXP (ad, 0), cst);
3395 new = gen_rtx_PLUS (Pmode, tem, GEN_INT (lower));
3397 push_reload (XEXP (tem, 1), 0, &XEXP (tem, 1), 0,
3398 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3399 opnum, (enum reload_type) type);
3406 /* Emit code to move LEN bytes from DST to SRC. */
3409 s390_expand_movmem (rtx dst, rtx src, rtx len)
3411 if (GET_CODE (len) == CONST_INT && INTVAL (len) >= 0 && INTVAL (len) <= 256)
3413 if (INTVAL (len) > 0)
3414 emit_insn (gen_movmem_short (dst, src, GEN_INT (INTVAL (len) - 1)));
3417 else if (TARGET_MVCLE)
3419 emit_insn (gen_movmem_long (dst, src, convert_to_mode (Pmode, len, 1)));
3424 rtx dst_addr, src_addr, count, blocks, temp;
3425 rtx loop_start_label = gen_label_rtx ();
3426 rtx loop_end_label = gen_label_rtx ();
3427 rtx end_label = gen_label_rtx ();
3428 enum machine_mode mode;
3430 mode = GET_MODE (len);
3431 if (mode == VOIDmode)
3434 dst_addr = gen_reg_rtx (Pmode);
3435 src_addr = gen_reg_rtx (Pmode);
3436 count = gen_reg_rtx (mode);
3437 blocks = gen_reg_rtx (mode);
3439 convert_move (count, len, 1);
3440 emit_cmp_and_jump_insns (count, const0_rtx,
3441 EQ, NULL_RTX, mode, 1, end_label);
3443 emit_move_insn (dst_addr, force_operand (XEXP (dst, 0), NULL_RTX));
3444 emit_move_insn (src_addr, force_operand (XEXP (src, 0), NULL_RTX));
3445 dst = change_address (dst, VOIDmode, dst_addr);
3446 src = change_address (src, VOIDmode, src_addr);
3448 temp = expand_binop (mode, add_optab, count, constm1_rtx, count, 1, 0);
3450 emit_move_insn (count, temp);
3452 temp = expand_binop (mode, ashr_optab, count, GEN_INT (8), blocks, 1, 0);
3454 emit_move_insn (blocks, temp);
3456 emit_cmp_and_jump_insns (blocks, const0_rtx,
3457 EQ, NULL_RTX, mode, 1, loop_end_label);
3459 emit_label (loop_start_label);
3461 emit_insn (gen_movmem_short (dst, src, GEN_INT (255)));
3462 s390_load_address (dst_addr,
3463 gen_rtx_PLUS (Pmode, dst_addr, GEN_INT (256)));
3464 s390_load_address (src_addr,
3465 gen_rtx_PLUS (Pmode, src_addr, GEN_INT (256)));
3467 temp = expand_binop (mode, add_optab, blocks, constm1_rtx, blocks, 1, 0);
3469 emit_move_insn (blocks, temp);
3471 emit_cmp_and_jump_insns (blocks, const0_rtx,
3472 EQ, NULL_RTX, mode, 1, loop_end_label);
3474 emit_jump (loop_start_label);
3475 emit_label (loop_end_label);
3477 emit_insn (gen_movmem_short (dst, src,
3478 convert_to_mode (Pmode, count, 1)));
3479 emit_label (end_label);