1 /* Medium-level subroutines: convert bit-field store and extract
2 and shifts, multiplies and divides to rtl instructions.
3 Copyright (C) 1987-2015 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
26 #include "diagnostic-core.h"
31 #include "double-int.h"
38 #include "fold-const.h"
39 #include "stor-layout.h"
42 #include "insn-config.h"
44 #include "hard-reg-set.h"
46 #include "statistics.h"
48 #include "fixed-value.h"
57 #include "insn-codes.h"
60 #include "langhooks.h"
62 #include "basic-block.h"
66 struct target_expmed default_target_expmed
;
68 struct target_expmed
*this_target_expmed
= &default_target_expmed
;
71 static void store_fixed_bit_field (rtx
, unsigned HOST_WIDE_INT
,
72 unsigned HOST_WIDE_INT
,
73 unsigned HOST_WIDE_INT
,
74 unsigned HOST_WIDE_INT
,
76 static void store_fixed_bit_field_1 (rtx
, unsigned HOST_WIDE_INT
,
77 unsigned HOST_WIDE_INT
,
79 static void store_split_bit_field (rtx
, unsigned HOST_WIDE_INT
,
80 unsigned HOST_WIDE_INT
,
81 unsigned HOST_WIDE_INT
,
82 unsigned HOST_WIDE_INT
,
84 static rtx
extract_fixed_bit_field (machine_mode
, rtx
,
85 unsigned HOST_WIDE_INT
,
86 unsigned HOST_WIDE_INT
, rtx
, int);
87 static rtx
extract_fixed_bit_field_1 (machine_mode
, rtx
,
88 unsigned HOST_WIDE_INT
,
89 unsigned HOST_WIDE_INT
, rtx
, int);
90 static rtx
lshift_value (machine_mode
, unsigned HOST_WIDE_INT
, int);
91 static rtx
extract_split_bit_field (rtx
, unsigned HOST_WIDE_INT
,
92 unsigned HOST_WIDE_INT
, int);
93 static void do_cmp_and_jump (rtx
, rtx
, enum rtx_code
, machine_mode
, rtx_code_label
*);
94 static rtx
expand_smod_pow2 (machine_mode
, rtx
, HOST_WIDE_INT
);
95 static rtx
expand_sdiv_pow2 (machine_mode
, rtx
, HOST_WIDE_INT
);
97 /* Return a constant integer mask value of mode MODE with BITSIZE ones
98 followed by BITPOS zeros, or the complement of that if COMPLEMENT.
99 The mask is truncated if necessary to the width of mode MODE. The
100 mask is zero-extended if BITSIZE+BITPOS is too small for MODE. */
103 mask_rtx (machine_mode mode
, int bitpos
, int bitsize
, bool complement
)
105 return immed_wide_int_const
106 (wi::shifted_mask (bitpos
, bitsize
, complement
,
107 GET_MODE_PRECISION (mode
)), mode
);
110 /* Test whether a value is zero of a power of two. */
111 #define EXACT_POWER_OF_2_OR_ZERO_P(x) \
112 (((x) & ((x) - (unsigned HOST_WIDE_INT) 1)) == 0)
114 struct init_expmed_rtl
135 rtx pow2
[MAX_BITS_PER_WORD
];
136 rtx cint
[MAX_BITS_PER_WORD
];
140 init_expmed_one_conv (struct init_expmed_rtl
*all
, machine_mode to_mode
,
141 machine_mode from_mode
, bool speed
)
143 int to_size
, from_size
;
146 to_size
= GET_MODE_PRECISION (to_mode
);
147 from_size
= GET_MODE_PRECISION (from_mode
);
149 /* Most partial integers have a precision less than the "full"
150 integer it requires for storage. In case one doesn't, for
151 comparison purposes here, reduce the bit size by one in that
153 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
154 && exact_log2 (to_size
) != -1)
156 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
157 && exact_log2 (from_size
) != -1)
160 /* Assume cost of zero-extend and sign-extend is the same. */
161 which
= (to_size
< from_size
? all
->trunc
: all
->zext
);
163 PUT_MODE (all
->reg
, from_mode
);
164 set_convert_cost (to_mode
, from_mode
, speed
, set_src_cost (which
, speed
));
168 init_expmed_one_mode (struct init_expmed_rtl
*all
,
169 machine_mode mode
, int speed
)
171 int m
, n
, mode_bitsize
;
172 machine_mode mode_from
;
174 mode_bitsize
= GET_MODE_UNIT_BITSIZE (mode
);
176 PUT_MODE (all
->reg
, mode
);
177 PUT_MODE (all
->plus
, mode
);
178 PUT_MODE (all
->neg
, mode
);
179 PUT_MODE (all
->mult
, mode
);
180 PUT_MODE (all
->sdiv
, mode
);
181 PUT_MODE (all
->udiv
, mode
);
182 PUT_MODE (all
->sdiv_32
, mode
);
183 PUT_MODE (all
->smod_32
, mode
);
184 PUT_MODE (all
->wide_trunc
, mode
);
185 PUT_MODE (all
->shift
, mode
);
186 PUT_MODE (all
->shift_mult
, mode
);
187 PUT_MODE (all
->shift_add
, mode
);
188 PUT_MODE (all
->shift_sub0
, mode
);
189 PUT_MODE (all
->shift_sub1
, mode
);
190 PUT_MODE (all
->zext
, mode
);
191 PUT_MODE (all
->trunc
, mode
);
193 set_add_cost (speed
, mode
, set_src_cost (all
->plus
, speed
));
194 set_neg_cost (speed
, mode
, set_src_cost (all
->neg
, speed
));
195 set_mul_cost (speed
, mode
, set_src_cost (all
->mult
, speed
));
196 set_sdiv_cost (speed
, mode
, set_src_cost (all
->sdiv
, speed
));
197 set_udiv_cost (speed
, mode
, set_src_cost (all
->udiv
, speed
));
199 set_sdiv_pow2_cheap (speed
, mode
, (set_src_cost (all
->sdiv_32
, speed
)
200 <= 2 * add_cost (speed
, mode
)));
201 set_smod_pow2_cheap (speed
, mode
, (set_src_cost (all
->smod_32
, speed
)
202 <= 4 * add_cost (speed
, mode
)));
204 set_shift_cost (speed
, mode
, 0, 0);
206 int cost
= add_cost (speed
, mode
);
207 set_shiftadd_cost (speed
, mode
, 0, cost
);
208 set_shiftsub0_cost (speed
, mode
, 0, cost
);
209 set_shiftsub1_cost (speed
, mode
, 0, cost
);
212 n
= MIN (MAX_BITS_PER_WORD
, mode_bitsize
);
213 for (m
= 1; m
< n
; m
++)
215 XEXP (all
->shift
, 1) = all
->cint
[m
];
216 XEXP (all
->shift_mult
, 1) = all
->pow2
[m
];
218 set_shift_cost (speed
, mode
, m
, set_src_cost (all
->shift
, speed
));
219 set_shiftadd_cost (speed
, mode
, m
, set_src_cost (all
->shift_add
, speed
));
220 set_shiftsub0_cost (speed
, mode
, m
, set_src_cost (all
->shift_sub0
, speed
));
221 set_shiftsub1_cost (speed
, mode
, m
, set_src_cost (all
->shift_sub1
, speed
));
224 if (SCALAR_INT_MODE_P (mode
))
226 for (mode_from
= MIN_MODE_INT
; mode_from
<= MAX_MODE_INT
;
227 mode_from
= (machine_mode
)(mode_from
+ 1))
228 init_expmed_one_conv (all
, mode
, mode_from
, speed
);
230 if (GET_MODE_CLASS (mode
) == MODE_INT
)
232 machine_mode wider_mode
= GET_MODE_WIDER_MODE (mode
);
233 if (wider_mode
!= VOIDmode
)
235 PUT_MODE (all
->zext
, wider_mode
);
236 PUT_MODE (all
->wide_mult
, wider_mode
);
237 PUT_MODE (all
->wide_lshr
, wider_mode
);
238 XEXP (all
->wide_lshr
, 1) = GEN_INT (mode_bitsize
);
240 set_mul_widen_cost (speed
, wider_mode
,
241 set_src_cost (all
->wide_mult
, speed
));
242 set_mul_highpart_cost (speed
, mode
,
243 set_src_cost (all
->wide_trunc
, speed
));
251 struct init_expmed_rtl all
;
252 machine_mode mode
= QImode
;
255 memset (&all
, 0, sizeof all
);
256 for (m
= 1; m
< MAX_BITS_PER_WORD
; m
++)
258 all
.pow2
[m
] = GEN_INT ((HOST_WIDE_INT
) 1 << m
);
259 all
.cint
[m
] = GEN_INT (m
);
262 /* Avoid using hard regs in ways which may be unsupported. */
263 all
.reg
= gen_rtx_raw_REG (mode
, LAST_VIRTUAL_REGISTER
+ 1);
264 all
.plus
= gen_rtx_PLUS (mode
, all
.reg
, all
.reg
);
265 all
.neg
= gen_rtx_NEG (mode
, all
.reg
);
266 all
.mult
= gen_rtx_MULT (mode
, all
.reg
, all
.reg
);
267 all
.sdiv
= gen_rtx_DIV (mode
, all
.reg
, all
.reg
);
268 all
.udiv
= gen_rtx_UDIV (mode
, all
.reg
, all
.reg
);
269 all
.sdiv_32
= gen_rtx_DIV (mode
, all
.reg
, all
.pow2
[5]);
270 all
.smod_32
= gen_rtx_MOD (mode
, all
.reg
, all
.pow2
[5]);
271 all
.zext
= gen_rtx_ZERO_EXTEND (mode
, all
.reg
);
272 all
.wide_mult
= gen_rtx_MULT (mode
, all
.zext
, all
.zext
);
273 all
.wide_lshr
= gen_rtx_LSHIFTRT (mode
, all
.wide_mult
, all
.reg
);
274 all
.wide_trunc
= gen_rtx_TRUNCATE (mode
, all
.wide_lshr
);
275 all
.shift
= gen_rtx_ASHIFT (mode
, all
.reg
, all
.reg
);
276 all
.shift_mult
= gen_rtx_MULT (mode
, all
.reg
, all
.reg
);
277 all
.shift_add
= gen_rtx_PLUS (mode
, all
.shift_mult
, all
.reg
);
278 all
.shift_sub0
= gen_rtx_MINUS (mode
, all
.shift_mult
, all
.reg
);
279 all
.shift_sub1
= gen_rtx_MINUS (mode
, all
.reg
, all
.shift_mult
);
280 all
.trunc
= gen_rtx_TRUNCATE (mode
, all
.reg
);
282 for (speed
= 0; speed
< 2; speed
++)
284 crtl
->maybe_hot_insn_p
= speed
;
285 set_zero_cost (speed
, set_src_cost (const0_rtx
, speed
));
287 for (mode
= MIN_MODE_INT
; mode
<= MAX_MODE_INT
;
288 mode
= (machine_mode
)(mode
+ 1))
289 init_expmed_one_mode (&all
, mode
, speed
);
291 if (MIN_MODE_PARTIAL_INT
!= VOIDmode
)
292 for (mode
= MIN_MODE_PARTIAL_INT
; mode
<= MAX_MODE_PARTIAL_INT
;
293 mode
= (machine_mode
)(mode
+ 1))
294 init_expmed_one_mode (&all
, mode
, speed
);
296 if (MIN_MODE_VECTOR_INT
!= VOIDmode
)
297 for (mode
= MIN_MODE_VECTOR_INT
; mode
<= MAX_MODE_VECTOR_INT
;
298 mode
= (machine_mode
)(mode
+ 1))
299 init_expmed_one_mode (&all
, mode
, speed
);
302 if (alg_hash_used_p ())
304 struct alg_hash_entry
*p
= alg_hash_entry_ptr (0);
305 memset (p
, 0, sizeof (*p
) * NUM_ALG_HASH_ENTRIES
);
308 set_alg_hash_used_p (true);
309 default_rtl_profile ();
311 ggc_free (all
.trunc
);
312 ggc_free (all
.shift_sub1
);
313 ggc_free (all
.shift_sub0
);
314 ggc_free (all
.shift_add
);
315 ggc_free (all
.shift_mult
);
316 ggc_free (all
.shift
);
317 ggc_free (all
.wide_trunc
);
318 ggc_free (all
.wide_lshr
);
319 ggc_free (all
.wide_mult
);
321 ggc_free (all
.smod_32
);
322 ggc_free (all
.sdiv_32
);
331 /* Return an rtx representing minus the value of X.
332 MODE is the intended mode of the result,
333 useful if X is a CONST_INT. */
336 negate_rtx (machine_mode mode
, rtx x
)
338 rtx result
= simplify_unary_operation (NEG
, mode
, x
, mode
);
341 result
= expand_unop (mode
, neg_optab
, x
, NULL_RTX
, 0);
346 /* Adjust bitfield memory MEM so that it points to the first unit of mode
347 MODE that contains a bitfield of size BITSIZE at bit position BITNUM.
348 If MODE is BLKmode, return a reference to every byte in the bitfield.
349 Set *NEW_BITNUM to the bit position of the field within the new memory. */
352 narrow_bit_field_mem (rtx mem
, machine_mode mode
,
353 unsigned HOST_WIDE_INT bitsize
,
354 unsigned HOST_WIDE_INT bitnum
,
355 unsigned HOST_WIDE_INT
*new_bitnum
)
359 *new_bitnum
= bitnum
% BITS_PER_UNIT
;
360 HOST_WIDE_INT offset
= bitnum
/ BITS_PER_UNIT
;
361 HOST_WIDE_INT size
= ((*new_bitnum
+ bitsize
+ BITS_PER_UNIT
- 1)
363 return adjust_bitfield_address_size (mem
, mode
, offset
, size
);
367 unsigned int unit
= GET_MODE_BITSIZE (mode
);
368 *new_bitnum
= bitnum
% unit
;
369 HOST_WIDE_INT offset
= (bitnum
- *new_bitnum
) / BITS_PER_UNIT
;
370 return adjust_bitfield_address (mem
, mode
, offset
);
374 /* The caller wants to perform insertion or extraction PATTERN on a
375 bitfield of size BITSIZE at BITNUM bits into memory operand OP0.
376 BITREGION_START and BITREGION_END are as for store_bit_field
377 and FIELDMODE is the natural mode of the field.
379 Search for a mode that is compatible with the memory access
380 restrictions and (where applicable) with a register insertion or
381 extraction. Return the new memory on success, storing the adjusted
382 bit position in *NEW_BITNUM. Return null otherwise. */
385 adjust_bit_field_mem_for_reg (enum extraction_pattern pattern
,
386 rtx op0
, HOST_WIDE_INT bitsize
,
387 HOST_WIDE_INT bitnum
,
388 unsigned HOST_WIDE_INT bitregion_start
,
389 unsigned HOST_WIDE_INT bitregion_end
,
390 machine_mode fieldmode
,
391 unsigned HOST_WIDE_INT
*new_bitnum
)
393 bit_field_mode_iterator
iter (bitsize
, bitnum
, bitregion_start
,
394 bitregion_end
, MEM_ALIGN (op0
),
395 MEM_VOLATILE_P (op0
));
396 machine_mode best_mode
;
397 if (iter
.next_mode (&best_mode
))
399 /* We can use a memory in BEST_MODE. See whether this is true for
400 any wider modes. All other things being equal, we prefer to
401 use the widest mode possible because it tends to expose more
402 CSE opportunities. */
403 if (!iter
.prefer_smaller_modes ())
405 /* Limit the search to the mode required by the corresponding
406 register insertion or extraction instruction, if any. */
407 machine_mode limit_mode
= word_mode
;
408 extraction_insn insn
;
409 if (get_best_reg_extraction_insn (&insn
, pattern
,
410 GET_MODE_BITSIZE (best_mode
),
412 limit_mode
= insn
.field_mode
;
414 machine_mode wider_mode
;
415 while (iter
.next_mode (&wider_mode
)
416 && GET_MODE_SIZE (wider_mode
) <= GET_MODE_SIZE (limit_mode
))
417 best_mode
= wider_mode
;
419 return narrow_bit_field_mem (op0
, best_mode
, bitsize
, bitnum
,
425 /* Return true if a bitfield of size BITSIZE at bit number BITNUM within
426 a structure of mode STRUCT_MODE represents a lowpart subreg. The subreg
427 offset is then BITNUM / BITS_PER_UNIT. */
430 lowpart_bit_field_p (unsigned HOST_WIDE_INT bitnum
,
431 unsigned HOST_WIDE_INT bitsize
,
432 machine_mode struct_mode
)
434 if (BYTES_BIG_ENDIAN
)
435 return (bitnum
% BITS_PER_UNIT
== 0
436 && (bitnum
+ bitsize
== GET_MODE_BITSIZE (struct_mode
)
437 || (bitnum
+ bitsize
) % BITS_PER_WORD
== 0));
439 return bitnum
% BITS_PER_WORD
== 0;
442 /* Return true if -fstrict-volatile-bitfields applies to an access of OP0
443 containing BITSIZE bits starting at BITNUM, with field mode FIELDMODE.
444 Return false if the access would touch memory outside the range
445 BITREGION_START to BITREGION_END for conformance to the C++ memory
449 strict_volatile_bitfield_p (rtx op0
, unsigned HOST_WIDE_INT bitsize
,
450 unsigned HOST_WIDE_INT bitnum
,
451 machine_mode fieldmode
,
452 unsigned HOST_WIDE_INT bitregion_start
,
453 unsigned HOST_WIDE_INT bitregion_end
)
455 unsigned HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (fieldmode
);
457 /* -fstrict-volatile-bitfields must be enabled and we must have a
460 || !MEM_VOLATILE_P (op0
)
461 || flag_strict_volatile_bitfields
<= 0)
464 /* Non-integral modes likely only happen with packed structures.
466 if (!SCALAR_INT_MODE_P (fieldmode
))
469 /* The bit size must not be larger than the field mode, and
470 the field mode must not be larger than a word. */
471 if (bitsize
> modesize
|| modesize
> BITS_PER_WORD
)
474 /* Check for cases of unaligned fields that must be split. */
475 if (bitnum
% BITS_PER_UNIT
+ bitsize
> modesize
477 && bitnum
% GET_MODE_ALIGNMENT (fieldmode
) + bitsize
> modesize
))
480 /* Check for cases where the C++ memory model applies. */
481 if (bitregion_end
!= 0
482 && (bitnum
- bitnum
% modesize
< bitregion_start
483 || bitnum
- bitnum
% modesize
+ modesize
- 1 > bitregion_end
))
489 /* Return true if OP is a memory and if a bitfield of size BITSIZE at
490 bit number BITNUM can be treated as a simple value of mode MODE. */
493 simple_mem_bitfield_p (rtx op0
, unsigned HOST_WIDE_INT bitsize
,
494 unsigned HOST_WIDE_INT bitnum
, machine_mode mode
)
497 && bitnum
% BITS_PER_UNIT
== 0
498 && bitsize
== GET_MODE_BITSIZE (mode
)
499 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (op0
))
500 || (bitnum
% GET_MODE_ALIGNMENT (mode
) == 0
501 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode
))));
504 /* Try to use instruction INSV to store VALUE into a field of OP0.
505 BITSIZE and BITNUM are as for store_bit_field. */
508 store_bit_field_using_insv (const extraction_insn
*insv
, rtx op0
,
509 unsigned HOST_WIDE_INT bitsize
,
510 unsigned HOST_WIDE_INT bitnum
,
513 struct expand_operand ops
[4];
516 rtx_insn
*last
= get_last_insn ();
517 bool copy_back
= false;
519 machine_mode op_mode
= insv
->field_mode
;
520 unsigned int unit
= GET_MODE_BITSIZE (op_mode
);
521 if (bitsize
== 0 || bitsize
> unit
)
525 /* Get a reference to the first byte of the field. */
526 xop0
= narrow_bit_field_mem (xop0
, insv
->struct_mode
, bitsize
, bitnum
,
530 /* Convert from counting within OP0 to counting in OP_MODE. */
531 if (BYTES_BIG_ENDIAN
)
532 bitnum
+= unit
- GET_MODE_BITSIZE (GET_MODE (op0
));
534 /* If xop0 is a register, we need it in OP_MODE
535 to make it acceptable to the format of insv. */
536 if (GET_CODE (xop0
) == SUBREG
)
537 /* We can't just change the mode, because this might clobber op0,
538 and we will need the original value of op0 if insv fails. */
539 xop0
= gen_rtx_SUBREG (op_mode
, SUBREG_REG (xop0
), SUBREG_BYTE (xop0
));
540 if (REG_P (xop0
) && GET_MODE (xop0
) != op_mode
)
541 xop0
= gen_lowpart_SUBREG (op_mode
, xop0
);
544 /* If the destination is a paradoxical subreg such that we need a
545 truncate to the inner mode, perform the insertion on a temporary and
546 truncate the result to the original destination. Note that we can't
547 just truncate the paradoxical subreg as (truncate:N (subreg:W (reg:N
548 X) 0)) is (reg:N X). */
549 if (GET_CODE (xop0
) == SUBREG
550 && REG_P (SUBREG_REG (xop0
))
551 && !TRULY_NOOP_TRUNCATION_MODES_P (GET_MODE (SUBREG_REG (xop0
)),
554 rtx tem
= gen_reg_rtx (op_mode
);
555 emit_move_insn (tem
, xop0
);
560 /* There are similar overflow check at the start of store_bit_field_1,
561 but that only check the situation where the field lies completely
562 outside the register, while there do have situation where the field
563 lies partialy in the register, we need to adjust bitsize for this
564 partial overflow situation. Without this fix, pr48335-2.c on big-endian
565 will broken on those arch support bit insert instruction, like arm, aarch64
567 if (bitsize
+ bitnum
> unit
&& bitnum
< unit
)
569 warning (OPT_Wextra
, "write of %wu-bit data outside the bound of "
570 "destination object, data truncated into %wu-bit",
571 bitsize
, unit
- bitnum
);
572 bitsize
= unit
- bitnum
;
575 /* If BITS_BIG_ENDIAN is zero on a BYTES_BIG_ENDIAN machine, we count
576 "backwards" from the size of the unit we are inserting into.
577 Otherwise, we count bits from the most significant on a
578 BYTES/BITS_BIG_ENDIAN machine. */
580 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
581 bitnum
= unit
- bitsize
- bitnum
;
583 /* Convert VALUE to op_mode (which insv insn wants) in VALUE1. */
585 if (GET_MODE (value
) != op_mode
)
587 if (GET_MODE_BITSIZE (GET_MODE (value
)) >= bitsize
)
589 /* Optimization: Don't bother really extending VALUE
590 if it has all the bits we will actually use. However,
591 if we must narrow it, be sure we do it correctly. */
593 if (GET_MODE_SIZE (GET_MODE (value
)) < GET_MODE_SIZE (op_mode
))
597 tmp
= simplify_subreg (op_mode
, value1
, GET_MODE (value
), 0);
599 tmp
= simplify_gen_subreg (op_mode
,
600 force_reg (GET_MODE (value
),
602 GET_MODE (value
), 0);
606 value1
= gen_lowpart (op_mode
, value1
);
608 else if (CONST_INT_P (value
))
609 value1
= gen_int_mode (INTVAL (value
), op_mode
);
611 /* Parse phase is supposed to make VALUE's data type
612 match that of the component reference, which is a type
613 at least as wide as the field; so VALUE should have
614 a mode that corresponds to that type. */
615 gcc_assert (CONSTANT_P (value
));
618 create_fixed_operand (&ops
[0], xop0
);
619 create_integer_operand (&ops
[1], bitsize
);
620 create_integer_operand (&ops
[2], bitnum
);
621 create_input_operand (&ops
[3], value1
, op_mode
);
622 if (maybe_expand_insn (insv
->icode
, 4, ops
))
625 convert_move (op0
, xop0
, true);
628 delete_insns_since (last
);
632 /* A subroutine of store_bit_field, with the same arguments. Return true
633 if the operation could be implemented.
635 If FALLBACK_P is true, fall back to store_fixed_bit_field if we have
636 no other way of implementing the operation. If FALLBACK_P is false,
637 return false instead. */
640 store_bit_field_1 (rtx str_rtx
, unsigned HOST_WIDE_INT bitsize
,
641 unsigned HOST_WIDE_INT bitnum
,
642 unsigned HOST_WIDE_INT bitregion_start
,
643 unsigned HOST_WIDE_INT bitregion_end
,
644 machine_mode fieldmode
,
645 rtx value
, bool fallback_p
)
650 while (GET_CODE (op0
) == SUBREG
)
652 /* The following line once was done only if WORDS_BIG_ENDIAN,
653 but I think that is a mistake. WORDS_BIG_ENDIAN is
654 meaningful at a much higher level; when structures are copied
655 between memory and regs, the higher-numbered regs
656 always get higher addresses. */
657 int inner_mode_size
= GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0
)));
658 int outer_mode_size
= GET_MODE_SIZE (GET_MODE (op0
));
661 /* Paradoxical subregs need special handling on big endian machines. */
662 if (SUBREG_BYTE (op0
) == 0 && inner_mode_size
< outer_mode_size
)
664 int difference
= inner_mode_size
- outer_mode_size
;
666 if (WORDS_BIG_ENDIAN
)
667 byte_offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
668 if (BYTES_BIG_ENDIAN
)
669 byte_offset
+= difference
% UNITS_PER_WORD
;
672 byte_offset
= SUBREG_BYTE (op0
);
674 bitnum
+= byte_offset
* BITS_PER_UNIT
;
675 op0
= SUBREG_REG (op0
);
678 /* No action is needed if the target is a register and if the field
679 lies completely outside that register. This can occur if the source
680 code contains an out-of-bounds access to a small array. */
681 if (REG_P (op0
) && bitnum
>= GET_MODE_BITSIZE (GET_MODE (op0
)))
684 /* Use vec_set patterns for inserting parts of vectors whenever
686 if (VECTOR_MODE_P (GET_MODE (op0
))
688 && optab_handler (vec_set_optab
, GET_MODE (op0
)) != CODE_FOR_nothing
689 && fieldmode
== GET_MODE_INNER (GET_MODE (op0
))
690 && bitsize
== GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0
)))
691 && !(bitnum
% GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0
)))))
693 struct expand_operand ops
[3];
694 machine_mode outermode
= GET_MODE (op0
);
695 machine_mode innermode
= GET_MODE_INNER (outermode
);
696 enum insn_code icode
= optab_handler (vec_set_optab
, outermode
);
697 int pos
= bitnum
/ GET_MODE_BITSIZE (innermode
);
699 create_fixed_operand (&ops
[0], op0
);
700 create_input_operand (&ops
[1], value
, innermode
);
701 create_integer_operand (&ops
[2], pos
);
702 if (maybe_expand_insn (icode
, 3, ops
))
706 /* If the target is a register, overwriting the entire object, or storing
707 a full-word or multi-word field can be done with just a SUBREG. */
709 && bitsize
== GET_MODE_BITSIZE (fieldmode
)
710 && ((bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)) && bitnum
== 0)
711 || (bitsize
% BITS_PER_WORD
== 0 && bitnum
% BITS_PER_WORD
== 0)))
713 /* Use the subreg machinery either to narrow OP0 to the required
714 words or to cope with mode punning between equal-sized modes.
715 In the latter case, use subreg on the rhs side, not lhs. */
718 if (bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
720 sub
= simplify_gen_subreg (GET_MODE (op0
), value
, fieldmode
, 0);
723 emit_move_insn (op0
, sub
);
729 sub
= simplify_gen_subreg (fieldmode
, op0
, GET_MODE (op0
),
730 bitnum
/ BITS_PER_UNIT
);
733 emit_move_insn (sub
, value
);
739 /* If the target is memory, storing any naturally aligned field can be
740 done with a simple store. For targets that support fast unaligned
741 memory, any naturally sized, unit aligned field can be done directly. */
742 if (simple_mem_bitfield_p (op0
, bitsize
, bitnum
, fieldmode
))
744 op0
= adjust_bitfield_address (op0
, fieldmode
, bitnum
/ BITS_PER_UNIT
);
745 emit_move_insn (op0
, value
);
749 /* Make sure we are playing with integral modes. Pun with subregs
750 if we aren't. This must come after the entire register case above,
751 since that case is valid for any mode. The following cases are only
752 valid for integral modes. */
754 machine_mode imode
= int_mode_for_mode (GET_MODE (op0
));
755 if (imode
!= GET_MODE (op0
))
758 op0
= adjust_bitfield_address_size (op0
, imode
, 0, MEM_SIZE (op0
));
761 gcc_assert (imode
!= BLKmode
);
762 op0
= gen_lowpart (imode
, op0
);
767 /* Storing an lsb-aligned field in a register
768 can be done with a movstrict instruction. */
771 && lowpart_bit_field_p (bitnum
, bitsize
, GET_MODE (op0
))
772 && bitsize
== GET_MODE_BITSIZE (fieldmode
)
773 && optab_handler (movstrict_optab
, fieldmode
) != CODE_FOR_nothing
)
775 struct expand_operand ops
[2];
776 enum insn_code icode
= optab_handler (movstrict_optab
, fieldmode
);
778 unsigned HOST_WIDE_INT subreg_off
;
780 if (GET_CODE (arg0
) == SUBREG
)
782 /* Else we've got some float mode source being extracted into
783 a different float mode destination -- this combination of
784 subregs results in Severe Tire Damage. */
785 gcc_assert (GET_MODE (SUBREG_REG (arg0
)) == fieldmode
786 || GET_MODE_CLASS (fieldmode
) == MODE_INT
787 || GET_MODE_CLASS (fieldmode
) == MODE_PARTIAL_INT
);
788 arg0
= SUBREG_REG (arg0
);
791 subreg_off
= bitnum
/ BITS_PER_UNIT
;
792 if (validate_subreg (fieldmode
, GET_MODE (arg0
), arg0
, subreg_off
))
794 arg0
= gen_rtx_SUBREG (fieldmode
, arg0
, subreg_off
);
796 create_fixed_operand (&ops
[0], arg0
);
797 /* Shrink the source operand to FIELDMODE. */
798 create_convert_operand_to (&ops
[1], value
, fieldmode
, false);
799 if (maybe_expand_insn (icode
, 2, ops
))
804 /* Handle fields bigger than a word. */
806 if (bitsize
> BITS_PER_WORD
)
808 /* Here we transfer the words of the field
809 in the order least significant first.
810 This is because the most significant word is the one which may
812 However, only do that if the value is not BLKmode. */
814 unsigned int backwards
= WORDS_BIG_ENDIAN
&& fieldmode
!= BLKmode
;
815 unsigned int nwords
= (bitsize
+ (BITS_PER_WORD
- 1)) / BITS_PER_WORD
;
819 /* This is the mode we must force value to, so that there will be enough
820 subwords to extract. Note that fieldmode will often (always?) be
821 VOIDmode, because that is what store_field uses to indicate that this
822 is a bit field, but passing VOIDmode to operand_subword_force
824 fieldmode
= GET_MODE (value
);
825 if (fieldmode
== VOIDmode
)
826 fieldmode
= smallest_mode_for_size (nwords
* BITS_PER_WORD
, MODE_INT
);
828 last
= get_last_insn ();
829 for (i
= 0; i
< nwords
; i
++)
831 /* If I is 0, use the low-order word in both field and target;
832 if I is 1, use the next to lowest word; and so on. */
833 unsigned int wordnum
= (backwards
834 ? GET_MODE_SIZE (fieldmode
) / UNITS_PER_WORD
837 unsigned int bit_offset
= (backwards
838 ? MAX ((int) bitsize
- ((int) i
+ 1)
841 : (int) i
* BITS_PER_WORD
);
842 rtx value_word
= operand_subword_force (value
, wordnum
, fieldmode
);
843 unsigned HOST_WIDE_INT new_bitsize
=
844 MIN (BITS_PER_WORD
, bitsize
- i
* BITS_PER_WORD
);
846 /* If the remaining chunk doesn't have full wordsize we have
847 to make sure that for big endian machines the higher order
849 if (new_bitsize
< BITS_PER_WORD
&& BYTES_BIG_ENDIAN
&& !backwards
)
850 value_word
= simplify_expand_binop (word_mode
, lshr_optab
,
852 GEN_INT (BITS_PER_WORD
857 if (!store_bit_field_1 (op0
, new_bitsize
,
859 bitregion_start
, bitregion_end
,
861 value_word
, fallback_p
))
863 delete_insns_since (last
);
870 /* If VALUE has a floating-point or complex mode, access it as an
871 integer of the corresponding size. This can occur on a machine
872 with 64 bit registers that uses SFmode for float. It can also
873 occur for unaligned float or complex fields. */
875 if (GET_MODE (value
) != VOIDmode
876 && GET_MODE_CLASS (GET_MODE (value
)) != MODE_INT
877 && GET_MODE_CLASS (GET_MODE (value
)) != MODE_PARTIAL_INT
)
879 value
= gen_reg_rtx (int_mode_for_mode (GET_MODE (value
)));
880 emit_move_insn (gen_lowpart (GET_MODE (orig_value
), value
), orig_value
);
883 /* If OP0 is a multi-word register, narrow it to the affected word.
884 If the region spans two words, defer to store_split_bit_field. */
885 if (!MEM_P (op0
) && GET_MODE_SIZE (GET_MODE (op0
)) > UNITS_PER_WORD
)
887 op0
= simplify_gen_subreg (word_mode
, op0
, GET_MODE (op0
),
888 bitnum
/ BITS_PER_WORD
* UNITS_PER_WORD
);
890 bitnum
%= BITS_PER_WORD
;
891 if (bitnum
+ bitsize
> BITS_PER_WORD
)
896 store_split_bit_field (op0
, bitsize
, bitnum
, bitregion_start
,
897 bitregion_end
, value
);
902 /* From here on we can assume that the field to be stored in fits
903 within a word. If the destination is a register, it too fits
906 extraction_insn insv
;
908 && get_best_reg_extraction_insn (&insv
, EP_insv
,
909 GET_MODE_BITSIZE (GET_MODE (op0
)),
911 && store_bit_field_using_insv (&insv
, op0
, bitsize
, bitnum
, value
))
914 /* If OP0 is a memory, try copying it to a register and seeing if a
915 cheap register alternative is available. */
918 if (get_best_mem_extraction_insn (&insv
, EP_insv
, bitsize
, bitnum
,
920 && store_bit_field_using_insv (&insv
, op0
, bitsize
, bitnum
, value
))
923 rtx_insn
*last
= get_last_insn ();
925 /* Try loading part of OP0 into a register, inserting the bitfield
926 into that, and then copying the result back to OP0. */
927 unsigned HOST_WIDE_INT bitpos
;
928 rtx xop0
= adjust_bit_field_mem_for_reg (EP_insv
, op0
, bitsize
, bitnum
,
929 bitregion_start
, bitregion_end
,
933 rtx tempreg
= copy_to_reg (xop0
);
934 if (store_bit_field_1 (tempreg
, bitsize
, bitpos
,
935 bitregion_start
, bitregion_end
,
936 fieldmode
, orig_value
, false))
938 emit_move_insn (xop0
, tempreg
);
941 delete_insns_since (last
);
948 store_fixed_bit_field (op0
, bitsize
, bitnum
, bitregion_start
,
949 bitregion_end
, value
);
953 /* Generate code to store value from rtx VALUE
954 into a bit-field within structure STR_RTX
955 containing BITSIZE bits starting at bit BITNUM.
957 BITREGION_START is bitpos of the first bitfield in this region.
958 BITREGION_END is the bitpos of the ending bitfield in this region.
959 These two fields are 0, if the C++ memory model does not apply,
960 or we are not interested in keeping track of bitfield regions.
962 FIELDMODE is the machine-mode of the FIELD_DECL node for this field. */
965 store_bit_field (rtx str_rtx
, unsigned HOST_WIDE_INT bitsize
,
966 unsigned HOST_WIDE_INT bitnum
,
967 unsigned HOST_WIDE_INT bitregion_start
,
968 unsigned HOST_WIDE_INT bitregion_end
,
969 machine_mode fieldmode
,
972 /* Handle -fstrict-volatile-bitfields in the cases where it applies. */
973 if (strict_volatile_bitfield_p (str_rtx
, bitsize
, bitnum
, fieldmode
,
974 bitregion_start
, bitregion_end
))
976 /* Storing any naturally aligned field can be done with a simple
977 store. For targets that support fast unaligned memory, any
978 naturally sized, unit aligned field can be done directly. */
979 if (simple_mem_bitfield_p (str_rtx
, bitsize
, bitnum
, fieldmode
))
981 str_rtx
= adjust_bitfield_address (str_rtx
, fieldmode
,
982 bitnum
/ BITS_PER_UNIT
);
983 emit_move_insn (str_rtx
, value
);
987 str_rtx
= narrow_bit_field_mem (str_rtx
, fieldmode
, bitsize
, bitnum
,
989 /* Explicitly override the C/C++ memory model; ignore the
990 bit range so that we can do the access in the mode mandated
991 by -fstrict-volatile-bitfields instead. */
992 store_fixed_bit_field_1 (str_rtx
, bitsize
, bitnum
, value
);
998 /* Under the C++0x memory model, we must not touch bits outside the
999 bit region. Adjust the address to start at the beginning of the
1001 if (MEM_P (str_rtx
) && bitregion_start
> 0)
1003 machine_mode bestmode
;
1004 HOST_WIDE_INT offset
, size
;
1006 gcc_assert ((bitregion_start
% BITS_PER_UNIT
) == 0);
1008 offset
= bitregion_start
/ BITS_PER_UNIT
;
1009 bitnum
-= bitregion_start
;
1010 size
= (bitnum
+ bitsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
1011 bitregion_end
-= bitregion_start
;
1012 bitregion_start
= 0;
1013 bestmode
= get_best_mode (bitsize
, bitnum
,
1014 bitregion_start
, bitregion_end
,
1015 MEM_ALIGN (str_rtx
), VOIDmode
,
1016 MEM_VOLATILE_P (str_rtx
));
1017 str_rtx
= adjust_bitfield_address_size (str_rtx
, bestmode
, offset
, size
);
1020 if (!store_bit_field_1 (str_rtx
, bitsize
, bitnum
,
1021 bitregion_start
, bitregion_end
,
1022 fieldmode
, value
, true))
1026 /* Use shifts and boolean operations to store VALUE into a bit field of
1027 width BITSIZE in OP0, starting at bit BITNUM. */
1030 store_fixed_bit_field (rtx op0
, unsigned HOST_WIDE_INT bitsize
,
1031 unsigned HOST_WIDE_INT bitnum
,
1032 unsigned HOST_WIDE_INT bitregion_start
,
1033 unsigned HOST_WIDE_INT bitregion_end
,
1036 /* There is a case not handled here:
1037 a structure with a known alignment of just a halfword
1038 and a field split across two aligned halfwords within the structure.
1039 Or likewise a structure with a known alignment of just a byte
1040 and a field split across two bytes.
1041 Such cases are not supposed to be able to occur. */
1045 machine_mode mode
= GET_MODE (op0
);
1046 if (GET_MODE_BITSIZE (mode
) == 0
1047 || GET_MODE_BITSIZE (mode
) > GET_MODE_BITSIZE (word_mode
))
1049 mode
= get_best_mode (bitsize
, bitnum
, bitregion_start
, bitregion_end
,
1050 MEM_ALIGN (op0
), mode
, MEM_VOLATILE_P (op0
));
1052 if (mode
== VOIDmode
)
1054 /* The only way this should occur is if the field spans word
1056 store_split_bit_field (op0
, bitsize
, bitnum
, bitregion_start
,
1057 bitregion_end
, value
);
1061 op0
= narrow_bit_field_mem (op0
, mode
, bitsize
, bitnum
, &bitnum
);
1064 store_fixed_bit_field_1 (op0
, bitsize
, bitnum
, value
);
1067 /* Helper function for store_fixed_bit_field, stores
1068 the bit field always using the MODE of OP0. */
1071 store_fixed_bit_field_1 (rtx op0
, unsigned HOST_WIDE_INT bitsize
,
1072 unsigned HOST_WIDE_INT bitnum
,
1080 mode
= GET_MODE (op0
);
1081 gcc_assert (SCALAR_INT_MODE_P (mode
));
1083 /* Note that bitsize + bitnum can be greater than GET_MODE_BITSIZE (mode)
1084 for invalid input, such as f5 from gcc.dg/pr48335-2.c. */
1086 if (BYTES_BIG_ENDIAN
)
1087 /* BITNUM is the distance between our msb
1088 and that of the containing datum.
1089 Convert it to the distance from the lsb. */
1090 bitnum
= GET_MODE_BITSIZE (mode
) - bitsize
- bitnum
;
1092 /* Now BITNUM is always the distance between our lsb
1095 /* Shift VALUE left by BITNUM bits. If VALUE is not constant,
1096 we must first convert its mode to MODE. */
1098 if (CONST_INT_P (value
))
1100 unsigned HOST_WIDE_INT v
= UINTVAL (value
);
1102 if (bitsize
< HOST_BITS_PER_WIDE_INT
)
1103 v
&= ((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1;
1107 else if ((bitsize
< HOST_BITS_PER_WIDE_INT
1108 && v
== ((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1)
1109 || (bitsize
== HOST_BITS_PER_WIDE_INT
1110 && v
== (unsigned HOST_WIDE_INT
) -1))
1113 value
= lshift_value (mode
, v
, bitnum
);
1117 int must_and
= (GET_MODE_BITSIZE (GET_MODE (value
)) != bitsize
1118 && bitnum
+ bitsize
!= GET_MODE_BITSIZE (mode
));
1120 if (GET_MODE (value
) != mode
)
1121 value
= convert_to_mode (mode
, value
, 1);
1124 value
= expand_binop (mode
, and_optab
, value
,
1125 mask_rtx (mode
, 0, bitsize
, 0),
1126 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1128 value
= expand_shift (LSHIFT_EXPR
, mode
, value
,
1129 bitnum
, NULL_RTX
, 1);
1132 /* Now clear the chosen bits in OP0,
1133 except that if VALUE is -1 we need not bother. */
1134 /* We keep the intermediates in registers to allow CSE to combine
1135 consecutive bitfield assignments. */
1137 temp
= force_reg (mode
, op0
);
1141 temp
= expand_binop (mode
, and_optab
, temp
,
1142 mask_rtx (mode
, bitnum
, bitsize
, 1),
1143 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1144 temp
= force_reg (mode
, temp
);
1147 /* Now logical-or VALUE into OP0, unless it is zero. */
1151 temp
= expand_binop (mode
, ior_optab
, temp
, value
,
1152 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1153 temp
= force_reg (mode
, temp
);
1158 op0
= copy_rtx (op0
);
1159 emit_move_insn (op0
, temp
);
1163 /* Store a bit field that is split across multiple accessible memory objects.
1165 OP0 is the REG, SUBREG or MEM rtx for the first of the objects.
1166 BITSIZE is the field width; BITPOS the position of its first bit
1168 VALUE is the value to store.
1170 This does not yet handle fields wider than BITS_PER_WORD. */
1173 store_split_bit_field (rtx op0
, unsigned HOST_WIDE_INT bitsize
,
1174 unsigned HOST_WIDE_INT bitpos
,
1175 unsigned HOST_WIDE_INT bitregion_start
,
1176 unsigned HOST_WIDE_INT bitregion_end
,
1180 unsigned int bitsdone
= 0;
1182 /* Make sure UNIT isn't larger than BITS_PER_WORD, we can only handle that
1184 if (REG_P (op0
) || GET_CODE (op0
) == SUBREG
)
1185 unit
= BITS_PER_WORD
;
1187 unit
= MIN (MEM_ALIGN (op0
), BITS_PER_WORD
);
1189 /* If OP0 is a memory with a mode, then UNIT must not be larger than
1190 OP0's mode as well. Otherwise, store_fixed_bit_field will call us
1191 again, and we will mutually recurse forever. */
1192 if (MEM_P (op0
) && GET_MODE_BITSIZE (GET_MODE (op0
)) > 0)
1193 unit
= MIN (unit
, GET_MODE_BITSIZE (GET_MODE (op0
)));
1195 /* If VALUE is a constant other than a CONST_INT, get it into a register in
1196 WORD_MODE. If we can do this using gen_lowpart_common, do so. Note
1197 that VALUE might be a floating-point constant. */
1198 if (CONSTANT_P (value
) && !CONST_INT_P (value
))
1200 rtx word
= gen_lowpart_common (word_mode
, value
);
1202 if (word
&& (value
!= word
))
1205 value
= gen_lowpart_common (word_mode
,
1206 force_reg (GET_MODE (value
) != VOIDmode
1208 : word_mode
, value
));
1211 while (bitsdone
< bitsize
)
1213 unsigned HOST_WIDE_INT thissize
;
1215 unsigned HOST_WIDE_INT thispos
;
1216 unsigned HOST_WIDE_INT offset
;
1218 offset
= (bitpos
+ bitsdone
) / unit
;
1219 thispos
= (bitpos
+ bitsdone
) % unit
;
1221 /* When region of bytes we can touch is restricted, decrease
1222 UNIT close to the end of the region as needed. If op0 is a REG
1223 or SUBREG of REG, don't do this, as there can't be data races
1224 on a register and we can expand shorter code in some cases. */
1226 && unit
> BITS_PER_UNIT
1227 && bitpos
+ bitsdone
- thispos
+ unit
> bitregion_end
+ 1
1229 && (GET_CODE (op0
) != SUBREG
|| !REG_P (SUBREG_REG (op0
))))
1235 /* THISSIZE must not overrun a word boundary. Otherwise,
1236 store_fixed_bit_field will call us again, and we will mutually
1238 thissize
= MIN (bitsize
- bitsdone
, BITS_PER_WORD
);
1239 thissize
= MIN (thissize
, unit
- thispos
);
1241 if (BYTES_BIG_ENDIAN
)
1243 /* Fetch successively less significant portions. */
1244 if (CONST_INT_P (value
))
1245 part
= GEN_INT (((unsigned HOST_WIDE_INT
) (INTVAL (value
))
1246 >> (bitsize
- bitsdone
- thissize
))
1247 & (((HOST_WIDE_INT
) 1 << thissize
) - 1));
1250 int total_bits
= GET_MODE_BITSIZE (GET_MODE (value
));
1251 /* The args are chosen so that the last part includes the
1252 lsb. Give extract_bit_field the value it needs (with
1253 endianness compensation) to fetch the piece we want. */
1254 part
= extract_fixed_bit_field (word_mode
, value
, thissize
,
1255 total_bits
- bitsize
+ bitsdone
,
1261 /* Fetch successively more significant portions. */
1262 if (CONST_INT_P (value
))
1263 part
= GEN_INT (((unsigned HOST_WIDE_INT
) (INTVAL (value
))
1265 & (((HOST_WIDE_INT
) 1 << thissize
) - 1));
1267 part
= extract_fixed_bit_field (word_mode
, value
, thissize
,
1268 bitsdone
, NULL_RTX
, 1);
1271 /* If OP0 is a register, then handle OFFSET here.
1273 When handling multiword bitfields, extract_bit_field may pass
1274 down a word_mode SUBREG of a larger REG for a bitfield that actually
1275 crosses a word boundary. Thus, for a SUBREG, we must find
1276 the current word starting from the base register. */
1277 if (GET_CODE (op0
) == SUBREG
)
1279 int word_offset
= (SUBREG_BYTE (op0
) / UNITS_PER_WORD
)
1280 + (offset
* unit
/ BITS_PER_WORD
);
1281 machine_mode sub_mode
= GET_MODE (SUBREG_REG (op0
));
1282 if (sub_mode
!= BLKmode
&& GET_MODE_SIZE (sub_mode
) < UNITS_PER_WORD
)
1283 word
= word_offset
? const0_rtx
: op0
;
1285 word
= operand_subword_force (SUBREG_REG (op0
), word_offset
,
1286 GET_MODE (SUBREG_REG (op0
)));
1287 offset
&= BITS_PER_WORD
/ unit
- 1;
1289 else if (REG_P (op0
))
1291 machine_mode op0_mode
= GET_MODE (op0
);
1292 if (op0_mode
!= BLKmode
&& GET_MODE_SIZE (op0_mode
) < UNITS_PER_WORD
)
1293 word
= offset
? const0_rtx
: op0
;
1295 word
= operand_subword_force (op0
, offset
* unit
/ BITS_PER_WORD
,
1297 offset
&= BITS_PER_WORD
/ unit
- 1;
1302 /* OFFSET is in UNITs, and UNIT is in bits. If WORD is const0_rtx,
1303 it is just an out-of-bounds access. Ignore it. */
1304 if (word
!= const0_rtx
)
1305 store_fixed_bit_field (word
, thissize
, offset
* unit
+ thispos
,
1306 bitregion_start
, bitregion_end
, part
);
1307 bitsdone
+= thissize
;
1311 /* A subroutine of extract_bit_field_1 that converts return value X
1312 to either MODE or TMODE. MODE, TMODE and UNSIGNEDP are arguments
1313 to extract_bit_field. */
1316 convert_extracted_bit_field (rtx x
, machine_mode mode
,
1317 machine_mode tmode
, bool unsignedp
)
1319 if (GET_MODE (x
) == tmode
|| GET_MODE (x
) == mode
)
1322 /* If the x mode is not a scalar integral, first convert to the
1323 integer mode of that size and then access it as a floating-point
1324 value via a SUBREG. */
1325 if (!SCALAR_INT_MODE_P (tmode
))
1329 smode
= mode_for_size (GET_MODE_BITSIZE (tmode
), MODE_INT
, 0);
1330 x
= convert_to_mode (smode
, x
, unsignedp
);
1331 x
= force_reg (smode
, x
);
1332 return gen_lowpart (tmode
, x
);
1335 return convert_to_mode (tmode
, x
, unsignedp
);
1338 /* Try to use an ext(z)v pattern to extract a field from OP0.
1339 Return the extracted value on success, otherwise return null.
1340 EXT_MODE is the mode of the extraction and the other arguments
1341 are as for extract_bit_field. */
1344 extract_bit_field_using_extv (const extraction_insn
*extv
, rtx op0
,
1345 unsigned HOST_WIDE_INT bitsize
,
1346 unsigned HOST_WIDE_INT bitnum
,
1347 int unsignedp
, rtx target
,
1348 machine_mode mode
, machine_mode tmode
)
1350 struct expand_operand ops
[4];
1351 rtx spec_target
= target
;
1352 rtx spec_target_subreg
= 0;
1353 machine_mode ext_mode
= extv
->field_mode
;
1354 unsigned unit
= GET_MODE_BITSIZE (ext_mode
);
1356 if (bitsize
== 0 || unit
< bitsize
)
1360 /* Get a reference to the first byte of the field. */
1361 op0
= narrow_bit_field_mem (op0
, extv
->struct_mode
, bitsize
, bitnum
,
1365 /* Convert from counting within OP0 to counting in EXT_MODE. */
1366 if (BYTES_BIG_ENDIAN
)
1367 bitnum
+= unit
- GET_MODE_BITSIZE (GET_MODE (op0
));
1369 /* If op0 is a register, we need it in EXT_MODE to make it
1370 acceptable to the format of ext(z)v. */
1371 if (GET_CODE (op0
) == SUBREG
&& GET_MODE (op0
) != ext_mode
)
1373 if (REG_P (op0
) && GET_MODE (op0
) != ext_mode
)
1374 op0
= gen_lowpart_SUBREG (ext_mode
, op0
);
1377 /* If BITS_BIG_ENDIAN is zero on a BYTES_BIG_ENDIAN machine, we count
1378 "backwards" from the size of the unit we are extracting from.
1379 Otherwise, we count bits from the most significant on a
1380 BYTES/BITS_BIG_ENDIAN machine. */
1382 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
1383 bitnum
= unit
- bitsize
- bitnum
;
1386 target
= spec_target
= gen_reg_rtx (tmode
);
1388 if (GET_MODE (target
) != ext_mode
)
1390 /* Don't use LHS paradoxical subreg if explicit truncation is needed
1391 between the mode of the extraction (word_mode) and the target
1392 mode. Instead, create a temporary and use convert_move to set
1395 && TRULY_NOOP_TRUNCATION_MODES_P (GET_MODE (target
), ext_mode
))
1397 target
= gen_lowpart (ext_mode
, target
);
1398 if (GET_MODE_PRECISION (ext_mode
)
1399 > GET_MODE_PRECISION (GET_MODE (spec_target
)))
1400 spec_target_subreg
= target
;
1403 target
= gen_reg_rtx (ext_mode
);
1406 create_output_operand (&ops
[0], target
, ext_mode
);
1407 create_fixed_operand (&ops
[1], op0
);
1408 create_integer_operand (&ops
[2], bitsize
);
1409 create_integer_operand (&ops
[3], bitnum
);
1410 if (maybe_expand_insn (extv
->icode
, 4, ops
))
1412 target
= ops
[0].value
;
1413 if (target
== spec_target
)
1415 if (target
== spec_target_subreg
)
1417 return convert_extracted_bit_field (target
, mode
, tmode
, unsignedp
);
1422 /* A subroutine of extract_bit_field, with the same arguments.
1423 If FALLBACK_P is true, fall back to extract_fixed_bit_field
1424 if we can find no other means of implementing the operation.
1425 if FALLBACK_P is false, return NULL instead. */
1428 extract_bit_field_1 (rtx str_rtx
, unsigned HOST_WIDE_INT bitsize
,
1429 unsigned HOST_WIDE_INT bitnum
, int unsignedp
, rtx target
,
1430 machine_mode mode
, machine_mode tmode
,
1434 machine_mode int_mode
;
1437 if (tmode
== VOIDmode
)
1440 while (GET_CODE (op0
) == SUBREG
)
1442 bitnum
+= SUBREG_BYTE (op0
) * BITS_PER_UNIT
;
1443 op0
= SUBREG_REG (op0
);
1446 /* If we have an out-of-bounds access to a register, just return an
1447 uninitialized register of the required mode. This can occur if the
1448 source code contains an out-of-bounds access to a small array. */
1449 if (REG_P (op0
) && bitnum
>= GET_MODE_BITSIZE (GET_MODE (op0
)))
1450 return gen_reg_rtx (tmode
);
1453 && mode
== GET_MODE (op0
)
1455 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
1457 /* We're trying to extract a full register from itself. */
1461 /* See if we can get a better vector mode before extracting. */
1462 if (VECTOR_MODE_P (GET_MODE (op0
))
1464 && GET_MODE_INNER (GET_MODE (op0
)) != tmode
)
1466 machine_mode new_mode
;
1468 if (GET_MODE_CLASS (tmode
) == MODE_FLOAT
)
1469 new_mode
= MIN_MODE_VECTOR_FLOAT
;
1470 else if (GET_MODE_CLASS (tmode
) == MODE_FRACT
)
1471 new_mode
= MIN_MODE_VECTOR_FRACT
;
1472 else if (GET_MODE_CLASS (tmode
) == MODE_UFRACT
)
1473 new_mode
= MIN_MODE_VECTOR_UFRACT
;
1474 else if (GET_MODE_CLASS (tmode
) == MODE_ACCUM
)
1475 new_mode
= MIN_MODE_VECTOR_ACCUM
;
1476 else if (GET_MODE_CLASS (tmode
) == MODE_UACCUM
)
1477 new_mode
= MIN_MODE_VECTOR_UACCUM
;
1479 new_mode
= MIN_MODE_VECTOR_INT
;
1481 for (; new_mode
!= VOIDmode
; new_mode
= GET_MODE_WIDER_MODE (new_mode
))
1482 if (GET_MODE_SIZE (new_mode
) == GET_MODE_SIZE (GET_MODE (op0
))
1483 && targetm
.vector_mode_supported_p (new_mode
))
1485 if (new_mode
!= VOIDmode
)
1486 op0
= gen_lowpart (new_mode
, op0
);
1489 /* Use vec_extract patterns for extracting parts of vectors whenever
1491 if (VECTOR_MODE_P (GET_MODE (op0
))
1493 && optab_handler (vec_extract_optab
, GET_MODE (op0
)) != CODE_FOR_nothing
1494 && ((bitnum
+ bitsize
- 1) / GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0
)))
1495 == bitnum
/ GET_MODE_BITSIZE (GET_MODE_INNER (GET_MODE (op0
)))))
1497 struct expand_operand ops
[3];
1498 machine_mode outermode
= GET_MODE (op0
);
1499 machine_mode innermode
= GET_MODE_INNER (outermode
);
1500 enum insn_code icode
= optab_handler (vec_extract_optab
, outermode
);
1501 unsigned HOST_WIDE_INT pos
= bitnum
/ GET_MODE_BITSIZE (innermode
);
1503 create_output_operand (&ops
[0], target
, innermode
);
1504 create_input_operand (&ops
[1], op0
, outermode
);
1505 create_integer_operand (&ops
[2], pos
);
1506 if (maybe_expand_insn (icode
, 3, ops
))
1508 target
= ops
[0].value
;
1509 if (GET_MODE (target
) != mode
)
1510 return gen_lowpart (tmode
, target
);
1515 /* Make sure we are playing with integral modes. Pun with subregs
1518 machine_mode imode
= int_mode_for_mode (GET_MODE (op0
));
1519 if (imode
!= GET_MODE (op0
))
1522 op0
= adjust_bitfield_address_size (op0
, imode
, 0, MEM_SIZE (op0
));
1523 else if (imode
!= BLKmode
)
1525 op0
= gen_lowpart (imode
, op0
);
1527 /* If we got a SUBREG, force it into a register since we
1528 aren't going to be able to do another SUBREG on it. */
1529 if (GET_CODE (op0
) == SUBREG
)
1530 op0
= force_reg (imode
, op0
);
1532 else if (REG_P (op0
))
1535 imode
= smallest_mode_for_size (GET_MODE_BITSIZE (GET_MODE (op0
)),
1537 reg
= gen_reg_rtx (imode
);
1538 subreg
= gen_lowpart_SUBREG (GET_MODE (op0
), reg
);
1539 emit_move_insn (subreg
, op0
);
1541 bitnum
+= SUBREG_BYTE (subreg
) * BITS_PER_UNIT
;
1545 HOST_WIDE_INT size
= GET_MODE_SIZE (GET_MODE (op0
));
1546 rtx mem
= assign_stack_temp (GET_MODE (op0
), size
);
1547 emit_move_insn (mem
, op0
);
1548 op0
= adjust_bitfield_address_size (mem
, BLKmode
, 0, size
);
1553 /* ??? We currently assume TARGET is at least as big as BITSIZE.
1554 If that's wrong, the solution is to test for it and set TARGET to 0
1557 /* Get the mode of the field to use for atomic access or subreg
1560 if (SCALAR_INT_MODE_P (tmode
))
1562 machine_mode try_mode
= mode_for_size (bitsize
,
1563 GET_MODE_CLASS (tmode
), 0);
1564 if (try_mode
!= BLKmode
)
1567 gcc_assert (mode1
!= BLKmode
);
1569 /* Extraction of a full MODE1 value can be done with a subreg as long
1570 as the least significant bit of the value is the least significant
1571 bit of either OP0 or a word of OP0. */
1573 && lowpart_bit_field_p (bitnum
, bitsize
, GET_MODE (op0
))
1574 && bitsize
== GET_MODE_BITSIZE (mode1
)
1575 && TRULY_NOOP_TRUNCATION_MODES_P (mode1
, GET_MODE (op0
)))
1577 rtx sub
= simplify_gen_subreg (mode1
, op0
, GET_MODE (op0
),
1578 bitnum
/ BITS_PER_UNIT
);
1580 return convert_extracted_bit_field (sub
, mode
, tmode
, unsignedp
);
1583 /* Extraction of a full MODE1 value can be done with a load as long as
1584 the field is on a byte boundary and is sufficiently aligned. */
1585 if (simple_mem_bitfield_p (op0
, bitsize
, bitnum
, mode1
))
1587 op0
= adjust_bitfield_address (op0
, mode1
, bitnum
/ BITS_PER_UNIT
);
1588 return convert_extracted_bit_field (op0
, mode
, tmode
, unsignedp
);
1591 /* Handle fields bigger than a word. */
1593 if (bitsize
> BITS_PER_WORD
)
1595 /* Here we transfer the words of the field
1596 in the order least significant first.
1597 This is because the most significant word is the one which may
1598 be less than full. */
1600 unsigned int backwards
= WORDS_BIG_ENDIAN
;
1601 unsigned int nwords
= (bitsize
+ (BITS_PER_WORD
- 1)) / BITS_PER_WORD
;
1605 if (target
== 0 || !REG_P (target
) || !valid_multiword_target_p (target
))
1606 target
= gen_reg_rtx (mode
);
1608 /* Indicate for flow that the entire target reg is being set. */
1609 emit_clobber (target
);
1611 last
= get_last_insn ();
1612 for (i
= 0; i
< nwords
; i
++)
1614 /* If I is 0, use the low-order word in both field and target;
1615 if I is 1, use the next to lowest word; and so on. */
1616 /* Word number in TARGET to use. */
1617 unsigned int wordnum
1619 ? GET_MODE_SIZE (GET_MODE (target
)) / UNITS_PER_WORD
- i
- 1
1621 /* Offset from start of field in OP0. */
1622 unsigned int bit_offset
= (backwards
1623 ? MAX ((int) bitsize
- ((int) i
+ 1)
1626 : (int) i
* BITS_PER_WORD
);
1627 rtx target_part
= operand_subword (target
, wordnum
, 1, VOIDmode
);
1629 = extract_bit_field_1 (op0
, MIN (BITS_PER_WORD
,
1630 bitsize
- i
* BITS_PER_WORD
),
1631 bitnum
+ bit_offset
, 1, target_part
,
1632 mode
, word_mode
, fallback_p
);
1634 gcc_assert (target_part
);
1637 delete_insns_since (last
);
1641 if (result_part
!= target_part
)
1642 emit_move_insn (target_part
, result_part
);
1647 /* Unless we've filled TARGET, the upper regs in a multi-reg value
1648 need to be zero'd out. */
1649 if (GET_MODE_SIZE (GET_MODE (target
)) > nwords
* UNITS_PER_WORD
)
1651 unsigned int i
, total_words
;
1653 total_words
= GET_MODE_SIZE (GET_MODE (target
)) / UNITS_PER_WORD
;
1654 for (i
= nwords
; i
< total_words
; i
++)
1656 (operand_subword (target
,
1657 backwards
? total_words
- i
- 1 : i
,
1664 /* Signed bit field: sign-extend with two arithmetic shifts. */
1665 target
= expand_shift (LSHIFT_EXPR
, mode
, target
,
1666 GET_MODE_BITSIZE (mode
) - bitsize
, NULL_RTX
, 0);
1667 return expand_shift (RSHIFT_EXPR
, mode
, target
,
1668 GET_MODE_BITSIZE (mode
) - bitsize
, NULL_RTX
, 0);
1671 /* If OP0 is a multi-word register, narrow it to the affected word.
1672 If the region spans two words, defer to extract_split_bit_field. */
1673 if (!MEM_P (op0
) && GET_MODE_SIZE (GET_MODE (op0
)) > UNITS_PER_WORD
)
1675 op0
= simplify_gen_subreg (word_mode
, op0
, GET_MODE (op0
),
1676 bitnum
/ BITS_PER_WORD
* UNITS_PER_WORD
);
1677 bitnum
%= BITS_PER_WORD
;
1678 if (bitnum
+ bitsize
> BITS_PER_WORD
)
1682 target
= extract_split_bit_field (op0
, bitsize
, bitnum
, unsignedp
);
1683 return convert_extracted_bit_field (target
, mode
, tmode
, unsignedp
);
1687 /* From here on we know the desired field is smaller than a word.
1688 If OP0 is a register, it too fits within a word. */
1689 enum extraction_pattern pattern
= unsignedp
? EP_extzv
: EP_extv
;
1690 extraction_insn extv
;
1692 /* ??? We could limit the structure size to the part of OP0 that
1693 contains the field, with appropriate checks for endianness
1694 and TRULY_NOOP_TRUNCATION. */
1695 && get_best_reg_extraction_insn (&extv
, pattern
,
1696 GET_MODE_BITSIZE (GET_MODE (op0
)),
1699 rtx result
= extract_bit_field_using_extv (&extv
, op0
, bitsize
, bitnum
,
1700 unsignedp
, target
, mode
,
1706 /* If OP0 is a memory, try copying it to a register and seeing if a
1707 cheap register alternative is available. */
1710 if (get_best_mem_extraction_insn (&extv
, pattern
, bitsize
, bitnum
,
1713 rtx result
= extract_bit_field_using_extv (&extv
, op0
, bitsize
,
1721 rtx_insn
*last
= get_last_insn ();
1723 /* Try loading part of OP0 into a register and extracting the
1724 bitfield from that. */
1725 unsigned HOST_WIDE_INT bitpos
;
1726 rtx xop0
= adjust_bit_field_mem_for_reg (pattern
, op0
, bitsize
, bitnum
,
1727 0, 0, tmode
, &bitpos
);
1730 xop0
= copy_to_reg (xop0
);
1731 rtx result
= extract_bit_field_1 (xop0
, bitsize
, bitpos
,
1733 mode
, tmode
, false);
1736 delete_insns_since (last
);
1743 /* Find a correspondingly-sized integer field, so we can apply
1744 shifts and masks to it. */
1745 int_mode
= int_mode_for_mode (tmode
);
1746 if (int_mode
== BLKmode
)
1747 int_mode
= int_mode_for_mode (mode
);
1748 /* Should probably push op0 out to memory and then do a load. */
1749 gcc_assert (int_mode
!= BLKmode
);
1751 target
= extract_fixed_bit_field (int_mode
, op0
, bitsize
, bitnum
,
1753 return convert_extracted_bit_field (target
, mode
, tmode
, unsignedp
);
1756 /* Generate code to extract a byte-field from STR_RTX
1757 containing BITSIZE bits, starting at BITNUM,
1758 and put it in TARGET if possible (if TARGET is nonzero).
1759 Regardless of TARGET, we return the rtx for where the value is placed.
1761 STR_RTX is the structure containing the byte (a REG or MEM).
1762 UNSIGNEDP is nonzero if this is an unsigned bit field.
1763 MODE is the natural mode of the field value once extracted.
1764 TMODE is the mode the caller would like the value to have;
1765 but the value may be returned with type MODE instead.
1767 If a TARGET is specified and we can store in it at no extra cost,
1768 we do so, and return TARGET.
1769 Otherwise, we return a REG of mode TMODE or MODE, with TMODE preferred
1770 if they are equally easy. */
1773 extract_bit_field (rtx str_rtx
, unsigned HOST_WIDE_INT bitsize
,
1774 unsigned HOST_WIDE_INT bitnum
, int unsignedp
, rtx target
,
1775 machine_mode mode
, machine_mode tmode
)
1779 /* Handle -fstrict-volatile-bitfields in the cases where it applies. */
1780 if (GET_MODE_BITSIZE (GET_MODE (str_rtx
)) > 0)
1781 mode1
= GET_MODE (str_rtx
);
1782 else if (target
&& GET_MODE_BITSIZE (GET_MODE (target
)) > 0)
1783 mode1
= GET_MODE (target
);
1787 if (strict_volatile_bitfield_p (str_rtx
, bitsize
, bitnum
, mode1
, 0, 0))
1791 /* Extraction of a full MODE1 value can be done with a load as long as
1792 the field is on a byte boundary and is sufficiently aligned. */
1793 if (simple_mem_bitfield_p (str_rtx
, bitsize
, bitnum
, mode1
))
1794 result
= adjust_bitfield_address (str_rtx
, mode1
,
1795 bitnum
/ BITS_PER_UNIT
);
1798 str_rtx
= narrow_bit_field_mem (str_rtx
, mode1
, bitsize
, bitnum
,
1800 result
= extract_fixed_bit_field_1 (mode
, str_rtx
, bitsize
, bitnum
,
1804 return convert_extracted_bit_field (result
, mode
, tmode
, unsignedp
);
1807 return extract_bit_field_1 (str_rtx
, bitsize
, bitnum
, unsignedp
,
1808 target
, mode
, tmode
, true);
1811 /* Use shifts and boolean operations to extract a field of BITSIZE bits
1812 from bit BITNUM of OP0.
1814 UNSIGNEDP is nonzero for an unsigned bit field (don't sign-extend value).
1815 If TARGET is nonzero, attempts to store the value there
1816 and return TARGET, but this is not guaranteed.
1817 If TARGET is not used, create a pseudo-reg of mode TMODE for the value. */
1820 extract_fixed_bit_field (machine_mode tmode
, rtx op0
,
1821 unsigned HOST_WIDE_INT bitsize
,
1822 unsigned HOST_WIDE_INT bitnum
, rtx target
,
1828 = get_best_mode (bitsize
, bitnum
, 0, 0, MEM_ALIGN (op0
), word_mode
,
1829 MEM_VOLATILE_P (op0
));
1831 if (mode
== VOIDmode
)
1832 /* The only way this should occur is if the field spans word
1834 return extract_split_bit_field (op0
, bitsize
, bitnum
, unsignedp
);
1836 op0
= narrow_bit_field_mem (op0
, mode
, bitsize
, bitnum
, &bitnum
);
1839 return extract_fixed_bit_field_1 (tmode
, op0
, bitsize
, bitnum
,
1843 /* Helper function for extract_fixed_bit_field, extracts
1844 the bit field always using the MODE of OP0. */
1847 extract_fixed_bit_field_1 (machine_mode tmode
, rtx op0
,
1848 unsigned HOST_WIDE_INT bitsize
,
1849 unsigned HOST_WIDE_INT bitnum
, rtx target
,
1852 machine_mode mode
= GET_MODE (op0
);
1853 gcc_assert (SCALAR_INT_MODE_P (mode
));
1855 /* Note that bitsize + bitnum can be greater than GET_MODE_BITSIZE (mode)
1856 for invalid input, such as extract equivalent of f5 from
1857 gcc.dg/pr48335-2.c. */
1859 if (BYTES_BIG_ENDIAN
)
1860 /* BITNUM is the distance between our msb and that of OP0.
1861 Convert it to the distance from the lsb. */
1862 bitnum
= GET_MODE_BITSIZE (mode
) - bitsize
- bitnum
;
1864 /* Now BITNUM is always the distance between the field's lsb and that of OP0.
1865 We have reduced the big-endian case to the little-endian case. */
1871 /* If the field does not already start at the lsb,
1872 shift it so it does. */
1873 /* Maybe propagate the target for the shift. */
1874 rtx subtarget
= (target
!= 0 && REG_P (target
) ? target
: 0);
1877 op0
= expand_shift (RSHIFT_EXPR
, mode
, op0
, bitnum
, subtarget
, 1);
1879 /* Convert the value to the desired mode. */
1881 op0
= convert_to_mode (tmode
, op0
, 1);
1883 /* Unless the msb of the field used to be the msb when we shifted,
1884 mask out the upper bits. */
1886 if (GET_MODE_BITSIZE (mode
) != bitnum
+ bitsize
)
1887 return expand_binop (GET_MODE (op0
), and_optab
, op0
,
1888 mask_rtx (GET_MODE (op0
), 0, bitsize
, 0),
1889 target
, 1, OPTAB_LIB_WIDEN
);
1893 /* To extract a signed bit-field, first shift its msb to the msb of the word,
1894 then arithmetic-shift its lsb to the lsb of the word. */
1895 op0
= force_reg (mode
, op0
);
1897 /* Find the narrowest integer mode that contains the field. */
1899 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1900 mode
= GET_MODE_WIDER_MODE (mode
))
1901 if (GET_MODE_BITSIZE (mode
) >= bitsize
+ bitnum
)
1903 op0
= convert_to_mode (mode
, op0
, 0);
1910 if (GET_MODE_BITSIZE (mode
) != (bitsize
+ bitnum
))
1912 int amount
= GET_MODE_BITSIZE (mode
) - (bitsize
+ bitnum
);
1913 /* Maybe propagate the target for the shift. */
1914 rtx subtarget
= (target
!= 0 && REG_P (target
) ? target
: 0);
1915 op0
= expand_shift (LSHIFT_EXPR
, mode
, op0
, amount
, subtarget
, 1);
1918 return expand_shift (RSHIFT_EXPR
, mode
, op0
,
1919 GET_MODE_BITSIZE (mode
) - bitsize
, target
, 0);
1922 /* Return a constant integer (CONST_INT or CONST_DOUBLE) rtx with the value
1926 lshift_value (machine_mode mode
, unsigned HOST_WIDE_INT value
,
1929 return immed_wide_int_const (wi::lshift (value
, bitpos
), mode
);
1932 /* Extract a bit field that is split across two words
1933 and return an RTX for the result.
1935 OP0 is the REG, SUBREG or MEM rtx for the first of the two words.
1936 BITSIZE is the field width; BITPOS, position of its first bit, in the word.
1937 UNSIGNEDP is 1 if should zero-extend the contents; else sign-extend. */
1940 extract_split_bit_field (rtx op0
, unsigned HOST_WIDE_INT bitsize
,
1941 unsigned HOST_WIDE_INT bitpos
, int unsignedp
)
1944 unsigned int bitsdone
= 0;
1945 rtx result
= NULL_RTX
;
1948 /* Make sure UNIT isn't larger than BITS_PER_WORD, we can only handle that
1950 if (REG_P (op0
) || GET_CODE (op0
) == SUBREG
)
1951 unit
= BITS_PER_WORD
;
1953 unit
= MIN (MEM_ALIGN (op0
), BITS_PER_WORD
);
1955 while (bitsdone
< bitsize
)
1957 unsigned HOST_WIDE_INT thissize
;
1959 unsigned HOST_WIDE_INT thispos
;
1960 unsigned HOST_WIDE_INT offset
;
1962 offset
= (bitpos
+ bitsdone
) / unit
;
1963 thispos
= (bitpos
+ bitsdone
) % unit
;
1965 /* THISSIZE must not overrun a word boundary. Otherwise,
1966 extract_fixed_bit_field will call us again, and we will mutually
1968 thissize
= MIN (bitsize
- bitsdone
, BITS_PER_WORD
);
1969 thissize
= MIN (thissize
, unit
- thispos
);
1971 /* If OP0 is a register, then handle OFFSET here.
1973 When handling multiword bitfields, extract_bit_field may pass
1974 down a word_mode SUBREG of a larger REG for a bitfield that actually
1975 crosses a word boundary. Thus, for a SUBREG, we must find
1976 the current word starting from the base register. */
1977 if (GET_CODE (op0
) == SUBREG
)
1979 int word_offset
= (SUBREG_BYTE (op0
) / UNITS_PER_WORD
) + offset
;
1980 word
= operand_subword_force (SUBREG_REG (op0
), word_offset
,
1981 GET_MODE (SUBREG_REG (op0
)));
1984 else if (REG_P (op0
))
1986 word
= operand_subword_force (op0
, offset
, GET_MODE (op0
));
1992 /* Extract the parts in bit-counting order,
1993 whose meaning is determined by BYTES_PER_UNIT.
1994 OFFSET is in UNITs, and UNIT is in bits. */
1995 part
= extract_fixed_bit_field (word_mode
, word
, thissize
,
1996 offset
* unit
+ thispos
, 0, 1);
1997 bitsdone
+= thissize
;
1999 /* Shift this part into place for the result. */
2000 if (BYTES_BIG_ENDIAN
)
2002 if (bitsize
!= bitsdone
)
2003 part
= expand_shift (LSHIFT_EXPR
, word_mode
, part
,
2004 bitsize
- bitsdone
, 0, 1);
2008 if (bitsdone
!= thissize
)
2009 part
= expand_shift (LSHIFT_EXPR
, word_mode
, part
,
2010 bitsdone
- thissize
, 0, 1);
2016 /* Combine the parts with bitwise or. This works
2017 because we extracted each part as an unsigned bit field. */
2018 result
= expand_binop (word_mode
, ior_optab
, part
, result
, NULL_RTX
, 1,
2024 /* Unsigned bit field: we are done. */
2027 /* Signed bit field: sign-extend with two arithmetic shifts. */
2028 result
= expand_shift (LSHIFT_EXPR
, word_mode
, result
,
2029 BITS_PER_WORD
- bitsize
, NULL_RTX
, 0);
2030 return expand_shift (RSHIFT_EXPR
, word_mode
, result
,
2031 BITS_PER_WORD
- bitsize
, NULL_RTX
, 0);
2034 /* Try to read the low bits of SRC as an rvalue of mode MODE, preserving
2035 the bit pattern. SRC_MODE is the mode of SRC; if this is smaller than
2036 MODE, fill the upper bits with zeros. Fail if the layout of either
2037 mode is unknown (as for CC modes) or if the extraction would involve
2038 unprofitable mode punning. Return the value on success, otherwise
2041 This is different from gen_lowpart* in these respects:
2043 - the returned value must always be considered an rvalue
2045 - when MODE is wider than SRC_MODE, the extraction involves
2048 - when MODE is smaller than SRC_MODE, the extraction involves
2049 a truncation (and is thus subject to TRULY_NOOP_TRUNCATION).
2051 In other words, this routine performs a computation, whereas the
2052 gen_lowpart* routines are conceptually lvalue or rvalue subreg
2056 extract_low_bits (machine_mode mode
, machine_mode src_mode
, rtx src
)
2058 machine_mode int_mode
, src_int_mode
;
2060 if (mode
== src_mode
)
2063 if (CONSTANT_P (src
))
2065 /* simplify_gen_subreg can't be used here, as if simplify_subreg
2066 fails, it will happily create (subreg (symbol_ref)) or similar
2068 unsigned int byte
= subreg_lowpart_offset (mode
, src_mode
);
2069 rtx ret
= simplify_subreg (mode
, src
, src_mode
, byte
);
2073 if (GET_MODE (src
) == VOIDmode
2074 || !validate_subreg (mode
, src_mode
, src
, byte
))
2077 src
= force_reg (GET_MODE (src
), src
);
2078 return gen_rtx_SUBREG (mode
, src
, byte
);
2081 if (GET_MODE_CLASS (mode
) == MODE_CC
|| GET_MODE_CLASS (src_mode
) == MODE_CC
)
2084 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (src_mode
)
2085 && MODES_TIEABLE_P (mode
, src_mode
))
2087 rtx x
= gen_lowpart_common (mode
, src
);
2092 src_int_mode
= int_mode_for_mode (src_mode
);
2093 int_mode
= int_mode_for_mode (mode
);
2094 if (src_int_mode
== BLKmode
|| int_mode
== BLKmode
)
2097 if (!MODES_TIEABLE_P (src_int_mode
, src_mode
))
2099 if (!MODES_TIEABLE_P (int_mode
, mode
))
2102 src
= gen_lowpart (src_int_mode
, src
);
2103 src
= convert_modes (int_mode
, src_int_mode
, src
, true);
2104 src
= gen_lowpart (mode
, src
);
2108 /* Add INC into TARGET. */
2111 expand_inc (rtx target
, rtx inc
)
2113 rtx value
= expand_binop (GET_MODE (target
), add_optab
,
2115 target
, 0, OPTAB_LIB_WIDEN
);
2116 if (value
!= target
)
2117 emit_move_insn (target
, value
);
2120 /* Subtract DEC from TARGET. */
2123 expand_dec (rtx target
, rtx dec
)
2125 rtx value
= expand_binop (GET_MODE (target
), sub_optab
,
2127 target
, 0, OPTAB_LIB_WIDEN
);
2128 if (value
!= target
)
2129 emit_move_insn (target
, value
);
2132 /* Output a shift instruction for expression code CODE,
2133 with SHIFTED being the rtx for the value to shift,
2134 and AMOUNT the rtx for the amount to shift by.
2135 Store the result in the rtx TARGET, if that is convenient.
2136 If UNSIGNEDP is nonzero, do a logical shift; otherwise, arithmetic.
2137 Return the rtx for where the value is. */
2140 expand_shift_1 (enum tree_code code
, machine_mode mode
, rtx shifted
,
2141 rtx amount
, rtx target
, int unsignedp
)
2144 int left
= (code
== LSHIFT_EXPR
|| code
== LROTATE_EXPR
);
2145 int rotate
= (code
== LROTATE_EXPR
|| code
== RROTATE_EXPR
);
2146 optab lshift_optab
= ashl_optab
;
2147 optab rshift_arith_optab
= ashr_optab
;
2148 optab rshift_uns_optab
= lshr_optab
;
2149 optab lrotate_optab
= rotl_optab
;
2150 optab rrotate_optab
= rotr_optab
;
2151 machine_mode op1_mode
;
2152 machine_mode scalar_mode
= mode
;
2154 bool speed
= optimize_insn_for_speed_p ();
2156 if (VECTOR_MODE_P (mode
))
2157 scalar_mode
= GET_MODE_INNER (mode
);
2159 op1_mode
= GET_MODE (op1
);
2161 /* Determine whether the shift/rotate amount is a vector, or scalar. If the
2162 shift amount is a vector, use the vector/vector shift patterns. */
2163 if (VECTOR_MODE_P (mode
) && VECTOR_MODE_P (op1_mode
))
2165 lshift_optab
= vashl_optab
;
2166 rshift_arith_optab
= vashr_optab
;
2167 rshift_uns_optab
= vlshr_optab
;
2168 lrotate_optab
= vrotl_optab
;
2169 rrotate_optab
= vrotr_optab
;
2172 /* Previously detected shift-counts computed by NEGATE_EXPR
2173 and shifted in the other direction; but that does not work
2176 if (SHIFT_COUNT_TRUNCATED
)
2178 if (CONST_INT_P (op1
)
2179 && ((unsigned HOST_WIDE_INT
) INTVAL (op1
) >=
2180 (unsigned HOST_WIDE_INT
) GET_MODE_BITSIZE (scalar_mode
)))
2181 op1
= GEN_INT ((unsigned HOST_WIDE_INT
) INTVAL (op1
)
2182 % GET_MODE_BITSIZE (scalar_mode
));
2183 else if (GET_CODE (op1
) == SUBREG
2184 && subreg_lowpart_p (op1
)
2185 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (op1
)))
2186 && SCALAR_INT_MODE_P (GET_MODE (op1
)))
2187 op1
= SUBREG_REG (op1
);
2190 /* Canonicalize rotates by constant amount. If op1 is bitsize / 2,
2191 prefer left rotation, if op1 is from bitsize / 2 + 1 to
2192 bitsize - 1, use other direction of rotate with 1 .. bitsize / 2 - 1
2195 && CONST_INT_P (op1
)
2196 && IN_RANGE (INTVAL (op1
), GET_MODE_BITSIZE (scalar_mode
) / 2 + left
,
2197 GET_MODE_BITSIZE (scalar_mode
) - 1))
2199 op1
= GEN_INT (GET_MODE_BITSIZE (scalar_mode
) - INTVAL (op1
));
2201 code
= left
? LROTATE_EXPR
: RROTATE_EXPR
;
2204 /* Rotation of 16bit values by 8 bits is effectively equivalent to a bswaphi.
2205 Note that this is not the case for bigger values. For instance a rotation
2206 of 0x01020304 by 16 bits gives 0x03040102 which is different from
2207 0x04030201 (bswapsi). */
2209 && CONST_INT_P (op1
)
2210 && INTVAL (op1
) == BITS_PER_UNIT
2211 && GET_MODE_SIZE (scalar_mode
) == 2
2212 && optab_handler (bswap_optab
, HImode
) != CODE_FOR_nothing
)
2213 return expand_unop (HImode
, bswap_optab
, shifted
, NULL_RTX
,
2216 if (op1
== const0_rtx
)
2219 /* Check whether its cheaper to implement a left shift by a constant
2220 bit count by a sequence of additions. */
2221 if (code
== LSHIFT_EXPR
2222 && CONST_INT_P (op1
)
2224 && INTVAL (op1
) < GET_MODE_PRECISION (scalar_mode
)
2225 && INTVAL (op1
) < MAX_BITS_PER_WORD
2226 && (shift_cost (speed
, mode
, INTVAL (op1
))
2227 > INTVAL (op1
) * add_cost (speed
, mode
))
2228 && shift_cost (speed
, mode
, INTVAL (op1
)) != MAX_COST
)
2231 for (i
= 0; i
< INTVAL (op1
); i
++)
2233 temp
= force_reg (mode
, shifted
);
2234 shifted
= expand_binop (mode
, add_optab
, temp
, temp
, NULL_RTX
,
2235 unsignedp
, OPTAB_LIB_WIDEN
);
2240 for (attempt
= 0; temp
== 0 && attempt
< 3; attempt
++)
2242 enum optab_methods methods
;
2245 methods
= OPTAB_DIRECT
;
2246 else if (attempt
== 1)
2247 methods
= OPTAB_WIDEN
;
2249 methods
= OPTAB_LIB_WIDEN
;
2253 /* Widening does not work for rotation. */
2254 if (methods
== OPTAB_WIDEN
)
2256 else if (methods
== OPTAB_LIB_WIDEN
)
2258 /* If we have been unable to open-code this by a rotation,
2259 do it as the IOR of two shifts. I.e., to rotate A
2261 (A << N) | ((unsigned) A >> ((-N) & (C - 1)))
2262 where C is the bitsize of A.
2264 It is theoretically possible that the target machine might
2265 not be able to perform either shift and hence we would
2266 be making two libcalls rather than just the one for the
2267 shift (similarly if IOR could not be done). We will allow
2268 this extremely unlikely lossage to avoid complicating the
2271 rtx subtarget
= target
== shifted
? 0 : target
;
2272 rtx new_amount
, other_amount
;
2276 if (op1
== const0_rtx
)
2278 else if (CONST_INT_P (op1
))
2279 other_amount
= GEN_INT (GET_MODE_BITSIZE (scalar_mode
)
2284 = simplify_gen_unary (NEG
, GET_MODE (op1
),
2285 op1
, GET_MODE (op1
));
2286 HOST_WIDE_INT mask
= GET_MODE_PRECISION (scalar_mode
) - 1;
2288 = simplify_gen_binary (AND
, GET_MODE (op1
), other_amount
,
2289 gen_int_mode (mask
, GET_MODE (op1
)));
2292 shifted
= force_reg (mode
, shifted
);
2294 temp
= expand_shift_1 (left
? LSHIFT_EXPR
: RSHIFT_EXPR
,
2295 mode
, shifted
, new_amount
, 0, 1);
2296 temp1
= expand_shift_1 (left
? RSHIFT_EXPR
: LSHIFT_EXPR
,
2297 mode
, shifted
, other_amount
,
2299 return expand_binop (mode
, ior_optab
, temp
, temp1
, target
,
2300 unsignedp
, methods
);
2303 temp
= expand_binop (mode
,
2304 left
? lrotate_optab
: rrotate_optab
,
2305 shifted
, op1
, target
, unsignedp
, methods
);
2308 temp
= expand_binop (mode
,
2309 left
? lshift_optab
: rshift_uns_optab
,
2310 shifted
, op1
, target
, unsignedp
, methods
);
2312 /* Do arithmetic shifts.
2313 Also, if we are going to widen the operand, we can just as well
2314 use an arithmetic right-shift instead of a logical one. */
2315 if (temp
== 0 && ! rotate
2316 && (! unsignedp
|| (! left
&& methods
== OPTAB_WIDEN
)))
2318 enum optab_methods methods1
= methods
;
2320 /* If trying to widen a log shift to an arithmetic shift,
2321 don't accept an arithmetic shift of the same size. */
2323 methods1
= OPTAB_MUST_WIDEN
;
2325 /* Arithmetic shift */
2327 temp
= expand_binop (mode
,
2328 left
? lshift_optab
: rshift_arith_optab
,
2329 shifted
, op1
, target
, unsignedp
, methods1
);
2332 /* We used to try extzv here for logical right shifts, but that was
2333 only useful for one machine, the VAX, and caused poor code
2334 generation there for lshrdi3, so the code was deleted and a
2335 define_expand for lshrsi3 was added to vax.md. */
2342 /* Output a shift instruction for expression code CODE,
2343 with SHIFTED being the rtx for the value to shift,
2344 and AMOUNT the amount to shift by.
2345 Store the result in the rtx TARGET, if that is convenient.
2346 If UNSIGNEDP is nonzero, do a logical shift; otherwise, arithmetic.
2347 Return the rtx for where the value is. */
2350 expand_shift (enum tree_code code
, machine_mode mode
, rtx shifted
,
2351 int amount
, rtx target
, int unsignedp
)
2353 return expand_shift_1 (code
, mode
,
2354 shifted
, GEN_INT (amount
), target
, unsignedp
);
2357 /* Output a shift instruction for expression code CODE,
2358 with SHIFTED being the rtx for the value to shift,
2359 and AMOUNT the tree for the amount to shift by.
2360 Store the result in the rtx TARGET, if that is convenient.
2361 If UNSIGNEDP is nonzero, do a logical shift; otherwise, arithmetic.
2362 Return the rtx for where the value is. */
2365 expand_variable_shift (enum tree_code code
, machine_mode mode
, rtx shifted
,
2366 tree amount
, rtx target
, int unsignedp
)
2368 return expand_shift_1 (code
, mode
,
2369 shifted
, expand_normal (amount
), target
, unsignedp
);
2373 /* Indicates the type of fixup needed after a constant multiplication.
2374 BASIC_VARIANT means no fixup is needed, NEGATE_VARIANT means that
2375 the result should be negated, and ADD_VARIANT means that the
2376 multiplicand should be added to the result. */
2377 enum mult_variant
{basic_variant
, negate_variant
, add_variant
};
2379 static void synth_mult (struct algorithm
*, unsigned HOST_WIDE_INT
,
2380 const struct mult_cost
*, machine_mode mode
);
2381 static bool choose_mult_variant (machine_mode
, HOST_WIDE_INT
,
2382 struct algorithm
*, enum mult_variant
*, int);
2383 static rtx
expand_mult_const (machine_mode
, rtx
, HOST_WIDE_INT
, rtx
,
2384 const struct algorithm
*, enum mult_variant
);
2385 static unsigned HOST_WIDE_INT
invert_mod2n (unsigned HOST_WIDE_INT
, int);
2386 static rtx
extract_high_half (machine_mode
, rtx
);
2387 static rtx
expmed_mult_highpart (machine_mode
, rtx
, rtx
, rtx
, int, int);
2388 static rtx
expmed_mult_highpart_optab (machine_mode
, rtx
, rtx
, rtx
,
2390 /* Compute and return the best algorithm for multiplying by T.
2391 The algorithm must cost less than cost_limit
2392 If retval.cost >= COST_LIMIT, no algorithm was found and all
2393 other field of the returned struct are undefined.
2394 MODE is the machine mode of the multiplication. */
2397 synth_mult (struct algorithm
*alg_out
, unsigned HOST_WIDE_INT t
,
2398 const struct mult_cost
*cost_limit
, machine_mode mode
)
2401 struct algorithm
*alg_in
, *best_alg
;
2402 struct mult_cost best_cost
;
2403 struct mult_cost new_limit
;
2404 int op_cost
, op_latency
;
2405 unsigned HOST_WIDE_INT orig_t
= t
;
2406 unsigned HOST_WIDE_INT q
;
2407 int maxm
, hash_index
;
2408 bool cache_hit
= false;
2409 enum alg_code cache_alg
= alg_zero
;
2410 bool speed
= optimize_insn_for_speed_p ();
2412 struct alg_hash_entry
*entry_ptr
;
2414 /* Indicate that no algorithm is yet found. If no algorithm
2415 is found, this value will be returned and indicate failure. */
2416 alg_out
->cost
.cost
= cost_limit
->cost
+ 1;
2417 alg_out
->cost
.latency
= cost_limit
->latency
+ 1;
2419 if (cost_limit
->cost
< 0
2420 || (cost_limit
->cost
== 0 && cost_limit
->latency
<= 0))
2423 /* Be prepared for vector modes. */
2424 imode
= GET_MODE_INNER (mode
);
2425 if (imode
== VOIDmode
)
2428 maxm
= MIN (BITS_PER_WORD
, GET_MODE_BITSIZE (imode
));
2430 /* Restrict the bits of "t" to the multiplication's mode. */
2431 t
&= GET_MODE_MASK (imode
);
2433 /* t == 1 can be done in zero cost. */
2437 alg_out
->cost
.cost
= 0;
2438 alg_out
->cost
.latency
= 0;
2439 alg_out
->op
[0] = alg_m
;
2443 /* t == 0 sometimes has a cost. If it does and it exceeds our limit,
2447 if (MULT_COST_LESS (cost_limit
, zero_cost (speed
)))
2452 alg_out
->cost
.cost
= zero_cost (speed
);
2453 alg_out
->cost
.latency
= zero_cost (speed
);
2454 alg_out
->op
[0] = alg_zero
;
2459 /* We'll be needing a couple extra algorithm structures now. */
2461 alg_in
= XALLOCA (struct algorithm
);
2462 best_alg
= XALLOCA (struct algorithm
);
2463 best_cost
= *cost_limit
;
2465 /* Compute the hash index. */
2466 hash_index
= (t
^ (unsigned int) mode
^ (speed
* 256)) % NUM_ALG_HASH_ENTRIES
;
2468 /* See if we already know what to do for T. */
2469 entry_ptr
= alg_hash_entry_ptr (hash_index
);
2470 if (entry_ptr
->t
== t
2471 && entry_ptr
->mode
== mode
2472 && entry_ptr
->mode
== mode
2473 && entry_ptr
->speed
== speed
2474 && entry_ptr
->alg
!= alg_unknown
)
2476 cache_alg
= entry_ptr
->alg
;
2478 if (cache_alg
== alg_impossible
)
2480 /* The cache tells us that it's impossible to synthesize
2481 multiplication by T within entry_ptr->cost. */
2482 if (!CHEAPER_MULT_COST (&entry_ptr
->cost
, cost_limit
))
2483 /* COST_LIMIT is at least as restrictive as the one
2484 recorded in the hash table, in which case we have no
2485 hope of synthesizing a multiplication. Just
2489 /* If we get here, COST_LIMIT is less restrictive than the
2490 one recorded in the hash table, so we may be able to
2491 synthesize a multiplication. Proceed as if we didn't
2492 have the cache entry. */
2496 if (CHEAPER_MULT_COST (cost_limit
, &entry_ptr
->cost
))
2497 /* The cached algorithm shows that this multiplication
2498 requires more cost than COST_LIMIT. Just return. This
2499 way, we don't clobber this cache entry with
2500 alg_impossible but retain useful information. */
2512 goto do_alg_addsub_t_m2
;
2514 case alg_add_factor
:
2515 case alg_sub_factor
:
2516 goto do_alg_addsub_factor
;
2519 goto do_alg_add_t2_m
;
2522 goto do_alg_sub_t2_m
;
2530 /* If we have a group of zero bits at the low-order part of T, try
2531 multiplying by the remaining bits and then doing a shift. */
2536 m
= floor_log2 (t
& -t
); /* m = number of low zero bits */
2540 /* The function expand_shift will choose between a shift and
2541 a sequence of additions, so the observed cost is given as
2542 MIN (m * add_cost(speed, mode), shift_cost(speed, mode, m)). */
2543 op_cost
= m
* add_cost (speed
, mode
);
2544 if (shift_cost (speed
, mode
, m
) < op_cost
)
2545 op_cost
= shift_cost (speed
, mode
, m
);
2546 new_limit
.cost
= best_cost
.cost
- op_cost
;
2547 new_limit
.latency
= best_cost
.latency
- op_cost
;
2548 synth_mult (alg_in
, q
, &new_limit
, mode
);
2550 alg_in
->cost
.cost
+= op_cost
;
2551 alg_in
->cost
.latency
+= op_cost
;
2552 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2554 struct algorithm
*x
;
2555 best_cost
= alg_in
->cost
;
2556 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2557 best_alg
->log
[best_alg
->ops
] = m
;
2558 best_alg
->op
[best_alg
->ops
] = alg_shift
;
2561 /* See if treating ORIG_T as a signed number yields a better
2562 sequence. Try this sequence only for a negative ORIG_T
2563 as it would be useless for a non-negative ORIG_T. */
2564 if ((HOST_WIDE_INT
) orig_t
< 0)
2566 /* Shift ORIG_T as follows because a right shift of a
2567 negative-valued signed type is implementation
2569 q
= ~(~orig_t
>> m
);
2570 /* The function expand_shift will choose between a shift
2571 and a sequence of additions, so the observed cost is
2572 given as MIN (m * add_cost(speed, mode),
2573 shift_cost(speed, mode, m)). */
2574 op_cost
= m
* add_cost (speed
, mode
);
2575 if (shift_cost (speed
, mode
, m
) < op_cost
)
2576 op_cost
= shift_cost (speed
, mode
, m
);
2577 new_limit
.cost
= best_cost
.cost
- op_cost
;
2578 new_limit
.latency
= best_cost
.latency
- op_cost
;
2579 synth_mult (alg_in
, q
, &new_limit
, mode
);
2581 alg_in
->cost
.cost
+= op_cost
;
2582 alg_in
->cost
.latency
+= op_cost
;
2583 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2585 struct algorithm
*x
;
2586 best_cost
= alg_in
->cost
;
2587 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2588 best_alg
->log
[best_alg
->ops
] = m
;
2589 best_alg
->op
[best_alg
->ops
] = alg_shift
;
2597 /* If we have an odd number, add or subtract one. */
2600 unsigned HOST_WIDE_INT w
;
2603 for (w
= 1; (w
& t
) != 0; w
<<= 1)
2605 /* If T was -1, then W will be zero after the loop. This is another
2606 case where T ends with ...111. Handling this with (T + 1) and
2607 subtract 1 produces slightly better code and results in algorithm
2608 selection much faster than treating it like the ...0111 case
2612 /* Reject the case where t is 3.
2613 Thus we prefer addition in that case. */
2616 /* T ends with ...111. Multiply by (T + 1) and subtract 1. */
2618 op_cost
= add_cost (speed
, mode
);
2619 new_limit
.cost
= best_cost
.cost
- op_cost
;
2620 new_limit
.latency
= best_cost
.latency
- op_cost
;
2621 synth_mult (alg_in
, t
+ 1, &new_limit
, mode
);
2623 alg_in
->cost
.cost
+= op_cost
;
2624 alg_in
->cost
.latency
+= op_cost
;
2625 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2627 struct algorithm
*x
;
2628 best_cost
= alg_in
->cost
;
2629 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2630 best_alg
->log
[best_alg
->ops
] = 0;
2631 best_alg
->op
[best_alg
->ops
] = alg_sub_t_m2
;
2636 /* T ends with ...01 or ...011. Multiply by (T - 1) and add 1. */
2638 op_cost
= add_cost (speed
, mode
);
2639 new_limit
.cost
= best_cost
.cost
- op_cost
;
2640 new_limit
.latency
= best_cost
.latency
- op_cost
;
2641 synth_mult (alg_in
, t
- 1, &new_limit
, mode
);
2643 alg_in
->cost
.cost
+= op_cost
;
2644 alg_in
->cost
.latency
+= op_cost
;
2645 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2647 struct algorithm
*x
;
2648 best_cost
= alg_in
->cost
;
2649 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2650 best_alg
->log
[best_alg
->ops
] = 0;
2651 best_alg
->op
[best_alg
->ops
] = alg_add_t_m2
;
2655 /* We may be able to calculate a * -7, a * -15, a * -31, etc
2656 quickly with a - a * n for some appropriate constant n. */
2657 m
= exact_log2 (-orig_t
+ 1);
2658 if (m
>= 0 && m
< maxm
)
2660 op_cost
= shiftsub1_cost (speed
, mode
, m
);
2661 new_limit
.cost
= best_cost
.cost
- op_cost
;
2662 new_limit
.latency
= best_cost
.latency
- op_cost
;
2663 synth_mult (alg_in
, (unsigned HOST_WIDE_INT
) (-orig_t
+ 1) >> m
,
2666 alg_in
->cost
.cost
+= op_cost
;
2667 alg_in
->cost
.latency
+= op_cost
;
2668 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2670 struct algorithm
*x
;
2671 best_cost
= alg_in
->cost
;
2672 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2673 best_alg
->log
[best_alg
->ops
] = m
;
2674 best_alg
->op
[best_alg
->ops
] = alg_sub_t_m2
;
2682 /* Look for factors of t of the form
2683 t = q(2**m +- 1), 2 <= m <= floor(log2(t - 1)).
2684 If we find such a factor, we can multiply by t using an algorithm that
2685 multiplies by q, shift the result by m and add/subtract it to itself.
2687 We search for large factors first and loop down, even if large factors
2688 are less probable than small; if we find a large factor we will find a
2689 good sequence quickly, and therefore be able to prune (by decreasing
2690 COST_LIMIT) the search. */
2692 do_alg_addsub_factor
:
2693 for (m
= floor_log2 (t
- 1); m
>= 2; m
--)
2695 unsigned HOST_WIDE_INT d
;
2697 d
= ((unsigned HOST_WIDE_INT
) 1 << m
) + 1;
2698 if (t
% d
== 0 && t
> d
&& m
< maxm
2699 && (!cache_hit
|| cache_alg
== alg_add_factor
))
2701 /* If the target has a cheap shift-and-add instruction use
2702 that in preference to a shift insn followed by an add insn.
2703 Assume that the shift-and-add is "atomic" with a latency
2704 equal to its cost, otherwise assume that on superscalar
2705 hardware the shift may be executed concurrently with the
2706 earlier steps in the algorithm. */
2707 op_cost
= add_cost (speed
, mode
) + shift_cost (speed
, mode
, m
);
2708 if (shiftadd_cost (speed
, mode
, m
) < op_cost
)
2710 op_cost
= shiftadd_cost (speed
, mode
, m
);
2711 op_latency
= op_cost
;
2714 op_latency
= add_cost (speed
, mode
);
2716 new_limit
.cost
= best_cost
.cost
- op_cost
;
2717 new_limit
.latency
= best_cost
.latency
- op_latency
;
2718 synth_mult (alg_in
, t
/ d
, &new_limit
, mode
);
2720 alg_in
->cost
.cost
+= op_cost
;
2721 alg_in
->cost
.latency
+= op_latency
;
2722 if (alg_in
->cost
.latency
< op_cost
)
2723 alg_in
->cost
.latency
= op_cost
;
2724 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2726 struct algorithm
*x
;
2727 best_cost
= alg_in
->cost
;
2728 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2729 best_alg
->log
[best_alg
->ops
] = m
;
2730 best_alg
->op
[best_alg
->ops
] = alg_add_factor
;
2732 /* Other factors will have been taken care of in the recursion. */
2736 d
= ((unsigned HOST_WIDE_INT
) 1 << m
) - 1;
2737 if (t
% d
== 0 && t
> d
&& m
< maxm
2738 && (!cache_hit
|| cache_alg
== alg_sub_factor
))
2740 /* If the target has a cheap shift-and-subtract insn use
2741 that in preference to a shift insn followed by a sub insn.
2742 Assume that the shift-and-sub is "atomic" with a latency
2743 equal to it's cost, otherwise assume that on superscalar
2744 hardware the shift may be executed concurrently with the
2745 earlier steps in the algorithm. */
2746 op_cost
= add_cost (speed
, mode
) + shift_cost (speed
, mode
, m
);
2747 if (shiftsub0_cost (speed
, mode
, m
) < op_cost
)
2749 op_cost
= shiftsub0_cost (speed
, mode
, m
);
2750 op_latency
= op_cost
;
2753 op_latency
= add_cost (speed
, mode
);
2755 new_limit
.cost
= best_cost
.cost
- op_cost
;
2756 new_limit
.latency
= best_cost
.latency
- op_latency
;
2757 synth_mult (alg_in
, t
/ d
, &new_limit
, mode
);
2759 alg_in
->cost
.cost
+= op_cost
;
2760 alg_in
->cost
.latency
+= op_latency
;
2761 if (alg_in
->cost
.latency
< op_cost
)
2762 alg_in
->cost
.latency
= op_cost
;
2763 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2765 struct algorithm
*x
;
2766 best_cost
= alg_in
->cost
;
2767 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2768 best_alg
->log
[best_alg
->ops
] = m
;
2769 best_alg
->op
[best_alg
->ops
] = alg_sub_factor
;
2777 /* Try shift-and-add (load effective address) instructions,
2778 i.e. do a*3, a*5, a*9. */
2785 if (m
>= 0 && m
< maxm
)
2787 op_cost
= shiftadd_cost (speed
, mode
, m
);
2788 new_limit
.cost
= best_cost
.cost
- op_cost
;
2789 new_limit
.latency
= best_cost
.latency
- op_cost
;
2790 synth_mult (alg_in
, (t
- 1) >> m
, &new_limit
, mode
);
2792 alg_in
->cost
.cost
+= op_cost
;
2793 alg_in
->cost
.latency
+= op_cost
;
2794 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2796 struct algorithm
*x
;
2797 best_cost
= alg_in
->cost
;
2798 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2799 best_alg
->log
[best_alg
->ops
] = m
;
2800 best_alg
->op
[best_alg
->ops
] = alg_add_t2_m
;
2810 if (m
>= 0 && m
< maxm
)
2812 op_cost
= shiftsub0_cost (speed
, mode
, m
);
2813 new_limit
.cost
= best_cost
.cost
- op_cost
;
2814 new_limit
.latency
= best_cost
.latency
- op_cost
;
2815 synth_mult (alg_in
, (t
+ 1) >> m
, &new_limit
, mode
);
2817 alg_in
->cost
.cost
+= op_cost
;
2818 alg_in
->cost
.latency
+= op_cost
;
2819 if (CHEAPER_MULT_COST (&alg_in
->cost
, &best_cost
))
2821 struct algorithm
*x
;
2822 best_cost
= alg_in
->cost
;
2823 x
= alg_in
, alg_in
= best_alg
, best_alg
= x
;
2824 best_alg
->log
[best_alg
->ops
] = m
;
2825 best_alg
->op
[best_alg
->ops
] = alg_sub_t2_m
;
2833 /* If best_cost has not decreased, we have not found any algorithm. */
2834 if (!CHEAPER_MULT_COST (&best_cost
, cost_limit
))
2836 /* We failed to find an algorithm. Record alg_impossible for
2837 this case (that is, <T, MODE, COST_LIMIT>) so that next time
2838 we are asked to find an algorithm for T within the same or
2839 lower COST_LIMIT, we can immediately return to the
2842 entry_ptr
->mode
= mode
;
2843 entry_ptr
->speed
= speed
;
2844 entry_ptr
->alg
= alg_impossible
;
2845 entry_ptr
->cost
= *cost_limit
;
2849 /* Cache the result. */
2853 entry_ptr
->mode
= mode
;
2854 entry_ptr
->speed
= speed
;
2855 entry_ptr
->alg
= best_alg
->op
[best_alg
->ops
];
2856 entry_ptr
->cost
.cost
= best_cost
.cost
;
2857 entry_ptr
->cost
.latency
= best_cost
.latency
;
2860 /* If we are getting a too long sequence for `struct algorithm'
2861 to record, make this search fail. */
2862 if (best_alg
->ops
== MAX_BITS_PER_WORD
)
2865 /* Copy the algorithm from temporary space to the space at alg_out.
2866 We avoid using structure assignment because the majority of
2867 best_alg is normally undefined, and this is a critical function. */
2868 alg_out
->ops
= best_alg
->ops
+ 1;
2869 alg_out
->cost
= best_cost
;
2870 memcpy (alg_out
->op
, best_alg
->op
,
2871 alg_out
->ops
* sizeof *alg_out
->op
);
2872 memcpy (alg_out
->log
, best_alg
->log
,
2873 alg_out
->ops
* sizeof *alg_out
->log
);
2876 /* Find the cheapest way of multiplying a value of mode MODE by VAL.
2877 Try three variations:
2879 - a shift/add sequence based on VAL itself
2880 - a shift/add sequence based on -VAL, followed by a negation
2881 - a shift/add sequence based on VAL - 1, followed by an addition.
2883 Return true if the cheapest of these cost less than MULT_COST,
2884 describing the algorithm in *ALG and final fixup in *VARIANT. */
2887 choose_mult_variant (machine_mode mode
, HOST_WIDE_INT val
,
2888 struct algorithm
*alg
, enum mult_variant
*variant
,
2891 struct algorithm alg2
;
2892 struct mult_cost limit
;
2894 bool speed
= optimize_insn_for_speed_p ();
2896 /* Fail quickly for impossible bounds. */
2900 /* Ensure that mult_cost provides a reasonable upper bound.
2901 Any constant multiplication can be performed with less
2902 than 2 * bits additions. */
2903 op_cost
= 2 * GET_MODE_UNIT_BITSIZE (mode
) * add_cost (speed
, mode
);
2904 if (mult_cost
> op_cost
)
2905 mult_cost
= op_cost
;
2907 *variant
= basic_variant
;
2908 limit
.cost
= mult_cost
;
2909 limit
.latency
= mult_cost
;
2910 synth_mult (alg
, val
, &limit
, mode
);
2912 /* This works only if the inverted value actually fits in an
2914 if (HOST_BITS_PER_INT
>= GET_MODE_UNIT_BITSIZE (mode
))
2916 op_cost
= neg_cost (speed
, mode
);
2917 if (MULT_COST_LESS (&alg
->cost
, mult_cost
))
2919 limit
.cost
= alg
->cost
.cost
- op_cost
;
2920 limit
.latency
= alg
->cost
.latency
- op_cost
;
2924 limit
.cost
= mult_cost
- op_cost
;
2925 limit
.latency
= mult_cost
- op_cost
;
2928 synth_mult (&alg2
, -val
, &limit
, mode
);
2929 alg2
.cost
.cost
+= op_cost
;
2930 alg2
.cost
.latency
+= op_cost
;
2931 if (CHEAPER_MULT_COST (&alg2
.cost
, &alg
->cost
))
2932 *alg
= alg2
, *variant
= negate_variant
;
2935 /* This proves very useful for division-by-constant. */
2936 op_cost
= add_cost (speed
, mode
);
2937 if (MULT_COST_LESS (&alg
->cost
, mult_cost
))
2939 limit
.cost
= alg
->cost
.cost
- op_cost
;
2940 limit
.latency
= alg
->cost
.latency
- op_cost
;
2944 limit
.cost
= mult_cost
- op_cost
;
2945 limit
.latency
= mult_cost
- op_cost
;
2948 synth_mult (&alg2
, val
- 1, &limit
, mode
);
2949 alg2
.cost
.cost
+= op_cost
;
2950 alg2
.cost
.latency
+= op_cost
;
2951 if (CHEAPER_MULT_COST (&alg2
.cost
, &alg
->cost
))
2952 *alg
= alg2
, *variant
= add_variant
;
2954 return MULT_COST_LESS (&alg
->cost
, mult_cost
);
2957 /* A subroutine of expand_mult, used for constant multiplications.
2958 Multiply OP0 by VAL in mode MODE, storing the result in TARGET if
2959 convenient. Use the shift/add sequence described by ALG and apply
2960 the final fixup specified by VARIANT. */
2963 expand_mult_const (machine_mode mode
, rtx op0
, HOST_WIDE_INT val
,
2964 rtx target
, const struct algorithm
*alg
,
2965 enum mult_variant variant
)
2967 HOST_WIDE_INT val_so_far
;
2973 /* Avoid referencing memory over and over and invalid sharing
2975 op0
= force_reg (mode
, op0
);
2977 /* ACCUM starts out either as OP0 or as a zero, depending on
2978 the first operation. */
2980 if (alg
->op
[0] == alg_zero
)
2982 accum
= copy_to_mode_reg (mode
, CONST0_RTX (mode
));
2985 else if (alg
->op
[0] == alg_m
)
2987 accum
= copy_to_mode_reg (mode
, op0
);
2993 for (opno
= 1; opno
< alg
->ops
; opno
++)
2995 int log
= alg
->log
[opno
];
2996 rtx shift_subtarget
= optimize
? 0 : accum
;
2998 = (opno
== alg
->ops
- 1 && target
!= 0 && variant
!= add_variant
3001 rtx accum_target
= optimize
? 0 : accum
;
3004 switch (alg
->op
[opno
])
3007 tem
= expand_shift (LSHIFT_EXPR
, mode
, accum
, log
, NULL_RTX
, 0);
3008 /* REG_EQUAL note will be attached to the following insn. */
3009 emit_move_insn (accum
, tem
);
3014 tem
= expand_shift (LSHIFT_EXPR
, mode
, op0
, log
, NULL_RTX
, 0);
3015 accum
= force_operand (gen_rtx_PLUS (mode
, accum
, tem
),
3016 add_target
? add_target
: accum_target
);
3017 val_so_far
+= (HOST_WIDE_INT
) 1 << log
;
3021 tem
= expand_shift (LSHIFT_EXPR
, mode
, op0
, log
, NULL_RTX
, 0);
3022 accum
= force_operand (gen_rtx_MINUS (mode
, accum
, tem
),
3023 add_target
? add_target
: accum_target
);
3024 val_so_far
-= (HOST_WIDE_INT
) 1 << log
;
3028 accum
= expand_shift (LSHIFT_EXPR
, mode
, accum
,
3029 log
, shift_subtarget
, 0);
3030 accum
= force_operand (gen_rtx_PLUS (mode
, accum
, op0
),
3031 add_target
? add_target
: accum_target
);
3032 val_so_far
= (val_so_far
<< log
) + 1;
3036 accum
= expand_shift (LSHIFT_EXPR
, mode
, accum
,
3037 log
, shift_subtarget
, 0);
3038 accum
= force_operand (gen_rtx_MINUS (mode
, accum
, op0
),
3039 add_target
? add_target
: accum_target
);
3040 val_so_far
= (val_so_far
<< log
) - 1;
3043 case alg_add_factor
:
3044 tem
= expand_shift (LSHIFT_EXPR
, mode
, accum
, log
, NULL_RTX
, 0);
3045 accum
= force_operand (gen_rtx_PLUS (mode
, accum
, tem
),
3046 add_target
? add_target
: accum_target
);
3047 val_so_far
+= val_so_far
<< log
;
3050 case alg_sub_factor
:
3051 tem
= expand_shift (LSHIFT_EXPR
, mode
, accum
, log
, NULL_RTX
, 0);
3052 accum
= force_operand (gen_rtx_MINUS (mode
, tem
, accum
),
3054 ? add_target
: (optimize
? 0 : tem
)));
3055 val_so_far
= (val_so_far
<< log
) - val_so_far
;
3062 if (SCALAR_INT_MODE_P (mode
))
3064 /* Write a REG_EQUAL note on the last insn so that we can cse
3065 multiplication sequences. Note that if ACCUM is a SUBREG,
3066 we've set the inner register and must properly indicate that. */
3067 tem
= op0
, nmode
= mode
;
3068 accum_inner
= accum
;
3069 if (GET_CODE (accum
) == SUBREG
)
3071 accum_inner
= SUBREG_REG (accum
);
3072 nmode
= GET_MODE (accum_inner
);
3073 tem
= gen_lowpart (nmode
, op0
);
3076 insn
= get_last_insn ();
3077 set_dst_reg_note (insn
, REG_EQUAL
,
3078 gen_rtx_MULT (nmode
, tem
,
3079 gen_int_mode (val_so_far
, nmode
)),
3084 if (variant
== negate_variant
)
3086 val_so_far
= -val_so_far
;
3087 accum
= expand_unop (mode
, neg_optab
, accum
, target
, 0);
3089 else if (variant
== add_variant
)
3091 val_so_far
= val_so_far
+ 1;
3092 accum
= force_operand (gen_rtx_PLUS (mode
, accum
, op0
), target
);
3095 /* Compare only the bits of val and val_so_far that are significant
3096 in the result mode, to avoid sign-/zero-extension confusion. */
3097 nmode
= GET_MODE_INNER (mode
);
3098 if (nmode
== VOIDmode
)
3100 val
&= GET_MODE_MASK (nmode
);
3101 val_so_far
&= GET_MODE_MASK (nmode
);
3102 gcc_assert (val
== val_so_far
);
3107 /* Perform a multiplication and return an rtx for the result.
3108 MODE is mode of value; OP0 and OP1 are what to multiply (rtx's);
3109 TARGET is a suggestion for where to store the result (an rtx).
3111 We check specially for a constant integer as OP1.
3112 If you want this check for OP0 as well, then before calling
3113 you should swap the two operands if OP0 would be constant. */
3116 expand_mult (machine_mode mode
, rtx op0
, rtx op1
, rtx target
,
3119 enum mult_variant variant
;
3120 struct algorithm algorithm
;
3123 bool speed
= optimize_insn_for_speed_p ();
3124 bool do_trapv
= flag_trapv
&& SCALAR_INT_MODE_P (mode
) && !unsignedp
;
3126 if (CONSTANT_P (op0
))
3127 std::swap (op0
, op1
);
3129 /* For vectors, there are several simplifications that can be made if
3130 all elements of the vector constant are identical. */
3132 if (GET_CODE (op1
) == CONST_VECTOR
)
3134 int i
, n
= CONST_VECTOR_NUNITS (op1
);
3135 scalar_op1
= CONST_VECTOR_ELT (op1
, 0);
3136 for (i
= 1; i
< n
; ++i
)
3137 if (!rtx_equal_p (scalar_op1
, CONST_VECTOR_ELT (op1
, i
)))
3141 if (INTEGRAL_MODE_P (mode
))
3144 HOST_WIDE_INT coeff
;
3148 if (op1
== CONST0_RTX (mode
))
3150 if (op1
== CONST1_RTX (mode
))
3152 if (op1
== CONSTM1_RTX (mode
))
3153 return expand_unop (mode
, do_trapv
? negv_optab
: neg_optab
,
3159 /* If mode is integer vector mode, check if the backend supports
3160 vector lshift (by scalar or vector) at all. If not, we can't use
3161 synthetized multiply. */
3162 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
3163 && optab_handler (vashl_optab
, mode
) == CODE_FOR_nothing
3164 && optab_handler (ashl_optab
, mode
) == CODE_FOR_nothing
)
3167 /* These are the operations that are potentially turned into
3168 a sequence of shifts and additions. */
3169 mode_bitsize
= GET_MODE_UNIT_BITSIZE (mode
);
3171 /* synth_mult does an `unsigned int' multiply. As long as the mode is
3172 less than or equal in size to `unsigned int' this doesn't matter.
3173 If the mode is larger than `unsigned int', then synth_mult works
3174 only if the constant value exactly fits in an `unsigned int' without
3175 any truncation. This means that multiplying by negative values does
3176 not work; results are off by 2^32 on a 32 bit machine. */
3177 if (CONST_INT_P (scalar_op1
))
3179 coeff
= INTVAL (scalar_op1
);
3182 #if TARGET_SUPPORTS_WIDE_INT
3183 else if (CONST_WIDE_INT_P (scalar_op1
))
3185 else if (CONST_DOUBLE_AS_INT_P (scalar_op1
))
3188 int shift
= wi::exact_log2 (std::make_pair (scalar_op1
, mode
));
3189 /* Perfect power of 2 (other than 1, which is handled above). */
3191 return expand_shift (LSHIFT_EXPR
, mode
, op0
,
3192 shift
, target
, unsignedp
);
3199 /* We used to test optimize here, on the grounds that it's better to
3200 produce a smaller program when -O is not used. But this causes
3201 such a terrible slowdown sometimes that it seems better to always
3204 /* Special case powers of two. */
3205 if (EXACT_POWER_OF_2_OR_ZERO_P (coeff
)
3206 && !(is_neg
&& mode_bitsize
> HOST_BITS_PER_WIDE_INT
))
3207 return expand_shift (LSHIFT_EXPR
, mode
, op0
,
3208 floor_log2 (coeff
), target
, unsignedp
);
3210 fake_reg
= gen_raw_REG (mode
, LAST_VIRTUAL_REGISTER
+ 1);
3212 /* Attempt to handle multiplication of DImode values by negative
3213 coefficients, by performing the multiplication by a positive
3214 multiplier and then inverting the result. */
3215 if (is_neg
&& mode_bitsize
> HOST_BITS_PER_WIDE_INT
)
3217 /* Its safe to use -coeff even for INT_MIN, as the
3218 result is interpreted as an unsigned coefficient.
3219 Exclude cost of op0 from max_cost to match the cost
3220 calculation of the synth_mult. */
3221 coeff
= -(unsigned HOST_WIDE_INT
) coeff
;
3222 max_cost
= (set_src_cost (gen_rtx_MULT (mode
, fake_reg
, op1
), speed
)
3223 - neg_cost (speed
, mode
));
3227 /* Special case powers of two. */
3228 if (EXACT_POWER_OF_2_OR_ZERO_P (coeff
))
3230 rtx temp
= expand_shift (LSHIFT_EXPR
, mode
, op0
,
3231 floor_log2 (coeff
), target
, unsignedp
);
3232 return expand_unop (mode
, neg_optab
, temp
, target
, 0);
3235 if (choose_mult_variant (mode
, coeff
, &algorithm
, &variant
,
3238 rtx temp
= expand_mult_const (mode
, op0
, coeff
, NULL_RTX
,
3239 &algorithm
, variant
);
3240 return expand_unop (mode
, neg_optab
, temp
, target
, 0);
3245 /* Exclude cost of op0 from max_cost to match the cost
3246 calculation of the synth_mult. */
3247 max_cost
= set_src_cost (gen_rtx_MULT (mode
, fake_reg
, op1
), speed
);
3248 if (choose_mult_variant (mode
, coeff
, &algorithm
, &variant
, max_cost
))
3249 return expand_mult_const (mode
, op0
, coeff
, target
,
3250 &algorithm
, variant
);
3254 /* Expand x*2.0 as x+x. */
3255 if (CONST_DOUBLE_AS_FLOAT_P (scalar_op1
))
3258 REAL_VALUE_FROM_CONST_DOUBLE (d
, scalar_op1
);
3260 if (REAL_VALUES_EQUAL (d
, dconst2
))
3262 op0
= force_reg (GET_MODE (op0
), op0
);
3263 return expand_binop (mode
, add_optab
, op0
, op0
,
3264 target
, unsignedp
, OPTAB_LIB_WIDEN
);
3269 /* This used to use umul_optab if unsigned, but for non-widening multiply
3270 there is no difference between signed and unsigned. */
3271 op0
= expand_binop (mode
, do_trapv
? smulv_optab
: smul_optab
,
3272 op0
, op1
, target
, unsignedp
, OPTAB_LIB_WIDEN
);
3277 /* Return a cost estimate for multiplying a register by the given
3278 COEFFicient in the given MODE and SPEED. */
3281 mult_by_coeff_cost (HOST_WIDE_INT coeff
, machine_mode mode
, bool speed
)
3284 struct algorithm algorithm
;
3285 enum mult_variant variant
;
3287 rtx fake_reg
= gen_raw_REG (mode
, LAST_VIRTUAL_REGISTER
+ 1);
3288 max_cost
= set_src_cost (gen_rtx_MULT (mode
, fake_reg
, fake_reg
), speed
);
3289 if (choose_mult_variant (mode
, coeff
, &algorithm
, &variant
, max_cost
))
3290 return algorithm
.cost
.cost
;
3295 /* Perform a widening multiplication and return an rtx for the result.
3296 MODE is mode of value; OP0 and OP1 are what to multiply (rtx's);
3297 TARGET is a suggestion for where to store the result (an rtx).
3298 THIS_OPTAB is the optab we should use, it must be either umul_widen_optab
3299 or smul_widen_optab.
3301 We check specially for a constant integer as OP1, comparing the
3302 cost of a widening multiply against the cost of a sequence of shifts
3306 expand_widening_mult (machine_mode mode
, rtx op0
, rtx op1
, rtx target
,
3307 int unsignedp
, optab this_optab
)
3309 bool speed
= optimize_insn_for_speed_p ();
3312 if (CONST_INT_P (op1
)
3313 && GET_MODE (op0
) != VOIDmode
3314 && (cop1
= convert_modes (mode
, GET_MODE (op0
), op1
,
3315 this_optab
== umul_widen_optab
))
3316 && CONST_INT_P (cop1
)
3317 && (INTVAL (cop1
) >= 0
3318 || HWI_COMPUTABLE_MODE_P (mode
)))
3320 HOST_WIDE_INT coeff
= INTVAL (cop1
);
3322 enum mult_variant variant
;
3323 struct algorithm algorithm
;
3326 return CONST0_RTX (mode
);
3328 /* Special case powers of two. */
3329 if (EXACT_POWER_OF_2_OR_ZERO_P (coeff
))
3331 op0
= convert_to_mode (mode
, op0
, this_optab
== umul_widen_optab
);
3332 return expand_shift (LSHIFT_EXPR
, mode
, op0
,
3333 floor_log2 (coeff
), target
, unsignedp
);
3336 /* Exclude cost of op0 from max_cost to match the cost
3337 calculation of the synth_mult. */
3338 max_cost
= mul_widen_cost (speed
, mode
);
3339 if (choose_mult_variant (mode
, coeff
, &algorithm
, &variant
,
3342 op0
= convert_to_mode (mode
, op0
, this_optab
== umul_widen_optab
);
3343 return expand_mult_const (mode
, op0
, coeff
, target
,
3344 &algorithm
, variant
);
3347 return expand_binop (mode
, this_optab
, op0
, op1
, target
,
3348 unsignedp
, OPTAB_LIB_WIDEN
);
3351 /* Choose a minimal N + 1 bit approximation to 1/D that can be used to
3352 replace division by D, and put the least significant N bits of the result
3353 in *MULTIPLIER_PTR and return the most significant bit.
3355 The width of operations is N (should be <= HOST_BITS_PER_WIDE_INT), the
3356 needed precision is in PRECISION (should be <= N).
3358 PRECISION should be as small as possible so this function can choose
3359 multiplier more freely.
3361 The rounded-up logarithm of D is placed in *lgup_ptr. A shift count that
3362 is to be used for a final right shift is placed in *POST_SHIFT_PTR.
3364 Using this function, x/D will be equal to (x * m) >> (*POST_SHIFT_PTR),
3365 where m is the full HOST_BITS_PER_WIDE_INT + 1 bit multiplier. */
3367 unsigned HOST_WIDE_INT
3368 choose_multiplier (unsigned HOST_WIDE_INT d
, int n
, int precision
,
3369 unsigned HOST_WIDE_INT
*multiplier_ptr
,
3370 int *post_shift_ptr
, int *lgup_ptr
)
3372 int lgup
, post_shift
;
3375 /* lgup = ceil(log2(divisor)); */
3376 lgup
= ceil_log2 (d
);
3378 gcc_assert (lgup
<= n
);
3381 pow2
= n
+ lgup
- precision
;
3383 /* mlow = 2^(N + lgup)/d */
3384 wide_int val
= wi::set_bit_in_zero (pow
, HOST_BITS_PER_DOUBLE_INT
);
3385 wide_int mlow
= wi::udiv_trunc (val
, d
);
3387 /* mhigh = (2^(N + lgup) + 2^(N + lgup - precision))/d */
3388 val
|= wi::set_bit_in_zero (pow2
, HOST_BITS_PER_DOUBLE_INT
);
3389 wide_int mhigh
= wi::udiv_trunc (val
, d
);
3391 /* If precision == N, then mlow, mhigh exceed 2^N
3392 (but they do not exceed 2^(N+1)). */
3394 /* Reduce to lowest terms. */
3395 for (post_shift
= lgup
; post_shift
> 0; post_shift
--)
3397 unsigned HOST_WIDE_INT ml_lo
= wi::extract_uhwi (mlow
, 1,
3398 HOST_BITS_PER_WIDE_INT
);
3399 unsigned HOST_WIDE_INT mh_lo
= wi::extract_uhwi (mhigh
, 1,
3400 HOST_BITS_PER_WIDE_INT
);
3404 mlow
= wi::uhwi (ml_lo
, HOST_BITS_PER_DOUBLE_INT
);
3405 mhigh
= wi::uhwi (mh_lo
, HOST_BITS_PER_DOUBLE_INT
);
3408 *post_shift_ptr
= post_shift
;
3410 if (n
< HOST_BITS_PER_WIDE_INT
)
3412 unsigned HOST_WIDE_INT mask
= ((unsigned HOST_WIDE_INT
) 1 << n
) - 1;
3413 *multiplier_ptr
= mhigh
.to_uhwi () & mask
;
3414 return mhigh
.to_uhwi () >= mask
;
3418 *multiplier_ptr
= mhigh
.to_uhwi ();
3419 return wi::extract_uhwi (mhigh
, HOST_BITS_PER_WIDE_INT
, 1);
3423 /* Compute the inverse of X mod 2**n, i.e., find Y such that X * Y is
3424 congruent to 1 (mod 2**N). */
3426 static unsigned HOST_WIDE_INT
3427 invert_mod2n (unsigned HOST_WIDE_INT x
, int n
)
3429 /* Solve x*y == 1 (mod 2^n), where x is odd. Return y. */
3431 /* The algorithm notes that the choice y = x satisfies
3432 x*y == 1 mod 2^3, since x is assumed odd.
3433 Each iteration doubles the number of bits of significance in y. */
3435 unsigned HOST_WIDE_INT mask
;
3436 unsigned HOST_WIDE_INT y
= x
;
3439 mask
= (n
== HOST_BITS_PER_WIDE_INT
3440 ? ~(unsigned HOST_WIDE_INT
) 0
3441 : ((unsigned HOST_WIDE_INT
) 1 << n
) - 1);
3445 y
= y
* (2 - x
*y
) & mask
; /* Modulo 2^N */
3451 /* Emit code to adjust ADJ_OPERAND after multiplication of wrong signedness
3452 flavor of OP0 and OP1. ADJ_OPERAND is already the high half of the
3453 product OP0 x OP1. If UNSIGNEDP is nonzero, adjust the signed product
3454 to become unsigned, if UNSIGNEDP is zero, adjust the unsigned product to
3457 The result is put in TARGET if that is convenient.
3459 MODE is the mode of operation. */
3462 expand_mult_highpart_adjust (machine_mode mode
, rtx adj_operand
, rtx op0
,
3463 rtx op1
, rtx target
, int unsignedp
)
3466 enum rtx_code adj_code
= unsignedp
? PLUS
: MINUS
;
3468 tem
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
3469 GET_MODE_BITSIZE (mode
) - 1, NULL_RTX
, 0);
3470 tem
= expand_and (mode
, tem
, op1
, NULL_RTX
);
3472 = force_operand (gen_rtx_fmt_ee (adj_code
, mode
, adj_operand
, tem
),
3475 tem
= expand_shift (RSHIFT_EXPR
, mode
, op1
,
3476 GET_MODE_BITSIZE (mode
) - 1, NULL_RTX
, 0);
3477 tem
= expand_and (mode
, tem
, op0
, NULL_RTX
);
3478 target
= force_operand (gen_rtx_fmt_ee (adj_code
, mode
, adj_operand
, tem
),
3484 /* Subroutine of expmed_mult_highpart. Return the MODE high part of OP. */
3487 extract_high_half (machine_mode mode
, rtx op
)
3489 machine_mode wider_mode
;
3491 if (mode
== word_mode
)
3492 return gen_highpart (mode
, op
);
3494 gcc_assert (!SCALAR_FLOAT_MODE_P (mode
));
3496 wider_mode
= GET_MODE_WIDER_MODE (mode
);
3497 op
= expand_shift (RSHIFT_EXPR
, wider_mode
, op
,
3498 GET_MODE_BITSIZE (mode
), 0, 1);
3499 return convert_modes (mode
, wider_mode
, op
, 0);
3502 /* Like expmed_mult_highpart, but only consider using a multiplication
3503 optab. OP1 is an rtx for the constant operand. */
3506 expmed_mult_highpart_optab (machine_mode mode
, rtx op0
, rtx op1
,
3507 rtx target
, int unsignedp
, int max_cost
)
3509 rtx narrow_op1
= gen_int_mode (INTVAL (op1
), mode
);
3510 machine_mode wider_mode
;
3514 bool speed
= optimize_insn_for_speed_p ();
3516 gcc_assert (!SCALAR_FLOAT_MODE_P (mode
));
3518 wider_mode
= GET_MODE_WIDER_MODE (mode
);
3519 size
= GET_MODE_BITSIZE (mode
);
3521 /* Firstly, try using a multiplication insn that only generates the needed
3522 high part of the product, and in the sign flavor of unsignedp. */
3523 if (mul_highpart_cost (speed
, mode
) < max_cost
)
3525 moptab
= unsignedp
? umul_highpart_optab
: smul_highpart_optab
;
3526 tem
= expand_binop (mode
, moptab
, op0
, narrow_op1
, target
,
3527 unsignedp
, OPTAB_DIRECT
);
3532 /* Secondly, same as above, but use sign flavor opposite of unsignedp.
3533 Need to adjust the result after the multiplication. */
3534 if (size
- 1 < BITS_PER_WORD
3535 && (mul_highpart_cost (speed
, mode
)
3536 + 2 * shift_cost (speed
, mode
, size
-1)
3537 + 4 * add_cost (speed
, mode
) < max_cost
))
3539 moptab
= unsignedp
? smul_highpart_optab
: umul_highpart_optab
;
3540 tem
= expand_binop (mode
, moptab
, op0
, narrow_op1
, target
,
3541 unsignedp
, OPTAB_DIRECT
);
3543 /* We used the wrong signedness. Adjust the result. */
3544 return expand_mult_highpart_adjust (mode
, tem
, op0
, narrow_op1
,
3548 /* Try widening multiplication. */
3549 moptab
= unsignedp
? umul_widen_optab
: smul_widen_optab
;
3550 if (widening_optab_handler (moptab
, wider_mode
, mode
) != CODE_FOR_nothing
3551 && mul_widen_cost (speed
, wider_mode
) < max_cost
)
3553 tem
= expand_binop (wider_mode
, moptab
, op0
, narrow_op1
, 0,
3554 unsignedp
, OPTAB_WIDEN
);
3556 return extract_high_half (mode
, tem
);
3559 /* Try widening the mode and perform a non-widening multiplication. */
3560 if (optab_handler (smul_optab
, wider_mode
) != CODE_FOR_nothing
3561 && size
- 1 < BITS_PER_WORD
3562 && (mul_cost (speed
, wider_mode
) + shift_cost (speed
, mode
, size
-1)
3568 /* We need to widen the operands, for example to ensure the
3569 constant multiplier is correctly sign or zero extended.
3570 Use a sequence to clean-up any instructions emitted by
3571 the conversions if things don't work out. */
3573 wop0
= convert_modes (wider_mode
, mode
, op0
, unsignedp
);
3574 wop1
= convert_modes (wider_mode
, mode
, op1
, unsignedp
);
3575 tem
= expand_binop (wider_mode
, smul_optab
, wop0
, wop1
, 0,
3576 unsignedp
, OPTAB_WIDEN
);
3577 insns
= get_insns ();
3583 return extract_high_half (mode
, tem
);
3587 /* Try widening multiplication of opposite signedness, and adjust. */
3588 moptab
= unsignedp
? smul_widen_optab
: umul_widen_optab
;
3589 if (widening_optab_handler (moptab
, wider_mode
, mode
) != CODE_FOR_nothing
3590 && size
- 1 < BITS_PER_WORD
3591 && (mul_widen_cost (speed
, wider_mode
)
3592 + 2 * shift_cost (speed
, mode
, size
-1)
3593 + 4 * add_cost (speed
, mode
) < max_cost
))
3595 tem
= expand_binop (wider_mode
, moptab
, op0
, narrow_op1
,
3596 NULL_RTX
, ! unsignedp
, OPTAB_WIDEN
);
3599 tem
= extract_high_half (mode
, tem
);
3600 /* We used the wrong signedness. Adjust the result. */
3601 return expand_mult_highpart_adjust (mode
, tem
, op0
, narrow_op1
,
3609 /* Emit code to multiply OP0 and OP1 (where OP1 is an integer constant),
3610 putting the high half of the result in TARGET if that is convenient,
3611 and return where the result is. If the operation can not be performed,
3614 MODE is the mode of operation and result.
3616 UNSIGNEDP nonzero means unsigned multiply.
3618 MAX_COST is the total allowed cost for the expanded RTL. */
3621 expmed_mult_highpart (machine_mode mode
, rtx op0
, rtx op1
,
3622 rtx target
, int unsignedp
, int max_cost
)
3624 machine_mode wider_mode
= GET_MODE_WIDER_MODE (mode
);
3625 unsigned HOST_WIDE_INT cnst1
;
3627 bool sign_adjust
= false;
3628 enum mult_variant variant
;
3629 struct algorithm alg
;
3631 bool speed
= optimize_insn_for_speed_p ();
3633 gcc_assert (!SCALAR_FLOAT_MODE_P (mode
));
3634 /* We can't support modes wider than HOST_BITS_PER_INT. */
3635 gcc_assert (HWI_COMPUTABLE_MODE_P (mode
));
3637 cnst1
= INTVAL (op1
) & GET_MODE_MASK (mode
);
3639 /* We can't optimize modes wider than BITS_PER_WORD.
3640 ??? We might be able to perform double-word arithmetic if
3641 mode == word_mode, however all the cost calculations in
3642 synth_mult etc. assume single-word operations. */
3643 if (GET_MODE_BITSIZE (wider_mode
) > BITS_PER_WORD
)
3644 return expmed_mult_highpart_optab (mode
, op0
, op1
, target
,
3645 unsignedp
, max_cost
);
3647 extra_cost
= shift_cost (speed
, mode
, GET_MODE_BITSIZE (mode
) - 1);
3649 /* Check whether we try to multiply by a negative constant. */
3650 if (!unsignedp
&& ((cnst1
>> (GET_MODE_BITSIZE (mode
) - 1)) & 1))
3653 extra_cost
+= add_cost (speed
, mode
);
3656 /* See whether shift/add multiplication is cheap enough. */
3657 if (choose_mult_variant (wider_mode
, cnst1
, &alg
, &variant
,
3658 max_cost
- extra_cost
))
3660 /* See whether the specialized multiplication optabs are
3661 cheaper than the shift/add version. */
3662 tem
= expmed_mult_highpart_optab (mode
, op0
, op1
, target
, unsignedp
,
3663 alg
.cost
.cost
+ extra_cost
);
3667 tem
= convert_to_mode (wider_mode
, op0
, unsignedp
);
3668 tem
= expand_mult_const (wider_mode
, tem
, cnst1
, 0, &alg
, variant
);
3669 tem
= extract_high_half (mode
, tem
);
3671 /* Adjust result for signedness. */
3673 tem
= force_operand (gen_rtx_MINUS (mode
, tem
, op0
), tem
);
3677 return expmed_mult_highpart_optab (mode
, op0
, op1
, target
,
3678 unsignedp
, max_cost
);
3682 /* Expand signed modulus of OP0 by a power of two D in mode MODE. */
3685 expand_smod_pow2 (machine_mode mode
, rtx op0
, HOST_WIDE_INT d
)
3687 rtx result
, temp
, shift
;
3688 rtx_code_label
*label
;
3690 int prec
= GET_MODE_PRECISION (mode
);
3692 logd
= floor_log2 (d
);
3693 result
= gen_reg_rtx (mode
);
3695 /* Avoid conditional branches when they're expensive. */
3696 if (BRANCH_COST (optimize_insn_for_speed_p (), false) >= 2
3697 && optimize_insn_for_speed_p ())
3699 rtx signmask
= emit_store_flag (result
, LT
, op0
, const0_rtx
,
3703 HOST_WIDE_INT masklow
= ((HOST_WIDE_INT
) 1 << logd
) - 1;
3704 signmask
= force_reg (mode
, signmask
);
3705 shift
= GEN_INT (GET_MODE_BITSIZE (mode
) - logd
);
3707 /* Use the rtx_cost of a LSHIFTRT instruction to determine
3708 which instruction sequence to use. If logical right shifts
3709 are expensive the use 2 XORs, 2 SUBs and an AND, otherwise
3710 use a LSHIFTRT, 1 ADD, 1 SUB and an AND. */
3712 temp
= gen_rtx_LSHIFTRT (mode
, result
, shift
);
3713 if (optab_handler (lshr_optab
, mode
) == CODE_FOR_nothing
3714 || (set_src_cost (temp
, optimize_insn_for_speed_p ())
3715 > COSTS_N_INSNS (2)))
3717 temp
= expand_binop (mode
, xor_optab
, op0
, signmask
,
3718 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3719 temp
= expand_binop (mode
, sub_optab
, temp
, signmask
,
3720 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3721 temp
= expand_binop (mode
, and_optab
, temp
,
3722 gen_int_mode (masklow
, mode
),
3723 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3724 temp
= expand_binop (mode
, xor_optab
, temp
, signmask
,
3725 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3726 temp
= expand_binop (mode
, sub_optab
, temp
, signmask
,
3727 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3731 signmask
= expand_binop (mode
, lshr_optab
, signmask
, shift
,
3732 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3733 signmask
= force_reg (mode
, signmask
);
3735 temp
= expand_binop (mode
, add_optab
, op0
, signmask
,
3736 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3737 temp
= expand_binop (mode
, and_optab
, temp
,
3738 gen_int_mode (masklow
, mode
),
3739 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3740 temp
= expand_binop (mode
, sub_optab
, temp
, signmask
,
3741 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3747 /* Mask contains the mode's signbit and the significant bits of the
3748 modulus. By including the signbit in the operation, many targets
3749 can avoid an explicit compare operation in the following comparison
3751 wide_int mask
= wi::mask (logd
, false, prec
);
3752 mask
= wi::set_bit (mask
, prec
- 1);
3754 temp
= expand_binop (mode
, and_optab
, op0
,
3755 immed_wide_int_const (mask
, mode
),
3756 result
, 1, OPTAB_LIB_WIDEN
);
3758 emit_move_insn (result
, temp
);
3760 label
= gen_label_rtx ();
3761 do_cmp_and_jump (result
, const0_rtx
, GE
, mode
, label
);
3763 temp
= expand_binop (mode
, sub_optab
, result
, const1_rtx
, result
,
3764 0, OPTAB_LIB_WIDEN
);
3766 mask
= wi::mask (logd
, true, prec
);
3767 temp
= expand_binop (mode
, ior_optab
, temp
,
3768 immed_wide_int_const (mask
, mode
),
3769 result
, 1, OPTAB_LIB_WIDEN
);
3770 temp
= expand_binop (mode
, add_optab
, temp
, const1_rtx
, result
,
3771 0, OPTAB_LIB_WIDEN
);
3773 emit_move_insn (result
, temp
);
3778 /* Expand signed division of OP0 by a power of two D in mode MODE.
3779 This routine is only called for positive values of D. */
3782 expand_sdiv_pow2 (machine_mode mode
, rtx op0
, HOST_WIDE_INT d
)
3785 rtx_code_label
*label
;
3788 logd
= floor_log2 (d
);
3791 && BRANCH_COST (optimize_insn_for_speed_p (),
3794 temp
= gen_reg_rtx (mode
);
3795 temp
= emit_store_flag (temp
, LT
, op0
, const0_rtx
, mode
, 0, 1);
3796 temp
= expand_binop (mode
, add_optab
, temp
, op0
, NULL_RTX
,
3797 0, OPTAB_LIB_WIDEN
);
3798 return expand_shift (RSHIFT_EXPR
, mode
, temp
, logd
, NULL_RTX
, 0);
3801 #ifdef HAVE_conditional_move
3802 if (BRANCH_COST (optimize_insn_for_speed_p (), false)
3808 temp2
= copy_to_mode_reg (mode
, op0
);
3809 temp
= expand_binop (mode
, add_optab
, temp2
, gen_int_mode (d
- 1, mode
),
3810 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
3811 temp
= force_reg (mode
, temp
);
3813 /* Construct "temp2 = (temp2 < 0) ? temp : temp2". */
3814 temp2
= emit_conditional_move (temp2
, LT
, temp2
, const0_rtx
,
3815 mode
, temp
, temp2
, mode
, 0);
3818 rtx_insn
*seq
= get_insns ();
3821 return expand_shift (RSHIFT_EXPR
, mode
, temp2
, logd
, NULL_RTX
, 0);
3827 if (BRANCH_COST (optimize_insn_for_speed_p (),
3830 int ushift
= GET_MODE_BITSIZE (mode
) - logd
;
3832 temp
= gen_reg_rtx (mode
);
3833 temp
= emit_store_flag (temp
, LT
, op0
, const0_rtx
, mode
, 0, -1);
3834 if (GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
3835 || shift_cost (optimize_insn_for_speed_p (), mode
, ushift
)
3836 > COSTS_N_INSNS (1))
3837 temp
= expand_binop (mode
, and_optab
, temp
, gen_int_mode (d
- 1, mode
),
3838 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
3840 temp
= expand_shift (RSHIFT_EXPR
, mode
, temp
,
3841 ushift
, NULL_RTX
, 1);
3842 temp
= expand_binop (mode
, add_optab
, temp
, op0
, NULL_RTX
,
3843 0, OPTAB_LIB_WIDEN
);
3844 return expand_shift (RSHIFT_EXPR
, mode
, temp
, logd
, NULL_RTX
, 0);
3847 label
= gen_label_rtx ();
3848 temp
= copy_to_mode_reg (mode
, op0
);
3849 do_cmp_and_jump (temp
, const0_rtx
, GE
, mode
, label
);
3850 expand_inc (temp
, gen_int_mode (d
- 1, mode
));
3852 return expand_shift (RSHIFT_EXPR
, mode
, temp
, logd
, NULL_RTX
, 0);
3855 /* Emit the code to divide OP0 by OP1, putting the result in TARGET
3856 if that is convenient, and returning where the result is.
3857 You may request either the quotient or the remainder as the result;
3858 specify REM_FLAG nonzero to get the remainder.
3860 CODE is the expression code for which kind of division this is;
3861 it controls how rounding is done. MODE is the machine mode to use.
3862 UNSIGNEDP nonzero means do unsigned division. */
3864 /* ??? For CEIL_MOD_EXPR, can compute incorrect remainder with ANDI
3865 and then correct it by or'ing in missing high bits
3866 if result of ANDI is nonzero.
3867 For ROUND_MOD_EXPR, can use ANDI and then sign-extend the result.
3868 This could optimize to a bfexts instruction.
3869 But C doesn't use these operations, so their optimizations are
3871 /* ??? For modulo, we don't actually need the highpart of the first product,
3872 the low part will do nicely. And for small divisors, the second multiply
3873 can also be a low-part only multiply or even be completely left out.
3874 E.g. to calculate the remainder of a division by 3 with a 32 bit
3875 multiply, multiply with 0x55555556 and extract the upper two bits;
3876 the result is exact for inputs up to 0x1fffffff.
3877 The input range can be reduced by using cross-sum rules.
3878 For odd divisors >= 3, the following table gives right shift counts
3879 so that if a number is shifted by an integer multiple of the given
3880 amount, the remainder stays the same:
3881 2, 4, 3, 6, 10, 12, 4, 8, 18, 6, 11, 20, 18, 0, 5, 10, 12, 0, 12, 20,
3882 14, 12, 23, 21, 8, 0, 20, 18, 0, 0, 6, 12, 0, 22, 0, 18, 20, 30, 0, 0,
3883 0, 8, 0, 11, 12, 10, 36, 0, 30, 0, 0, 12, 0, 0, 0, 0, 44, 12, 24, 0,
3884 20, 0, 7, 14, 0, 18, 36, 0, 0, 46, 60, 0, 42, 0, 15, 24, 20, 0, 0, 33,
3885 0, 20, 0, 0, 18, 0, 60, 0, 0, 0, 0, 0, 40, 18, 0, 0, 12
3887 Cross-sum rules for even numbers can be derived by leaving as many bits
3888 to the right alone as the divisor has zeros to the right.
3889 E.g. if x is an unsigned 32 bit number:
3890 (x mod 12) == (((x & 1023) + ((x >> 8) & ~3)) * 0x15555558 >> 2 * 3) >> 28
3894 expand_divmod (int rem_flag
, enum tree_code code
, machine_mode mode
,
3895 rtx op0
, rtx op1
, rtx target
, int unsignedp
)
3897 machine_mode compute_mode
;
3899 rtx quotient
= 0, remainder
= 0;
3903 optab optab1
, optab2
;
3904 int op1_is_constant
, op1_is_pow2
= 0;
3905 int max_cost
, extra_cost
;
3906 static HOST_WIDE_INT last_div_const
= 0;
3907 bool speed
= optimize_insn_for_speed_p ();
3909 op1_is_constant
= CONST_INT_P (op1
);
3910 if (op1_is_constant
)
3912 unsigned HOST_WIDE_INT ext_op1
= UINTVAL (op1
);
3914 ext_op1
&= GET_MODE_MASK (mode
);
3915 op1_is_pow2
= ((EXACT_POWER_OF_2_OR_ZERO_P (ext_op1
)
3916 || (! unsignedp
&& EXACT_POWER_OF_2_OR_ZERO_P (-ext_op1
))));
3920 This is the structure of expand_divmod:
3922 First comes code to fix up the operands so we can perform the operations
3923 correctly and efficiently.
3925 Second comes a switch statement with code specific for each rounding mode.
3926 For some special operands this code emits all RTL for the desired
3927 operation, for other cases, it generates only a quotient and stores it in
3928 QUOTIENT. The case for trunc division/remainder might leave quotient = 0,
3929 to indicate that it has not done anything.
3931 Last comes code that finishes the operation. If QUOTIENT is set and
3932 REM_FLAG is set, the remainder is computed as OP0 - QUOTIENT * OP1. If
3933 QUOTIENT is not set, it is computed using trunc rounding.
3935 We try to generate special code for division and remainder when OP1 is a
3936 constant. If |OP1| = 2**n we can use shifts and some other fast
3937 operations. For other values of OP1, we compute a carefully selected
3938 fixed-point approximation m = 1/OP1, and generate code that multiplies OP0
3941 In all cases but EXACT_DIV_EXPR, this multiplication requires the upper
3942 half of the product. Different strategies for generating the product are
3943 implemented in expmed_mult_highpart.
3945 If what we actually want is the remainder, we generate that by another
3946 by-constant multiplication and a subtraction. */
3948 /* We shouldn't be called with OP1 == const1_rtx, but some of the
3949 code below will malfunction if we are, so check here and handle
3950 the special case if so. */
3951 if (op1
== const1_rtx
)
3952 return rem_flag
? const0_rtx
: op0
;
3954 /* When dividing by -1, we could get an overflow.
3955 negv_optab can handle overflows. */
3956 if (! unsignedp
&& op1
== constm1_rtx
)
3960 return expand_unop (mode
, flag_trapv
&& GET_MODE_CLASS (mode
) == MODE_INT
3961 ? negv_optab
: neg_optab
, op0
, target
, 0);
3965 /* Don't use the function value register as a target
3966 since we have to read it as well as write it,
3967 and function-inlining gets confused by this. */
3968 && ((REG_P (target
) && REG_FUNCTION_VALUE_P (target
))
3969 /* Don't clobber an operand while doing a multi-step calculation. */
3970 || ((rem_flag
|| op1_is_constant
)
3971 && (reg_mentioned_p (target
, op0
)
3972 || (MEM_P (op0
) && MEM_P (target
))))
3973 || reg_mentioned_p (target
, op1
)
3974 || (MEM_P (op1
) && MEM_P (target
))))
3977 /* Get the mode in which to perform this computation. Normally it will
3978 be MODE, but sometimes we can't do the desired operation in MODE.
3979 If so, pick a wider mode in which we can do the operation. Convert
3980 to that mode at the start to avoid repeated conversions.
3982 First see what operations we need. These depend on the expression
3983 we are evaluating. (We assume that divxx3 insns exist under the
3984 same conditions that modxx3 insns and that these insns don't normally
3985 fail. If these assumptions are not correct, we may generate less
3986 efficient code in some cases.)
3988 Then see if we find a mode in which we can open-code that operation
3989 (either a division, modulus, or shift). Finally, check for the smallest
3990 mode for which we can do the operation with a library call. */
3992 /* We might want to refine this now that we have division-by-constant
3993 optimization. Since expmed_mult_highpart tries so many variants, it is
3994 not straightforward to generalize this. Maybe we should make an array
3995 of possible modes in init_expmed? Save this for GCC 2.7. */
3997 optab1
= ((op1_is_pow2
&& op1
!= const0_rtx
)
3998 ? (unsignedp
? lshr_optab
: ashr_optab
)
3999 : (unsignedp
? udiv_optab
: sdiv_optab
));
4000 optab2
= ((op1_is_pow2
&& op1
!= const0_rtx
)
4002 : (unsignedp
? udivmod_optab
: sdivmod_optab
));
4004 for (compute_mode
= mode
; compute_mode
!= VOIDmode
;
4005 compute_mode
= GET_MODE_WIDER_MODE (compute_mode
))
4006 if (optab_handler (optab1
, compute_mode
) != CODE_FOR_nothing
4007 || optab_handler (optab2
, compute_mode
) != CODE_FOR_nothing
)
4010 if (compute_mode
== VOIDmode
)
4011 for (compute_mode
= mode
; compute_mode
!= VOIDmode
;
4012 compute_mode
= GET_MODE_WIDER_MODE (compute_mode
))
4013 if (optab_libfunc (optab1
, compute_mode
)
4014 || optab_libfunc (optab2
, compute_mode
))
4017 /* If we still couldn't find a mode, use MODE, but expand_binop will
4019 if (compute_mode
== VOIDmode
)
4020 compute_mode
= mode
;
4022 if (target
&& GET_MODE (target
) == compute_mode
)
4025 tquotient
= gen_reg_rtx (compute_mode
);
4027 size
= GET_MODE_BITSIZE (compute_mode
);
4029 /* It should be possible to restrict the precision to GET_MODE_BITSIZE
4030 (mode), and thereby get better code when OP1 is a constant. Do that
4031 later. It will require going over all usages of SIZE below. */
4032 size
= GET_MODE_BITSIZE (mode
);
4035 /* Only deduct something for a REM if the last divide done was
4036 for a different constant. Then set the constant of the last
4038 max_cost
= (unsignedp
4039 ? udiv_cost (speed
, compute_mode
)
4040 : sdiv_cost (speed
, compute_mode
));
4041 if (rem_flag
&& ! (last_div_const
!= 0 && op1_is_constant
4042 && INTVAL (op1
) == last_div_const
))
4043 max_cost
-= (mul_cost (speed
, compute_mode
)
4044 + add_cost (speed
, compute_mode
));
4046 last_div_const
= ! rem_flag
&& op1_is_constant
? INTVAL (op1
) : 0;
4048 /* Now convert to the best mode to use. */
4049 if (compute_mode
!= mode
)
4051 op0
= convert_modes (compute_mode
, mode
, op0
, unsignedp
);
4052 op1
= convert_modes (compute_mode
, mode
, op1
, unsignedp
);
4054 /* convert_modes may have placed op1 into a register, so we
4055 must recompute the following. */
4056 op1_is_constant
= CONST_INT_P (op1
);
4057 op1_is_pow2
= (op1_is_constant
4058 && ((EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1
))
4060 && EXACT_POWER_OF_2_OR_ZERO_P (-UINTVAL (op1
))))));
4063 /* If one of the operands is a volatile MEM, copy it into a register. */
4065 if (MEM_P (op0
) && MEM_VOLATILE_P (op0
))
4066 op0
= force_reg (compute_mode
, op0
);
4067 if (MEM_P (op1
) && MEM_VOLATILE_P (op1
))
4068 op1
= force_reg (compute_mode
, op1
);
4070 /* If we need the remainder or if OP1 is constant, we need to
4071 put OP0 in a register in case it has any queued subexpressions. */
4072 if (rem_flag
|| op1_is_constant
)
4073 op0
= force_reg (compute_mode
, op0
);
4075 last
= get_last_insn ();
4077 /* Promote floor rounding to trunc rounding for unsigned operations. */
4080 if (code
== FLOOR_DIV_EXPR
)
4081 code
= TRUNC_DIV_EXPR
;
4082 if (code
== FLOOR_MOD_EXPR
)
4083 code
= TRUNC_MOD_EXPR
;
4084 if (code
== EXACT_DIV_EXPR
&& op1_is_pow2
)
4085 code
= TRUNC_DIV_EXPR
;
4088 if (op1
!= const0_rtx
)
4091 case TRUNC_MOD_EXPR
:
4092 case TRUNC_DIV_EXPR
:
4093 if (op1_is_constant
)
4097 unsigned HOST_WIDE_INT mh
, ml
;
4098 int pre_shift
, post_shift
;
4100 unsigned HOST_WIDE_INT d
= (INTVAL (op1
)
4101 & GET_MODE_MASK (compute_mode
));
4103 if (EXACT_POWER_OF_2_OR_ZERO_P (d
))
4105 pre_shift
= floor_log2 (d
);
4108 unsigned HOST_WIDE_INT mask
4109 = ((unsigned HOST_WIDE_INT
) 1 << pre_shift
) - 1;
4111 = expand_binop (compute_mode
, and_optab
, op0
,
4112 gen_int_mode (mask
, compute_mode
),
4116 return gen_lowpart (mode
, remainder
);
4118 quotient
= expand_shift (RSHIFT_EXPR
, compute_mode
, op0
,
4119 pre_shift
, tquotient
, 1);
4121 else if (size
<= HOST_BITS_PER_WIDE_INT
)
4123 if (d
>= ((unsigned HOST_WIDE_INT
) 1 << (size
- 1)))
4125 /* Most significant bit of divisor is set; emit an scc
4127 quotient
= emit_store_flag_force (tquotient
, GEU
, op0
, op1
,
4128 compute_mode
, 1, 1);
4132 /* Find a suitable multiplier and right shift count
4133 instead of multiplying with D. */
4135 mh
= choose_multiplier (d
, size
, size
,
4136 &ml
, &post_shift
, &dummy
);
4138 /* If the suggested multiplier is more than SIZE bits,
4139 we can do better for even divisors, using an
4140 initial right shift. */
4141 if (mh
!= 0 && (d
& 1) == 0)
4143 pre_shift
= floor_log2 (d
& -d
);
4144 mh
= choose_multiplier (d
>> pre_shift
, size
,
4146 &ml
, &post_shift
, &dummy
);
4156 if (post_shift
- 1 >= BITS_PER_WORD
)
4160 = (shift_cost (speed
, compute_mode
, post_shift
- 1)
4161 + shift_cost (speed
, compute_mode
, 1)
4162 + 2 * add_cost (speed
, compute_mode
));
4163 t1
= expmed_mult_highpart
4165 gen_int_mode (ml
, compute_mode
),
4166 NULL_RTX
, 1, max_cost
- extra_cost
);
4169 t2
= force_operand (gen_rtx_MINUS (compute_mode
,
4172 t3
= expand_shift (RSHIFT_EXPR
, compute_mode
,
4173 t2
, 1, NULL_RTX
, 1);
4174 t4
= force_operand (gen_rtx_PLUS (compute_mode
,
4177 quotient
= expand_shift
4178 (RSHIFT_EXPR
, compute_mode
, t4
,
4179 post_shift
- 1, tquotient
, 1);
4185 if (pre_shift
>= BITS_PER_WORD
4186 || post_shift
>= BITS_PER_WORD
)
4190 (RSHIFT_EXPR
, compute_mode
, op0
,
4191 pre_shift
, NULL_RTX
, 1);
4193 = (shift_cost (speed
, compute_mode
, pre_shift
)
4194 + shift_cost (speed
, compute_mode
, post_shift
));
4195 t2
= expmed_mult_highpart
4197 gen_int_mode (ml
, compute_mode
),
4198 NULL_RTX
, 1, max_cost
- extra_cost
);
4201 quotient
= expand_shift
4202 (RSHIFT_EXPR
, compute_mode
, t2
,
4203 post_shift
, tquotient
, 1);
4207 else /* Too wide mode to use tricky code */
4210 insn
= get_last_insn ();
4212 set_dst_reg_note (insn
, REG_EQUAL
,
4213 gen_rtx_UDIV (compute_mode
, op0
, op1
),
4216 else /* TRUNC_DIV, signed */
4218 unsigned HOST_WIDE_INT ml
;
4219 int lgup
, post_shift
;
4221 HOST_WIDE_INT d
= INTVAL (op1
);
4222 unsigned HOST_WIDE_INT abs_d
;
4224 /* Since d might be INT_MIN, we have to cast to
4225 unsigned HOST_WIDE_INT before negating to avoid
4226 undefined signed overflow. */
4228 ? (unsigned HOST_WIDE_INT
) d
4229 : - (unsigned HOST_WIDE_INT
) d
);
4231 /* n rem d = n rem -d */
4232 if (rem_flag
&& d
< 0)
4235 op1
= gen_int_mode (abs_d
, compute_mode
);
4241 quotient
= expand_unop (compute_mode
, neg_optab
, op0
,
4243 else if (HOST_BITS_PER_WIDE_INT
>= size
4244 && abs_d
== (unsigned HOST_WIDE_INT
) 1 << (size
- 1))
4246 /* This case is not handled correctly below. */
4247 quotient
= emit_store_flag (tquotient
, EQ
, op0
, op1
,
4248 compute_mode
, 1, 1);
4252 else if (EXACT_POWER_OF_2_OR_ZERO_P (d
)
4254 ? smod_pow2_cheap (speed
, compute_mode
)
4255 : sdiv_pow2_cheap (speed
, compute_mode
))
4256 /* We assume that cheap metric is true if the
4257 optab has an expander for this mode. */
4258 && ((optab_handler ((rem_flag
? smod_optab
4261 != CODE_FOR_nothing
)
4262 || (optab_handler (sdivmod_optab
,
4264 != CODE_FOR_nothing
)))
4266 else if (EXACT_POWER_OF_2_OR_ZERO_P (abs_d
))
4270 remainder
= expand_smod_pow2 (compute_mode
, op0
, d
);
4272 return gen_lowpart (mode
, remainder
);
4275 if (sdiv_pow2_cheap (speed
, compute_mode
)
4276 && ((optab_handler (sdiv_optab
, compute_mode
)
4277 != CODE_FOR_nothing
)
4278 || (optab_handler (sdivmod_optab
, compute_mode
)
4279 != CODE_FOR_nothing
)))
4280 quotient
= expand_divmod (0, TRUNC_DIV_EXPR
,
4282 gen_int_mode (abs_d
,
4286 quotient
= expand_sdiv_pow2 (compute_mode
, op0
, abs_d
);
4288 /* We have computed OP0 / abs(OP1). If OP1 is negative,
4289 negate the quotient. */
4292 insn
= get_last_insn ();
4294 && abs_d
< ((unsigned HOST_WIDE_INT
) 1
4295 << (HOST_BITS_PER_WIDE_INT
- 1)))
4296 set_dst_reg_note (insn
, REG_EQUAL
,
4297 gen_rtx_DIV (compute_mode
, op0
,
4303 quotient
= expand_unop (compute_mode
, neg_optab
,
4304 quotient
, quotient
, 0);
4307 else if (size
<= HOST_BITS_PER_WIDE_INT
)
4309 choose_multiplier (abs_d
, size
, size
- 1,
4310 &ml
, &post_shift
, &lgup
);
4311 if (ml
< (unsigned HOST_WIDE_INT
) 1 << (size
- 1))
4315 if (post_shift
>= BITS_PER_WORD
4316 || size
- 1 >= BITS_PER_WORD
)
4319 extra_cost
= (shift_cost (speed
, compute_mode
, post_shift
)
4320 + shift_cost (speed
, compute_mode
, size
- 1)
4321 + add_cost (speed
, compute_mode
));
4322 t1
= expmed_mult_highpart
4323 (compute_mode
, op0
, gen_int_mode (ml
, compute_mode
),
4324 NULL_RTX
, 0, max_cost
- extra_cost
);
4328 (RSHIFT_EXPR
, compute_mode
, t1
,
4329 post_shift
, NULL_RTX
, 0);
4331 (RSHIFT_EXPR
, compute_mode
, op0
,
4332 size
- 1, NULL_RTX
, 0);
4335 = force_operand (gen_rtx_MINUS (compute_mode
,
4340 = force_operand (gen_rtx_MINUS (compute_mode
,
4348 if (post_shift
>= BITS_PER_WORD
4349 || size
- 1 >= BITS_PER_WORD
)
4352 ml
|= (~(unsigned HOST_WIDE_INT
) 0) << (size
- 1);
4353 mlr
= gen_int_mode (ml
, compute_mode
);
4354 extra_cost
= (shift_cost (speed
, compute_mode
, post_shift
)
4355 + shift_cost (speed
, compute_mode
, size
- 1)
4356 + 2 * add_cost (speed
, compute_mode
));
4357 t1
= expmed_mult_highpart (compute_mode
, op0
, mlr
,
4359 max_cost
- extra_cost
);
4362 t2
= force_operand (gen_rtx_PLUS (compute_mode
,
4366 (RSHIFT_EXPR
, compute_mode
, t2
,
4367 post_shift
, NULL_RTX
, 0);
4369 (RSHIFT_EXPR
, compute_mode
, op0
,
4370 size
- 1, NULL_RTX
, 0);
4373 = force_operand (gen_rtx_MINUS (compute_mode
,
4378 = force_operand (gen_rtx_MINUS (compute_mode
,
4383 else /* Too wide mode to use tricky code */
4386 insn
= get_last_insn ();
4388 set_dst_reg_note (insn
, REG_EQUAL
,
4389 gen_rtx_DIV (compute_mode
, op0
, op1
),
4395 delete_insns_since (last
);
4398 case FLOOR_DIV_EXPR
:
4399 case FLOOR_MOD_EXPR
:
4400 /* We will come here only for signed operations. */
4401 if (op1_is_constant
&& HOST_BITS_PER_WIDE_INT
>= size
)
4403 unsigned HOST_WIDE_INT mh
, ml
;
4404 int pre_shift
, lgup
, post_shift
;
4405 HOST_WIDE_INT d
= INTVAL (op1
);
4409 /* We could just as easily deal with negative constants here,
4410 but it does not seem worth the trouble for GCC 2.6. */
4411 if (EXACT_POWER_OF_2_OR_ZERO_P (d
))
4413 pre_shift
= floor_log2 (d
);
4416 unsigned HOST_WIDE_INT mask
4417 = ((unsigned HOST_WIDE_INT
) 1 << pre_shift
) - 1;
4418 remainder
= expand_binop
4419 (compute_mode
, and_optab
, op0
,
4420 gen_int_mode (mask
, compute_mode
),
4421 remainder
, 0, OPTAB_LIB_WIDEN
);
4423 return gen_lowpart (mode
, remainder
);
4425 quotient
= expand_shift
4426 (RSHIFT_EXPR
, compute_mode
, op0
,
4427 pre_shift
, tquotient
, 0);
4433 mh
= choose_multiplier (d
, size
, size
- 1,
4434 &ml
, &post_shift
, &lgup
);
4437 if (post_shift
< BITS_PER_WORD
4438 && size
- 1 < BITS_PER_WORD
)
4441 (RSHIFT_EXPR
, compute_mode
, op0
,
4442 size
- 1, NULL_RTX
, 0);
4443 t2
= expand_binop (compute_mode
, xor_optab
, op0
, t1
,
4444 NULL_RTX
, 0, OPTAB_WIDEN
);
4445 extra_cost
= (shift_cost (speed
, compute_mode
, post_shift
)
4446 + shift_cost (speed
, compute_mode
, size
- 1)
4447 + 2 * add_cost (speed
, compute_mode
));
4448 t3
= expmed_mult_highpart
4449 (compute_mode
, t2
, gen_int_mode (ml
, compute_mode
),
4450 NULL_RTX
, 1, max_cost
- extra_cost
);
4454 (RSHIFT_EXPR
, compute_mode
, t3
,
4455 post_shift
, NULL_RTX
, 1);
4456 quotient
= expand_binop (compute_mode
, xor_optab
,
4457 t4
, t1
, tquotient
, 0,
4465 rtx nsign
, t1
, t2
, t3
, t4
;
4466 t1
= force_operand (gen_rtx_PLUS (compute_mode
,
4467 op0
, constm1_rtx
), NULL_RTX
);
4468 t2
= expand_binop (compute_mode
, ior_optab
, op0
, t1
, NULL_RTX
,
4470 nsign
= expand_shift
4471 (RSHIFT_EXPR
, compute_mode
, t2
,
4472 size
- 1, NULL_RTX
, 0);
4473 t3
= force_operand (gen_rtx_MINUS (compute_mode
, t1
, nsign
),
4475 t4
= expand_divmod (0, TRUNC_DIV_EXPR
, compute_mode
, t3
, op1
,
4480 t5
= expand_unop (compute_mode
, one_cmpl_optab
, nsign
,
4482 quotient
= force_operand (gen_rtx_PLUS (compute_mode
,
4491 delete_insns_since (last
);
4493 /* Try using an instruction that produces both the quotient and
4494 remainder, using truncation. We can easily compensate the quotient
4495 or remainder to get floor rounding, once we have the remainder.
4496 Notice that we compute also the final remainder value here,
4497 and return the result right away. */
4498 if (target
== 0 || GET_MODE (target
) != compute_mode
)
4499 target
= gen_reg_rtx (compute_mode
);
4504 = REG_P (target
) ? target
: gen_reg_rtx (compute_mode
);
4505 quotient
= gen_reg_rtx (compute_mode
);
4510 = REG_P (target
) ? target
: gen_reg_rtx (compute_mode
);
4511 remainder
= gen_reg_rtx (compute_mode
);
4514 if (expand_twoval_binop (sdivmod_optab
, op0
, op1
,
4515 quotient
, remainder
, 0))
4517 /* This could be computed with a branch-less sequence.
4518 Save that for later. */
4520 rtx_code_label
*label
= gen_label_rtx ();
4521 do_cmp_and_jump (remainder
, const0_rtx
, EQ
, compute_mode
, label
);
4522 tem
= expand_binop (compute_mode
, xor_optab
, op0
, op1
,
4523 NULL_RTX
, 0, OPTAB_WIDEN
);
4524 do_cmp_and_jump (tem
, const0_rtx
, GE
, compute_mode
, label
);
4525 expand_dec (quotient
, const1_rtx
);
4526 expand_inc (remainder
, op1
);
4528 return gen_lowpart (mode
, rem_flag
? remainder
: quotient
);
4531 /* No luck with division elimination or divmod. Have to do it
4532 by conditionally adjusting op0 *and* the result. */
4534 rtx_code_label
*label1
, *label2
, *label3
, *label4
, *label5
;
4538 quotient
= gen_reg_rtx (compute_mode
);
4539 adjusted_op0
= copy_to_mode_reg (compute_mode
, op0
);
4540 label1
= gen_label_rtx ();
4541 label2
= gen_label_rtx ();
4542 label3
= gen_label_rtx ();
4543 label4
= gen_label_rtx ();
4544 label5
= gen_label_rtx ();
4545 do_cmp_and_jump (op1
, const0_rtx
, LT
, compute_mode
, label2
);
4546 do_cmp_and_jump (adjusted_op0
, const0_rtx
, LT
, compute_mode
, label1
);
4547 tem
= expand_binop (compute_mode
, sdiv_optab
, adjusted_op0
, op1
,
4548 quotient
, 0, OPTAB_LIB_WIDEN
);
4549 if (tem
!= quotient
)
4550 emit_move_insn (quotient
, tem
);
4551 emit_jump_insn (gen_jump (label5
));
4553 emit_label (label1
);
4554 expand_inc (adjusted_op0
, const1_rtx
);
4555 emit_jump_insn (gen_jump (label4
));
4557 emit_label (label2
);
4558 do_cmp_and_jump (adjusted_op0
, const0_rtx
, GT
, compute_mode
, label3
);
4559 tem
= expand_binop (compute_mode
, sdiv_optab
, adjusted_op0
, op1
,
4560 quotient
, 0, OPTAB_LIB_WIDEN
);
4561 if (tem
!= quotient
)
4562 emit_move_insn (quotient
, tem
);
4563 emit_jump_insn (gen_jump (label5
));
4565 emit_label (label3
);
4566 expand_dec (adjusted_op0
, const1_rtx
);
4567 emit_label (label4
);
4568 tem
= expand_binop (compute_mode
, sdiv_optab
, adjusted_op0
, op1
,
4569 quotient
, 0, OPTAB_LIB_WIDEN
);
4570 if (tem
!= quotient
)
4571 emit_move_insn (quotient
, tem
);
4572 expand_dec (quotient
, const1_rtx
);
4573 emit_label (label5
);
4581 if (op1_is_constant
&& EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1
)))
4584 unsigned HOST_WIDE_INT d
= INTVAL (op1
);
4585 t1
= expand_shift (RSHIFT_EXPR
, compute_mode
, op0
,
4586 floor_log2 (d
), tquotient
, 1);
4587 t2
= expand_binop (compute_mode
, and_optab
, op0
,
4588 gen_int_mode (d
- 1, compute_mode
),
4589 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
4590 t3
= gen_reg_rtx (compute_mode
);
4591 t3
= emit_store_flag (t3
, NE
, t2
, const0_rtx
,
4592 compute_mode
, 1, 1);
4595 rtx_code_label
*lab
;
4596 lab
= gen_label_rtx ();
4597 do_cmp_and_jump (t2
, const0_rtx
, EQ
, compute_mode
, lab
);
4598 expand_inc (t1
, const1_rtx
);
4603 quotient
= force_operand (gen_rtx_PLUS (compute_mode
,
4609 /* Try using an instruction that produces both the quotient and
4610 remainder, using truncation. We can easily compensate the
4611 quotient or remainder to get ceiling rounding, once we have the
4612 remainder. Notice that we compute also the final remainder
4613 value here, and return the result right away. */
4614 if (target
== 0 || GET_MODE (target
) != compute_mode
)
4615 target
= gen_reg_rtx (compute_mode
);
4619 remainder
= (REG_P (target
)
4620 ? target
: gen_reg_rtx (compute_mode
));
4621 quotient
= gen_reg_rtx (compute_mode
);
4625 quotient
= (REG_P (target
)
4626 ? target
: gen_reg_rtx (compute_mode
));
4627 remainder
= gen_reg_rtx (compute_mode
);
4630 if (expand_twoval_binop (udivmod_optab
, op0
, op1
, quotient
,
4633 /* This could be computed with a branch-less sequence.
4634 Save that for later. */
4635 rtx_code_label
*label
= gen_label_rtx ();
4636 do_cmp_and_jump (remainder
, const0_rtx
, EQ
,
4637 compute_mode
, label
);
4638 expand_inc (quotient
, const1_rtx
);
4639 expand_dec (remainder
, op1
);
4641 return gen_lowpart (mode
, rem_flag
? remainder
: quotient
);
4644 /* No luck with division elimination or divmod. Have to do it
4645 by conditionally adjusting op0 *and* the result. */
4647 rtx_code_label
*label1
, *label2
;
4648 rtx adjusted_op0
, tem
;
4650 quotient
= gen_reg_rtx (compute_mode
);
4651 adjusted_op0
= copy_to_mode_reg (compute_mode
, op0
);
4652 label1
= gen_label_rtx ();
4653 label2
= gen_label_rtx ();
4654 do_cmp_and_jump (adjusted_op0
, const0_rtx
, NE
,
4655 compute_mode
, label1
);
4656 emit_move_insn (quotient
, const0_rtx
);
4657 emit_jump_insn (gen_jump (label2
));
4659 emit_label (label1
);
4660 expand_dec (adjusted_op0
, const1_rtx
);
4661 tem
= expand_binop (compute_mode
, udiv_optab
, adjusted_op0
, op1
,
4662 quotient
, 1, OPTAB_LIB_WIDEN
);
4663 if (tem
!= quotient
)
4664 emit_move_insn (quotient
, tem
);
4665 expand_inc (quotient
, const1_rtx
);
4666 emit_label (label2
);
4671 if (op1_is_constant
&& EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1
))
4672 && INTVAL (op1
) >= 0)
4674 /* This is extremely similar to the code for the unsigned case
4675 above. For 2.7 we should merge these variants, but for
4676 2.6.1 I don't want to touch the code for unsigned since that
4677 get used in C. The signed case will only be used by other
4681 unsigned HOST_WIDE_INT d
= INTVAL (op1
);
4682 t1
= expand_shift (RSHIFT_EXPR
, compute_mode
, op0
,
4683 floor_log2 (d
), tquotient
, 0);
4684 t2
= expand_binop (compute_mode
, and_optab
, op0
,
4685 gen_int_mode (d
- 1, compute_mode
),
4686 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
4687 t3
= gen_reg_rtx (compute_mode
);
4688 t3
= emit_store_flag (t3
, NE
, t2
, const0_rtx
,
4689 compute_mode
, 1, 1);
4692 rtx_code_label
*lab
;
4693 lab
= gen_label_rtx ();
4694 do_cmp_and_jump (t2
, const0_rtx
, EQ
, compute_mode
, lab
);
4695 expand_inc (t1
, const1_rtx
);
4700 quotient
= force_operand (gen_rtx_PLUS (compute_mode
,
4706 /* Try using an instruction that produces both the quotient and
4707 remainder, using truncation. We can easily compensate the
4708 quotient or remainder to get ceiling rounding, once we have the
4709 remainder. Notice that we compute also the final remainder
4710 value here, and return the result right away. */
4711 if (target
== 0 || GET_MODE (target
) != compute_mode
)
4712 target
= gen_reg_rtx (compute_mode
);
4715 remainder
= (REG_P (target
)
4716 ? target
: gen_reg_rtx (compute_mode
));
4717 quotient
= gen_reg_rtx (compute_mode
);
4721 quotient
= (REG_P (target
)
4722 ? target
: gen_reg_rtx (compute_mode
));
4723 remainder
= gen_reg_rtx (compute_mode
);
4726 if (expand_twoval_binop (sdivmod_optab
, op0
, op1
, quotient
,
4729 /* This could be computed with a branch-less sequence.
4730 Save that for later. */
4732 rtx_code_label
*label
= gen_label_rtx ();
4733 do_cmp_and_jump (remainder
, const0_rtx
, EQ
,
4734 compute_mode
, label
);
4735 tem
= expand_binop (compute_mode
, xor_optab
, op0
, op1
,
4736 NULL_RTX
, 0, OPTAB_WIDEN
);
4737 do_cmp_and_jump (tem
, const0_rtx
, LT
, compute_mode
, label
);
4738 expand_inc (quotient
, const1_rtx
);
4739 expand_dec (remainder
, op1
);
4741 return gen_lowpart (mode
, rem_flag
? remainder
: quotient
);
4744 /* No luck with division elimination or divmod. Have to do it
4745 by conditionally adjusting op0 *and* the result. */
4747 rtx_code_label
*label1
, *label2
, *label3
, *label4
, *label5
;
4751 quotient
= gen_reg_rtx (compute_mode
);
4752 adjusted_op0
= copy_to_mode_reg (compute_mode
, op0
);
4753 label1
= gen_label_rtx ();
4754 label2
= gen_label_rtx ();
4755 label3
= gen_label_rtx ();
4756 label4
= gen_label_rtx ();
4757 label5
= gen_label_rtx ();
4758 do_cmp_and_jump (op1
, const0_rtx
, LT
, compute_mode
, label2
);
4759 do_cmp_and_jump (adjusted_op0
, const0_rtx
, GT
,
4760 compute_mode
, label1
);
4761 tem
= expand_binop (compute_mode
, sdiv_optab
, adjusted_op0
, op1
,
4762 quotient
, 0, OPTAB_LIB_WIDEN
);
4763 if (tem
!= quotient
)
4764 emit_move_insn (quotient
, tem
);
4765 emit_jump_insn (gen_jump (label5
));
4767 emit_label (label1
);
4768 expand_dec (adjusted_op0
, const1_rtx
);
4769 emit_jump_insn (gen_jump (label4
));
4771 emit_label (label2
);
4772 do_cmp_and_jump (adjusted_op0
, const0_rtx
, LT
,
4773 compute_mode
, label3
);
4774 tem
= expand_binop (compute_mode
, sdiv_optab
, adjusted_op0
, op1
,
4775 quotient
, 0, OPTAB_LIB_WIDEN
);
4776 if (tem
!= quotient
)
4777 emit_move_insn (quotient
, tem
);
4778 emit_jump_insn (gen_jump (label5
));
4780 emit_label (label3
);
4781 expand_inc (adjusted_op0
, const1_rtx
);
4782 emit_label (label4
);
4783 tem
= expand_binop (compute_mode
, sdiv_optab
, adjusted_op0
, op1
,
4784 quotient
, 0, OPTAB_LIB_WIDEN
);
4785 if (tem
!= quotient
)
4786 emit_move_insn (quotient
, tem
);
4787 expand_inc (quotient
, const1_rtx
);
4788 emit_label (label5
);
4793 case EXACT_DIV_EXPR
:
4794 if (op1_is_constant
&& HOST_BITS_PER_WIDE_INT
>= size
)
4796 HOST_WIDE_INT d
= INTVAL (op1
);
4797 unsigned HOST_WIDE_INT ml
;
4801 pre_shift
= floor_log2 (d
& -d
);
4802 ml
= invert_mod2n (d
>> pre_shift
, size
);
4803 t1
= expand_shift (RSHIFT_EXPR
, compute_mode
, op0
,
4804 pre_shift
, NULL_RTX
, unsignedp
);
4805 quotient
= expand_mult (compute_mode
, t1
,
4806 gen_int_mode (ml
, compute_mode
),
4809 insn
= get_last_insn ();
4810 set_dst_reg_note (insn
, REG_EQUAL
,
4811 gen_rtx_fmt_ee (unsignedp
? UDIV
: DIV
,
4812 compute_mode
, op0
, op1
),
4817 case ROUND_DIV_EXPR
:
4818 case ROUND_MOD_EXPR
:
4822 rtx_code_label
*label
;
4823 label
= gen_label_rtx ();
4824 quotient
= gen_reg_rtx (compute_mode
);
4825 remainder
= gen_reg_rtx (compute_mode
);
4826 if (expand_twoval_binop (udivmod_optab
, op0
, op1
, quotient
, remainder
, 1) == 0)
4829 quotient
= expand_binop (compute_mode
, udiv_optab
, op0
, op1
,
4830 quotient
, 1, OPTAB_LIB_WIDEN
);
4831 tem
= expand_mult (compute_mode
, quotient
, op1
, NULL_RTX
, 1);
4832 remainder
= expand_binop (compute_mode
, sub_optab
, op0
, tem
,
4833 remainder
, 1, OPTAB_LIB_WIDEN
);
4835 tem
= plus_constant (compute_mode
, op1
, -1);
4836 tem
= expand_shift (RSHIFT_EXPR
, compute_mode
, tem
, 1, NULL_RTX
, 1);
4837 do_cmp_and_jump (remainder
, tem
, LEU
, compute_mode
, label
);
4838 expand_inc (quotient
, const1_rtx
);
4839 expand_dec (remainder
, op1
);
4844 rtx abs_rem
, abs_op1
, tem
, mask
;
4845 rtx_code_label
*label
;
4846 label
= gen_label_rtx ();
4847 quotient
= gen_reg_rtx (compute_mode
);
4848 remainder
= gen_reg_rtx (compute_mode
);
4849 if (expand_twoval_binop (sdivmod_optab
, op0
, op1
, quotient
, remainder
, 0) == 0)
4852 quotient
= expand_binop (compute_mode
, sdiv_optab
, op0
, op1
,
4853 quotient
, 0, OPTAB_LIB_WIDEN
);
4854 tem
= expand_mult (compute_mode
, quotient
, op1
, NULL_RTX
, 0);
4855 remainder
= expand_binop (compute_mode
, sub_optab
, op0
, tem
,
4856 remainder
, 0, OPTAB_LIB_WIDEN
);
4858 abs_rem
= expand_abs (compute_mode
, remainder
, NULL_RTX
, 1, 0);
4859 abs_op1
= expand_abs (compute_mode
, op1
, NULL_RTX
, 1, 0);
4860 tem
= expand_shift (LSHIFT_EXPR
, compute_mode
, abs_rem
,
4862 do_cmp_and_jump (tem
, abs_op1
, LTU
, compute_mode
, label
);
4863 tem
= expand_binop (compute_mode
, xor_optab
, op0
, op1
,
4864 NULL_RTX
, 0, OPTAB_WIDEN
);
4865 mask
= expand_shift (RSHIFT_EXPR
, compute_mode
, tem
,
4866 size
- 1, NULL_RTX
, 0);
4867 tem
= expand_binop (compute_mode
, xor_optab
, mask
, const1_rtx
,
4868 NULL_RTX
, 0, OPTAB_WIDEN
);
4869 tem
= expand_binop (compute_mode
, sub_optab
, tem
, mask
,
4870 NULL_RTX
, 0, OPTAB_WIDEN
);
4871 expand_inc (quotient
, tem
);
4872 tem
= expand_binop (compute_mode
, xor_optab
, mask
, op1
,
4873 NULL_RTX
, 0, OPTAB_WIDEN
);
4874 tem
= expand_binop (compute_mode
, sub_optab
, tem
, mask
,
4875 NULL_RTX
, 0, OPTAB_WIDEN
);
4876 expand_dec (remainder
, tem
);
4879 return gen_lowpart (mode
, rem_flag
? remainder
: quotient
);
4887 if (target
&& GET_MODE (target
) != compute_mode
)
4892 /* Try to produce the remainder without producing the quotient.
4893 If we seem to have a divmod pattern that does not require widening,
4894 don't try widening here. We should really have a WIDEN argument
4895 to expand_twoval_binop, since what we'd really like to do here is
4896 1) try a mod insn in compute_mode
4897 2) try a divmod insn in compute_mode
4898 3) try a div insn in compute_mode and multiply-subtract to get
4900 4) try the same things with widening allowed. */
4902 = sign_expand_binop (compute_mode
, umod_optab
, smod_optab
,
4905 ((optab_handler (optab2
, compute_mode
)
4906 != CODE_FOR_nothing
)
4907 ? OPTAB_DIRECT
: OPTAB_WIDEN
));
4910 /* No luck there. Can we do remainder and divide at once
4911 without a library call? */
4912 remainder
= gen_reg_rtx (compute_mode
);
4913 if (! expand_twoval_binop ((unsignedp
4917 NULL_RTX
, remainder
, unsignedp
))
4922 return gen_lowpart (mode
, remainder
);
4925 /* Produce the quotient. Try a quotient insn, but not a library call.
4926 If we have a divmod in this mode, use it in preference to widening
4927 the div (for this test we assume it will not fail). Note that optab2
4928 is set to the one of the two optabs that the call below will use. */
4930 = sign_expand_binop (compute_mode
, udiv_optab
, sdiv_optab
,
4931 op0
, op1
, rem_flag
? NULL_RTX
: target
,
4933 ((optab_handler (optab2
, compute_mode
)
4934 != CODE_FOR_nothing
)
4935 ? OPTAB_DIRECT
: OPTAB_WIDEN
));
4939 /* No luck there. Try a quotient-and-remainder insn,
4940 keeping the quotient alone. */
4941 quotient
= gen_reg_rtx (compute_mode
);
4942 if (! expand_twoval_binop (unsignedp
? udivmod_optab
: sdivmod_optab
,
4944 quotient
, NULL_RTX
, unsignedp
))
4948 /* Still no luck. If we are not computing the remainder,
4949 use a library call for the quotient. */
4950 quotient
= sign_expand_binop (compute_mode
,
4951 udiv_optab
, sdiv_optab
,
4953 unsignedp
, OPTAB_LIB_WIDEN
);
4960 if (target
&& GET_MODE (target
) != compute_mode
)
4965 /* No divide instruction either. Use library for remainder. */
4966 remainder
= sign_expand_binop (compute_mode
, umod_optab
, smod_optab
,
4968 unsignedp
, OPTAB_LIB_WIDEN
);
4969 /* No remainder function. Try a quotient-and-remainder
4970 function, keeping the remainder. */
4973 remainder
= gen_reg_rtx (compute_mode
);
4974 if (!expand_twoval_binop_libfunc
4975 (unsignedp
? udivmod_optab
: sdivmod_optab
,
4977 NULL_RTX
, remainder
,
4978 unsignedp
? UMOD
: MOD
))
4979 remainder
= NULL_RTX
;
4984 /* We divided. Now finish doing X - Y * (X / Y). */
4985 remainder
= expand_mult (compute_mode
, quotient
, op1
,
4986 NULL_RTX
, unsignedp
);
4987 remainder
= expand_binop (compute_mode
, sub_optab
, op0
,
4988 remainder
, target
, unsignedp
,
4993 return gen_lowpart (mode
, rem_flag
? remainder
: quotient
);
4996 /* Return a tree node with data type TYPE, describing the value of X.
4997 Usually this is an VAR_DECL, if there is no obvious better choice.
4998 X may be an expression, however we only support those expressions
4999 generated by loop.c. */
5002 make_tree (tree type
, rtx x
)
5006 switch (GET_CODE (x
))
5009 case CONST_WIDE_INT
:
5010 t
= wide_int_to_tree (type
, std::make_pair (x
, TYPE_MODE (type
)));
5014 STATIC_ASSERT (HOST_BITS_PER_WIDE_INT
* 2 <= MAX_BITSIZE_MODE_ANY_INT
);
5015 if (TARGET_SUPPORTS_WIDE_INT
== 0 && GET_MODE (x
) == VOIDmode
)
5016 t
= wide_int_to_tree (type
,
5017 wide_int::from_array (&CONST_DOUBLE_LOW (x
), 2,
5018 HOST_BITS_PER_WIDE_INT
* 2));
5023 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
5024 t
= build_real (type
, d
);
5031 int units
= CONST_VECTOR_NUNITS (x
);
5032 tree itype
= TREE_TYPE (type
);
5036 /* Build a tree with vector elements. */
5037 elts
= XALLOCAVEC (tree
, units
);
5038 for (i
= units
- 1; i
>= 0; --i
)
5040 rtx elt
= CONST_VECTOR_ELT (x
, i
);
5041 elts
[i
] = make_tree (itype
, elt
);
5044 return build_vector (type
, elts
);
5048 return fold_build2 (PLUS_EXPR
, type
, make_tree (type
, XEXP (x
, 0)),
5049 make_tree (type
, XEXP (x
, 1)));
5052 return fold_build2 (MINUS_EXPR
, type
, make_tree (type
, XEXP (x
, 0)),
5053 make_tree (type
, XEXP (x
, 1)));
5056 return fold_build1 (NEGATE_EXPR
, type
, make_tree (type
, XEXP (x
, 0)));
5059 return fold_build2 (MULT_EXPR
, type
, make_tree (type
, XEXP (x
, 0)),
5060 make_tree (type
, XEXP (x
, 1)));
5063 return fold_build2 (LSHIFT_EXPR
, type
, make_tree (type
, XEXP (x
, 0)),
5064 make_tree (type
, XEXP (x
, 1)));
5067 t
= unsigned_type_for (type
);
5068 return fold_convert (type
, build2 (RSHIFT_EXPR
, t
,
5069 make_tree (t
, XEXP (x
, 0)),
5070 make_tree (type
, XEXP (x
, 1))));
5073 t
= signed_type_for (type
);
5074 return fold_convert (type
, build2 (RSHIFT_EXPR
, t
,
5075 make_tree (t
, XEXP (x
, 0)),
5076 make_tree (type
, XEXP (x
, 1))));
5079 if (TREE_CODE (type
) != REAL_TYPE
)
5080 t
= signed_type_for (type
);
5084 return fold_convert (type
, build2 (TRUNC_DIV_EXPR
, t
,
5085 make_tree (t
, XEXP (x
, 0)),
5086 make_tree (t
, XEXP (x
, 1))));
5088 t
= unsigned_type_for (type
);
5089 return fold_convert (type
, build2 (TRUNC_DIV_EXPR
, t
,
5090 make_tree (t
, XEXP (x
, 0)),
5091 make_tree (t
, XEXP (x
, 1))));
5095 t
= lang_hooks
.types
.type_for_mode (GET_MODE (XEXP (x
, 0)),
5096 GET_CODE (x
) == ZERO_EXTEND
);
5097 return fold_convert (type
, make_tree (t
, XEXP (x
, 0)));
5100 return make_tree (type
, XEXP (x
, 0));
5103 t
= SYMBOL_REF_DECL (x
);
5105 return fold_convert (type
, build_fold_addr_expr (t
));
5106 /* else fall through. */
5109 t
= build_decl (RTL_LOCATION (x
), VAR_DECL
, NULL_TREE
, type
);
5111 /* If TYPE is a POINTER_TYPE, we might need to convert X from
5112 address mode to pointer mode. */
5113 if (POINTER_TYPE_P (type
))
5114 x
= convert_memory_address_addr_space
5115 (TYPE_MODE (type
), x
, TYPE_ADDR_SPACE (TREE_TYPE (type
)));
5117 /* Note that we do *not* use SET_DECL_RTL here, because we do not
5118 want set_decl_rtl to go adjusting REG_ATTRS for this temporary. */
5119 t
->decl_with_rtl
.rtl
= x
;
5125 /* Compute the logical-and of OP0 and OP1, storing it in TARGET
5126 and returning TARGET.
5128 If TARGET is 0, a pseudo-register or constant is returned. */
5131 expand_and (machine_mode mode
, rtx op0
, rtx op1
, rtx target
)
5135 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
5136 tem
= simplify_binary_operation (AND
, mode
, op0
, op1
);
5138 tem
= expand_binop (mode
, and_optab
, op0
, op1
, target
, 0, OPTAB_LIB_WIDEN
);
5142 else if (tem
!= target
)
5143 emit_move_insn (target
, tem
);
5147 /* Helper function for emit_store_flag. */
5149 emit_cstore (rtx target
, enum insn_code icode
, enum rtx_code code
,
5150 machine_mode mode
, machine_mode compare_mode
,
5151 int unsignedp
, rtx x
, rtx y
, int normalizep
,
5152 machine_mode target_mode
)
5154 struct expand_operand ops
[4];
5155 rtx op0
, comparison
, subtarget
;
5157 machine_mode result_mode
= targetm
.cstore_mode (icode
);
5159 last
= get_last_insn ();
5160 x
= prepare_operand (icode
, x
, 2, mode
, compare_mode
, unsignedp
);
5161 y
= prepare_operand (icode
, y
, 3, mode
, compare_mode
, unsignedp
);
5164 delete_insns_since (last
);
5168 if (target_mode
== VOIDmode
)
5169 target_mode
= result_mode
;
5171 target
= gen_reg_rtx (target_mode
);
5173 comparison
= gen_rtx_fmt_ee (code
, result_mode
, x
, y
);
5175 create_output_operand (&ops
[0], optimize
? NULL_RTX
: target
, result_mode
);
5176 create_fixed_operand (&ops
[1], comparison
);
5177 create_fixed_operand (&ops
[2], x
);
5178 create_fixed_operand (&ops
[3], y
);
5179 if (!maybe_expand_insn (icode
, 4, ops
))
5181 delete_insns_since (last
);
5184 subtarget
= ops
[0].value
;
5186 /* If we are converting to a wider mode, first convert to
5187 TARGET_MODE, then normalize. This produces better combining
5188 opportunities on machines that have a SIGN_EXTRACT when we are
5189 testing a single bit. This mostly benefits the 68k.
5191 If STORE_FLAG_VALUE does not have the sign bit set when
5192 interpreted in MODE, we can do this conversion as unsigned, which
5193 is usually more efficient. */
5194 if (GET_MODE_SIZE (target_mode
) > GET_MODE_SIZE (result_mode
))
5196 convert_move (target
, subtarget
,
5197 val_signbit_known_clear_p (result_mode
,
5200 result_mode
= target_mode
;
5205 /* If we want to keep subexpressions around, don't reuse our last
5210 /* Now normalize to the proper value in MODE. Sometimes we don't
5211 have to do anything. */
5212 if (normalizep
== 0 || normalizep
== STORE_FLAG_VALUE
)
5214 /* STORE_FLAG_VALUE might be the most negative number, so write
5215 the comparison this way to avoid a compiler-time warning. */
5216 else if (- normalizep
== STORE_FLAG_VALUE
)
5217 op0
= expand_unop (result_mode
, neg_optab
, op0
, subtarget
, 0);
5219 /* We don't want to use STORE_FLAG_VALUE < 0 below since this makes
5220 it hard to use a value of just the sign bit due to ANSI integer
5221 constant typing rules. */
5222 else if (val_signbit_known_set_p (result_mode
, STORE_FLAG_VALUE
))
5223 op0
= expand_shift (RSHIFT_EXPR
, result_mode
, op0
,
5224 GET_MODE_BITSIZE (result_mode
) - 1, subtarget
,
5228 gcc_assert (STORE_FLAG_VALUE
& 1);
5230 op0
= expand_and (result_mode
, op0
, const1_rtx
, subtarget
);
5231 if (normalizep
== -1)
5232 op0
= expand_unop (result_mode
, neg_optab
, op0
, op0
, 0);
5235 /* If we were converting to a smaller mode, do the conversion now. */
5236 if (target_mode
!= result_mode
)
5238 convert_move (target
, op0
, 0);
5246 /* A subroutine of emit_store_flag only including "tricks" that do not
5247 need a recursive call. These are kept separate to avoid infinite
5251 emit_store_flag_1 (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
5252 machine_mode mode
, int unsignedp
, int normalizep
,
5253 machine_mode target_mode
)
5256 enum insn_code icode
;
5257 machine_mode compare_mode
;
5258 enum mode_class mclass
;
5259 enum rtx_code scode
;
5263 code
= unsigned_condition (code
);
5264 scode
= swap_condition (code
);
5266 /* If one operand is constant, make it the second one. Only do this
5267 if the other operand is not constant as well. */
5269 if (swap_commutative_operands_p (op0
, op1
))
5274 code
= swap_condition (code
);
5277 if (mode
== VOIDmode
)
5278 mode
= GET_MODE (op0
);
5280 /* For some comparisons with 1 and -1, we can convert this to
5281 comparisons with zero. This will often produce more opportunities for
5282 store-flag insns. */
5287 if (op1
== const1_rtx
)
5288 op1
= const0_rtx
, code
= LE
;
5291 if (op1
== constm1_rtx
)
5292 op1
= const0_rtx
, code
= LT
;
5295 if (op1
== const1_rtx
)
5296 op1
= const0_rtx
, code
= GT
;
5299 if (op1
== constm1_rtx
)
5300 op1
= const0_rtx
, code
= GE
;
5303 if (op1
== const1_rtx
)
5304 op1
= const0_rtx
, code
= NE
;
5307 if (op1
== const1_rtx
)
5308 op1
= const0_rtx
, code
= EQ
;
5314 /* If we are comparing a double-word integer with zero or -1, we can
5315 convert the comparison into one involving a single word. */
5316 if (GET_MODE_BITSIZE (mode
) == BITS_PER_WORD
* 2
5317 && GET_MODE_CLASS (mode
) == MODE_INT
5318 && (!MEM_P (op0
) || ! MEM_VOLATILE_P (op0
)))
5320 if ((code
== EQ
|| code
== NE
)
5321 && (op1
== const0_rtx
|| op1
== constm1_rtx
))
5325 /* Do a logical OR or AND of the two words and compare the
5327 op00
= simplify_gen_subreg (word_mode
, op0
, mode
, 0);
5328 op01
= simplify_gen_subreg (word_mode
, op0
, mode
, UNITS_PER_WORD
);
5329 tem
= expand_binop (word_mode
,
5330 op1
== const0_rtx
? ior_optab
: and_optab
,
5331 op00
, op01
, NULL_RTX
, unsignedp
,
5335 tem
= emit_store_flag (NULL_RTX
, code
, tem
, op1
, word_mode
,
5336 unsignedp
, normalizep
);
5338 else if ((code
== LT
|| code
== GE
) && op1
== const0_rtx
)
5342 /* If testing the sign bit, can just test on high word. */
5343 op0h
= simplify_gen_subreg (word_mode
, op0
, mode
,
5344 subreg_highpart_offset (word_mode
,
5346 tem
= emit_store_flag (NULL_RTX
, code
, op0h
, op1
, word_mode
,
5347 unsignedp
, normalizep
);
5354 if (target_mode
== VOIDmode
|| GET_MODE (tem
) == target_mode
)
5357 target
= gen_reg_rtx (target_mode
);
5359 convert_move (target
, tem
,
5360 !val_signbit_known_set_p (word_mode
,
5361 (normalizep
? normalizep
5362 : STORE_FLAG_VALUE
)));
5367 /* If this is A < 0 or A >= 0, we can do this by taking the ones
5368 complement of A (for GE) and shifting the sign bit to the low bit. */
5369 if (op1
== const0_rtx
&& (code
== LT
|| code
== GE
)
5370 && GET_MODE_CLASS (mode
) == MODE_INT
5371 && (normalizep
|| STORE_FLAG_VALUE
== 1
5372 || val_signbit_p (mode
, STORE_FLAG_VALUE
)))
5379 /* If the result is to be wider than OP0, it is best to convert it
5380 first. If it is to be narrower, it is *incorrect* to convert it
5382 else if (GET_MODE_SIZE (target_mode
) > GET_MODE_SIZE (mode
))
5384 op0
= convert_modes (target_mode
, mode
, op0
, 0);
5388 if (target_mode
!= mode
)
5392 op0
= expand_unop (mode
, one_cmpl_optab
, op0
,
5393 ((STORE_FLAG_VALUE
== 1 || normalizep
)
5394 ? 0 : subtarget
), 0);
5396 if (STORE_FLAG_VALUE
== 1 || normalizep
)
5397 /* If we are supposed to produce a 0/1 value, we want to do
5398 a logical shift from the sign bit to the low-order bit; for
5399 a -1/0 value, we do an arithmetic shift. */
5400 op0
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
5401 GET_MODE_BITSIZE (mode
) - 1,
5402 subtarget
, normalizep
!= -1);
5404 if (mode
!= target_mode
)
5405 op0
= convert_modes (target_mode
, mode
, op0
, 0);
5410 mclass
= GET_MODE_CLASS (mode
);
5411 for (compare_mode
= mode
; compare_mode
!= VOIDmode
;
5412 compare_mode
= GET_MODE_WIDER_MODE (compare_mode
))
5414 machine_mode optab_mode
= mclass
== MODE_CC
? CCmode
: compare_mode
;
5415 icode
= optab_handler (cstore_optab
, optab_mode
);
5416 if (icode
!= CODE_FOR_nothing
)
5418 do_pending_stack_adjust ();
5419 tem
= emit_cstore (target
, icode
, code
, mode
, compare_mode
,
5420 unsignedp
, op0
, op1
, normalizep
, target_mode
);
5424 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5426 tem
= emit_cstore (target
, icode
, scode
, mode
, compare_mode
,
5427 unsignedp
, op1
, op0
, normalizep
, target_mode
);
5438 /* Emit a store-flags instruction for comparison CODE on OP0 and OP1
5439 and storing in TARGET. Normally return TARGET.
5440 Return 0 if that cannot be done.
5442 MODE is the mode to use for OP0 and OP1 should they be CONST_INTs. If
5443 it is VOIDmode, they cannot both be CONST_INT.
5445 UNSIGNEDP is for the case where we have to widen the operands
5446 to perform the operation. It says to use zero-extension.
5448 NORMALIZEP is 1 if we should convert the result to be either zero
5449 or one. Normalize is -1 if we should convert the result to be
5450 either zero or -1. If NORMALIZEP is zero, the result will be left
5451 "raw" out of the scc insn. */
5454 emit_store_flag (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
5455 machine_mode mode
, int unsignedp
, int normalizep
)
5457 machine_mode target_mode
= target
? GET_MODE (target
) : VOIDmode
;
5458 enum rtx_code rcode
;
5463 /* If we compare constants, we shouldn't use a store-flag operation,
5464 but a constant load. We can get there via the vanilla route that
5465 usually generates a compare-branch sequence, but will in this case
5466 fold the comparison to a constant, and thus elide the branch. */
5467 if (CONSTANT_P (op0
) && CONSTANT_P (op1
))
5470 tem
= emit_store_flag_1 (target
, code
, op0
, op1
, mode
, unsignedp
, normalizep
,
5475 /* If we reached here, we can't do this with a scc insn, however there
5476 are some comparisons that can be done in other ways. Don't do any
5477 of these cases if branches are very cheap. */
5478 if (BRANCH_COST (optimize_insn_for_speed_p (), false) == 0)
5481 /* See what we need to return. We can only return a 1, -1, or the
5484 if (normalizep
== 0)
5486 if (STORE_FLAG_VALUE
== 1 || STORE_FLAG_VALUE
== -1)
5487 normalizep
= STORE_FLAG_VALUE
;
5489 else if (val_signbit_p (mode
, STORE_FLAG_VALUE
))
5495 last
= get_last_insn ();
5497 /* If optimizing, use different pseudo registers for each insn, instead
5498 of reusing the same pseudo. This leads to better CSE, but slows
5499 down the compiler, since there are more pseudos */
5500 subtarget
= (!optimize
5501 && (target_mode
== mode
)) ? target
: NULL_RTX
;
5502 trueval
= GEN_INT (normalizep
? normalizep
: STORE_FLAG_VALUE
);
5504 /* For floating-point comparisons, try the reverse comparison or try
5505 changing the "orderedness" of the comparison. */
5506 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5508 enum rtx_code first_code
;
5511 rcode
= reverse_condition_maybe_unordered (code
);
5512 if (can_compare_p (rcode
, mode
, ccp_store_flag
)
5513 && (code
== ORDERED
|| code
== UNORDERED
5514 || (! HONOR_NANS (mode
) && (code
== LTGT
|| code
== UNEQ
))
5515 || (! HONOR_SNANS (mode
) && (code
== EQ
|| code
== NE
))))
5517 int want_add
= ((STORE_FLAG_VALUE
== 1 && normalizep
== -1)
5518 || (STORE_FLAG_VALUE
== -1 && normalizep
== 1));
5520 /* For the reverse comparison, use either an addition or a XOR. */
5522 && rtx_cost (GEN_INT (normalizep
), PLUS
, 1,
5523 optimize_insn_for_speed_p ()) == 0)
5525 tem
= emit_store_flag_1 (subtarget
, rcode
, op0
, op1
, mode
, 0,
5526 STORE_FLAG_VALUE
, target_mode
);
5528 return expand_binop (target_mode
, add_optab
, tem
,
5529 gen_int_mode (normalizep
, target_mode
),
5530 target
, 0, OPTAB_WIDEN
);
5533 && rtx_cost (trueval
, XOR
, 1,
5534 optimize_insn_for_speed_p ()) == 0)
5536 tem
= emit_store_flag_1 (subtarget
, rcode
, op0
, op1
, mode
, 0,
5537 normalizep
, target_mode
);
5539 return expand_binop (target_mode
, xor_optab
, tem
, trueval
,
5540 target
, INTVAL (trueval
) >= 0, OPTAB_WIDEN
);
5544 delete_insns_since (last
);
5546 /* Cannot split ORDERED and UNORDERED, only try the above trick. */
5547 if (code
== ORDERED
|| code
== UNORDERED
)
5550 and_them
= split_comparison (code
, mode
, &first_code
, &code
);
5552 /* If there are no NaNs, the first comparison should always fall through.
5553 Effectively change the comparison to the other one. */
5554 if (!HONOR_NANS (mode
))
5556 gcc_assert (first_code
== (and_them
? ORDERED
: UNORDERED
));
5557 return emit_store_flag_1 (target
, code
, op0
, op1
, mode
, 0, normalizep
,
5561 #ifdef HAVE_conditional_move
5562 /* Try using a setcc instruction for ORDERED/UNORDERED, followed by a
5563 conditional move. */
5564 tem
= emit_store_flag_1 (subtarget
, first_code
, op0
, op1
, mode
, 0,
5565 normalizep
, target_mode
);
5570 tem
= emit_conditional_move (target
, code
, op0
, op1
, mode
,
5571 tem
, const0_rtx
, GET_MODE (tem
), 0);
5573 tem
= emit_conditional_move (target
, code
, op0
, op1
, mode
,
5574 trueval
, tem
, GET_MODE (tem
), 0);
5577 delete_insns_since (last
);
5584 /* The remaining tricks only apply to integer comparisons. */
5586 if (GET_MODE_CLASS (mode
) != MODE_INT
)
5589 /* If this is an equality comparison of integers, we can try to exclusive-or
5590 (or subtract) the two operands and use a recursive call to try the
5591 comparison with zero. Don't do any of these cases if branches are
5594 if ((code
== EQ
|| code
== NE
) && op1
!= const0_rtx
)
5596 tem
= expand_binop (mode
, xor_optab
, op0
, op1
, subtarget
, 1,
5600 tem
= expand_binop (mode
, sub_optab
, op0
, op1
, subtarget
, 1,
5603 tem
= emit_store_flag (target
, code
, tem
, const0_rtx
,
5604 mode
, unsignedp
, normalizep
);
5608 delete_insns_since (last
);
5611 /* For integer comparisons, try the reverse comparison. However, for
5612 small X and if we'd have anyway to extend, implementing "X != 0"
5613 as "-(int)X >> 31" is still cheaper than inverting "(int)X == 0". */
5614 rcode
= reverse_condition (code
);
5615 if (can_compare_p (rcode
, mode
, ccp_store_flag
)
5616 && ! (optab_handler (cstore_optab
, mode
) == CODE_FOR_nothing
5618 && GET_MODE_SIZE (mode
) < UNITS_PER_WORD
5619 && op1
== const0_rtx
))
5621 int want_add
= ((STORE_FLAG_VALUE
== 1 && normalizep
== -1)
5622 || (STORE_FLAG_VALUE
== -1 && normalizep
== 1));
5624 /* Again, for the reverse comparison, use either an addition or a XOR. */
5626 && rtx_cost (GEN_INT (normalizep
), PLUS
, 1,
5627 optimize_insn_for_speed_p ()) == 0)
5629 tem
= emit_store_flag_1 (subtarget
, rcode
, op0
, op1
, mode
, 0,
5630 STORE_FLAG_VALUE
, target_mode
);
5632 tem
= expand_binop (target_mode
, add_optab
, tem
,
5633 gen_int_mode (normalizep
, target_mode
),
5634 target
, 0, OPTAB_WIDEN
);
5637 && rtx_cost (trueval
, XOR
, 1,
5638 optimize_insn_for_speed_p ()) == 0)
5640 tem
= emit_store_flag_1 (subtarget
, rcode
, op0
, op1
, mode
, 0,
5641 normalizep
, target_mode
);
5643 tem
= expand_binop (target_mode
, xor_optab
, tem
, trueval
, target
,
5644 INTVAL (trueval
) >= 0, OPTAB_WIDEN
);
5649 delete_insns_since (last
);
5652 /* Some other cases we can do are EQ, NE, LE, and GT comparisons with
5653 the constant zero. Reject all other comparisons at this point. Only
5654 do LE and GT if branches are expensive since they are expensive on
5655 2-operand machines. */
5657 if (op1
!= const0_rtx
5658 || (code
!= EQ
&& code
!= NE
5659 && (BRANCH_COST (optimize_insn_for_speed_p (),
5660 false) <= 1 || (code
!= LE
&& code
!= GT
))))
5663 /* Try to put the result of the comparison in the sign bit. Assume we can't
5664 do the necessary operation below. */
5668 /* To see if A <= 0, compute (A | (A - 1)). A <= 0 iff that result has
5669 the sign bit set. */
5673 /* This is destructive, so SUBTARGET can't be OP0. */
5674 if (rtx_equal_p (subtarget
, op0
))
5677 tem
= expand_binop (mode
, sub_optab
, op0
, const1_rtx
, subtarget
, 0,
5680 tem
= expand_binop (mode
, ior_optab
, op0
, tem
, subtarget
, 0,
5684 /* To see if A > 0, compute (((signed) A) << BITS) - A, where BITS is the
5685 number of bits in the mode of OP0, minus one. */
5689 if (rtx_equal_p (subtarget
, op0
))
5692 tem
= expand_shift (RSHIFT_EXPR
, mode
, op0
,
5693 GET_MODE_BITSIZE (mode
) - 1,
5695 tem
= expand_binop (mode
, sub_optab
, tem
, op0
, subtarget
, 0,
5699 if (code
== EQ
|| code
== NE
)
5701 /* For EQ or NE, one way to do the comparison is to apply an operation
5702 that converts the operand into a positive number if it is nonzero
5703 or zero if it was originally zero. Then, for EQ, we subtract 1 and
5704 for NE we negate. This puts the result in the sign bit. Then we
5705 normalize with a shift, if needed.
5707 Two operations that can do the above actions are ABS and FFS, so try
5708 them. If that doesn't work, and MODE is smaller than a full word,
5709 we can use zero-extension to the wider mode (an unsigned conversion)
5710 as the operation. */
5712 /* Note that ABS doesn't yield a positive number for INT_MIN, but
5713 that is compensated by the subsequent overflow when subtracting
5716 if (optab_handler (abs_optab
, mode
) != CODE_FOR_nothing
)
5717 tem
= expand_unop (mode
, abs_optab
, op0
, subtarget
, 1);
5718 else if (optab_handler (ffs_optab
, mode
) != CODE_FOR_nothing
)
5719 tem
= expand_unop (mode
, ffs_optab
, op0
, subtarget
, 1);
5720 else if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
5722 tem
= convert_modes (word_mode
, mode
, op0
, 1);
5729 tem
= expand_binop (mode
, sub_optab
, tem
, const1_rtx
, subtarget
,
5732 tem
= expand_unop (mode
, neg_optab
, tem
, subtarget
, 0);
5735 /* If we couldn't do it that way, for NE we can "or" the two's complement
5736 of the value with itself. For EQ, we take the one's complement of
5737 that "or", which is an extra insn, so we only handle EQ if branches
5742 || BRANCH_COST (optimize_insn_for_speed_p (),
5745 if (rtx_equal_p (subtarget
, op0
))
5748 tem
= expand_unop (mode
, neg_optab
, op0
, subtarget
, 0);
5749 tem
= expand_binop (mode
, ior_optab
, tem
, op0
, subtarget
, 0,
5752 if (tem
&& code
== EQ
)
5753 tem
= expand_unop (mode
, one_cmpl_optab
, tem
, subtarget
, 0);
5757 if (tem
&& normalizep
)
5758 tem
= expand_shift (RSHIFT_EXPR
, mode
, tem
,
5759 GET_MODE_BITSIZE (mode
) - 1,
5760 subtarget
, normalizep
== 1);
5766 else if (GET_MODE (tem
) != target_mode
)
5768 convert_move (target
, tem
, 0);
5771 else if (!subtarget
)
5773 emit_move_insn (target
, tem
);
5778 delete_insns_since (last
);
5783 /* Like emit_store_flag, but always succeeds. */
5786 emit_store_flag_force (rtx target
, enum rtx_code code
, rtx op0
, rtx op1
,
5787 machine_mode mode
, int unsignedp
, int normalizep
)
5790 rtx_code_label
*label
;
5791 rtx trueval
, falseval
;
5793 /* First see if emit_store_flag can do the job. */
5794 tem
= emit_store_flag (target
, code
, op0
, op1
, mode
, unsignedp
, normalizep
);
5799 target
= gen_reg_rtx (word_mode
);
5801 /* If this failed, we have to do this with set/compare/jump/set code.
5802 For foo != 0, if foo is in OP0, just replace it with 1 if nonzero. */
5803 trueval
= normalizep
? GEN_INT (normalizep
) : const1_rtx
;
5805 && GET_MODE_CLASS (mode
) == MODE_INT
5808 && op1
== const0_rtx
)
5810 label
= gen_label_rtx ();
5811 do_compare_rtx_and_jump (target
, const0_rtx
, EQ
, unsignedp
,
5812 mode
, NULL_RTX
, NULL_RTX
, label
, -1);
5813 emit_move_insn (target
, trueval
);
5819 || reg_mentioned_p (target
, op0
) || reg_mentioned_p (target
, op1
))
5820 target
= gen_reg_rtx (GET_MODE (target
));
5822 /* Jump in the right direction if the target cannot implement CODE
5823 but can jump on its reverse condition. */
5824 falseval
= const0_rtx
;
5825 if (! can_compare_p (code
, mode
, ccp_jump
)
5826 && (! FLOAT_MODE_P (mode
)
5827 || code
== ORDERED
|| code
== UNORDERED
5828 || (! HONOR_NANS (mode
) && (code
== LTGT
|| code
== UNEQ
))
5829 || (! HONOR_SNANS (mode
) && (code
== EQ
|| code
== NE
))))
5831 enum rtx_code rcode
;
5832 if (FLOAT_MODE_P (mode
))
5833 rcode
= reverse_condition_maybe_unordered (code
);
5835 rcode
= reverse_condition (code
);
5837 /* Canonicalize to UNORDERED for the libcall. */
5838 if (can_compare_p (rcode
, mode
, ccp_jump
)
5839 || (code
== ORDERED
&& ! can_compare_p (ORDERED
, mode
, ccp_jump
)))
5842 trueval
= const0_rtx
;
5847 emit_move_insn (target
, trueval
);
5848 label
= gen_label_rtx ();
5849 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
, NULL_RTX
,
5850 NULL_RTX
, label
, -1);
5852 emit_move_insn (target
, falseval
);
5858 /* Perform possibly multi-word comparison and conditional jump to LABEL
5859 if ARG1 OP ARG2 true where ARG1 and ARG2 are of mode MODE. This is
5860 now a thin wrapper around do_compare_rtx_and_jump. */
5863 do_cmp_and_jump (rtx arg1
, rtx arg2
, enum rtx_code op
, machine_mode mode
,
5864 rtx_code_label
*label
)
5866 int unsignedp
= (op
== LTU
|| op
== LEU
|| op
== GTU
|| op
== GEU
);
5867 do_compare_rtx_and_jump (arg1
, arg2
, op
, unsignedp
, mode
,
5868 NULL_RTX
, NULL_RTX
, label
, -1);