1 /* Optimize by combining instructions for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 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 2, 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 COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This module is essentially the "combiner" phase of the U. of Arizona
23 Portable Optimizer, but redone to work on our list-structured
24 representation for RTL instead of their string representation.
26 The LOG_LINKS of each insn identify the most recent assignment
27 to each REG used in the insn. It is a list of previous insns,
28 each of which contains a SET for a REG that is used in this insn
29 and not used or set in between. LOG_LINKs never cross basic blocks.
30 They were set up by the preceding pass (lifetime analysis).
32 We try to combine each pair of insns joined by a logical link.
33 We also try to combine triples of insns A, B and C when
34 C has a link back to B and B has a link back to A.
36 LOG_LINKS does not have links for use of the CC0. They don't
37 need to, because the insn that sets the CC0 is always immediately
38 before the insn that tests it. So we always regard a branch
39 insn as having a logical link to the preceding insn. The same is true
40 for an insn explicitly using CC0.
42 We check (with use_crosses_set_p) to avoid combining in such a way
43 as to move a computation to a place where its value would be different.
45 Combination is done by mathematically substituting the previous
46 insn(s) values for the regs they set into the expressions in
47 the later insns that refer to these regs. If the result is a valid insn
48 for our target machine, according to the machine description,
49 we install it, delete the earlier insns, and update the data flow
50 information (LOG_LINKS and REG_NOTES) for what we did.
52 There are a few exceptions where the dataflow information created by
53 flow.c aren't completely updated:
55 - reg_live_length is not updated
56 - reg_n_refs is not adjusted in the rare case when a register is
57 no longer required in a computation
58 - there are extremely rare cases (see distribute_regnotes) when a
60 - a LOG_LINKS entry that refers to an insn with multiple SETs may be
61 removed because there is no way to know which register it was
64 To simplify substitution, we combine only when the earlier insn(s)
65 consist of only a single assignment. To simplify updating afterward,
66 we never combine when a subroutine call appears in the middle.
68 Since we do not represent assignments to CC0 explicitly except when that
69 is all an insn does, there is no LOG_LINKS entry in an insn that uses
70 the condition code for the insn that set the condition code.
71 Fortunately, these two insns must be consecutive.
72 Therefore, every JUMP_INSN is taken to have an implicit logical link
73 to the preceding insn. This is not quite right, since non-jumps can
74 also use the condition code; but in practice such insns would not
79 #include "coretypes.h"
85 #include "hard-reg-set.h"
86 #include "basic-block.h"
87 #include "insn-config.h"
89 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
91 #include "insn-attr.h"
96 /* It is not safe to use ordinary gen_lowpart in combine.
97 Use gen_lowpart_for_combine instead. See comments there. */
98 #define gen_lowpart dont_use_gen_lowpart_you_dummy
100 /* Number of attempts to combine instructions in this function. */
102 static int combine_attempts
;
104 /* Number of attempts that got as far as substitution in this function. */
106 static int combine_merges
;
108 /* Number of instructions combined with added SETs in this function. */
110 static int combine_extras
;
112 /* Number of instructions combined in this function. */
114 static int combine_successes
;
116 /* Totals over entire compilation. */
118 static int total_attempts
, total_merges
, total_extras
, total_successes
;
121 /* Vector mapping INSN_UIDs to cuids.
122 The cuids are like uids but increase monotonically always.
123 Combine always uses cuids so that it can compare them.
124 But actually renumbering the uids, which we used to do,
125 proves to be a bad idea because it makes it hard to compare
126 the dumps produced by earlier passes with those from later passes. */
128 static int *uid_cuid
;
129 static int max_uid_cuid
;
131 /* Get the cuid of an insn. */
133 #define INSN_CUID(INSN) \
134 (INSN_UID (INSN) > max_uid_cuid ? insn_cuid (INSN) : uid_cuid[INSN_UID (INSN)])
136 /* In case BITS_PER_WORD == HOST_BITS_PER_WIDE_INT, shifting by
137 BITS_PER_WORD would invoke undefined behavior. Work around it. */
139 #define UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD(val) \
140 (((unsigned HOST_WIDE_INT) (val) << (BITS_PER_WORD - 1)) << 1)
142 #define nonzero_bits(X, M) \
143 cached_nonzero_bits (X, M, NULL_RTX, VOIDmode, 0)
145 #define num_sign_bit_copies(X, M) \
146 cached_num_sign_bit_copies (X, M, NULL_RTX, VOIDmode, 0)
148 /* Maximum register number, which is the size of the tables below. */
150 static unsigned int combine_max_regno
;
152 /* Record last point of death of (hard or pseudo) register n. */
154 static rtx
*reg_last_death
;
156 /* Record last point of modification of (hard or pseudo) register n. */
158 static rtx
*reg_last_set
;
160 /* Record the cuid of the last insn that invalidated memory
161 (anything that writes memory, and subroutine calls, but not pushes). */
163 static int mem_last_set
;
165 /* Record the cuid of the last CALL_INSN
166 so we can tell whether a potential combination crosses any calls. */
168 static int last_call_cuid
;
170 /* When `subst' is called, this is the insn that is being modified
171 (by combining in a previous insn). The PATTERN of this insn
172 is still the old pattern partially modified and it should not be
173 looked at, but this may be used to examine the successors of the insn
174 to judge whether a simplification is valid. */
176 static rtx subst_insn
;
178 /* This is the lowest CUID that `subst' is currently dealing with.
179 get_last_value will not return a value if the register was set at or
180 after this CUID. If not for this mechanism, we could get confused if
181 I2 or I1 in try_combine were an insn that used the old value of a register
182 to obtain a new value. In that case, we might erroneously get the
183 new value of the register when we wanted the old one. */
185 static int subst_low_cuid
;
187 /* This contains any hard registers that are used in newpat; reg_dead_at_p
188 must consider all these registers to be always live. */
190 static HARD_REG_SET newpat_used_regs
;
192 /* This is an insn to which a LOG_LINKS entry has been added. If this
193 insn is the earlier than I2 or I3, combine should rescan starting at
196 static rtx added_links_insn
;
198 /* Basic block in which we are performing combines. */
199 static basic_block this_basic_block
;
201 /* A bitmap indicating which blocks had registers go dead at entry.
202 After combine, we'll need to re-do global life analysis with
203 those blocks as starting points. */
204 static sbitmap refresh_blocks
;
206 /* The next group of arrays allows the recording of the last value assigned
207 to (hard or pseudo) register n. We use this information to see if an
208 operation being processed is redundant given a prior operation performed
209 on the register. For example, an `and' with a constant is redundant if
210 all the zero bits are already known to be turned off.
212 We use an approach similar to that used by cse, but change it in the
215 (1) We do not want to reinitialize at each label.
216 (2) It is useful, but not critical, to know the actual value assigned
217 to a register. Often just its form is helpful.
219 Therefore, we maintain the following arrays:
221 reg_last_set_value the last value assigned
222 reg_last_set_label records the value of label_tick when the
223 register was assigned
224 reg_last_set_table_tick records the value of label_tick when a
225 value using the register is assigned
226 reg_last_set_invalid set to nonzero when it is not valid
227 to use the value of this register in some
230 To understand the usage of these tables, it is important to understand
231 the distinction between the value in reg_last_set_value being valid
232 and the register being validly contained in some other expression in the
235 Entry I in reg_last_set_value is valid if it is nonzero, and either
236 reg_n_sets[i] is 1 or reg_last_set_label[i] == label_tick.
238 Register I may validly appear in any expression returned for the value
239 of another register if reg_n_sets[i] is 1. It may also appear in the
240 value for register J if reg_last_set_label[i] < reg_last_set_label[j] or
241 reg_last_set_invalid[j] is zero.
243 If an expression is found in the table containing a register which may
244 not validly appear in an expression, the register is replaced by
245 something that won't match, (clobber (const_int 0)).
247 reg_last_set_invalid[i] is set nonzero when register I is being assigned
248 to and reg_last_set_table_tick[i] == label_tick. */
250 /* Record last value assigned to (hard or pseudo) register n. */
252 static rtx
*reg_last_set_value
;
254 /* Record the value of label_tick when the value for register n is placed in
255 reg_last_set_value[n]. */
257 static int *reg_last_set_label
;
259 /* Record the value of label_tick when an expression involving register n
260 is placed in reg_last_set_value. */
262 static int *reg_last_set_table_tick
;
264 /* Set nonzero if references to register n in expressions should not be
267 static char *reg_last_set_invalid
;
269 /* Incremented for each label. */
271 static int label_tick
;
273 /* Some registers that are set more than once and used in more than one
274 basic block are nevertheless always set in similar ways. For example,
275 a QImode register may be loaded from memory in two places on a machine
276 where byte loads zero extend.
278 We record in the following array what we know about the nonzero
279 bits of a register, specifically which bits are known to be zero.
281 If an entry is zero, it means that we don't know anything special. */
283 static unsigned HOST_WIDE_INT
*reg_nonzero_bits
;
285 /* Mode used to compute significance in reg_nonzero_bits. It is the largest
286 integer mode that can fit in HOST_BITS_PER_WIDE_INT. */
288 static enum machine_mode nonzero_bits_mode
;
290 /* Nonzero if we know that a register has some leading bits that are always
291 equal to the sign bit. */
293 static unsigned char *reg_sign_bit_copies
;
295 /* Nonzero when reg_nonzero_bits and reg_sign_bit_copies can be safely used.
296 It is zero while computing them and after combine has completed. This
297 former test prevents propagating values based on previously set values,
298 which can be incorrect if a variable is modified in a loop. */
300 static int nonzero_sign_valid
;
302 /* These arrays are maintained in parallel with reg_last_set_value
303 and are used to store the mode in which the register was last set,
304 the bits that were known to be zero when it was last set, and the
305 number of sign bits copies it was known to have when it was last set. */
307 static enum machine_mode
*reg_last_set_mode
;
308 static unsigned HOST_WIDE_INT
*reg_last_set_nonzero_bits
;
309 static char *reg_last_set_sign_bit_copies
;
311 /* Record one modification to rtl structure
312 to be undone by storing old_contents into *where.
313 is_int is 1 if the contents are an int. */
319 union {rtx r
; int i
;} old_contents
;
320 union {rtx
*r
; int *i
;} where
;
323 /* Record a bunch of changes to be undone, up to MAX_UNDO of them.
324 num_undo says how many are currently recorded.
326 other_insn is nonzero if we have modified some other insn in the process
327 of working on subst_insn. It must be verified too. */
336 static struct undobuf undobuf
;
338 /* Number of times the pseudo being substituted for
339 was found and replaced. */
341 static int n_occurrences
;
343 static void do_SUBST
PARAMS ((rtx
*, rtx
));
344 static void do_SUBST_INT
PARAMS ((int *, int));
345 static void init_reg_last_arrays
PARAMS ((void));
346 static void setup_incoming_promotions
PARAMS ((void));
347 static void set_nonzero_bits_and_sign_copies
PARAMS ((rtx
, rtx
, void *));
348 static int cant_combine_insn_p
PARAMS ((rtx
));
349 static int can_combine_p
PARAMS ((rtx
, rtx
, rtx
, rtx
, rtx
*, rtx
*));
350 static int sets_function_arg_p
PARAMS ((rtx
));
351 static int combinable_i3pat
PARAMS ((rtx
, rtx
*, rtx
, rtx
, int, rtx
*));
352 static int contains_muldiv
PARAMS ((rtx
));
353 static rtx try_combine
PARAMS ((rtx
, rtx
, rtx
, int *));
354 static void undo_all
PARAMS ((void));
355 static void undo_commit
PARAMS ((void));
356 static rtx
*find_split_point
PARAMS ((rtx
*, rtx
));
357 static rtx subst
PARAMS ((rtx
, rtx
, rtx
, int, int));
358 static rtx combine_simplify_rtx
PARAMS ((rtx
, enum machine_mode
, int, int));
359 static rtx simplify_if_then_else
PARAMS ((rtx
));
360 static rtx simplify_set
PARAMS ((rtx
));
361 static rtx simplify_logical
PARAMS ((rtx
, int));
362 static rtx expand_compound_operation
PARAMS ((rtx
));
363 static rtx expand_field_assignment
PARAMS ((rtx
));
364 static rtx make_extraction
PARAMS ((enum machine_mode
, rtx
, HOST_WIDE_INT
,
365 rtx
, unsigned HOST_WIDE_INT
, int,
367 static rtx extract_left_shift
PARAMS ((rtx
, int));
368 static rtx make_compound_operation
PARAMS ((rtx
, enum rtx_code
));
369 static int get_pos_from_mask
PARAMS ((unsigned HOST_WIDE_INT
,
370 unsigned HOST_WIDE_INT
*));
371 static rtx force_to_mode
PARAMS ((rtx
, enum machine_mode
,
372 unsigned HOST_WIDE_INT
, rtx
, int));
373 static rtx if_then_else_cond
PARAMS ((rtx
, rtx
*, rtx
*));
374 static rtx known_cond
PARAMS ((rtx
, enum rtx_code
, rtx
, rtx
));
375 static int rtx_equal_for_field_assignment_p
PARAMS ((rtx
, rtx
));
376 static rtx make_field_assignment
PARAMS ((rtx
));
377 static rtx apply_distributive_law
PARAMS ((rtx
));
378 static rtx simplify_and_const_int
PARAMS ((rtx
, enum machine_mode
, rtx
,
379 unsigned HOST_WIDE_INT
));
380 static unsigned HOST_WIDE_INT cached_nonzero_bits
381 PARAMS ((rtx
, enum machine_mode
, rtx
,
383 unsigned HOST_WIDE_INT
));
384 static unsigned HOST_WIDE_INT nonzero_bits1
385 PARAMS ((rtx
, enum machine_mode
, rtx
,
387 unsigned HOST_WIDE_INT
));
388 static unsigned int cached_num_sign_bit_copies
389 PARAMS ((rtx
, enum machine_mode
, rtx
,
390 enum machine_mode
, unsigned int));
391 static unsigned int num_sign_bit_copies1
392 PARAMS ((rtx
, enum machine_mode
, rtx
,
393 enum machine_mode
, unsigned int));
394 static int merge_outer_ops
PARAMS ((enum rtx_code
*, HOST_WIDE_INT
*,
395 enum rtx_code
, HOST_WIDE_INT
,
396 enum machine_mode
, int *));
397 static rtx simplify_shift_const
PARAMS ((rtx
, enum rtx_code
, enum machine_mode
,
399 static int recog_for_combine
PARAMS ((rtx
*, rtx
, rtx
*));
400 static rtx gen_lowpart_for_combine
PARAMS ((enum machine_mode
, rtx
));
401 static rtx gen_binary
PARAMS ((enum rtx_code
, enum machine_mode
,
403 static enum rtx_code simplify_comparison
PARAMS ((enum rtx_code
, rtx
*, rtx
*));
404 static void update_table_tick
PARAMS ((rtx
));
405 static void record_value_for_reg
PARAMS ((rtx
, rtx
, rtx
));
406 static void check_promoted_subreg
PARAMS ((rtx
, rtx
));
407 static void record_dead_and_set_regs_1
PARAMS ((rtx
, rtx
, void *));
408 static void record_dead_and_set_regs
PARAMS ((rtx
));
409 static int get_last_value_validate
PARAMS ((rtx
*, rtx
, int, int));
410 static rtx get_last_value
PARAMS ((rtx
));
411 static int use_crosses_set_p
PARAMS ((rtx
, int));
412 static void reg_dead_at_p_1
PARAMS ((rtx
, rtx
, void *));
413 static int reg_dead_at_p
PARAMS ((rtx
, rtx
));
414 static void move_deaths
PARAMS ((rtx
, rtx
, int, rtx
, rtx
*));
415 static int reg_bitfield_target_p
PARAMS ((rtx
, rtx
));
416 static void distribute_notes
PARAMS ((rtx
, rtx
, rtx
, rtx
, rtx
, rtx
));
417 static void distribute_links
PARAMS ((rtx
));
418 static void mark_used_regs_combine
PARAMS ((rtx
));
419 static int insn_cuid
PARAMS ((rtx
));
420 static void record_promoted_value
PARAMS ((rtx
, rtx
));
421 static rtx reversed_comparison
PARAMS ((rtx
, enum machine_mode
, rtx
, rtx
));
422 static enum rtx_code combine_reversed_comparison_code
PARAMS ((rtx
));
424 /* Substitute NEWVAL, an rtx expression, into INTO, a place in some
425 insn. The substitution can be undone by undo_all. If INTO is already
426 set to NEWVAL, do not record this change. Because computing NEWVAL might
427 also call SUBST, we have to compute it before we put anything into
431 do_SUBST (into
, newval
)
437 if (oldval
== newval
)
440 /* We'd like to catch as many invalid transformations here as
441 possible. Unfortunately, there are way too many mode changes
442 that are perfectly valid, so we'd waste too much effort for
443 little gain doing the checks here. Focus on catching invalid
444 transformations involving integer constants. */
445 if (GET_MODE_CLASS (GET_MODE (oldval
)) == MODE_INT
446 && GET_CODE (newval
) == CONST_INT
)
448 /* Sanity check that we're replacing oldval with a CONST_INT
449 that is a valid sign-extension for the original mode. */
450 if (INTVAL (newval
) != trunc_int_for_mode (INTVAL (newval
),
454 /* Replacing the operand of a SUBREG or a ZERO_EXTEND with a
455 CONST_INT is not valid, because after the replacement, the
456 original mode would be gone. Unfortunately, we can't tell
457 when do_SUBST is called to replace the operand thereof, so we
458 perform this test on oldval instead, checking whether an
459 invalid replacement took place before we got here. */
460 if ((GET_CODE (oldval
) == SUBREG
461 && GET_CODE (SUBREG_REG (oldval
)) == CONST_INT
)
462 || (GET_CODE (oldval
) == ZERO_EXTEND
463 && GET_CODE (XEXP (oldval
, 0)) == CONST_INT
))
468 buf
= undobuf
.frees
, undobuf
.frees
= buf
->next
;
470 buf
= (struct undo
*) xmalloc (sizeof (struct undo
));
474 buf
->old_contents
.r
= oldval
;
477 buf
->next
= undobuf
.undos
, undobuf
.undos
= buf
;
480 #define SUBST(INTO, NEWVAL) do_SUBST(&(INTO), (NEWVAL))
482 /* Similar to SUBST, but NEWVAL is an int expression. Note that substitution
483 for the value of a HOST_WIDE_INT value (including CONST_INT) is
487 do_SUBST_INT (into
, newval
)
493 if (oldval
== newval
)
497 buf
= undobuf
.frees
, undobuf
.frees
= buf
->next
;
499 buf
= (struct undo
*) xmalloc (sizeof (struct undo
));
503 buf
->old_contents
.i
= oldval
;
506 buf
->next
= undobuf
.undos
, undobuf
.undos
= buf
;
509 #define SUBST_INT(INTO, NEWVAL) do_SUBST_INT(&(INTO), (NEWVAL))
511 /* Main entry point for combiner. F is the first insn of the function.
512 NREGS is the first unused pseudo-reg number.
514 Return nonzero if the combiner has turned an indirect jump
515 instruction into a direct jump. */
517 combine_instructions (f
, nregs
)
526 rtx links
, nextlinks
;
528 int new_direct_jump_p
= 0;
530 combine_attempts
= 0;
533 combine_successes
= 0;
535 combine_max_regno
= nregs
;
537 reg_nonzero_bits
= ((unsigned HOST_WIDE_INT
*)
538 xcalloc (nregs
, sizeof (unsigned HOST_WIDE_INT
)));
540 = (unsigned char *) xcalloc (nregs
, sizeof (unsigned char));
542 reg_last_death
= (rtx
*) xmalloc (nregs
* sizeof (rtx
));
543 reg_last_set
= (rtx
*) xmalloc (nregs
* sizeof (rtx
));
544 reg_last_set_value
= (rtx
*) xmalloc (nregs
* sizeof (rtx
));
545 reg_last_set_table_tick
= (int *) xmalloc (nregs
* sizeof (int));
546 reg_last_set_label
= (int *) xmalloc (nregs
* sizeof (int));
547 reg_last_set_invalid
= (char *) xmalloc (nregs
* sizeof (char));
549 = (enum machine_mode
*) xmalloc (nregs
* sizeof (enum machine_mode
));
550 reg_last_set_nonzero_bits
551 = (unsigned HOST_WIDE_INT
*) xmalloc (nregs
* sizeof (HOST_WIDE_INT
));
552 reg_last_set_sign_bit_copies
553 = (char *) xmalloc (nregs
* sizeof (char));
555 init_reg_last_arrays ();
557 init_recog_no_volatile ();
559 /* Compute maximum uid value so uid_cuid can be allocated. */
561 for (insn
= f
, i
= 0; insn
; insn
= NEXT_INSN (insn
))
562 if (INSN_UID (insn
) > i
)
565 uid_cuid
= (int *) xmalloc ((i
+ 1) * sizeof (int));
568 nonzero_bits_mode
= mode_for_size (HOST_BITS_PER_WIDE_INT
, MODE_INT
, 0);
570 /* Don't use reg_nonzero_bits when computing it. This can cause problems
571 when, for example, we have j <<= 1 in a loop. */
573 nonzero_sign_valid
= 0;
575 /* Compute the mapping from uids to cuids.
576 Cuids are numbers assigned to insns, like uids,
577 except that cuids increase monotonically through the code.
579 Scan all SETs and see if we can deduce anything about what
580 bits are known to be zero for some registers and how many copies
581 of the sign bit are known to exist for those registers.
583 Also set any known values so that we can use it while searching
584 for what bits are known to be set. */
588 setup_incoming_promotions ();
590 refresh_blocks
= sbitmap_alloc (last_basic_block
);
591 sbitmap_zero (refresh_blocks
);
593 for (insn
= f
, i
= 0; insn
; insn
= NEXT_INSN (insn
))
595 uid_cuid
[INSN_UID (insn
)] = ++i
;
601 note_stores (PATTERN (insn
), set_nonzero_bits_and_sign_copies
,
603 record_dead_and_set_regs (insn
);
606 for (links
= REG_NOTES (insn
); links
; links
= XEXP (links
, 1))
607 if (REG_NOTE_KIND (links
) == REG_INC
)
608 set_nonzero_bits_and_sign_copies (XEXP (links
, 0), NULL_RTX
,
613 if (GET_CODE (insn
) == CODE_LABEL
)
617 nonzero_sign_valid
= 1;
619 /* Now scan all the insns in forward order. */
624 init_reg_last_arrays ();
625 setup_incoming_promotions ();
627 FOR_EACH_BB (this_basic_block
)
629 for (insn
= this_basic_block
->head
;
630 insn
!= NEXT_INSN (this_basic_block
->end
);
631 insn
= next
? next
: NEXT_INSN (insn
))
635 if (GET_CODE (insn
) == CODE_LABEL
)
638 else if (INSN_P (insn
))
640 /* See if we know about function return values before this
641 insn based upon SUBREG flags. */
642 check_promoted_subreg (insn
, PATTERN (insn
));
644 /* Try this insn with each insn it links back to. */
646 for (links
= LOG_LINKS (insn
); links
; links
= XEXP (links
, 1))
647 if ((next
= try_combine (insn
, XEXP (links
, 0),
648 NULL_RTX
, &new_direct_jump_p
)) != 0)
651 /* Try each sequence of three linked insns ending with this one. */
653 for (links
= LOG_LINKS (insn
); links
; links
= XEXP (links
, 1))
655 rtx link
= XEXP (links
, 0);
657 /* If the linked insn has been replaced by a note, then there
658 is no point in pursuing this chain any further. */
659 if (GET_CODE (link
) == NOTE
)
662 for (nextlinks
= LOG_LINKS (link
);
664 nextlinks
= XEXP (nextlinks
, 1))
665 if ((next
= try_combine (insn
, link
,
667 &new_direct_jump_p
)) != 0)
672 /* Try to combine a jump insn that uses CC0
673 with a preceding insn that sets CC0, and maybe with its
674 logical predecessor as well.
675 This is how we make decrement-and-branch insns.
676 We need this special code because data flow connections
677 via CC0 do not get entered in LOG_LINKS. */
679 if (GET_CODE (insn
) == JUMP_INSN
680 && (prev
= prev_nonnote_insn (insn
)) != 0
681 && GET_CODE (prev
) == INSN
682 && sets_cc0_p (PATTERN (prev
)))
684 if ((next
= try_combine (insn
, prev
,
685 NULL_RTX
, &new_direct_jump_p
)) != 0)
688 for (nextlinks
= LOG_LINKS (prev
); nextlinks
;
689 nextlinks
= XEXP (nextlinks
, 1))
690 if ((next
= try_combine (insn
, prev
,
692 &new_direct_jump_p
)) != 0)
696 /* Do the same for an insn that explicitly references CC0. */
697 if (GET_CODE (insn
) == INSN
698 && (prev
= prev_nonnote_insn (insn
)) != 0
699 && GET_CODE (prev
) == INSN
700 && sets_cc0_p (PATTERN (prev
))
701 && GET_CODE (PATTERN (insn
)) == SET
702 && reg_mentioned_p (cc0_rtx
, SET_SRC (PATTERN (insn
))))
704 if ((next
= try_combine (insn
, prev
,
705 NULL_RTX
, &new_direct_jump_p
)) != 0)
708 for (nextlinks
= LOG_LINKS (prev
); nextlinks
;
709 nextlinks
= XEXP (nextlinks
, 1))
710 if ((next
= try_combine (insn
, prev
,
712 &new_direct_jump_p
)) != 0)
716 /* Finally, see if any of the insns that this insn links to
717 explicitly references CC0. If so, try this insn, that insn,
718 and its predecessor if it sets CC0. */
719 for (links
= LOG_LINKS (insn
); links
; links
= XEXP (links
, 1))
720 if (GET_CODE (XEXP (links
, 0)) == INSN
721 && GET_CODE (PATTERN (XEXP (links
, 0))) == SET
722 && reg_mentioned_p (cc0_rtx
, SET_SRC (PATTERN (XEXP (links
, 0))))
723 && (prev
= prev_nonnote_insn (XEXP (links
, 0))) != 0
724 && GET_CODE (prev
) == INSN
725 && sets_cc0_p (PATTERN (prev
))
726 && (next
= try_combine (insn
, XEXP (links
, 0),
727 prev
, &new_direct_jump_p
)) != 0)
731 /* Try combining an insn with two different insns whose results it
733 for (links
= LOG_LINKS (insn
); links
; links
= XEXP (links
, 1))
734 for (nextlinks
= XEXP (links
, 1); nextlinks
;
735 nextlinks
= XEXP (nextlinks
, 1))
736 if ((next
= try_combine (insn
, XEXP (links
, 0),
738 &new_direct_jump_p
)) != 0)
741 if (GET_CODE (insn
) != NOTE
)
742 record_dead_and_set_regs (insn
);
751 EXECUTE_IF_SET_IN_SBITMAP (refresh_blocks
, 0, i
,
752 BASIC_BLOCK (i
)->flags
|= BB_DIRTY
);
753 new_direct_jump_p
|= purge_all_dead_edges (0);
754 delete_noop_moves (f
);
756 update_life_info_in_dirty_blocks (UPDATE_LIFE_GLOBAL_RM_NOTES
,
757 PROP_DEATH_NOTES
| PROP_SCAN_DEAD_CODE
758 | PROP_KILL_DEAD_CODE
);
761 sbitmap_free (refresh_blocks
);
762 free (reg_nonzero_bits
);
763 free (reg_sign_bit_copies
);
764 free (reg_last_death
);
766 free (reg_last_set_value
);
767 free (reg_last_set_table_tick
);
768 free (reg_last_set_label
);
769 free (reg_last_set_invalid
);
770 free (reg_last_set_mode
);
771 free (reg_last_set_nonzero_bits
);
772 free (reg_last_set_sign_bit_copies
);
776 struct undo
*undo
, *next
;
777 for (undo
= undobuf
.frees
; undo
; undo
= next
)
785 total_attempts
+= combine_attempts
;
786 total_merges
+= combine_merges
;
787 total_extras
+= combine_extras
;
788 total_successes
+= combine_successes
;
790 nonzero_sign_valid
= 0;
792 /* Make recognizer allow volatile MEMs again. */
795 return new_direct_jump_p
;
798 /* Wipe the reg_last_xxx arrays in preparation for another pass. */
801 init_reg_last_arrays ()
803 unsigned int nregs
= combine_max_regno
;
805 memset ((char *) reg_last_death
, 0, nregs
* sizeof (rtx
));
806 memset ((char *) reg_last_set
, 0, nregs
* sizeof (rtx
));
807 memset ((char *) reg_last_set_value
, 0, nregs
* sizeof (rtx
));
808 memset ((char *) reg_last_set_table_tick
, 0, nregs
* sizeof (int));
809 memset ((char *) reg_last_set_label
, 0, nregs
* sizeof (int));
810 memset (reg_last_set_invalid
, 0, nregs
* sizeof (char));
811 memset ((char *) reg_last_set_mode
, 0, nregs
* sizeof (enum machine_mode
));
812 memset ((char *) reg_last_set_nonzero_bits
, 0, nregs
* sizeof (HOST_WIDE_INT
));
813 memset (reg_last_set_sign_bit_copies
, 0, nregs
* sizeof (char));
816 /* Set up any promoted values for incoming argument registers. */
819 setup_incoming_promotions ()
821 #ifdef PROMOTE_FUNCTION_ARGS
824 enum machine_mode mode
;
826 rtx first
= get_insns ();
828 #ifndef OUTGOING_REGNO
829 #define OUTGOING_REGNO(N) N
831 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
832 /* Check whether this register can hold an incoming pointer
833 argument. FUNCTION_ARG_REGNO_P tests outgoing register
834 numbers, so translate if necessary due to register windows. */
835 if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (regno
))
836 && (reg
= promoted_input_arg (regno
, &mode
, &unsignedp
)) != 0)
839 (reg
, first
, gen_rtx_fmt_e ((unsignedp
? ZERO_EXTEND
842 gen_rtx_CLOBBER (mode
, const0_rtx
)));
847 /* Called via note_stores. If X is a pseudo that is narrower than
848 HOST_BITS_PER_WIDE_INT and is being set, record what bits are known zero.
850 If we are setting only a portion of X and we can't figure out what
851 portion, assume all bits will be used since we don't know what will
854 Similarly, set how many bits of X are known to be copies of the sign bit
855 at all locations in the function. This is the smallest number implied
859 set_nonzero_bits_and_sign_copies (x
, set
, data
)
862 void *data ATTRIBUTE_UNUSED
;
866 if (GET_CODE (x
) == REG
867 && REGNO (x
) >= FIRST_PSEUDO_REGISTER
868 /* If this register is undefined at the start of the file, we can't
869 say what its contents were. */
870 && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR
->next_bb
->global_live_at_start
, REGNO (x
))
871 && GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
)
873 if (set
== 0 || GET_CODE (set
) == CLOBBER
)
875 reg_nonzero_bits
[REGNO (x
)] = GET_MODE_MASK (GET_MODE (x
));
876 reg_sign_bit_copies
[REGNO (x
)] = 1;
880 /* If this is a complex assignment, see if we can convert it into a
881 simple assignment. */
882 set
= expand_field_assignment (set
);
884 /* If this is a simple assignment, or we have a paradoxical SUBREG,
885 set what we know about X. */
887 if (SET_DEST (set
) == x
888 || (GET_CODE (SET_DEST (set
)) == SUBREG
889 && (GET_MODE_SIZE (GET_MODE (SET_DEST (set
)))
890 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (set
)))))
891 && SUBREG_REG (SET_DEST (set
)) == x
))
893 rtx src
= SET_SRC (set
);
895 #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
896 /* If X is narrower than a word and SRC is a non-negative
897 constant that would appear negative in the mode of X,
898 sign-extend it for use in reg_nonzero_bits because some
899 machines (maybe most) will actually do the sign-extension
900 and this is the conservative approach.
902 ??? For 2.5, try to tighten up the MD files in this regard
903 instead of this kludge. */
905 if (GET_MODE_BITSIZE (GET_MODE (x
)) < BITS_PER_WORD
906 && GET_CODE (src
) == CONST_INT
908 && 0 != (INTVAL (src
)
910 << (GET_MODE_BITSIZE (GET_MODE (x
)) - 1))))
911 src
= GEN_INT (INTVAL (src
)
912 | ((HOST_WIDE_INT
) (-1)
913 << GET_MODE_BITSIZE (GET_MODE (x
))));
916 /* Don't call nonzero_bits if it cannot change anything. */
917 if (reg_nonzero_bits
[REGNO (x
)] != ~(unsigned HOST_WIDE_INT
) 0)
918 reg_nonzero_bits
[REGNO (x
)]
919 |= nonzero_bits (src
, nonzero_bits_mode
);
920 num
= num_sign_bit_copies (SET_SRC (set
), GET_MODE (x
));
921 if (reg_sign_bit_copies
[REGNO (x
)] == 0
922 || reg_sign_bit_copies
[REGNO (x
)] > num
)
923 reg_sign_bit_copies
[REGNO (x
)] = num
;
927 reg_nonzero_bits
[REGNO (x
)] = GET_MODE_MASK (GET_MODE (x
));
928 reg_sign_bit_copies
[REGNO (x
)] = 1;
933 /* See if INSN can be combined into I3. PRED and SUCC are optionally
934 insns that were previously combined into I3 or that will be combined
935 into the merger of INSN and I3.
937 Return 0 if the combination is not allowed for any reason.
939 If the combination is allowed, *PDEST will be set to the single
940 destination of INSN and *PSRC to the single source, and this function
944 can_combine_p (insn
, i3
, pred
, succ
, pdest
, psrc
)
947 rtx pred ATTRIBUTE_UNUSED
;
952 rtx set
= 0, src
, dest
;
957 int all_adjacent
= (succ
? (next_active_insn (insn
) == succ
958 && next_active_insn (succ
) == i3
)
959 : next_active_insn (insn
) == i3
);
961 /* Can combine only if previous insn is a SET of a REG, a SUBREG or CC0.
962 or a PARALLEL consisting of such a SET and CLOBBERs.
964 If INSN has CLOBBER parallel parts, ignore them for our processing.
965 By definition, these happen during the execution of the insn. When it
966 is merged with another insn, all bets are off. If they are, in fact,
967 needed and aren't also supplied in I3, they may be added by
968 recog_for_combine. Otherwise, it won't match.
970 We can also ignore a SET whose SET_DEST is mentioned in a REG_UNUSED
973 Get the source and destination of INSN. If more than one, can't
976 if (GET_CODE (PATTERN (insn
)) == SET
)
977 set
= PATTERN (insn
);
978 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
979 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
981 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
983 rtx elt
= XVECEXP (PATTERN (insn
), 0, i
);
985 switch (GET_CODE (elt
))
987 /* This is important to combine floating point insns
990 /* Combining an isolated USE doesn't make sense.
991 We depend here on combinable_i3pat to reject them. */
992 /* The code below this loop only verifies that the inputs of
993 the SET in INSN do not change. We call reg_set_between_p
994 to verify that the REG in the USE does not change between
996 If the USE in INSN was for a pseudo register, the matching
997 insn pattern will likely match any register; combining this
998 with any other USE would only be safe if we knew that the
999 used registers have identical values, or if there was
1000 something to tell them apart, e.g. different modes. For
1001 now, we forgo such complicated tests and simply disallow
1002 combining of USES of pseudo registers with any other USE. */
1003 if (GET_CODE (XEXP (elt
, 0)) == REG
1004 && GET_CODE (PATTERN (i3
)) == PARALLEL
)
1006 rtx i3pat
= PATTERN (i3
);
1007 int i
= XVECLEN (i3pat
, 0) - 1;
1008 unsigned int regno
= REGNO (XEXP (elt
, 0));
1012 rtx i3elt
= XVECEXP (i3pat
, 0, i
);
1014 if (GET_CODE (i3elt
) == USE
1015 && GET_CODE (XEXP (i3elt
, 0)) == REG
1016 && (REGNO (XEXP (i3elt
, 0)) == regno
1017 ? reg_set_between_p (XEXP (elt
, 0),
1018 PREV_INSN (insn
), i3
)
1019 : regno
>= FIRST_PSEUDO_REGISTER
))
1026 /* We can ignore CLOBBERs. */
1031 /* Ignore SETs whose result isn't used but not those that
1032 have side-effects. */
1033 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (elt
))
1034 && ! side_effects_p (elt
))
1037 /* If we have already found a SET, this is a second one and
1038 so we cannot combine with this insn. */
1046 /* Anything else means we can't combine. */
1052 /* If SET_SRC is an ASM_OPERANDS we can't throw away these CLOBBERs,
1053 so don't do anything with it. */
1054 || GET_CODE (SET_SRC (set
)) == ASM_OPERANDS
)
1063 set
= expand_field_assignment (set
);
1064 src
= SET_SRC (set
), dest
= SET_DEST (set
);
1066 /* Don't eliminate a store in the stack pointer. */
1067 if (dest
== stack_pointer_rtx
1068 /* Don't combine with an insn that sets a register to itself if it has
1069 a REG_EQUAL note. This may be part of a REG_NO_CONFLICT sequence. */
1070 || (rtx_equal_p (src
, dest
) && find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1071 /* Can't merge an ASM_OPERANDS. */
1072 || GET_CODE (src
) == ASM_OPERANDS
1073 /* Can't merge a function call. */
1074 || GET_CODE (src
) == CALL
1075 /* Don't eliminate a function call argument. */
1076 || (GET_CODE (i3
) == CALL_INSN
1077 && (find_reg_fusage (i3
, USE
, dest
)
1078 || (GET_CODE (dest
) == REG
1079 && REGNO (dest
) < FIRST_PSEUDO_REGISTER
1080 && global_regs
[REGNO (dest
)])))
1081 /* Don't substitute into an incremented register. */
1082 || FIND_REG_INC_NOTE (i3
, dest
)
1083 || (succ
&& FIND_REG_INC_NOTE (succ
, dest
))
1085 /* Don't combine the end of a libcall into anything. */
1086 /* ??? This gives worse code, and appears to be unnecessary, since no
1087 pass after flow uses REG_LIBCALL/REG_RETVAL notes. Local-alloc does
1088 use REG_RETVAL notes for noconflict blocks, but other code here
1089 makes sure that those insns don't disappear. */
1090 || find_reg_note (insn
, REG_RETVAL
, NULL_RTX
)
1092 /* Make sure that DEST is not used after SUCC but before I3. */
1093 || (succ
&& ! all_adjacent
1094 && reg_used_between_p (dest
, succ
, i3
))
1095 /* Make sure that the value that is to be substituted for the register
1096 does not use any registers whose values alter in between. However,
1097 If the insns are adjacent, a use can't cross a set even though we
1098 think it might (this can happen for a sequence of insns each setting
1099 the same destination; reg_last_set of that register might point to
1100 a NOTE). If INSN has a REG_EQUIV note, the register is always
1101 equivalent to the memory so the substitution is valid even if there
1102 are intervening stores. Also, don't move a volatile asm or
1103 UNSPEC_VOLATILE across any other insns. */
1105 && (((GET_CODE (src
) != MEM
1106 || ! find_reg_note (insn
, REG_EQUIV
, src
))
1107 && use_crosses_set_p (src
, INSN_CUID (insn
)))
1108 || (GET_CODE (src
) == ASM_OPERANDS
&& MEM_VOLATILE_P (src
))
1109 || GET_CODE (src
) == UNSPEC_VOLATILE
))
1110 /* If there is a REG_NO_CONFLICT note for DEST in I3 or SUCC, we get
1111 better register allocation by not doing the combine. */
1112 || find_reg_note (i3
, REG_NO_CONFLICT
, dest
)
1113 || (succ
&& find_reg_note (succ
, REG_NO_CONFLICT
, dest
))
1114 /* Don't combine across a CALL_INSN, because that would possibly
1115 change whether the life span of some REGs crosses calls or not,
1116 and it is a pain to update that information.
1117 Exception: if source is a constant, moving it later can't hurt.
1118 Accept that special case, because it helps -fforce-addr a lot. */
1119 || (INSN_CUID (insn
) < last_call_cuid
&& ! CONSTANT_P (src
)))
1122 /* DEST must either be a REG or CC0. */
1123 if (GET_CODE (dest
) == REG
)
1125 /* If register alignment is being enforced for multi-word items in all
1126 cases except for parameters, it is possible to have a register copy
1127 insn referencing a hard register that is not allowed to contain the
1128 mode being copied and which would not be valid as an operand of most
1129 insns. Eliminate this problem by not combining with such an insn.
1131 Also, on some machines we don't want to extend the life of a hard
1134 if (GET_CODE (src
) == REG
1135 && ((REGNO (dest
) < FIRST_PSEUDO_REGISTER
1136 && ! HARD_REGNO_MODE_OK (REGNO (dest
), GET_MODE (dest
)))
1137 /* Don't extend the life of a hard register unless it is
1138 user variable (if we have few registers) or it can't
1139 fit into the desired register (meaning something special
1141 Also avoid substituting a return register into I3, because
1142 reload can't handle a conflict with constraints of other
1144 || (REGNO (src
) < FIRST_PSEUDO_REGISTER
1145 && ! HARD_REGNO_MODE_OK (REGNO (src
), GET_MODE (src
)))))
1148 else if (GET_CODE (dest
) != CC0
)
1151 /* Don't substitute for a register intended as a clobberable operand.
1152 Similarly, don't substitute an expression containing a register that
1153 will be clobbered in I3. */
1154 if (GET_CODE (PATTERN (i3
)) == PARALLEL
)
1155 for (i
= XVECLEN (PATTERN (i3
), 0) - 1; i
>= 0; i
--)
1156 if (GET_CODE (XVECEXP (PATTERN (i3
), 0, i
)) == CLOBBER
1157 && (reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (i3
), 0, i
), 0),
1159 || rtx_equal_p (XEXP (XVECEXP (PATTERN (i3
), 0, i
), 0), dest
)))
1162 /* If INSN contains anything volatile, or is an `asm' (whether volatile
1163 or not), reject, unless nothing volatile comes between it and I3 */
1165 if (GET_CODE (src
) == ASM_OPERANDS
|| volatile_refs_p (src
))
1167 /* Make sure succ doesn't contain a volatile reference. */
1168 if (succ
!= 0 && volatile_refs_p (PATTERN (succ
)))
1171 for (p
= NEXT_INSN (insn
); p
!= i3
; p
= NEXT_INSN (p
))
1172 if (INSN_P (p
) && p
!= succ
&& volatile_refs_p (PATTERN (p
)))
1176 /* If INSN is an asm, and DEST is a hard register, reject, since it has
1177 to be an explicit register variable, and was chosen for a reason. */
1179 if (GET_CODE (src
) == ASM_OPERANDS
1180 && GET_CODE (dest
) == REG
&& REGNO (dest
) < FIRST_PSEUDO_REGISTER
)
1183 /* If there are any volatile insns between INSN and I3, reject, because
1184 they might affect machine state. */
1186 for (p
= NEXT_INSN (insn
); p
!= i3
; p
= NEXT_INSN (p
))
1187 if (INSN_P (p
) && p
!= succ
&& volatile_insn_p (PATTERN (p
)))
1190 /* If INSN or I2 contains an autoincrement or autodecrement,
1191 make sure that register is not used between there and I3,
1192 and not already used in I3 either.
1193 Also insist that I3 not be a jump; if it were one
1194 and the incremented register were spilled, we would lose. */
1197 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1198 if (REG_NOTE_KIND (link
) == REG_INC
1199 && (GET_CODE (i3
) == JUMP_INSN
1200 || reg_used_between_p (XEXP (link
, 0), insn
, i3
)
1201 || reg_overlap_mentioned_p (XEXP (link
, 0), PATTERN (i3
))))
1206 /* Don't combine an insn that follows a CC0-setting insn.
1207 An insn that uses CC0 must not be separated from the one that sets it.
1208 We do, however, allow I2 to follow a CC0-setting insn if that insn
1209 is passed as I1; in that case it will be deleted also.
1210 We also allow combining in this case if all the insns are adjacent
1211 because that would leave the two CC0 insns adjacent as well.
1212 It would be more logical to test whether CC0 occurs inside I1 or I2,
1213 but that would be much slower, and this ought to be equivalent. */
1215 p
= prev_nonnote_insn (insn
);
1216 if (p
&& p
!= pred
&& GET_CODE (p
) == INSN
&& sets_cc0_p (PATTERN (p
))
1221 /* If we get here, we have passed all the tests and the combination is
1230 /* Check if PAT is an insn - or a part of it - used to set up an
1231 argument for a function in a hard register. */
1234 sets_function_arg_p (pat
)
1240 switch (GET_CODE (pat
))
1243 return sets_function_arg_p (PATTERN (pat
));
1246 for (i
= XVECLEN (pat
, 0); --i
>= 0;)
1247 if (sets_function_arg_p (XVECEXP (pat
, 0, i
)))
1253 inner_dest
= SET_DEST (pat
);
1254 while (GET_CODE (inner_dest
) == STRICT_LOW_PART
1255 || GET_CODE (inner_dest
) == SUBREG
1256 || GET_CODE (inner_dest
) == ZERO_EXTRACT
)
1257 inner_dest
= XEXP (inner_dest
, 0);
1259 return (GET_CODE (inner_dest
) == REG
1260 && REGNO (inner_dest
) < FIRST_PSEUDO_REGISTER
1261 && FUNCTION_ARG_REGNO_P (REGNO (inner_dest
)));
1270 /* LOC is the location within I3 that contains its pattern or the component
1271 of a PARALLEL of the pattern. We validate that it is valid for combining.
1273 One problem is if I3 modifies its output, as opposed to replacing it
1274 entirely, we can't allow the output to contain I2DEST or I1DEST as doing
1275 so would produce an insn that is not equivalent to the original insns.
1279 (set (reg:DI 101) (reg:DI 100))
1280 (set (subreg:SI (reg:DI 101) 0) <foo>)
1282 This is NOT equivalent to:
1284 (parallel [(set (subreg:SI (reg:DI 100) 0) <foo>)
1285 (set (reg:DI 101) (reg:DI 100))])
1287 Not only does this modify 100 (in which case it might still be valid
1288 if 100 were dead in I2), it sets 101 to the ORIGINAL value of 100.
1290 We can also run into a problem if I2 sets a register that I1
1291 uses and I1 gets directly substituted into I3 (not via I2). In that
1292 case, we would be getting the wrong value of I2DEST into I3, so we
1293 must reject the combination. This case occurs when I2 and I1 both
1294 feed into I3, rather than when I1 feeds into I2, which feeds into I3.
1295 If I1_NOT_IN_SRC is nonzero, it means that finding I1 in the source
1296 of a SET must prevent combination from occurring.
1298 Before doing the above check, we first try to expand a field assignment
1299 into a set of logical operations.
1301 If PI3_DEST_KILLED is nonzero, it is a pointer to a location in which
1302 we place a register that is both set and used within I3. If more than one
1303 such register is detected, we fail.
1305 Return 1 if the combination is valid, zero otherwise. */
1308 combinable_i3pat (i3
, loc
, i2dest
, i1dest
, i1_not_in_src
, pi3dest_killed
)
1314 rtx
*pi3dest_killed
;
1318 if (GET_CODE (x
) == SET
)
1321 rtx dest
= SET_DEST (set
);
1322 rtx src
= SET_SRC (set
);
1323 rtx inner_dest
= dest
;
1325 while (GET_CODE (inner_dest
) == STRICT_LOW_PART
1326 || GET_CODE (inner_dest
) == SUBREG
1327 || GET_CODE (inner_dest
) == ZERO_EXTRACT
)
1328 inner_dest
= XEXP (inner_dest
, 0);
1330 /* Check for the case where I3 modifies its output, as
1332 if ((inner_dest
!= dest
1333 && (reg_overlap_mentioned_p (i2dest
, inner_dest
)
1334 || (i1dest
&& reg_overlap_mentioned_p (i1dest
, inner_dest
))))
1336 /* This is the same test done in can_combine_p except we can't test
1337 all_adjacent; we don't have to, since this instruction will stay
1338 in place, thus we are not considering increasing the lifetime of
1341 Also, if this insn sets a function argument, combining it with
1342 something that might need a spill could clobber a previous
1343 function argument; the all_adjacent test in can_combine_p also
1344 checks this; here, we do a more specific test for this case. */
1346 || (GET_CODE (inner_dest
) == REG
1347 && REGNO (inner_dest
) < FIRST_PSEUDO_REGISTER
1348 && (! HARD_REGNO_MODE_OK (REGNO (inner_dest
),
1349 GET_MODE (inner_dest
))))
1350 || (i1_not_in_src
&& reg_overlap_mentioned_p (i1dest
, src
)))
1353 /* If DEST is used in I3, it is being killed in this insn,
1354 so record that for later.
1355 Never add REG_DEAD notes for the FRAME_POINTER_REGNUM or the
1356 STACK_POINTER_REGNUM, since these are always considered to be
1357 live. Similarly for ARG_POINTER_REGNUM if it is fixed. */
1358 if (pi3dest_killed
&& GET_CODE (dest
) == REG
1359 && reg_referenced_p (dest
, PATTERN (i3
))
1360 && REGNO (dest
) != FRAME_POINTER_REGNUM
1361 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
1362 && REGNO (dest
) != HARD_FRAME_POINTER_REGNUM
1364 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
1365 && (REGNO (dest
) != ARG_POINTER_REGNUM
1366 || ! fixed_regs
[REGNO (dest
)])
1368 && REGNO (dest
) != STACK_POINTER_REGNUM
)
1370 if (*pi3dest_killed
)
1373 *pi3dest_killed
= dest
;
1377 else if (GET_CODE (x
) == PARALLEL
)
1381 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
1382 if (! combinable_i3pat (i3
, &XVECEXP (x
, 0, i
), i2dest
, i1dest
,
1383 i1_not_in_src
, pi3dest_killed
))
1390 /* Return 1 if X is an arithmetic expression that contains a multiplication
1391 and division. We don't count multiplications by powers of two here. */
1397 switch (GET_CODE (x
))
1399 case MOD
: case DIV
: case UMOD
: case UDIV
:
1403 return ! (GET_CODE (XEXP (x
, 1)) == CONST_INT
1404 && exact_log2 (INTVAL (XEXP (x
, 1))) >= 0);
1406 switch (GET_RTX_CLASS (GET_CODE (x
)))
1408 case 'c': case '<': case '2':
1409 return contains_muldiv (XEXP (x
, 0))
1410 || contains_muldiv (XEXP (x
, 1));
1413 return contains_muldiv (XEXP (x
, 0));
1421 /* Determine whether INSN can be used in a combination. Return nonzero if
1422 not. This is used in try_combine to detect early some cases where we
1423 can't perform combinations. */
1426 cant_combine_insn_p (insn
)
1432 /* If this isn't really an insn, we can't do anything.
1433 This can occur when flow deletes an insn that it has merged into an
1434 auto-increment address. */
1435 if (! INSN_P (insn
))
1438 /* Never combine loads and stores involving hard regs that are likely
1439 to be spilled. The register allocator can usually handle such
1440 reg-reg moves by tying. If we allow the combiner to make
1441 substitutions of likely-spilled regs, we may abort in reload.
1442 As an exception, we allow combinations involving fixed regs; these are
1443 not available to the register allocator so there's no risk involved. */
1445 set
= single_set (insn
);
1448 src
= SET_SRC (set
);
1449 dest
= SET_DEST (set
);
1450 if (GET_CODE (src
) == SUBREG
)
1451 src
= SUBREG_REG (src
);
1452 if (GET_CODE (dest
) == SUBREG
)
1453 dest
= SUBREG_REG (dest
);
1454 if (REG_P (src
) && REG_P (dest
)
1455 && ((REGNO (src
) < FIRST_PSEUDO_REGISTER
1456 && ! fixed_regs
[REGNO (src
)]
1457 && CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (REGNO (src
))))
1458 || (REGNO (dest
) < FIRST_PSEUDO_REGISTER
1459 && ! fixed_regs
[REGNO (dest
)]
1460 && CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (REGNO (dest
))))))
1466 /* Try to combine the insns I1 and I2 into I3.
1467 Here I1 and I2 appear earlier than I3.
1468 I1 can be zero; then we combine just I2 into I3.
1470 If we are combining three insns and the resulting insn is not recognized,
1471 try splitting it into two insns. If that happens, I2 and I3 are retained
1472 and I1 is pseudo-deleted by turning it into a NOTE. Otherwise, I1 and I2
1475 Return 0 if the combination does not work. Then nothing is changed.
1476 If we did the combination, return the insn at which combine should
1479 Set NEW_DIRECT_JUMP_P to a nonzero value if try_combine creates a
1480 new direct jump instruction. */
1483 try_combine (i3
, i2
, i1
, new_direct_jump_p
)
1485 int *new_direct_jump_p
;
1487 /* New patterns for I3 and I2, respectively. */
1488 rtx newpat
, newi2pat
= 0;
1489 int substed_i2
= 0, substed_i1
= 0;
1490 /* Indicates need to preserve SET in I1 or I2 in I3 if it is not dead. */
1491 int added_sets_1
, added_sets_2
;
1492 /* Total number of SETs to put into I3. */
1494 /* Nonzero is I2's body now appears in I3. */
1496 /* INSN_CODEs for new I3, new I2, and user of condition code. */
1497 int insn_code_number
, i2_code_number
= 0, other_code_number
= 0;
1498 /* Contains I3 if the destination of I3 is used in its source, which means
1499 that the old life of I3 is being killed. If that usage is placed into
1500 I2 and not in I3, a REG_DEAD note must be made. */
1501 rtx i3dest_killed
= 0;
1502 /* SET_DEST and SET_SRC of I2 and I1. */
1503 rtx i2dest
, i2src
, i1dest
= 0, i1src
= 0;
1504 /* PATTERN (I2), or a copy of it in certain cases. */
1506 /* Indicates if I2DEST or I1DEST is in I2SRC or I1_SRC. */
1507 int i2dest_in_i2src
= 0, i1dest_in_i1src
= 0, i2dest_in_i1src
= 0;
1508 int i1_feeds_i3
= 0;
1509 /* Notes that must be added to REG_NOTES in I3 and I2. */
1510 rtx new_i3_notes
, new_i2_notes
;
1511 /* Notes that we substituted I3 into I2 instead of the normal case. */
1512 int i3_subst_into_i2
= 0;
1513 /* Notes that I1, I2 or I3 is a MULT operation. */
1521 /* Exit early if one of the insns involved can't be used for
1523 if (cant_combine_insn_p (i3
)
1524 || cant_combine_insn_p (i2
)
1525 || (i1
&& cant_combine_insn_p (i1
))
1526 /* We also can't do anything if I3 has a
1527 REG_LIBCALL note since we don't want to disrupt the contiguity of a
1530 /* ??? This gives worse code, and appears to be unnecessary, since no
1531 pass after flow uses REG_LIBCALL/REG_RETVAL notes. */
1532 || find_reg_note (i3
, REG_LIBCALL
, NULL_RTX
)
1538 undobuf
.other_insn
= 0;
1540 /* Reset the hard register usage information. */
1541 CLEAR_HARD_REG_SET (newpat_used_regs
);
1543 /* If I1 and I2 both feed I3, they can be in any order. To simplify the
1544 code below, set I1 to be the earlier of the two insns. */
1545 if (i1
&& INSN_CUID (i1
) > INSN_CUID (i2
))
1546 temp
= i1
, i1
= i2
, i2
= temp
;
1548 added_links_insn
= 0;
1550 /* First check for one important special-case that the code below will
1551 not handle. Namely, the case where I1 is zero, I2 is a PARALLEL
1552 and I3 is a SET whose SET_SRC is a SET_DEST in I2. In that case,
1553 we may be able to replace that destination with the destination of I3.
1554 This occurs in the common code where we compute both a quotient and
1555 remainder into a structure, in which case we want to do the computation
1556 directly into the structure to avoid register-register copies.
1558 Note that this case handles both multiple sets in I2 and also
1559 cases where I2 has a number of CLOBBER or PARALLELs.
1561 We make very conservative checks below and only try to handle the
1562 most common cases of this. For example, we only handle the case
1563 where I2 and I3 are adjacent to avoid making difficult register
1566 if (i1
== 0 && GET_CODE (i3
) == INSN
&& GET_CODE (PATTERN (i3
)) == SET
1567 && GET_CODE (SET_SRC (PATTERN (i3
))) == REG
1568 && REGNO (SET_SRC (PATTERN (i3
))) >= FIRST_PSEUDO_REGISTER
1569 && find_reg_note (i3
, REG_DEAD
, SET_SRC (PATTERN (i3
)))
1570 && GET_CODE (PATTERN (i2
)) == PARALLEL
1571 && ! side_effects_p (SET_DEST (PATTERN (i3
)))
1572 /* If the dest of I3 is a ZERO_EXTRACT or STRICT_LOW_PART, the code
1573 below would need to check what is inside (and reg_overlap_mentioned_p
1574 doesn't support those codes anyway). Don't allow those destinations;
1575 the resulting insn isn't likely to be recognized anyway. */
1576 && GET_CODE (SET_DEST (PATTERN (i3
))) != ZERO_EXTRACT
1577 && GET_CODE (SET_DEST (PATTERN (i3
))) != STRICT_LOW_PART
1578 && ! reg_overlap_mentioned_p (SET_SRC (PATTERN (i3
)),
1579 SET_DEST (PATTERN (i3
)))
1580 && next_real_insn (i2
) == i3
)
1582 rtx p2
= PATTERN (i2
);
1584 /* Make sure that the destination of I3,
1585 which we are going to substitute into one output of I2,
1586 is not used within another output of I2. We must avoid making this:
1587 (parallel [(set (mem (reg 69)) ...)
1588 (set (reg 69) ...)])
1589 which is not well-defined as to order of actions.
1590 (Besides, reload can't handle output reloads for this.)
1592 The problem can also happen if the dest of I3 is a memory ref,
1593 if another dest in I2 is an indirect memory ref. */
1594 for (i
= 0; i
< XVECLEN (p2
, 0); i
++)
1595 if ((GET_CODE (XVECEXP (p2
, 0, i
)) == SET
1596 || GET_CODE (XVECEXP (p2
, 0, i
)) == CLOBBER
)
1597 && reg_overlap_mentioned_p (SET_DEST (PATTERN (i3
)),
1598 SET_DEST (XVECEXP (p2
, 0, i
))))
1601 if (i
== XVECLEN (p2
, 0))
1602 for (i
= 0; i
< XVECLEN (p2
, 0); i
++)
1603 if ((GET_CODE (XVECEXP (p2
, 0, i
)) == SET
1604 || GET_CODE (XVECEXP (p2
, 0, i
)) == CLOBBER
)
1605 && SET_DEST (XVECEXP (p2
, 0, i
)) == SET_SRC (PATTERN (i3
)))
1610 subst_low_cuid
= INSN_CUID (i2
);
1612 added_sets_2
= added_sets_1
= 0;
1613 i2dest
= SET_SRC (PATTERN (i3
));
1615 /* Replace the dest in I2 with our dest and make the resulting
1616 insn the new pattern for I3. Then skip to where we
1617 validate the pattern. Everything was set up above. */
1618 SUBST (SET_DEST (XVECEXP (p2
, 0, i
)),
1619 SET_DEST (PATTERN (i3
)));
1622 i3_subst_into_i2
= 1;
1623 goto validate_replacement
;
1627 /* If I2 is setting a double-word pseudo to a constant and I3 is setting
1628 one of those words to another constant, merge them by making a new
1631 && (temp
= single_set (i2
)) != 0
1632 && (GET_CODE (SET_SRC (temp
)) == CONST_INT
1633 || GET_CODE (SET_SRC (temp
)) == CONST_DOUBLE
)
1634 && GET_CODE (SET_DEST (temp
)) == REG
1635 && GET_MODE_CLASS (GET_MODE (SET_DEST (temp
))) == MODE_INT
1636 && GET_MODE_SIZE (GET_MODE (SET_DEST (temp
))) == 2 * UNITS_PER_WORD
1637 && GET_CODE (PATTERN (i3
)) == SET
1638 && GET_CODE (SET_DEST (PATTERN (i3
))) == SUBREG
1639 && SUBREG_REG (SET_DEST (PATTERN (i3
))) == SET_DEST (temp
)
1640 && GET_MODE_CLASS (GET_MODE (SET_DEST (PATTERN (i3
)))) == MODE_INT
1641 && GET_MODE_SIZE (GET_MODE (SET_DEST (PATTERN (i3
)))) == UNITS_PER_WORD
1642 && GET_CODE (SET_SRC (PATTERN (i3
))) == CONST_INT
)
1644 HOST_WIDE_INT lo
, hi
;
1646 if (GET_CODE (SET_SRC (temp
)) == CONST_INT
)
1647 lo
= INTVAL (SET_SRC (temp
)), hi
= lo
< 0 ? -1 : 0;
1650 lo
= CONST_DOUBLE_LOW (SET_SRC (temp
));
1651 hi
= CONST_DOUBLE_HIGH (SET_SRC (temp
));
1654 if (subreg_lowpart_p (SET_DEST (PATTERN (i3
))))
1656 /* We don't handle the case of the target word being wider
1657 than a host wide int. */
1658 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_WORD
)
1661 lo
&= ~(UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD (1) - 1);
1662 lo
|= (INTVAL (SET_SRC (PATTERN (i3
)))
1663 & (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD (1) - 1));
1665 else if (HOST_BITS_PER_WIDE_INT
== BITS_PER_WORD
)
1666 hi
= INTVAL (SET_SRC (PATTERN (i3
)));
1667 else if (HOST_BITS_PER_WIDE_INT
>= 2 * BITS_PER_WORD
)
1669 int sign
= -(int) ((unsigned HOST_WIDE_INT
) lo
1670 >> (HOST_BITS_PER_WIDE_INT
- 1));
1672 lo
&= ~ (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD
1673 (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD (1) - 1));
1674 lo
|= (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD
1675 (INTVAL (SET_SRC (PATTERN (i3
)))));
1677 hi
= lo
< 0 ? -1 : 0;
1680 /* We don't handle the case of the higher word not fitting
1681 entirely in either hi or lo. */
1686 subst_low_cuid
= INSN_CUID (i2
);
1687 added_sets_2
= added_sets_1
= 0;
1688 i2dest
= SET_DEST (temp
);
1690 SUBST (SET_SRC (temp
),
1691 immed_double_const (lo
, hi
, GET_MODE (SET_DEST (temp
))));
1693 newpat
= PATTERN (i2
);
1694 goto validate_replacement
;
1698 /* If we have no I1 and I2 looks like:
1699 (parallel [(set (reg:CC X) (compare:CC OP (const_int 0)))
1701 make up a dummy I1 that is
1704 (set (reg:CC X) (compare:CC Y (const_int 0)))
1706 (We can ignore any trailing CLOBBERs.)
1708 This undoes a previous combination and allows us to match a branch-and-
1711 if (i1
== 0 && GET_CODE (PATTERN (i2
)) == PARALLEL
1712 && XVECLEN (PATTERN (i2
), 0) >= 2
1713 && GET_CODE (XVECEXP (PATTERN (i2
), 0, 0)) == SET
1714 && (GET_MODE_CLASS (GET_MODE (SET_DEST (XVECEXP (PATTERN (i2
), 0, 0))))
1716 && GET_CODE (SET_SRC (XVECEXP (PATTERN (i2
), 0, 0))) == COMPARE
1717 && XEXP (SET_SRC (XVECEXP (PATTERN (i2
), 0, 0)), 1) == const0_rtx
1718 && GET_CODE (XVECEXP (PATTERN (i2
), 0, 1)) == SET
1719 && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2
), 0, 1))) == REG
1720 && rtx_equal_p (XEXP (SET_SRC (XVECEXP (PATTERN (i2
), 0, 0)), 0),
1721 SET_SRC (XVECEXP (PATTERN (i2
), 0, 1))))
1723 for (i
= XVECLEN (PATTERN (i2
), 0) - 1; i
>= 2; i
--)
1724 if (GET_CODE (XVECEXP (PATTERN (i2
), 0, i
)) != CLOBBER
)
1729 /* We make I1 with the same INSN_UID as I2. This gives it
1730 the same INSN_CUID for value tracking. Our fake I1 will
1731 never appear in the insn stream so giving it the same INSN_UID
1732 as I2 will not cause a problem. */
1734 i1
= gen_rtx_INSN (VOIDmode
, INSN_UID (i2
), NULL_RTX
, i2
,
1735 BLOCK_FOR_INSN (i2
), INSN_SCOPE (i2
),
1736 XVECEXP (PATTERN (i2
), 0, 1), -1, NULL_RTX
,
1739 SUBST (PATTERN (i2
), XVECEXP (PATTERN (i2
), 0, 0));
1740 SUBST (XEXP (SET_SRC (PATTERN (i2
)), 0),
1741 SET_DEST (PATTERN (i1
)));
1746 /* Verify that I2 and I1 are valid for combining. */
1747 if (! can_combine_p (i2
, i3
, i1
, NULL_RTX
, &i2dest
, &i2src
)
1748 || (i1
&& ! can_combine_p (i1
, i3
, NULL_RTX
, i2
, &i1dest
, &i1src
)))
1754 /* Record whether I2DEST is used in I2SRC and similarly for the other
1755 cases. Knowing this will help in register status updating below. */
1756 i2dest_in_i2src
= reg_overlap_mentioned_p (i2dest
, i2src
);
1757 i1dest_in_i1src
= i1
&& reg_overlap_mentioned_p (i1dest
, i1src
);
1758 i2dest_in_i1src
= i1
&& reg_overlap_mentioned_p (i2dest
, i1src
);
1760 /* See if I1 directly feeds into I3. It does if I1DEST is not used
1762 i1_feeds_i3
= i1
&& ! reg_overlap_mentioned_p (i1dest
, i2src
);
1764 /* Ensure that I3's pattern can be the destination of combines. */
1765 if (! combinable_i3pat (i3
, &PATTERN (i3
), i2dest
, i1dest
,
1766 i1
&& i2dest_in_i1src
&& i1_feeds_i3
,
1773 /* See if any of the insns is a MULT operation. Unless one is, we will
1774 reject a combination that is, since it must be slower. Be conservative
1776 if (GET_CODE (i2src
) == MULT
1777 || (i1
!= 0 && GET_CODE (i1src
) == MULT
)
1778 || (GET_CODE (PATTERN (i3
)) == SET
1779 && GET_CODE (SET_SRC (PATTERN (i3
))) == MULT
))
1782 /* If I3 has an inc, then give up if I1 or I2 uses the reg that is inc'd.
1783 We used to do this EXCEPT in one case: I3 has a post-inc in an
1784 output operand. However, that exception can give rise to insns like
1786 which is a famous insn on the PDP-11 where the value of r3 used as the
1787 source was model-dependent. Avoid this sort of thing. */
1790 if (!(GET_CODE (PATTERN (i3
)) == SET
1791 && GET_CODE (SET_SRC (PATTERN (i3
))) == REG
1792 && GET_CODE (SET_DEST (PATTERN (i3
))) == MEM
1793 && (GET_CODE (XEXP (SET_DEST (PATTERN (i3
)), 0)) == POST_INC
1794 || GET_CODE (XEXP (SET_DEST (PATTERN (i3
)), 0)) == POST_DEC
)))
1795 /* It's not the exception. */
1798 for (link
= REG_NOTES (i3
); link
; link
= XEXP (link
, 1))
1799 if (REG_NOTE_KIND (link
) == REG_INC
1800 && (reg_overlap_mentioned_p (XEXP (link
, 0), PATTERN (i2
))
1802 && reg_overlap_mentioned_p (XEXP (link
, 0), PATTERN (i1
)))))
1809 /* See if the SETs in I1 or I2 need to be kept around in the merged
1810 instruction: whenever the value set there is still needed past I3.
1811 For the SETs in I2, this is easy: we see if I2DEST dies or is set in I3.
1813 For the SET in I1, we have two cases: If I1 and I2 independently
1814 feed into I3, the set in I1 needs to be kept around if I1DEST dies
1815 or is set in I3. Otherwise (if I1 feeds I2 which feeds I3), the set
1816 in I1 needs to be kept around unless I1DEST dies or is set in either
1817 I2 or I3. We can distinguish these cases by seeing if I2SRC mentions
1818 I1DEST. If so, we know I1 feeds into I2. */
1820 added_sets_2
= ! dead_or_set_p (i3
, i2dest
);
1823 = i1
&& ! (i1_feeds_i3
? dead_or_set_p (i3
, i1dest
)
1824 : (dead_or_set_p (i3
, i1dest
) || dead_or_set_p (i2
, i1dest
)));
1826 /* If the set in I2 needs to be kept around, we must make a copy of
1827 PATTERN (I2), so that when we substitute I1SRC for I1DEST in
1828 PATTERN (I2), we are only substituting for the original I1DEST, not into
1829 an already-substituted copy. This also prevents making self-referential
1830 rtx. If I2 is a PARALLEL, we just need the piece that assigns I2SRC to
1833 i2pat
= (GET_CODE (PATTERN (i2
)) == PARALLEL
1834 ? gen_rtx_SET (VOIDmode
, i2dest
, i2src
)
1838 i2pat
= copy_rtx (i2pat
);
1842 /* Substitute in the latest insn for the regs set by the earlier ones. */
1844 maxreg
= max_reg_num ();
1848 /* It is possible that the source of I2 or I1 may be performing an
1849 unneeded operation, such as a ZERO_EXTEND of something that is known
1850 to have the high part zero. Handle that case by letting subst look at
1851 the innermost one of them.
1853 Another way to do this would be to have a function that tries to
1854 simplify a single insn instead of merging two or more insns. We don't
1855 do this because of the potential of infinite loops and because
1856 of the potential extra memory required. However, doing it the way
1857 we are is a bit of a kludge and doesn't catch all cases.
1859 But only do this if -fexpensive-optimizations since it slows things down
1860 and doesn't usually win. */
1862 if (flag_expensive_optimizations
)
1864 /* Pass pc_rtx so no substitutions are done, just simplifications.
1865 The cases that we are interested in here do not involve the few
1866 cases were is_replaced is checked. */
1869 subst_low_cuid
= INSN_CUID (i1
);
1870 i1src
= subst (i1src
, pc_rtx
, pc_rtx
, 0, 0);
1874 subst_low_cuid
= INSN_CUID (i2
);
1875 i2src
= subst (i2src
, pc_rtx
, pc_rtx
, 0, 0);
1880 /* Many machines that don't use CC0 have insns that can both perform an
1881 arithmetic operation and set the condition code. These operations will
1882 be represented as a PARALLEL with the first element of the vector
1883 being a COMPARE of an arithmetic operation with the constant zero.
1884 The second element of the vector will set some pseudo to the result
1885 of the same arithmetic operation. If we simplify the COMPARE, we won't
1886 match such a pattern and so will generate an extra insn. Here we test
1887 for this case, where both the comparison and the operation result are
1888 needed, and make the PARALLEL by just replacing I2DEST in I3SRC with
1889 I2SRC. Later we will make the PARALLEL that contains I2. */
1891 if (i1
== 0 && added_sets_2
&& GET_CODE (PATTERN (i3
)) == SET
1892 && GET_CODE (SET_SRC (PATTERN (i3
))) == COMPARE
1893 && XEXP (SET_SRC (PATTERN (i3
)), 1) == const0_rtx
1894 && rtx_equal_p (XEXP (SET_SRC (PATTERN (i3
)), 0), i2dest
))
1896 #ifdef EXTRA_CC_MODES
1898 enum machine_mode compare_mode
;
1901 newpat
= PATTERN (i3
);
1902 SUBST (XEXP (SET_SRC (newpat
), 0), i2src
);
1906 #ifdef EXTRA_CC_MODES
1907 /* See if a COMPARE with the operand we substituted in should be done
1908 with the mode that is currently being used. If not, do the same
1909 processing we do in `subst' for a SET; namely, if the destination
1910 is used only once, try to replace it with a register of the proper
1911 mode and also replace the COMPARE. */
1912 if (undobuf
.other_insn
== 0
1913 && (cc_use
= find_single_use (SET_DEST (newpat
), i3
,
1914 &undobuf
.other_insn
))
1915 && ((compare_mode
= SELECT_CC_MODE (GET_CODE (*cc_use
),
1917 != GET_MODE (SET_DEST (newpat
))))
1919 unsigned int regno
= REGNO (SET_DEST (newpat
));
1920 rtx new_dest
= gen_rtx_REG (compare_mode
, regno
);
1922 if (regno
< FIRST_PSEUDO_REGISTER
1923 || (REG_N_SETS (regno
) == 1 && ! added_sets_2
1924 && ! REG_USERVAR_P (SET_DEST (newpat
))))
1926 if (regno
>= FIRST_PSEUDO_REGISTER
)
1927 SUBST (regno_reg_rtx
[regno
], new_dest
);
1929 SUBST (SET_DEST (newpat
), new_dest
);
1930 SUBST (XEXP (*cc_use
, 0), new_dest
);
1931 SUBST (SET_SRC (newpat
),
1932 gen_rtx_COMPARE (compare_mode
, i2src
, const0_rtx
));
1935 undobuf
.other_insn
= 0;
1942 n_occurrences
= 0; /* `subst' counts here */
1944 /* If I1 feeds into I2 (not into I3) and I1DEST is in I1SRC, we
1945 need to make a unique copy of I2SRC each time we substitute it
1946 to avoid self-referential rtl. */
1948 subst_low_cuid
= INSN_CUID (i2
);
1949 newpat
= subst (PATTERN (i3
), i2dest
, i2src
, 0,
1950 ! i1_feeds_i3
&& i1dest_in_i1src
);
1953 /* Record whether i2's body now appears within i3's body. */
1954 i2_is_used
= n_occurrences
;
1957 /* If we already got a failure, don't try to do more. Otherwise,
1958 try to substitute in I1 if we have it. */
1960 if (i1
&& GET_CODE (newpat
) != CLOBBER
)
1962 /* Before we can do this substitution, we must redo the test done
1963 above (see detailed comments there) that ensures that I1DEST
1964 isn't mentioned in any SETs in NEWPAT that are field assignments. */
1966 if (! combinable_i3pat (NULL_RTX
, &newpat
, i1dest
, NULL_RTX
,
1974 subst_low_cuid
= INSN_CUID (i1
);
1975 newpat
= subst (newpat
, i1dest
, i1src
, 0, 0);
1979 /* Fail if an autoincrement side-effect has been duplicated. Be careful
1980 to count all the ways that I2SRC and I1SRC can be used. */
1981 if ((FIND_REG_INC_NOTE (i2
, NULL_RTX
) != 0
1982 && i2_is_used
+ added_sets_2
> 1)
1983 || (i1
!= 0 && FIND_REG_INC_NOTE (i1
, NULL_RTX
) != 0
1984 && (n_occurrences
+ added_sets_1
+ (added_sets_2
&& ! i1_feeds_i3
)
1986 /* Fail if we tried to make a new register (we used to abort, but there's
1987 really no reason to). */
1988 || max_reg_num () != maxreg
1989 /* Fail if we couldn't do something and have a CLOBBER. */
1990 || GET_CODE (newpat
) == CLOBBER
1991 /* Fail if this new pattern is a MULT and we didn't have one before
1992 at the outer level. */
1993 || (GET_CODE (newpat
) == SET
&& GET_CODE (SET_SRC (newpat
)) == MULT
2000 /* If the actions of the earlier insns must be kept
2001 in addition to substituting them into the latest one,
2002 we must make a new PARALLEL for the latest insn
2003 to hold additional the SETs. */
2005 if (added_sets_1
|| added_sets_2
)
2009 if (GET_CODE (newpat
) == PARALLEL
)
2011 rtvec old
= XVEC (newpat
, 0);
2012 total_sets
= XVECLEN (newpat
, 0) + added_sets_1
+ added_sets_2
;
2013 newpat
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (total_sets
));
2014 memcpy (XVEC (newpat
, 0)->elem
, &old
->elem
[0],
2015 sizeof (old
->elem
[0]) * old
->num_elem
);
2020 total_sets
= 1 + added_sets_1
+ added_sets_2
;
2021 newpat
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (total_sets
));
2022 XVECEXP (newpat
, 0, 0) = old
;
2026 XVECEXP (newpat
, 0, --total_sets
)
2027 = (GET_CODE (PATTERN (i1
)) == PARALLEL
2028 ? gen_rtx_SET (VOIDmode
, i1dest
, i1src
) : PATTERN (i1
));
2032 /* If there is no I1, use I2's body as is. We used to also not do
2033 the subst call below if I2 was substituted into I3,
2034 but that could lose a simplification. */
2036 XVECEXP (newpat
, 0, --total_sets
) = i2pat
;
2038 /* See comment where i2pat is assigned. */
2039 XVECEXP (newpat
, 0, --total_sets
)
2040 = subst (i2pat
, i1dest
, i1src
, 0, 0);
2044 /* We come here when we are replacing a destination in I2 with the
2045 destination of I3. */
2046 validate_replacement
:
2048 /* Note which hard regs this insn has as inputs. */
2049 mark_used_regs_combine (newpat
);
2051 /* Is the result of combination a valid instruction? */
2052 insn_code_number
= recog_for_combine (&newpat
, i3
, &new_i3_notes
);
2054 /* If the result isn't valid, see if it is a PARALLEL of two SETs where
2055 the second SET's destination is a register that is unused. In that case,
2056 we just need the first SET. This can occur when simplifying a divmod
2057 insn. We *must* test for this case here because the code below that
2058 splits two independent SETs doesn't handle this case correctly when it
2059 updates the register status. Also check the case where the first
2060 SET's destination is unused. That would not cause incorrect code, but
2061 does cause an unneeded insn to remain. */
2063 if (insn_code_number
< 0 && GET_CODE (newpat
) == PARALLEL
2064 && XVECLEN (newpat
, 0) == 2
2065 && GET_CODE (XVECEXP (newpat
, 0, 0)) == SET
2066 && GET_CODE (XVECEXP (newpat
, 0, 1)) == SET
2067 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) == REG
2068 && find_reg_note (i3
, REG_UNUSED
, SET_DEST (XVECEXP (newpat
, 0, 1)))
2069 && ! side_effects_p (SET_SRC (XVECEXP (newpat
, 0, 1)))
2070 && asm_noperands (newpat
) < 0)
2072 newpat
= XVECEXP (newpat
, 0, 0);
2073 insn_code_number
= recog_for_combine (&newpat
, i3
, &new_i3_notes
);
2076 else if (insn_code_number
< 0 && GET_CODE (newpat
) == PARALLEL
2077 && XVECLEN (newpat
, 0) == 2
2078 && GET_CODE (XVECEXP (newpat
, 0, 0)) == SET
2079 && GET_CODE (XVECEXP (newpat
, 0, 1)) == SET
2080 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 0))) == REG
2081 && find_reg_note (i3
, REG_UNUSED
, SET_DEST (XVECEXP (newpat
, 0, 0)))
2082 && ! side_effects_p (SET_SRC (XVECEXP (newpat
, 0, 0)))
2083 && asm_noperands (newpat
) < 0)
2085 newpat
= XVECEXP (newpat
, 0, 1);
2086 insn_code_number
= recog_for_combine (&newpat
, i3
, &new_i3_notes
);
2089 /* If we were combining three insns and the result is a simple SET
2090 with no ASM_OPERANDS that wasn't recognized, try to split it into two
2091 insns. There are two ways to do this. It can be split using a
2092 machine-specific method (like when you have an addition of a large
2093 constant) or by combine in the function find_split_point. */
2095 if (i1
&& insn_code_number
< 0 && GET_CODE (newpat
) == SET
2096 && asm_noperands (newpat
) < 0)
2098 rtx m_split
, *split
;
2099 rtx ni2dest
= i2dest
;
2101 /* See if the MD file can split NEWPAT. If it can't, see if letting it
2102 use I2DEST as a scratch register will help. In the latter case,
2103 convert I2DEST to the mode of the source of NEWPAT if we can. */
2105 m_split
= split_insns (newpat
, i3
);
2107 /* We can only use I2DEST as a scratch reg if it doesn't overlap any
2108 inputs of NEWPAT. */
2110 /* ??? If I2DEST is not safe, and I1DEST exists, then it would be
2111 possible to try that as a scratch reg. This would require adding
2112 more code to make it work though. */
2114 if (m_split
== 0 && ! reg_overlap_mentioned_p (ni2dest
, newpat
))
2116 /* If I2DEST is a hard register or the only use of a pseudo,
2117 we can change its mode. */
2118 if (GET_MODE (SET_DEST (newpat
)) != GET_MODE (i2dest
)
2119 && GET_MODE (SET_DEST (newpat
)) != VOIDmode
2120 && GET_CODE (i2dest
) == REG
2121 && (REGNO (i2dest
) < FIRST_PSEUDO_REGISTER
2122 || (REG_N_SETS (REGNO (i2dest
)) == 1 && ! added_sets_2
2123 && ! REG_USERVAR_P (i2dest
))))
2124 ni2dest
= gen_rtx_REG (GET_MODE (SET_DEST (newpat
)),
2127 m_split
= split_insns (gen_rtx_PARALLEL
2129 gen_rtvec (2, newpat
,
2130 gen_rtx_CLOBBER (VOIDmode
,
2133 /* If the split with the mode-changed register didn't work, try
2134 the original register. */
2135 if (! m_split
&& ni2dest
!= i2dest
)
2138 m_split
= split_insns (gen_rtx_PARALLEL
2140 gen_rtvec (2, newpat
,
2141 gen_rtx_CLOBBER (VOIDmode
,
2147 if (m_split
&& NEXT_INSN (m_split
) == NULL_RTX
)
2149 m_split
= PATTERN (m_split
);
2150 insn_code_number
= recog_for_combine (&m_split
, i3
, &new_i3_notes
);
2151 if (insn_code_number
>= 0)
2154 else if (m_split
&& NEXT_INSN (NEXT_INSN (m_split
)) == NULL_RTX
2155 && (next_real_insn (i2
) == i3
2156 || ! use_crosses_set_p (PATTERN (m_split
), INSN_CUID (i2
))))
2159 rtx newi3pat
= PATTERN (NEXT_INSN (m_split
));
2160 newi2pat
= PATTERN (m_split
);
2162 i3set
= single_set (NEXT_INSN (m_split
));
2163 i2set
= single_set (m_split
);
2165 /* In case we changed the mode of I2DEST, replace it in the
2166 pseudo-register table here. We can't do it above in case this
2167 code doesn't get executed and we do a split the other way. */
2169 if (REGNO (i2dest
) >= FIRST_PSEUDO_REGISTER
)
2170 SUBST (regno_reg_rtx
[REGNO (i2dest
)], ni2dest
);
2172 i2_code_number
= recog_for_combine (&newi2pat
, i2
, &new_i2_notes
);
2174 /* If I2 or I3 has multiple SETs, we won't know how to track
2175 register status, so don't use these insns. If I2's destination
2176 is used between I2 and I3, we also can't use these insns. */
2178 if (i2_code_number
>= 0 && i2set
&& i3set
2179 && (next_real_insn (i2
) == i3
2180 || ! reg_used_between_p (SET_DEST (i2set
), i2
, i3
)))
2181 insn_code_number
= recog_for_combine (&newi3pat
, i3
,
2183 if (insn_code_number
>= 0)
2186 /* It is possible that both insns now set the destination of I3.
2187 If so, we must show an extra use of it. */
2189 if (insn_code_number
>= 0)
2191 rtx new_i3_dest
= SET_DEST (i3set
);
2192 rtx new_i2_dest
= SET_DEST (i2set
);
2194 while (GET_CODE (new_i3_dest
) == ZERO_EXTRACT
2195 || GET_CODE (new_i3_dest
) == STRICT_LOW_PART
2196 || GET_CODE (new_i3_dest
) == SUBREG
)
2197 new_i3_dest
= XEXP (new_i3_dest
, 0);
2199 while (GET_CODE (new_i2_dest
) == ZERO_EXTRACT
2200 || GET_CODE (new_i2_dest
) == STRICT_LOW_PART
2201 || GET_CODE (new_i2_dest
) == SUBREG
)
2202 new_i2_dest
= XEXP (new_i2_dest
, 0);
2204 if (GET_CODE (new_i3_dest
) == REG
2205 && GET_CODE (new_i2_dest
) == REG
2206 && REGNO (new_i3_dest
) == REGNO (new_i2_dest
))
2207 REG_N_SETS (REGNO (new_i2_dest
))++;
2211 /* If we can split it and use I2DEST, go ahead and see if that
2212 helps things be recognized. Verify that none of the registers
2213 are set between I2 and I3. */
2214 if (insn_code_number
< 0 && (split
= find_split_point (&newpat
, i3
)) != 0
2216 && GET_CODE (i2dest
) == REG
2218 /* We need I2DEST in the proper mode. If it is a hard register
2219 or the only use of a pseudo, we can change its mode. */
2220 && (GET_MODE (*split
) == GET_MODE (i2dest
)
2221 || GET_MODE (*split
) == VOIDmode
2222 || REGNO (i2dest
) < FIRST_PSEUDO_REGISTER
2223 || (REG_N_SETS (REGNO (i2dest
)) == 1 && ! added_sets_2
2224 && ! REG_USERVAR_P (i2dest
)))
2225 && (next_real_insn (i2
) == i3
2226 || ! use_crosses_set_p (*split
, INSN_CUID (i2
)))
2227 /* We can't overwrite I2DEST if its value is still used by
2229 && ! reg_referenced_p (i2dest
, newpat
))
2231 rtx newdest
= i2dest
;
2232 enum rtx_code split_code
= GET_CODE (*split
);
2233 enum machine_mode split_mode
= GET_MODE (*split
);
2235 /* Get NEWDEST as a register in the proper mode. We have already
2236 validated that we can do this. */
2237 if (GET_MODE (i2dest
) != split_mode
&& split_mode
!= VOIDmode
)
2239 newdest
= gen_rtx_REG (split_mode
, REGNO (i2dest
));
2241 if (REGNO (i2dest
) >= FIRST_PSEUDO_REGISTER
)
2242 SUBST (regno_reg_rtx
[REGNO (i2dest
)], newdest
);
2245 /* If *SPLIT is a (mult FOO (const_int pow2)), convert it to
2246 an ASHIFT. This can occur if it was inside a PLUS and hence
2247 appeared to be a memory address. This is a kludge. */
2248 if (split_code
== MULT
2249 && GET_CODE (XEXP (*split
, 1)) == CONST_INT
2250 && INTVAL (XEXP (*split
, 1)) > 0
2251 && (i
= exact_log2 (INTVAL (XEXP (*split
, 1)))) >= 0)
2253 SUBST (*split
, gen_rtx_ASHIFT (split_mode
,
2254 XEXP (*split
, 0), GEN_INT (i
)));
2255 /* Update split_code because we may not have a multiply
2257 split_code
= GET_CODE (*split
);
2260 #ifdef INSN_SCHEDULING
2261 /* If *SPLIT is a paradoxical SUBREG, when we split it, it should
2262 be written as a ZERO_EXTEND. */
2263 if (split_code
== SUBREG
&& GET_CODE (SUBREG_REG (*split
)) == MEM
)
2265 #ifdef LOAD_EXTEND_OP
2266 /* Or as a SIGN_EXTEND if LOAD_EXTEND_OP says that that's
2267 what it really is. */
2268 if (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (*split
)))
2270 SUBST (*split
, gen_rtx_SIGN_EXTEND (split_mode
,
2271 SUBREG_REG (*split
)));
2274 SUBST (*split
, gen_rtx_ZERO_EXTEND (split_mode
,
2275 SUBREG_REG (*split
)));
2279 newi2pat
= gen_rtx_SET (VOIDmode
, newdest
, *split
);
2280 SUBST (*split
, newdest
);
2281 i2_code_number
= recog_for_combine (&newi2pat
, i2
, &new_i2_notes
);
2283 /* If the split point was a MULT and we didn't have one before,
2284 don't use one now. */
2285 if (i2_code_number
>= 0 && ! (split_code
== MULT
&& ! have_mult
))
2286 insn_code_number
= recog_for_combine (&newpat
, i3
, &new_i3_notes
);
2290 /* Check for a case where we loaded from memory in a narrow mode and
2291 then sign extended it, but we need both registers. In that case,
2292 we have a PARALLEL with both loads from the same memory location.
2293 We can split this into a load from memory followed by a register-register
2294 copy. This saves at least one insn, more if register allocation can
2297 We cannot do this if the destination of the first assignment is a
2298 condition code register or cc0. We eliminate this case by making sure
2299 the SET_DEST and SET_SRC have the same mode.
2301 We cannot do this if the destination of the second assignment is
2302 a register that we have already assumed is zero-extended. Similarly
2303 for a SUBREG of such a register. */
2305 else if (i1
&& insn_code_number
< 0 && asm_noperands (newpat
) < 0
2306 && GET_CODE (newpat
) == PARALLEL
2307 && XVECLEN (newpat
, 0) == 2
2308 && GET_CODE (XVECEXP (newpat
, 0, 0)) == SET
2309 && GET_CODE (SET_SRC (XVECEXP (newpat
, 0, 0))) == SIGN_EXTEND
2310 && (GET_MODE (SET_DEST (XVECEXP (newpat
, 0, 0)))
2311 == GET_MODE (SET_SRC (XVECEXP (newpat
, 0, 0))))
2312 && GET_CODE (XVECEXP (newpat
, 0, 1)) == SET
2313 && rtx_equal_p (SET_SRC (XVECEXP (newpat
, 0, 1)),
2314 XEXP (SET_SRC (XVECEXP (newpat
, 0, 0)), 0))
2315 && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat
, 0, 1)),
2317 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) != ZERO_EXTRACT
2318 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) != STRICT_LOW_PART
2319 && ! (temp
= SET_DEST (XVECEXP (newpat
, 0, 1)),
2320 (GET_CODE (temp
) == REG
2321 && reg_nonzero_bits
[REGNO (temp
)] != 0
2322 && GET_MODE_BITSIZE (GET_MODE (temp
)) < BITS_PER_WORD
2323 && GET_MODE_BITSIZE (GET_MODE (temp
)) < HOST_BITS_PER_INT
2324 && (reg_nonzero_bits
[REGNO (temp
)]
2325 != GET_MODE_MASK (word_mode
))))
2326 && ! (GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) == SUBREG
2327 && (temp
= SUBREG_REG (SET_DEST (XVECEXP (newpat
, 0, 1))),
2328 (GET_CODE (temp
) == REG
2329 && reg_nonzero_bits
[REGNO (temp
)] != 0
2330 && GET_MODE_BITSIZE (GET_MODE (temp
)) < BITS_PER_WORD
2331 && GET_MODE_BITSIZE (GET_MODE (temp
)) < HOST_BITS_PER_INT
2332 && (reg_nonzero_bits
[REGNO (temp
)]
2333 != GET_MODE_MASK (word_mode
)))))
2334 && ! reg_overlap_mentioned_p (SET_DEST (XVECEXP (newpat
, 0, 1)),
2335 SET_SRC (XVECEXP (newpat
, 0, 1)))
2336 && ! find_reg_note (i3
, REG_UNUSED
,
2337 SET_DEST (XVECEXP (newpat
, 0, 0))))
2341 newi2pat
= XVECEXP (newpat
, 0, 0);
2342 ni2dest
= SET_DEST (XVECEXP (newpat
, 0, 0));
2343 newpat
= XVECEXP (newpat
, 0, 1);
2344 SUBST (SET_SRC (newpat
),
2345 gen_lowpart_for_combine (GET_MODE (SET_SRC (newpat
)), ni2dest
));
2346 i2_code_number
= recog_for_combine (&newi2pat
, i2
, &new_i2_notes
);
2348 if (i2_code_number
>= 0)
2349 insn_code_number
= recog_for_combine (&newpat
, i3
, &new_i3_notes
);
2351 if (insn_code_number
>= 0)
2356 /* If we will be able to accept this, we have made a change to the
2357 destination of I3. This can invalidate a LOG_LINKS pointing
2358 to I3. No other part of combine.c makes such a transformation.
2360 The new I3 will have a destination that was previously the
2361 destination of I1 or I2 and which was used in i2 or I3. Call
2362 distribute_links to make a LOG_LINK from the next use of
2363 that destination. */
2365 PATTERN (i3
) = newpat
;
2366 distribute_links (gen_rtx_INSN_LIST (VOIDmode
, i3
, NULL_RTX
));
2368 /* I3 now uses what used to be its destination and which is
2369 now I2's destination. That means we need a LOG_LINK from
2370 I3 to I2. But we used to have one, so we still will.
2372 However, some later insn might be using I2's dest and have
2373 a LOG_LINK pointing at I3. We must remove this link.
2374 The simplest way to remove the link is to point it at I1,
2375 which we know will be a NOTE. */
2377 for (insn
= NEXT_INSN (i3
);
2378 insn
&& (this_basic_block
->next_bb
== EXIT_BLOCK_PTR
2379 || insn
!= this_basic_block
->next_bb
->head
);
2380 insn
= NEXT_INSN (insn
))
2382 if (INSN_P (insn
) && reg_referenced_p (ni2dest
, PATTERN (insn
)))
2384 for (link
= LOG_LINKS (insn
); link
;
2385 link
= XEXP (link
, 1))
2386 if (XEXP (link
, 0) == i3
)
2387 XEXP (link
, 0) = i1
;
2395 /* Similarly, check for a case where we have a PARALLEL of two independent
2396 SETs but we started with three insns. In this case, we can do the sets
2397 as two separate insns. This case occurs when some SET allows two
2398 other insns to combine, but the destination of that SET is still live. */
2400 else if (i1
&& insn_code_number
< 0 && asm_noperands (newpat
) < 0
2401 && GET_CODE (newpat
) == PARALLEL
2402 && XVECLEN (newpat
, 0) == 2
2403 && GET_CODE (XVECEXP (newpat
, 0, 0)) == SET
2404 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 0))) != ZERO_EXTRACT
2405 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 0))) != STRICT_LOW_PART
2406 && GET_CODE (XVECEXP (newpat
, 0, 1)) == SET
2407 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) != ZERO_EXTRACT
2408 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) != STRICT_LOW_PART
2409 && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat
, 0, 1)),
2411 /* Don't pass sets with (USE (MEM ...)) dests to the following. */
2412 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 1))) != USE
2413 && GET_CODE (SET_DEST (XVECEXP (newpat
, 0, 0))) != USE
2414 && ! reg_referenced_p (SET_DEST (XVECEXP (newpat
, 0, 1)),
2415 XVECEXP (newpat
, 0, 0))
2416 && ! reg_referenced_p (SET_DEST (XVECEXP (newpat
, 0, 0)),
2417 XVECEXP (newpat
, 0, 1))
2418 && ! (contains_muldiv (SET_SRC (XVECEXP (newpat
, 0, 0)))
2419 && contains_muldiv (SET_SRC (XVECEXP (newpat
, 0, 1)))))
2421 /* Normally, it doesn't matter which of the two is done first,
2422 but it does if one references cc0. In that case, it has to
2425 if (reg_referenced_p (cc0_rtx
, XVECEXP (newpat
, 0, 0)))
2427 newi2pat
= XVECEXP (newpat
, 0, 0);
2428 newpat
= XVECEXP (newpat
, 0, 1);
2433 newi2pat
= XVECEXP (newpat
, 0, 1);
2434 newpat
= XVECEXP (newpat
, 0, 0);
2437 i2_code_number
= recog_for_combine (&newi2pat
, i2
, &new_i2_notes
);
2439 if (i2_code_number
>= 0)
2440 insn_code_number
= recog_for_combine (&newpat
, i3
, &new_i3_notes
);
2443 /* If it still isn't recognized, fail and change things back the way they
2445 if ((insn_code_number
< 0
2446 /* Is the result a reasonable ASM_OPERANDS? */
2447 && (! check_asm_operands (newpat
) || added_sets_1
|| added_sets_2
)))
2453 /* If we had to change another insn, make sure it is valid also. */
2454 if (undobuf
.other_insn
)
2456 rtx other_pat
= PATTERN (undobuf
.other_insn
);
2457 rtx new_other_notes
;
2460 CLEAR_HARD_REG_SET (newpat_used_regs
);
2462 other_code_number
= recog_for_combine (&other_pat
, undobuf
.other_insn
,
2465 if (other_code_number
< 0 && ! check_asm_operands (other_pat
))
2471 PATTERN (undobuf
.other_insn
) = other_pat
;
2473 /* If any of the notes in OTHER_INSN were REG_UNUSED, ensure that they
2474 are still valid. Then add any non-duplicate notes added by
2475 recog_for_combine. */
2476 for (note
= REG_NOTES (undobuf
.other_insn
); note
; note
= next
)
2478 next
= XEXP (note
, 1);
2480 if (REG_NOTE_KIND (note
) == REG_UNUSED
2481 && ! reg_set_p (XEXP (note
, 0), PATTERN (undobuf
.other_insn
)))
2483 if (GET_CODE (XEXP (note
, 0)) == REG
)
2484 REG_N_DEATHS (REGNO (XEXP (note
, 0)))--;
2486 remove_note (undobuf
.other_insn
, note
);
2490 for (note
= new_other_notes
; note
; note
= XEXP (note
, 1))
2491 if (GET_CODE (XEXP (note
, 0)) == REG
)
2492 REG_N_DEATHS (REGNO (XEXP (note
, 0)))++;
2494 distribute_notes (new_other_notes
, undobuf
.other_insn
,
2495 undobuf
.other_insn
, NULL_RTX
, NULL_RTX
, NULL_RTX
);
2498 /* If I2 is the setter CC0 and I3 is the user CC0 then check whether
2499 they are adjacent to each other or not. */
2501 rtx p
= prev_nonnote_insn (i3
);
2502 if (p
&& p
!= i2
&& GET_CODE (p
) == INSN
&& newi2pat
2503 && sets_cc0_p (newi2pat
))
2511 /* We now know that we can do this combination. Merge the insns and
2512 update the status of registers and LOG_LINKS. */
2515 rtx i3notes
, i2notes
, i1notes
= 0;
2516 rtx i3links
, i2links
, i1links
= 0;
2519 /* Compute which registers we expect to eliminate. newi2pat may be setting
2520 either i3dest or i2dest, so we must check it. Also, i1dest may be the
2521 same as i3dest, in which case newi2pat may be setting i1dest. */
2522 rtx elim_i2
= ((newi2pat
&& reg_set_p (i2dest
, newi2pat
))
2523 || i2dest_in_i2src
|| i2dest_in_i1src
2525 rtx elim_i1
= (i1
== 0 || i1dest_in_i1src
2526 || (newi2pat
&& reg_set_p (i1dest
, newi2pat
))
2529 /* Get the old REG_NOTES and LOG_LINKS from all our insns and
2531 i3notes
= REG_NOTES (i3
), i3links
= LOG_LINKS (i3
);
2532 i2notes
= REG_NOTES (i2
), i2links
= LOG_LINKS (i2
);
2534 i1notes
= REG_NOTES (i1
), i1links
= LOG_LINKS (i1
);
2536 /* Ensure that we do not have something that should not be shared but
2537 occurs multiple times in the new insns. Check this by first
2538 resetting all the `used' flags and then copying anything is shared. */
2540 reset_used_flags (i3notes
);
2541 reset_used_flags (i2notes
);
2542 reset_used_flags (i1notes
);
2543 reset_used_flags (newpat
);
2544 reset_used_flags (newi2pat
);
2545 if (undobuf
.other_insn
)
2546 reset_used_flags (PATTERN (undobuf
.other_insn
));
2548 i3notes
= copy_rtx_if_shared (i3notes
);
2549 i2notes
= copy_rtx_if_shared (i2notes
);
2550 i1notes
= copy_rtx_if_shared (i1notes
);
2551 newpat
= copy_rtx_if_shared (newpat
);
2552 newi2pat
= copy_rtx_if_shared (newi2pat
);
2553 if (undobuf
.other_insn
)
2554 reset_used_flags (PATTERN (undobuf
.other_insn
));
2556 INSN_CODE (i3
) = insn_code_number
;
2557 PATTERN (i3
) = newpat
;
2559 if (GET_CODE (i3
) == CALL_INSN
&& CALL_INSN_FUNCTION_USAGE (i3
))
2561 rtx call_usage
= CALL_INSN_FUNCTION_USAGE (i3
);
2563 reset_used_flags (call_usage
);
2564 call_usage
= copy_rtx (call_usage
);
2567 replace_rtx (call_usage
, i2dest
, i2src
);
2570 replace_rtx (call_usage
, i1dest
, i1src
);
2572 CALL_INSN_FUNCTION_USAGE (i3
) = call_usage
;
2575 if (undobuf
.other_insn
)
2576 INSN_CODE (undobuf
.other_insn
) = other_code_number
;
2578 /* We had one special case above where I2 had more than one set and
2579 we replaced a destination of one of those sets with the destination
2580 of I3. In that case, we have to update LOG_LINKS of insns later
2581 in this basic block. Note that this (expensive) case is rare.
2583 Also, in this case, we must pretend that all REG_NOTEs for I2
2584 actually came from I3, so that REG_UNUSED notes from I2 will be
2585 properly handled. */
2587 if (i3_subst_into_i2
)
2589 for (i
= 0; i
< XVECLEN (PATTERN (i2
), 0); i
++)
2590 if (GET_CODE (XVECEXP (PATTERN (i2
), 0, i
)) != USE
2591 && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2
), 0, i
))) == REG
2592 && SET_DEST (XVECEXP (PATTERN (i2
), 0, i
)) != i2dest
2593 && ! find_reg_note (i2
, REG_UNUSED
,
2594 SET_DEST (XVECEXP (PATTERN (i2
), 0, i
))))
2595 for (temp
= NEXT_INSN (i2
);
2596 temp
&& (this_basic_block
->next_bb
== EXIT_BLOCK_PTR
2597 || this_basic_block
->head
!= temp
);
2598 temp
= NEXT_INSN (temp
))
2599 if (temp
!= i3
&& INSN_P (temp
))
2600 for (link
= LOG_LINKS (temp
); link
; link
= XEXP (link
, 1))
2601 if (XEXP (link
, 0) == i2
)
2602 XEXP (link
, 0) = i3
;
2607 while (XEXP (link
, 1))
2608 link
= XEXP (link
, 1);
2609 XEXP (link
, 1) = i2notes
;
2623 INSN_CODE (i2
) = i2_code_number
;
2624 PATTERN (i2
) = newi2pat
;
2628 PUT_CODE (i2
, NOTE
);
2629 NOTE_LINE_NUMBER (i2
) = NOTE_INSN_DELETED
;
2630 NOTE_SOURCE_FILE (i2
) = 0;
2637 PUT_CODE (i1
, NOTE
);
2638 NOTE_LINE_NUMBER (i1
) = NOTE_INSN_DELETED
;
2639 NOTE_SOURCE_FILE (i1
) = 0;
2642 /* Get death notes for everything that is now used in either I3 or
2643 I2 and used to die in a previous insn. If we built two new
2644 patterns, move from I1 to I2 then I2 to I3 so that we get the
2645 proper movement on registers that I2 modifies. */
2649 move_deaths (newi2pat
, NULL_RTX
, INSN_CUID (i1
), i2
, &midnotes
);
2650 move_deaths (newpat
, newi2pat
, INSN_CUID (i1
), i3
, &midnotes
);
2653 move_deaths (newpat
, NULL_RTX
, i1
? INSN_CUID (i1
) : INSN_CUID (i2
),
2656 /* Distribute all the LOG_LINKS and REG_NOTES from I1, I2, and I3. */
2658 distribute_notes (i3notes
, i3
, i3
, newi2pat
? i2
: NULL_RTX
,
2661 distribute_notes (i2notes
, i2
, i3
, newi2pat
? i2
: NULL_RTX
,
2664 distribute_notes (i1notes
, i1
, i3
, newi2pat
? i2
: NULL_RTX
,
2667 distribute_notes (midnotes
, NULL_RTX
, i3
, newi2pat
? i2
: NULL_RTX
,
2670 /* Distribute any notes added to I2 or I3 by recog_for_combine. We
2671 know these are REG_UNUSED and want them to go to the desired insn,
2672 so we always pass it as i3. We have not counted the notes in
2673 reg_n_deaths yet, so we need to do so now. */
2675 if (newi2pat
&& new_i2_notes
)
2677 for (temp
= new_i2_notes
; temp
; temp
= XEXP (temp
, 1))
2678 if (GET_CODE (XEXP (temp
, 0)) == REG
)
2679 REG_N_DEATHS (REGNO (XEXP (temp
, 0)))++;
2681 distribute_notes (new_i2_notes
, i2
, i2
, NULL_RTX
, NULL_RTX
, NULL_RTX
);
2686 for (temp
= new_i3_notes
; temp
; temp
= XEXP (temp
, 1))
2687 if (GET_CODE (XEXP (temp
, 0)) == REG
)
2688 REG_N_DEATHS (REGNO (XEXP (temp
, 0)))++;
2690 distribute_notes (new_i3_notes
, i3
, i3
, NULL_RTX
, NULL_RTX
, NULL_RTX
);
2693 /* If I3DEST was used in I3SRC, it really died in I3. We may need to
2694 put a REG_DEAD note for it somewhere. If NEWI2PAT exists and sets
2695 I3DEST, the death must be somewhere before I2, not I3. If we passed I3
2696 in that case, it might delete I2. Similarly for I2 and I1.
2697 Show an additional death due to the REG_DEAD note we make here. If
2698 we discard it in distribute_notes, we will decrement it again. */
2702 if (GET_CODE (i3dest_killed
) == REG
)
2703 REG_N_DEATHS (REGNO (i3dest_killed
))++;
2705 if (newi2pat
&& reg_set_p (i3dest_killed
, newi2pat
))
2706 distribute_notes (gen_rtx_EXPR_LIST (REG_DEAD
, i3dest_killed
,
2708 NULL_RTX
, i2
, NULL_RTX
, elim_i2
, elim_i1
);
2710 distribute_notes (gen_rtx_EXPR_LIST (REG_DEAD
, i3dest_killed
,
2712 NULL_RTX
, i3
, newi2pat
? i2
: NULL_RTX
,
2716 if (i2dest_in_i2src
)
2718 if (GET_CODE (i2dest
) == REG
)
2719 REG_N_DEATHS (REGNO (i2dest
))++;
2721 if (newi2pat
&& reg_set_p (i2dest
, newi2pat
))
2722 distribute_notes (gen_rtx_EXPR_LIST (REG_DEAD
, i2dest
, NULL_RTX
),
2723 NULL_RTX
, i2
, NULL_RTX
, NULL_RTX
, NULL_RTX
);
2725 distribute_notes (gen_rtx_EXPR_LIST (REG_DEAD
, i2dest
, NULL_RTX
),
2726 NULL_RTX
, i3
, newi2pat
? i2
: NULL_RTX
,
2727 NULL_RTX
, NULL_RTX
);
2730 if (i1dest_in_i1src
)
2732 if (GET_CODE (i1dest
) == REG
)
2733 REG_N_DEATHS (REGNO (i1dest
))++;
2735 if (newi2pat
&& reg_set_p (i1dest
, newi2pat
))
2736 distribute_notes (gen_rtx_EXPR_LIST (REG_DEAD
, i1dest
, NULL_RTX
),
2737 NULL_RTX
, i2
, NULL_RTX
, NULL_RTX
, NULL_RTX
);
2739 distribute_notes (gen_rtx_EXPR_LIST (REG_DEAD
, i1dest
, NULL_RTX
),
2740 NULL_RTX
, i3
, newi2pat
? i2
: NULL_RTX
,
2741 NULL_RTX
, NULL_RTX
);
2744 distribute_links (i3links
);
2745 distribute_links (i2links
);
2746 distribute_links (i1links
);
2748 if (GET_CODE (i2dest
) == REG
)
2751 rtx i2_insn
= 0, i2_val
= 0, set
;
2753 /* The insn that used to set this register doesn't exist, and
2754 this life of the register may not exist either. See if one of
2755 I3's links points to an insn that sets I2DEST. If it does,
2756 that is now the last known value for I2DEST. If we don't update
2757 this and I2 set the register to a value that depended on its old
2758 contents, we will get confused. If this insn is used, thing
2759 will be set correctly in combine_instructions. */
2761 for (link
= LOG_LINKS (i3
); link
; link
= XEXP (link
, 1))
2762 if ((set
= single_set (XEXP (link
, 0))) != 0
2763 && rtx_equal_p (i2dest
, SET_DEST (set
)))
2764 i2_insn
= XEXP (link
, 0), i2_val
= SET_SRC (set
);
2766 record_value_for_reg (i2dest
, i2_insn
, i2_val
);
2768 /* If the reg formerly set in I2 died only once and that was in I3,
2769 zero its use count so it won't make `reload' do any work. */
2771 && (newi2pat
== 0 || ! reg_mentioned_p (i2dest
, newi2pat
))
2772 && ! i2dest_in_i2src
)
2774 regno
= REGNO (i2dest
);
2775 REG_N_SETS (regno
)--;
2779 if (i1
&& GET_CODE (i1dest
) == REG
)
2782 rtx i1_insn
= 0, i1_val
= 0, set
;
2784 for (link
= LOG_LINKS (i3
); link
; link
= XEXP (link
, 1))
2785 if ((set
= single_set (XEXP (link
, 0))) != 0
2786 && rtx_equal_p (i1dest
, SET_DEST (set
)))
2787 i1_insn
= XEXP (link
, 0), i1_val
= SET_SRC (set
);
2789 record_value_for_reg (i1dest
, i1_insn
, i1_val
);
2791 regno
= REGNO (i1dest
);
2792 if (! added_sets_1
&& ! i1dest_in_i1src
)
2793 REG_N_SETS (regno
)--;
2796 /* Update reg_nonzero_bits et al for any changes that may have been made
2797 to this insn. The order of set_nonzero_bits_and_sign_copies() is
2798 important. Because newi2pat can affect nonzero_bits of newpat */
2800 note_stores (newi2pat
, set_nonzero_bits_and_sign_copies
, NULL
);
2801 note_stores (newpat
, set_nonzero_bits_and_sign_copies
, NULL
);
2803 /* Set new_direct_jump_p if a new return or simple jump instruction
2806 If I3 is now an unconditional jump, ensure that it has a
2807 BARRIER following it since it may have initially been a
2808 conditional jump. It may also be the last nonnote insn. */
2810 if (returnjump_p (i3
) || any_uncondjump_p (i3
))
2812 *new_direct_jump_p
= 1;
2814 if ((temp
= next_nonnote_insn (i3
)) == NULL_RTX
2815 || GET_CODE (temp
) != BARRIER
)
2816 emit_barrier_after (i3
);
2819 if (undobuf
.other_insn
!= NULL_RTX
2820 && (returnjump_p (undobuf
.other_insn
)
2821 || any_uncondjump_p (undobuf
.other_insn
)))
2823 *new_direct_jump_p
= 1;
2825 if ((temp
= next_nonnote_insn (undobuf
.other_insn
)) == NULL_RTX
2826 || GET_CODE (temp
) != BARRIER
)
2827 emit_barrier_after (undobuf
.other_insn
);
2830 /* An NOOP jump does not need barrier, but it does need cleaning up
2832 if (GET_CODE (newpat
) == SET
2833 && SET_SRC (newpat
) == pc_rtx
2834 && SET_DEST (newpat
) == pc_rtx
)
2835 *new_direct_jump_p
= 1;
2838 combine_successes
++;
2841 if (added_links_insn
2842 && (newi2pat
== 0 || INSN_CUID (added_links_insn
) < INSN_CUID (i2
))
2843 && INSN_CUID (added_links_insn
) < INSN_CUID (i3
))
2844 return added_links_insn
;
2846 return newi2pat
? i2
: i3
;
2849 /* Undo all the modifications recorded in undobuf. */
2854 struct undo
*undo
, *next
;
2856 for (undo
= undobuf
.undos
; undo
; undo
= next
)
2860 *undo
->where
.i
= undo
->old_contents
.i
;
2862 *undo
->where
.r
= undo
->old_contents
.r
;
2864 undo
->next
= undobuf
.frees
;
2865 undobuf
.frees
= undo
;
2871 /* We've committed to accepting the changes we made. Move all
2872 of the undos to the free list. */
2877 struct undo
*undo
, *next
;
2879 for (undo
= undobuf
.undos
; undo
; undo
= next
)
2882 undo
->next
= undobuf
.frees
;
2883 undobuf
.frees
= undo
;
2889 /* Find the innermost point within the rtx at LOC, possibly LOC itself,
2890 where we have an arithmetic expression and return that point. LOC will
2893 try_combine will call this function to see if an insn can be split into
2897 find_split_point (loc
, insn
)
2902 enum rtx_code code
= GET_CODE (x
);
2904 unsigned HOST_WIDE_INT len
= 0;
2905 HOST_WIDE_INT pos
= 0;
2907 rtx inner
= NULL_RTX
;
2909 /* First special-case some codes. */
2913 #ifdef INSN_SCHEDULING
2914 /* If we are making a paradoxical SUBREG invalid, it becomes a split
2916 if (GET_CODE (SUBREG_REG (x
)) == MEM
)
2919 return find_split_point (&SUBREG_REG (x
), insn
);
2923 /* If we have (mem (const ..)) or (mem (symbol_ref ...)), split it
2924 using LO_SUM and HIGH. */
2925 if (GET_CODE (XEXP (x
, 0)) == CONST
2926 || GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
)
2929 gen_rtx_LO_SUM (Pmode
,
2930 gen_rtx_HIGH (Pmode
, XEXP (x
, 0)),
2932 return &XEXP (XEXP (x
, 0), 0);
2936 /* If we have a PLUS whose second operand is a constant and the
2937 address is not valid, perhaps will can split it up using
2938 the machine-specific way to split large constants. We use
2939 the first pseudo-reg (one of the virtual regs) as a placeholder;
2940 it will not remain in the result. */
2941 if (GET_CODE (XEXP (x
, 0)) == PLUS
2942 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2943 && ! memory_address_p (GET_MODE (x
), XEXP (x
, 0)))
2945 rtx reg
= regno_reg_rtx
[FIRST_PSEUDO_REGISTER
];
2946 rtx seq
= split_insns (gen_rtx_SET (VOIDmode
, reg
, XEXP (x
, 0)),
2949 /* This should have produced two insns, each of which sets our
2950 placeholder. If the source of the second is a valid address,
2951 we can make put both sources together and make a split point
2955 && NEXT_INSN (seq
) != NULL_RTX
2956 && NEXT_INSN (NEXT_INSN (seq
)) == NULL_RTX
2957 && GET_CODE (seq
) == INSN
2958 && GET_CODE (PATTERN (seq
)) == SET
2959 && SET_DEST (PATTERN (seq
)) == reg
2960 && ! reg_mentioned_p (reg
,
2961 SET_SRC (PATTERN (seq
)))
2962 && GET_CODE (NEXT_INSN (seq
)) == INSN
2963 && GET_CODE (PATTERN (NEXT_INSN (seq
))) == SET
2964 && SET_DEST (PATTERN (NEXT_INSN (seq
))) == reg
2965 && memory_address_p (GET_MODE (x
),
2966 SET_SRC (PATTERN (NEXT_INSN (seq
)))))
2968 rtx src1
= SET_SRC (PATTERN (seq
));
2969 rtx src2
= SET_SRC (PATTERN (NEXT_INSN (seq
)));
2971 /* Replace the placeholder in SRC2 with SRC1. If we can
2972 find where in SRC2 it was placed, that can become our
2973 split point and we can replace this address with SRC2.
2974 Just try two obvious places. */
2976 src2
= replace_rtx (src2
, reg
, src1
);
2978 if (XEXP (src2
, 0) == src1
)
2979 split
= &XEXP (src2
, 0);
2980 else if (GET_RTX_FORMAT (GET_CODE (XEXP (src2
, 0)))[0] == 'e'
2981 && XEXP (XEXP (src2
, 0), 0) == src1
)
2982 split
= &XEXP (XEXP (src2
, 0), 0);
2986 SUBST (XEXP (x
, 0), src2
);
2991 /* If that didn't work, perhaps the first operand is complex and
2992 needs to be computed separately, so make a split point there.
2993 This will occur on machines that just support REG + CONST
2994 and have a constant moved through some previous computation. */
2996 else if (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x
, 0), 0))) != 'o'
2997 && ! (GET_CODE (XEXP (XEXP (x
, 0), 0)) == SUBREG
2998 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (XEXP (x
, 0), 0))))
3000 return &XEXP (XEXP (x
, 0), 0);
3006 /* If SET_DEST is CC0 and SET_SRC is not an operand, a COMPARE, or a
3007 ZERO_EXTRACT, the most likely reason why this doesn't match is that
3008 we need to put the operand into a register. So split at that
3011 if (SET_DEST (x
) == cc0_rtx
3012 && GET_CODE (SET_SRC (x
)) != COMPARE
3013 && GET_CODE (SET_SRC (x
)) != ZERO_EXTRACT
3014 && GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) != 'o'
3015 && ! (GET_CODE (SET_SRC (x
)) == SUBREG
3016 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (SET_SRC (x
)))) == 'o'))
3017 return &SET_SRC (x
);
3020 /* See if we can split SET_SRC as it stands. */
3021 split
= find_split_point (&SET_SRC (x
), insn
);
3022 if (split
&& split
!= &SET_SRC (x
))
3025 /* See if we can split SET_DEST as it stands. */
3026 split
= find_split_point (&SET_DEST (x
), insn
);
3027 if (split
&& split
!= &SET_DEST (x
))
3030 /* See if this is a bitfield assignment with everything constant. If
3031 so, this is an IOR of an AND, so split it into that. */
3032 if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
3033 && (GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x
), 0)))
3034 <= HOST_BITS_PER_WIDE_INT
)
3035 && GET_CODE (XEXP (SET_DEST (x
), 1)) == CONST_INT
3036 && GET_CODE (XEXP (SET_DEST (x
), 2)) == CONST_INT
3037 && GET_CODE (SET_SRC (x
)) == CONST_INT
3038 && ((INTVAL (XEXP (SET_DEST (x
), 1))
3039 + INTVAL (XEXP (SET_DEST (x
), 2)))
3040 <= GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x
), 0))))
3041 && ! side_effects_p (XEXP (SET_DEST (x
), 0)))
3043 HOST_WIDE_INT pos
= INTVAL (XEXP (SET_DEST (x
), 2));
3044 unsigned HOST_WIDE_INT len
= INTVAL (XEXP (SET_DEST (x
), 1));
3045 unsigned HOST_WIDE_INT src
= INTVAL (SET_SRC (x
));
3046 rtx dest
= XEXP (SET_DEST (x
), 0);
3047 enum machine_mode mode
= GET_MODE (dest
);
3048 unsigned HOST_WIDE_INT mask
= ((HOST_WIDE_INT
) 1 << len
) - 1;
3050 if (BITS_BIG_ENDIAN
)
3051 pos
= GET_MODE_BITSIZE (mode
) - len
- pos
;
3055 gen_binary (IOR
, mode
, dest
, GEN_INT (src
<< pos
)));
3058 gen_binary (IOR
, mode
,
3059 gen_binary (AND
, mode
, dest
,
3060 gen_int_mode (~(mask
<< pos
),
3062 GEN_INT (src
<< pos
)));
3064 SUBST (SET_DEST (x
), dest
);
3066 split
= find_split_point (&SET_SRC (x
), insn
);
3067 if (split
&& split
!= &SET_SRC (x
))
3071 /* Otherwise, see if this is an operation that we can split into two.
3072 If so, try to split that. */
3073 code
= GET_CODE (SET_SRC (x
));
3078 /* If we are AND'ing with a large constant that is only a single
3079 bit and the result is only being used in a context where we
3080 need to know if it is zero or nonzero, replace it with a bit
3081 extraction. This will avoid the large constant, which might
3082 have taken more than one insn to make. If the constant were
3083 not a valid argument to the AND but took only one insn to make,
3084 this is no worse, but if it took more than one insn, it will
3087 if (GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST_INT
3088 && GET_CODE (XEXP (SET_SRC (x
), 0)) == REG
3089 && (pos
= exact_log2 (INTVAL (XEXP (SET_SRC (x
), 1)))) >= 7
3090 && GET_CODE (SET_DEST (x
)) == REG
3091 && (split
= find_single_use (SET_DEST (x
), insn
, (rtx
*) 0)) != 0
3092 && (GET_CODE (*split
) == EQ
|| GET_CODE (*split
) == NE
)
3093 && XEXP (*split
, 0) == SET_DEST (x
)
3094 && XEXP (*split
, 1) == const0_rtx
)
3096 rtx extraction
= make_extraction (GET_MODE (SET_DEST (x
)),
3097 XEXP (SET_SRC (x
), 0),
3098 pos
, NULL_RTX
, 1, 1, 0, 0);
3099 if (extraction
!= 0)
3101 SUBST (SET_SRC (x
), extraction
);
3102 return find_split_point (loc
, insn
);
3108 /* if STORE_FLAG_VALUE is -1, this is (NE X 0) and only one bit of X
3109 is known to be on, this can be converted into a NEG of a shift. */
3110 if (STORE_FLAG_VALUE
== -1 && XEXP (SET_SRC (x
), 1) == const0_rtx
3111 && GET_MODE (SET_SRC (x
)) == GET_MODE (XEXP (SET_SRC (x
), 0))
3112 && 1 <= (pos
= exact_log2
3113 (nonzero_bits (XEXP (SET_SRC (x
), 0),
3114 GET_MODE (XEXP (SET_SRC (x
), 0))))))
3116 enum machine_mode mode
= GET_MODE (XEXP (SET_SRC (x
), 0));
3120 gen_rtx_LSHIFTRT (mode
,
3121 XEXP (SET_SRC (x
), 0),
3124 split
= find_split_point (&SET_SRC (x
), insn
);
3125 if (split
&& split
!= &SET_SRC (x
))
3131 inner
= XEXP (SET_SRC (x
), 0);
3133 /* We can't optimize if either mode is a partial integer
3134 mode as we don't know how many bits are significant
3136 if (GET_MODE_CLASS (GET_MODE (inner
)) == MODE_PARTIAL_INT
3137 || GET_MODE_CLASS (GET_MODE (SET_SRC (x
))) == MODE_PARTIAL_INT
)
3141 len
= GET_MODE_BITSIZE (GET_MODE (inner
));
3147 if (GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST_INT
3148 && GET_CODE (XEXP (SET_SRC (x
), 2)) == CONST_INT
)
3150 inner
= XEXP (SET_SRC (x
), 0);
3151 len
= INTVAL (XEXP (SET_SRC (x
), 1));
3152 pos
= INTVAL (XEXP (SET_SRC (x
), 2));
3154 if (BITS_BIG_ENDIAN
)
3155 pos
= GET_MODE_BITSIZE (GET_MODE (inner
)) - len
- pos
;
3156 unsignedp
= (code
== ZERO_EXTRACT
);
3164 if (len
&& pos
>= 0 && pos
+ len
<= GET_MODE_BITSIZE (GET_MODE (inner
)))
3166 enum machine_mode mode
= GET_MODE (SET_SRC (x
));
3168 /* For unsigned, we have a choice of a shift followed by an
3169 AND or two shifts. Use two shifts for field sizes where the
3170 constant might be too large. We assume here that we can
3171 always at least get 8-bit constants in an AND insn, which is
3172 true for every current RISC. */
3174 if (unsignedp
&& len
<= 8)
3179 (mode
, gen_lowpart_for_combine (mode
, inner
),
3181 GEN_INT (((HOST_WIDE_INT
) 1 << len
) - 1)));
3183 split
= find_split_point (&SET_SRC (x
), insn
);
3184 if (split
&& split
!= &SET_SRC (x
))
3191 (unsignedp
? LSHIFTRT
: ASHIFTRT
, mode
,
3192 gen_rtx_ASHIFT (mode
,
3193 gen_lowpart_for_combine (mode
, inner
),
3194 GEN_INT (GET_MODE_BITSIZE (mode
)
3196 GEN_INT (GET_MODE_BITSIZE (mode
) - len
)));
3198 split
= find_split_point (&SET_SRC (x
), insn
);
3199 if (split
&& split
!= &SET_SRC (x
))
3204 /* See if this is a simple operation with a constant as the second
3205 operand. It might be that this constant is out of range and hence
3206 could be used as a split point. */
3207 if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == '2'
3208 || GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == 'c'
3209 || GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == '<')
3210 && CONSTANT_P (XEXP (SET_SRC (x
), 1))
3211 && (GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (x
), 0))) == 'o'
3212 || (GET_CODE (XEXP (SET_SRC (x
), 0)) == SUBREG
3213 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (SET_SRC (x
), 0))))
3215 return &XEXP (SET_SRC (x
), 1);
3217 /* Finally, see if this is a simple operation with its first operand
3218 not in a register. The operation might require this operand in a
3219 register, so return it as a split point. We can always do this
3220 because if the first operand were another operation, we would have
3221 already found it as a split point. */
3222 if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == '2'
3223 || GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == 'c'
3224 || GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == '<'
3225 || GET_RTX_CLASS (GET_CODE (SET_SRC (x
))) == '1')
3226 && ! register_operand (XEXP (SET_SRC (x
), 0), VOIDmode
))
3227 return &XEXP (SET_SRC (x
), 0);
3233 /* We write NOR as (and (not A) (not B)), but if we don't have a NOR,
3234 it is better to write this as (not (ior A B)) so we can split it.
3235 Similarly for IOR. */
3236 if (GET_CODE (XEXP (x
, 0)) == NOT
&& GET_CODE (XEXP (x
, 1)) == NOT
)
3239 gen_rtx_NOT (GET_MODE (x
),
3240 gen_rtx_fmt_ee (code
== IOR
? AND
: IOR
,
3242 XEXP (XEXP (x
, 0), 0),
3243 XEXP (XEXP (x
, 1), 0))));
3244 return find_split_point (loc
, insn
);
3247 /* Many RISC machines have a large set of logical insns. If the
3248 second operand is a NOT, put it first so we will try to split the
3249 other operand first. */
3250 if (GET_CODE (XEXP (x
, 1)) == NOT
)
3252 rtx tem
= XEXP (x
, 0);
3253 SUBST (XEXP (x
, 0), XEXP (x
, 1));
3254 SUBST (XEXP (x
, 1), tem
);
3262 /* Otherwise, select our actions depending on our rtx class. */
3263 switch (GET_RTX_CLASS (code
))
3265 case 'b': /* This is ZERO_EXTRACT and SIGN_EXTRACT. */
3267 split
= find_split_point (&XEXP (x
, 2), insn
);
3270 /* ... fall through ... */
3274 split
= find_split_point (&XEXP (x
, 1), insn
);
3277 /* ... fall through ... */
3279 /* Some machines have (and (shift ...) ...) insns. If X is not
3280 an AND, but XEXP (X, 0) is, use it as our split point. */
3281 if (GET_CODE (x
) != AND
&& GET_CODE (XEXP (x
, 0)) == AND
)
3282 return &XEXP (x
, 0);
3284 split
= find_split_point (&XEXP (x
, 0), insn
);
3290 /* Otherwise, we don't have a split point. */
3294 /* Throughout X, replace FROM with TO, and return the result.
3295 The result is TO if X is FROM;
3296 otherwise the result is X, but its contents may have been modified.
3297 If they were modified, a record was made in undobuf so that
3298 undo_all will (among other things) return X to its original state.
3300 If the number of changes necessary is too much to record to undo,
3301 the excess changes are not made, so the result is invalid.
3302 The changes already made can still be undone.
3303 undobuf.num_undo is incremented for such changes, so by testing that
3304 the caller can tell whether the result is valid.
3306 `n_occurrences' is incremented each time FROM is replaced.
3308 IN_DEST is nonzero if we are processing the SET_DEST of a SET.
3310 UNIQUE_COPY is nonzero if each substitution must be unique. We do this
3311 by copying if `n_occurrences' is nonzero. */
3314 subst (x
, from
, to
, in_dest
, unique_copy
)
3319 enum rtx_code code
= GET_CODE (x
);
3320 enum machine_mode op0_mode
= VOIDmode
;
3325 /* Two expressions are equal if they are identical copies of a shared
3326 RTX or if they are both registers with the same register number
3329 #define COMBINE_RTX_EQUAL_P(X,Y) \
3331 || (GET_CODE (X) == REG && GET_CODE (Y) == REG \
3332 && REGNO (X) == REGNO (Y) && GET_MODE (X) == GET_MODE (Y)))
3334 if (! in_dest
&& COMBINE_RTX_EQUAL_P (x
, from
))
3337 return (unique_copy
&& n_occurrences
> 1 ? copy_rtx (to
) : to
);
3340 /* If X and FROM are the same register but different modes, they will
3341 not have been seen as equal above. However, flow.c will make a
3342 LOG_LINKS entry for that case. If we do nothing, we will try to
3343 rerecognize our original insn and, when it succeeds, we will
3344 delete the feeding insn, which is incorrect.
3346 So force this insn not to match in this (rare) case. */
3347 if (! in_dest
&& code
== REG
&& GET_CODE (from
) == REG
3348 && REGNO (x
) == REGNO (from
))
3349 return gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
3351 /* If this is an object, we are done unless it is a MEM or LO_SUM, both
3352 of which may contain things that can be combined. */
3353 if (code
!= MEM
&& code
!= LO_SUM
&& GET_RTX_CLASS (code
) == 'o')
3356 /* It is possible to have a subexpression appear twice in the insn.
3357 Suppose that FROM is a register that appears within TO.
3358 Then, after that subexpression has been scanned once by `subst',
3359 the second time it is scanned, TO may be found. If we were
3360 to scan TO here, we would find FROM within it and create a
3361 self-referent rtl structure which is completely wrong. */
3362 if (COMBINE_RTX_EQUAL_P (x
, to
))
3365 /* Parallel asm_operands need special attention because all of the
3366 inputs are shared across the arms. Furthermore, unsharing the
3367 rtl results in recognition failures. Failure to handle this case
3368 specially can result in circular rtl.
3370 Solve this by doing a normal pass across the first entry of the
3371 parallel, and only processing the SET_DESTs of the subsequent
3374 if (code
== PARALLEL
3375 && GET_CODE (XVECEXP (x
, 0, 0)) == SET
3376 && GET_CODE (SET_SRC (XVECEXP (x
, 0, 0))) == ASM_OPERANDS
)
3378 new = subst (XVECEXP (x
, 0, 0), from
, to
, 0, unique_copy
);
3380 /* If this substitution failed, this whole thing fails. */
3381 if (GET_CODE (new) == CLOBBER
3382 && XEXP (new, 0) == const0_rtx
)
3385 SUBST (XVECEXP (x
, 0, 0), new);
3387 for (i
= XVECLEN (x
, 0) - 1; i
>= 1; i
--)
3389 rtx dest
= SET_DEST (XVECEXP (x
, 0, i
));
3391 if (GET_CODE (dest
) != REG
3392 && GET_CODE (dest
) != CC0
3393 && GET_CODE (dest
) != PC
)
3395 new = subst (dest
, from
, to
, 0, unique_copy
);
3397 /* If this substitution failed, this whole thing fails. */
3398 if (GET_CODE (new) == CLOBBER
3399 && XEXP (new, 0) == const0_rtx
)
3402 SUBST (SET_DEST (XVECEXP (x
, 0, i
)), new);
3408 len
= GET_RTX_LENGTH (code
);
3409 fmt
= GET_RTX_FORMAT (code
);
3411 /* We don't need to process a SET_DEST that is a register, CC0,
3412 or PC, so set up to skip this common case. All other cases
3413 where we want to suppress replacing something inside a
3414 SET_SRC are handled via the IN_DEST operand. */
3416 && (GET_CODE (SET_DEST (x
)) == REG
3417 || GET_CODE (SET_DEST (x
)) == CC0
3418 || GET_CODE (SET_DEST (x
)) == PC
))
3421 /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a
3424 op0_mode
= GET_MODE (XEXP (x
, 0));
3426 for (i
= 0; i
< len
; i
++)
3431 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3433 if (COMBINE_RTX_EQUAL_P (XVECEXP (x
, i
, j
), from
))
3435 new = (unique_copy
&& n_occurrences
3436 ? copy_rtx (to
) : to
);
3441 new = subst (XVECEXP (x
, i
, j
), from
, to
, 0,
3444 /* If this substitution failed, this whole thing
3446 if (GET_CODE (new) == CLOBBER
3447 && XEXP (new, 0) == const0_rtx
)
3451 SUBST (XVECEXP (x
, i
, j
), new);
3454 else if (fmt
[i
] == 'e')
3456 /* If this is a register being set, ignore it. */
3459 && (code
== SUBREG
|| code
== STRICT_LOW_PART
3460 || code
== ZERO_EXTRACT
)
3462 && GET_CODE (new) == REG
)
3465 else if (COMBINE_RTX_EQUAL_P (XEXP (x
, i
), from
))
3467 /* In general, don't install a subreg involving two
3468 modes not tieable. It can worsen register
3469 allocation, and can even make invalid reload
3470 insns, since the reg inside may need to be copied
3471 from in the outside mode, and that may be invalid
3472 if it is an fp reg copied in integer mode.
3474 We allow two exceptions to this: It is valid if
3475 it is inside another SUBREG and the mode of that
3476 SUBREG and the mode of the inside of TO is
3477 tieable and it is valid if X is a SET that copies
3480 if (GET_CODE (to
) == SUBREG
3481 && ! MODES_TIEABLE_P (GET_MODE (to
),
3482 GET_MODE (SUBREG_REG (to
)))
3483 && ! (code
== SUBREG
3484 && MODES_TIEABLE_P (GET_MODE (x
),
3485 GET_MODE (SUBREG_REG (to
))))
3487 && ! (code
== SET
&& i
== 1 && XEXP (x
, 0) == cc0_rtx
)
3490 return gen_rtx_CLOBBER (VOIDmode
, const0_rtx
);
3492 #ifdef CANNOT_CHANGE_MODE_CLASS
3494 && GET_CODE (to
) == REG
3495 && REGNO (to
) < FIRST_PSEUDO_REGISTER
3496 && REG_CANNOT_CHANGE_MODE_P (REGNO (to
),
3499 return gen_rtx_CLOBBER (VOIDmode
, const0_rtx
);
3502 new = (unique_copy
&& n_occurrences
? copy_rtx (to
) : to
);
3506 /* If we are in a SET_DEST, suppress most cases unless we
3507 have gone inside a MEM, in which case we want to
3508 simplify the address. We assume here that things that
3509 are actually part of the destination have their inner
3510 parts in the first expression. This is true for SUBREG,
3511 STRICT_LOW_PART, and ZERO_EXTRACT, which are the only
3512 things aside from REG and MEM that should appear in a
3514 new = subst (XEXP (x
, i
), from
, to
,
3516 && (code
== SUBREG
|| code
== STRICT_LOW_PART
3517 || code
== ZERO_EXTRACT
))
3519 && i
== 0), unique_copy
);
3521 /* If we found that we will have to reject this combination,
3522 indicate that by returning the CLOBBER ourselves, rather than
3523 an expression containing it. This will speed things up as
3524 well as prevent accidents where two CLOBBERs are considered
3525 to be equal, thus producing an incorrect simplification. */
3527 if (GET_CODE (new) == CLOBBER
&& XEXP (new, 0) == const0_rtx
)
3530 if (GET_CODE (new) == CONST_INT
&& GET_CODE (x
) == SUBREG
)
3532 enum machine_mode mode
= GET_MODE (x
);
3534 x
= simplify_subreg (GET_MODE (x
), new,
3535 GET_MODE (SUBREG_REG (x
)),
3538 x
= gen_rtx_CLOBBER (mode
, const0_rtx
);
3540 else if (GET_CODE (new) == CONST_INT
3541 && GET_CODE (x
) == ZERO_EXTEND
)
3543 x
= simplify_unary_operation (ZERO_EXTEND
, GET_MODE (x
),
3544 new, GET_MODE (XEXP (x
, 0)));
3549 SUBST (XEXP (x
, i
), new);
3554 /* Try to simplify X. If the simplification changed the code, it is likely
3555 that further simplification will help, so loop, but limit the number
3556 of repetitions that will be performed. */
3558 for (i
= 0; i
< 4; i
++)
3560 /* If X is sufficiently simple, don't bother trying to do anything
3562 if (code
!= CONST_INT
&& code
!= REG
&& code
!= CLOBBER
)
3563 x
= combine_simplify_rtx (x
, op0_mode
, i
== 3, in_dest
);
3565 if (GET_CODE (x
) == code
)
3568 code
= GET_CODE (x
);
3570 /* We no longer know the original mode of operand 0 since we
3571 have changed the form of X) */
3572 op0_mode
= VOIDmode
;
3578 /* Simplify X, a piece of RTL. We just operate on the expression at the
3579 outer level; call `subst' to simplify recursively. Return the new
3582 OP0_MODE is the original mode of XEXP (x, 0); LAST is nonzero if this
3583 will be the iteration even if an expression with a code different from
3584 X is returned; IN_DEST is nonzero if we are inside a SET_DEST. */
3587 combine_simplify_rtx (x
, op0_mode
, last
, in_dest
)
3589 enum machine_mode op0_mode
;
3593 enum rtx_code code
= GET_CODE (x
);
3594 enum machine_mode mode
= GET_MODE (x
);
3599 /* If this is a commutative operation, put a constant last and a complex
3600 expression first. We don't need to do this for comparisons here. */
3601 if (GET_RTX_CLASS (code
) == 'c'
3602 && swap_commutative_operands_p (XEXP (x
, 0), XEXP (x
, 1)))
3605 SUBST (XEXP (x
, 0), XEXP (x
, 1));
3606 SUBST (XEXP (x
, 1), temp
);
3609 /* If this is a PLUS, MINUS, or MULT, and the first operand is the
3610 sign extension of a PLUS with a constant, reverse the order of the sign
3611 extension and the addition. Note that this not the same as the original
3612 code, but overflow is undefined for signed values. Also note that the
3613 PLUS will have been partially moved "inside" the sign-extension, so that
3614 the first operand of X will really look like:
3615 (ashiftrt (plus (ashift A C4) C5) C4).
3617 (plus (ashiftrt (ashift A C4) C2) C4)
3618 and replace the first operand of X with that expression. Later parts
3619 of this function may simplify the expression further.
3621 For example, if we start with (mult (sign_extend (plus A C1)) C2),
3622 we swap the SIGN_EXTEND and PLUS. Later code will apply the
3623 distributive law to produce (plus (mult (sign_extend X) C1) C3).
3625 We do this to simplify address expressions. */
3627 if ((code
== PLUS
|| code
== MINUS
|| code
== MULT
)
3628 && GET_CODE (XEXP (x
, 0)) == ASHIFTRT
3629 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
3630 && GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == ASHIFT
3631 && GET_CODE (XEXP (XEXP (XEXP (XEXP (x
, 0), 0), 0), 1)) == CONST_INT
3632 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3633 && XEXP (XEXP (XEXP (XEXP (x
, 0), 0), 0), 1) == XEXP (XEXP (x
, 0), 1)
3634 && GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 1)) == CONST_INT
3635 && (temp
= simplify_binary_operation (ASHIFTRT
, mode
,
3636 XEXP (XEXP (XEXP (x
, 0), 0), 1),
3637 XEXP (XEXP (x
, 0), 1))) != 0)
3640 = simplify_shift_const (NULL_RTX
, ASHIFT
, mode
,
3641 XEXP (XEXP (XEXP (XEXP (x
, 0), 0), 0), 0),
3642 INTVAL (XEXP (XEXP (x
, 0), 1)));
3644 new = simplify_shift_const (NULL_RTX
, ASHIFTRT
, mode
, new,
3645 INTVAL (XEXP (XEXP (x
, 0), 1)));
3647 SUBST (XEXP (x
, 0), gen_binary (PLUS
, mode
, new, temp
));
3650 /* If this is a simple operation applied to an IF_THEN_ELSE, try
3651 applying it to the arms of the IF_THEN_ELSE. This often simplifies
3652 things. Check for cases where both arms are testing the same
3655 Don't do anything if all operands are very simple. */
3657 if (((GET_RTX_CLASS (code
) == '2' || GET_RTX_CLASS (code
) == 'c'
3658 || GET_RTX_CLASS (code
) == '<')
3659 && ((GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) != 'o'
3660 && ! (GET_CODE (XEXP (x
, 0)) == SUBREG
3661 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x
, 0))))
3663 || (GET_RTX_CLASS (GET_CODE (XEXP (x
, 1))) != 'o'
3664 && ! (GET_CODE (XEXP (x
, 1)) == SUBREG
3665 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x
, 1))))
3667 || (GET_RTX_CLASS (code
) == '1'
3668 && ((GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) != 'o'
3669 && ! (GET_CODE (XEXP (x
, 0)) == SUBREG
3670 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x
, 0))))
3673 rtx cond
, true_rtx
, false_rtx
;
3675 cond
= if_then_else_cond (x
, &true_rtx
, &false_rtx
);
3677 /* If everything is a comparison, what we have is highly unlikely
3678 to be simpler, so don't use it. */
3679 && ! (GET_RTX_CLASS (code
) == '<'
3680 && (GET_RTX_CLASS (GET_CODE (true_rtx
)) == '<'
3681 || GET_RTX_CLASS (GET_CODE (false_rtx
)) == '<')))
3683 rtx cop1
= const0_rtx
;
3684 enum rtx_code cond_code
= simplify_comparison (NE
, &cond
, &cop1
);
3686 if (cond_code
== NE
&& GET_RTX_CLASS (GET_CODE (cond
)) == '<')
3689 /* Simplify the alternative arms; this may collapse the true and
3690 false arms to store-flag values. */
3691 true_rtx
= subst (true_rtx
, pc_rtx
, pc_rtx
, 0, 0);
3692 false_rtx
= subst (false_rtx
, pc_rtx
, pc_rtx
, 0, 0);
3694 /* If true_rtx and false_rtx are not general_operands, an if_then_else
3695 is unlikely to be simpler. */
3696 if (general_operand (true_rtx
, VOIDmode
)
3697 && general_operand (false_rtx
, VOIDmode
))
3699 enum rtx_code reversed
;
3701 /* Restarting if we generate a store-flag expression will cause
3702 us to loop. Just drop through in this case. */
3704 /* If the result values are STORE_FLAG_VALUE and zero, we can
3705 just make the comparison operation. */
3706 if (true_rtx
== const_true_rtx
&& false_rtx
== const0_rtx
)
3707 x
= gen_binary (cond_code
, mode
, cond
, cop1
);
3708 else if (true_rtx
== const0_rtx
&& false_rtx
== const_true_rtx
3709 && ((reversed
= reversed_comparison_code_parts
3710 (cond_code
, cond
, cop1
, NULL
))
3712 x
= gen_binary (reversed
, mode
, cond
, cop1
);
3714 /* Likewise, we can make the negate of a comparison operation
3715 if the result values are - STORE_FLAG_VALUE and zero. */
3716 else if (GET_CODE (true_rtx
) == CONST_INT
3717 && INTVAL (true_rtx
) == - STORE_FLAG_VALUE
3718 && false_rtx
== const0_rtx
)
3719 x
= simplify_gen_unary (NEG
, mode
,
3720 gen_binary (cond_code
, mode
, cond
,
3723 else if (GET_CODE (false_rtx
) == CONST_INT
3724 && INTVAL (false_rtx
) == - STORE_FLAG_VALUE
3725 && true_rtx
== const0_rtx
3726 && ((reversed
= reversed_comparison_code_parts
3727 (cond_code
, cond
, cop1
, NULL
))
3729 x
= simplify_gen_unary (NEG
, mode
,
3730 gen_binary (reversed
, mode
,
3734 return gen_rtx_IF_THEN_ELSE (mode
,
3735 gen_binary (cond_code
, VOIDmode
,
3737 true_rtx
, false_rtx
);
3739 code
= GET_CODE (x
);
3740 op0_mode
= VOIDmode
;
3745 /* Try to fold this expression in case we have constants that weren't
3748 switch (GET_RTX_CLASS (code
))
3751 temp
= simplify_unary_operation (code
, mode
, XEXP (x
, 0), op0_mode
);
3755 enum machine_mode cmp_mode
= GET_MODE (XEXP (x
, 0));
3756 if (cmp_mode
== VOIDmode
)
3758 cmp_mode
= GET_MODE (XEXP (x
, 1));
3759 if (cmp_mode
== VOIDmode
)
3760 cmp_mode
= op0_mode
;
3762 temp
= simplify_relational_operation (code
, cmp_mode
,
3763 XEXP (x
, 0), XEXP (x
, 1));
3765 #ifdef FLOAT_STORE_FLAG_VALUE
3766 if (temp
!= 0 && GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3768 if (temp
== const0_rtx
)
3769 temp
= CONST0_RTX (mode
);
3771 temp
= CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE (mode
),
3778 temp
= simplify_binary_operation (code
, mode
, XEXP (x
, 0), XEXP (x
, 1));
3782 temp
= simplify_ternary_operation (code
, mode
, op0_mode
, XEXP (x
, 0),
3783 XEXP (x
, 1), XEXP (x
, 2));
3790 code
= GET_CODE (temp
);
3791 op0_mode
= VOIDmode
;
3792 mode
= GET_MODE (temp
);
3795 /* First see if we can apply the inverse distributive law. */
3796 if (code
== PLUS
|| code
== MINUS
3797 || code
== AND
|| code
== IOR
|| code
== XOR
)
3799 x
= apply_distributive_law (x
);
3800 code
= GET_CODE (x
);
3801 op0_mode
= VOIDmode
;
3804 /* If CODE is an associative operation not otherwise handled, see if we
3805 can associate some operands. This can win if they are constants or
3806 if they are logically related (i.e. (a & b) & a). */
3807 if ((code
== PLUS
|| code
== MINUS
|| code
== MULT
|| code
== DIV
3808 || code
== AND
|| code
== IOR
|| code
== XOR
3809 || code
== SMAX
|| code
== SMIN
|| code
== UMAX
|| code
== UMIN
)
3810 && ((INTEGRAL_MODE_P (mode
) && code
!= DIV
)
3811 || (flag_unsafe_math_optimizations
&& FLOAT_MODE_P (mode
))))
3813 if (GET_CODE (XEXP (x
, 0)) == code
)
3815 rtx other
= XEXP (XEXP (x
, 0), 0);
3816 rtx inner_op0
= XEXP (XEXP (x
, 0), 1);
3817 rtx inner_op1
= XEXP (x
, 1);
3820 /* Make sure we pass the constant operand if any as the second
3821 one if this is a commutative operation. */
3822 if (CONSTANT_P (inner_op0
) && GET_RTX_CLASS (code
) == 'c')
3824 rtx tem
= inner_op0
;
3825 inner_op0
= inner_op1
;
3828 inner
= simplify_binary_operation (code
== MINUS
? PLUS
3829 : code
== DIV
? MULT
3831 mode
, inner_op0
, inner_op1
);
3833 /* For commutative operations, try the other pair if that one
3835 if (inner
== 0 && GET_RTX_CLASS (code
) == 'c')
3837 other
= XEXP (XEXP (x
, 0), 1);
3838 inner
= simplify_binary_operation (code
, mode
,
3839 XEXP (XEXP (x
, 0), 0),
3844 return gen_binary (code
, mode
, other
, inner
);
3848 /* A little bit of algebraic simplification here. */
3852 /* Ensure that our address has any ASHIFTs converted to MULT in case
3853 address-recognizing predicates are called later. */
3854 temp
= make_compound_operation (XEXP (x
, 0), MEM
);
3855 SUBST (XEXP (x
, 0), temp
);
3859 if (op0_mode
== VOIDmode
)
3860 op0_mode
= GET_MODE (SUBREG_REG (x
));
3862 /* simplify_subreg can't use gen_lowpart_for_combine. */
3863 if (CONSTANT_P (SUBREG_REG (x
))
3864 && subreg_lowpart_offset (mode
, op0_mode
) == SUBREG_BYTE (x
)
3865 /* Don't call gen_lowpart_for_combine if the inner mode
3866 is VOIDmode and we cannot simplify it, as SUBREG without
3867 inner mode is invalid. */
3868 && (GET_MODE (SUBREG_REG (x
)) != VOIDmode
3869 || gen_lowpart_common (mode
, SUBREG_REG (x
))))
3870 return gen_lowpart_for_combine (mode
, SUBREG_REG (x
));
3872 if (GET_MODE_CLASS (GET_MODE (SUBREG_REG (x
))) == MODE_CC
)
3876 temp
= simplify_subreg (mode
, SUBREG_REG (x
), op0_mode
,
3882 /* Don't change the mode of the MEM if that would change the meaning
3884 if (GET_CODE (SUBREG_REG (x
)) == MEM
3885 && (MEM_VOLATILE_P (SUBREG_REG (x
))
3886 || mode_dependent_address_p (XEXP (SUBREG_REG (x
), 0))))
3887 return gen_rtx_CLOBBER (mode
, const0_rtx
);
3889 /* Note that we cannot do any narrowing for non-constants since
3890 we might have been counting on using the fact that some bits were
3891 zero. We now do this in the SET. */
3896 /* (not (plus X -1)) can become (neg X). */
3897 if (GET_CODE (XEXP (x
, 0)) == PLUS
3898 && XEXP (XEXP (x
, 0), 1) == constm1_rtx
)
3899 return gen_rtx_NEG (mode
, XEXP (XEXP (x
, 0), 0));
3901 /* Similarly, (not (neg X)) is (plus X -1). */
3902 if (GET_CODE (XEXP (x
, 0)) == NEG
)
3903 return gen_rtx_PLUS (mode
, XEXP (XEXP (x
, 0), 0), constm1_rtx
);
3905 /* (not (xor X C)) for C constant is (xor X D) with D = ~C. */
3906 if (GET_CODE (XEXP (x
, 0)) == XOR
3907 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3908 && (temp
= simplify_unary_operation (NOT
, mode
,
3909 XEXP (XEXP (x
, 0), 1),
3911 return gen_binary (XOR
, mode
, XEXP (XEXP (x
, 0), 0), temp
);
3913 /* (not (ashift 1 X)) is (rotate ~1 X). We used to do this for operands
3914 other than 1, but that is not valid. We could do a similar
3915 simplification for (not (lshiftrt C X)) where C is just the sign bit,
3916 but this doesn't seem common enough to bother with. */
3917 if (GET_CODE (XEXP (x
, 0)) == ASHIFT
3918 && XEXP (XEXP (x
, 0), 0) == const1_rtx
)
3919 return gen_rtx_ROTATE (mode
, simplify_gen_unary (NOT
, mode
,
3921 XEXP (XEXP (x
, 0), 1));
3923 if (GET_CODE (XEXP (x
, 0)) == SUBREG
3924 && subreg_lowpart_p (XEXP (x
, 0))
3925 && (GET_MODE_SIZE (GET_MODE (XEXP (x
, 0)))
3926 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (x
, 0)))))
3927 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == ASHIFT
3928 && XEXP (SUBREG_REG (XEXP (x
, 0)), 0) == const1_rtx
)
3930 enum machine_mode inner_mode
= GET_MODE (SUBREG_REG (XEXP (x
, 0)));
3932 x
= gen_rtx_ROTATE (inner_mode
,
3933 simplify_gen_unary (NOT
, inner_mode
, const1_rtx
,
3935 XEXP (SUBREG_REG (XEXP (x
, 0)), 1));
3936 return gen_lowpart_for_combine (mode
, x
);
3939 /* If STORE_FLAG_VALUE is -1, (not (comparison foo bar)) can be done by
3940 reversing the comparison code if valid. */
3941 if (STORE_FLAG_VALUE
== -1
3942 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == '<'
3943 && (reversed
= reversed_comparison (x
, mode
, XEXP (XEXP (x
, 0), 0),
3944 XEXP (XEXP (x
, 0), 1))))
3947 /* (not (ashiftrt foo C)) where C is the number of bits in FOO minus 1
3948 is (ge foo (const_int 0)) if STORE_FLAG_VALUE is -1, so we can
3949 perform the above simplification. */
3951 if (STORE_FLAG_VALUE
== -1
3952 && GET_CODE (XEXP (x
, 0)) == ASHIFTRT
3953 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3954 && INTVAL (XEXP (XEXP (x
, 0), 1)) == GET_MODE_BITSIZE (mode
) - 1)
3955 return gen_rtx_GE (mode
, XEXP (XEXP (x
, 0), 0), const0_rtx
);
3957 /* Apply De Morgan's laws to reduce number of patterns for machines
3958 with negating logical insns (and-not, nand, etc.). If result has
3959 only one NOT, put it first, since that is how the patterns are
3962 if (GET_CODE (XEXP (x
, 0)) == IOR
|| GET_CODE (XEXP (x
, 0)) == AND
)
3964 rtx in1
= XEXP (XEXP (x
, 0), 0), in2
= XEXP (XEXP (x
, 0), 1);
3965 enum machine_mode op_mode
;
3967 op_mode
= GET_MODE (in1
);
3968 in1
= simplify_gen_unary (NOT
, op_mode
, in1
, op_mode
);
3970 op_mode
= GET_MODE (in2
);
3971 if (op_mode
== VOIDmode
)
3973 in2
= simplify_gen_unary (NOT
, op_mode
, in2
, op_mode
);
3975 if (GET_CODE (in2
) == NOT
&& GET_CODE (in1
) != NOT
)
3978 in2
= in1
; in1
= tem
;
3981 return gen_rtx_fmt_ee (GET_CODE (XEXP (x
, 0)) == IOR
? AND
: IOR
,
3987 /* (neg (plus X 1)) can become (not X). */
3988 if (GET_CODE (XEXP (x
, 0)) == PLUS
3989 && XEXP (XEXP (x
, 0), 1) == const1_rtx
)
3990 return gen_rtx_NOT (mode
, XEXP (XEXP (x
, 0), 0));
3992 /* Similarly, (neg (not X)) is (plus X 1). */
3993 if (GET_CODE (XEXP (x
, 0)) == NOT
)
3994 return plus_constant (XEXP (XEXP (x
, 0), 0), 1);
3996 /* (neg (minus X Y)) can become (minus Y X). This transformation
3997 isn't safe for modes with signed zeros, since if X and Y are
3998 both +0, (minus Y X) is the same as (minus X Y). If the rounding
3999 mode is towards +infinity (or -infinity) then the two expressions
4000 will be rounded differently. */
4001 if (GET_CODE (XEXP (x
, 0)) == MINUS
4002 && !HONOR_SIGNED_ZEROS (mode
)
4003 && !HONOR_SIGN_DEPENDENT_ROUNDING (mode
))
4004 return gen_binary (MINUS
, mode
, XEXP (XEXP (x
, 0), 1),
4005 XEXP (XEXP (x
, 0), 0));
4007 /* (neg (plus A B)) is canonicalized to (minus (neg A) B). */
4008 if (GET_CODE (XEXP (x
, 0)) == PLUS
4009 && !HONOR_SIGNED_ZEROS (mode
)
4010 && !HONOR_SIGN_DEPENDENT_ROUNDING (mode
))
4012 temp
= simplify_gen_unary (NEG
, mode
, XEXP (XEXP (x
, 0), 0), mode
);
4013 temp
= combine_simplify_rtx (temp
, mode
, last
, in_dest
);
4014 return gen_binary (MINUS
, mode
, temp
, XEXP (XEXP (x
, 0), 1));
4017 /* (neg (mult A B)) becomes (mult (neg A) B).
4018 This works even for floating-point values. */
4019 if (GET_CODE (XEXP (x
, 0)) == MULT
)
4021 temp
= simplify_gen_unary (NEG
, mode
, XEXP (XEXP (x
, 0), 0), mode
);
4022 return gen_binary (MULT
, mode
, temp
, XEXP (XEXP (x
, 0), 1));
4025 /* (neg (xor A 1)) is (plus A -1) if A is known to be either 0 or 1. */
4026 if (GET_CODE (XEXP (x
, 0)) == XOR
&& XEXP (XEXP (x
, 0), 1) == const1_rtx
4027 && nonzero_bits (XEXP (XEXP (x
, 0), 0), mode
) == 1)
4028 return gen_binary (PLUS
, mode
, XEXP (XEXP (x
, 0), 0), constm1_rtx
);
4030 /* NEG commutes with ASHIFT since it is multiplication. Only do this
4031 if we can then eliminate the NEG (e.g.,
4032 if the operand is a constant). */
4034 if (GET_CODE (XEXP (x
, 0)) == ASHIFT
)
4036 temp
= simplify_unary_operation (NEG
, mode
,
4037 XEXP (XEXP (x
, 0), 0), mode
);
4039 return gen_binary (ASHIFT
, mode
, temp
, XEXP (XEXP (x
, 0), 1));
4042 temp
= expand_compound_operation (XEXP (x
, 0));
4044 /* For C equal to the width of MODE minus 1, (neg (ashiftrt X C)) can be
4045 replaced by (lshiftrt X C). This will convert
4046 (neg (sign_extract X 1 Y)) to (zero_extract X 1 Y). */
4048 if (GET_CODE (temp
) == ASHIFTRT
4049 && GET_CODE (XEXP (temp
, 1)) == CONST_INT
4050 && INTVAL (XEXP (temp
, 1)) == GET_MODE_BITSIZE (mode
) - 1)
4051 return simplify_shift_const (temp
, LSHIFTRT
, mode
, XEXP (temp
, 0),
4052 INTVAL (XEXP (temp
, 1)));
4054 /* If X has only a single bit that might be nonzero, say, bit I, convert
4055 (neg X) to (ashiftrt (ashift X C-I) C-I) where C is the bitsize of
4056 MODE minus 1. This will convert (neg (zero_extract X 1 Y)) to
4057 (sign_extract X 1 Y). But only do this if TEMP isn't a register
4058 or a SUBREG of one since we'd be making the expression more
4059 complex if it was just a register. */
4061 if (GET_CODE (temp
) != REG
4062 && ! (GET_CODE (temp
) == SUBREG
4063 && GET_CODE (SUBREG_REG (temp
)) == REG
)
4064 && (i
= exact_log2 (nonzero_bits (temp
, mode
))) >= 0)
4066 rtx temp1
= simplify_shift_const
4067 (NULL_RTX
, ASHIFTRT
, mode
,
4068 simplify_shift_const (NULL_RTX
, ASHIFT
, mode
, temp
,
4069 GET_MODE_BITSIZE (mode
) - 1 - i
),
4070 GET_MODE_BITSIZE (mode
) - 1 - i
);
4072 /* If all we did was surround TEMP with the two shifts, we
4073 haven't improved anything, so don't use it. Otherwise,
4074 we are better off with TEMP1. */
4075 if (GET_CODE (temp1
) != ASHIFTRT
4076 || GET_CODE (XEXP (temp1
, 0)) != ASHIFT
4077 || XEXP (XEXP (temp1
, 0), 0) != temp
)
4083 /* We can't handle truncation to a partial integer mode here
4084 because we don't know the real bitsize of the partial
4086 if (GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
4089 if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
4090 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode
),
4091 GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))))
4093 force_to_mode (XEXP (x
, 0), GET_MODE (XEXP (x
, 0)),
4094 GET_MODE_MASK (mode
), NULL_RTX
, 0));
4096 /* (truncate:SI ({sign,zero}_extend:DI foo:SI)) == foo:SI. */
4097 if ((GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
4098 || GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
)
4099 && GET_MODE (XEXP (XEXP (x
, 0), 0)) == mode
)
4100 return XEXP (XEXP (x
, 0), 0);
4102 /* (truncate:SI (OP:DI ({sign,zero}_extend:DI foo:SI))) is
4103 (OP:SI foo:SI) if OP is NEG or ABS. */
4104 if ((GET_CODE (XEXP (x
, 0)) == ABS
4105 || GET_CODE (XEXP (x
, 0)) == NEG
)
4106 && (GET_CODE (XEXP (XEXP (x
, 0), 0)) == SIGN_EXTEND
4107 || GET_CODE (XEXP (XEXP (x
, 0), 0)) == ZERO_EXTEND
)
4108 && GET_MODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == mode
)
4109 return simplify_gen_unary (GET_CODE (XEXP (x
, 0)), mode
,
4110 XEXP (XEXP (XEXP (x
, 0), 0), 0), mode
);
4112 /* (truncate:SI (subreg:DI (truncate:SI X) 0)) is
4114 if (GET_CODE (XEXP (x
, 0)) == SUBREG
4115 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == TRUNCATE
4116 && subreg_lowpart_p (XEXP (x
, 0)))
4117 return SUBREG_REG (XEXP (x
, 0));
4119 /* If we know that the value is already truncated, we can
4120 replace the TRUNCATE with a SUBREG if TRULY_NOOP_TRUNCATION
4121 is nonzero for the corresponding modes. But don't do this
4122 for an (LSHIFTRT (MULT ...)) since this will cause problems
4123 with the umulXi3_highpart patterns. */
4124 if (TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode
),
4125 GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0))))
4126 && num_sign_bit_copies (XEXP (x
, 0), GET_MODE (XEXP (x
, 0)))
4127 >= (unsigned int) (GET_MODE_BITSIZE (mode
) + 1)
4128 && ! (GET_CODE (XEXP (x
, 0)) == LSHIFTRT
4129 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == MULT
))
4130 return gen_lowpart_for_combine (mode
, XEXP (x
, 0));
4132 /* A truncate of a comparison can be replaced with a subreg if
4133 STORE_FLAG_VALUE permits. This is like the previous test,
4134 but it works even if the comparison is done in a mode larger
4135 than HOST_BITS_PER_WIDE_INT. */
4136 if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
4137 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == '<'
4138 && ((HOST_WIDE_INT
) STORE_FLAG_VALUE
& ~GET_MODE_MASK (mode
)) == 0)
4139 return gen_lowpart_for_combine (mode
, XEXP (x
, 0));
4141 /* Similarly, a truncate of a register whose value is a
4142 comparison can be replaced with a subreg if STORE_FLAG_VALUE
4144 if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
4145 && ((HOST_WIDE_INT
) STORE_FLAG_VALUE
& ~GET_MODE_MASK (mode
)) == 0
4146 && (temp
= get_last_value (XEXP (x
, 0)))
4147 && GET_RTX_CLASS (GET_CODE (temp
)) == '<')
4148 return gen_lowpart_for_combine (mode
, XEXP (x
, 0));
4152 case FLOAT_TRUNCATE
:
4153 /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF. */
4154 if (GET_CODE (XEXP (x
, 0)) == FLOAT_EXTEND
4155 && GET_MODE (XEXP (XEXP (x
, 0), 0)) == mode
)
4156 return XEXP (XEXP (x
, 0), 0);
4158 /* (float_truncate:SF (float_truncate:DF foo:XF))
4159 = (float_truncate:SF foo:XF).
4160 This may elliminate double rounding, so it is unsafe.
4162 (float_truncate:SF (float_extend:XF foo:DF))
4163 = (float_truncate:SF foo:DF).
4165 (float_truncate:DF (float_extend:XF foo:SF))
4166 = (float_extend:SF foo:DF). */
4167 if ((GET_CODE (XEXP (x
, 0)) == FLOAT_TRUNCATE
4168 && flag_unsafe_math_optimizations
)
4169 || GET_CODE (XEXP (x
, 0)) == FLOAT_EXTEND
)
4170 return simplify_gen_unary (GET_MODE_SIZE (GET_MODE (XEXP (XEXP (x
, 0),
4172 > GET_MODE_SIZE (mode
)
4173 ? FLOAT_TRUNCATE
: FLOAT_EXTEND
,
4175 XEXP (XEXP (x
, 0), 0), mode
);
4177 /* (float_truncate (float x)) is (float x) */
4178 if (GET_CODE (XEXP (x
, 0)) == FLOAT
4179 && (flag_unsafe_math_optimizations
4180 || ((unsigned)significand_size (GET_MODE (XEXP (x
, 0)))
4181 >= (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x
, 0), 0)))
4182 - num_sign_bit_copies (XEXP (XEXP (x
, 0), 0),
4183 GET_MODE (XEXP (XEXP (x
, 0), 0)))))))
4184 return simplify_gen_unary (FLOAT
, mode
,
4185 XEXP (XEXP (x
, 0), 0),
4186 GET_MODE (XEXP (XEXP (x
, 0), 0)));
4188 /* (float_truncate:SF (OP:DF (float_extend:DF foo:sf))) is
4189 (OP:SF foo:SF) if OP is NEG or ABS. */
4190 if ((GET_CODE (XEXP (x
, 0)) == ABS
4191 || GET_CODE (XEXP (x
, 0)) == NEG
)
4192 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == FLOAT_EXTEND
4193 && GET_MODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == mode
)
4194 return simplify_gen_unary (GET_CODE (XEXP (x
, 0)), mode
,
4195 XEXP (XEXP (XEXP (x
, 0), 0), 0), mode
);
4197 /* (float_truncate:SF (subreg:DF (float_truncate:SF X) 0))
4198 is (float_truncate:SF x). */
4199 if (GET_CODE (XEXP (x
, 0)) == SUBREG
4200 && subreg_lowpart_p (XEXP (x
, 0))
4201 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == FLOAT_TRUNCATE
)
4202 return SUBREG_REG (XEXP (x
, 0));
4205 /* (float_extend (float_extend x)) is (float_extend x)
4207 (float_extend (float x)) is (float x) assuming that double
4208 rounding can't happen.
4210 if (GET_CODE (XEXP (x
, 0)) == FLOAT_EXTEND
4211 || (GET_CODE (XEXP (x
, 0)) == FLOAT
4212 && ((unsigned)significand_size (GET_MODE (XEXP (x
, 0)))
4213 >= (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x
, 0), 0)))
4214 - num_sign_bit_copies (XEXP (XEXP (x
, 0), 0),
4215 GET_MODE (XEXP (XEXP (x
, 0), 0)))))))
4216 return simplify_gen_unary (GET_CODE (XEXP (x
, 0)), mode
,
4217 XEXP (XEXP (x
, 0), 0),
4218 GET_MODE (XEXP (XEXP (x
, 0), 0)));
4223 /* Convert (compare FOO (const_int 0)) to FOO unless we aren't
4224 using cc0, in which case we want to leave it as a COMPARE
4225 so we can distinguish it from a register-register-copy. */
4226 if (XEXP (x
, 1) == const0_rtx
)
4229 /* x - 0 is the same as x unless x's mode has signed zeros and
4230 allows rounding towards -infinity. Under those conditions,
4232 if (!(HONOR_SIGNED_ZEROS (GET_MODE (XEXP (x
, 0)))
4233 && HONOR_SIGN_DEPENDENT_ROUNDING (GET_MODE (XEXP (x
, 0))))
4234 && XEXP (x
, 1) == CONST0_RTX (GET_MODE (XEXP (x
, 0))))
4240 /* (const (const X)) can become (const X). Do it this way rather than
4241 returning the inner CONST since CONST can be shared with a
4243 if (GET_CODE (XEXP (x
, 0)) == CONST
)
4244 SUBST (XEXP (x
, 0), XEXP (XEXP (x
, 0), 0));
4249 /* Convert (lo_sum (high FOO) FOO) to FOO. This is necessary so we
4250 can add in an offset. find_split_point will split this address up
4251 again if it doesn't match. */
4252 if (GET_CODE (XEXP (x
, 0)) == HIGH
4253 && rtx_equal_p (XEXP (XEXP (x
, 0), 0), XEXP (x
, 1)))
4259 /* Canonicalize (plus (mult (neg B) C) A) to (minus A (mult B C)).
4261 if (GET_CODE (XEXP (x
, 0)) == MULT
4262 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == NEG
)
4266 in1
= XEXP (XEXP (XEXP (x
, 0), 0), 0);
4267 in2
= XEXP (XEXP (x
, 0), 1);
4268 return gen_binary (MINUS
, mode
, XEXP (x
, 1),
4269 gen_binary (MULT
, mode
, in1
, in2
));
4272 /* If we have (plus (plus (A const) B)), associate it so that CONST is
4273 outermost. That's because that's the way indexed addresses are
4274 supposed to appear. This code used to check many more cases, but
4275 they are now checked elsewhere. */
4276 if (GET_CODE (XEXP (x
, 0)) == PLUS
4277 && CONSTANT_ADDRESS_P (XEXP (XEXP (x
, 0), 1)))
4278 return gen_binary (PLUS
, mode
,
4279 gen_binary (PLUS
, mode
, XEXP (XEXP (x
, 0), 0),
4281 XEXP (XEXP (x
, 0), 1));
4283 /* (plus (xor (and <foo> (const_int pow2 - 1)) <c>) <-c>)
4284 when c is (const_int (pow2 + 1) / 2) is a sign extension of a
4285 bit-field and can be replaced by either a sign_extend or a
4286 sign_extract. The `and' may be a zero_extend and the two
4287 <c>, -<c> constants may be reversed. */
4288 if (GET_CODE (XEXP (x
, 0)) == XOR
4289 && GET_CODE (XEXP (x
, 1)) == CONST_INT
4290 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
4291 && INTVAL (XEXP (x
, 1)) == -INTVAL (XEXP (XEXP (x
, 0), 1))
4292 && ((i
= exact_log2 (INTVAL (XEXP (XEXP (x
, 0), 1)))) >= 0
4293 || (i
= exact_log2 (INTVAL (XEXP (x
, 1)))) >= 0)
4294 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
4295 && ((GET_CODE (XEXP (XEXP (x
, 0), 0)) == AND
4296 && GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 1)) == CONST_INT
4297 && (INTVAL (XEXP (XEXP (XEXP (x
, 0), 0), 1))
4298 == ((HOST_WIDE_INT
) 1 << (i
+ 1)) - 1))
4299 || (GET_CODE (XEXP (XEXP (x
, 0), 0)) == ZERO_EXTEND
4300 && (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)))
4301 == (unsigned int) i
+ 1))))
4302 return simplify_shift_const
4303 (NULL_RTX
, ASHIFTRT
, mode
,
4304 simplify_shift_const (NULL_RTX
, ASHIFT
, mode
,
4305 XEXP (XEXP (XEXP (x
, 0), 0), 0),
4306 GET_MODE_BITSIZE (mode
) - (i
+ 1)),
4307 GET_MODE_BITSIZE (mode
) - (i
+ 1));
4309 /* (plus (comparison A B) C) can become (neg (rev-comp A B)) if
4310 C is 1 and STORE_FLAG_VALUE is -1 or if C is -1 and STORE_FLAG_VALUE
4311 is 1. This produces better code than the alternative immediately
4313 if (GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == '<'
4314 && ((STORE_FLAG_VALUE
== -1 && XEXP (x
, 1) == const1_rtx
)
4315 || (STORE_FLAG_VALUE
== 1 && XEXP (x
, 1) == constm1_rtx
))
4316 && (reversed
= reversed_comparison (XEXP (x
, 0), mode
,
4317 XEXP (XEXP (x
, 0), 0),
4318 XEXP (XEXP (x
, 0), 1))))
4320 simplify_gen_unary (NEG
, mode
, reversed
, mode
);
4322 /* If only the low-order bit of X is possibly nonzero, (plus x -1)
4323 can become (ashiftrt (ashift (xor x 1) C) C) where C is
4324 the bitsize of the mode - 1. This allows simplification of
4325 "a = (b & 8) == 0;" */
4326 if (XEXP (x
, 1) == constm1_rtx
4327 && GET_CODE (XEXP (x
, 0)) != REG
4328 && ! (GET_CODE (XEXP (x
, 0)) == SUBREG
4329 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == REG
)
4330 && nonzero_bits (XEXP (x
, 0), mode
) == 1)
4331 return simplify_shift_const (NULL_RTX
, ASHIFTRT
, mode
,
4332 simplify_shift_const (NULL_RTX
, ASHIFT
, mode
,
4333 gen_rtx_XOR (mode
, XEXP (x
, 0), const1_rtx
),
4334 GET_MODE_BITSIZE (mode
) - 1),
4335 GET_MODE_BITSIZE (mode
) - 1);
4337 /* If we are adding two things that have no bits in common, convert
4338 the addition into an IOR. This will often be further simplified,
4339 for example in cases like ((a & 1) + (a & 2)), which can
4342 if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
4343 && (nonzero_bits (XEXP (x
, 0), mode
)
4344 & nonzero_bits (XEXP (x
, 1), mode
)) == 0)
4346 /* Try to simplify the expression further. */
4347 rtx tor
= gen_binary (IOR
, mode
, XEXP (x
, 0), XEXP (x
, 1));
4348 temp
= combine_simplify_rtx (tor
, mode
, last
, in_dest
);
4350 /* If we could, great. If not, do not go ahead with the IOR
4351 replacement, since PLUS appears in many special purpose
4352 address arithmetic instructions. */
4353 if (GET_CODE (temp
) != CLOBBER
&& temp
!= tor
)
4359 /* If STORE_FLAG_VALUE is 1, (minus 1 (comparison foo bar)) can be done
4360 by reversing the comparison code if valid. */
4361 if (STORE_FLAG_VALUE
== 1
4362 && XEXP (x
, 0) == const1_rtx
4363 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 1))) == '<'
4364 && (reversed
= reversed_comparison (XEXP (x
, 1), mode
,
4365 XEXP (XEXP (x
, 1), 0),
4366 XEXP (XEXP (x
, 1), 1))))
4369 /* (minus <foo> (and <foo> (const_int -pow2))) becomes
4370 (and <foo> (const_int pow2-1)) */
4371 if (GET_CODE (XEXP (x
, 1)) == AND
4372 && GET_CODE (XEXP (XEXP (x
, 1), 1)) == CONST_INT
4373 && exact_log2 (-INTVAL (XEXP (XEXP (x
, 1), 1))) >= 0
4374 && rtx_equal_p (XEXP (XEXP (x
, 1), 0), XEXP (x
, 0)))
4375 return simplify_and_const_int (NULL_RTX
, mode
, XEXP (x
, 0),
4376 -INTVAL (XEXP (XEXP (x
, 1), 1)) - 1);
4378 /* Canonicalize (minus A (mult (neg B) C)) to (plus (mult B C) A).
4380 if (GET_CODE (XEXP (x
, 1)) == MULT
4381 && GET_CODE (XEXP (XEXP (x
, 1), 0)) == NEG
)
4385 in1
= XEXP (XEXP (XEXP (x
, 1), 0), 0);
4386 in2
= XEXP (XEXP (x
, 1), 1);
4387 return gen_binary (PLUS
, mode
, gen_binary (MULT
, mode
, in1
, in2
),
4391 /* Canonicalize (minus (neg A) (mult B C)) to
4392 (minus (mult (neg B) C) A). */
4393 if (GET_CODE (XEXP (x
, 1)) == MULT
4394 && GET_CODE (XEXP (x
, 0)) == NEG
)
4398 in1
= simplify_gen_unary (NEG
, mode
, XEXP (XEXP (x
, 1), 0), mode
);
4399 in2
= XEXP (XEXP (x
, 1), 1);
4400 return gen_binary (MINUS
, mode
, gen_binary (MULT
, mode
, in1
, in2
),
4401 XEXP (XEXP (x
, 0), 0));
4404 /* Canonicalize (minus A (plus B C)) to (minus (minus A B) C) for
4406 if (GET_CODE (XEXP (x
, 1)) == PLUS
&& INTEGRAL_MODE_P (mode
))
4407 return gen_binary (MINUS
, mode
,
4408 gen_binary (MINUS
, mode
, XEXP (x
, 0),
4409 XEXP (XEXP (x
, 1), 0)),
4410 XEXP (XEXP (x
, 1), 1));
4414 /* If we have (mult (plus A B) C), apply the distributive law and then
4415 the inverse distributive law to see if things simplify. This
4416 occurs mostly in addresses, often when unrolling loops. */
4418 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
4420 x
= apply_distributive_law
4421 (gen_binary (PLUS
, mode
,
4422 gen_binary (MULT
, mode
,
4423 XEXP (XEXP (x
, 0), 0), XEXP (x
, 1)),
4424 gen_binary (MULT
, mode
,
4425 XEXP (XEXP (x
, 0), 1),
4426 copy_rtx (XEXP (x
, 1)))));
4428 if (GET_CODE (x
) != MULT
)
4431 /* Try simplify a*(b/c) as (a*b)/c. */
4432 if (FLOAT_MODE_P (mode
) && flag_unsafe_math_optimizations
4433 && GET_CODE (XEXP (x
, 0)) == DIV
)
4435 rtx tem
= simplify_binary_operation (MULT
, mode
,
4436 XEXP (XEXP (x
, 0), 0),
4439 return gen_binary (DIV
, mode
, tem
, XEXP (XEXP (x
, 0), 1));
4444 /* If this is a divide by a power of two, treat it as a shift if
4445 its first operand is a shift. */
4446 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
4447 && (i
= exact_log2 (INTVAL (XEXP (x
, 1)))) >= 0
4448 && (GET_CODE (XEXP (x
, 0)) == ASHIFT
4449 || GET_CODE (XEXP (x
, 0)) == LSHIFTRT
4450 || GET_CODE (XEXP (x
, 0)) == ASHIFTRT
4451 || GET_CODE (XEXP (x
, 0)) == ROTATE
4452 || GET_CODE (XEXP (x
, 0)) == ROTATERT
))
4453 return simplify_shift_const (NULL_RTX
, LSHIFTRT
, mode
, XEXP (x
, 0), i
);
4457 case GT
: case GTU
: case GE
: case GEU
:
4458 case LT
: case LTU
: case LE
: case LEU
:
4459 case UNEQ
: case LTGT
:
4460 case UNGT
: case UNGE
:
4461 case UNLT
: case UNLE
:
4462 case UNORDERED
: case ORDERED
:
4463 /* If the first operand is a condition code, we can't do anything
4465 if (GET_CODE (XEXP (x
, 0)) == COMPARE
4466 || (GET_MODE_CLASS (GET_MODE (XEXP (x
, 0))) != MODE_CC
4467 && ! CC0_P (XEXP (x
, 0))))
4469 rtx op0
= XEXP (x
, 0);
4470 rtx op1
= XEXP (x
, 1);
4471 enum rtx_code new_code
;
4473 if (GET_CODE (op0
) == COMPARE
)
4474 op1
= XEXP (op0
, 1), op0
= XEXP (op0
, 0);
4476 /* Simplify our comparison, if possible. */
4477 new_code
= simplify_comparison (code
, &op0
, &op1
);
4479 /* If STORE_FLAG_VALUE is 1, we can convert (ne x 0) to simply X
4480 if only the low-order bit is possibly nonzero in X (such as when
4481 X is a ZERO_EXTRACT of one bit). Similarly, we can convert EQ to
4482 (xor X 1) or (minus 1 X); we use the former. Finally, if X is
4483 known to be either 0 or -1, NE becomes a NEG and EQ becomes
4486 Remove any ZERO_EXTRACT we made when thinking this was a
4487 comparison. It may now be simpler to use, e.g., an AND. If a
4488 ZERO_EXTRACT is indeed appropriate, it will be placed back by
4489 the call to make_compound_operation in the SET case. */
4491 if (STORE_FLAG_VALUE
== 1
4492 && new_code
== NE
&& GET_MODE_CLASS (mode
) == MODE_INT
4493 && op1
== const0_rtx
4494 && mode
== GET_MODE (op0
)
4495 && nonzero_bits (op0
, mode
) == 1)
4496 return gen_lowpart_for_combine (mode
,
4497 expand_compound_operation (op0
));
4499 else if (STORE_FLAG_VALUE
== 1
4500 && new_code
== NE
&& GET_MODE_CLASS (mode
) == MODE_INT
4501 && op1
== const0_rtx
4502 && mode
== GET_MODE (op0
)
4503 && (num_sign_bit_copies (op0
, mode
)
4504 == GET_MODE_BITSIZE (mode
)))
4506 op0
= expand_compound_operation (op0
);
4507 return simplify_gen_unary (NEG
, mode
,
4508 gen_lowpart_for_combine (mode
, op0
),
4512 else if (STORE_FLAG_VALUE
== 1
4513 && new_code
== EQ
&& GET_MODE_CLASS (mode
) == MODE_INT
4514 && op1
== const0_rtx
4515 && mode
== GET_MODE (op0
)
4516 && nonzero_bits (op0
, mode
) == 1)
4518 op0
= expand_compound_operation (op0
);
4519 return gen_binary (XOR
, mode
,
4520 gen_lowpart_for_combine (mode
, op0
),
4524 else if (STORE_FLAG_VALUE
== 1
4525 && new_code
== EQ
&& GET_MODE_CLASS (mode
) == MODE_INT
4526 && op1
== const0_rtx
4527 && mode
== GET_MODE (op0
)
4528 && (num_sign_bit_copies (op0
, mode
)
4529 == GET_MODE_BITSIZE (mode
)))
4531 op0
= expand_compound_operation (op0
);
4532 return plus_constant (gen_lowpart_for_combine (mode
, op0
), 1);
4535 /* If STORE_FLAG_VALUE is -1, we have cases similar to
4537 if (STORE_FLAG_VALUE
== -1
4538 && new_code
== NE
&& GET_MODE_CLASS (mode
) == MODE_INT
4539 && op1
== const0_rtx
4540 && (num_sign_bit_copies (op0
, mode
)
4541 == GET_MODE_BITSIZE (mode
)))
4542 return gen_lowpart_for_combine (mode
,
4543 expand_compound_operation (op0
));
4545 else if (STORE_FLAG_VALUE
== -1
4546 && new_code
== NE
&& GET_MODE_CLASS (mode
) == MODE_INT
4547 && op1
== const0_rtx
4548 && mode
== GET_MODE (op0
)
4549 && nonzero_bits (op0
, mode
) == 1)
4551 op0
= expand_compound_operation (op0
);
4552 return simplify_gen_unary (NEG
, mode
,
4553 gen_lowpart_for_combine (mode
, op0
),
4557 else if (STORE_FLAG_VALUE
== -1
4558 && new_code
== EQ
&& GET_MODE_CLASS (mode
) == MODE_INT
4559 && op1
== const0_rtx
4560 && mode
== GET_MODE (op0
)
4561 && (num_sign_bit_copies (op0
, mode
)
4562 == GET_MODE_BITSIZE (mode
)))
4564 op0
= expand_compound_operation (op0
);
4565 return simplify_gen_unary (NOT
, mode
,
4566 gen_lowpart_for_combine (mode
, op0
),
4570 /* If X is 0/1, (eq X 0) is X-1. */
4571 else if (STORE_FLAG_VALUE
== -1
4572 && new_code
== EQ
&& GET_MODE_CLASS (mode
) == MODE_INT
4573 && op1
== const0_rtx
4574 && mode
== GET_MODE (op0
)
4575 && nonzero_bits (op0
, mode
) == 1)
4577 op0
= expand_compound_operation (op0
);
4578 return plus_constant (gen_lowpart_for_combine (mode
, op0
), -1);
4581 /* If STORE_FLAG_VALUE says to just test the sign bit and X has just
4582 one bit that might be nonzero, we can convert (ne x 0) to
4583 (ashift x c) where C puts the bit in the sign bit. Remove any
4584 AND with STORE_FLAG_VALUE when we are done, since we are only
4585 going to test the sign bit. */
4586 if (new_code
== NE
&& GET_MODE_CLASS (mode
) == MODE_INT
4587 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
4588 && ((STORE_FLAG_VALUE
& GET_MODE_MASK (mode
))
4589 == (unsigned HOST_WIDE_INT
) 1 << (GET_MODE_BITSIZE (mode
) - 1))
4590 && op1
== const0_rtx
4591 && mode
== GET_MODE (op0
)
4592 && (i
= exact_log2 (nonzero_bits (op0
, mode
))) >= 0)
4594 x
= simplify_shift_const (NULL_RTX
, ASHIFT
, mode
,
4595 expand_compound_operation (op0
),
4596 GET_MODE_BITSIZE (mode
) - 1 - i
);
4597 if (GET_CODE (x
) == AND
&& XEXP (x
, 1) == const_true_rtx
)
4603 /* If the code changed, return a whole new comparison. */
4604 if (new_code
!= code
)
4605 return gen_rtx_fmt_ee (new_code
, mode
, op0
, op1
);
4607 /* Otherwise, keep this operation, but maybe change its operands.
4608 This also converts (ne (compare FOO BAR) 0) to (ne FOO BAR). */
4609 SUBST (XEXP (x
, 0), op0
);
4610 SUBST (XEXP (x
, 1), op1
);
4615 return simplify_if_then_else (x
);
4621 /* If we are processing SET_DEST, we are done. */
4625 return expand_compound_operation (x
);
4628 return simplify_set (x
);
4633 return simplify_logical (x
, last
);
4636 /* (abs (neg <foo>)) -> (abs <foo>) */
4637 if (GET_CODE (XEXP (x
, 0)) == NEG
)
4638 SUBST (XEXP (x
, 0), XEXP (XEXP (x
, 0), 0));
4640 /* If the mode of the operand is VOIDmode (i.e. if it is ASM_OPERANDS),
4642 if (GET_MODE (XEXP (x
, 0)) == VOIDmode
)
4645 /* If operand is something known to be positive, ignore the ABS. */
4646 if (GET_CODE (XEXP (x
, 0)) == FFS
|| GET_CODE (XEXP (x
, 0)) == ABS
4647 || ((GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
4648 <= HOST_BITS_PER_WIDE_INT
)
4649 && ((nonzero_bits (XEXP (x
, 0), GET_MODE (XEXP (x
, 0)))
4650 & ((HOST_WIDE_INT
) 1
4651 << (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0))) - 1)))
4655 /* If operand is known to be only -1 or 0, convert ABS to NEG. */
4656 if (num_sign_bit_copies (XEXP (x
, 0), mode
) == GET_MODE_BITSIZE (mode
))
4657 return gen_rtx_NEG (mode
, XEXP (x
, 0));
4662 /* (ffs (*_extend <X>)) = (ffs <X>) */
4663 if (GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
4664 || GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
)
4665 SUBST (XEXP (x
, 0), XEXP (XEXP (x
, 0), 0));
4670 /* (pop* (zero_extend <X>)) = (pop* <X>) */
4671 if (GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
)
4672 SUBST (XEXP (x
, 0), XEXP (XEXP (x
, 0), 0));
4676 /* (float (sign_extend <X>)) = (float <X>). */
4677 if (GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
)
4678 SUBST (XEXP (x
, 0), XEXP (XEXP (x
, 0), 0));
4686 /* If this is a shift by a constant amount, simplify it. */
4687 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
4688 return simplify_shift_const (x
, code
, mode
, XEXP (x
, 0),
4689 INTVAL (XEXP (x
, 1)));
4691 #ifdef SHIFT_COUNT_TRUNCATED
4692 else if (SHIFT_COUNT_TRUNCATED
&& GET_CODE (XEXP (x
, 1)) != REG
)
4694 force_to_mode (XEXP (x
, 1), GET_MODE (XEXP (x
, 1)),
4696 << exact_log2 (GET_MODE_BITSIZE (GET_MODE (x
))))
4705 rtx op0
= XEXP (x
, 0);
4706 rtx op1
= XEXP (x
, 1);
4709 if (GET_CODE (op1
) != PARALLEL
)
4711 len
= XVECLEN (op1
, 0);
4713 && GET_CODE (XVECEXP (op1
, 0, 0)) == CONST_INT
4714 && GET_CODE (op0
) == VEC_CONCAT
)
4716 int offset
= INTVAL (XVECEXP (op1
, 0, 0)) * GET_MODE_SIZE (GET_MODE (x
));
4718 /* Try to find the element in the VEC_CONCAT. */
4721 if (GET_MODE (op0
) == GET_MODE (x
))
4723 if (GET_CODE (op0
) == VEC_CONCAT
)
4725 HOST_WIDE_INT op0_size
= GET_MODE_SIZE (GET_MODE (XEXP (op0
, 0)));
4726 if (op0_size
< offset
)
4727 op0
= XEXP (op0
, 0);
4731 op0
= XEXP (op0
, 1);
4749 /* Simplify X, an IF_THEN_ELSE expression. Return the new expression. */
4752 simplify_if_then_else (x
)
4755 enum machine_mode mode
= GET_MODE (x
);
4756 rtx cond
= XEXP (x
, 0);
4757 rtx true_rtx
= XEXP (x
, 1);
4758 rtx false_rtx
= XEXP (x
, 2);
4759 enum rtx_code true_code
= GET_CODE (cond
);
4760 int comparison_p
= GET_RTX_CLASS (true_code
) == '<';
4763 enum rtx_code false_code
;
4766 /* Simplify storing of the truth value. */
4767 if (comparison_p
&& true_rtx
== const_true_rtx
&& false_rtx
== const0_rtx
)
4768 return gen_binary (true_code
, mode
, XEXP (cond
, 0), XEXP (cond
, 1));
4770 /* Also when the truth value has to be reversed. */
4772 && true_rtx
== const0_rtx
&& false_rtx
== const_true_rtx
4773 && (reversed
= reversed_comparison (cond
, mode
, XEXP (cond
, 0),
4777 /* Sometimes we can simplify the arm of an IF_THEN_ELSE if a register used
4778 in it is being compared against certain values. Get the true and false
4779 comparisons and see if that says anything about the value of each arm. */
4782 && ((false_code
= combine_reversed_comparison_code (cond
))
4784 && GET_CODE (XEXP (cond
, 0)) == REG
)
4787 rtx from
= XEXP (cond
, 0);
4788 rtx true_val
= XEXP (cond
, 1);
4789 rtx false_val
= true_val
;
4792 /* If FALSE_CODE is EQ, swap the codes and arms. */
4794 if (false_code
== EQ
)
4796 swapped
= 1, true_code
= EQ
, false_code
= NE
;
4797 temp
= true_rtx
, true_rtx
= false_rtx
, false_rtx
= temp
;
4800 /* If we are comparing against zero and the expression being tested has
4801 only a single bit that might be nonzero, that is its value when it is
4802 not equal to zero. Similarly if it is known to be -1 or 0. */
4804 if (true_code
== EQ
&& true_val
== const0_rtx
4805 && exact_log2 (nzb
= nonzero_bits (from
, GET_MODE (from
))) >= 0)
4806 false_code
= EQ
, false_val
= GEN_INT (nzb
);
4807 else if (true_code
== EQ
&& true_val
== const0_rtx
4808 && (num_sign_bit_copies (from
, GET_MODE (from
))
4809 == GET_MODE_BITSIZE (GET_MODE (from
))))
4810 false_code
= EQ
, false_val
= constm1_rtx
;
4812 /* Now simplify an arm if we know the value of the register in the
4813 branch and it is used in the arm. Be careful due to the potential
4814 of locally-shared RTL. */
4816 if (reg_mentioned_p (from
, true_rtx
))
4817 true_rtx
= subst (known_cond (copy_rtx (true_rtx
), true_code
,
4819 pc_rtx
, pc_rtx
, 0, 0);
4820 if (reg_mentioned_p (from
, false_rtx
))
4821 false_rtx
= subst (known_cond (copy_rtx (false_rtx
), false_code
,
4823 pc_rtx
, pc_rtx
, 0, 0);
4825 SUBST (XEXP (x
, 1), swapped
? false_rtx
: true_rtx
);
4826 SUBST (XEXP (x
, 2), swapped
? true_rtx
: false_rtx
);
4828 true_rtx
= XEXP (x
, 1);
4829 false_rtx
= XEXP (x
, 2);
4830 true_code
= GET_CODE (cond
);
4833 /* If we have (if_then_else FOO (pc) (label_ref BAR)) and FOO can be
4834 reversed, do so to avoid needing two sets of patterns for
4835 subtract-and-branch insns. Similarly if we have a constant in the true
4836 arm, the false arm is the same as the first operand of the comparison, or
4837 the false arm is more complicated than the true arm. */
4840 && combine_reversed_comparison_code (cond
) != UNKNOWN
4841 && (true_rtx
== pc_rtx
4842 || (CONSTANT_P (true_rtx
)
4843 && GET_CODE (false_rtx
) != CONST_INT
&& false_rtx
!= pc_rtx
)
4844 || true_rtx
== const0_rtx
4845 || (GET_RTX_CLASS (GET_CODE (true_rtx
)) == 'o'
4846 && GET_RTX_CLASS (GET_CODE (false_rtx
)) != 'o')
4847 || (GET_CODE (true_rtx
) == SUBREG
4848 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (true_rtx
))) == 'o'
4849 && GET_RTX_CLASS (GET_CODE (false_rtx
)) != 'o')
4850 || reg_mentioned_p (true_rtx
, false_rtx
)
4851 || rtx_equal_p (false_rtx
, XEXP (cond
, 0))))
4853 true_code
= reversed_comparison_code (cond
, NULL
);
4855 reversed_comparison (cond
, GET_MODE (cond
), XEXP (cond
, 0),
4858 SUBST (XEXP (x
, 1), false_rtx
);
4859 SUBST (XEXP (x
, 2), true_rtx
);
4861 temp
= true_rtx
, true_rtx
= false_rtx
, false_rtx
= temp
;
4864 /* It is possible that the conditional has been simplified out. */
4865 true_code
= GET_CODE (cond
);
4866 comparison_p
= GET_RTX_CLASS (true_code
) == '<';
4869 /* If the two arms are identical, we don't need the comparison. */
4871 if (rtx_equal_p (true_rtx
, false_rtx
) && ! side_effects_p (cond
))
4874 /* Convert a == b ? b : a to "a". */
4875 if (true_code
== EQ
&& ! side_effects_p (cond
)
4876 && !HONOR_NANS (mode
)
4877 && rtx_equal_p (XEXP (cond
, 0), false_rtx
)
4878 && rtx_equal_p (XEXP (cond
, 1), true_rtx
))
4880 else if (true_code
== NE
&& ! side_effects_p (cond
)
4881 && !HONOR_NANS (mode
)
4882 && rtx_equal_p (XEXP (cond
, 0), true_rtx
)
4883 && rtx_equal_p (XEXP (cond
, 1), false_rtx
))
4886 /* Look for cases where we have (abs x) or (neg (abs X)). */
4888 if (GET_MODE_CLASS (mode
) == MODE_INT
4889 && GET_CODE (false_rtx
) == NEG
4890 && rtx_equal_p (true_rtx
, XEXP (false_rtx
, 0))
4892 && rtx_equal_p (true_rtx
, XEXP (cond
, 0))
4893 && ! side_effects_p (true_rtx
))
4898 return simplify_gen_unary (ABS
, mode
, true_rtx
, mode
);
4902 simplify_gen_unary (NEG
, mode
,
4903 simplify_gen_unary (ABS
, mode
, true_rtx
, mode
),
4909 /* Look for MIN or MAX. */
4911 if ((! FLOAT_MODE_P (mode
) || flag_unsafe_math_optimizations
)
4913 && rtx_equal_p (XEXP (cond
, 0), true_rtx
)
4914 && rtx_equal_p (XEXP (cond
, 1), false_rtx
)
4915 && ! side_effects_p (cond
))
4920 return gen_binary (SMAX
, mode
, true_rtx
, false_rtx
);
4923 return gen_binary (SMIN
, mode
, true_rtx
, false_rtx
);
4926 return gen_binary (UMAX
, mode
, true_rtx
, false_rtx
);
4929 return gen_binary (UMIN
, mode
, true_rtx
, false_rtx
);
4934 /* If we have (if_then_else COND (OP Z C1) Z) and OP is an identity when its
4935 second operand is zero, this can be done as (OP Z (mult COND C2)) where
4936 C2 = C1 * STORE_FLAG_VALUE. Similarly if OP has an outer ZERO_EXTEND or
4937 SIGN_EXTEND as long as Z is already extended (so we don't destroy it).
4938 We can do this kind of thing in some cases when STORE_FLAG_VALUE is
4939 neither 1 or -1, but it isn't worth checking for. */
4941 if ((STORE_FLAG_VALUE
== 1 || STORE_FLAG_VALUE
== -1)
4943 && GET_MODE_CLASS (mode
) == MODE_INT
4944 && ! side_effects_p (x
))
4946 rtx t
= make_compound_operation (true_rtx
, SET
);
4947 rtx f
= make_compound_operation (false_rtx
, SET
);
4948 rtx cond_op0
= XEXP (cond
, 0);
4949 rtx cond_op1
= XEXP (cond
, 1);
4950 enum rtx_code op
= NIL
, extend_op
= NIL
;
4951 enum machine_mode m
= mode
;
4952 rtx z
= 0, c1
= NULL_RTX
;
4954 if ((GET_CODE (t
) == PLUS
|| GET_CODE (t
) == MINUS
4955 || GET_CODE (t
) == IOR
|| GET_CODE (t
) == XOR
4956 || GET_CODE (t
) == ASHIFT
4957 || GET_CODE (t
) == LSHIFTRT
|| GET_CODE (t
) == ASHIFTRT
)
4958 && rtx_equal_p (XEXP (t
, 0), f
))
4959 c1
= XEXP (t
, 1), op
= GET_CODE (t
), z
= f
;
4961 /* If an identity-zero op is commutative, check whether there
4962 would be a match if we swapped the operands. */
4963 else if ((GET_CODE (t
) == PLUS
|| GET_CODE (t
) == IOR
4964 || GET_CODE (t
) == XOR
)
4965 && rtx_equal_p (XEXP (t
, 1), f
))
4966 c1
= XEXP (t
, 0), op
= GET_CODE (t
), z
= f
;
4967 else if (GET_CODE (t
) == SIGN_EXTEND
4968 && (GET_CODE (XEXP (t
, 0)) == PLUS
4969 || GET_CODE (XEXP (t
, 0)) == MINUS
4970 || GET_CODE (XEXP (t
, 0)) == IOR
4971 || GET_CODE (XEXP (t
, 0)) == XOR
4972 || GET_CODE (XEXP (t
, 0)) == ASHIFT
4973 || GET_CODE (XEXP (t
, 0)) == LSHIFTRT
4974 || GET_CODE (XEXP (t
, 0)) == ASHIFTRT
)
4975 && GET_CODE (XEXP (XEXP (t
, 0), 0)) == SUBREG
4976 && subreg_lowpart_p (XEXP (XEXP (t
, 0), 0))
4977 && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t
, 0), 0)), f
)
4978 && (num_sign_bit_copies (f
, GET_MODE (f
))
4980 (GET_MODE_BITSIZE (mode
)
4981 - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t
, 0), 0))))))
4983 c1
= XEXP (XEXP (t
, 0), 1); z
= f
; op
= GET_CODE (XEXP (t
, 0));
4984 extend_op
= SIGN_EXTEND
;
4985 m
= GET_MODE (XEXP (t
, 0));
4987 else if (GET_CODE (t
) == SIGN_EXTEND
4988 && (GET_CODE (XEXP (t
, 0)) == PLUS
4989 || GET_CODE (XEXP (t
, 0)) == IOR
4990 || GET_CODE (XEXP (t
, 0)) == XOR
)
4991 && GET_CODE (XEXP (XEXP (t
, 0), 1)) == SUBREG
4992 && subreg_lowpart_p (XEXP (XEXP (t
, 0), 1))
4993 && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t
, 0), 1)), f
)
4994 && (num_sign_bit_copies (f
, GET_MODE (f
))
4996 (GET_MODE_BITSIZE (mode
)
4997 - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t
, 0), 1))))))
4999 c1
= XEXP (XEXP (t
, 0), 0); z
= f
; op
= GET_CODE (XEXP (t
, 0));
5000 extend_op
= SIGN_EXTEND
;
5001 m
= GET_MODE (XEXP (t
, 0));
5003 else if (GET_CODE (t
) == ZERO_EXTEND
5004 && (GET_CODE (XEXP (t
, 0)) == PLUS
5005 || GET_CODE (XEXP (t
, 0)) == MINUS
5006 || GET_CODE (XEXP (t
, 0)) == IOR
5007 || GET_CODE (XEXP (t
, 0)) == XOR
5008 || GET_CODE (XEXP (t
, 0)) == ASHIFT
5009 || GET_CODE (XEXP (t
, 0)) == LSHIFTRT
5010 || GET_CODE (XEXP (t
, 0)) == ASHIFTRT
)
5011 && GET_CODE (XEXP (XEXP (t
, 0), 0)) == SUBREG
5012 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
5013 && subreg_lowpart_p (XEXP (XEXP (t
, 0), 0))
5014 && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t
, 0), 0)), f
)
5015 && ((nonzero_bits (f
, GET_MODE (f
))
5016 & ~GET_MODE_MASK (GET_MODE (XEXP (XEXP (t
, 0), 0))))
5019 c1
= XEXP (XEXP (t
, 0), 1); z
= f
; op
= GET_CODE (XEXP (t
, 0));
5020 extend_op
= ZERO_EXTEND
;
5021 m
= GET_MODE (XEXP (t
, 0));
5023 else if (GET_CODE (t
) == ZERO_EXTEND
5024 && (GET_CODE (XEXP (t
, 0)) == PLUS
5025 || GET_CODE (XEXP (t
, 0)) == IOR
5026 || GET_CODE (XEXP (t
, 0)) == XOR
)
5027 && GET_CODE (XEXP (XEXP (t
, 0), 1)) == SUBREG
5028 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
5029 && subreg_lowpart_p (XEXP (XEXP (t
, 0), 1))
5030 && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t
, 0), 1)), f
)
5031 && ((nonzero_bits (f
, GET_MODE (f
))
5032 & ~GET_MODE_MASK (GET_MODE (XEXP (XEXP (t
, 0), 1))))
5035 c1
= XEXP (XEXP (t
, 0), 0); z
= f
; op
= GET_CODE (XEXP (t
, 0));
5036 extend_op
= ZERO_EXTEND
;
5037 m
= GET_MODE (XEXP (t
, 0));
5042 temp
= subst (gen_binary (true_code
, m
, cond_op0
, cond_op1
),
5043 pc_rtx
, pc_rtx
, 0, 0);
5044 temp
= gen_binary (MULT
, m
, temp
,
5045 gen_binary (MULT
, m
, c1
, const_true_rtx
));
5046 temp
= subst (temp
, pc_rtx
, pc_rtx
, 0, 0);
5047 temp
= gen_binary (op
, m
, gen_lowpart_for_combine (m
, z
), temp
);
5049 if (extend_op
!= NIL
)
5050 temp
= simplify_gen_unary (extend_op
, mode
, temp
, m
);
5056 /* If we have (if_then_else (ne A 0) C1 0) and either A is known to be 0 or
5057 1 and C1 is a single bit or A is known to be 0 or -1 and C1 is the
5058 negation of a single bit, we can convert this operation to a shift. We
5059 can actually do this more generally, but it doesn't seem worth it. */
5061 if (true_code
== NE
&& XEXP (cond
, 1) == const0_rtx
5062 && false_rtx
== const0_rtx
&& GET_CODE (true_rtx
) == CONST_INT
5063 && ((1 == nonzero_bits (XEXP (cond
, 0), mode
)
5064 && (i
= exact_log2 (INTVAL (true_rtx
))) >= 0)
5065 || ((num_sign_bit_copies (XEXP (cond
, 0), mode
)
5066 == GET_MODE_BITSIZE (mode
))
5067 && (i
= exact_log2 (-INTVAL (true_rtx
))) >= 0)))
5069 simplify_shift_const (NULL_RTX
, ASHIFT
, mode
,
5070 gen_lowpart_for_combine (mode
, XEXP (cond
, 0)), i
);
5075 /* Simplify X, a SET expression. Return the new expression. */
5081 rtx src
= SET_SRC (x
);
5082 rtx dest
= SET_DEST (x
);
5083 enum machine_mode mode
5084 = GET_MODE (src
) != VOIDmode
? GET_MODE (src
) : GET_MODE (dest
);
5088 /* (set (pc) (return)) gets written as (return). */
5089 if (GET_CODE (dest
) == PC
&& GET_CODE (src
) == RETURN
)
5092 /* Now that we know for sure which bits of SRC we are using, see if we can
5093 simplify the expression for the object knowing that we only need the
5096 if (GET_MODE_CLASS (mode
) == MODE_INT
5097 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
5099 src
= force_to_mode (src
, mode
, ~(HOST_WIDE_INT
) 0, NULL_RTX
, 0);
5100 SUBST (SET_SRC (x
), src
);
5103 /* If we are setting CC0 or if the source is a COMPARE, look for the use of
5104 the comparison result and try to simplify it unless we already have used
5105 undobuf.other_insn. */
5106 if ((GET_MODE_CLASS (mode
) == MODE_CC
5107 || GET_CODE (src
) == COMPARE
5109 && (cc_use
= find_single_use (dest
, subst_insn
, &other_insn
)) != 0
5110 && (undobuf
.other_insn
== 0 || other_insn
== undobuf
.other_insn
)
5111 && GET_RTX_CLASS (GET_CODE (*cc_use
)) == '<'
5112 && rtx_equal_p (XEXP (*cc_use
, 0), dest
))
5114 enum rtx_code old_code
= GET_CODE (*cc_use
);
5115 enum rtx_code new_code
;
5117 int other_changed
= 0;
5118 enum machine_mode compare_mode
= GET_MODE (dest
);
5119 enum machine_mode tmp_mode
;
5121 if (GET_CODE (src
) == COMPARE
)
5122 op0
= XEXP (src
, 0), op1
= XEXP (src
, 1);
5124 op0
= src
, op1
= const0_rtx
;
5126 /* Check whether the comparison is known at compile time. */
5127 if (GET_MODE (op0
) != VOIDmode
)
5128 tmp_mode
= GET_MODE (op0
);
5129 else if (GET_MODE (op1
) != VOIDmode
)
5130 tmp_mode
= GET_MODE (op1
);
5132 tmp_mode
= compare_mode
;
5133 tmp
= simplify_relational_operation (old_code
, tmp_mode
, op0
, op1
);
5134 if (tmp
!= NULL_RTX
)
5136 rtx pat
= PATTERN (other_insn
);
5137 undobuf
.other_insn
= other_insn
;
5138 SUBST (*cc_use
, tmp
);
5140 /* Attempt to simplify CC user. */
5141 if (GET_CODE (pat
) == SET
)
5143 rtx
new = simplify_rtx (SET_SRC (pat
));
5144 if (new != NULL_RTX
)
5145 SUBST (SET_SRC (pat
), new);
5148 /* Convert X into a no-op move. */
5149 SUBST (SET_DEST (x
), pc_rtx
);
5150 SUBST (SET_SRC (x
), pc_rtx
);
5154 /* Simplify our comparison, if possible. */
5155 new_code
= simplify_comparison (old_code
, &op0
, &op1
);
5157 #ifdef EXTRA_CC_MODES
5158 /* If this machine has CC modes other than CCmode, check to see if we
5159 need to use a different CC mode here. */
5160 compare_mode
= SELECT_CC_MODE (new_code
, op0
, op1
);
5161 #endif /* EXTRA_CC_MODES */
5163 #if !defined (HAVE_cc0) && defined (EXTRA_CC_MODES)
5164 /* If the mode changed, we have to change SET_DEST, the mode in the
5165 compare, and the mode in the place SET_DEST is used. If SET_DEST is
5166 a hard register, just build new versions with the proper mode. If it
5167 is a pseudo, we lose unless it is only time we set the pseudo, in
5168 which case we can safely change its mode. */
5169 if (compare_mode
!= GET_MODE (dest
))
5171 unsigned int regno
= REGNO (dest
);
5172 rtx new_dest
= gen_rtx_REG (compare_mode
, regno
);
5174 if (regno
< FIRST_PSEUDO_REGISTER
5175 || (REG_N_SETS (regno
) == 1 && ! REG_USERVAR_P (dest
)))
5177 if (regno
>= FIRST_PSEUDO_REGISTER
)
5178 SUBST (regno_reg_rtx
[regno
], new_dest
);
5180 SUBST (SET_DEST (x
), new_dest
);
5181 SUBST (XEXP (*cc_use
, 0), new_dest
);
5189 /* If the code changed, we have to build a new comparison in
5190 undobuf.other_insn. */
5191 if (new_code
!= old_code
)
5193 unsigned HOST_WIDE_INT mask
;
5195 SUBST (*cc_use
, gen_rtx_fmt_ee (new_code
, GET_MODE (*cc_use
),
5198 /* If the only change we made was to change an EQ into an NE or
5199 vice versa, OP0 has only one bit that might be nonzero, and OP1
5200 is zero, check if changing the user of the condition code will
5201 produce a valid insn. If it won't, we can keep the original code
5202 in that insn by surrounding our operation with an XOR. */
5204 if (((old_code
== NE
&& new_code
== EQ
)
5205 || (old_code
== EQ
&& new_code
== NE
))
5206 && ! other_changed
&& op1
== const0_rtx
5207 && GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
5208 && exact_log2 (mask
= nonzero_bits (op0
, GET_MODE (op0
))) >= 0)
5210 rtx pat
= PATTERN (other_insn
), note
= 0;
5212 if ((recog_for_combine (&pat
, other_insn
, ¬e
) < 0
5213 && ! check_asm_operands (pat
)))
5215 PUT_CODE (*cc_use
, old_code
);
5218 op0
= gen_binary (XOR
, GET_MODE (op0
), op0
, GEN_INT (mask
));
5226 undobuf
.other_insn
= other_insn
;
5229 /* If we are now comparing against zero, change our source if
5230 needed. If we do not use cc0, we always have a COMPARE. */
5231 if (op1
== const0_rtx
&& dest
== cc0_rtx
)
5233 SUBST (SET_SRC (x
), op0
);
5239 /* Otherwise, if we didn't previously have a COMPARE in the
5240 correct mode, we need one. */
5241 if (GET_CODE (src
) != COMPARE
|| GET_MODE (src
) != compare_mode
)
5243 SUBST (SET_SRC (x
), gen_rtx_COMPARE (compare_mode
, op0
, op1
));
5248 /* Otherwise, update the COMPARE if needed. */
5249 SUBST (XEXP (src
, 0), op0
);
5250 SUBST (XEXP (src
, 1), op1
);
5255 /* Get SET_SRC in a form where we have placed back any
5256 compound expressions. Then do the checks below. */
5257 src
= make_compound_operation (src
, SET
);
5258 SUBST (SET_SRC (x
), src
);
5261 /* If we have (set x (subreg:m1 (op:m2 ...) 0)) with OP being some operation,
5262 and X being a REG or (subreg (reg)), we may be able to convert this to
5263 (set (subreg:m2 x) (op)).
5265 We can always do this if M1 is narrower than M2 because that means that
5266 we only care about the low bits of the result.
5268 However, on machines without WORD_REGISTER_OPERATIONS defined, we cannot
5269 perform a narrower operation than requested since the high-order bits will
5270 be undefined. On machine where it is defined, this transformation is safe
5271 as long as M1 and M2 have the same number of words. */
5273 if (GET_CODE (src
) == SUBREG
&& subreg_lowpart_p (src
)
5274 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (src
))) != 'o'
5275 && (((GET_MODE_SIZE (GET_MODE (src
)) + (UNITS_PER_WORD
- 1))
5277 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (src
)))
5278 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
))
5279 #ifndef WORD_REGISTER_OPERATIONS
5280 && (GET_MODE_SIZE (GET_MODE (src
))
5281 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (src
))))
5283 #ifdef CANNOT_CHANGE_MODE_CLASS
5284 && ! (GET_CODE (dest
) == REG
&& REGNO (dest
) < FIRST_PSEUDO_REGISTER
5285 && REG_CANNOT_CHANGE_MODE_P (REGNO (dest
),
5286 GET_MODE (SUBREG_REG (src
)),
5289 && (GET_CODE (dest
) == REG
5290 || (GET_CODE (dest
) == SUBREG
5291 && GET_CODE (SUBREG_REG (dest
)) == REG
)))
5293 SUBST (SET_DEST (x
),
5294 gen_lowpart_for_combine (GET_MODE (SUBREG_REG (src
)),
5296 SUBST (SET_SRC (x
), SUBREG_REG (src
));
5298 src
= SET_SRC (x
), dest
= SET_DEST (x
);
5302 /* If we have (set (cc0) (subreg ...)), we try to remove the subreg
5305 && GET_CODE (src
) == SUBREG
5306 && subreg_lowpart_p (src
)
5307 && (GET_MODE_BITSIZE (GET_MODE (src
))
5308 < GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (src
)))))
5310 rtx inner
= SUBREG_REG (src
);
5311 enum machine_mode inner_mode
= GET_MODE (inner
);
5313 /* Here we make sure that we don't have a sign bit on. */
5314 if (GET_MODE_BITSIZE (inner_mode
) <= HOST_BITS_PER_WIDE_INT
5315 && (nonzero_bits (inner
, inner_mode
)
5316 < ((unsigned HOST_WIDE_INT
) 1
5317 << (GET_MODE_BITSIZE (GET_MODE (src
)) - 1))))
5319 SUBST (SET_SRC (x
), inner
);
5325 #ifdef LOAD_EXTEND_OP
5326 /* If we have (set FOO (subreg:M (mem:N BAR) 0)) with M wider than N, this
5327 would require a paradoxical subreg. Replace the subreg with a
5328 zero_extend to avoid the reload that would otherwise be required. */
5330 if (GET_CODE (src
) == SUBREG
&& subreg_lowpart_p (src
)
5331 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src
))) != NIL
5332 && SUBREG_BYTE (src
) == 0
5333 && (GET_MODE_SIZE (GET_MODE (src
))
5334 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (src
))))
5335 && GET_CODE (SUBREG_REG (src
)) == MEM
)
5338 gen_rtx (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src
))),
5339 GET_MODE (src
), SUBREG_REG (src
)));
5345 /* If we don't have a conditional move, SET_SRC is an IF_THEN_ELSE, and we
5346 are comparing an item known to be 0 or -1 against 0, use a logical
5347 operation instead. Check for one of the arms being an IOR of the other
5348 arm with some value. We compute three terms to be IOR'ed together. In
5349 practice, at most two will be nonzero. Then we do the IOR's. */
5351 if (GET_CODE (dest
) != PC
5352 && GET_CODE (src
) == IF_THEN_ELSE
5353 && GET_MODE_CLASS (GET_MODE (src
)) == MODE_INT
5354 && (GET_CODE (XEXP (src
, 0)) == EQ
|| GET_CODE (XEXP (src
, 0)) == NE
)
5355 && XEXP (XEXP (src
, 0), 1) == const0_rtx
5356 && GET_MODE (src
) == GET_MODE (XEXP (XEXP (src
, 0), 0))
5357 #ifdef HAVE_conditional_move
5358 && ! can_conditionally_move_p (GET_MODE (src
))
5360 && (num_sign_bit_copies (XEXP (XEXP (src
, 0), 0),
5361 GET_MODE (XEXP (XEXP (src
, 0), 0)))
5362 == GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (src
, 0), 0))))
5363 && ! side_effects_p (src
))
5365 rtx true_rtx
= (GET_CODE (XEXP (src
, 0)) == NE
5366 ? XEXP (src
, 1) : XEXP (src
, 2));
5367 rtx false_rtx
= (GET_CODE (XEXP (src
, 0)) == NE
5368 ? XEXP (src
, 2) : XEXP (src
, 1));
5369 rtx term1
= const0_rtx
, term2
, term3
;
5371 if (GET_CODE (true_rtx
) == IOR
5372 && rtx_equal_p (XEXP (true_rtx
, 0), false_rtx
))
5373 term1
= false_rtx
, true_rtx
= XEXP (true_rtx
, 1), false_rtx
= const0_rtx
;
5374 else if (GET_CODE (true_rtx
) == IOR
5375 && rtx_equal_p (XEXP (true_rtx
, 1), false_rtx
))
5376 term1
= false_rtx
, true_rtx
= XEXP (true_rtx
, 0), false_rtx
= const0_rtx
;
5377 else if (GET_CODE (false_rtx
) == IOR
5378 && rtx_equal_p (XEXP (false_rtx
, 0), true_rtx
))
5379 term1
= true_rtx
, false_rtx
= XEXP (false_rtx
, 1), true_rtx
= const0_rtx
;
5380 else if (GET_CODE (false_rtx
) == IOR
5381 && rtx_equal_p (XEXP (false_rtx
, 1), true_rtx
))
5382 term1
= true_rtx
, false_rtx
= XEXP (false_rtx
, 0), true_rtx
= const0_rtx
;
5384 term2
= gen_binary (AND
, GET_MODE (src
),
5385 XEXP (XEXP (src
, 0), 0), true_rtx
);
5386 term3
= gen_binary (AND
, GET_MODE (src
),
5387 simplify_gen_unary (NOT
, GET_MODE (src
),
5388 XEXP (XEXP (src
, 0), 0),
5393 gen_binary (IOR
, GET_MODE (src
),
5394 gen_binary (IOR
, GET_MODE (src
), term1
, term2
),
5400 /* If either SRC or DEST is a CLOBBER of (const_int 0), make this
5401 whole thing fail. */
5402 if (GET_CODE (src
) == CLOBBER
&& XEXP (src
, 0) == const0_rtx
)
5404 else if (GET_CODE (dest
) == CLOBBER
&& XEXP (dest
, 0) == const0_rtx
)
5407 /* Convert this into a field assignment operation, if possible. */
5408 return make_field_assignment (x
);
5411 /* Simplify, X, and AND, IOR, or XOR operation, and return the simplified
5412 result. LAST is nonzero if this is the last retry. */
5415 simplify_logical (x
, last
)
5419 enum machine_mode mode
= GET_MODE (x
);
5420 rtx op0
= XEXP (x
, 0);
5421 rtx op1
= XEXP (x
, 1);
5424 switch (GET_CODE (x
))
5427 /* Convert (A ^ B) & A to A & (~B) since the latter is often a single
5428 insn (and may simplify more). */
5429 if (GET_CODE (op0
) == XOR
5430 && rtx_equal_p (XEXP (op0
, 0), op1
)
5431 && ! side_effects_p (op1
))
5432 x
= gen_binary (AND
, mode
,
5433 simplify_gen_unary (NOT
, mode
, XEXP (op0
, 1), mode
),
5436 if (GET_CODE (op0
) == XOR
5437 && rtx_equal_p (XEXP (op0
, 1), op1
)
5438 && ! side_effects_p (op1
))
5439 x
= gen_binary (AND
, mode
,
5440 simplify_gen_unary (NOT
, mode
, XEXP (op0
, 0), mode
),
5443 /* Similarly for (~(A ^ B)) & A. */
5444 if (GET_CODE (op0
) == NOT
5445 && GET_CODE (XEXP (op0
, 0)) == XOR
5446 && rtx_equal_p (XEXP (XEXP (op0
, 0), 0), op1
)
5447 && ! side_effects_p (op1
))
5448 x
= gen_binary (AND
, mode
, XEXP (XEXP (op0
, 0), 1), op1
);
5450 if (GET_CODE (op0
) == NOT
5451 && GET_CODE (XEXP (op0
, 0)) == XOR
5452 && rtx_equal_p (XEXP (XEXP (op0
, 0), 1), op1
)
5453 && ! side_effects_p (op1
))
5454 x
= gen_binary (AND
, mode
, XEXP (XEXP (op0
, 0), 0), op1
);
5456 /* We can call simplify_and_const_int only if we don't lose
5457 any (sign) bits when converting INTVAL (op1) to
5458 "unsigned HOST_WIDE_INT". */
5459 if (GET_CODE (op1
) == CONST_INT
5460 && (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
5461 || INTVAL (op1
) > 0))
5463 x
= simplify_and_const_int (x
, mode
, op0
, INTVAL (op1
));
5465 /* If we have (ior (and (X C1) C2)) and the next restart would be
5466 the last, simplify this by making C1 as small as possible
5469 && GET_CODE (x
) == IOR
&& GET_CODE (op0
) == AND
5470 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
5471 && GET_CODE (op1
) == CONST_INT
)
5472 return gen_binary (IOR
, mode
,
5473 gen_binary (AND
, mode
, XEXP (op0
, 0),
5474 GEN_INT (INTVAL (XEXP (op0
, 1))
5475 & ~INTVAL (op1
))), op1
);
5477 if (GET_CODE (x
) != AND
)
5480 if (GET_RTX_CLASS (GET_CODE (x
)) == 'c'
5481 || GET_RTX_CLASS (GET_CODE (x
)) == '2')
5482 op0
= XEXP (x
, 0), op1
= XEXP (x
, 1);
5485 /* Convert (A | B) & A to A. */
5486 if (GET_CODE (op0
) == IOR
5487 && (rtx_equal_p (XEXP (op0
, 0), op1
)
5488 || rtx_equal_p (XEXP (op0
, 1), op1
))
5489 && ! side_effects_p (XEXP (op0
, 0))
5490 && ! side_effects_p (XEXP (op0
, 1)))
5493 /* In the following group of tests (and those in case IOR below),
5494 we start with some combination of logical operations and apply
5495 the distributive law followed by the inverse distributive law.
5496 Most of the time, this results in no change. However, if some of
5497 the operands are the same or inverses of each other, simplifications
5500 For example, (and (ior A B) (not B)) can occur as the result of
5501 expanding a bit field assignment. When we apply the distributive
5502 law to this, we get (ior (and (A (not B))) (and (B (not B)))),
5503 which then simplifies to (and (A (not B))).
5505 If we have (and (ior A B) C), apply the distributive law and then
5506 the inverse distributive law to see if things simplify. */
5508 if (GET_CODE (op0
) == IOR
|| GET_CODE (op0
) == XOR
)
5510 x
= apply_distributive_law
5511 (gen_binary (GET_CODE (op0
), mode
,
5512 gen_binary (AND
, mode
, XEXP (op0
, 0), op1
),
5513 gen_binary (AND
, mode
, XEXP (op0
, 1),
5515 if (GET_CODE (x
) != AND
)
5519 if (GET_CODE (op1
) == IOR
|| GET_CODE (op1
) == XOR
)
5520 return apply_distributive_law
5521 (gen_binary (GET_CODE (op1
), mode
,
5522 gen_binary (AND
, mode
, XEXP (op1
, 0), op0
),
5523 gen_binary (AND
, mode
, XEXP (op1
, 1),
5526 /* Similarly, taking advantage of the fact that
5527 (and (not A) (xor B C)) == (xor (ior A B) (ior A C)) */
5529 if (GET_CODE (op0
) == NOT
&& GET_CODE (op1
) == XOR
)
5530 return apply_distributive_law
5531 (gen_binary (XOR
, mode
,
5532 gen_binary (IOR
, mode
, XEXP (op0
, 0), XEXP (op1
, 0)),
5533 gen_binary (IOR
, mode
, copy_rtx (XEXP (op0
, 0)),
5536 else if (GET_CODE (op1
) == NOT
&& GET_CODE (op0
) == XOR
)
5537 return apply_distributive_law
5538 (gen_binary (XOR
, mode
,
5539 gen_binary (IOR
, mode
, XEXP (op1
, 0), XEXP (op0
, 0)),
5540 gen_binary (IOR
, mode
, copy_rtx (XEXP (op1
, 0)), XEXP (op0
, 1))));
5544 /* (ior A C) is C if all bits of A that might be nonzero are on in C. */
5545 if (GET_CODE (op1
) == CONST_INT
5546 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
5547 && (nonzero_bits (op0
, mode
) & ~INTVAL (op1
)) == 0)
5550 /* Convert (A & B) | A to A. */
5551 if (GET_CODE (op0
) == AND
5552 && (rtx_equal_p (XEXP (op0
, 0), op1
)
5553 || rtx_equal_p (XEXP (op0
, 1), op1
))
5554 && ! side_effects_p (XEXP (op0
, 0))
5555 && ! side_effects_p (XEXP (op0
, 1)))
5558 /* If we have (ior (and A B) C), apply the distributive law and then
5559 the inverse distributive law to see if things simplify. */
5561 if (GET_CODE (op0
) == AND
)
5563 x
= apply_distributive_law
5564 (gen_binary (AND
, mode
,
5565 gen_binary (IOR
, mode
, XEXP (op0
, 0), op1
),
5566 gen_binary (IOR
, mode
, XEXP (op0
, 1),
5569 if (GET_CODE (x
) != IOR
)
5573 if (GET_CODE (op1
) == AND
)
5575 x
= apply_distributive_law
5576 (gen_binary (AND
, mode
,
5577 gen_binary (IOR
, mode
, XEXP (op1
, 0), op0
),
5578 gen_binary (IOR
, mode
, XEXP (op1
, 1),
5581 if (GET_CODE (x
) != IOR
)
5585 /* Convert (ior (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
5586 mode size to (rotate A CX). */
5588 if (((GET_CODE (op0
) == ASHIFT
&& GET_CODE (op1
) == LSHIFTRT
)
5589 || (GET_CODE (op1
) == ASHIFT
&& GET_CODE (op0
) == LSHIFTRT
))
5590 && rtx_equal_p (XEXP (op0
, 0), XEXP (op1
, 0))
5591 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
5592 && GET_CODE (XEXP (op1
, 1)) == CONST_INT
5593 && (INTVAL (XEXP (op0
, 1)) + INTVAL (XEXP (op1
, 1))
5594 == GET_MODE_BITSIZE (mode
)))
5595 return gen_rtx_ROTATE (mode
, XEXP (op0
, 0),
5596 (GET_CODE (op0
) == ASHIFT
5597 ? XEXP (op0
, 1) : XEXP (op1
, 1)));
5599 /* If OP0 is (ashiftrt (plus ...) C), it might actually be
5600 a (sign_extend (plus ...)). If so, OP1 is a CONST_INT, and the PLUS
5601 does not affect any of the bits in OP1, it can really be done
5602 as a PLUS and we can associate. We do this by seeing if OP1
5603 can be safely shifted left C bits. */
5604 if (GET_CODE (op1
) == CONST_INT
&& GET_CODE (op0
) == ASHIFTRT
5605 && GET_CODE (XEXP (op0
, 0)) == PLUS
5606 && GET_CODE (XEXP (XEXP (op0
, 0), 1)) == CONST_INT
5607 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
5608 && INTVAL (XEXP (op0
, 1)) < HOST_BITS_PER_WIDE_INT
)
5610 int count
= INTVAL (XEXP (op0
, 1));
5611 HOST_WIDE_INT mask
= INTVAL (op1
) << count
;
5613 if (mask
>> count
== INTVAL (op1
)
5614 && (mask
& nonzero_bits (XEXP (op0
, 0), mode
)) == 0)
5616 SUBST (XEXP (XEXP (op0
, 0), 1),
5617 GEN_INT (INTVAL (XEXP (XEXP (op0
, 0), 1)) | mask
));
5624 /* If we are XORing two things that have no bits in common,
5625 convert them into an IOR. This helps to detect rotation encoded
5626 using those methods and possibly other simplifications. */
5628 if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
5629 && (nonzero_bits (op0
, mode
)
5630 & nonzero_bits (op1
, mode
)) == 0)
5631 return (gen_binary (IOR
, mode
, op0
, op1
));
5633 /* Convert (XOR (NOT x) (NOT y)) to (XOR x y).
5634 Also convert (XOR (NOT x) y) to (NOT (XOR x y)), similarly for
5637 int num_negated
= 0;
5639 if (GET_CODE (op0
) == NOT
)
5640 num_negated
++, op0
= XEXP (op0
, 0);
5641 if (GET_CODE (op1
) == NOT
)
5642 num_negated
++, op1
= XEXP (op1
, 0);
5644 if (num_negated
== 2)
5646 SUBST (XEXP (x
, 0), op0
);
5647 SUBST (XEXP (x
, 1), op1
);
5649 else if (num_negated
== 1)
5651 simplify_gen_unary (NOT
, mode
, gen_binary (XOR
, mode
, op0
, op1
),
5655 /* Convert (xor (and A B) B) to (and (not A) B). The latter may
5656 correspond to a machine insn or result in further simplifications
5657 if B is a constant. */
5659 if (GET_CODE (op0
) == AND
5660 && rtx_equal_p (XEXP (op0
, 1), op1
)
5661 && ! side_effects_p (op1
))
5662 return gen_binary (AND
, mode
,
5663 simplify_gen_unary (NOT
, mode
, XEXP (op0
, 0), mode
),
5666 else if (GET_CODE (op0
) == AND
5667 && rtx_equal_p (XEXP (op0
, 0), op1
)
5668 && ! side_effects_p (op1
))
5669 return gen_binary (AND
, mode
,
5670 simplify_gen_unary (NOT
, mode
, XEXP (op0
, 1), mode
),
5673 /* (xor (comparison foo bar) (const_int 1)) can become the reversed
5674 comparison if STORE_FLAG_VALUE is 1. */
5675 if (STORE_FLAG_VALUE
== 1
5676 && op1
== const1_rtx
5677 && GET_RTX_CLASS (GET_CODE (op0
)) == '<'
5678 && (reversed
= reversed_comparison (op0
, mode
, XEXP (op0
, 0),
5682 /* (lshiftrt foo C) where C is the number of bits in FOO minus 1
5683 is (lt foo (const_int 0)), so we can perform the above
5684 simplification if STORE_FLAG_VALUE is 1. */
5686 if (STORE_FLAG_VALUE
== 1
5687 && op1
== const1_rtx
5688 && GET_CODE (op0
) == LSHIFTRT
5689 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
5690 && INTVAL (XEXP (op0
, 1)) == GET_MODE_BITSIZE (mode
) - 1)
5691 return gen_rtx_GE (mode
, XEXP (op0
, 0), const0_rtx
);
5693 /* (xor (comparison foo bar) (const_int sign-bit))
5694 when STORE_FLAG_VALUE is the sign bit. */
5695 if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
5696 && ((STORE_FLAG_VALUE
& GET_MODE_MASK (mode
))
5697 == (unsigned HOST_WIDE_INT
) 1 << (GET_MODE_BITSIZE (mode
) - 1))
5698 && op1
== const_true_rtx
5699 && GET_RTX_CLASS (GET_CODE (op0
)) == '<'
5700 && (reversed
= reversed_comparison (op0
, mode
, XEXP (op0
, 0),
5713 /* We consider ZERO_EXTRACT, SIGN_EXTRACT, and SIGN_EXTEND as "compound
5714 operations" because they can be replaced with two more basic operations.
5715 ZERO_EXTEND is also considered "compound" because it can be replaced with
5716 an AND operation, which is simpler, though only one operation.
5718 The function expand_compound_operation is called with an rtx expression
5719 and will convert it to the appropriate shifts and AND operations,
5720 simplifying at each stage.
5722 The function make_compound_operation is called to convert an expression
5723 consisting of shifts and ANDs into the equivalent compound expression.
5724 It is the inverse of this function, loosely speaking. */
5727 expand_compound_operation (x
)
5730 unsigned HOST_WIDE_INT pos
= 0, len
;
5732 unsigned int modewidth
;
5735 switch (GET_CODE (x
))
5740 /* We can't necessarily use a const_int for a multiword mode;
5741 it depends on implicitly extending the value.
5742 Since we don't know the right way to extend it,
5743 we can't tell whether the implicit way is right.
5745 Even for a mode that is no wider than a const_int,
5746 we can't win, because we need to sign extend one of its bits through
5747 the rest of it, and we don't know which bit. */
5748 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
5751 /* Return if (subreg:MODE FROM 0) is not a safe replacement for
5752 (zero_extend:MODE FROM) or (sign_extend:MODE FROM). It is for any MEM
5753 because (SUBREG (MEM...)) is guaranteed to cause the MEM to be
5754 reloaded. If not for that, MEM's would very rarely be safe.
5756 Reject MODEs bigger than a word, because we might not be able
5757 to reference a two-register group starting with an arbitrary register
5758 (and currently gen_lowpart might crash for a SUBREG). */
5760 if (GET_MODE_SIZE (GET_MODE (XEXP (x
, 0))) > UNITS_PER_WORD
)
5763 /* Reject MODEs that aren't scalar integers because turning vector
5764 or complex modes into shifts causes problems. */
5766 if (! SCALAR_INT_MODE_P (GET_MODE (XEXP (x
, 0))))
5769 len
= GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)));
5770 /* If the inner object has VOIDmode (the only way this can happen
5771 is if it is an ASM_OPERANDS), we can't do anything since we don't
5772 know how much masking to do. */
5781 /* If the operand is a CLOBBER, just return it. */
5782 if (GET_CODE (XEXP (x
, 0)) == CLOBBER
)
5785 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
5786 || GET_CODE (XEXP (x
, 2)) != CONST_INT
5787 || GET_MODE (XEXP (x
, 0)) == VOIDmode
)
5790 /* Reject MODEs that aren't scalar integers because turning vector
5791 or complex modes into shifts causes problems. */
5793 if (! SCALAR_INT_MODE_P (GET_MODE (XEXP (x
, 0))))
5796 len
= INTVAL (XEXP (x
, 1));
5797 pos
= INTVAL (XEXP (x
, 2));
5799 /* If this goes outside the object being extracted, replace the object
5800 with a (use (mem ...)) construct that only combine understands
5801 and is used only for this purpose. */
5802 if (len
+ pos
> GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0))))
5803 SUBST (XEXP (x
, 0), gen_rtx_USE (GET_MODE (x
), XEXP (x
, 0)));
5805 if (BITS_BIG_ENDIAN
)
5806 pos
= GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0))) - len
- pos
;
5813 /* Convert sign extension to zero extension, if we know that the high
5814 bit is not set, as this is easier to optimize. It will be converted
5815 back to cheaper alternative in make_extraction. */
5816 if (GET_CODE (x
) == SIGN_EXTEND
5817 && (GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
5818 && ((nonzero_bits (XEXP (x
, 0), GET_MODE (XEXP (x
, 0)))
5819 & ~(((unsigned HOST_WIDE_INT
)
5820 GET_MODE_MASK (GET_MODE (XEXP (x
, 0))))
5824 rtx temp
= gen_rtx_ZERO_EXTEND (GET_MODE (x
), XEXP (x
, 0));
5825 return expand_compound_operation (temp
);
5828 /* We can optimize some special cases of ZERO_EXTEND. */
5829 if (GET_CODE (x
) == ZERO_EXTEND
)
5831 /* (zero_extend:DI (truncate:SI foo:DI)) is just foo:DI if we
5832 know that the last value didn't have any inappropriate bits
5834 if (GET_CODE (XEXP (x
, 0)) == TRUNCATE
5835 && GET_MODE (XEXP (XEXP (x
, 0), 0)) == GET_MODE (x
)
5836 && GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
5837 && (nonzero_bits (XEXP (XEXP (x
, 0), 0), GET_MODE (x
))
5838 & ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0)))) == 0)
5839 return XEXP (XEXP (x
, 0), 0);
5841 /* Likewise for (zero_extend:DI (subreg:SI foo:DI 0)). */
5842 if (GET_CODE (XEXP (x
, 0)) == SUBREG
5843 && GET_MODE (SUBREG_REG (XEXP (x
, 0))) == GET_MODE (x
)
5844 && subreg_lowpart_p (XEXP (x
, 0))
5845 && GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
5846 && (nonzero_bits (SUBREG_REG (XEXP (x
, 0)), GET_MODE (x
))
5847 & ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0)))) == 0)
5848 return SUBREG_REG (XEXP (x
, 0));
5850 /* (zero_extend:DI (truncate:SI foo:DI)) is just foo:DI when foo
5851 is a comparison and STORE_FLAG_VALUE permits. This is like
5852 the first case, but it works even when GET_MODE (x) is larger
5853 than HOST_WIDE_INT. */
5854 if (GET_CODE (XEXP (x
, 0)) == TRUNCATE
5855 && GET_MODE (XEXP (XEXP (x
, 0), 0)) == GET_MODE (x
)
5856 && GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x
, 0), 0))) == '<'
5857 && (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
5858 <= HOST_BITS_PER_WIDE_INT
)
5859 && ((HOST_WIDE_INT
) STORE_FLAG_VALUE
5860 & ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0)))) == 0)
5861 return XEXP (XEXP (x
, 0), 0);
5863 /* Likewise for (zero_extend:DI (subreg:SI foo:DI 0)). */
5864 if (GET_CODE (XEXP (x
, 0)) == SUBREG
5865 && GET_MODE (SUBREG_REG (XEXP (x
, 0))) == GET_MODE (x
)
5866 && subreg_lowpart_p (XEXP (x
, 0))
5867 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x
, 0)))) == '<'
5868 && (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
5869 <= HOST_BITS_PER_WIDE_INT
)
5870 && ((HOST_WIDE_INT
) STORE_FLAG_VALUE
5871 & ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0)))) == 0)
5872 return SUBREG_REG (XEXP (x
, 0));
5876 /* If we reach here, we want to return a pair of shifts. The inner
5877 shift is a left shift of BITSIZE - POS - LEN bits. The outer
5878 shift is a right shift of BITSIZE - LEN bits. It is arithmetic or
5879 logical depending on the value of UNSIGNEDP.
5881 If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be
5882 converted into an AND of a shift.
5884 We must check for the case where the left shift would have a negative
5885 count. This can happen in a case like (x >> 31) & 255 on machines
5886 that can't shift by a constant. On those machines, we would first
5887 combine the shift with the AND to produce a variable-position
5888 extraction. Then the constant of 31 would be substituted in to produce
5889 a such a position. */
5891 modewidth
= GET_MODE_BITSIZE (GET_MODE (x
));
5892 if (modewidth
+ len
>= pos
)
5893 tem
= simplify_shift_const (NULL_RTX
, unsignedp
? LSHIFTRT
: ASHIFTRT
,
5895 simplify_shift_const (NULL_RTX
, ASHIFT
,
5898 modewidth
- pos
- len
),
5901 else if (unsignedp
&& len
< HOST_BITS_PER_WIDE_INT
)
5902 tem
= simplify_and_const_int (NULL_RTX
, GET_MODE (x
),
5903 simplify_shift_const (NULL_RTX
, LSHIFTRT
,
5906 ((HOST_WIDE_INT
) 1 << len
) - 1);
5908 /* Any other cases we can't handle. */
5911 /* If we couldn't do this for some reason, return the original
5913 if (GET_CODE (tem
) == CLOBBER
)
5919 /* X is a SET which contains an assignment of one object into
5920 a part of another (such as a bit-field assignment, STRICT_LOW_PART,
5921 or certain SUBREGS). If possible, convert it into a series of
5924 We half-heartedly support variable positions, but do not at all
5925 support variable lengths. */
5928 expand_field_assignment (x
)
5932 rtx pos
; /* Always counts from low bit. */
5935 enum machine_mode compute_mode
;
5937 /* Loop until we find something we can't simplify. */
5940 if (GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
5941 && GET_CODE (XEXP (SET_DEST (x
), 0)) == SUBREG
)
5943 inner
= SUBREG_REG (XEXP (SET_DEST (x
), 0));
5944 len
= GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x
), 0)));
5945 pos
= GEN_INT (subreg_lsb (XEXP (SET_DEST (x
), 0)));
5947 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
5948 && GET_CODE (XEXP (SET_DEST (x
), 1)) == CONST_INT
)
5950 inner
= XEXP (SET_DEST (x
), 0);
5951 len
= INTVAL (XEXP (SET_DEST (x
), 1));
5952 pos
= XEXP (SET_DEST (x
), 2);
5954 /* If the position is constant and spans the width of INNER,
5955 surround INNER with a USE to indicate this. */
5956 if (GET_CODE (pos
) == CONST_INT
5957 && INTVAL (pos
) + len
> GET_MODE_BITSIZE (GET_MODE (inner
)))
5958 inner
= gen_rtx_USE (GET_MODE (SET_DEST (x
)), inner
);
5960 if (BITS_BIG_ENDIAN
)
5962 if (GET_CODE (pos
) == CONST_INT
)
5963 pos
= GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner
)) - len
5965 else if (GET_CODE (pos
) == MINUS
5966 && GET_CODE (XEXP (pos
, 1)) == CONST_INT
5967 && (INTVAL (XEXP (pos
, 1))
5968 == GET_MODE_BITSIZE (GET_MODE (inner
)) - len
))
5969 /* If position is ADJUST - X, new position is X. */
5970 pos
= XEXP (pos
, 0);
5972 pos
= gen_binary (MINUS
, GET_MODE (pos
),
5973 GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner
))
5979 /* A SUBREG between two modes that occupy the same numbers of words
5980 can be done by moving the SUBREG to the source. */
5981 else if (GET_CODE (SET_DEST (x
)) == SUBREG
5982 /* We need SUBREGs to compute nonzero_bits properly. */
5983 && nonzero_sign_valid
5984 && (((GET_MODE_SIZE (GET_MODE (SET_DEST (x
)))
5985 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
5986 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x
))))
5987 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
5989 x
= gen_rtx_SET (VOIDmode
, SUBREG_REG (SET_DEST (x
)),
5990 gen_lowpart_for_combine
5991 (GET_MODE (SUBREG_REG (SET_DEST (x
))),
5998 while (GET_CODE (inner
) == SUBREG
&& subreg_lowpart_p (inner
))
5999 inner
= SUBREG_REG (inner
);
6001 compute_mode
= GET_MODE (inner
);
6003 /* Don't attempt bitwise arithmetic on non scalar integer modes. */
6004 if (! SCALAR_INT_MODE_P (compute_mode
))
6006 enum machine_mode imode
;
6008 /* Don't do anything for vector or complex integral types. */
6009 if (! FLOAT_MODE_P (compute_mode
))
6012 /* Try to find an integral mode to pun with. */
6013 imode
= mode_for_size (GET_MODE_BITSIZE (compute_mode
), MODE_INT
, 0);
6014 if (imode
== BLKmode
)
6017 compute_mode
= imode
;
6018 inner
= gen_lowpart_for_combine (imode
, inner
);
6021 /* Compute a mask of LEN bits, if we can do this on the host machine. */
6022 if (len
< HOST_BITS_PER_WIDE_INT
)
6023 mask
= GEN_INT (((HOST_WIDE_INT
) 1 << len
) - 1);
6027 /* Now compute the equivalent expression. Make a copy of INNER
6028 for the SET_DEST in case it is a MEM into which we will substitute;
6029 we don't want shared RTL in that case. */
6031 (VOIDmode
, copy_rtx (inner
),
6032 gen_binary (IOR
, compute_mode
,
6033 gen_binary (AND
, compute_mode
,
6034 simplify_gen_unary (NOT
, compute_mode
,
6040 gen_binary (ASHIFT
, compute_mode
,
6041 gen_binary (AND
, compute_mode
,
6042 gen_lowpart_for_combine
6043 (compute_mode
, SET_SRC (x
)),
6051 /* Return an RTX for a reference to LEN bits of INNER. If POS_RTX is nonzero,
6052 it is an RTX that represents a variable starting position; otherwise,
6053 POS is the (constant) starting bit position (counted from the LSB).
6055 INNER may be a USE. This will occur when we started with a bitfield
6056 that went outside the boundary of the object in memory, which is
6057 allowed on most machines. To isolate this case, we produce a USE
6058 whose mode is wide enough and surround the MEM with it. The only
6059 code that understands the USE is this routine. If it is not removed,
6060 it will cause the resulting insn not to match.
6062 UNSIGNEDP is nonzero for an unsigned reference and zero for a
6065 IN_DEST is nonzero if this is a reference in the destination of a
6066 SET. This is used when a ZERO_ or SIGN_EXTRACT isn't needed. If nonzero,
6067 a STRICT_LOW_PART will be used, if zero, ZERO_EXTEND or SIGN_EXTEND will
6070 IN_COMPARE is nonzero if we are in a COMPARE. This means that a
6071 ZERO_EXTRACT should be built even for bits starting at bit 0.
6073 MODE is the desired mode of the result (if IN_DEST == 0).
6075 The result is an RTX for the extraction or NULL_RTX if the target
6079 make_extraction (mode
, inner
, pos
, pos_rtx
, len
,
6080 unsignedp
, in_dest
, in_compare
)
6081 enum machine_mode mode
;
6085 unsigned HOST_WIDE_INT len
;
6087 int in_dest
, in_compare
;
6089 /* This mode describes the size of the storage area
6090 to fetch the overall value from. Within that, we
6091 ignore the POS lowest bits, etc. */
6092 enum machine_mode is_mode
= GET_MODE (inner
);
6093 enum machine_mode inner_mode
;
6094 enum machine_mode wanted_inner_mode
= byte_mode
;
6095 enum machine_mode wanted_inner_reg_mode
= word_mode
;
6096 enum machine_mode pos_mode
= word_mode
;
6097 enum machine_mode extraction_mode
= word_mode
;
6098 enum machine_mode tmode
= mode_for_size (len
, MODE_INT
, 1);
6101 rtx orig_pos_rtx
= pos_rtx
;
6102 HOST_WIDE_INT orig_pos
;
6104 /* Get some information about INNER and get the innermost object. */
6105 if (GET_CODE (inner
) == USE
)
6106 /* (use:SI (mem:QI foo)) stands for (mem:SI foo). */
6107 /* We don't need to adjust the position because we set up the USE
6108 to pretend that it was a full-word object. */
6109 spans_byte
= 1, inner
= XEXP (inner
, 0);
6110 else if (GET_CODE (inner
) == SUBREG
&& subreg_lowpart_p (inner
))
6112 /* If going from (subreg:SI (mem:QI ...)) to (mem:QI ...),
6113 consider just the QI as the memory to extract from.
6114 The subreg adds or removes high bits; its mode is
6115 irrelevant to the meaning of this extraction,
6116 since POS and LEN count from the lsb. */
6117 if (GET_CODE (SUBREG_REG (inner
)) == MEM
)
6118 is_mode
= GET_MODE (SUBREG_REG (inner
));
6119 inner
= SUBREG_REG (inner
);
6121 else if (GET_CODE (inner
) == ASHIFT
6122 && GET_CODE (XEXP (inner
, 1)) == CONST_INT
6123 && pos_rtx
== 0 && pos
== 0
6124 && len
> (unsigned HOST_WIDE_INT
) INTVAL (XEXP (inner
, 1)))
6126 /* We're extracting the least significant bits of an rtx
6127 (ashift X (const_int C)), where LEN > C. Extract the
6128 least significant (LEN - C) bits of X, giving an rtx
6129 whose mode is MODE, then shift it left C times. */
6130 new = make_extraction (mode
, XEXP (inner
, 0),
6131 0, 0, len
- INTVAL (XEXP (inner
, 1)),
6132 unsignedp
, in_dest
, in_compare
);
6134 return gen_rtx_ASHIFT (mode
, new, XEXP (inner
, 1));
6137 inner_mode
= GET_MODE (inner
);
6139 if (pos_rtx
&& GET_CODE (pos_rtx
) == CONST_INT
)
6140 pos
= INTVAL (pos_rtx
), pos_rtx
= 0;
6142 /* See if this can be done without an extraction. We never can if the
6143 width of the field is not the same as that of some integer mode. For
6144 registers, we can only avoid the extraction if the position is at the
6145 low-order bit and this is either not in the destination or we have the
6146 appropriate STRICT_LOW_PART operation available.
6148 For MEM, we can avoid an extract if the field starts on an appropriate
6149 boundary and we can change the mode of the memory reference. However,
6150 we cannot directly access the MEM if we have a USE and the underlying
6151 MEM is not TMODE. This combination means that MEM was being used in a
6152 context where bits outside its mode were being referenced; that is only
6153 valid in bit-field insns. */
6155 if (tmode
!= BLKmode
6156 && ! (spans_byte
&& inner_mode
!= tmode
)
6157 && ((pos_rtx
== 0 && (pos
% BITS_PER_WORD
) == 0
6158 && GET_CODE (inner
) != MEM
6160 || (GET_CODE (inner
) == REG
6161 && have_insn_for (STRICT_LOW_PART
, tmode
))))
6162 || (GET_CODE (inner
) == MEM
&& pos_rtx
== 0
6164 % (STRICT_ALIGNMENT
? GET_MODE_ALIGNMENT (tmode
)
6165 : BITS_PER_UNIT
)) == 0
6166 /* We can't do this if we are widening INNER_MODE (it
6167 may not be aligned, for one thing). */
6168 && GET_MODE_BITSIZE (inner_mode
) >= GET_MODE_BITSIZE (tmode
)
6169 && (inner_mode
== tmode
6170 || (! mode_dependent_address_p (XEXP (inner
, 0))
6171 && ! MEM_VOLATILE_P (inner
))))))
6173 /* If INNER is a MEM, make a new MEM that encompasses just the desired
6174 field. If the original and current mode are the same, we need not
6175 adjust the offset. Otherwise, we do if bytes big endian.
6177 If INNER is not a MEM, get a piece consisting of just the field
6178 of interest (in this case POS % BITS_PER_WORD must be 0). */
6180 if (GET_CODE (inner
) == MEM
)
6182 HOST_WIDE_INT offset
;
6184 /* POS counts from lsb, but make OFFSET count in memory order. */
6185 if (BYTES_BIG_ENDIAN
)
6186 offset
= (GET_MODE_BITSIZE (is_mode
) - len
- pos
) / BITS_PER_UNIT
;
6188 offset
= pos
/ BITS_PER_UNIT
;
6190 new = adjust_address_nv (inner
, tmode
, offset
);
6192 else if (GET_CODE (inner
) == REG
)
6194 /* We can't call gen_lowpart_for_combine here since we always want
6195 a SUBREG and it would sometimes return a new hard register. */
6196 if (tmode
!= inner_mode
)
6198 HOST_WIDE_INT final_word
= pos
/ BITS_PER_WORD
;
6200 if (WORDS_BIG_ENDIAN
6201 && GET_MODE_SIZE (inner_mode
) > UNITS_PER_WORD
)
6202 final_word
= ((GET_MODE_SIZE (inner_mode
)
6203 - GET_MODE_SIZE (tmode
))
6204 / UNITS_PER_WORD
) - final_word
;
6206 final_word
*= UNITS_PER_WORD
;
6207 if (BYTES_BIG_ENDIAN
&&
6208 GET_MODE_SIZE (inner_mode
) > GET_MODE_SIZE (tmode
))
6209 final_word
+= (GET_MODE_SIZE (inner_mode
)
6210 - GET_MODE_SIZE (tmode
)) % UNITS_PER_WORD
;
6212 /* Avoid creating invalid subregs, for example when
6213 simplifying (x>>32)&255. */
6214 if (final_word
>= GET_MODE_SIZE (inner_mode
))
6217 new = gen_rtx_SUBREG (tmode
, inner
, final_word
);
6223 new = force_to_mode (inner
, tmode
,
6224 len
>= HOST_BITS_PER_WIDE_INT
6225 ? ~(unsigned HOST_WIDE_INT
) 0
6226 : ((unsigned HOST_WIDE_INT
) 1 << len
) - 1,
6229 /* If this extraction is going into the destination of a SET,
6230 make a STRICT_LOW_PART unless we made a MEM. */
6233 return (GET_CODE (new) == MEM
? new
6234 : (GET_CODE (new) != SUBREG
6235 ? gen_rtx_CLOBBER (tmode
, const0_rtx
)
6236 : gen_rtx_STRICT_LOW_PART (VOIDmode
, new)));
6241 if (GET_CODE (new) == CONST_INT
)
6242 return gen_int_mode (INTVAL (new), mode
);
6244 /* If we know that no extraneous bits are set, and that the high
6245 bit is not set, convert the extraction to the cheaper of
6246 sign and zero extension, that are equivalent in these cases. */
6247 if (flag_expensive_optimizations
6248 && (GET_MODE_BITSIZE (tmode
) <= HOST_BITS_PER_WIDE_INT
6249 && ((nonzero_bits (new, tmode
)
6250 & ~(((unsigned HOST_WIDE_INT
)
6251 GET_MODE_MASK (tmode
))
6255 rtx temp
= gen_rtx_ZERO_EXTEND (mode
, new);
6256 rtx temp1
= gen_rtx_SIGN_EXTEND (mode
, new);
6258 /* Prefer ZERO_EXTENSION, since it gives more information to
6260 if (rtx_cost (temp
, SET
) <= rtx_cost (temp1
, SET
))
6265 /* Otherwise, sign- or zero-extend unless we already are in the
6268 return (gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
,
6272 /* Unless this is a COMPARE or we have a funny memory reference,
6273 don't do anything with zero-extending field extracts starting at
6274 the low-order bit since they are simple AND operations. */
6275 if (pos_rtx
== 0 && pos
== 0 && ! in_dest
6276 && ! in_compare
&& ! spans_byte
&& unsignedp
)
6279 /* Unless we are allowed to span bytes or INNER is not MEM, reject this if
6280 we would be spanning bytes or if the position is not a constant and the
6281 length is not 1. In all other cases, we would only be going outside
6282 our object in cases when an original shift would have been
6284 if (! spans_byte
&& GET_CODE (inner
) == MEM
6285 && ((pos_rtx
== 0 && pos
+ len
> GET_MODE_BITSIZE (is_mode
))
6286 || (pos_rtx
!= 0 && len
!= 1)))
6289 /* Get the mode to use should INNER not be a MEM, the mode for the position,
6290 and the mode for the result. */
6291 if (in_dest
&& mode_for_extraction (EP_insv
, -1) != MAX_MACHINE_MODE
)
6293 wanted_inner_reg_mode
= mode_for_extraction (EP_insv
, 0);
6294 pos_mode
= mode_for_extraction (EP_insv
, 2);
6295 extraction_mode
= mode_for_extraction (EP_insv
, 3);
6298 if (! in_dest
&& unsignedp
6299 && mode_for_extraction (EP_extzv
, -1) != MAX_MACHINE_MODE
)
6301 wanted_inner_reg_mode
= mode_for_extraction (EP_extzv
, 1);
6302 pos_mode
= mode_for_extraction (EP_extzv
, 3);
6303 extraction_mode
= mode_for_extraction (EP_extzv
, 0);
6306 if (! in_dest
&& ! unsignedp
6307 && mode_for_extraction (EP_extv
, -1) != MAX_MACHINE_MODE
)
6309 wanted_inner_reg_mode
= mode_for_extraction (EP_extv
, 1);
6310 pos_mode
= mode_for_extraction (EP_extv
, 3);
6311 extraction_mode
= mode_for_extraction (EP_extv
, 0);
6314 /* Never narrow an object, since that might not be safe. */
6316 if (mode
!= VOIDmode
6317 && GET_MODE_SIZE (extraction_mode
) < GET_MODE_SIZE (mode
))
6318 extraction_mode
= mode
;
6320 if (pos_rtx
&& GET_MODE (pos_rtx
) != VOIDmode
6321 && GET_MODE_SIZE (pos_mode
) < GET_MODE_SIZE (GET_MODE (pos_rtx
)))
6322 pos_mode
= GET_MODE (pos_rtx
);
6324 /* If this is not from memory, the desired mode is wanted_inner_reg_mode;
6325 if we have to change the mode of memory and cannot, the desired mode is
6327 if (GET_CODE (inner
) != MEM
)
6328 wanted_inner_mode
= wanted_inner_reg_mode
;
6329 else if (inner_mode
!= wanted_inner_mode
6330 && (mode_dependent_address_p (XEXP (inner
, 0))
6331 || MEM_VOLATILE_P (inner
)))
6332 wanted_inner_mode
= extraction_mode
;
6336 if (BITS_BIG_ENDIAN
)
6338 /* POS is passed as if BITS_BIG_ENDIAN == 0, so we need to convert it to
6339 BITS_BIG_ENDIAN style. If position is constant, compute new
6340 position. Otherwise, build subtraction.
6341 Note that POS is relative to the mode of the original argument.
6342 If it's a MEM we need to recompute POS relative to that.
6343 However, if we're extracting from (or inserting into) a register,
6344 we want to recompute POS relative to wanted_inner_mode. */
6345 int width
= (GET_CODE (inner
) == MEM
6346 ? GET_MODE_BITSIZE (is_mode
)
6347 : GET_MODE_BITSIZE (wanted_inner_mode
));
6350 pos
= width
- len
- pos
;
6353 = gen_rtx_MINUS (GET_MODE (pos_rtx
), GEN_INT (width
- len
), pos_rtx
);
6354 /* POS may be less than 0 now, but we check for that below.
6355 Note that it can only be less than 0 if GET_CODE (inner) != MEM. */
6358 /* If INNER has a wider mode, make it smaller. If this is a constant
6359 extract, try to adjust the byte to point to the byte containing
6361 if (wanted_inner_mode
!= VOIDmode
6362 && GET_MODE_SIZE (wanted_inner_mode
) < GET_MODE_SIZE (is_mode
)
6363 && ((GET_CODE (inner
) == MEM
6364 && (inner_mode
== wanted_inner_mode
6365 || (! mode_dependent_address_p (XEXP (inner
, 0))
6366 && ! MEM_VOLATILE_P (inner
))))))
6370 /* The computations below will be correct if the machine is big
6371 endian in both bits and bytes or little endian in bits and bytes.
6372 If it is mixed, we must adjust. */
6374 /* If bytes are big endian and we had a paradoxical SUBREG, we must
6375 adjust OFFSET to compensate. */
6376 if (BYTES_BIG_ENDIAN
6378 && GET_MODE_SIZE (inner_mode
) < GET_MODE_SIZE (is_mode
))
6379 offset
-= GET_MODE_SIZE (is_mode
) - GET_MODE_SIZE (inner_mode
);
6381 /* If this is a constant position, we can move to the desired byte. */
6384 offset
+= pos
/ BITS_PER_UNIT
;
6385 pos
%= GET_MODE_BITSIZE (wanted_inner_mode
);
6388 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
6390 && is_mode
!= wanted_inner_mode
)
6391 offset
= (GET_MODE_SIZE (is_mode
)
6392 - GET_MODE_SIZE (wanted_inner_mode
) - offset
);
6394 if (offset
!= 0 || inner_mode
!= wanted_inner_mode
)
6395 inner
= adjust_address_nv (inner
, wanted_inner_mode
, offset
);
6398 /* If INNER is not memory, we can always get it into the proper mode. If we
6399 are changing its mode, POS must be a constant and smaller than the size
6401 else if (GET_CODE (inner
) != MEM
)
6403 if (GET_MODE (inner
) != wanted_inner_mode
6405 || orig_pos
+ len
> GET_MODE_BITSIZE (wanted_inner_mode
)))
6408 inner
= force_to_mode (inner
, wanted_inner_mode
,
6410 || len
+ orig_pos
>= HOST_BITS_PER_WIDE_INT
6411 ? ~(unsigned HOST_WIDE_INT
) 0
6412 : ((((unsigned HOST_WIDE_INT
) 1 << len
) - 1)
6417 /* Adjust mode of POS_RTX, if needed. If we want a wider mode, we
6418 have to zero extend. Otherwise, we can just use a SUBREG. */
6420 && GET_MODE_SIZE (pos_mode
) > GET_MODE_SIZE (GET_MODE (pos_rtx
)))
6422 rtx temp
= gen_rtx_ZERO_EXTEND (pos_mode
, pos_rtx
);
6424 /* If we know that no extraneous bits are set, and that the high
6425 bit is not set, convert extraction to cheaper one - either
6426 SIGN_EXTENSION or ZERO_EXTENSION, that are equivalent in these
6428 if (flag_expensive_optimizations
6429 && (GET_MODE_BITSIZE (GET_MODE (pos_rtx
)) <= HOST_BITS_PER_WIDE_INT
6430 && ((nonzero_bits (pos_rtx
, GET_MODE (pos_rtx
))
6431 & ~(((unsigned HOST_WIDE_INT
)
6432 GET_MODE_MASK (GET_MODE (pos_rtx
)))
6436 rtx temp1
= gen_rtx_SIGN_EXTEND (pos_mode
, pos_rtx
);
6438 /* Prefer ZERO_EXTENSION, since it gives more information to
6440 if (rtx_cost (temp1
, SET
) < rtx_cost (temp
, SET
))
6445 else if (pos_rtx
!= 0
6446 && GET_MODE_SIZE (pos_mode
) < GET_MODE_SIZE (GET_MODE (pos_rtx
)))
6447 pos_rtx
= gen_lowpart_for_combine (pos_mode
, pos_rtx
);
6449 /* Make POS_RTX unless we already have it and it is correct. If we don't
6450 have a POS_RTX but we do have an ORIG_POS_RTX, the latter must
6452 if (pos_rtx
== 0 && orig_pos_rtx
!= 0 && INTVAL (orig_pos_rtx
) == pos
)
6453 pos_rtx
= orig_pos_rtx
;
6455 else if (pos_rtx
== 0)
6456 pos_rtx
= GEN_INT (pos
);
6458 /* Make the required operation. See if we can use existing rtx. */
6459 new = gen_rtx_fmt_eee (unsignedp
? ZERO_EXTRACT
: SIGN_EXTRACT
,
6460 extraction_mode
, inner
, GEN_INT (len
), pos_rtx
);
6462 new = gen_lowpart_for_combine (mode
, new);
6467 /* See if X contains an ASHIFT of COUNT or more bits that can be commuted
6468 with any other operations in X. Return X without that shift if so. */
6471 extract_left_shift (x
, count
)
6475 enum rtx_code code
= GET_CODE (x
);
6476 enum machine_mode mode
= GET_MODE (x
);
6482 /* This is the shift itself. If it is wide enough, we will return
6483 either the value being shifted if the shift count is equal to
6484 COUNT or a shift for the difference. */
6485 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
6486 && INTVAL (XEXP (x
, 1)) >= count
)
6487 return simplify_shift_const (NULL_RTX
, ASHIFT
, mode
, XEXP (x
, 0),
6488 INTVAL (XEXP (x
, 1)) - count
);
6492 if ((tem
= extract_left_shift (XEXP (x
, 0), count
)) != 0)
6493 return simplify_gen_unary (code
, mode
, tem
, mode
);
6497 case PLUS
: case IOR
: case XOR
: case AND
:
6498 /* If we can safely shift this constant and we find the inner shift,
6499 make a new operation. */
6500 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
6501 && (INTVAL (XEXP (x
, 1)) & ((((HOST_WIDE_INT
) 1 << count
)) - 1)) == 0
6502 && (tem
= extract_left_shift (XEXP (x
, 0), count
)) != 0)
6503 return gen_binary (code
, mode
, tem
,
6504 GEN_INT (INTVAL (XEXP (x
, 1)) >> count
));
6515 /* Look at the expression rooted at X. Look for expressions
6516 equivalent to ZERO_EXTRACT, SIGN_EXTRACT, ZERO_EXTEND, SIGN_EXTEND.
6517 Form these expressions.
6519 Return the new rtx, usually just X.
6521 Also, for machines like the VAX that don't have logical shift insns,
6522 try to convert logical to arithmetic shift operations in cases where
6523 they are equivalent. This undoes the canonicalizations to logical
6524 shifts done elsewhere.
6526 We try, as much as possible, to re-use rtl expressions to save memory.
6528 IN_CODE says what kind of expression we are processing. Normally, it is
6529 SET. In a memory address (inside a MEM, PLUS or minus, the latter two
6530 being kludges), it is MEM. When processing the arguments of a comparison
6531 or a COMPARE against zero, it is COMPARE. */
6534 make_compound_operation (x
, in_code
)
6536 enum rtx_code in_code
;
6538 enum rtx_code code
= GET_CODE (x
);
6539 enum machine_mode mode
= GET_MODE (x
);
6540 int mode_width
= GET_MODE_BITSIZE (mode
);
6542 enum rtx_code next_code
;
6548 /* Select the code to be used in recursive calls. Once we are inside an
6549 address, we stay there. If we have a comparison, set to COMPARE,
6550 but once inside, go back to our default of SET. */
6552 next_code
= (code
== MEM
|| code
== PLUS
|| code
== MINUS
? MEM
6553 : ((code
== COMPARE
|| GET_RTX_CLASS (code
) == '<')
6554 && XEXP (x
, 1) == const0_rtx
) ? COMPARE
6555 : in_code
== COMPARE
? SET
: in_code
);
6557 /* Process depending on the code of this operation. If NEW is set
6558 nonzero, it will be returned. */
6563 /* Convert shifts by constants into multiplications if inside
6565 if (in_code
== MEM
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
6566 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
6567 && INTVAL (XEXP (x
, 1)) >= 0)
6569 new = make_compound_operation (XEXP (x
, 0), next_code
);
6570 new = gen_rtx_MULT (mode
, new,
6571 GEN_INT ((HOST_WIDE_INT
) 1
6572 << INTVAL (XEXP (x
, 1))));
6577 /* If the second operand is not a constant, we can't do anything
6579 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
6582 /* If the constant is a power of two minus one and the first operand
6583 is a logical right shift, make an extraction. */
6584 if (GET_CODE (XEXP (x
, 0)) == LSHIFTRT
6585 && (i
= exact_log2 (INTVAL (XEXP (x
, 1)) + 1)) >= 0)
6587 new = make_compound_operation (XEXP (XEXP (x
, 0), 0), next_code
);
6588 new = make_extraction (mode
, new, 0, XEXP (XEXP (x
, 0), 1), i
, 1,
6589 0, in_code
== COMPARE
);
6592 /* Same as previous, but for (subreg (lshiftrt ...)) in first op. */
6593 else if (GET_CODE (XEXP (x
, 0)) == SUBREG
6594 && subreg_lowpart_p (XEXP (x
, 0))
6595 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == LSHIFTRT
6596 && (i
= exact_log2 (INTVAL (XEXP (x
, 1)) + 1)) >= 0)
6598 new = make_compound_operation (XEXP (SUBREG_REG (XEXP (x
, 0)), 0),
6600 new = make_extraction (GET_MODE (SUBREG_REG (XEXP (x
, 0))), new, 0,
6601 XEXP (SUBREG_REG (XEXP (x
, 0)), 1), i
, 1,
6602 0, in_code
== COMPARE
);
6604 /* Same as previous, but for (xor/ior (lshiftrt...) (lshiftrt...)). */
6605 else if ((GET_CODE (XEXP (x
, 0)) == XOR
6606 || GET_CODE (XEXP (x
, 0)) == IOR
)
6607 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LSHIFTRT
6608 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == LSHIFTRT
6609 && (i
= exact_log2 (INTVAL (XEXP (x
, 1)) + 1)) >= 0)
6611 /* Apply the distributive law, and then try to make extractions. */
6612 new = gen_rtx_fmt_ee (GET_CODE (XEXP (x
, 0)), mode
,
6613 gen_rtx_AND (mode
, XEXP (XEXP (x
, 0), 0),
6615 gen_rtx_AND (mode
, XEXP (XEXP (x
, 0), 1),
6617 new = make_compound_operation (new, in_code
);
6620 /* If we are have (and (rotate X C) M) and C is larger than the number
6621 of bits in M, this is an extraction. */
6623 else if (GET_CODE (XEXP (x
, 0)) == ROTATE
6624 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
6625 && (i
= exact_log2 (INTVAL (XEXP (x
, 1)) + 1)) >= 0
6626 && i
<= INTVAL (XEXP (XEXP (x
, 0), 1)))
6628 new = make_compound_operation (XEXP (XEXP (x
, 0), 0), next_code
);
6629 new = make_extraction (mode
, new,
6630 (GET_MODE_BITSIZE (mode
)
6631 - INTVAL (XEXP (XEXP (x
, 0), 1))),
6632 NULL_RTX
, i
, 1, 0, in_code
== COMPARE
);
6635 /* On machines without logical shifts, if the operand of the AND is
6636 a logical shift and our mask turns off all the propagated sign
6637 bits, we can replace the logical shift with an arithmetic shift. */
6638 else if (GET_CODE (XEXP (x
, 0)) == LSHIFTRT
6639 && !have_insn_for (LSHIFTRT
, mode
)
6640 && have_insn_for (ASHIFTRT
, mode
)
6641 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
6642 && INTVAL (XEXP (XEXP (x
, 0), 1)) >= 0
6643 && INTVAL (XEXP (XEXP (x
, 0), 1)) < HOST_BITS_PER_WIDE_INT
6644 && mode_width
<= HOST_BITS_PER_WIDE_INT
)
6646 unsigned HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
6648 mask
>>= INTVAL (XEXP (XEXP (x
, 0), 1));
6649 if ((INTVAL (XEXP (x
, 1)) & ~mask
) == 0)
6651 gen_rtx_ASHIFTRT (mode
,
6652 make_compound_operation
6653 (XEXP (XEXP (x
, 0), 0), next_code
),
6654 XEXP (XEXP (x
, 0), 1)));
6657 /* If the constant is one less than a power of two, this might be
6658 representable by an extraction even if no shift is present.
6659 If it doesn't end up being a ZERO_EXTEND, we will ignore it unless
6660 we are in a COMPARE. */
6661 else if ((i
= exact_log2 (INTVAL (XEXP (x
, 1)) + 1)) >= 0)
6662 new = make_extraction (mode
,
6663 make_compound_operation (XEXP (x
, 0),
6665 0, NULL_RTX
, i
, 1, 0, in_code
== COMPARE
);
6667 /* If we are in a comparison and this is an AND with a power of two,
6668 convert this into the appropriate bit extract. */
6669 else if (in_code
== COMPARE
6670 && (i
= exact_log2 (INTVAL (XEXP (x
, 1)))) >= 0)
6671 new = make_extraction (mode
,
6672 make_compound_operation (XEXP (x
, 0),
6674 i
, NULL_RTX
, 1, 1, 0, 1);
6679 /* If the sign bit is known to be zero, replace this with an
6680 arithmetic shift. */
6681 if (have_insn_for (ASHIFTRT
, mode
)
6682 && ! have_insn_for (LSHIFTRT
, mode
)
6683 && mode_width
<= HOST_BITS_PER_WIDE_INT
6684 && (nonzero_bits (XEXP (x
, 0), mode
) & (1 << (mode_width
- 1))) == 0)
6686 new = gen_rtx_ASHIFTRT (mode
,
6687 make_compound_operation (XEXP (x
, 0),
6693 /* ... fall through ... */
6699 /* If we have (ashiftrt (ashift foo C1) C2) with C2 >= C1,
6700 this is a SIGN_EXTRACT. */
6701 if (GET_CODE (rhs
) == CONST_INT
6702 && GET_CODE (lhs
) == ASHIFT
6703 && GET_CODE (XEXP (lhs
, 1)) == CONST_INT
6704 && INTVAL (rhs
) >= INTVAL (XEXP (lhs
, 1)))
6706 new = make_compound_operation (XEXP (lhs
, 0), next_code
);
6707 new = make_extraction (mode
, new,
6708 INTVAL (rhs
) - INTVAL (XEXP (lhs
, 1)),
6709 NULL_RTX
, mode_width
- INTVAL (rhs
),
6710 code
== LSHIFTRT
, 0, in_code
== COMPARE
);
6714 /* See if we have operations between an ASHIFTRT and an ASHIFT.
6715 If so, try to merge the shifts into a SIGN_EXTEND. We could
6716 also do this for some cases of SIGN_EXTRACT, but it doesn't
6717 seem worth the effort; the case checked for occurs on Alpha. */
6719 if (GET_RTX_CLASS (GET_CODE (lhs
)) != 'o'
6720 && ! (GET_CODE (lhs
) == SUBREG
6721 && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (lhs
))) == 'o'))
6722 && GET_CODE (rhs
) == CONST_INT
6723 && INTVAL (rhs
) < HOST_BITS_PER_WIDE_INT
6724 && (new = extract_left_shift (lhs
, INTVAL (rhs
))) != 0)
6725 new = make_extraction (mode
, make_compound_operation (new, next_code
),
6726 0, NULL_RTX
, mode_width
- INTVAL (rhs
),
6727 code
== LSHIFTRT
, 0, in_code
== COMPARE
);
6732 /* Call ourselves recursively on the inner expression. If we are
6733 narrowing the object and it has a different RTL code from
6734 what it originally did, do this SUBREG as a force_to_mode. */
6736 tem
= make_compound_operation (SUBREG_REG (x
), in_code
);
6737 if (GET_CODE (tem
) != GET_CODE (SUBREG_REG (x
))
6738 && GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (tem
))
6739 && subreg_lowpart_p (x
))
6741 rtx newer
= force_to_mode (tem
, mode
, ~(HOST_WIDE_INT
) 0,
6744 /* If we have something other than a SUBREG, we might have
6745 done an expansion, so rerun ourselves. */
6746 if (GET_CODE (newer
) != SUBREG
)
6747 newer
= make_compound_operation (newer
, in_code
);
6752 /* If this is a paradoxical subreg, and the new code is a sign or
6753 zero extension, omit the subreg and widen the extension. If it
6754 is a regular subreg, we can still get rid of the subreg by not
6755 widening so much, or in fact removing the extension entirely. */
6756 if ((GET_CODE (tem
) == SIGN_EXTEND
6757 || GET_CODE (tem
) == ZERO_EXTEND
)
6758 && subreg_lowpart_p (x
))
6760 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (tem
))
6761 || (GET_MODE_SIZE (mode
) >
6762 GET_MODE_SIZE (GET_MODE (XEXP (tem
, 0)))))
6764 if (! SCALAR_INT_MODE_P (mode
))
6766 tem
= gen_rtx_fmt_e (GET_CODE (tem
), mode
, XEXP (tem
, 0));
6769 tem
= gen_lowpart_for_combine (mode
, XEXP (tem
, 0));
6780 x
= gen_lowpart_for_combine (mode
, new);
6781 code
= GET_CODE (x
);
6784 /* Now recursively process each operand of this operation. */
6785 fmt
= GET_RTX_FORMAT (code
);
6786 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
6789 new = make_compound_operation (XEXP (x
, i
), next_code
);
6790 SUBST (XEXP (x
, i
), new);
6796 /* Given M see if it is a value that would select a field of bits
6797 within an item, but not the entire word. Return -1 if not.
6798 Otherwise, return the starting position of the field, where 0 is the
6801 *PLEN is set to the length of the field. */
6804 get_pos_from_mask (m
, plen
)
6805 unsigned HOST_WIDE_INT m
;
6806 unsigned HOST_WIDE_INT
*plen
;
6808 /* Get the bit number of the first 1 bit from the right, -1 if none. */
6809 int pos
= exact_log2 (m
& -m
);
6815 /* Now shift off the low-order zero bits and see if we have a power of
6817 len
= exact_log2 ((m
>> pos
) + 1);
6826 /* See if X can be simplified knowing that we will only refer to it in
6827 MODE and will only refer to those bits that are nonzero in MASK.
6828 If other bits are being computed or if masking operations are done
6829 that select a superset of the bits in MASK, they can sometimes be
6832 Return a possibly simplified expression, but always convert X to
6833 MODE. If X is a CONST_INT, AND the CONST_INT with MASK.
6835 Also, if REG is nonzero and X is a register equal in value to REG,
6838 If JUST_SELECT is nonzero, don't optimize by noticing that bits in MASK
6839 are all off in X. This is used when X will be complemented, by either
6840 NOT, NEG, or XOR. */
6843 force_to_mode (x
, mode
, mask
, reg
, just_select
)
6845 enum machine_mode mode
;
6846 unsigned HOST_WIDE_INT mask
;
6850 enum rtx_code code
= GET_CODE (x
);
6851 int next_select
= just_select
|| code
== XOR
|| code
== NOT
|| code
== NEG
;
6852 enum machine_mode op_mode
;
6853 unsigned HOST_WIDE_INT fuller_mask
, nonzero
;
6856 /* If this is a CALL or ASM_OPERANDS, don't do anything. Some of the
6857 code below will do the wrong thing since the mode of such an
6858 expression is VOIDmode.
6860 Also do nothing if X is a CLOBBER; this can happen if X was
6861 the return value from a call to gen_lowpart_for_combine. */
6862 if (code
== CALL
|| code
== ASM_OPERANDS
|| code
== CLOBBER
)
6865 /* We want to perform the operation is its present mode unless we know
6866 that the operation is valid in MODE, in which case we do the operation
6868 op_mode
= ((GET_MODE_CLASS (mode
) == GET_MODE_CLASS (GET_MODE (x
))
6869 && have_insn_for (code
, mode
))
6870 ? mode
: GET_MODE (x
));
6872 /* It is not valid to do a right-shift in a narrower mode
6873 than the one it came in with. */
6874 if ((code
== LSHIFTRT
|| code
== ASHIFTRT
)
6875 && GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (GET_MODE (x
)))
6876 op_mode
= GET_MODE (x
);
6878 /* Truncate MASK to fit OP_MODE. */
6880 mask
&= GET_MODE_MASK (op_mode
);
6882 /* When we have an arithmetic operation, or a shift whose count we
6883 do not know, we need to assume that all bit the up to the highest-order
6884 bit in MASK will be needed. This is how we form such a mask. */
6886 fuller_mask
= (GET_MODE_BITSIZE (op_mode
) >= HOST_BITS_PER_WIDE_INT
6887 ? GET_MODE_MASK (op_mode
)
6888 : (((unsigned HOST_WIDE_INT
) 1 << (floor_log2 (mask
) + 1))
6891 fuller_mask
= ~(HOST_WIDE_INT
) 0;
6893 /* Determine what bits of X are guaranteed to be (non)zero. */
6894 nonzero
= nonzero_bits (x
, mode
);
6896 /* If none of the bits in X are needed, return a zero. */
6897 if (! just_select
&& (nonzero
& mask
) == 0)
6900 /* If X is a CONST_INT, return a new one. Do this here since the
6901 test below will fail. */
6902 if (GET_CODE (x
) == CONST_INT
)
6904 if (SCALAR_INT_MODE_P (mode
))
6905 return gen_int_mode (INTVAL (x
) & mask
, mode
);
6908 x
= GEN_INT (INTVAL (x
) & mask
);
6909 return gen_lowpart_common (mode
, x
);
6913 /* If X is narrower than MODE and we want all the bits in X's mode, just
6914 get X in the proper mode. */
6915 if (GET_MODE_SIZE (GET_MODE (x
)) < GET_MODE_SIZE (mode
)
6916 && (GET_MODE_MASK (GET_MODE (x
)) & ~mask
) == 0)
6917 return gen_lowpart_for_combine (mode
, x
);
6919 /* If we aren't changing the mode, X is not a SUBREG, and all zero bits in
6920 MASK are already known to be zero in X, we need not do anything. */
6921 if (GET_MODE (x
) == mode
&& code
!= SUBREG
&& (~mask
& nonzero
) == 0)
6927 /* If X is a (clobber (const_int)), return it since we know we are
6928 generating something that won't match. */
6932 /* X is a (use (mem ..)) that was made from a bit-field extraction that
6933 spanned the boundary of the MEM. If we are now masking so it is
6934 within that boundary, we don't need the USE any more. */
6935 if (! BITS_BIG_ENDIAN
6936 && (mask
& ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0)))) == 0)
6937 return force_to_mode (XEXP (x
, 0), mode
, mask
, reg
, next_select
);
6944 x
= expand_compound_operation (x
);
6945 if (GET_CODE (x
) != code
)
6946 return force_to_mode (x
, mode
, mask
, reg
, next_select
);
6950 if (reg
!= 0 && (rtx_equal_p (get_last_value (reg
), x
)
6951 || rtx_equal_p (reg
, get_last_value (x
))))
6956 if (subreg_lowpart_p (x
)
6957 /* We can ignore the effect of this SUBREG if it narrows the mode or
6958 if the constant masks to zero all the bits the mode doesn't
6960 && ((GET_MODE_SIZE (GET_MODE (x
))
6961 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
6963 & GET_MODE_MASK (GET_MODE (x
))
6964 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (x
)))))))
6965 return force_to_mode (SUBREG_REG (x
), mode
, mask
, reg
, next_select
);
6969 /* If this is an AND with a constant, convert it into an AND
6970 whose constant is the AND of that constant with MASK. If it
6971 remains an AND of MASK, delete it since it is redundant. */
6973 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
6975 x
= simplify_and_const_int (x
, op_mode
, XEXP (x
, 0),
6976 mask
& INTVAL (XEXP (x
, 1)));
6978 /* If X is still an AND, see if it is an AND with a mask that
6979 is just some low-order bits. If so, and it is MASK, we don't
6982 if (GET_CODE (x
) == AND
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
6983 && ((INTVAL (XEXP (x
, 1)) & GET_MODE_MASK (GET_MODE (x
)))
6987 /* If it remains an AND, try making another AND with the bits
6988 in the mode mask that aren't in MASK turned on. If the
6989 constant in the AND is wide enough, this might make a
6990 cheaper constant. */
6992 if (GET_CODE (x
) == AND
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
6993 && GET_MODE_MASK (GET_MODE (x
)) != mask
6994 && GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
)
6996 HOST_WIDE_INT cval
= (INTVAL (XEXP (x
, 1))
6997 | (GET_MODE_MASK (GET_MODE (x
)) & ~mask
));
6998 int width
= GET_MODE_BITSIZE (GET_MODE (x
));
7001 /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative
7002 number, sign extend it. */
7003 if (width
> 0 && width
< HOST_BITS_PER_WIDE_INT
7004 && (cval
& ((HOST_WIDE_INT
) 1 << (width
- 1))) != 0)
7005 cval
|= (HOST_WIDE_INT
) -1 << width
;
7007 y
= gen_binary (AND
, GET_MODE (x
), XEXP (x
, 0), GEN_INT (cval
));
7008 if (rtx_cost (y
, SET
) < rtx_cost (x
, SET
))
7018 /* In (and (plus FOO C1) M), if M is a mask that just turns off
7019 low-order bits (as in an alignment operation) and FOO is already
7020 aligned to that boundary, mask C1 to that boundary as well.
7021 This may eliminate that PLUS and, later, the AND. */
7024 unsigned int width
= GET_MODE_BITSIZE (mode
);
7025 unsigned HOST_WIDE_INT smask
= mask
;
7027 /* If MODE is narrower than HOST_WIDE_INT and mask is a negative
7028 number, sign extend it. */
7030 if (width
< HOST_BITS_PER_WIDE_INT
7031 && (smask
& ((HOST_WIDE_INT
) 1 << (width
- 1))) != 0)
7032 smask
|= (HOST_WIDE_INT
) -1 << width
;
7034 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
7035 && exact_log2 (- smask
) >= 0
7036 && (nonzero_bits (XEXP (x
, 0), mode
) & ~smask
) == 0
7037 && (INTVAL (XEXP (x
, 1)) & ~smask
) != 0)
7038 return force_to_mode (plus_constant (XEXP (x
, 0),
7039 (INTVAL (XEXP (x
, 1)) & smask
)),
7040 mode
, smask
, reg
, next_select
);
7043 /* ... fall through ... */
7046 /* For PLUS, MINUS and MULT, we need any bits less significant than the
7047 most significant bit in MASK since carries from those bits will
7048 affect the bits we are interested in. */
7053 /* If X is (minus C Y) where C's least set bit is larger than any bit
7054 in the mask, then we may replace with (neg Y). */
7055 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
7056 && (((unsigned HOST_WIDE_INT
) (INTVAL (XEXP (x
, 0))
7057 & -INTVAL (XEXP (x
, 0))))
7060 x
= simplify_gen_unary (NEG
, GET_MODE (x
), XEXP (x
, 1),
7062 return force_to_mode (x
, mode
, mask
, reg
, next_select
);
7065 /* Similarly, if C contains every bit in the fuller_mask, then we may
7066 replace with (not Y). */
7067 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
7068 && ((INTVAL (XEXP (x
, 0)) | (HOST_WIDE_INT
) fuller_mask
)
7069 == INTVAL (XEXP (x
, 0))))
7071 x
= simplify_gen_unary (NOT
, GET_MODE (x
),
7072 XEXP (x
, 1), GET_MODE (x
));
7073 return force_to_mode (x
, mode
, mask
, reg
, next_select
);
7081 /* If X is (ior (lshiftrt FOO C1) C2), try to commute the IOR and
7082 LSHIFTRT so we end up with an (and (lshiftrt (ior ...) ...) ...)
7083 operation which may be a bitfield extraction. Ensure that the
7084 constant we form is not wider than the mode of X. */
7086 if (GET_CODE (XEXP (x
, 0)) == LSHIFTRT
7087 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
7088 && INTVAL (XEXP (XEXP (x
, 0), 1)) >= 0
7089 && INTVAL (XEXP (XEXP (x
, 0), 1)) < HOST_BITS_PER_WIDE_INT
7090 && GET_CODE (XEXP (x
, 1)) == CONST_INT
7091 && ((INTVAL (XEXP (XEXP (x
, 0), 1))
7092 + floor_log2 (INTVAL (XEXP (x
, 1))))
7093 < GET_MODE_BITSIZE (GET_MODE (x
)))
7094 && (INTVAL (XEXP (x
, 1))
7095 & ~nonzero_bits (XEXP (x
, 0), GET_MODE (x
))) == 0)
7097 temp
= GEN_INT ((INTVAL (XEXP (x
, 1)) & mask
)
7098 << INTVAL (XEXP (XEXP (x
, 0), 1)));
7099 temp
= gen_binary (GET_CODE (x
), GET_MODE (x
),
7100 XEXP (XEXP (x
, 0), 0), temp
);
7101 x
= gen_binary (LSHIFTRT
, GET_MODE (x
), temp
,
7102 XEXP (XEXP (x
, 0), 1));
7103 return force_to_mode (x
, mode
, mask
, reg
, next_select
);
7107 /* For most binary operations, just propagate into the operation and
7108 change the mode if we have an operation of that mode. */
7110 op0
= gen_lowpart_for_combine (op_mode
,
7111 force_to_mode (XEXP (x
, 0), mode
, mask
,
7113 op1
= gen_lowpart_for_combine (op_mode
,
7114 force_to_mode (XEXP (x
, 1), mode
, mask
,
7117 if (op_mode
!= GET_MODE (x
) || op0
!= XEXP (x
, 0) || op1
!= XEXP (x
, 1))
7118 x
= gen_binary (code
, op_mode
, op0
, op1
);
7122 /* For left shifts, do the same, but just for the first operand.
7123 However, we cannot do anything with shifts where we cannot
7124 guarantee that the counts are smaller than the size of the mode
7125 because such a count will have a different meaning in a
7128 if (! (GET_CODE (XEXP (x
, 1)) == CONST_INT
7129 && INTVAL (XEXP (x
, 1)) >= 0
7130 && INTVAL (XEXP (x
, 1)) < GET_MODE_BITSIZE (mode
))
7131 && ! (GET_MODE (XEXP (x
, 1)) != VOIDmode
7132 && (nonzero_bits (XEXP (x
, 1), GET_MODE (XEXP (x
, 1)))
7133 < (unsigned HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
))))
7136 /* If the shift count is a constant and we can do arithmetic in
7137 the mode of the shift, refine which bits we need. Otherwise, use the
7138 conservative form of the mask. */
7139 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
7140 && INTVAL (XEXP (x
, 1)) >= 0
7141 && INTVAL (XEXP (x
, 1)) < GET_MODE_BITSIZE (op_mode
)
7142 && GET_MODE_BITSIZE (op_mode
) <= HOST_BITS_PER_WIDE_INT
)
7143 mask
>>= INTVAL (XEXP (x
, 1));
7147 op0
= gen_lowpart_for_combine (op_mode
,
7148 force_to_mode (XEXP (x
, 0), op_mode
,
7149 mask
, reg
, next_select
));
7151 if (op_mode
!= GET_MODE (x
) || op0
!= XEXP (x
, 0))
7152 x
= gen_binary (code
, op_mode
, op0
, XEXP (x
, 1));
7156 /* Here we can only do something if the shift count is a constant,
7157 this shift constant is valid for the host, and we can do arithmetic
7160 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
7161 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
7162 && GET_MODE_BITSIZE (op_mode
) <= HOST_BITS_PER_WIDE_INT
)
7164 rtx inner
= XEXP (x
, 0);
7165 unsigned HOST_WIDE_INT inner_mask
;
7167 /* Select the mask of the bits we need for the shift operand. */
7168 inner_mask
= mask
<< INTVAL (XEXP (x
, 1));
7170 /* We can only change the mode of the shift if we can do arithmetic
7171 in the mode of the shift and INNER_MASK is no wider than the
7172 width of OP_MODE. */
7173 if (GET_MODE_BITSIZE (op_mode
) > HOST_BITS_PER_WIDE_INT
7174 || (inner_mask
& ~GET_MODE_MASK (op_mode
)) != 0)
7175 op_mode
= GET_MODE (x
);
7177 inner
= force_to_mode (inner
, op_mode
, inner_mask
, reg
, next_select
);
7179 if (GET_MODE (x
) != op_mode
|| inner
!= XEXP (x
, 0))
7180 x
= gen_binary (LSHIFTRT
, op_mode
, inner
, XEXP (x
, 1));
7183 /* If we have (and (lshiftrt FOO C1) C2) where the combination of the
7184 shift and AND produces only copies of the sign bit (C2 is one less
7185 than a power of two), we can do this with just a shift. */
7187 if (GET_CODE (x
) == LSHIFTRT
7188 && GET_CODE (XEXP (x
, 1)) == CONST_INT
7189 /* The shift puts one of the sign bit copies in the least significant
7191 && ((INTVAL (XEXP (x
, 1))
7192 + num_sign_bit_copies (XEXP (x
, 0), GET_MODE (XEXP (x
, 0))))
7193 >= GET_MODE_BITSIZE (GET_MODE (x
)))
7194 && exact_log2 (mask
+ 1) >= 0
7195 /* Number of bits left after the shift must be more than the mask
7197 && ((INTVAL (XEXP (x
, 1)) + exact_log2 (mask
+ 1))
7198 <= GET_MODE_BITSIZE (GET_MODE (x
)))
7199 /* Must be more sign bit copies than the mask needs. */
7200 && ((int) num_sign_bit_copies (XEXP (x
, 0), GET_MODE (XEXP (x
, 0)))
7201 >= exact_log2 (mask
+ 1)))
7202 x
= gen_binary (LSHIFTRT
, GET_MODE (x
), XEXP (x
, 0),
7203 GEN_INT (GET_MODE_BITSIZE (GET_MODE (x
))
7204 - exact_log2 (mask
+ 1)));
7209 /* If we are just looking for the sign bit, we don't need this shift at
7210 all, even if it has a variable count. */
7211 if (GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
7212 && (mask
== ((unsigned HOST_WIDE_INT
) 1
7213 << (GET_MODE_BITSIZE (GET_MODE (x
)) - 1))))
7214 return force_to_mode (XEXP (x
, 0), mode
, mask
, reg
, next_select
);
7216 /* If this is a shift by a constant, get a mask that contains those bits
7217 that are not copies of the sign bit. We then have two cases: If
7218 MASK only includes those bits, this can be a logical shift, which may
7219 allow simplifications. If MASK is a single-bit field not within
7220 those bits, we are requesting a copy of the sign bit and hence can
7221 shift the sign bit to the appropriate location. */
7223 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) >= 0
7224 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
)
7228 /* If the considered data is wider than HOST_WIDE_INT, we can't
7229 represent a mask for all its bits in a single scalar.
7230 But we only care about the lower bits, so calculate these. */
7232 if (GET_MODE_BITSIZE (GET_MODE (x
)) > HOST_BITS_PER_WIDE_INT
)
7234 nonzero
= ~(HOST_WIDE_INT
) 0;
7236 /* GET_MODE_BITSIZE (GET_MODE (x)) - INTVAL (XEXP (x, 1))
7237 is the number of bits a full-width mask would have set.
7238 We need only shift if these are fewer than nonzero can
7239 hold. If not, we must keep all bits set in nonzero. */
7241 if (GET_MODE_BITSIZE (GET_MODE (x
)) - INTVAL (XEXP (x
, 1))
7242 < HOST_BITS_PER_WIDE_INT
)
7243 nonzero
>>= INTVAL (XEXP (x
, 1))
7244 + HOST_BITS_PER_WIDE_INT
7245 - GET_MODE_BITSIZE (GET_MODE (x
)) ;
7249 nonzero
= GET_MODE_MASK (GET_MODE (x
));
7250 nonzero
>>= INTVAL (XEXP (x
, 1));
7253 if ((mask
& ~nonzero
) == 0
7254 || (i
= exact_log2 (mask
)) >= 0)
7256 x
= simplify_shift_const
7257 (x
, LSHIFTRT
, GET_MODE (x
), XEXP (x
, 0),
7258 i
< 0 ? INTVAL (XEXP (x
, 1))
7259 : GET_MODE_BITSIZE (GET_MODE (x
)) - 1 - i
);
7261 if (GET_CODE (x
) != ASHIFTRT
)
7262 return force_to_mode (x
, mode
, mask
, reg
, next_select
);
7266 /* If MASK is 1, convert this to an LSHIFTRT. This can be done
7267 even if the shift count isn't a constant. */
7269 x
= gen_binary (LSHIFTRT
, GET_MODE (x
), XEXP (x
, 0), XEXP (x
, 1));
7273 /* If this is a zero- or sign-extension operation that just affects bits
7274 we don't care about, remove it. Be sure the call above returned
7275 something that is still a shift. */
7277 if ((GET_CODE (x
) == LSHIFTRT
|| GET_CODE (x
) == ASHIFTRT
)
7278 && GET_CODE (XEXP (x
, 1)) == CONST_INT
7279 && INTVAL (XEXP (x
, 1)) >= 0
7280 && (INTVAL (XEXP (x
, 1))
7281 <= GET_MODE_BITSIZE (GET_MODE (x
)) - (floor_log2 (mask
) + 1))
7282 && GET_CODE (XEXP (x
, 0)) == ASHIFT
7283 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
7284 && INTVAL (XEXP (XEXP (x
, 0), 1)) == INTVAL (XEXP (x
, 1)))
7285 return force_to_mode (XEXP (XEXP (x
, 0), 0), mode
, mask
,
7292 /* If the shift count is constant and we can do computations
7293 in the mode of X, compute where the bits we care about are.
7294 Otherwise, we can't do anything. Don't change the mode of
7295 the shift or propagate MODE into the shift, though. */
7296 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
7297 && INTVAL (XEXP (x
, 1)) >= 0)
7299 temp
= simplify_binary_operation (code
== ROTATE
? ROTATERT
: ROTATE
,
7300 GET_MODE (x
), GEN_INT (mask
),
7302 if (temp
&& GET_CODE (temp
) == CONST_INT
)
7304 force_to_mode (XEXP (x
, 0), GET_MODE (x
),
7305 INTVAL (temp
), reg
, next_select
));
7310 /* If we just want the low-order bit, the NEG isn't needed since it
7311 won't change the low-order bit. */
7313 return force_to_mode (XEXP (x
, 0), mode
, mask
, reg
, just_select
);
7315 /* We need any bits less significant than the most significant bit in
7316 MASK since carries from those bits will affect the bits we are
7322 /* (not FOO) is (xor FOO CONST), so if FOO is an LSHIFTRT, we can do the
7323 same as the XOR case above. Ensure that the constant we form is not
7324 wider than the mode of X. */
7326 if (GET_CODE (XEXP (x
, 0)) == LSHIFTRT
7327 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
7328 && INTVAL (XEXP (XEXP (x
, 0), 1)) >= 0
7329 && (INTVAL (XEXP (XEXP (x
, 0), 1)) + floor_log2 (mask
)
7330 < GET_MODE_BITSIZE (GET_MODE (x
)))
7331 && INTVAL (XEXP (XEXP (x
, 0), 1)) < HOST_BITS_PER_WIDE_INT
)
7333 temp
= gen_int_mode (mask
<< INTVAL (XEXP (XEXP (x
, 0), 1)),
7335 temp
= gen_binary (XOR
, GET_MODE (x
), XEXP (XEXP (x
, 0), 0), temp
);
7336 x
= gen_binary (LSHIFTRT
, GET_MODE (x
), temp
, XEXP (XEXP (x
, 0), 1));
7338 return force_to_mode (x
, mode
, mask
, reg
, next_select
);
7341 /* (and (not FOO) CONST) is (not (or FOO (not CONST))), so we must
7342 use the full mask inside the NOT. */
7346 op0
= gen_lowpart_for_combine (op_mode
,
7347 force_to_mode (XEXP (x
, 0), mode
, mask
,
7349 if (op_mode
!= GET_MODE (x
) || op0
!= XEXP (x
, 0))
7350 x
= simplify_gen_unary (code
, op_mode
, op0
, op_mode
);
7354 /* (and (ne FOO 0) CONST) can be (and FOO CONST) if CONST is included
7355 in STORE_FLAG_VALUE and FOO has a single bit that might be nonzero,
7356 which is equal to STORE_FLAG_VALUE. */
7357 if ((mask
& ~STORE_FLAG_VALUE
) == 0 && XEXP (x
, 1) == const0_rtx
7358 && exact_log2 (nonzero_bits (XEXP (x
, 0), mode
)) >= 0
7359 && (nonzero_bits (XEXP (x
, 0), mode
)
7360 == (unsigned HOST_WIDE_INT
) STORE_FLAG_VALUE
))
7361 return force_to_mode (XEXP (x
, 0), mode
, mask
, reg
, next_select
);
7366 /* We have no way of knowing if the IF_THEN_ELSE can itself be
7367 written in a narrower mode. We play it safe and do not do so. */
7370 gen_lowpart_for_combine (GET_MODE (x
),
7371 force_to_mode (XEXP (x
, 1), mode
,
7372 mask
, reg
, next_select
)));
7374 gen_lowpart_for_combine (GET_MODE (x
),
7375 force_to_mode (XEXP (x
, 2), mode
,
7376 mask
, reg
, next_select
)));
7383 /* Ensure we return a value of the proper mode. */
7384 return gen_lowpart_for_combine (mode
, x
);
7387 /* Return nonzero if X is an expression that has one of two values depending on
7388 whether some other value is zero or nonzero. In that case, we return the
7389 value that is being tested, *PTRUE is set to the value if the rtx being
7390 returned has a nonzero value, and *PFALSE is set to the other alternative.
7392 If we return zero, we set *PTRUE and *PFALSE to X. */
7395 if_then_else_cond (x
, ptrue
, pfalse
)
7397 rtx
*ptrue
, *pfalse
;
7399 enum machine_mode mode
= GET_MODE (x
);
7400 enum rtx_code code
= GET_CODE (x
);
7401 rtx cond0
, cond1
, true0
, true1
, false0
, false1
;
7402 unsigned HOST_WIDE_INT nz
;
7404 /* If we are comparing a value against zero, we are done. */
7405 if ((code
== NE
|| code
== EQ
)
7406 && GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
7408 *ptrue
= (code
== NE
) ? const_true_rtx
: const0_rtx
;
7409 *pfalse
= (code
== NE
) ? const0_rtx
: const_true_rtx
;
7413 /* If this is a unary operation whose operand has one of two values, apply
7414 our opcode to compute those values. */
7415 else if (GET_RTX_CLASS (code
) == '1'
7416 && (cond0
= if_then_else_cond (XEXP (x
, 0), &true0
, &false0
)) != 0)
7418 *ptrue
= simplify_gen_unary (code
, mode
, true0
, GET_MODE (XEXP (x
, 0)));
7419 *pfalse
= simplify_gen_unary (code
, mode
, false0
,
7420 GET_MODE (XEXP (x
, 0)));
7424 /* If this is a COMPARE, do nothing, since the IF_THEN_ELSE we would
7425 make can't possibly match and would suppress other optimizations. */
7426 else if (code
== COMPARE
)
7429 /* If this is a binary operation, see if either side has only one of two
7430 values. If either one does or if both do and they are conditional on
7431 the same value, compute the new true and false values. */
7432 else if (GET_RTX_CLASS (code
) == 'c' || GET_RTX_CLASS (code
) == '2'
7433 || GET_RTX_CLASS (code
) == '<')
7435 cond0
= if_then_else_cond (XEXP (x
, 0), &true0
, &false0
);
7436 cond1
= if_then_else_cond (XEXP (x
, 1), &true1
, &false1
);
7438 if ((cond0
!= 0 || cond1
!= 0)
7439 && ! (cond0
!= 0 && cond1
!= 0 && ! rtx_equal_p (cond0
, cond1
)))
7441 /* If if_then_else_cond returned zero, then true/false are the
7442 same rtl. We must copy one of them to prevent invalid rtl
7445 true0
= copy_rtx (true0
);
7446 else if (cond1
== 0)
7447 true1
= copy_rtx (true1
);
7449 *ptrue
= gen_binary (code
, mode
, true0
, true1
);
7450 *pfalse
= gen_binary (code
, mode
, false0
, false1
);
7451 return cond0
? cond0
: cond1
;
7454 /* See if we have PLUS, IOR, XOR, MINUS or UMAX, where one of the
7455 operands is zero when the other is nonzero, and vice-versa,
7456 and STORE_FLAG_VALUE is 1 or -1. */
7458 if ((STORE_FLAG_VALUE
== 1 || STORE_FLAG_VALUE
== -1)
7459 && (code
== PLUS
|| code
== IOR
|| code
== XOR
|| code
== MINUS
7461 && GET_CODE (XEXP (x
, 0)) == MULT
&& GET_CODE (XEXP (x
, 1)) == MULT
)
7463 rtx op0
= XEXP (XEXP (x
, 0), 1);
7464 rtx op1
= XEXP (XEXP (x
, 1), 1);
7466 cond0
= XEXP (XEXP (x
, 0), 0);
7467 cond1
= XEXP (XEXP (x
, 1), 0);
7469 if (GET_RTX_CLASS (GET_CODE (cond0
)) == '<'
7470 && GET_RTX_CLASS (GET_CODE (cond1
)) == '<'
7471 && ((GET_CODE (cond0
) == combine_reversed_comparison_code (cond1
)
7472 && rtx_equal_p (XEXP (cond0
, 0), XEXP (cond1
, 0))
7473 && rtx_equal_p (XEXP (cond0
, 1), XEXP (cond1
, 1)))
7474 || ((swap_condition (GET_CODE (cond0
))
7475 == combine_reversed_comparison_code (cond1
))
7476 && rtx_equal_p (XEXP (cond0
, 0), XEXP (cond1
, 1))
7477 && rtx_equal_p (XEXP (cond0
, 1), XEXP (cond1
, 0))))
7478 && ! side_effects_p (x
))
7480 *ptrue
= gen_binary (MULT
, mode
, op0
, const_true_rtx
);
7481 *pfalse
= gen_binary (MULT
, mode
,
7483 ? simplify_gen_unary (NEG
, mode
, op1
,
7491 /* Similarly for MULT, AND and UMIN, except that for these the result
7493 if ((STORE_FLAG_VALUE
== 1 || STORE_FLAG_VALUE
== -1)
7494 && (code
== MULT
|| code
== AND
|| code
== UMIN
)
7495 && GET_CODE (XEXP (x
, 0)) == MULT
&& GET_CODE (XEXP (x
, 1)) == MULT
)
7497 cond0
= XEXP (XEXP (x
, 0), 0);
7498 cond1
= XEXP (XEXP (x
, 1), 0);
7500 if (GET_RTX_CLASS (GET_CODE (cond0
)) == '<'
7501 && GET_RTX_CLASS (GET_CODE (cond1
)) == '<'
7502 && ((GET_CODE (cond0
) == combine_reversed_comparison_code (cond1
)
7503 && rtx_equal_p (XEXP (cond0
, 0), XEXP (cond1
, 0))
7504 && rtx_equal_p (XEXP (cond0
, 1), XEXP (cond1
, 1)))
7505 || ((swap_condition (GET_CODE (cond0
))
7506 == combine_reversed_comparison_code (cond1
))
7507 && rtx_equal_p (XEXP (cond0
, 0), XEXP (cond1
, 1))
7508 && rtx_equal_p (XEXP (cond0
, 1), XEXP (cond1
, 0))))
7509 && ! side_effects_p (x
))
7511 *ptrue
= *pfalse
= const0_rtx
;
7517 else if (code
== IF_THEN_ELSE
)
7519 /* If we have IF_THEN_ELSE already, extract the condition and
7520 canonicalize it if it is NE or EQ. */
7521 cond0
= XEXP (x
, 0);
7522 *ptrue
= XEXP (x
, 1), *pfalse
= XEXP (x
, 2);
7523 if (GET_CODE (cond0
) == NE
&& XEXP (cond0
, 1) == const0_rtx
)
7524 return XEXP (cond0
, 0);
7525 else if (GET_CODE (cond0
) == EQ
&& XEXP (cond0
, 1) == const0_rtx
)
7527 *ptrue
= XEXP (x
, 2), *pfalse
= XEXP (x
, 1);
7528 return XEXP (cond0
, 0);
7534 /* If X is a SUBREG, we can narrow both the true and false values
7535 if the inner expression, if there is a condition. */
7536 else if (code
== SUBREG
7537 && 0 != (cond0
= if_then_else_cond (SUBREG_REG (x
),
7540 *ptrue
= simplify_gen_subreg (mode
, true0
,
7541 GET_MODE (SUBREG_REG (x
)), SUBREG_BYTE (x
));
7542 *pfalse
= simplify_gen_subreg (mode
, false0
,
7543 GET_MODE (SUBREG_REG (x
)), SUBREG_BYTE (x
));
7548 /* If X is a constant, this isn't special and will cause confusions
7549 if we treat it as such. Likewise if it is equivalent to a constant. */
7550 else if (CONSTANT_P (x
)
7551 || ((cond0
= get_last_value (x
)) != 0 && CONSTANT_P (cond0
)))
7554 /* If we're in BImode, canonicalize on 0 and STORE_FLAG_VALUE, as that
7555 will be least confusing to the rest of the compiler. */
7556 else if (mode
== BImode
)
7558 *ptrue
= GEN_INT (STORE_FLAG_VALUE
), *pfalse
= const0_rtx
;
7562 /* If X is known to be either 0 or -1, those are the true and
7563 false values when testing X. */
7564 else if (x
== constm1_rtx
|| x
== const0_rtx
7565 || (mode
!= VOIDmode
7566 && num_sign_bit_copies (x
, mode
) == GET_MODE_BITSIZE (mode
)))
7568 *ptrue
= constm1_rtx
, *pfalse
= const0_rtx
;
7572 /* Likewise for 0 or a single bit. */
7573 else if (mode
!= VOIDmode
7574 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
7575 && exact_log2 (nz
= nonzero_bits (x
, mode
)) >= 0)
7577 *ptrue
= gen_int_mode (nz
, mode
), *pfalse
= const0_rtx
;
7581 /* Otherwise fail; show no condition with true and false values the same. */
7582 *ptrue
= *pfalse
= x
;
7586 /* Return the value of expression X given the fact that condition COND
7587 is known to be true when applied to REG as its first operand and VAL
7588 as its second. X is known to not be shared and so can be modified in
7591 We only handle the simplest cases, and specifically those cases that
7592 arise with IF_THEN_ELSE expressions. */
7595 known_cond (x
, cond
, reg
, val
)
7600 enum rtx_code code
= GET_CODE (x
);
7605 if (side_effects_p (x
))
7608 /* If either operand of the condition is a floating point value,
7609 then we have to avoid collapsing an EQ comparison. */
7611 && rtx_equal_p (x
, reg
)
7612 && ! FLOAT_MODE_P (GET_MODE (x
))
7613 && ! FLOAT_MODE_P (GET_MODE (val
)))
7616 if (cond
== UNEQ
&& rtx_equal_p (x
, reg
))
7619 /* If X is (abs REG) and we know something about REG's relationship
7620 with zero, we may be able to simplify this. */
7622 if (code
== ABS
&& rtx_equal_p (XEXP (x
, 0), reg
) && val
== const0_rtx
)
7625 case GE
: case GT
: case EQ
:
7628 return simplify_gen_unary (NEG
, GET_MODE (XEXP (x
, 0)),
7630 GET_MODE (XEXP (x
, 0)));
7635 /* The only other cases we handle are MIN, MAX, and comparisons if the
7636 operands are the same as REG and VAL. */
7638 else if (GET_RTX_CLASS (code
) == '<' || GET_RTX_CLASS (code
) == 'c')
7640 if (rtx_equal_p (XEXP (x
, 0), val
))
7641 cond
= swap_condition (cond
), temp
= val
, val
= reg
, reg
= temp
;
7643 if (rtx_equal_p (XEXP (x
, 0), reg
) && rtx_equal_p (XEXP (x
, 1), val
))
7645 if (GET_RTX_CLASS (code
) == '<')
7647 if (comparison_dominates_p (cond
, code
))
7648 return const_true_rtx
;
7650 code
= combine_reversed_comparison_code (x
);
7652 && comparison_dominates_p (cond
, code
))
7657 else if (code
== SMAX
|| code
== SMIN
7658 || code
== UMIN
|| code
== UMAX
)
7660 int unsignedp
= (code
== UMIN
|| code
== UMAX
);
7662 /* Do not reverse the condition when it is NE or EQ.
7663 This is because we cannot conclude anything about
7664 the value of 'SMAX (x, y)' when x is not equal to y,
7665 but we can when x equals y. */
7666 if ((code
== SMAX
|| code
== UMAX
)
7667 && ! (cond
== EQ
|| cond
== NE
))
7668 cond
= reverse_condition (cond
);
7673 return unsignedp
? x
: XEXP (x
, 1);
7675 return unsignedp
? x
: XEXP (x
, 0);
7677 return unsignedp
? XEXP (x
, 1) : x
;
7679 return unsignedp
? XEXP (x
, 0) : x
;
7686 else if (code
== SUBREG
)
7688 enum machine_mode inner_mode
= GET_MODE (SUBREG_REG (x
));
7689 rtx
new, r
= known_cond (SUBREG_REG (x
), cond
, reg
, val
);
7691 if (SUBREG_REG (x
) != r
)
7693 /* We must simplify subreg here, before we lose track of the
7694 original inner_mode. */
7695 new = simplify_subreg (GET_MODE (x
), r
,
7696 inner_mode
, SUBREG_BYTE (x
));
7700 SUBST (SUBREG_REG (x
), r
);
7705 /* We don't have to handle SIGN_EXTEND here, because even in the
7706 case of replacing something with a modeless CONST_INT, a
7707 CONST_INT is already (supposed to be) a valid sign extension for
7708 its narrower mode, which implies it's already properly
7709 sign-extended for the wider mode. Now, for ZERO_EXTEND, the
7710 story is different. */
7711 else if (code
== ZERO_EXTEND
)
7713 enum machine_mode inner_mode
= GET_MODE (XEXP (x
, 0));
7714 rtx
new, r
= known_cond (XEXP (x
, 0), cond
, reg
, val
);
7716 if (XEXP (x
, 0) != r
)
7718 /* We must simplify the zero_extend here, before we lose
7719 track of the original inner_mode. */
7720 new = simplify_unary_operation (ZERO_EXTEND
, GET_MODE (x
),
7725 SUBST (XEXP (x
, 0), r
);
7731 fmt
= GET_RTX_FORMAT (code
);
7732 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
7735 SUBST (XEXP (x
, i
), known_cond (XEXP (x
, i
), cond
, reg
, val
));
7736 else if (fmt
[i
] == 'E')
7737 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
7738 SUBST (XVECEXP (x
, i
, j
), known_cond (XVECEXP (x
, i
, j
),
7745 /* See if X and Y are equal for the purposes of seeing if we can rewrite an
7746 assignment as a field assignment. */
7749 rtx_equal_for_field_assignment_p (x
, y
)
7753 if (x
== y
|| rtx_equal_p (x
, y
))
7756 if (x
== 0 || y
== 0 || GET_MODE (x
) != GET_MODE (y
))
7759 /* Check for a paradoxical SUBREG of a MEM compared with the MEM.
7760 Note that all SUBREGs of MEM are paradoxical; otherwise they
7761 would have been rewritten. */
7762 if (GET_CODE (x
) == MEM
&& GET_CODE (y
) == SUBREG
7763 && GET_CODE (SUBREG_REG (y
)) == MEM
7764 && rtx_equal_p (SUBREG_REG (y
),
7765 gen_lowpart_for_combine (GET_MODE (SUBREG_REG (y
)), x
)))
7768 if (GET_CODE (y
) == MEM
&& GET_CODE (x
) == SUBREG
7769 && GET_CODE (SUBREG_REG (x
)) == MEM
7770 && rtx_equal_p (SUBREG_REG (x
),
7771 gen_lowpart_for_combine (GET_MODE (SUBREG_REG (x
)), y
)))
7774 /* We used to see if get_last_value of X and Y were the same but that's
7775 not correct. In one direction, we'll cause the assignment to have
7776 the wrong destination and in the case, we'll import a register into this
7777 insn that might have already have been dead. So fail if none of the
7778 above cases are true. */
7782 /* See if X, a SET operation, can be rewritten as a bit-field assignment.
7783 Return that assignment if so.
7785 We only handle the most common cases. */
7788 make_field_assignment (x
)
7791 rtx dest
= SET_DEST (x
);
7792 rtx src
= SET_SRC (x
);
7797 unsigned HOST_WIDE_INT len
;
7799 enum machine_mode mode
;
7801 /* If SRC was (and (not (ashift (const_int 1) POS)) DEST), this is
7802 a clear of a one-bit field. We will have changed it to
7803 (and (rotate (const_int -2) POS) DEST), so check for that. Also check
7806 if (GET_CODE (src
) == AND
&& GET_CODE (XEXP (src
, 0)) == ROTATE
7807 && GET_CODE (XEXP (XEXP (src
, 0), 0)) == CONST_INT
7808 && INTVAL (XEXP (XEXP (src
, 0), 0)) == -2
7809 && rtx_equal_for_field_assignment_p (dest
, XEXP (src
, 1)))
7811 assign
= make_extraction (VOIDmode
, dest
, 0, XEXP (XEXP (src
, 0), 1),
7814 return gen_rtx_SET (VOIDmode
, assign
, const0_rtx
);
7818 else if (GET_CODE (src
) == AND
&& GET_CODE (XEXP (src
, 0)) == SUBREG
7819 && subreg_lowpart_p (XEXP (src
, 0))
7820 && (GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)))
7821 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (src
, 0)))))
7822 && GET_CODE (SUBREG_REG (XEXP (src
, 0))) == ROTATE
7823 && INTVAL (XEXP (SUBREG_REG (XEXP (src
, 0)), 0)) == -2
7824 && rtx_equal_for_field_assignment_p (dest
, XEXP (src
, 1)))
7826 assign
= make_extraction (VOIDmode
, dest
, 0,
7827 XEXP (SUBREG_REG (XEXP (src
, 0)), 1),
7830 return gen_rtx_SET (VOIDmode
, assign
, const0_rtx
);
7834 /* If SRC is (ior (ashift (const_int 1) POS) DEST), this is a set of a
7836 else if (GET_CODE (src
) == IOR
&& GET_CODE (XEXP (src
, 0)) == ASHIFT
7837 && XEXP (XEXP (src
, 0), 0) == const1_rtx
7838 && rtx_equal_for_field_assignment_p (dest
, XEXP (src
, 1)))
7840 assign
= make_extraction (VOIDmode
, dest
, 0, XEXP (XEXP (src
, 0), 1),
7843 return gen_rtx_SET (VOIDmode
, assign
, const1_rtx
);
7847 /* The other case we handle is assignments into a constant-position
7848 field. They look like (ior/xor (and DEST C1) OTHER). If C1 represents
7849 a mask that has all one bits except for a group of zero bits and
7850 OTHER is known to have zeros where C1 has ones, this is such an
7851 assignment. Compute the position and length from C1. Shift OTHER
7852 to the appropriate position, force it to the required mode, and
7853 make the extraction. Check for the AND in both operands. */
7855 if (GET_CODE (src
) != IOR
&& GET_CODE (src
) != XOR
)
7858 rhs
= expand_compound_operation (XEXP (src
, 0));
7859 lhs
= expand_compound_operation (XEXP (src
, 1));
7861 if (GET_CODE (rhs
) == AND
7862 && GET_CODE (XEXP (rhs
, 1)) == CONST_INT
7863 && rtx_equal_for_field_assignment_p (XEXP (rhs
, 0), dest
))
7864 c1
= INTVAL (XEXP (rhs
, 1)), other
= lhs
;
7865 else if (GET_CODE (lhs
) == AND
7866 && GET_CODE (XEXP (lhs
, 1)) == CONST_INT
7867 && rtx_equal_for_field_assignment_p (XEXP (lhs
, 0), dest
))
7868 c1
= INTVAL (XEXP (lhs
, 1)), other
= rhs
;
7872 pos
= get_pos_from_mask ((~c1
) & GET_MODE_MASK (GET_MODE (dest
)), &len
);
7873 if (pos
< 0 || pos
+ len
> GET_MODE_BITSIZE (GET_MODE (dest
))
7874 || GET_MODE_BITSIZE (GET_MODE (dest
)) > HOST_BITS_PER_WIDE_INT
7875 || (c1
& nonzero_bits (other
, GET_MODE (dest
))) != 0)
7878 assign
= make_extraction (VOIDmode
, dest
, pos
, NULL_RTX
, len
, 1, 1, 0);
7882 /* The mode to use for the source is the mode of the assignment, or of
7883 what is inside a possible STRICT_LOW_PART. */
7884 mode
= (GET_CODE (assign
) == STRICT_LOW_PART
7885 ? GET_MODE (XEXP (assign
, 0)) : GET_MODE (assign
));
7887 /* Shift OTHER right POS places and make it the source, restricting it
7888 to the proper length and mode. */
7890 src
= force_to_mode (simplify_shift_const (NULL_RTX
, LSHIFTRT
,
7891 GET_MODE (src
), other
, pos
),
7893 GET_MODE_BITSIZE (mode
) >= HOST_BITS_PER_WIDE_INT
7894 ? ~(unsigned HOST_WIDE_INT
) 0
7895 : ((unsigned HOST_WIDE_INT
) 1 << len
) - 1,
7898 /* If SRC is masked by an AND that does not make a difference in
7899 the value being stored, strip it. */
7900 if (GET_CODE (assign
) == ZERO_EXTRACT
7901 && GET_CODE (XEXP (assign
, 1)) == CONST_INT
7902 && INTVAL (XEXP (assign
, 1)) < HOST_BITS_PER_WIDE_INT
7903 && GET_CODE (src
) == AND
7904 && GET_CODE (XEXP (src
, 1)) == CONST_INT
7905 && ((unsigned HOST_WIDE_INT
) INTVAL (XEXP (src
, 1))
7906 == ((unsigned HOST_WIDE_INT
) 1 << INTVAL (XEXP (assign
, 1))) - 1))
7907 src
= XEXP (src
, 0);
7909 return gen_rtx_SET (VOIDmode
, assign
, src
);
7912 /* See if X is of the form (+ (* a c) (* b c)) and convert to (* (+ a b) c)
7916 apply_distributive_law (x
)
7919 enum rtx_code code
= GET_CODE (x
);
7920 rtx lhs
, rhs
, other
;
7922 enum rtx_code inner_code
;
7924 /* Distributivity is not true for floating point.
7925 It can change the value. So don't do it.
7926 -- rms and moshier@world.std.com. */
7927 if (FLOAT_MODE_P (GET_MODE (x
)))
7930 /* The outer operation can only be one of the following: */
7931 if (code
!= IOR
&& code
!= AND
&& code
!= XOR
7932 && code
!= PLUS
&& code
!= MINUS
)
7935 lhs
= XEXP (x
, 0), rhs
= XEXP (x
, 1);
7937 /* If either operand is a primitive we can't do anything, so get out
7939 if (GET_RTX_CLASS (GET_CODE (lhs
)) == 'o'
7940 || GET_RTX_CLASS (GET_CODE (rhs
)) == 'o')
7943 lhs
= expand_compound_operation (lhs
);
7944 rhs
= expand_compound_operation (rhs
);
7945 inner_code
= GET_CODE (lhs
);
7946 if (inner_code
!= GET_CODE (rhs
))
7949 /* See if the inner and outer operations distribute. */
7956 /* These all distribute except over PLUS. */
7957 if (code
== PLUS
|| code
== MINUS
)
7962 if (code
!= PLUS
&& code
!= MINUS
)
7967 /* This is also a multiply, so it distributes over everything. */
7971 /* Non-paradoxical SUBREGs distributes over all operations, provided
7972 the inner modes and byte offsets are the same, this is an extraction
7973 of a low-order part, we don't convert an fp operation to int or
7974 vice versa, and we would not be converting a single-word
7975 operation into a multi-word operation. The latter test is not
7976 required, but it prevents generating unneeded multi-word operations.
7977 Some of the previous tests are redundant given the latter test, but
7978 are retained because they are required for correctness.
7980 We produce the result slightly differently in this case. */
7982 if (GET_MODE (SUBREG_REG (lhs
)) != GET_MODE (SUBREG_REG (rhs
))
7983 || SUBREG_BYTE (lhs
) != SUBREG_BYTE (rhs
)
7984 || ! subreg_lowpart_p (lhs
)
7985 || (GET_MODE_CLASS (GET_MODE (lhs
))
7986 != GET_MODE_CLASS (GET_MODE (SUBREG_REG (lhs
))))
7987 || (GET_MODE_SIZE (GET_MODE (lhs
))
7988 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs
))))
7989 || GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs
))) > UNITS_PER_WORD
)
7992 tem
= gen_binary (code
, GET_MODE (SUBREG_REG (lhs
)),
7993 SUBREG_REG (lhs
), SUBREG_REG (rhs
));
7994 return gen_lowpart_for_combine (GET_MODE (x
), tem
);
8000 /* Set LHS and RHS to the inner operands (A and B in the example
8001 above) and set OTHER to the common operand (C in the example).
8002 These is only one way to do this unless the inner operation is
8004 if (GET_RTX_CLASS (inner_code
) == 'c'
8005 && rtx_equal_p (XEXP (lhs
, 0), XEXP (rhs
, 0)))
8006 other
= XEXP (lhs
, 0), lhs
= XEXP (lhs
, 1), rhs
= XEXP (rhs
, 1);
8007 else if (GET_RTX_CLASS (inner_code
) == 'c'
8008 && rtx_equal_p (XEXP (lhs
, 0), XEXP (rhs
, 1)))
8009 other
= XEXP (lhs
, 0), lhs
= XEXP (lhs
, 1), rhs
= XEXP (rhs
, 0);
8010 else if (GET_RTX_CLASS (inner_code
) == 'c'
8011 && rtx_equal_p (XEXP (lhs
, 1), XEXP (rhs
, 0)))
8012 other
= XEXP (lhs
, 1), lhs
= XEXP (lhs
, 0), rhs
= XEXP (rhs
, 1);
8013 else if (rtx_equal_p (XEXP (lhs
, 1), XEXP (rhs
, 1)))
8014 other
= XEXP (lhs
, 1), lhs
= XEXP (lhs
, 0), rhs
= XEXP (rhs
, 0);
8018 /* Form the new inner operation, seeing if it simplifies first. */
8019 tem
= gen_binary (code
, GET_MODE (x
), lhs
, rhs
);
8021 /* There is one exception to the general way of distributing:
8022 (a ^ b) | (a ^ c) -> (~a) & (b ^ c) */
8023 if (code
== XOR
&& inner_code
== IOR
)
8026 other
= simplify_gen_unary (NOT
, GET_MODE (x
), other
, GET_MODE (x
));
8029 /* We may be able to continuing distributing the result, so call
8030 ourselves recursively on the inner operation before forming the
8031 outer operation, which we return. */
8032 return gen_binary (inner_code
, GET_MODE (x
),
8033 apply_distributive_law (tem
), other
);
8036 /* We have X, a logical `and' of VAROP with the constant CONSTOP, to be done
8039 Return an equivalent form, if different from X. Otherwise, return X. If
8040 X is zero, we are to always construct the equivalent form. */
8043 simplify_and_const_int (x
, mode
, varop
, constop
)
8045 enum machine_mode mode
;
8047 unsigned HOST_WIDE_INT constop
;
8049 unsigned HOST_WIDE_INT nonzero
;
8052 /* Simplify VAROP knowing that we will be only looking at some of the
8055 Note by passing in CONSTOP, we guarantee that the bits not set in
8056 CONSTOP are not significant and will never be examined. We must
8057 ensure that is the case by explicitly masking out those bits
8058 before returning. */
8059 varop
= force_to_mode (varop
, mode
, constop
, NULL_RTX
, 0);
8061 /* If VAROP is a CLOBBER, we will fail so return it. */
8062 if (GET_CODE (varop
) == CLOBBER
)
8065 /* If VAROP is a CONST_INT, then we need to apply the mask in CONSTOP
8066 to VAROP and return the new constant. */
8067 if (GET_CODE (varop
) == CONST_INT
)
8068 return GEN_INT (trunc_int_for_mode (INTVAL (varop
) & constop
, mode
));
8070 /* See what bits may be nonzero in VAROP. Unlike the general case of
8071 a call to nonzero_bits, here we don't care about bits outside
8074 nonzero
= nonzero_bits (varop
, mode
) & GET_MODE_MASK (mode
);
8076 /* Turn off all bits in the constant that are known to already be zero.
8077 Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS
8078 which is tested below. */
8082 /* If we don't have any bits left, return zero. */
8086 /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is
8087 a power of two, we can replace this with an ASHIFT. */
8088 if (GET_CODE (varop
) == NEG
&& nonzero_bits (XEXP (varop
, 0), mode
) == 1
8089 && (i
= exact_log2 (constop
)) >= 0)
8090 return simplify_shift_const (NULL_RTX
, ASHIFT
, mode
, XEXP (varop
, 0), i
);
8092 /* If VAROP is an IOR or XOR, apply the AND to both branches of the IOR
8093 or XOR, then try to apply the distributive law. This may eliminate
8094 operations if either branch can be simplified because of the AND.
8095 It may also make some cases more complex, but those cases probably
8096 won't match a pattern either with or without this. */
8098 if (GET_CODE (varop
) == IOR
|| GET_CODE (varop
) == XOR
)
8100 gen_lowpart_for_combine
8102 apply_distributive_law
8103 (gen_binary (GET_CODE (varop
), GET_MODE (varop
),
8104 simplify_and_const_int (NULL_RTX
, GET_MODE (varop
),
8105 XEXP (varop
, 0), constop
),
8106 simplify_and_const_int (NULL_RTX
, GET_MODE (varop
),
8107 XEXP (varop
, 1), constop
))));
8109 /* If VAROP is PLUS, and the constant is a mask of low bite, distribute
8110 the AND and see if one of the operands simplifies to zero. If so, we
8111 may eliminate it. */
8113 if (GET_CODE (varop
) == PLUS
8114 && exact_log2 (constop
+ 1) >= 0)
8118 o0
= simplify_and_const_int (NULL_RTX
, mode
, XEXP (varop
, 0), constop
);
8119 o1
= simplify_and_const_int (NULL_RTX
, mode
, XEXP (varop
, 1), constop
);
8120 if (o0
== const0_rtx
)
8122 if (o1
== const0_rtx
)
8126 /* Get VAROP in MODE. Try to get a SUBREG if not. Don't make a new SUBREG
8127 if we already had one (just check for the simplest cases). */
8128 if (x
&& GET_CODE (XEXP (x
, 0)) == SUBREG
8129 && GET_MODE (XEXP (x
, 0)) == mode
8130 && SUBREG_REG (XEXP (x
, 0)) == varop
)
8131 varop
= XEXP (x
, 0);
8133 varop
= gen_lowpart_for_combine (mode
, varop
);
8135 /* If we can't make the SUBREG, try to return what we were given. */
8136 if (GET_CODE (varop
) == CLOBBER
)
8137 return x
? x
: varop
;
8139 /* If we are only masking insignificant bits, return VAROP. */
8140 if (constop
== nonzero
)
8144 /* Otherwise, return an AND. */
8145 constop
= trunc_int_for_mode (constop
, mode
);
8146 /* See how much, if any, of X we can use. */
8147 if (x
== 0 || GET_CODE (x
) != AND
|| GET_MODE (x
) != mode
)
8148 x
= gen_binary (AND
, mode
, varop
, GEN_INT (constop
));
8152 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
8153 || (unsigned HOST_WIDE_INT
) INTVAL (XEXP (x
, 1)) != constop
)
8154 SUBST (XEXP (x
, 1), GEN_INT (constop
));
8156 SUBST (XEXP (x
, 0), varop
);
8163 #define nonzero_bits_with_known(X, MODE) \
8164 cached_nonzero_bits (X, MODE, known_x, known_mode, known_ret)
8166 /* The function cached_nonzero_bits is a wrapper around nonzero_bits1.
8167 It avoids exponential behavior in nonzero_bits1 when X has
8168 identical subexpressions on the first or the second level. */
8170 static unsigned HOST_WIDE_INT
8171 cached_nonzero_bits (x
, mode
, known_x
, known_mode
, known_ret
)
8173 enum machine_mode mode
;
8175 enum machine_mode known_mode
;
8176 unsigned HOST_WIDE_INT known_ret
;
8178 if (x
== known_x
&& mode
== known_mode
)
8181 /* Try to find identical subexpressions. If found call
8182 nonzero_bits1 on X with the subexpressions as KNOWN_X and the
8183 precomputed value for the subexpression as KNOWN_RET. */
8185 if (GET_RTX_CLASS (GET_CODE (x
)) == '2'
8186 || GET_RTX_CLASS (GET_CODE (x
)) == 'c')
8188 rtx x0
= XEXP (x
, 0);
8189 rtx x1
= XEXP (x
, 1);
8191 /* Check the first level. */
8193 return nonzero_bits1 (x
, mode
, x0
, mode
,
8194 nonzero_bits_with_known (x0
, mode
));
8196 /* Check the second level. */
8197 if ((GET_RTX_CLASS (GET_CODE (x0
)) == '2'
8198 || GET_RTX_CLASS (GET_CODE (x0
)) == 'c')
8199 && (x1
== XEXP (x0
, 0) || x1
== XEXP (x0
, 1)))
8200 return nonzero_bits1 (x
, mode
, x1
, mode
,
8201 nonzero_bits_with_known (x1
, mode
));
8203 if ((GET_RTX_CLASS (GET_CODE (x1
)) == '2'
8204 || GET_RTX_CLASS (GET_CODE (x1
)) == 'c')
8205 && (x0
== XEXP (x1
, 0) || x0
== XEXP (x1
, 1)))
8206 return nonzero_bits1 (x
, mode
, x0
, mode
,
8207 nonzero_bits_with_known (x0
, mode
));
8210 return nonzero_bits1 (x
, mode
, known_x
, known_mode
, known_ret
);
8213 /* We let num_sign_bit_copies recur into nonzero_bits as that is useful.
8214 We don't let nonzero_bits recur into num_sign_bit_copies, because that
8215 is less useful. We can't allow both, because that results in exponential
8216 run time recursion. There is a nullstone testcase that triggered
8217 this. This macro avoids accidental uses of num_sign_bit_copies. */
8218 #define cached_num_sign_bit_copies()
8220 /* Given an expression, X, compute which bits in X can be nonzero.
8221 We don't care about bits outside of those defined in MODE.
8223 For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
8224 a shift, AND, or zero_extract, we can do better. */
8226 static unsigned HOST_WIDE_INT
8227 nonzero_bits1 (x
, mode
, known_x
, known_mode
, known_ret
)
8229 enum machine_mode mode
;
8231 enum machine_mode known_mode
;
8232 unsigned HOST_WIDE_INT known_ret
;
8234 unsigned HOST_WIDE_INT nonzero
= GET_MODE_MASK (mode
);
8235 unsigned HOST_WIDE_INT inner_nz
;
8237 unsigned int mode_width
= GET_MODE_BITSIZE (mode
);
8240 /* For floating-point values, assume all bits are needed. */
8241 if (FLOAT_MODE_P (GET_MODE (x
)) || FLOAT_MODE_P (mode
))
8244 /* If X is wider than MODE, use its mode instead. */
8245 if (GET_MODE_BITSIZE (GET_MODE (x
)) > mode_width
)
8247 mode
= GET_MODE (x
);
8248 nonzero
= GET_MODE_MASK (mode
);
8249 mode_width
= GET_MODE_BITSIZE (mode
);
8252 if (mode_width
> HOST_BITS_PER_WIDE_INT
)
8253 /* Our only callers in this case look for single bit values. So
8254 just return the mode mask. Those tests will then be false. */
8257 #ifndef WORD_REGISTER_OPERATIONS
8258 /* If MODE is wider than X, but both are a single word for both the host
8259 and target machines, we can compute this from which bits of the
8260 object might be nonzero in its own mode, taking into account the fact
8261 that on many CISC machines, accessing an object in a wider mode
8262 causes the high-order bits to become undefined. So they are
8263 not known to be zero. */
8265 if (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != mode
8266 && GET_MODE_BITSIZE (GET_MODE (x
)) <= BITS_PER_WORD
8267 && GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
8268 && GET_MODE_BITSIZE (mode
) > GET_MODE_BITSIZE (GET_MODE (x
)))
8270 nonzero
&= nonzero_bits_with_known (x
, GET_MODE (x
));
8271 nonzero
|= GET_MODE_MASK (mode
) & ~GET_MODE_MASK (GET_MODE (x
));
8276 code
= GET_CODE (x
);
8280 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
8281 /* If pointers extend unsigned and this is a pointer in Pmode, say that
8282 all the bits above ptr_mode are known to be zero. */
8283 if (POINTERS_EXTEND_UNSIGNED
&& GET_MODE (x
) == Pmode
8285 nonzero
&= GET_MODE_MASK (ptr_mode
);
8288 /* Include declared information about alignment of pointers. */
8289 /* ??? We don't properly preserve REG_POINTER changes across
8290 pointer-to-integer casts, so we can't trust it except for
8291 things that we know must be pointers. See execute/960116-1.c. */
8292 if ((x
== stack_pointer_rtx
8293 || x
== frame_pointer_rtx
8294 || x
== arg_pointer_rtx
)
8295 && REGNO_POINTER_ALIGN (REGNO (x
)))
8297 unsigned HOST_WIDE_INT alignment
8298 = REGNO_POINTER_ALIGN (REGNO (x
)) / BITS_PER_UNIT
;
8300 #ifdef PUSH_ROUNDING
8301 /* If PUSH_ROUNDING is defined, it is possible for the
8302 stack to be momentarily aligned only to that amount,
8303 so we pick the least alignment. */
8304 if (x
== stack_pointer_rtx
&& PUSH_ARGS
)
8305 alignment
= MIN (PUSH_ROUNDING (1), alignment
);
8308 nonzero
&= ~(alignment
- 1);
8311 /* If X is a register whose nonzero bits value is current, use it.
8312 Otherwise, if X is a register whose value we can find, use that
8313 value. Otherwise, use the previously-computed global nonzero bits
8314 for this register. */
8316 if (reg_last_set_value
[REGNO (x
)] != 0
8317 && (reg_last_set_mode
[REGNO (x
)] == mode
8318 || (GET_MODE_CLASS (reg_last_set_mode
[REGNO (x
)]) == MODE_INT
8319 && GET_MODE_CLASS (mode
) == MODE_INT
))
8320 && (reg_last_set_label
[REGNO (x
)] == label_tick
8321 || (REGNO (x
) >= FIRST_PSEUDO_REGISTER
8322 && REG_N_SETS (REGNO (x
)) == 1
8323 && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR
->next_bb
->global_live_at_start
,
8325 && INSN_CUID (reg_last_set
[REGNO (x
)]) < subst_low_cuid
)
8326 return reg_last_set_nonzero_bits
[REGNO (x
)] & nonzero
;
8328 tem
= get_last_value (x
);
8332 #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
8333 /* If X is narrower than MODE and TEM is a non-negative
8334 constant that would appear negative in the mode of X,
8335 sign-extend it for use in reg_nonzero_bits because some
8336 machines (maybe most) will actually do the sign-extension
8337 and this is the conservative approach.
8339 ??? For 2.5, try to tighten up the MD files in this regard
8340 instead of this kludge. */
8342 if (GET_MODE_BITSIZE (GET_MODE (x
)) < mode_width
8343 && GET_CODE (tem
) == CONST_INT
8345 && 0 != (INTVAL (tem
)
8346 & ((HOST_WIDE_INT
) 1
8347 << (GET_MODE_BITSIZE (GET_MODE (x
)) - 1))))
8348 tem
= GEN_INT (INTVAL (tem
)
8349 | ((HOST_WIDE_INT
) (-1)
8350 << GET_MODE_BITSIZE (GET_MODE (x
))));
8352 return nonzero_bits_with_known (tem
, mode
) & nonzero
;
8354 else if (nonzero_sign_valid
&& reg_nonzero_bits
[REGNO (x
)])
8356 unsigned HOST_WIDE_INT mask
= reg_nonzero_bits
[REGNO (x
)];
8358 if (GET_MODE_BITSIZE (GET_MODE (x
)) < mode_width
)
8359 /* We don't know anything about the upper bits. */
8360 mask
|= GET_MODE_MASK (mode
) ^ GET_MODE_MASK (GET_MODE (x
));
8361 return nonzero
& mask
;
8367 #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
8368 /* If X is negative in MODE, sign-extend the value. */
8369 if (INTVAL (x
) > 0 && mode_width
< BITS_PER_WORD
8370 && 0 != (INTVAL (x
) & ((HOST_WIDE_INT
) 1 << (mode_width
- 1))))
8371 return (INTVAL (x
) | ((HOST_WIDE_INT
) (-1) << mode_width
));
8377 #ifdef LOAD_EXTEND_OP
8378 /* In many, if not most, RISC machines, reading a byte from memory
8379 zeros the rest of the register. Noticing that fact saves a lot
8380 of extra zero-extends. */
8381 if (LOAD_EXTEND_OP (GET_MODE (x
)) == ZERO_EXTEND
)
8382 nonzero
&= GET_MODE_MASK (GET_MODE (x
));
8387 case UNEQ
: case LTGT
:
8388 case GT
: case GTU
: case UNGT
:
8389 case LT
: case LTU
: case UNLT
:
8390 case GE
: case GEU
: case UNGE
:
8391 case LE
: case LEU
: case UNLE
:
8392 case UNORDERED
: case ORDERED
:
8394 /* If this produces an integer result, we know which bits are set.
8395 Code here used to clear bits outside the mode of X, but that is
8398 if (GET_MODE_CLASS (mode
) == MODE_INT
8399 && mode_width
<= HOST_BITS_PER_WIDE_INT
)
8400 nonzero
= STORE_FLAG_VALUE
;
8405 /* Disabled to avoid exponential mutual recursion between nonzero_bits
8406 and num_sign_bit_copies. */
8407 if (num_sign_bit_copies (XEXP (x
, 0), GET_MODE (x
))
8408 == GET_MODE_BITSIZE (GET_MODE (x
)))
8412 if (GET_MODE_SIZE (GET_MODE (x
)) < mode_width
)
8413 nonzero
|= (GET_MODE_MASK (mode
) & ~GET_MODE_MASK (GET_MODE (x
)));
8418 /* Disabled to avoid exponential mutual recursion between nonzero_bits
8419 and num_sign_bit_copies. */
8420 if (num_sign_bit_copies (XEXP (x
, 0), GET_MODE (x
))
8421 == GET_MODE_BITSIZE (GET_MODE (x
)))
8427 nonzero
&= (nonzero_bits_with_known (XEXP (x
, 0), mode
)
8428 & GET_MODE_MASK (mode
));
8432 nonzero
&= nonzero_bits_with_known (XEXP (x
, 0), mode
);
8433 if (GET_MODE (XEXP (x
, 0)) != VOIDmode
)
8434 nonzero
&= GET_MODE_MASK (GET_MODE (XEXP (x
, 0)));
8438 /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
8439 Otherwise, show all the bits in the outer mode but not the inner
8441 inner_nz
= nonzero_bits_with_known (XEXP (x
, 0), mode
);
8442 if (GET_MODE (XEXP (x
, 0)) != VOIDmode
)
8444 inner_nz
&= GET_MODE_MASK (GET_MODE (XEXP (x
, 0)));
8446 & (((HOST_WIDE_INT
) 1
8447 << (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0))) - 1))))
8448 inner_nz
|= (GET_MODE_MASK (mode
)
8449 & ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0))));
8452 nonzero
&= inner_nz
;
8456 nonzero
&= (nonzero_bits_with_known (XEXP (x
, 0), mode
)
8457 & nonzero_bits_with_known (XEXP (x
, 1), mode
));
8461 case UMIN
: case UMAX
: case SMIN
: case SMAX
:
8463 unsigned HOST_WIDE_INT nonzero0
=
8464 nonzero_bits_with_known (XEXP (x
, 0), mode
);
8466 /* Don't call nonzero_bits for the second time if it cannot change
8468 if ((nonzero
& nonzero0
) != nonzero
)
8469 nonzero
&= (nonzero0
8470 | nonzero_bits_with_known (XEXP (x
, 1), mode
));
8474 case PLUS
: case MINUS
:
8476 case DIV
: case UDIV
:
8477 case MOD
: case UMOD
:
8478 /* We can apply the rules of arithmetic to compute the number of
8479 high- and low-order zero bits of these operations. We start by
8480 computing the width (position of the highest-order nonzero bit)
8481 and the number of low-order zero bits for each value. */
8483 unsigned HOST_WIDE_INT nz0
=
8484 nonzero_bits_with_known (XEXP (x
, 0), mode
);
8485 unsigned HOST_WIDE_INT nz1
=
8486 nonzero_bits_with_known (XEXP (x
, 1), mode
);
8487 int sign_index
= GET_MODE_BITSIZE (GET_MODE (x
)) - 1;
8488 int width0
= floor_log2 (nz0
) + 1;
8489 int width1
= floor_log2 (nz1
) + 1;
8490 int low0
= floor_log2 (nz0
& -nz0
);
8491 int low1
= floor_log2 (nz1
& -nz1
);
8492 HOST_WIDE_INT op0_maybe_minusp
8493 = (nz0
& ((HOST_WIDE_INT
) 1 << sign_index
));
8494 HOST_WIDE_INT op1_maybe_minusp
8495 = (nz1
& ((HOST_WIDE_INT
) 1 << sign_index
));
8496 unsigned int result_width
= mode_width
;
8502 result_width
= MAX (width0
, width1
) + 1;
8503 result_low
= MIN (low0
, low1
);
8506 result_low
= MIN (low0
, low1
);
8509 result_width
= width0
+ width1
;
8510 result_low
= low0
+ low1
;
8515 if (! op0_maybe_minusp
&& ! op1_maybe_minusp
)
8516 result_width
= width0
;
8521 result_width
= width0
;
8526 if (! op0_maybe_minusp
&& ! op1_maybe_minusp
)
8527 result_width
= MIN (width0
, width1
);
8528 result_low
= MIN (low0
, low1
);
8533 result_width
= MIN (width0
, width1
);
8534 result_low
= MIN (low0
, low1
);
8540 if (result_width
< mode_width
)
8541 nonzero
&= ((HOST_WIDE_INT
) 1 << result_width
) - 1;
8544 nonzero
&= ~(((HOST_WIDE_INT
) 1 << result_low
) - 1);
8546 #ifdef POINTERS_EXTEND_UNSIGNED
8547 /* If pointers extend unsigned and this is an addition or subtraction
8548 to a pointer in Pmode, all the bits above ptr_mode are known to be
8550 if (POINTERS_EXTEND_UNSIGNED
> 0 && GET_MODE (x
) == Pmode
8551 && (code
== PLUS
|| code
== MINUS
)
8552 && GET_CODE (XEXP (x
, 0)) == REG
&& REG_POINTER (XEXP (x
, 0)))
8553 nonzero
&= GET_MODE_MASK (ptr_mode
);
8559 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
8560 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
)
8561 nonzero
&= ((HOST_WIDE_INT
) 1 << INTVAL (XEXP (x
, 1))) - 1;
8565 /* If this is a SUBREG formed for a promoted variable that has
8566 been zero-extended, we know that at least the high-order bits
8567 are zero, though others might be too. */
8569 if (SUBREG_PROMOTED_VAR_P (x
) && SUBREG_PROMOTED_UNSIGNED_P (x
) > 0)
8570 nonzero
= (GET_MODE_MASK (GET_MODE (x
))
8571 & nonzero_bits_with_known (SUBREG_REG (x
), GET_MODE (x
)));
8573 /* If the inner mode is a single word for both the host and target
8574 machines, we can compute this from which bits of the inner
8575 object might be nonzero. */
8576 if (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))) <= BITS_PER_WORD
8577 && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
)))
8578 <= HOST_BITS_PER_WIDE_INT
))
8580 nonzero
&= nonzero_bits_with_known (SUBREG_REG (x
), mode
);
8582 #if defined (WORD_REGISTER_OPERATIONS) && defined (LOAD_EXTEND_OP)
8583 /* If this is a typical RISC machine, we only have to worry
8584 about the way loads are extended. */
8585 if ((LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x
))) == SIGN_EXTEND
8587 & (((unsigned HOST_WIDE_INT
) 1
8588 << (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))) - 1))))
8590 : LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x
))) != ZERO_EXTEND
)
8591 || GET_CODE (SUBREG_REG (x
)) != MEM
)
8594 /* On many CISC machines, accessing an object in a wider mode
8595 causes the high-order bits to become undefined. So they are
8596 not known to be zero. */
8597 if (GET_MODE_SIZE (GET_MODE (x
))
8598 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
8599 nonzero
|= (GET_MODE_MASK (GET_MODE (x
))
8600 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (x
))));
8609 /* The nonzero bits are in two classes: any bits within MODE
8610 that aren't in GET_MODE (x) are always significant. The rest of the
8611 nonzero bits are those that are significant in the operand of
8612 the shift when shifted the appropriate number of bits. This
8613 shows that high-order bits are cleared by the right shift and
8614 low-order bits by left shifts. */
8615 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
8616 && INTVAL (XEXP (x
, 1)) >= 0
8617 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
)
8619 enum machine_mode inner_mode
= GET_MODE (x
);
8620 unsigned int width
= GET_MODE_BITSIZE (inner_mode
);
8621 int count
= INTVAL (XEXP (x
, 1));
8622 unsigned HOST_WIDE_INT mode_mask
= GET_MODE_MASK (inner_mode
);
8623 unsigned HOST_WIDE_INT op_nonzero
=
8624 nonzero_bits_with_known (XEXP (x
, 0), mode
);
8625 unsigned HOST_WIDE_INT inner
= op_nonzero
& mode_mask
;
8626 unsigned HOST_WIDE_INT outer
= 0;
8628 if (mode_width
> width
)
8629 outer
= (op_nonzero
& nonzero
& ~mode_mask
);
8631 if (code
== LSHIFTRT
)
8633 else if (code
== ASHIFTRT
)
8637 /* If the sign bit may have been nonzero before the shift, we
8638 need to mark all the places it could have been copied to
8639 by the shift as possibly nonzero. */
8640 if (inner
& ((HOST_WIDE_INT
) 1 << (width
- 1 - count
)))
8641 inner
|= (((HOST_WIDE_INT
) 1 << count
) - 1) << (width
- count
);
8643 else if (code
== ASHIFT
)
8646 inner
= ((inner
<< (count
% width
)
8647 | (inner
>> (width
- (count
% width
)))) & mode_mask
);
8649 nonzero
&= (outer
| inner
);
8655 /* This is at most the number of bits in the mode. */
8656 nonzero
= ((HOST_WIDE_INT
) 2 << (floor_log2 (mode_width
))) - 1;
8660 /* If CLZ has a known value at zero, then the nonzero bits are
8661 that value, plus the number of bits in the mode minus one. */
8662 if (CLZ_DEFINED_VALUE_AT_ZERO (mode
, nonzero
))
8663 nonzero
|= ((HOST_WIDE_INT
) 1 << (floor_log2 (mode_width
))) - 1;
8669 /* If CTZ has a known value at zero, then the nonzero bits are
8670 that value, plus the number of bits in the mode minus one. */
8671 if (CTZ_DEFINED_VALUE_AT_ZERO (mode
, nonzero
))
8672 nonzero
|= ((HOST_WIDE_INT
) 1 << (floor_log2 (mode_width
))) - 1;
8682 nonzero
&= (nonzero_bits_with_known (XEXP (x
, 1), mode
)
8683 | nonzero_bits_with_known (XEXP (x
, 2), mode
));
8693 /* See the macro definition above. */
8694 #undef cached_num_sign_bit_copies
8696 #define num_sign_bit_copies_with_known(X, M) \
8697 cached_num_sign_bit_copies (X, M, known_x, known_mode, known_ret)
8699 /* The function cached_num_sign_bit_copies is a wrapper around
8700 num_sign_bit_copies1. It avoids exponential behavior in
8701 num_sign_bit_copies1 when X has identical subexpressions on the
8702 first or the second level. */
8705 cached_num_sign_bit_copies (x
, mode
, known_x
, known_mode
, known_ret
)
8707 enum machine_mode mode
;
8709 enum machine_mode known_mode
;
8710 unsigned int known_ret
;
8712 if (x
== known_x
&& mode
== known_mode
)
8715 /* Try to find identical subexpressions. If found call
8716 num_sign_bit_copies1 on X with the subexpressions as KNOWN_X and
8717 the precomputed value for the subexpression as KNOWN_RET. */
8719 if (GET_RTX_CLASS (GET_CODE (x
)) == '2'
8720 || GET_RTX_CLASS (GET_CODE (x
)) == 'c')
8722 rtx x0
= XEXP (x
, 0);
8723 rtx x1
= XEXP (x
, 1);
8725 /* Check the first level. */
8728 num_sign_bit_copies1 (x
, mode
, x0
, mode
,
8729 num_sign_bit_copies_with_known (x0
, mode
));
8731 /* Check the second level. */
8732 if ((GET_RTX_CLASS (GET_CODE (x0
)) == '2'
8733 || GET_RTX_CLASS (GET_CODE (x0
)) == 'c')
8734 && (x1
== XEXP (x0
, 0) || x1
== XEXP (x0
, 1)))
8736 num_sign_bit_copies1 (x
, mode
, x1
, mode
,
8737 num_sign_bit_copies_with_known (x1
, mode
));
8739 if ((GET_RTX_CLASS (GET_CODE (x1
)) == '2'
8740 || GET_RTX_CLASS (GET_CODE (x1
)) == 'c')
8741 && (x0
== XEXP (x1
, 0) || x0
== XEXP (x1
, 1)))
8743 num_sign_bit_copies1 (x
, mode
, x0
, mode
,
8744 num_sign_bit_copies_with_known (x0
, mode
));
8747 return num_sign_bit_copies1 (x
, mode
, known_x
, known_mode
, known_ret
);
8750 /* Return the number of bits at the high-order end of X that are known to
8751 be equal to the sign bit. X will be used in mode MODE; if MODE is
8752 VOIDmode, X will be used in its own mode. The returned value will always
8753 be between 1 and the number of bits in MODE. */
8756 num_sign_bit_copies1 (x
, mode
, known_x
, known_mode
, known_ret
)
8758 enum machine_mode mode
;
8760 enum machine_mode known_mode
;
8761 unsigned int known_ret
;
8763 enum rtx_code code
= GET_CODE (x
);
8764 unsigned int bitwidth
;
8765 int num0
, num1
, result
;
8766 unsigned HOST_WIDE_INT nonzero
;
8769 /* If we weren't given a mode, use the mode of X. If the mode is still
8770 VOIDmode, we don't know anything. Likewise if one of the modes is
8773 if (mode
== VOIDmode
)
8774 mode
= GET_MODE (x
);
8776 if (mode
== VOIDmode
|| FLOAT_MODE_P (mode
) || FLOAT_MODE_P (GET_MODE (x
)))
8779 bitwidth
= GET_MODE_BITSIZE (mode
);
8781 /* For a smaller object, just ignore the high bits. */
8782 if (bitwidth
< GET_MODE_BITSIZE (GET_MODE (x
)))
8784 num0
= num_sign_bit_copies_with_known (x
, GET_MODE (x
));
8786 num0
- (int) (GET_MODE_BITSIZE (GET_MODE (x
)) - bitwidth
));
8789 if (GET_MODE (x
) != VOIDmode
&& bitwidth
> GET_MODE_BITSIZE (GET_MODE (x
)))
8791 #ifndef WORD_REGISTER_OPERATIONS
8792 /* If this machine does not do all register operations on the entire
8793 register and MODE is wider than the mode of X, we can say nothing
8794 at all about the high-order bits. */
8797 /* Likewise on machines that do, if the mode of the object is smaller
8798 than a word and loads of that size don't sign extend, we can say
8799 nothing about the high order bits. */
8800 if (GET_MODE_BITSIZE (GET_MODE (x
)) < BITS_PER_WORD
8801 #ifdef LOAD_EXTEND_OP
8802 && LOAD_EXTEND_OP (GET_MODE (x
)) != SIGN_EXTEND
8813 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
8814 /* If pointers extend signed and this is a pointer in Pmode, say that
8815 all the bits above ptr_mode are known to be sign bit copies. */
8816 if (! POINTERS_EXTEND_UNSIGNED
&& GET_MODE (x
) == Pmode
&& mode
== Pmode
8818 return GET_MODE_BITSIZE (Pmode
) - GET_MODE_BITSIZE (ptr_mode
) + 1;
8821 if (reg_last_set_value
[REGNO (x
)] != 0
8822 && reg_last_set_mode
[REGNO (x
)] == mode
8823 && (reg_last_set_label
[REGNO (x
)] == label_tick
8824 || (REGNO (x
) >= FIRST_PSEUDO_REGISTER
8825 && REG_N_SETS (REGNO (x
)) == 1
8826 && ! REGNO_REG_SET_P (ENTRY_BLOCK_PTR
->next_bb
->global_live_at_start
,
8828 && INSN_CUID (reg_last_set
[REGNO (x
)]) < subst_low_cuid
)
8829 return reg_last_set_sign_bit_copies
[REGNO (x
)];
8831 tem
= get_last_value (x
);
8833 return num_sign_bit_copies_with_known (tem
, mode
);
8835 if (nonzero_sign_valid
&& reg_sign_bit_copies
[REGNO (x
)] != 0
8836 && GET_MODE_BITSIZE (GET_MODE (x
)) == bitwidth
)
8837 return reg_sign_bit_copies
[REGNO (x
)];
8841 #ifdef LOAD_EXTEND_OP
8842 /* Some RISC machines sign-extend all loads of smaller than a word. */
8843 if (LOAD_EXTEND_OP (GET_MODE (x
)) == SIGN_EXTEND
)
8844 return MAX (1, ((int) bitwidth
8845 - (int) GET_MODE_BITSIZE (GET_MODE (x
)) + 1));
8850 /* If the constant is negative, take its 1's complement and remask.
8851 Then see how many zero bits we have. */
8852 nonzero
= INTVAL (x
) & GET_MODE_MASK (mode
);
8853 if (bitwidth
<= HOST_BITS_PER_WIDE_INT
8854 && (nonzero
& ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
8855 nonzero
= (~nonzero
) & GET_MODE_MASK (mode
);
8857 return (nonzero
== 0 ? bitwidth
: bitwidth
- floor_log2 (nonzero
) - 1);
8860 /* If this is a SUBREG for a promoted object that is sign-extended
8861 and we are looking at it in a wider mode, we know that at least the
8862 high-order bits are known to be sign bit copies. */
8864 if (SUBREG_PROMOTED_VAR_P (x
) && ! SUBREG_PROMOTED_UNSIGNED_P (x
))
8866 num0
= num_sign_bit_copies_with_known (SUBREG_REG (x
), mode
);
8867 return MAX ((int) bitwidth
8868 - (int) GET_MODE_BITSIZE (GET_MODE (x
)) + 1,
8872 /* For a smaller object, just ignore the high bits. */
8873 if (bitwidth
<= GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))))
8875 num0
= num_sign_bit_copies_with_known (SUBREG_REG (x
), VOIDmode
);
8876 return MAX (1, (num0
8877 - (int) (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
)))
8881 #ifdef WORD_REGISTER_OPERATIONS
8882 #ifdef LOAD_EXTEND_OP
8883 /* For paradoxical SUBREGs on machines where all register operations
8884 affect the entire register, just look inside. Note that we are
8885 passing MODE to the recursive call, so the number of sign bit copies
8886 will remain relative to that mode, not the inner mode. */
8888 /* This works only if loads sign extend. Otherwise, if we get a
8889 reload for the inner part, it may be loaded from the stack, and
8890 then we lose all sign bit copies that existed before the store
8893 if ((GET_MODE_SIZE (GET_MODE (x
))
8894 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
8895 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x
))) == SIGN_EXTEND
8896 && GET_CODE (SUBREG_REG (x
)) == MEM
)
8897 return num_sign_bit_copies_with_known (SUBREG_REG (x
), mode
);
8903 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
8904 return MAX (1, (int) bitwidth
- INTVAL (XEXP (x
, 1)));
8908 return (bitwidth
- GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
8909 + num_sign_bit_copies_with_known (XEXP (x
, 0), VOIDmode
));
8912 /* For a smaller object, just ignore the high bits. */
8913 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), VOIDmode
);
8914 return MAX (1, (num0
- (int) (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
8918 return num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
8920 case ROTATE
: case ROTATERT
:
8921 /* If we are rotating left by a number of bits less than the number
8922 of sign bit copies, we can just subtract that amount from the
8924 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
8925 && INTVAL (XEXP (x
, 1)) >= 0
8926 && INTVAL (XEXP (x
, 1)) < (int) bitwidth
)
8928 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
8929 return MAX (1, num0
- (code
== ROTATE
? INTVAL (XEXP (x
, 1))
8930 : (int) bitwidth
- INTVAL (XEXP (x
, 1))));
8935 /* In general, this subtracts one sign bit copy. But if the value
8936 is known to be positive, the number of sign bit copies is the
8937 same as that of the input. Finally, if the input has just one bit
8938 that might be nonzero, all the bits are copies of the sign bit. */
8939 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
8940 if (bitwidth
> HOST_BITS_PER_WIDE_INT
)
8941 return num0
> 1 ? num0
- 1 : 1;
8943 nonzero
= nonzero_bits (XEXP (x
, 0), mode
);
8948 && (((HOST_WIDE_INT
) 1 << (bitwidth
- 1)) & nonzero
))
8953 case IOR
: case AND
: case XOR
:
8954 case SMIN
: case SMAX
: case UMIN
: case UMAX
:
8955 /* Logical operations will preserve the number of sign-bit copies.
8956 MIN and MAX operations always return one of the operands. */
8957 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
8958 num1
= num_sign_bit_copies_with_known (XEXP (x
, 1), mode
);
8959 return MIN (num0
, num1
);
8961 case PLUS
: case MINUS
:
8962 /* For addition and subtraction, we can have a 1-bit carry. However,
8963 if we are subtracting 1 from a positive number, there will not
8964 be such a carry. Furthermore, if the positive number is known to
8965 be 0 or 1, we know the result is either -1 or 0. */
8967 if (code
== PLUS
&& XEXP (x
, 1) == constm1_rtx
8968 && bitwidth
<= HOST_BITS_PER_WIDE_INT
)
8970 nonzero
= nonzero_bits (XEXP (x
, 0), mode
);
8971 if ((((HOST_WIDE_INT
) 1 << (bitwidth
- 1)) & nonzero
) == 0)
8972 return (nonzero
== 1 || nonzero
== 0 ? bitwidth
8973 : bitwidth
- floor_log2 (nonzero
) - 1);
8976 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
8977 num1
= num_sign_bit_copies_with_known (XEXP (x
, 1), mode
);
8978 result
= MAX (1, MIN (num0
, num1
) - 1);
8980 #ifdef POINTERS_EXTEND_UNSIGNED
8981 /* If pointers extend signed and this is an addition or subtraction
8982 to a pointer in Pmode, all the bits above ptr_mode are known to be
8984 if (! POINTERS_EXTEND_UNSIGNED
&& GET_MODE (x
) == Pmode
8985 && (code
== PLUS
|| code
== MINUS
)
8986 && GET_CODE (XEXP (x
, 0)) == REG
&& REG_POINTER (XEXP (x
, 0)))
8987 result
= MAX ((int) (GET_MODE_BITSIZE (Pmode
)
8988 - GET_MODE_BITSIZE (ptr_mode
) + 1),
8994 /* The number of bits of the product is the sum of the number of
8995 bits of both terms. However, unless one of the terms if known
8996 to be positive, we must allow for an additional bit since negating
8997 a negative number can remove one sign bit copy. */
8999 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
9000 num1
= num_sign_bit_copies_with_known (XEXP (x
, 1), mode
);
9002 result
= bitwidth
- (bitwidth
- num0
) - (bitwidth
- num1
);
9004 && (bitwidth
> HOST_BITS_PER_WIDE_INT
9005 || (((nonzero_bits (XEXP (x
, 0), mode
)
9006 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
9007 && ((nonzero_bits (XEXP (x
, 1), mode
)
9008 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0))))
9011 return MAX (1, result
);
9014 /* The result must be <= the first operand. If the first operand
9015 has the high bit set, we know nothing about the number of sign
9017 if (bitwidth
> HOST_BITS_PER_WIDE_INT
)
9019 else if ((nonzero_bits (XEXP (x
, 0), mode
)
9020 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
9023 return num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
9026 /* The result must be <= the second operand. */
9027 return num_sign_bit_copies_with_known (XEXP (x
, 1), mode
);
9030 /* Similar to unsigned division, except that we have to worry about
9031 the case where the divisor is negative, in which case we have
9033 result
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
9035 && (bitwidth
> HOST_BITS_PER_WIDE_INT
9036 || (nonzero_bits (XEXP (x
, 1), mode
)
9037 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0))
9043 result
= num_sign_bit_copies_with_known (XEXP (x
, 1), mode
);
9045 && (bitwidth
> HOST_BITS_PER_WIDE_INT
9046 || (nonzero_bits (XEXP (x
, 1), mode
)
9047 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0))
9053 /* Shifts by a constant add to the number of bits equal to the
9055 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
9056 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
9057 && INTVAL (XEXP (x
, 1)) > 0)
9058 num0
= MIN ((int) bitwidth
, num0
+ INTVAL (XEXP (x
, 1)));
9063 /* Left shifts destroy copies. */
9064 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
9065 || INTVAL (XEXP (x
, 1)) < 0
9066 || INTVAL (XEXP (x
, 1)) >= (int) bitwidth
)
9069 num0
= num_sign_bit_copies_with_known (XEXP (x
, 0), mode
);
9070 return MAX (1, num0
- INTVAL (XEXP (x
, 1)));
9073 num0
= num_sign_bit_copies_with_known (XEXP (x
, 1), mode
);
9074 num1
= num_sign_bit_copies_with_known (XEXP (x
, 2), mode
);
9075 return MIN (num0
, num1
);
9077 case EQ
: case NE
: case GE
: case GT
: case LE
: case LT
:
9078 case UNEQ
: case LTGT
: case UNGE
: case UNGT
: case UNLE
: case UNLT
:
9079 case GEU
: case GTU
: case LEU
: case LTU
:
9080 case UNORDERED
: case ORDERED
:
9081 /* If the constant is negative, take its 1's complement and remask.
9082 Then see how many zero bits we have. */
9083 nonzero
= STORE_FLAG_VALUE
;
9084 if (bitwidth
<= HOST_BITS_PER_WIDE_INT
9085 && (nonzero
& ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
9086 nonzero
= (~nonzero
) & GET_MODE_MASK (mode
);
9088 return (nonzero
== 0 ? bitwidth
: bitwidth
- floor_log2 (nonzero
) - 1);
9095 /* If we haven't been able to figure it out by one of the above rules,
9096 see if some of the high-order bits are known to be zero. If so,
9097 count those bits and return one less than that amount. If we can't
9098 safely compute the mask for this mode, always return BITWIDTH. */
9100 if (bitwidth
> HOST_BITS_PER_WIDE_INT
)
9103 nonzero
= nonzero_bits (x
, mode
);
9104 return (nonzero
& ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))
9105 ? 1 : bitwidth
- floor_log2 (nonzero
) - 1);
9108 /* Return the number of "extended" bits there are in X, when interpreted
9109 as a quantity in MODE whose signedness is indicated by UNSIGNEDP. For
9110 unsigned quantities, this is the number of high-order zero bits.
9111 For signed quantities, this is the number of copies of the sign bit
9112 minus 1. In both case, this function returns the number of "spare"
9113 bits. For example, if two quantities for which this function returns
9114 at least 1 are added, the addition is known not to overflow.
9116 This function will always return 0 unless called during combine, which
9117 implies that it must be called from a define_split. */
9120 extended_count (x
, mode
, unsignedp
)
9122 enum machine_mode mode
;
9125 if (nonzero_sign_valid
== 0)
9129 ? (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
9130 ? (unsigned int) (GET_MODE_BITSIZE (mode
) - 1
9131 - floor_log2 (nonzero_bits (x
, mode
)))
9133 : num_sign_bit_copies (x
, mode
) - 1);
9136 /* This function is called from `simplify_shift_const' to merge two
9137 outer operations. Specifically, we have already found that we need
9138 to perform operation *POP0 with constant *PCONST0 at the outermost
9139 position. We would now like to also perform OP1 with constant CONST1
9140 (with *POP0 being done last).
9142 Return 1 if we can do the operation and update *POP0 and *PCONST0 with
9143 the resulting operation. *PCOMP_P is set to 1 if we would need to
9144 complement the innermost operand, otherwise it is unchanged.
9146 MODE is the mode in which the operation will be done. No bits outside
9147 the width of this mode matter. It is assumed that the width of this mode
9148 is smaller than or equal to HOST_BITS_PER_WIDE_INT.
9150 If *POP0 or OP1 are NIL, it means no operation is required. Only NEG, PLUS,
9151 IOR, XOR, and AND are supported. We may set *POP0 to SET if the proper
9152 result is simply *PCONST0.
9154 If the resulting operation cannot be expressed as one operation, we
9155 return 0 and do not change *POP0, *PCONST0, and *PCOMP_P. */
9158 merge_outer_ops (pop0
, pconst0
, op1
, const1
, mode
, pcomp_p
)
9159 enum rtx_code
*pop0
;
9160 HOST_WIDE_INT
*pconst0
;
9162 HOST_WIDE_INT const1
;
9163 enum machine_mode mode
;
9166 enum rtx_code op0
= *pop0
;
9167 HOST_WIDE_INT const0
= *pconst0
;
9169 const0
&= GET_MODE_MASK (mode
);
9170 const1
&= GET_MODE_MASK (mode
);
9172 /* If OP0 is an AND, clear unimportant bits in CONST1. */
9176 /* If OP0 or OP1 is NIL, this is easy. Similarly if they are the same or
9179 if (op1
== NIL
|| op0
== SET
)
9182 else if (op0
== NIL
)
9183 op0
= op1
, const0
= const1
;
9185 else if (op0
== op1
)
9209 /* Otherwise, if either is a PLUS or NEG, we can't do anything. */
9210 else if (op0
== PLUS
|| op1
== PLUS
|| op0
== NEG
|| op1
== NEG
)
9213 /* If the two constants aren't the same, we can't do anything. The
9214 remaining six cases can all be done. */
9215 else if (const0
!= const1
)
9223 /* (a & b) | b == b */
9225 else /* op1 == XOR */
9226 /* (a ^ b) | b == a | b */
9232 /* (a & b) ^ b == (~a) & b */
9233 op0
= AND
, *pcomp_p
= 1;
9234 else /* op1 == IOR */
9235 /* (a | b) ^ b == a & ~b */
9236 op0
= AND
, const0
= ~const0
;
9241 /* (a | b) & b == b */
9243 else /* op1 == XOR */
9244 /* (a ^ b) & b) == (~a) & b */
9251 /* Check for NO-OP cases. */
9252 const0
&= GET_MODE_MASK (mode
);
9254 && (op0
== IOR
|| op0
== XOR
|| op0
== PLUS
))
9256 else if (const0
== 0 && op0
== AND
)
9258 else if ((unsigned HOST_WIDE_INT
) const0
== GET_MODE_MASK (mode
)
9262 /* ??? Slightly redundant with the above mask, but not entirely.
9263 Moving this above means we'd have to sign-extend the mode mask
9264 for the final test. */
9265 const0
= trunc_int_for_mode (const0
, mode
);
9273 /* Simplify a shift of VAROP by COUNT bits. CODE says what kind of shift.
9274 The result of the shift is RESULT_MODE. X, if nonzero, is an expression
9275 that we started with.
9277 The shift is normally computed in the widest mode we find in VAROP, as
9278 long as it isn't a different number of words than RESULT_MODE. Exceptions
9279 are ASHIFTRT and ROTATE, which are always done in their original mode, */
9282 simplify_shift_const (x
, code
, result_mode
, varop
, orig_count
)
9285 enum machine_mode result_mode
;
9289 enum rtx_code orig_code
= code
;
9292 enum machine_mode mode
= result_mode
;
9293 enum machine_mode shift_mode
, tmode
;
9294 unsigned int mode_words
9295 = (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
9296 /* We form (outer_op (code varop count) (outer_const)). */
9297 enum rtx_code outer_op
= NIL
;
9298 HOST_WIDE_INT outer_const
= 0;
9300 int complement_p
= 0;
9303 /* Make sure and truncate the "natural" shift on the way in. We don't
9304 want to do this inside the loop as it makes it more difficult to
9306 #ifdef SHIFT_COUNT_TRUNCATED
9307 if (SHIFT_COUNT_TRUNCATED
)
9308 orig_count
&= GET_MODE_BITSIZE (mode
) - 1;
9311 /* If we were given an invalid count, don't do anything except exactly
9312 what was requested. */
9314 if (orig_count
< 0 || orig_count
>= (int) GET_MODE_BITSIZE (mode
))
9319 return gen_rtx_fmt_ee (code
, mode
, varop
, GEN_INT (orig_count
));
9324 /* Unless one of the branches of the `if' in this loop does a `continue',
9325 we will `break' the loop after the `if'. */
9329 /* If we have an operand of (clobber (const_int 0)), just return that
9331 if (GET_CODE (varop
) == CLOBBER
)
9334 /* If we discovered we had to complement VAROP, leave. Making a NOT
9335 here would cause an infinite loop. */
9339 /* Convert ROTATERT to ROTATE. */
9340 if (code
== ROTATERT
)
9342 unsigned int bitsize
= GET_MODE_BITSIZE (result_mode
);;
9344 if (VECTOR_MODE_P (result_mode
))
9345 count
= bitsize
/ GET_MODE_NUNITS (result_mode
) - count
;
9347 count
= bitsize
- count
;
9350 /* We need to determine what mode we will do the shift in. If the
9351 shift is a right shift or a ROTATE, we must always do it in the mode
9352 it was originally done in. Otherwise, we can do it in MODE, the
9353 widest mode encountered. */
9355 = (code
== ASHIFTRT
|| code
== LSHIFTRT
|| code
== ROTATE
9356 ? result_mode
: mode
);
9358 /* Handle cases where the count is greater than the size of the mode
9359 minus 1. For ASHIFT, use the size minus one as the count (this can
9360 occur when simplifying (lshiftrt (ashiftrt ..))). For rotates,
9361 take the count modulo the size. For other shifts, the result is
9364 Since these shifts are being produced by the compiler by combining
9365 multiple operations, each of which are defined, we know what the
9366 result is supposed to be. */
9368 if (count
> (unsigned int) (GET_MODE_BITSIZE (shift_mode
) - 1))
9370 if (code
== ASHIFTRT
)
9371 count
= GET_MODE_BITSIZE (shift_mode
) - 1;
9372 else if (code
== ROTATE
|| code
== ROTATERT
)
9373 count
%= GET_MODE_BITSIZE (shift_mode
);
9376 /* We can't simply return zero because there may be an
9384 /* An arithmetic right shift of a quantity known to be -1 or 0
9386 if (code
== ASHIFTRT
9387 && (num_sign_bit_copies (varop
, shift_mode
)
9388 == GET_MODE_BITSIZE (shift_mode
)))
9394 /* If we are doing an arithmetic right shift and discarding all but
9395 the sign bit copies, this is equivalent to doing a shift by the
9396 bitsize minus one. Convert it into that shift because it will often
9397 allow other simplifications. */
9399 if (code
== ASHIFTRT
9400 && (count
+ num_sign_bit_copies (varop
, shift_mode
)
9401 >= GET_MODE_BITSIZE (shift_mode
)))
9402 count
= GET_MODE_BITSIZE (shift_mode
) - 1;
9404 /* We simplify the tests below and elsewhere by converting
9405 ASHIFTRT to LSHIFTRT if we know the sign bit is clear.
9406 `make_compound_operation' will convert it to an ASHIFTRT for
9407 those machines (such as VAX) that don't have an LSHIFTRT. */
9408 if (GET_MODE_BITSIZE (shift_mode
) <= HOST_BITS_PER_WIDE_INT
9410 && ((nonzero_bits (varop
, shift_mode
)
9411 & ((HOST_WIDE_INT
) 1 << (GET_MODE_BITSIZE (shift_mode
) - 1)))
9415 if (code
== LSHIFTRT
9416 && GET_MODE_BITSIZE (shift_mode
) <= HOST_BITS_PER_WIDE_INT
9417 && !(nonzero_bits (varop
, shift_mode
) >> count
))
9420 && GET_MODE_BITSIZE (shift_mode
) <= HOST_BITS_PER_WIDE_INT
9421 && !((nonzero_bits (varop
, shift_mode
) << count
)
9422 & GET_MODE_MASK (shift_mode
)))
9425 switch (GET_CODE (varop
))
9431 new = expand_compound_operation (varop
);
9440 /* If we have (xshiftrt (mem ...) C) and C is MODE_WIDTH
9441 minus the width of a smaller mode, we can do this with a
9442 SIGN_EXTEND or ZERO_EXTEND from the narrower memory location. */
9443 if ((code
== ASHIFTRT
|| code
== LSHIFTRT
)
9444 && ! mode_dependent_address_p (XEXP (varop
, 0))
9445 && ! MEM_VOLATILE_P (varop
)
9446 && (tmode
= mode_for_size (GET_MODE_BITSIZE (mode
) - count
,
9447 MODE_INT
, 1)) != BLKmode
)
9449 new = adjust_address_nv (varop
, tmode
,
9450 BYTES_BIG_ENDIAN
? 0
9451 : count
/ BITS_PER_UNIT
);
9453 varop
= gen_rtx_fmt_e (code
== ASHIFTRT
? SIGN_EXTEND
9454 : ZERO_EXTEND
, mode
, new);
9461 /* Similar to the case above, except that we can only do this if
9462 the resulting mode is the same as that of the underlying
9463 MEM and adjust the address depending on the *bits* endianness
9464 because of the way that bit-field extract insns are defined. */
9465 if ((code
== ASHIFTRT
|| code
== LSHIFTRT
)
9466 && (tmode
= mode_for_size (GET_MODE_BITSIZE (mode
) - count
,
9467 MODE_INT
, 1)) != BLKmode
9468 && tmode
== GET_MODE (XEXP (varop
, 0)))
9470 if (BITS_BIG_ENDIAN
)
9471 new = XEXP (varop
, 0);
9474 new = copy_rtx (XEXP (varop
, 0));
9475 SUBST (XEXP (new, 0),
9476 plus_constant (XEXP (new, 0),
9477 count
/ BITS_PER_UNIT
));
9480 varop
= gen_rtx_fmt_e (code
== ASHIFTRT
? SIGN_EXTEND
9481 : ZERO_EXTEND
, mode
, new);
9488 /* If VAROP is a SUBREG, strip it as long as the inner operand has
9489 the same number of words as what we've seen so far. Then store
9490 the widest mode in MODE. */
9491 if (subreg_lowpart_p (varop
)
9492 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop
)))
9493 > GET_MODE_SIZE (GET_MODE (varop
)))
9494 && (unsigned int) ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop
)))
9495 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
9498 varop
= SUBREG_REG (varop
);
9499 if (GET_MODE_SIZE (GET_MODE (varop
)) > GET_MODE_SIZE (mode
))
9500 mode
= GET_MODE (varop
);
9506 /* Some machines use MULT instead of ASHIFT because MULT
9507 is cheaper. But it is still better on those machines to
9508 merge two shifts into one. */
9509 if (GET_CODE (XEXP (varop
, 1)) == CONST_INT
9510 && exact_log2 (INTVAL (XEXP (varop
, 1))) >= 0)
9513 = gen_binary (ASHIFT
, GET_MODE (varop
), XEXP (varop
, 0),
9514 GEN_INT (exact_log2 (INTVAL (XEXP (varop
, 1)))));
9520 /* Similar, for when divides are cheaper. */
9521 if (GET_CODE (XEXP (varop
, 1)) == CONST_INT
9522 && exact_log2 (INTVAL (XEXP (varop
, 1))) >= 0)
9525 = gen_binary (LSHIFTRT
, GET_MODE (varop
), XEXP (varop
, 0),
9526 GEN_INT (exact_log2 (INTVAL (XEXP (varop
, 1)))));
9532 /* If we are extracting just the sign bit of an arithmetic
9533 right shift, that shift is not needed. However, the sign
9534 bit of a wider mode may be different from what would be
9535 interpreted as the sign bit in a narrower mode, so, if
9536 the result is narrower, don't discard the shift. */
9537 if (code
== LSHIFTRT
9538 && count
== (unsigned int) (GET_MODE_BITSIZE (result_mode
) - 1)
9539 && (GET_MODE_BITSIZE (result_mode
)
9540 >= GET_MODE_BITSIZE (GET_MODE (varop
))))
9542 varop
= XEXP (varop
, 0);
9546 /* ... fall through ... */
9551 /* Here we have two nested shifts. The result is usually the
9552 AND of a new shift with a mask. We compute the result below. */
9553 if (GET_CODE (XEXP (varop
, 1)) == CONST_INT
9554 && INTVAL (XEXP (varop
, 1)) >= 0
9555 && INTVAL (XEXP (varop
, 1)) < GET_MODE_BITSIZE (GET_MODE (varop
))
9556 && GET_MODE_BITSIZE (result_mode
) <= HOST_BITS_PER_WIDE_INT
9557 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
9559 enum rtx_code first_code
= GET_CODE (varop
);
9560 unsigned int first_count
= INTVAL (XEXP (varop
, 1));
9561 unsigned HOST_WIDE_INT mask
;
9564 /* We have one common special case. We can't do any merging if
9565 the inner code is an ASHIFTRT of a smaller mode. However, if
9566 we have (ashift:M1 (subreg:M1 (ashiftrt:M2 FOO C1) 0) C2)
9567 with C2 == GET_MODE_BITSIZE (M1) - GET_MODE_BITSIZE (M2),
9568 we can convert it to
9569 (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1).
9570 This simplifies certain SIGN_EXTEND operations. */
9571 if (code
== ASHIFT
&& first_code
== ASHIFTRT
9572 && count
== (unsigned int)
9573 (GET_MODE_BITSIZE (result_mode
)
9574 - GET_MODE_BITSIZE (GET_MODE (varop
))))
9576 /* C3 has the low-order C1 bits zero. */
9578 mask
= (GET_MODE_MASK (mode
)
9579 & ~(((HOST_WIDE_INT
) 1 << first_count
) - 1));
9581 varop
= simplify_and_const_int (NULL_RTX
, result_mode
,
9582 XEXP (varop
, 0), mask
);
9583 varop
= simplify_shift_const (NULL_RTX
, ASHIFT
, result_mode
,
9585 count
= first_count
;
9590 /* If this was (ashiftrt (ashift foo C1) C2) and FOO has more
9591 than C1 high-order bits equal to the sign bit, we can convert
9592 this to either an ASHIFT or an ASHIFTRT depending on the
9595 We cannot do this if VAROP's mode is not SHIFT_MODE. */
9597 if (code
== ASHIFTRT
&& first_code
== ASHIFT
9598 && GET_MODE (varop
) == shift_mode
9599 && (num_sign_bit_copies (XEXP (varop
, 0), shift_mode
)
9602 varop
= XEXP (varop
, 0);
9604 signed_count
= count
- first_count
;
9605 if (signed_count
< 0)
9606 count
= -signed_count
, code
= ASHIFT
;
9608 count
= signed_count
;
9613 /* There are some cases we can't do. If CODE is ASHIFTRT,
9614 we can only do this if FIRST_CODE is also ASHIFTRT.
9616 We can't do the case when CODE is ROTATE and FIRST_CODE is
9619 If the mode of this shift is not the mode of the outer shift,
9620 we can't do this if either shift is a right shift or ROTATE.
9622 Finally, we can't do any of these if the mode is too wide
9623 unless the codes are the same.
9625 Handle the case where the shift codes are the same
9628 if (code
== first_code
)
9630 if (GET_MODE (varop
) != result_mode
9631 && (code
== ASHIFTRT
|| code
== LSHIFTRT
9635 count
+= first_count
;
9636 varop
= XEXP (varop
, 0);
9640 if (code
== ASHIFTRT
9641 || (code
== ROTATE
&& first_code
== ASHIFTRT
)
9642 || GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_WIDE_INT
9643 || (GET_MODE (varop
) != result_mode
9644 && (first_code
== ASHIFTRT
|| first_code
== LSHIFTRT
9645 || first_code
== ROTATE
9646 || code
== ROTATE
)))
9649 /* To compute the mask to apply after the shift, shift the
9650 nonzero bits of the inner shift the same way the
9651 outer shift will. */
9653 mask_rtx
= GEN_INT (nonzero_bits (varop
, GET_MODE (varop
)));
9656 = simplify_binary_operation (code
, result_mode
, mask_rtx
,
9659 /* Give up if we can't compute an outer operation to use. */
9661 || GET_CODE (mask_rtx
) != CONST_INT
9662 || ! merge_outer_ops (&outer_op
, &outer_const
, AND
,
9664 result_mode
, &complement_p
))
9667 /* If the shifts are in the same direction, we add the
9668 counts. Otherwise, we subtract them. */
9669 signed_count
= count
;
9670 if ((code
== ASHIFTRT
|| code
== LSHIFTRT
)
9671 == (first_code
== ASHIFTRT
|| first_code
== LSHIFTRT
))
9672 signed_count
+= first_count
;
9674 signed_count
-= first_count
;
9676 /* If COUNT is positive, the new shift is usually CODE,
9677 except for the two exceptions below, in which case it is
9678 FIRST_CODE. If the count is negative, FIRST_CODE should
9680 if (signed_count
> 0
9681 && ((first_code
== ROTATE
&& code
== ASHIFT
)
9682 || (first_code
== ASHIFTRT
&& code
== LSHIFTRT
)))
9683 code
= first_code
, count
= signed_count
;
9684 else if (signed_count
< 0)
9685 code
= first_code
, count
= -signed_count
;
9687 count
= signed_count
;
9689 varop
= XEXP (varop
, 0);
9693 /* If we have (A << B << C) for any shift, we can convert this to
9694 (A << C << B). This wins if A is a constant. Only try this if
9695 B is not a constant. */
9697 else if (GET_CODE (varop
) == code
9698 && GET_CODE (XEXP (varop
, 1)) != CONST_INT
9700 = simplify_binary_operation (code
, mode
,
9704 varop
= gen_rtx_fmt_ee (code
, mode
, new, XEXP (varop
, 1));
9711 /* Make this fit the case below. */
9712 varop
= gen_rtx_XOR (mode
, XEXP (varop
, 0),
9713 GEN_INT (GET_MODE_MASK (mode
)));
9719 /* If we have (xshiftrt (ior (plus X (const_int -1)) X) C)
9720 with C the size of VAROP - 1 and the shift is logical if
9721 STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1,
9722 we have an (le X 0) operation. If we have an arithmetic shift
9723 and STORE_FLAG_VALUE is 1 or we have a logical shift with
9724 STORE_FLAG_VALUE of -1, we have a (neg (le X 0)) operation. */
9726 if (GET_CODE (varop
) == IOR
&& GET_CODE (XEXP (varop
, 0)) == PLUS
9727 && XEXP (XEXP (varop
, 0), 1) == constm1_rtx
9728 && (STORE_FLAG_VALUE
== 1 || STORE_FLAG_VALUE
== -1)
9729 && (code
== LSHIFTRT
|| code
== ASHIFTRT
)
9730 && count
== (unsigned int)
9731 (GET_MODE_BITSIZE (GET_MODE (varop
)) - 1)
9732 && rtx_equal_p (XEXP (XEXP (varop
, 0), 0), XEXP (varop
, 1)))
9735 varop
= gen_rtx_LE (GET_MODE (varop
), XEXP (varop
, 1),
9738 if (STORE_FLAG_VALUE
== 1 ? code
== ASHIFTRT
: code
== LSHIFTRT
)
9739 varop
= gen_rtx_NEG (GET_MODE (varop
), varop
);
9744 /* If we have (shift (logical)), move the logical to the outside
9745 to allow it to possibly combine with another logical and the
9746 shift to combine with another shift. This also canonicalizes to
9747 what a ZERO_EXTRACT looks like. Also, some machines have
9748 (and (shift)) insns. */
9750 if (GET_CODE (XEXP (varop
, 1)) == CONST_INT
9751 && (new = simplify_binary_operation (code
, result_mode
,
9753 GEN_INT (count
))) != 0
9754 && GET_CODE (new) == CONST_INT
9755 && merge_outer_ops (&outer_op
, &outer_const
, GET_CODE (varop
),
9756 INTVAL (new), result_mode
, &complement_p
))
9758 varop
= XEXP (varop
, 0);
9762 /* If we can't do that, try to simplify the shift in each arm of the
9763 logical expression, make a new logical expression, and apply
9764 the inverse distributive law. */
9766 rtx lhs
= simplify_shift_const (NULL_RTX
, code
, shift_mode
,
9767 XEXP (varop
, 0), count
);
9768 rtx rhs
= simplify_shift_const (NULL_RTX
, code
, shift_mode
,
9769 XEXP (varop
, 1), count
);
9771 varop
= gen_binary (GET_CODE (varop
), shift_mode
, lhs
, rhs
);
9772 varop
= apply_distributive_law (varop
);
9779 /* convert (lshiftrt (eq FOO 0) C) to (xor FOO 1) if STORE_FLAG_VALUE
9780 says that the sign bit can be tested, FOO has mode MODE, C is
9781 GET_MODE_BITSIZE (MODE) - 1, and FOO has only its low-order bit
9782 that may be nonzero. */
9783 if (code
== LSHIFTRT
9784 && XEXP (varop
, 1) == const0_rtx
9785 && GET_MODE (XEXP (varop
, 0)) == result_mode
9786 && count
== (unsigned int) (GET_MODE_BITSIZE (result_mode
) - 1)
9787 && GET_MODE_BITSIZE (result_mode
) <= HOST_BITS_PER_WIDE_INT
9788 && ((STORE_FLAG_VALUE
9789 & ((HOST_WIDE_INT
) 1
9790 < (GET_MODE_BITSIZE (result_mode
) - 1))))
9791 && nonzero_bits (XEXP (varop
, 0), result_mode
) == 1
9792 && merge_outer_ops (&outer_op
, &outer_const
, XOR
,
9793 (HOST_WIDE_INT
) 1, result_mode
,
9796 varop
= XEXP (varop
, 0);
9803 /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less
9804 than the number of bits in the mode is equivalent to A. */
9805 if (code
== LSHIFTRT
9806 && count
== (unsigned int) (GET_MODE_BITSIZE (result_mode
) - 1)
9807 && nonzero_bits (XEXP (varop
, 0), result_mode
) == 1)
9809 varop
= XEXP (varop
, 0);
9814 /* NEG commutes with ASHIFT since it is multiplication. Move the
9815 NEG outside to allow shifts to combine. */
9817 && merge_outer_ops (&outer_op
, &outer_const
, NEG
,
9818 (HOST_WIDE_INT
) 0, result_mode
,
9821 varop
= XEXP (varop
, 0);
9827 /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C
9828 is one less than the number of bits in the mode is
9829 equivalent to (xor A 1). */
9830 if (code
== LSHIFTRT
9831 && count
== (unsigned int) (GET_MODE_BITSIZE (result_mode
) - 1)
9832 && XEXP (varop
, 1) == constm1_rtx
9833 && nonzero_bits (XEXP (varop
, 0), result_mode
) == 1
9834 && merge_outer_ops (&outer_op
, &outer_const
, XOR
,
9835 (HOST_WIDE_INT
) 1, result_mode
,
9839 varop
= XEXP (varop
, 0);
9843 /* If we have (xshiftrt (plus FOO BAR) C), and the only bits
9844 that might be nonzero in BAR are those being shifted out and those
9845 bits are known zero in FOO, we can replace the PLUS with FOO.
9846 Similarly in the other operand order. This code occurs when
9847 we are computing the size of a variable-size array. */
9849 if ((code
== ASHIFTRT
|| code
== LSHIFTRT
)
9850 && count
< HOST_BITS_PER_WIDE_INT
9851 && nonzero_bits (XEXP (varop
, 1), result_mode
) >> count
== 0
9852 && (nonzero_bits (XEXP (varop
, 1), result_mode
)
9853 & nonzero_bits (XEXP (varop
, 0), result_mode
)) == 0)
9855 varop
= XEXP (varop
, 0);
9858 else if ((code
== ASHIFTRT
|| code
== LSHIFTRT
)
9859 && count
< HOST_BITS_PER_WIDE_INT
9860 && GET_MODE_BITSIZE (result_mode
) <= HOST_BITS_PER_WIDE_INT
9861 && 0 == (nonzero_bits (XEXP (varop
, 0), result_mode
)
9863 && 0 == (nonzero_bits (XEXP (varop
, 0), result_mode
)
9864 & nonzero_bits (XEXP (varop
, 1),
9867 varop
= XEXP (varop
, 1);
9871 /* (ashift (plus foo C) N) is (plus (ashift foo N) C'). */
9873 && GET_CODE (XEXP (varop
, 1)) == CONST_INT
9874 && (new = simplify_binary_operation (ASHIFT
, result_mode
,
9876 GEN_INT (count
))) != 0
9877 && GET_CODE (new) == CONST_INT
9878 && merge_outer_ops (&outer_op
, &outer_const
, PLUS
,
9879 INTVAL (new), result_mode
, &complement_p
))
9881 varop
= XEXP (varop
, 0);
9887 /* If we have (xshiftrt (minus (ashiftrt X C)) X) C)
9888 with C the size of VAROP - 1 and the shift is logical if
9889 STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1,
9890 we have a (gt X 0) operation. If the shift is arithmetic with
9891 STORE_FLAG_VALUE of 1 or logical with STORE_FLAG_VALUE == -1,
9892 we have a (neg (gt X 0)) operation. */
9894 if ((STORE_FLAG_VALUE
== 1 || STORE_FLAG_VALUE
== -1)
9895 && GET_CODE (XEXP (varop
, 0)) == ASHIFTRT
9896 && count
== (unsigned int)
9897 (GET_MODE_BITSIZE (GET_MODE (varop
)) - 1)
9898 && (code
== LSHIFTRT
|| code
== ASHIFTRT
)
9899 && GET_CODE (XEXP (XEXP (varop
, 0), 1)) == CONST_INT
9900 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (XEXP (varop
, 0), 1))
9902 && rtx_equal_p (XEXP (XEXP (varop
, 0), 0), XEXP (varop
, 1)))
9905 varop
= gen_rtx_GT (GET_MODE (varop
), XEXP (varop
, 1),
9908 if (STORE_FLAG_VALUE
== 1 ? code
== ASHIFTRT
: code
== LSHIFTRT
)
9909 varop
= gen_rtx_NEG (GET_MODE (varop
), varop
);
9916 /* Change (lshiftrt (truncate (lshiftrt))) to (truncate (lshiftrt))
9917 if the truncate does not affect the value. */
9918 if (code
== LSHIFTRT
9919 && GET_CODE (XEXP (varop
, 0)) == LSHIFTRT
9920 && GET_CODE (XEXP (XEXP (varop
, 0), 1)) == CONST_INT
9921 && (INTVAL (XEXP (XEXP (varop
, 0), 1))
9922 >= (GET_MODE_BITSIZE (GET_MODE (XEXP (varop
, 0)))
9923 - GET_MODE_BITSIZE (GET_MODE (varop
)))))
9925 rtx varop_inner
= XEXP (varop
, 0);
9928 = gen_rtx_LSHIFTRT (GET_MODE (varop_inner
),
9929 XEXP (varop_inner
, 0),
9931 (count
+ INTVAL (XEXP (varop_inner
, 1))));
9932 varop
= gen_rtx_TRUNCATE (GET_MODE (varop
), varop_inner
);
9945 /* We need to determine what mode to do the shift in. If the shift is
9946 a right shift or ROTATE, we must always do it in the mode it was
9947 originally done in. Otherwise, we can do it in MODE, the widest mode
9948 encountered. The code we care about is that of the shift that will
9949 actually be done, not the shift that was originally requested. */
9951 = (code
== ASHIFTRT
|| code
== LSHIFTRT
|| code
== ROTATE
9952 ? result_mode
: mode
);
9954 /* We have now finished analyzing the shift. The result should be
9955 a shift of type CODE with SHIFT_MODE shifting VAROP COUNT places. If
9956 OUTER_OP is non-NIL, it is an operation that needs to be applied
9957 to the result of the shift. OUTER_CONST is the relevant constant,
9958 but we must turn off all bits turned off in the shift.
9960 If we were passed a value for X, see if we can use any pieces of
9961 it. If not, make new rtx. */
9963 if (x
&& GET_RTX_CLASS (GET_CODE (x
)) == '2'
9964 && GET_CODE (XEXP (x
, 1)) == CONST_INT
9965 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (x
, 1)) == count
)
9966 const_rtx
= XEXP (x
, 1);
9968 const_rtx
= GEN_INT (count
);
9970 if (x
&& GET_CODE (XEXP (x
, 0)) == SUBREG
9971 && GET_MODE (XEXP (x
, 0)) == shift_mode
9972 && SUBREG_REG (XEXP (x
, 0)) == varop
)
9973 varop
= XEXP (x
, 0);
9974 else if (GET_MODE (varop
) != shift_mode
)
9975 varop
= gen_lowpart_for_combine (shift_mode
, varop
);
9977 /* If we can't make the SUBREG, try to return what we were given. */
9978 if (GET_CODE (varop
) == CLOBBER
)
9979 return x
? x
: varop
;
9981 new = simplify_binary_operation (code
, shift_mode
, varop
, const_rtx
);
9985 x
= gen_rtx_fmt_ee (code
, shift_mode
, varop
, const_rtx
);
9987 /* If we have an outer operation and we just made a shift, it is
9988 possible that we could have simplified the shift were it not
9989 for the outer operation. So try to do the simplification
9992 if (outer_op
!= NIL
&& GET_CODE (x
) == code
9993 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
9994 x
= simplify_shift_const (x
, code
, shift_mode
, XEXP (x
, 0),
9995 INTVAL (XEXP (x
, 1)));
9997 /* If we were doing an LSHIFTRT in a wider mode than it was originally,
9998 turn off all the bits that the shift would have turned off. */
9999 if (orig_code
== LSHIFTRT
&& result_mode
!= shift_mode
)
10000 x
= simplify_and_const_int (NULL_RTX
, shift_mode
, x
,
10001 GET_MODE_MASK (result_mode
) >> orig_count
);
10003 /* Do the remainder of the processing in RESULT_MODE. */
10004 x
= gen_lowpart_for_combine (result_mode
, x
);
10006 /* If COMPLEMENT_P is set, we have to complement X before doing the outer
10009 x
= simplify_gen_unary (NOT
, result_mode
, x
, result_mode
);
10011 if (outer_op
!= NIL
)
10013 if (GET_MODE_BITSIZE (result_mode
) < HOST_BITS_PER_WIDE_INT
)
10014 outer_const
= trunc_int_for_mode (outer_const
, result_mode
);
10016 if (outer_op
== AND
)
10017 x
= simplify_and_const_int (NULL_RTX
, result_mode
, x
, outer_const
);
10018 else if (outer_op
== SET
)
10019 /* This means that we have determined that the result is
10020 equivalent to a constant. This should be rare. */
10021 x
= GEN_INT (outer_const
);
10022 else if (GET_RTX_CLASS (outer_op
) == '1')
10023 x
= simplify_gen_unary (outer_op
, result_mode
, x
, result_mode
);
10025 x
= gen_binary (outer_op
, result_mode
, x
, GEN_INT (outer_const
));
10031 /* Like recog, but we receive the address of a pointer to a new pattern.
10032 We try to match the rtx that the pointer points to.
10033 If that fails, we may try to modify or replace the pattern,
10034 storing the replacement into the same pointer object.
10036 Modifications include deletion or addition of CLOBBERs.
10038 PNOTES is a pointer to a location where any REG_UNUSED notes added for
10039 the CLOBBERs are placed.
10041 The value is the final insn code from the pattern ultimately matched,
10045 recog_for_combine (pnewpat
, insn
, pnotes
)
10050 rtx pat
= *pnewpat
;
10051 int insn_code_number
;
10052 int num_clobbers_to_add
= 0;
10057 /* If PAT is a PARALLEL, check to see if it contains the CLOBBER
10058 we use to indicate that something didn't match. If we find such a
10059 thing, force rejection. */
10060 if (GET_CODE (pat
) == PARALLEL
)
10061 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; i
--)
10062 if (GET_CODE (XVECEXP (pat
, 0, i
)) == CLOBBER
10063 && XEXP (XVECEXP (pat
, 0, i
), 0) == const0_rtx
)
10066 /* *pnewpat does not have to be actual PATTERN (insn), so make a dummy
10067 instruction for pattern recognition. */
10068 dummy_insn
= shallow_copy_rtx (insn
);
10069 PATTERN (dummy_insn
) = pat
;
10070 REG_NOTES (dummy_insn
) = 0;
10072 insn_code_number
= recog (pat
, dummy_insn
, &num_clobbers_to_add
);
10074 /* If it isn't, there is the possibility that we previously had an insn
10075 that clobbered some register as a side effect, but the combined
10076 insn doesn't need to do that. So try once more without the clobbers
10077 unless this represents an ASM insn. */
10079 if (insn_code_number
< 0 && ! check_asm_operands (pat
)
10080 && GET_CODE (pat
) == PARALLEL
)
10084 for (pos
= 0, i
= 0; i
< XVECLEN (pat
, 0); i
++)
10085 if (GET_CODE (XVECEXP (pat
, 0, i
)) != CLOBBER
)
10088 SUBST (XVECEXP (pat
, 0, pos
), XVECEXP (pat
, 0, i
));
10092 SUBST_INT (XVECLEN (pat
, 0), pos
);
10095 pat
= XVECEXP (pat
, 0, 0);
10097 PATTERN (dummy_insn
) = pat
;
10098 insn_code_number
= recog (pat
, dummy_insn
, &num_clobbers_to_add
);
10101 /* Recognize all noop sets, these will be killed by followup pass. */
10102 if (insn_code_number
< 0 && GET_CODE (pat
) == SET
&& set_noop_p (pat
))
10103 insn_code_number
= NOOP_MOVE_INSN_CODE
, num_clobbers_to_add
= 0;
10105 /* If we had any clobbers to add, make a new pattern than contains
10106 them. Then check to make sure that all of them are dead. */
10107 if (num_clobbers_to_add
)
10109 rtx newpat
= gen_rtx_PARALLEL (VOIDmode
,
10110 rtvec_alloc (GET_CODE (pat
) == PARALLEL
10111 ? (XVECLEN (pat
, 0)
10112 + num_clobbers_to_add
)
10113 : num_clobbers_to_add
+ 1));
10115 if (GET_CODE (pat
) == PARALLEL
)
10116 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
10117 XVECEXP (newpat
, 0, i
) = XVECEXP (pat
, 0, i
);
10119 XVECEXP (newpat
, 0, 0) = pat
;
10121 add_clobbers (newpat
, insn_code_number
);
10123 for (i
= XVECLEN (newpat
, 0) - num_clobbers_to_add
;
10124 i
< XVECLEN (newpat
, 0); i
++)
10126 if (GET_CODE (XEXP (XVECEXP (newpat
, 0, i
), 0)) == REG
10127 && ! reg_dead_at_p (XEXP (XVECEXP (newpat
, 0, i
), 0), insn
))
10129 notes
= gen_rtx_EXPR_LIST (REG_UNUSED
,
10130 XEXP (XVECEXP (newpat
, 0, i
), 0), notes
);
10138 return insn_code_number
;
10141 /* Like gen_lowpart but for use by combine. In combine it is not possible
10142 to create any new pseudoregs. However, it is safe to create
10143 invalid memory addresses, because combine will try to recognize
10144 them and all they will do is make the combine attempt fail.
10146 If for some reason this cannot do its job, an rtx
10147 (clobber (const_int 0)) is returned.
10148 An insn containing that will not be recognized. */
10153 gen_lowpart_for_combine (mode
, x
)
10154 enum machine_mode mode
;
10159 if (GET_MODE (x
) == mode
)
10162 /* Return identity if this is a CONST or symbolic
10165 && (GET_CODE (x
) == CONST
10166 || GET_CODE (x
) == SYMBOL_REF
10167 || GET_CODE (x
) == LABEL_REF
))
10170 /* We can only support MODE being wider than a word if X is a
10171 constant integer or has a mode the same size. */
10173 if (GET_MODE_SIZE (mode
) > UNITS_PER_WORD
10174 && ! ((GET_MODE (x
) == VOIDmode
10175 && (GET_CODE (x
) == CONST_INT
10176 || GET_CODE (x
) == CONST_DOUBLE
))
10177 || GET_MODE_SIZE (GET_MODE (x
)) == GET_MODE_SIZE (mode
)))
10178 return gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
10180 /* X might be a paradoxical (subreg (mem)). In that case, gen_lowpart
10181 won't know what to do. So we will strip off the SUBREG here and
10182 process normally. */
10183 if (GET_CODE (x
) == SUBREG
&& GET_CODE (SUBREG_REG (x
)) == MEM
)
10185 x
= SUBREG_REG (x
);
10186 if (GET_MODE (x
) == mode
)
10190 result
= gen_lowpart_common (mode
, x
);
10191 #ifdef CANNOT_CHANGE_MODE_CLASS
10193 && GET_CODE (result
) == SUBREG
10194 && GET_CODE (SUBREG_REG (result
)) == REG
10195 && REGNO (SUBREG_REG (result
)) >= FIRST_PSEUDO_REGISTER
)
10196 bitmap_set_bit (&subregs_of_mode
, REGNO (SUBREG_REG (result
))
10198 + GET_MODE (result
));
10204 if (GET_CODE (x
) == MEM
)
10208 /* Refuse to work on a volatile memory ref or one with a mode-dependent
10210 if (MEM_VOLATILE_P (x
) || mode_dependent_address_p (XEXP (x
, 0)))
10211 return gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
10213 /* If we want to refer to something bigger than the original memref,
10214 generate a perverse subreg instead. That will force a reload
10215 of the original memref X. */
10216 if (GET_MODE_SIZE (GET_MODE (x
)) < GET_MODE_SIZE (mode
))
10217 return gen_rtx_SUBREG (mode
, x
, 0);
10219 if (WORDS_BIG_ENDIAN
)
10220 offset
= (MAX (GET_MODE_SIZE (GET_MODE (x
)), UNITS_PER_WORD
)
10221 - MAX (GET_MODE_SIZE (mode
), UNITS_PER_WORD
));
10223 if (BYTES_BIG_ENDIAN
)
10225 /* Adjust the address so that the address-after-the-data is
10227 offset
-= (MIN (UNITS_PER_WORD
, GET_MODE_SIZE (mode
))
10228 - MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (x
))));
10231 return adjust_address_nv (x
, mode
, offset
);
10234 /* If X is a comparison operator, rewrite it in a new mode. This
10235 probably won't match, but may allow further simplifications. */
10236 else if (GET_RTX_CLASS (GET_CODE (x
)) == '<')
10237 return gen_rtx_fmt_ee (GET_CODE (x
), mode
, XEXP (x
, 0), XEXP (x
, 1));
10239 /* If we couldn't simplify X any other way, just enclose it in a
10240 SUBREG. Normally, this SUBREG won't match, but some patterns may
10241 include an explicit SUBREG or we may simplify it further in combine. */
10246 enum machine_mode sub_mode
= GET_MODE (x
);
10248 offset
= subreg_lowpart_offset (mode
, sub_mode
);
10249 if (sub_mode
== VOIDmode
)
10251 sub_mode
= int_mode_for_mode (mode
);
10252 x
= gen_lowpart_common (sub_mode
, x
);
10254 return gen_rtx_CLOBBER (VOIDmode
, const0_rtx
);
10256 res
= simplify_gen_subreg (mode
, x
, sub_mode
, offset
);
10259 return gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
10263 /* These routines make binary and unary operations by first seeing if they
10264 fold; if not, a new expression is allocated. */
10267 gen_binary (code
, mode
, op0
, op1
)
10268 enum rtx_code code
;
10269 enum machine_mode mode
;
10275 if (GET_RTX_CLASS (code
) == 'c'
10276 && swap_commutative_operands_p (op0
, op1
))
10277 tem
= op0
, op0
= op1
, op1
= tem
;
10279 if (GET_RTX_CLASS (code
) == '<')
10281 enum machine_mode op_mode
= GET_MODE (op0
);
10283 /* Strip the COMPARE from (REL_OP (compare X Y) 0) to get
10284 just (REL_OP X Y). */
10285 if (GET_CODE (op0
) == COMPARE
&& op1
== const0_rtx
)
10287 op1
= XEXP (op0
, 1);
10288 op0
= XEXP (op0
, 0);
10289 op_mode
= GET_MODE (op0
);
10292 if (op_mode
== VOIDmode
)
10293 op_mode
= GET_MODE (op1
);
10294 result
= simplify_relational_operation (code
, op_mode
, op0
, op1
);
10297 result
= simplify_binary_operation (code
, mode
, op0
, op1
);
10302 /* Put complex operands first and constants second. */
10303 if (GET_RTX_CLASS (code
) == 'c'
10304 && swap_commutative_operands_p (op0
, op1
))
10305 return gen_rtx_fmt_ee (code
, mode
, op1
, op0
);
10307 /* If we are turning off bits already known off in OP0, we need not do
10309 else if (code
== AND
&& GET_CODE (op1
) == CONST_INT
10310 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
10311 && (nonzero_bits (op0
, mode
) & ~INTVAL (op1
)) == 0)
10314 return gen_rtx_fmt_ee (code
, mode
, op0
, op1
);
10317 /* Simplify a comparison between *POP0 and *POP1 where CODE is the
10318 comparison code that will be tested.
10320 The result is a possibly different comparison code to use. *POP0 and
10321 *POP1 may be updated.
10323 It is possible that we might detect that a comparison is either always
10324 true or always false. However, we do not perform general constant
10325 folding in combine, so this knowledge isn't useful. Such tautologies
10326 should have been detected earlier. Hence we ignore all such cases. */
10328 static enum rtx_code
10329 simplify_comparison (code
, pop0
, pop1
)
10330 enum rtx_code code
;
10338 enum machine_mode mode
, tmode
;
10340 /* Try a few ways of applying the same transformation to both operands. */
10343 #ifndef WORD_REGISTER_OPERATIONS
10344 /* The test below this one won't handle SIGN_EXTENDs on these machines,
10345 so check specially. */
10346 if (code
!= GTU
&& code
!= GEU
&& code
!= LTU
&& code
!= LEU
10347 && GET_CODE (op0
) == ASHIFTRT
&& GET_CODE (op1
) == ASHIFTRT
10348 && GET_CODE (XEXP (op0
, 0)) == ASHIFT
10349 && GET_CODE (XEXP (op1
, 0)) == ASHIFT
10350 && GET_CODE (XEXP (XEXP (op0
, 0), 0)) == SUBREG
10351 && GET_CODE (XEXP (XEXP (op1
, 0), 0)) == SUBREG
10352 && (GET_MODE (SUBREG_REG (XEXP (XEXP (op0
, 0), 0)))
10353 == GET_MODE (SUBREG_REG (XEXP (XEXP (op1
, 0), 0))))
10354 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
10355 && GET_CODE (XEXP (op1
, 1)) == CONST_INT
10356 && GET_CODE (XEXP (XEXP (op0
, 0), 1)) == CONST_INT
10357 && GET_CODE (XEXP (XEXP (op1
, 0), 1)) == CONST_INT
10358 && INTVAL (XEXP (op0
, 1)) == INTVAL (XEXP (op1
, 1))
10359 && INTVAL (XEXP (op0
, 1)) == INTVAL (XEXP (XEXP (op0
, 0), 1))
10360 && INTVAL (XEXP (op0
, 1)) == INTVAL (XEXP (XEXP (op1
, 0), 1))
10361 && (INTVAL (XEXP (op0
, 1))
10362 == (GET_MODE_BITSIZE (GET_MODE (op0
))
10363 - (GET_MODE_BITSIZE
10364 (GET_MODE (SUBREG_REG (XEXP (XEXP (op0
, 0), 0))))))))
10366 op0
= SUBREG_REG (XEXP (XEXP (op0
, 0), 0));
10367 op1
= SUBREG_REG (XEXP (XEXP (op1
, 0), 0));
10371 /* If both operands are the same constant shift, see if we can ignore the
10372 shift. We can if the shift is a rotate or if the bits shifted out of
10373 this shift are known to be zero for both inputs and if the type of
10374 comparison is compatible with the shift. */
10375 if (GET_CODE (op0
) == GET_CODE (op1
)
10376 && GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
10377 && ((GET_CODE (op0
) == ROTATE
&& (code
== NE
|| code
== EQ
))
10378 || ((GET_CODE (op0
) == LSHIFTRT
|| GET_CODE (op0
) == ASHIFT
)
10379 && (code
!= GT
&& code
!= LT
&& code
!= GE
&& code
!= LE
))
10380 || (GET_CODE (op0
) == ASHIFTRT
10381 && (code
!= GTU
&& code
!= LTU
10382 && code
!= GEU
&& code
!= LEU
)))
10383 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
10384 && INTVAL (XEXP (op0
, 1)) >= 0
10385 && INTVAL (XEXP (op0
, 1)) < HOST_BITS_PER_WIDE_INT
10386 && XEXP (op0
, 1) == XEXP (op1
, 1))
10388 enum machine_mode mode
= GET_MODE (op0
);
10389 unsigned HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
10390 int shift_count
= INTVAL (XEXP (op0
, 1));
10392 if (GET_CODE (op0
) == LSHIFTRT
|| GET_CODE (op0
) == ASHIFTRT
)
10393 mask
&= (mask
>> shift_count
) << shift_count
;
10394 else if (GET_CODE (op0
) == ASHIFT
)
10395 mask
= (mask
& (mask
<< shift_count
)) >> shift_count
;
10397 if ((nonzero_bits (XEXP (op0
, 0), mode
) & ~mask
) == 0
10398 && (nonzero_bits (XEXP (op1
, 0), mode
) & ~mask
) == 0)
10399 op0
= XEXP (op0
, 0), op1
= XEXP (op1
, 0);
10404 /* If both operands are AND's of a paradoxical SUBREG by constant, the
10405 SUBREGs are of the same mode, and, in both cases, the AND would
10406 be redundant if the comparison was done in the narrower mode,
10407 do the comparison in the narrower mode (e.g., we are AND'ing with 1
10408 and the operand's possibly nonzero bits are 0xffffff01; in that case
10409 if we only care about QImode, we don't need the AND). This case
10410 occurs if the output mode of an scc insn is not SImode and
10411 STORE_FLAG_VALUE == 1 (e.g., the 386).
10413 Similarly, check for a case where the AND's are ZERO_EXTEND
10414 operations from some narrower mode even though a SUBREG is not
10417 else if (GET_CODE (op0
) == AND
&& GET_CODE (op1
) == AND
10418 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
10419 && GET_CODE (XEXP (op1
, 1)) == CONST_INT
)
10421 rtx inner_op0
= XEXP (op0
, 0);
10422 rtx inner_op1
= XEXP (op1
, 0);
10423 HOST_WIDE_INT c0
= INTVAL (XEXP (op0
, 1));
10424 HOST_WIDE_INT c1
= INTVAL (XEXP (op1
, 1));
10427 if (GET_CODE (inner_op0
) == SUBREG
&& GET_CODE (inner_op1
) == SUBREG
10428 && (GET_MODE_SIZE (GET_MODE (inner_op0
))
10429 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner_op0
))))
10430 && (GET_MODE (SUBREG_REG (inner_op0
))
10431 == GET_MODE (SUBREG_REG (inner_op1
)))
10432 && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (inner_op0
)))
10433 <= HOST_BITS_PER_WIDE_INT
)
10434 && (0 == ((~c0
) & nonzero_bits (SUBREG_REG (inner_op0
),
10435 GET_MODE (SUBREG_REG (inner_op0
)))))
10436 && (0 == ((~c1
) & nonzero_bits (SUBREG_REG (inner_op1
),
10437 GET_MODE (SUBREG_REG (inner_op1
))))))
10439 op0
= SUBREG_REG (inner_op0
);
10440 op1
= SUBREG_REG (inner_op1
);
10442 /* The resulting comparison is always unsigned since we masked
10443 off the original sign bit. */
10444 code
= unsigned_condition (code
);
10450 for (tmode
= GET_CLASS_NARROWEST_MODE
10451 (GET_MODE_CLASS (GET_MODE (op0
)));
10452 tmode
!= GET_MODE (op0
); tmode
= GET_MODE_WIDER_MODE (tmode
))
10453 if ((unsigned HOST_WIDE_INT
) c0
== GET_MODE_MASK (tmode
))
10455 op0
= gen_lowpart_for_combine (tmode
, inner_op0
);
10456 op1
= gen_lowpart_for_combine (tmode
, inner_op1
);
10457 code
= unsigned_condition (code
);
10466 /* If both operands are NOT, we can strip off the outer operation
10467 and adjust the comparison code for swapped operands; similarly for
10468 NEG, except that this must be an equality comparison. */
10469 else if ((GET_CODE (op0
) == NOT
&& GET_CODE (op1
) == NOT
)
10470 || (GET_CODE (op0
) == NEG
&& GET_CODE (op1
) == NEG
10471 && (code
== EQ
|| code
== NE
)))
10472 op0
= XEXP (op0
, 0), op1
= XEXP (op1
, 0), code
= swap_condition (code
);
10478 /* If the first operand is a constant, swap the operands and adjust the
10479 comparison code appropriately, but don't do this if the second operand
10480 is already a constant integer. */
10481 if (swap_commutative_operands_p (op0
, op1
))
10483 tem
= op0
, op0
= op1
, op1
= tem
;
10484 code
= swap_condition (code
);
10487 /* We now enter a loop during which we will try to simplify the comparison.
10488 For the most part, we only are concerned with comparisons with zero,
10489 but some things may really be comparisons with zero but not start
10490 out looking that way. */
10492 while (GET_CODE (op1
) == CONST_INT
)
10494 enum machine_mode mode
= GET_MODE (op0
);
10495 unsigned int mode_width
= GET_MODE_BITSIZE (mode
);
10496 unsigned HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
10497 int equality_comparison_p
;
10498 int sign_bit_comparison_p
;
10499 int unsigned_comparison_p
;
10500 HOST_WIDE_INT const_op
;
10502 /* We only want to handle integral modes. This catches VOIDmode,
10503 CCmode, and the floating-point modes. An exception is that we
10504 can handle VOIDmode if OP0 is a COMPARE or a comparison
10507 if (GET_MODE_CLASS (mode
) != MODE_INT
10508 && ! (mode
== VOIDmode
10509 && (GET_CODE (op0
) == COMPARE
10510 || GET_RTX_CLASS (GET_CODE (op0
)) == '<')))
10513 /* Get the constant we are comparing against and turn off all bits
10514 not on in our mode. */
10515 const_op
= INTVAL (op1
);
10516 if (mode
!= VOIDmode
)
10517 const_op
= trunc_int_for_mode (const_op
, mode
);
10518 op1
= GEN_INT (const_op
);
10520 /* If we are comparing against a constant power of two and the value
10521 being compared can only have that single bit nonzero (e.g., it was
10522 `and'ed with that bit), we can replace this with a comparison
10525 && (code
== EQ
|| code
== NE
|| code
== GE
|| code
== GEU
10526 || code
== LT
|| code
== LTU
)
10527 && mode_width
<= HOST_BITS_PER_WIDE_INT
10528 && exact_log2 (const_op
) >= 0
10529 && nonzero_bits (op0
, mode
) == (unsigned HOST_WIDE_INT
) const_op
)
10531 code
= (code
== EQ
|| code
== GE
|| code
== GEU
? NE
: EQ
);
10532 op1
= const0_rtx
, const_op
= 0;
10535 /* Similarly, if we are comparing a value known to be either -1 or
10536 0 with -1, change it to the opposite comparison against zero. */
10539 && (code
== EQ
|| code
== NE
|| code
== GT
|| code
== LE
10540 || code
== GEU
|| code
== LTU
)
10541 && num_sign_bit_copies (op0
, mode
) == mode_width
)
10543 code
= (code
== EQ
|| code
== LE
|| code
== GEU
? NE
: EQ
);
10544 op1
= const0_rtx
, const_op
= 0;
10547 /* Do some canonicalizations based on the comparison code. We prefer
10548 comparisons against zero and then prefer equality comparisons.
10549 If we can reduce the size of a constant, we will do that too. */
10554 /* < C is equivalent to <= (C - 1) */
10558 op1
= GEN_INT (const_op
);
10560 /* ... fall through to LE case below. */
10566 /* <= C is equivalent to < (C + 1); we do this for C < 0 */
10570 op1
= GEN_INT (const_op
);
10574 /* If we are doing a <= 0 comparison on a value known to have
10575 a zero sign bit, we can replace this with == 0. */
10576 else if (const_op
== 0
10577 && mode_width
<= HOST_BITS_PER_WIDE_INT
10578 && (nonzero_bits (op0
, mode
)
10579 & ((HOST_WIDE_INT
) 1 << (mode_width
- 1))) == 0)
10584 /* >= C is equivalent to > (C - 1). */
10588 op1
= GEN_INT (const_op
);
10590 /* ... fall through to GT below. */
10596 /* > C is equivalent to >= (C + 1); we do this for C < 0. */
10600 op1
= GEN_INT (const_op
);
10604 /* If we are doing a > 0 comparison on a value known to have
10605 a zero sign bit, we can replace this with != 0. */
10606 else if (const_op
== 0
10607 && mode_width
<= HOST_BITS_PER_WIDE_INT
10608 && (nonzero_bits (op0
, mode
)
10609 & ((HOST_WIDE_INT
) 1 << (mode_width
- 1))) == 0)
10614 /* < C is equivalent to <= (C - 1). */
10618 op1
= GEN_INT (const_op
);
10620 /* ... fall through ... */
10623 /* (unsigned) < 0x80000000 is equivalent to >= 0. */
10624 else if ((mode_width
<= HOST_BITS_PER_WIDE_INT
)
10625 && (const_op
== (HOST_WIDE_INT
) 1 << (mode_width
- 1)))
10627 const_op
= 0, op1
= const0_rtx
;
10635 /* unsigned <= 0 is equivalent to == 0 */
10639 /* (unsigned) <= 0x7fffffff is equivalent to >= 0. */
10640 else if ((mode_width
<= HOST_BITS_PER_WIDE_INT
)
10641 && (const_op
== ((HOST_WIDE_INT
) 1 << (mode_width
- 1)) - 1))
10643 const_op
= 0, op1
= const0_rtx
;
10649 /* >= C is equivalent to < (C - 1). */
10653 op1
= GEN_INT (const_op
);
10655 /* ... fall through ... */
10658 /* (unsigned) >= 0x80000000 is equivalent to < 0. */
10659 else if ((mode_width
<= HOST_BITS_PER_WIDE_INT
)
10660 && (const_op
== (HOST_WIDE_INT
) 1 << (mode_width
- 1)))
10662 const_op
= 0, op1
= const0_rtx
;
10670 /* unsigned > 0 is equivalent to != 0 */
10674 /* (unsigned) > 0x7fffffff is equivalent to < 0. */
10675 else if ((mode_width
<= HOST_BITS_PER_WIDE_INT
)
10676 && (const_op
== ((HOST_WIDE_INT
) 1 << (mode_width
- 1)) - 1))
10678 const_op
= 0, op1
= const0_rtx
;
10687 /* Compute some predicates to simplify code below. */
10689 equality_comparison_p
= (code
== EQ
|| code
== NE
);
10690 sign_bit_comparison_p
= ((code
== LT
|| code
== GE
) && const_op
== 0);
10691 unsigned_comparison_p
= (code
== LTU
|| code
== LEU
|| code
== GTU
10694 /* If this is a sign bit comparison and we can do arithmetic in
10695 MODE, say that we will only be needing the sign bit of OP0. */
10696 if (sign_bit_comparison_p
10697 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
10698 op0
= force_to_mode (op0
, mode
,
10700 << (GET_MODE_BITSIZE (mode
) - 1)),
10703 /* Now try cases based on the opcode of OP0. If none of the cases
10704 does a "continue", we exit this loop immediately after the
10707 switch (GET_CODE (op0
))
10710 /* If we are extracting a single bit from a variable position in
10711 a constant that has only a single bit set and are comparing it
10712 with zero, we can convert this into an equality comparison
10713 between the position and the location of the single bit. */
10715 if (GET_CODE (XEXP (op0
, 0)) == CONST_INT
10716 && XEXP (op0
, 1) == const1_rtx
10717 && equality_comparison_p
&& const_op
== 0
10718 && (i
= exact_log2 (INTVAL (XEXP (op0
, 0)))) >= 0)
10720 if (BITS_BIG_ENDIAN
)
10722 enum machine_mode new_mode
10723 = mode_for_extraction (EP_extzv
, 1);
10724 if (new_mode
== MAX_MACHINE_MODE
)
10725 i
= BITS_PER_WORD
- 1 - i
;
10729 i
= (GET_MODE_BITSIZE (mode
) - 1 - i
);
10733 op0
= XEXP (op0
, 2);
10737 /* Result is nonzero iff shift count is equal to I. */
10738 code
= reverse_condition (code
);
10742 /* ... fall through ... */
10745 tem
= expand_compound_operation (op0
);
10754 /* If testing for equality, we can take the NOT of the constant. */
10755 if (equality_comparison_p
10756 && (tem
= simplify_unary_operation (NOT
, mode
, op1
, mode
)) != 0)
10758 op0
= XEXP (op0
, 0);
10763 /* If just looking at the sign bit, reverse the sense of the
10765 if (sign_bit_comparison_p
)
10767 op0
= XEXP (op0
, 0);
10768 code
= (code
== GE
? LT
: GE
);
10774 /* If testing for equality, we can take the NEG of the constant. */
10775 if (equality_comparison_p
10776 && (tem
= simplify_unary_operation (NEG
, mode
, op1
, mode
)) != 0)
10778 op0
= XEXP (op0
, 0);
10783 /* The remaining cases only apply to comparisons with zero. */
10787 /* When X is ABS or is known positive,
10788 (neg X) is < 0 if and only if X != 0. */
10790 if (sign_bit_comparison_p
10791 && (GET_CODE (XEXP (op0
, 0)) == ABS
10792 || (mode_width
<= HOST_BITS_PER_WIDE_INT
10793 && (nonzero_bits (XEXP (op0
, 0), mode
)
10794 & ((HOST_WIDE_INT
) 1 << (mode_width
- 1))) == 0)))
10796 op0
= XEXP (op0
, 0);
10797 code
= (code
== LT
? NE
: EQ
);
10801 /* If we have NEG of something whose two high-order bits are the
10802 same, we know that "(-a) < 0" is equivalent to "a > 0". */
10803 if (num_sign_bit_copies (op0
, mode
) >= 2)
10805 op0
= XEXP (op0
, 0);
10806 code
= swap_condition (code
);
10812 /* If we are testing equality and our count is a constant, we
10813 can perform the inverse operation on our RHS. */
10814 if (equality_comparison_p
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
10815 && (tem
= simplify_binary_operation (ROTATERT
, mode
,
10816 op1
, XEXP (op0
, 1))) != 0)
10818 op0
= XEXP (op0
, 0);
10823 /* If we are doing a < 0 or >= 0 comparison, it means we are testing
10824 a particular bit. Convert it to an AND of a constant of that
10825 bit. This will be converted into a ZERO_EXTRACT. */
10826 if (const_op
== 0 && sign_bit_comparison_p
10827 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
10828 && mode_width
<= HOST_BITS_PER_WIDE_INT
)
10830 op0
= simplify_and_const_int (NULL_RTX
, mode
, XEXP (op0
, 0),
10833 - INTVAL (XEXP (op0
, 1)))));
10834 code
= (code
== LT
? NE
: EQ
);
10838 /* Fall through. */
10841 /* ABS is ignorable inside an equality comparison with zero. */
10842 if (const_op
== 0 && equality_comparison_p
)
10844 op0
= XEXP (op0
, 0);
10850 /* Can simplify (compare (zero/sign_extend FOO) CONST)
10851 to (compare FOO CONST) if CONST fits in FOO's mode and we
10852 are either testing inequality or have an unsigned comparison
10853 with ZERO_EXTEND or a signed comparison with SIGN_EXTEND. */
10854 if (! unsigned_comparison_p
10855 && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10856 <= HOST_BITS_PER_WIDE_INT
)
10857 && ((unsigned HOST_WIDE_INT
) const_op
10858 < (((unsigned HOST_WIDE_INT
) 1
10859 << (GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0))) - 1)))))
10861 op0
= XEXP (op0
, 0);
10867 /* Check for the case where we are comparing A - C1 with C2,
10868 both constants are smaller than 1/2 the maximum positive
10869 value in MODE, and the comparison is equality or unsigned.
10870 In that case, if A is either zero-extended to MODE or has
10871 sufficient sign bits so that the high-order bit in MODE
10872 is a copy of the sign in the inner mode, we can prove that it is
10873 safe to do the operation in the wider mode. This simplifies
10874 many range checks. */
10876 if (mode_width
<= HOST_BITS_PER_WIDE_INT
10877 && subreg_lowpart_p (op0
)
10878 && GET_CODE (SUBREG_REG (op0
)) == PLUS
10879 && GET_CODE (XEXP (SUBREG_REG (op0
), 1)) == CONST_INT
10880 && INTVAL (XEXP (SUBREG_REG (op0
), 1)) < 0
10881 && (-INTVAL (XEXP (SUBREG_REG (op0
), 1))
10882 < (HOST_WIDE_INT
) (GET_MODE_MASK (mode
) / 2))
10883 && (unsigned HOST_WIDE_INT
) const_op
< GET_MODE_MASK (mode
) / 2
10884 && (0 == (nonzero_bits (XEXP (SUBREG_REG (op0
), 0),
10885 GET_MODE (SUBREG_REG (op0
)))
10886 & ~GET_MODE_MASK (mode
))
10887 || (num_sign_bit_copies (XEXP (SUBREG_REG (op0
), 0),
10888 GET_MODE (SUBREG_REG (op0
)))
10890 (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0
)))
10891 - GET_MODE_BITSIZE (mode
)))))
10893 op0
= SUBREG_REG (op0
);
10897 /* If the inner mode is narrower and we are extracting the low part,
10898 we can treat the SUBREG as if it were a ZERO_EXTEND. */
10899 if (subreg_lowpart_p (op0
)
10900 && GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0
))) < mode_width
)
10901 /* Fall through */ ;
10905 /* ... fall through ... */
10908 if ((unsigned_comparison_p
|| equality_comparison_p
)
10909 && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10910 <= HOST_BITS_PER_WIDE_INT
)
10911 && ((unsigned HOST_WIDE_INT
) const_op
10912 < GET_MODE_MASK (GET_MODE (XEXP (op0
, 0)))))
10914 op0
= XEXP (op0
, 0);
10920 /* (eq (plus X A) B) -> (eq X (minus B A)). We can only do
10921 this for equality comparisons due to pathological cases involving
10923 if (equality_comparison_p
10924 && 0 != (tem
= simplify_binary_operation (MINUS
, mode
,
10925 op1
, XEXP (op0
, 1))))
10927 op0
= XEXP (op0
, 0);
10932 /* (plus (abs X) (const_int -1)) is < 0 if and only if X == 0. */
10933 if (const_op
== 0 && XEXP (op0
, 1) == constm1_rtx
10934 && GET_CODE (XEXP (op0
, 0)) == ABS
&& sign_bit_comparison_p
)
10936 op0
= XEXP (XEXP (op0
, 0), 0);
10937 code
= (code
== LT
? EQ
: NE
);
10943 /* We used to optimize signed comparisons against zero, but that
10944 was incorrect. Unsigned comparisons against zero (GTU, LEU)
10945 arrive here as equality comparisons, or (GEU, LTU) are
10946 optimized away. No need to special-case them. */
10948 /* (eq (minus A B) C) -> (eq A (plus B C)) or
10949 (eq B (minus A C)), whichever simplifies. We can only do
10950 this for equality comparisons due to pathological cases involving
10952 if (equality_comparison_p
10953 && 0 != (tem
= simplify_binary_operation (PLUS
, mode
,
10954 XEXP (op0
, 1), op1
)))
10956 op0
= XEXP (op0
, 0);
10961 if (equality_comparison_p
10962 && 0 != (tem
= simplify_binary_operation (MINUS
, mode
,
10963 XEXP (op0
, 0), op1
)))
10965 op0
= XEXP (op0
, 1);
10970 /* The sign bit of (minus (ashiftrt X C) X), where C is the number
10971 of bits in X minus 1, is one iff X > 0. */
10972 if (sign_bit_comparison_p
&& GET_CODE (XEXP (op0
, 0)) == ASHIFTRT
10973 && GET_CODE (XEXP (XEXP (op0
, 0), 1)) == CONST_INT
10974 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (XEXP (op0
, 0), 1))
10976 && rtx_equal_p (XEXP (XEXP (op0
, 0), 0), XEXP (op0
, 1)))
10978 op0
= XEXP (op0
, 1);
10979 code
= (code
== GE
? LE
: GT
);
10985 /* (eq (xor A B) C) -> (eq A (xor B C)). This is a simplification
10986 if C is zero or B is a constant. */
10987 if (equality_comparison_p
10988 && 0 != (tem
= simplify_binary_operation (XOR
, mode
,
10989 XEXP (op0
, 1), op1
)))
10991 op0
= XEXP (op0
, 0);
10998 case UNEQ
: case LTGT
:
10999 case LT
: case LTU
: case UNLT
: case LE
: case LEU
: case UNLE
:
11000 case GT
: case GTU
: case UNGT
: case GE
: case GEU
: case UNGE
:
11001 case UNORDERED
: case ORDERED
:
11002 /* We can't do anything if OP0 is a condition code value, rather
11003 than an actual data value. */
11005 || CC0_P (XEXP (op0
, 0))
11006 || GET_MODE_CLASS (GET_MODE (XEXP (op0
, 0))) == MODE_CC
)
11009 /* Get the two operands being compared. */
11010 if (GET_CODE (XEXP (op0
, 0)) == COMPARE
)
11011 tem
= XEXP (XEXP (op0
, 0), 0), tem1
= XEXP (XEXP (op0
, 0), 1);
11013 tem
= XEXP (op0
, 0), tem1
= XEXP (op0
, 1);
11015 /* Check for the cases where we simply want the result of the
11016 earlier test or the opposite of that result. */
11017 if (code
== NE
|| code
== EQ
11018 || (GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
11019 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
11020 && (STORE_FLAG_VALUE
11021 & (((HOST_WIDE_INT
) 1
11022 << (GET_MODE_BITSIZE (GET_MODE (op0
)) - 1))))
11023 && (code
== LT
|| code
== GE
)))
11025 enum rtx_code new_code
;
11026 if (code
== LT
|| code
== NE
)
11027 new_code
= GET_CODE (op0
);
11029 new_code
= combine_reversed_comparison_code (op0
);
11031 if (new_code
!= UNKNOWN
)
11042 /* The sign bit of (ior (plus X (const_int -1)) X) is nonzero
11044 if (sign_bit_comparison_p
&& GET_CODE (XEXP (op0
, 0)) == PLUS
11045 && XEXP (XEXP (op0
, 0), 1) == constm1_rtx
11046 && rtx_equal_p (XEXP (XEXP (op0
, 0), 0), XEXP (op0
, 1)))
11048 op0
= XEXP (op0
, 1);
11049 code
= (code
== GE
? GT
: LE
);
11055 /* Convert (and (xshift 1 X) Y) to (and (lshiftrt Y X) 1). This
11056 will be converted to a ZERO_EXTRACT later. */
11057 if (const_op
== 0 && equality_comparison_p
11058 && GET_CODE (XEXP (op0
, 0)) == ASHIFT
11059 && XEXP (XEXP (op0
, 0), 0) == const1_rtx
)
11061 op0
= simplify_and_const_int
11062 (op0
, mode
, gen_rtx_LSHIFTRT (mode
,
11064 XEXP (XEXP (op0
, 0), 1)),
11065 (HOST_WIDE_INT
) 1);
11069 /* If we are comparing (and (lshiftrt X C1) C2) for equality with
11070 zero and X is a comparison and C1 and C2 describe only bits set
11071 in STORE_FLAG_VALUE, we can compare with X. */
11072 if (const_op
== 0 && equality_comparison_p
11073 && mode_width
<= HOST_BITS_PER_WIDE_INT
11074 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11075 && GET_CODE (XEXP (op0
, 0)) == LSHIFTRT
11076 && GET_CODE (XEXP (XEXP (op0
, 0), 1)) == CONST_INT
11077 && INTVAL (XEXP (XEXP (op0
, 0), 1)) >= 0
11078 && INTVAL (XEXP (XEXP (op0
, 0), 1)) < HOST_BITS_PER_WIDE_INT
)
11080 mask
= ((INTVAL (XEXP (op0
, 1)) & GET_MODE_MASK (mode
))
11081 << INTVAL (XEXP (XEXP (op0
, 0), 1)));
11082 if ((~STORE_FLAG_VALUE
& mask
) == 0
11083 && (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (op0
, 0), 0))) == '<'
11084 || ((tem
= get_last_value (XEXP (XEXP (op0
, 0), 0))) != 0
11085 && GET_RTX_CLASS (GET_CODE (tem
)) == '<')))
11087 op0
= XEXP (XEXP (op0
, 0), 0);
11092 /* If we are doing an equality comparison of an AND of a bit equal
11093 to the sign bit, replace this with a LT or GE comparison of
11094 the underlying value. */
11095 if (equality_comparison_p
11097 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11098 && mode_width
<= HOST_BITS_PER_WIDE_INT
11099 && ((INTVAL (XEXP (op0
, 1)) & GET_MODE_MASK (mode
))
11100 == (unsigned HOST_WIDE_INT
) 1 << (mode_width
- 1)))
11102 op0
= XEXP (op0
, 0);
11103 code
= (code
== EQ
? GE
: LT
);
11107 /* If this AND operation is really a ZERO_EXTEND from a narrower
11108 mode, the constant fits within that mode, and this is either an
11109 equality or unsigned comparison, try to do this comparison in
11110 the narrower mode. */
11111 if ((equality_comparison_p
|| unsigned_comparison_p
)
11112 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11113 && (i
= exact_log2 ((INTVAL (XEXP (op0
, 1))
11114 & GET_MODE_MASK (mode
))
11116 && const_op
>> i
== 0
11117 && (tmode
= mode_for_size (i
, MODE_INT
, 1)) != BLKmode
)
11119 op0
= gen_lowpart_for_combine (tmode
, XEXP (op0
, 0));
11123 /* If this is (and:M1 (subreg:M2 X 0) (const_int C1)) where C1
11124 fits in both M1 and M2 and the SUBREG is either paradoxical
11125 or represents the low part, permute the SUBREG and the AND
11127 if (GET_CODE (XEXP (op0
, 0)) == SUBREG
)
11129 unsigned HOST_WIDE_INT c1
;
11130 tmode
= GET_MODE (SUBREG_REG (XEXP (op0
, 0)));
11131 /* Require an integral mode, to avoid creating something like
11133 if (SCALAR_INT_MODE_P (tmode
)
11134 /* It is unsafe to commute the AND into the SUBREG if the
11135 SUBREG is paradoxical and WORD_REGISTER_OPERATIONS is
11136 not defined. As originally written the upper bits
11137 have a defined value due to the AND operation.
11138 However, if we commute the AND inside the SUBREG then
11139 they no longer have defined values and the meaning of
11140 the code has been changed. */
11142 #ifdef WORD_REGISTER_OPERATIONS
11143 || (mode_width
> GET_MODE_BITSIZE (tmode
)
11144 && mode_width
<= BITS_PER_WORD
)
11146 || (mode_width
<= GET_MODE_BITSIZE (tmode
)
11147 && subreg_lowpart_p (XEXP (op0
, 0))))
11148 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11149 && mode_width
<= HOST_BITS_PER_WIDE_INT
11150 && GET_MODE_BITSIZE (tmode
) <= HOST_BITS_PER_WIDE_INT
11151 && ((c1
= INTVAL (XEXP (op0
, 1))) & ~mask
) == 0
11152 && (c1
& ~GET_MODE_MASK (tmode
)) == 0
11154 && c1
!= GET_MODE_MASK (tmode
))
11156 op0
= gen_binary (AND
, tmode
,
11157 SUBREG_REG (XEXP (op0
, 0)),
11158 gen_int_mode (c1
, tmode
));
11159 op0
= gen_lowpart_for_combine (mode
, op0
);
11164 /* Convert (ne (and (lshiftrt (not X)) 1) 0) to
11165 (eq (and (lshiftrt X) 1) 0). */
11166 if (const_op
== 0 && equality_comparison_p
11167 && XEXP (op0
, 1) == const1_rtx
11168 && GET_CODE (XEXP (op0
, 0)) == LSHIFTRT
11169 && GET_CODE (XEXP (XEXP (op0
, 0), 0)) == NOT
)
11171 op0
= simplify_and_const_int
11173 gen_rtx_LSHIFTRT (mode
, XEXP (XEXP (XEXP (op0
, 0), 0), 0),
11174 XEXP (XEXP (op0
, 0), 1)),
11175 (HOST_WIDE_INT
) 1);
11176 code
= (code
== NE
? EQ
: NE
);
11182 /* If we have (compare (ashift FOO N) (const_int C)) and
11183 the high order N bits of FOO (N+1 if an inequality comparison)
11184 are known to be zero, we can do this by comparing FOO with C
11185 shifted right N bits so long as the low-order N bits of C are
11187 if (GET_CODE (XEXP (op0
, 1)) == CONST_INT
11188 && INTVAL (XEXP (op0
, 1)) >= 0
11189 && ((INTVAL (XEXP (op0
, 1)) + ! equality_comparison_p
)
11190 < HOST_BITS_PER_WIDE_INT
)
11192 & (((HOST_WIDE_INT
) 1 << INTVAL (XEXP (op0
, 1))) - 1)) == 0)
11193 && mode_width
<= HOST_BITS_PER_WIDE_INT
11194 && (nonzero_bits (XEXP (op0
, 0), mode
)
11195 & ~(mask
>> (INTVAL (XEXP (op0
, 1))
11196 + ! equality_comparison_p
))) == 0)
11198 /* We must perform a logical shift, not an arithmetic one,
11199 as we want the top N bits of C to be zero. */
11200 unsigned HOST_WIDE_INT temp
= const_op
& GET_MODE_MASK (mode
);
11202 temp
>>= INTVAL (XEXP (op0
, 1));
11203 op1
= gen_int_mode (temp
, mode
);
11204 op0
= XEXP (op0
, 0);
11208 /* If we are doing a sign bit comparison, it means we are testing
11209 a particular bit. Convert it to the appropriate AND. */
11210 if (sign_bit_comparison_p
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
11211 && mode_width
<= HOST_BITS_PER_WIDE_INT
)
11213 op0
= simplify_and_const_int (NULL_RTX
, mode
, XEXP (op0
, 0),
11216 - INTVAL (XEXP (op0
, 1)))));
11217 code
= (code
== LT
? NE
: EQ
);
11221 /* If this an equality comparison with zero and we are shifting
11222 the low bit to the sign bit, we can convert this to an AND of the
11224 if (const_op
== 0 && equality_comparison_p
11225 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11226 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (op0
, 1))
11229 op0
= simplify_and_const_int (NULL_RTX
, mode
, XEXP (op0
, 0),
11230 (HOST_WIDE_INT
) 1);
11236 /* If this is an equality comparison with zero, we can do this
11237 as a logical shift, which might be much simpler. */
11238 if (equality_comparison_p
&& const_op
== 0
11239 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
)
11241 op0
= simplify_shift_const (NULL_RTX
, LSHIFTRT
, mode
,
11243 INTVAL (XEXP (op0
, 1)));
11247 /* If OP0 is a sign extension and CODE is not an unsigned comparison,
11248 do the comparison in a narrower mode. */
11249 if (! unsigned_comparison_p
11250 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11251 && GET_CODE (XEXP (op0
, 0)) == ASHIFT
11252 && XEXP (op0
, 1) == XEXP (XEXP (op0
, 0), 1)
11253 && (tmode
= mode_for_size (mode_width
- INTVAL (XEXP (op0
, 1)),
11254 MODE_INT
, 1)) != BLKmode
11255 && (((unsigned HOST_WIDE_INT
) const_op
11256 + (GET_MODE_MASK (tmode
) >> 1) + 1)
11257 <= GET_MODE_MASK (tmode
)))
11259 op0
= gen_lowpart_for_combine (tmode
, XEXP (XEXP (op0
, 0), 0));
11263 /* Likewise if OP0 is a PLUS of a sign extension with a
11264 constant, which is usually represented with the PLUS
11265 between the shifts. */
11266 if (! unsigned_comparison_p
11267 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11268 && GET_CODE (XEXP (op0
, 0)) == PLUS
11269 && GET_CODE (XEXP (XEXP (op0
, 0), 1)) == CONST_INT
11270 && GET_CODE (XEXP (XEXP (op0
, 0), 0)) == ASHIFT
11271 && XEXP (op0
, 1) == XEXP (XEXP (XEXP (op0
, 0), 0), 1)
11272 && (tmode
= mode_for_size (mode_width
- INTVAL (XEXP (op0
, 1)),
11273 MODE_INT
, 1)) != BLKmode
11274 && (((unsigned HOST_WIDE_INT
) const_op
11275 + (GET_MODE_MASK (tmode
) >> 1) + 1)
11276 <= GET_MODE_MASK (tmode
)))
11278 rtx inner
= XEXP (XEXP (XEXP (op0
, 0), 0), 0);
11279 rtx add_const
= XEXP (XEXP (op0
, 0), 1);
11280 rtx new_const
= gen_binary (ASHIFTRT
, GET_MODE (op0
), add_const
,
11283 op0
= gen_binary (PLUS
, tmode
,
11284 gen_lowpart_for_combine (tmode
, inner
),
11289 /* ... fall through ... */
11291 /* If we have (compare (xshiftrt FOO N) (const_int C)) and
11292 the low order N bits of FOO are known to be zero, we can do this
11293 by comparing FOO with C shifted left N bits so long as no
11294 overflow occurs. */
11295 if (GET_CODE (XEXP (op0
, 1)) == CONST_INT
11296 && INTVAL (XEXP (op0
, 1)) >= 0
11297 && INTVAL (XEXP (op0
, 1)) < HOST_BITS_PER_WIDE_INT
11298 && mode_width
<= HOST_BITS_PER_WIDE_INT
11299 && (nonzero_bits (XEXP (op0
, 0), mode
)
11300 & (((HOST_WIDE_INT
) 1 << INTVAL (XEXP (op0
, 1))) - 1)) == 0
11301 && (((unsigned HOST_WIDE_INT
) const_op
11302 + (GET_CODE (op0
) != LSHIFTRT
11303 ? ((GET_MODE_MASK (mode
) >> INTVAL (XEXP (op0
, 1)) >> 1)
11306 <= GET_MODE_MASK (mode
) >> INTVAL (XEXP (op0
, 1))))
11308 /* If the shift was logical, then we must make the condition
11310 if (GET_CODE (op0
) == LSHIFTRT
)
11311 code
= unsigned_condition (code
);
11313 const_op
<<= INTVAL (XEXP (op0
, 1));
11314 op1
= GEN_INT (const_op
);
11315 op0
= XEXP (op0
, 0);
11319 /* If we are using this shift to extract just the sign bit, we
11320 can replace this with an LT or GE comparison. */
11322 && (equality_comparison_p
|| sign_bit_comparison_p
)
11323 && GET_CODE (XEXP (op0
, 1)) == CONST_INT
11324 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (op0
, 1))
11327 op0
= XEXP (op0
, 0);
11328 code
= (code
== NE
|| code
== GT
? LT
: GE
);
11340 /* Now make any compound operations involved in this comparison. Then,
11341 check for an outmost SUBREG on OP0 that is not doing anything or is
11342 paradoxical. The latter transformation must only be performed when
11343 it is known that the "extra" bits will be the same in op0 and op1 or
11344 that they don't matter. There are three cases to consider:
11346 1. SUBREG_REG (op0) is a register. In this case the bits are don't
11347 care bits and we can assume they have any convenient value. So
11348 making the transformation is safe.
11350 2. SUBREG_REG (op0) is a memory and LOAD_EXTEND_OP is not defined.
11351 In this case the upper bits of op0 are undefined. We should not make
11352 the simplification in that case as we do not know the contents of
11355 3. SUBREG_REG (op0) is a memory and LOAD_EXTEND_OP is defined and not
11356 NIL. In that case we know those bits are zeros or ones. We must
11357 also be sure that they are the same as the upper bits of op1.
11359 We can never remove a SUBREG for a non-equality comparison because
11360 the sign bit is in a different place in the underlying object. */
11362 op0
= make_compound_operation (op0
, op1
== const0_rtx
? COMPARE
: SET
);
11363 op1
= make_compound_operation (op1
, SET
);
11365 if (GET_CODE (op0
) == SUBREG
&& subreg_lowpart_p (op0
)
11366 /* Case 3 above, to sometimes allow (subreg (mem x)), isn't
11368 && GET_CODE (SUBREG_REG (op0
)) == REG
11369 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
11370 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op0
))) == MODE_INT
11371 && (code
== NE
|| code
== EQ
))
11373 if (GET_MODE_SIZE (GET_MODE (op0
))
11374 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0
))))
11376 op0
= SUBREG_REG (op0
);
11377 op1
= gen_lowpart_for_combine (GET_MODE (op0
), op1
);
11379 else if ((GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0
)))
11380 <= HOST_BITS_PER_WIDE_INT
)
11381 && (nonzero_bits (SUBREG_REG (op0
),
11382 GET_MODE (SUBREG_REG (op0
)))
11383 & ~GET_MODE_MASK (GET_MODE (op0
))) == 0)
11385 tem
= gen_lowpart_for_combine (GET_MODE (SUBREG_REG (op0
)), op1
);
11387 if ((nonzero_bits (tem
, GET_MODE (SUBREG_REG (op0
)))
11388 & ~GET_MODE_MASK (GET_MODE (op0
))) == 0)
11389 op0
= SUBREG_REG (op0
), op1
= tem
;
11393 /* We now do the opposite procedure: Some machines don't have compare
11394 insns in all modes. If OP0's mode is an integer mode smaller than a
11395 word and we can't do a compare in that mode, see if there is a larger
11396 mode for which we can do the compare. There are a number of cases in
11397 which we can use the wider mode. */
11399 mode
= GET_MODE (op0
);
11400 if (mode
!= VOIDmode
&& GET_MODE_CLASS (mode
) == MODE_INT
11401 && GET_MODE_SIZE (mode
) < UNITS_PER_WORD
11402 && ! have_insn_for (COMPARE
, mode
))
11403 for (tmode
= GET_MODE_WIDER_MODE (mode
);
11405 && GET_MODE_BITSIZE (tmode
) <= HOST_BITS_PER_WIDE_INT
);
11406 tmode
= GET_MODE_WIDER_MODE (tmode
))
11407 if (have_insn_for (COMPARE
, tmode
))
11411 /* If the only nonzero bits in OP0 and OP1 are those in the
11412 narrower mode and this is an equality or unsigned comparison,
11413 we can use the wider mode. Similarly for sign-extended
11414 values, in which case it is true for all comparisons. */
11415 zero_extended
= ((code
== EQ
|| code
== NE
11416 || code
== GEU
|| code
== GTU
11417 || code
== LEU
|| code
== LTU
)
11418 && (nonzero_bits (op0
, tmode
)
11419 & ~GET_MODE_MASK (mode
)) == 0
11420 && ((GET_CODE (op1
) == CONST_INT
11421 || (nonzero_bits (op1
, tmode
)
11422 & ~GET_MODE_MASK (mode
)) == 0)));
11425 || ((num_sign_bit_copies (op0
, tmode
)
11426 > (unsigned int) (GET_MODE_BITSIZE (tmode
)
11427 - GET_MODE_BITSIZE (mode
)))
11428 && (num_sign_bit_copies (op1
, tmode
)
11429 > (unsigned int) (GET_MODE_BITSIZE (tmode
)
11430 - GET_MODE_BITSIZE (mode
)))))
11432 /* If OP0 is an AND and we don't have an AND in MODE either,
11433 make a new AND in the proper mode. */
11434 if (GET_CODE (op0
) == AND
11435 && !have_insn_for (AND
, mode
))
11436 op0
= gen_binary (AND
, tmode
,
11437 gen_lowpart_for_combine (tmode
,
11439 gen_lowpart_for_combine (tmode
,
11442 op0
= gen_lowpart_for_combine (tmode
, op0
);
11443 if (zero_extended
&& GET_CODE (op1
) == CONST_INT
)
11444 op1
= GEN_INT (INTVAL (op1
) & GET_MODE_MASK (mode
));
11445 op1
= gen_lowpart_for_combine (tmode
, op1
);
11449 /* If this is a test for negative, we can make an explicit
11450 test of the sign bit. */
11452 if (op1
== const0_rtx
&& (code
== LT
|| code
== GE
)
11453 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11455 op0
= gen_binary (AND
, tmode
,
11456 gen_lowpart_for_combine (tmode
, op0
),
11457 GEN_INT ((HOST_WIDE_INT
) 1
11458 << (GET_MODE_BITSIZE (mode
) - 1)));
11459 code
= (code
== LT
) ? NE
: EQ
;
11464 #ifdef CANONICALIZE_COMPARISON
11465 /* If this machine only supports a subset of valid comparisons, see if we
11466 can convert an unsupported one into a supported one. */
11467 CANONICALIZE_COMPARISON (code
, op0
, op1
);
11476 /* Like jump.c' reversed_comparison_code, but use combine infrastructure for
11477 searching backward. */
11478 static enum rtx_code
11479 combine_reversed_comparison_code (exp
)
11482 enum rtx_code code1
= reversed_comparison_code (exp
, NULL
);
11485 if (code1
!= UNKNOWN
11486 || GET_MODE_CLASS (GET_MODE (XEXP (exp
, 0))) != MODE_CC
)
11488 /* Otherwise try and find where the condition codes were last set and
11490 x
= get_last_value (XEXP (exp
, 0));
11491 if (!x
|| GET_CODE (x
) != COMPARE
)
11493 return reversed_comparison_code_parts (GET_CODE (exp
),
11494 XEXP (x
, 0), XEXP (x
, 1), NULL
);
11497 /* Return comparison with reversed code of EXP and operands OP0 and OP1.
11498 Return NULL_RTX in case we fail to do the reversal. */
11500 reversed_comparison (exp
, mode
, op0
, op1
)
11502 enum machine_mode mode
;
11504 enum rtx_code reversed_code
= combine_reversed_comparison_code (exp
);
11505 if (reversed_code
== UNKNOWN
)
11508 return gen_binary (reversed_code
, mode
, op0
, op1
);
11511 /* Utility function for following routine. Called when X is part of a value
11512 being stored into reg_last_set_value. Sets reg_last_set_table_tick
11513 for each register mentioned. Similar to mention_regs in cse.c */
11516 update_table_tick (x
)
11519 enum rtx_code code
= GET_CODE (x
);
11520 const char *fmt
= GET_RTX_FORMAT (code
);
11525 unsigned int regno
= REGNO (x
);
11526 unsigned int endregno
11527 = regno
+ (regno
< FIRST_PSEUDO_REGISTER
11528 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
11531 for (r
= regno
; r
< endregno
; r
++)
11532 reg_last_set_table_tick
[r
] = label_tick
;
11537 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
11538 /* Note that we can't have an "E" in values stored; see
11539 get_last_value_validate. */
11542 /* Check for identical subexpressions. If x contains
11543 identical subexpression we only have to traverse one of
11546 && (GET_RTX_CLASS (code
) == '2'
11547 || GET_RTX_CLASS (code
) == 'c'))
11549 /* Note that at this point x1 has already been
11551 rtx x0
= XEXP (x
, 0);
11552 rtx x1
= XEXP (x
, 1);
11554 /* If x0 and x1 are identical then there is no need to
11559 /* If x0 is identical to a subexpression of x1 then while
11560 processing x1, x0 has already been processed. Thus we
11561 are done with x. */
11562 if ((GET_RTX_CLASS (GET_CODE (x1
)) == '2'
11563 || GET_RTX_CLASS (GET_CODE (x1
)) == 'c')
11564 && (x0
== XEXP (x1
, 0) || x0
== XEXP (x1
, 1)))
11567 /* If x1 is identical to a subexpression of x0 then we
11568 still have to process the rest of x0. */
11569 if ((GET_RTX_CLASS (GET_CODE (x0
)) == '2'
11570 || GET_RTX_CLASS (GET_CODE (x0
)) == 'c')
11571 && (x1
== XEXP (x0
, 0) || x1
== XEXP (x0
, 1)))
11573 update_table_tick (XEXP (x0
, x1
== XEXP (x0
, 0) ? 1 : 0));
11578 update_table_tick (XEXP (x
, i
));
11582 /* Record that REG is set to VALUE in insn INSN. If VALUE is zero, we
11583 are saying that the register is clobbered and we no longer know its
11584 value. If INSN is zero, don't update reg_last_set; this is only permitted
11585 with VALUE also zero and is used to invalidate the register. */
11588 record_value_for_reg (reg
, insn
, value
)
11593 unsigned int regno
= REGNO (reg
);
11594 unsigned int endregno
11595 = regno
+ (regno
< FIRST_PSEUDO_REGISTER
11596 ? HARD_REGNO_NREGS (regno
, GET_MODE (reg
)) : 1);
11599 /* If VALUE contains REG and we have a previous value for REG, substitute
11600 the previous value. */
11601 if (value
&& insn
&& reg_overlap_mentioned_p (reg
, value
))
11605 /* Set things up so get_last_value is allowed to see anything set up to
11607 subst_low_cuid
= INSN_CUID (insn
);
11608 tem
= get_last_value (reg
);
11610 /* If TEM is simply a binary operation with two CLOBBERs as operands,
11611 it isn't going to be useful and will take a lot of time to process,
11612 so just use the CLOBBER. */
11616 if ((GET_RTX_CLASS (GET_CODE (tem
)) == '2'
11617 || GET_RTX_CLASS (GET_CODE (tem
)) == 'c')
11618 && GET_CODE (XEXP (tem
, 0)) == CLOBBER
11619 && GET_CODE (XEXP (tem
, 1)) == CLOBBER
)
11620 tem
= XEXP (tem
, 0);
11622 value
= replace_rtx (copy_rtx (value
), reg
, tem
);
11626 /* For each register modified, show we don't know its value, that
11627 we don't know about its bitwise content, that its value has been
11628 updated, and that we don't know the location of the death of the
11630 for (i
= regno
; i
< endregno
; i
++)
11633 reg_last_set
[i
] = insn
;
11635 reg_last_set_value
[i
] = 0;
11636 reg_last_set_mode
[i
] = 0;
11637 reg_last_set_nonzero_bits
[i
] = 0;
11638 reg_last_set_sign_bit_copies
[i
] = 0;
11639 reg_last_death
[i
] = 0;
11642 /* Mark registers that are being referenced in this value. */
11644 update_table_tick (value
);
11646 /* Now update the status of each register being set.
11647 If someone is using this register in this block, set this register
11648 to invalid since we will get confused between the two lives in this
11649 basic block. This makes using this register always invalid. In cse, we
11650 scan the table to invalidate all entries using this register, but this
11651 is too much work for us. */
11653 for (i
= regno
; i
< endregno
; i
++)
11655 reg_last_set_label
[i
] = label_tick
;
11656 if (value
&& reg_last_set_table_tick
[i
] == label_tick
)
11657 reg_last_set_invalid
[i
] = 1;
11659 reg_last_set_invalid
[i
] = 0;
11662 /* The value being assigned might refer to X (like in "x++;"). In that
11663 case, we must replace it with (clobber (const_int 0)) to prevent
11665 if (value
&& ! get_last_value_validate (&value
, insn
,
11666 reg_last_set_label
[regno
], 0))
11668 value
= copy_rtx (value
);
11669 if (! get_last_value_validate (&value
, insn
,
11670 reg_last_set_label
[regno
], 1))
11674 /* For the main register being modified, update the value, the mode, the
11675 nonzero bits, and the number of sign bit copies. */
11677 reg_last_set_value
[regno
] = value
;
11681 enum machine_mode mode
= GET_MODE (reg
);
11682 subst_low_cuid
= INSN_CUID (insn
);
11683 reg_last_set_mode
[regno
] = mode
;
11684 if (GET_MODE_CLASS (mode
) == MODE_INT
11685 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11686 mode
= nonzero_bits_mode
;
11687 reg_last_set_nonzero_bits
[regno
] = nonzero_bits (value
, mode
);
11688 reg_last_set_sign_bit_copies
[regno
]
11689 = num_sign_bit_copies (value
, GET_MODE (reg
));
11693 /* Called via note_stores from record_dead_and_set_regs to handle one
11694 SET or CLOBBER in an insn. DATA is the instruction in which the
11695 set is occurring. */
11698 record_dead_and_set_regs_1 (dest
, setter
, data
)
11702 rtx record_dead_insn
= (rtx
) data
;
11704 if (GET_CODE (dest
) == SUBREG
)
11705 dest
= SUBREG_REG (dest
);
11707 if (GET_CODE (dest
) == REG
)
11709 /* If we are setting the whole register, we know its value. Otherwise
11710 show that we don't know the value. We can handle SUBREG in
11712 if (GET_CODE (setter
) == SET
&& dest
== SET_DEST (setter
))
11713 record_value_for_reg (dest
, record_dead_insn
, SET_SRC (setter
));
11714 else if (GET_CODE (setter
) == SET
11715 && GET_CODE (SET_DEST (setter
)) == SUBREG
11716 && SUBREG_REG (SET_DEST (setter
)) == dest
11717 && GET_MODE_BITSIZE (GET_MODE (dest
)) <= BITS_PER_WORD
11718 && subreg_lowpart_p (SET_DEST (setter
)))
11719 record_value_for_reg (dest
, record_dead_insn
,
11720 gen_lowpart_for_combine (GET_MODE (dest
),
11721 SET_SRC (setter
)));
11723 record_value_for_reg (dest
, record_dead_insn
, NULL_RTX
);
11725 else if (GET_CODE (dest
) == MEM
11726 /* Ignore pushes, they clobber nothing. */
11727 && ! push_operand (dest
, GET_MODE (dest
)))
11728 mem_last_set
= INSN_CUID (record_dead_insn
);
11731 /* Update the records of when each REG was most recently set or killed
11732 for the things done by INSN. This is the last thing done in processing
11733 INSN in the combiner loop.
11735 We update reg_last_set, reg_last_set_value, reg_last_set_mode,
11736 reg_last_set_nonzero_bits, reg_last_set_sign_bit_copies, reg_last_death,
11737 and also the similar information mem_last_set (which insn most recently
11738 modified memory) and last_call_cuid (which insn was the most recent
11739 subroutine call). */
11742 record_dead_and_set_regs (insn
)
11748 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
11750 if (REG_NOTE_KIND (link
) == REG_DEAD
11751 && GET_CODE (XEXP (link
, 0)) == REG
)
11753 unsigned int regno
= REGNO (XEXP (link
, 0));
11754 unsigned int endregno
11755 = regno
+ (regno
< FIRST_PSEUDO_REGISTER
11756 ? HARD_REGNO_NREGS (regno
, GET_MODE (XEXP (link
, 0)))
11759 for (i
= regno
; i
< endregno
; i
++)
11760 reg_last_death
[i
] = insn
;
11762 else if (REG_NOTE_KIND (link
) == REG_INC
)
11763 record_value_for_reg (XEXP (link
, 0), insn
, NULL_RTX
);
11766 if (GET_CODE (insn
) == CALL_INSN
)
11768 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
11769 if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
11771 reg_last_set_value
[i
] = 0;
11772 reg_last_set_mode
[i
] = 0;
11773 reg_last_set_nonzero_bits
[i
] = 0;
11774 reg_last_set_sign_bit_copies
[i
] = 0;
11775 reg_last_death
[i
] = 0;
11778 last_call_cuid
= mem_last_set
= INSN_CUID (insn
);
11780 /* Don't bother recording what this insn does. It might set the
11781 return value register, but we can't combine into a call
11782 pattern anyway, so there's no point trying (and it may cause
11783 a crash, if e.g. we wind up asking for last_set_value of a
11784 SUBREG of the return value register). */
11788 note_stores (PATTERN (insn
), record_dead_and_set_regs_1
, insn
);
11791 /* If a SUBREG has the promoted bit set, it is in fact a property of the
11792 register present in the SUBREG, so for each such SUBREG go back and
11793 adjust nonzero and sign bit information of the registers that are
11794 known to have some zero/sign bits set.
11796 This is needed because when combine blows the SUBREGs away, the
11797 information on zero/sign bits is lost and further combines can be
11798 missed because of that. */
11801 record_promoted_value (insn
, subreg
)
11806 unsigned int regno
= REGNO (SUBREG_REG (subreg
));
11807 enum machine_mode mode
= GET_MODE (subreg
);
11809 if (GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_WIDE_INT
)
11812 for (links
= LOG_LINKS (insn
); links
;)
11814 insn
= XEXP (links
, 0);
11815 set
= single_set (insn
);
11817 if (! set
|| GET_CODE (SET_DEST (set
)) != REG
11818 || REGNO (SET_DEST (set
)) != regno
11819 || GET_MODE (SET_DEST (set
)) != GET_MODE (SUBREG_REG (subreg
)))
11821 links
= XEXP (links
, 1);
11825 if (reg_last_set
[regno
] == insn
)
11827 if (SUBREG_PROMOTED_UNSIGNED_P (subreg
) > 0)
11828 reg_last_set_nonzero_bits
[regno
] &= GET_MODE_MASK (mode
);
11831 if (GET_CODE (SET_SRC (set
)) == REG
)
11833 regno
= REGNO (SET_SRC (set
));
11834 links
= LOG_LINKS (insn
);
11841 /* Scan X for promoted SUBREGs. For each one found,
11842 note what it implies to the registers used in it. */
11845 check_promoted_subreg (insn
, x
)
11849 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
11850 && GET_CODE (SUBREG_REG (x
)) == REG
)
11851 record_promoted_value (insn
, x
);
11854 const char *format
= GET_RTX_FORMAT (GET_CODE (x
));
11857 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
11861 check_promoted_subreg (insn
, XEXP (x
, i
));
11865 if (XVEC (x
, i
) != 0)
11866 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
11867 check_promoted_subreg (insn
, XVECEXP (x
, i
, j
));
11873 /* Utility routine for the following function. Verify that all the registers
11874 mentioned in *LOC are valid when *LOC was part of a value set when
11875 label_tick == TICK. Return 0 if some are not.
11877 If REPLACE is nonzero, replace the invalid reference with
11878 (clobber (const_int 0)) and return 1. This replacement is useful because
11879 we often can get useful information about the form of a value (e.g., if
11880 it was produced by a shift that always produces -1 or 0) even though
11881 we don't know exactly what registers it was produced from. */
11884 get_last_value_validate (loc
, insn
, tick
, replace
)
11891 const char *fmt
= GET_RTX_FORMAT (GET_CODE (x
));
11892 int len
= GET_RTX_LENGTH (GET_CODE (x
));
11895 if (GET_CODE (x
) == REG
)
11897 unsigned int regno
= REGNO (x
);
11898 unsigned int endregno
11899 = regno
+ (regno
< FIRST_PSEUDO_REGISTER
11900 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
11903 for (j
= regno
; j
< endregno
; j
++)
11904 if (reg_last_set_invalid
[j
]
11905 /* If this is a pseudo-register that was only set once and not
11906 live at the beginning of the function, it is always valid. */
11907 || (! (regno
>= FIRST_PSEUDO_REGISTER
11908 && REG_N_SETS (regno
) == 1
11909 && (! REGNO_REG_SET_P
11910 (ENTRY_BLOCK_PTR
->next_bb
->global_live_at_start
, regno
)))
11911 && reg_last_set_label
[j
] > tick
))
11914 *loc
= gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
11920 /* If this is a memory reference, make sure that there were
11921 no stores after it that might have clobbered the value. We don't
11922 have alias info, so we assume any store invalidates it. */
11923 else if (GET_CODE (x
) == MEM
&& ! RTX_UNCHANGING_P (x
)
11924 && INSN_CUID (insn
) <= mem_last_set
)
11927 *loc
= gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
11931 for (i
= 0; i
< len
; i
++)
11935 /* Check for identical subexpressions. If x contains
11936 identical subexpression we only have to traverse one of
11939 && (GET_RTX_CLASS (GET_CODE (x
)) == '2'
11940 || GET_RTX_CLASS (GET_CODE (x
)) == 'c'))
11942 /* Note that at this point x0 has already been checked
11943 and found valid. */
11944 rtx x0
= XEXP (x
, 0);
11945 rtx x1
= XEXP (x
, 1);
11947 /* If x0 and x1 are identical then x is also valid. */
11951 /* If x1 is identical to a subexpression of x0 then
11952 while checking x0, x1 has already been checked. Thus
11953 it is valid and so as x. */
11954 if ((GET_RTX_CLASS (GET_CODE (x0
)) == '2'
11955 || GET_RTX_CLASS (GET_CODE (x0
)) == 'c')
11956 && (x1
== XEXP (x0
, 0) || x1
== XEXP (x0
, 1)))
11959 /* If x0 is identical to a subexpression of x1 then x is
11960 valid iff the rest of x1 is valid. */
11961 if ((GET_RTX_CLASS (GET_CODE (x1
)) == '2'
11962 || GET_RTX_CLASS (GET_CODE (x1
)) == 'c')
11963 && (x0
== XEXP (x1
, 0) || x0
== XEXP (x1
, 1)))
11965 get_last_value_validate (&XEXP (x1
,
11966 x0
== XEXP (x1
, 0) ? 1 : 0),
11967 insn
, tick
, replace
);
11970 if (get_last_value_validate (&XEXP (x
, i
), insn
, tick
,
11974 /* Don't bother with these. They shouldn't occur anyway. */
11975 else if (fmt
[i
] == 'E')
11979 /* If we haven't found a reason for it to be invalid, it is valid. */
11983 /* Get the last value assigned to X, if known. Some registers
11984 in the value may be replaced with (clobber (const_int 0)) if their value
11985 is known longer known reliably. */
11991 unsigned int regno
;
11994 /* If this is a non-paradoxical SUBREG, get the value of its operand and
11995 then convert it to the desired mode. If this is a paradoxical SUBREG,
11996 we cannot predict what values the "extra" bits might have. */
11997 if (GET_CODE (x
) == SUBREG
11998 && subreg_lowpart_p (x
)
11999 && (GET_MODE_SIZE (GET_MODE (x
))
12000 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
12001 && (value
= get_last_value (SUBREG_REG (x
))) != 0)
12002 return gen_lowpart_for_combine (GET_MODE (x
), value
);
12004 if (GET_CODE (x
) != REG
)
12008 value
= reg_last_set_value
[regno
];
12010 /* If we don't have a value, or if it isn't for this basic block and
12011 it's either a hard register, set more than once, or it's a live
12012 at the beginning of the function, return 0.
12014 Because if it's not live at the beginning of the function then the reg
12015 is always set before being used (is never used without being set).
12016 And, if it's set only once, and it's always set before use, then all
12017 uses must have the same last value, even if it's not from this basic
12021 || (reg_last_set_label
[regno
] != label_tick
12022 && (regno
< FIRST_PSEUDO_REGISTER
12023 || REG_N_SETS (regno
) != 1
12024 || (REGNO_REG_SET_P
12025 (ENTRY_BLOCK_PTR
->next_bb
->global_live_at_start
, regno
)))))
12028 /* If the value was set in a later insn than the ones we are processing,
12029 we can't use it even if the register was only set once. */
12030 if (INSN_CUID (reg_last_set
[regno
]) >= subst_low_cuid
)
12033 /* If the value has all its registers valid, return it. */
12034 if (get_last_value_validate (&value
, reg_last_set
[regno
],
12035 reg_last_set_label
[regno
], 0))
12038 /* Otherwise, make a copy and replace any invalid register with
12039 (clobber (const_int 0)). If that fails for some reason, return 0. */
12041 value
= copy_rtx (value
);
12042 if (get_last_value_validate (&value
, reg_last_set
[regno
],
12043 reg_last_set_label
[regno
], 1))
12049 /* Return nonzero if expression X refers to a REG or to memory
12050 that is set in an instruction more recent than FROM_CUID. */
12053 use_crosses_set_p (x
, from_cuid
)
12059 enum rtx_code code
= GET_CODE (x
);
12063 unsigned int regno
= REGNO (x
);
12064 unsigned endreg
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
12065 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
12067 #ifdef PUSH_ROUNDING
12068 /* Don't allow uses of the stack pointer to be moved,
12069 because we don't know whether the move crosses a push insn. */
12070 if (regno
== STACK_POINTER_REGNUM
&& PUSH_ARGS
)
12073 for (; regno
< endreg
; regno
++)
12074 if (reg_last_set
[regno
]
12075 && INSN_CUID (reg_last_set
[regno
]) > from_cuid
)
12080 if (code
== MEM
&& mem_last_set
> from_cuid
)
12083 fmt
= GET_RTX_FORMAT (code
);
12085 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
12090 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
12091 if (use_crosses_set_p (XVECEXP (x
, i
, j
), from_cuid
))
12094 else if (fmt
[i
] == 'e'
12095 && use_crosses_set_p (XEXP (x
, i
), from_cuid
))
12101 /* Define three variables used for communication between the following
12104 static unsigned int reg_dead_regno
, reg_dead_endregno
;
12105 static int reg_dead_flag
;
12107 /* Function called via note_stores from reg_dead_at_p.
12109 If DEST is within [reg_dead_regno, reg_dead_endregno), set
12110 reg_dead_flag to 1 if X is a CLOBBER and to -1 it is a SET. */
12113 reg_dead_at_p_1 (dest
, x
, data
)
12116 void *data ATTRIBUTE_UNUSED
;
12118 unsigned int regno
, endregno
;
12120 if (GET_CODE (dest
) != REG
)
12123 regno
= REGNO (dest
);
12124 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
12125 ? HARD_REGNO_NREGS (regno
, GET_MODE (dest
)) : 1);
12127 if (reg_dead_endregno
> regno
&& reg_dead_regno
< endregno
)
12128 reg_dead_flag
= (GET_CODE (x
) == CLOBBER
) ? 1 : -1;
12131 /* Return nonzero if REG is known to be dead at INSN.
12133 We scan backwards from INSN. If we hit a REG_DEAD note or a CLOBBER
12134 referencing REG, it is dead. If we hit a SET referencing REG, it is
12135 live. Otherwise, see if it is live or dead at the start of the basic
12136 block we are in. Hard regs marked as being live in NEWPAT_USED_REGS
12137 must be assumed to be always live. */
12140 reg_dead_at_p (reg
, insn
)
12147 /* Set variables for reg_dead_at_p_1. */
12148 reg_dead_regno
= REGNO (reg
);
12149 reg_dead_endregno
= reg_dead_regno
+ (reg_dead_regno
< FIRST_PSEUDO_REGISTER
12150 ? HARD_REGNO_NREGS (reg_dead_regno
,
12156 /* Check that reg isn't mentioned in NEWPAT_USED_REGS. */
12157 if (reg_dead_regno
< FIRST_PSEUDO_REGISTER
)
12159 for (i
= reg_dead_regno
; i
< reg_dead_endregno
; i
++)
12160 if (TEST_HARD_REG_BIT (newpat_used_regs
, i
))
12164 /* Scan backwards until we find a REG_DEAD note, SET, CLOBBER, label, or
12165 beginning of function. */
12166 for (; insn
&& GET_CODE (insn
) != CODE_LABEL
&& GET_CODE (insn
) != BARRIER
;
12167 insn
= prev_nonnote_insn (insn
))
12169 note_stores (PATTERN (insn
), reg_dead_at_p_1
, NULL
);
12171 return reg_dead_flag
== 1 ? 1 : 0;
12173 if (find_regno_note (insn
, REG_DEAD
, reg_dead_regno
))
12177 /* Get the basic block that we were in. */
12179 block
= ENTRY_BLOCK_PTR
->next_bb
;
12182 FOR_EACH_BB (block
)
12183 if (insn
== block
->head
)
12186 if (block
== EXIT_BLOCK_PTR
)
12190 for (i
= reg_dead_regno
; i
< reg_dead_endregno
; i
++)
12191 if (REGNO_REG_SET_P (block
->global_live_at_start
, i
))
12197 /* Note hard registers in X that are used. This code is similar to
12198 that in flow.c, but much simpler since we don't care about pseudos. */
12201 mark_used_regs_combine (x
)
12204 RTX_CODE code
= GET_CODE (x
);
12205 unsigned int regno
;
12218 case ADDR_DIFF_VEC
:
12221 /* CC0 must die in the insn after it is set, so we don't need to take
12222 special note of it here. */
12228 /* If we are clobbering a MEM, mark any hard registers inside the
12229 address as used. */
12230 if (GET_CODE (XEXP (x
, 0)) == MEM
)
12231 mark_used_regs_combine (XEXP (XEXP (x
, 0), 0));
12236 /* A hard reg in a wide mode may really be multiple registers.
12237 If so, mark all of them just like the first. */
12238 if (regno
< FIRST_PSEUDO_REGISTER
)
12240 unsigned int endregno
, r
;
12242 /* None of this applies to the stack, frame or arg pointers. */
12243 if (regno
== STACK_POINTER_REGNUM
12244 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
12245 || regno
== HARD_FRAME_POINTER_REGNUM
12247 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
12248 || (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
12250 || regno
== FRAME_POINTER_REGNUM
)
12253 endregno
= regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
));
12254 for (r
= regno
; r
< endregno
; r
++)
12255 SET_HARD_REG_BIT (newpat_used_regs
, r
);
12261 /* If setting a MEM, or a SUBREG of a MEM, then note any hard regs in
12263 rtx testreg
= SET_DEST (x
);
12265 while (GET_CODE (testreg
) == SUBREG
12266 || GET_CODE (testreg
) == ZERO_EXTRACT
12267 || GET_CODE (testreg
) == SIGN_EXTRACT
12268 || GET_CODE (testreg
) == STRICT_LOW_PART
)
12269 testreg
= XEXP (testreg
, 0);
12271 if (GET_CODE (testreg
) == MEM
)
12272 mark_used_regs_combine (XEXP (testreg
, 0));
12274 mark_used_regs_combine (SET_SRC (x
));
12282 /* Recursively scan the operands of this expression. */
12285 const char *fmt
= GET_RTX_FORMAT (code
);
12287 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
12290 mark_used_regs_combine (XEXP (x
, i
));
12291 else if (fmt
[i
] == 'E')
12295 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
12296 mark_used_regs_combine (XVECEXP (x
, i
, j
));
12302 /* Remove register number REGNO from the dead registers list of INSN.
12304 Return the note used to record the death, if there was one. */
12307 remove_death (regno
, insn
)
12308 unsigned int regno
;
12311 rtx note
= find_regno_note (insn
, REG_DEAD
, regno
);
12315 REG_N_DEATHS (regno
)--;
12316 remove_note (insn
, note
);
12322 /* For each register (hardware or pseudo) used within expression X, if its
12323 death is in an instruction with cuid between FROM_CUID (inclusive) and
12324 TO_INSN (exclusive), put a REG_DEAD note for that register in the
12325 list headed by PNOTES.
12327 That said, don't move registers killed by maybe_kill_insn.
12329 This is done when X is being merged by combination into TO_INSN. These
12330 notes will then be distributed as needed. */
12333 move_deaths (x
, maybe_kill_insn
, from_cuid
, to_insn
, pnotes
)
12335 rtx maybe_kill_insn
;
12342 enum rtx_code code
= GET_CODE (x
);
12346 unsigned int regno
= REGNO (x
);
12347 rtx where_dead
= reg_last_death
[regno
];
12348 rtx before_dead
, after_dead
;
12350 /* Don't move the register if it gets killed in between from and to. */
12351 if (maybe_kill_insn
&& reg_set_p (x
, maybe_kill_insn
)
12352 && ! reg_referenced_p (x
, maybe_kill_insn
))
12355 /* WHERE_DEAD could be a USE insn made by combine, so first we
12356 make sure that we have insns with valid INSN_CUID values. */
12357 before_dead
= where_dead
;
12358 while (before_dead
&& INSN_UID (before_dead
) > max_uid_cuid
)
12359 before_dead
= PREV_INSN (before_dead
);
12361 after_dead
= where_dead
;
12362 while (after_dead
&& INSN_UID (after_dead
) > max_uid_cuid
)
12363 after_dead
= NEXT_INSN (after_dead
);
12365 if (before_dead
&& after_dead
12366 && INSN_CUID (before_dead
) >= from_cuid
12367 && (INSN_CUID (after_dead
) < INSN_CUID (to_insn
)
12368 || (where_dead
!= after_dead
12369 && INSN_CUID (after_dead
) == INSN_CUID (to_insn
))))
12371 rtx note
= remove_death (regno
, where_dead
);
12373 /* It is possible for the call above to return 0. This can occur
12374 when reg_last_death points to I2 or I1 that we combined with.
12375 In that case make a new note.
12377 We must also check for the case where X is a hard register
12378 and NOTE is a death note for a range of hard registers
12379 including X. In that case, we must put REG_DEAD notes for
12380 the remaining registers in place of NOTE. */
12382 if (note
!= 0 && regno
< FIRST_PSEUDO_REGISTER
12383 && (GET_MODE_SIZE (GET_MODE (XEXP (note
, 0)))
12384 > GET_MODE_SIZE (GET_MODE (x
))))
12386 unsigned int deadregno
= REGNO (XEXP (note
, 0));
12387 unsigned int deadend
12388 = (deadregno
+ HARD_REGNO_NREGS (deadregno
,
12389 GET_MODE (XEXP (note
, 0))));
12390 unsigned int ourend
12391 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
));
12394 for (i
= deadregno
; i
< deadend
; i
++)
12395 if (i
< regno
|| i
>= ourend
)
12396 REG_NOTES (where_dead
)
12397 = gen_rtx_EXPR_LIST (REG_DEAD
,
12399 REG_NOTES (where_dead
));
12402 /* If we didn't find any note, or if we found a REG_DEAD note that
12403 covers only part of the given reg, and we have a multi-reg hard
12404 register, then to be safe we must check for REG_DEAD notes
12405 for each register other than the first. They could have
12406 their own REG_DEAD notes lying around. */
12407 else if ((note
== 0
12409 && (GET_MODE_SIZE (GET_MODE (XEXP (note
, 0)))
12410 < GET_MODE_SIZE (GET_MODE (x
)))))
12411 && regno
< FIRST_PSEUDO_REGISTER
12412 && HARD_REGNO_NREGS (regno
, GET_MODE (x
)) > 1)
12414 unsigned int ourend
12415 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
));
12416 unsigned int i
, offset
;
12420 offset
= HARD_REGNO_NREGS (regno
, GET_MODE (XEXP (note
, 0)));
12424 for (i
= regno
+ offset
; i
< ourend
; i
++)
12425 move_deaths (regno_reg_rtx
[i
],
12426 maybe_kill_insn
, from_cuid
, to_insn
, &oldnotes
);
12429 if (note
!= 0 && GET_MODE (XEXP (note
, 0)) == GET_MODE (x
))
12431 XEXP (note
, 1) = *pnotes
;
12435 *pnotes
= gen_rtx_EXPR_LIST (REG_DEAD
, x
, *pnotes
);
12437 REG_N_DEATHS (regno
)++;
12443 else if (GET_CODE (x
) == SET
)
12445 rtx dest
= SET_DEST (x
);
12447 move_deaths (SET_SRC (x
), maybe_kill_insn
, from_cuid
, to_insn
, pnotes
);
12449 /* In the case of a ZERO_EXTRACT, a STRICT_LOW_PART, or a SUBREG
12450 that accesses one word of a multi-word item, some
12451 piece of everything register in the expression is used by
12452 this insn, so remove any old death. */
12453 /* ??? So why do we test for equality of the sizes? */
12455 if (GET_CODE (dest
) == ZERO_EXTRACT
12456 || GET_CODE (dest
) == STRICT_LOW_PART
12457 || (GET_CODE (dest
) == SUBREG
12458 && (((GET_MODE_SIZE (GET_MODE (dest
))
12459 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
12460 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
12461 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
))))
12463 move_deaths (dest
, maybe_kill_insn
, from_cuid
, to_insn
, pnotes
);
12467 /* If this is some other SUBREG, we know it replaces the entire
12468 value, so use that as the destination. */
12469 if (GET_CODE (dest
) == SUBREG
)
12470 dest
= SUBREG_REG (dest
);
12472 /* If this is a MEM, adjust deaths of anything used in the address.
12473 For a REG (the only other possibility), the entire value is
12474 being replaced so the old value is not used in this insn. */
12476 if (GET_CODE (dest
) == MEM
)
12477 move_deaths (XEXP (dest
, 0), maybe_kill_insn
, from_cuid
,
12482 else if (GET_CODE (x
) == CLOBBER
)
12485 len
= GET_RTX_LENGTH (code
);
12486 fmt
= GET_RTX_FORMAT (code
);
12488 for (i
= 0; i
< len
; i
++)
12493 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
12494 move_deaths (XVECEXP (x
, i
, j
), maybe_kill_insn
, from_cuid
,
12497 else if (fmt
[i
] == 'e')
12498 move_deaths (XEXP (x
, i
), maybe_kill_insn
, from_cuid
, to_insn
, pnotes
);
12502 /* Return 1 if X is the target of a bit-field assignment in BODY, the
12503 pattern of an insn. X must be a REG. */
12506 reg_bitfield_target_p (x
, body
)
12512 if (GET_CODE (body
) == SET
)
12514 rtx dest
= SET_DEST (body
);
12516 unsigned int regno
, tregno
, endregno
, endtregno
;
12518 if (GET_CODE (dest
) == ZERO_EXTRACT
)
12519 target
= XEXP (dest
, 0);
12520 else if (GET_CODE (dest
) == STRICT_LOW_PART
)
12521 target
= SUBREG_REG (XEXP (dest
, 0));
12525 if (GET_CODE (target
) == SUBREG
)
12526 target
= SUBREG_REG (target
);
12528 if (GET_CODE (target
) != REG
)
12531 tregno
= REGNO (target
), regno
= REGNO (x
);
12532 if (tregno
>= FIRST_PSEUDO_REGISTER
|| regno
>= FIRST_PSEUDO_REGISTER
)
12533 return target
== x
;
12535 endtregno
= tregno
+ HARD_REGNO_NREGS (tregno
, GET_MODE (target
));
12536 endregno
= regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
));
12538 return endregno
> tregno
&& regno
< endtregno
;
12541 else if (GET_CODE (body
) == PARALLEL
)
12542 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
12543 if (reg_bitfield_target_p (x
, XVECEXP (body
, 0, i
)))
12549 /* Given a chain of REG_NOTES originally from FROM_INSN, try to place them
12550 as appropriate. I3 and I2 are the insns resulting from the combination
12551 insns including FROM (I2 may be zero).
12553 ELIM_I2 and ELIM_I1 are either zero or registers that we know will
12554 not need REG_DEAD notes because they are being substituted for. This
12555 saves searching in the most common cases.
12557 Each note in the list is either ignored or placed on some insns, depending
12558 on the type of note. */
12561 distribute_notes (notes
, from_insn
, i3
, i2
, elim_i2
, elim_i1
)
12565 rtx elim_i2
, elim_i1
;
12567 rtx note
, next_note
;
12570 for (note
= notes
; note
; note
= next_note
)
12572 rtx place
= 0, place2
= 0;
12574 /* If this NOTE references a pseudo register, ensure it references
12575 the latest copy of that register. */
12576 if (XEXP (note
, 0) && GET_CODE (XEXP (note
, 0)) == REG
12577 && REGNO (XEXP (note
, 0)) >= FIRST_PSEUDO_REGISTER
)
12578 XEXP (note
, 0) = regno_reg_rtx
[REGNO (XEXP (note
, 0))];
12580 next_note
= XEXP (note
, 1);
12581 switch (REG_NOTE_KIND (note
))
12585 /* Doesn't matter much where we put this, as long as it's somewhere.
12586 It is preferable to keep these notes on branches, which is most
12587 likely to be i3. */
12591 case REG_VTABLE_REF
:
12592 /* ??? Should remain with *a particular* memory load. Given the
12593 nature of vtable data, the last insn seems relatively safe. */
12597 case REG_NON_LOCAL_GOTO
:
12598 if (GET_CODE (i3
) == JUMP_INSN
)
12600 else if (i2
&& GET_CODE (i2
) == JUMP_INSN
)
12606 case REG_EH_REGION
:
12607 /* These notes must remain with the call or trapping instruction. */
12608 if (GET_CODE (i3
) == CALL_INSN
)
12610 else if (i2
&& GET_CODE (i2
) == CALL_INSN
)
12612 else if (flag_non_call_exceptions
)
12614 if (may_trap_p (i3
))
12616 else if (i2
&& may_trap_p (i2
))
12618 /* ??? Otherwise assume we've combined things such that we
12619 can now prove that the instructions can't trap. Drop the
12620 note in this case. */
12628 /* These notes must remain with the call. It should not be
12629 possible for both I2 and I3 to be a call. */
12630 if (GET_CODE (i3
) == CALL_INSN
)
12632 else if (i2
&& GET_CODE (i2
) == CALL_INSN
)
12639 /* Any clobbers for i3 may still exist, and so we must process
12640 REG_UNUSED notes from that insn.
12642 Any clobbers from i2 or i1 can only exist if they were added by
12643 recog_for_combine. In that case, recog_for_combine created the
12644 necessary REG_UNUSED notes. Trying to keep any original
12645 REG_UNUSED notes from these insns can cause incorrect output
12646 if it is for the same register as the original i3 dest.
12647 In that case, we will notice that the register is set in i3,
12648 and then add a REG_UNUSED note for the destination of i3, which
12649 is wrong. However, it is possible to have REG_UNUSED notes from
12650 i2 or i1 for register which were both used and clobbered, so
12651 we keep notes from i2 or i1 if they will turn into REG_DEAD
12654 /* If this register is set or clobbered in I3, put the note there
12655 unless there is one already. */
12656 if (reg_set_p (XEXP (note
, 0), PATTERN (i3
)))
12658 if (from_insn
!= i3
)
12661 if (! (GET_CODE (XEXP (note
, 0)) == REG
12662 ? find_regno_note (i3
, REG_UNUSED
, REGNO (XEXP (note
, 0)))
12663 : find_reg_note (i3
, REG_UNUSED
, XEXP (note
, 0))))
12666 /* Otherwise, if this register is used by I3, then this register
12667 now dies here, so we must put a REG_DEAD note here unless there
12669 else if (reg_referenced_p (XEXP (note
, 0), PATTERN (i3
))
12670 && ! (GET_CODE (XEXP (note
, 0)) == REG
12671 ? find_regno_note (i3
, REG_DEAD
,
12672 REGNO (XEXP (note
, 0)))
12673 : find_reg_note (i3
, REG_DEAD
, XEXP (note
, 0))))
12675 PUT_REG_NOTE_KIND (note
, REG_DEAD
);
12683 /* These notes say something about results of an insn. We can
12684 only support them if they used to be on I3 in which case they
12685 remain on I3. Otherwise they are ignored.
12687 If the note refers to an expression that is not a constant, we
12688 must also ignore the note since we cannot tell whether the
12689 equivalence is still true. It might be possible to do
12690 slightly better than this (we only have a problem if I2DEST
12691 or I1DEST is present in the expression), but it doesn't
12692 seem worth the trouble. */
12694 if (from_insn
== i3
12695 && (XEXP (note
, 0) == 0 || CONSTANT_P (XEXP (note
, 0))))
12700 case REG_NO_CONFLICT
:
12701 /* These notes say something about how a register is used. They must
12702 be present on any use of the register in I2 or I3. */
12703 if (reg_mentioned_p (XEXP (note
, 0), PATTERN (i3
)))
12706 if (i2
&& reg_mentioned_p (XEXP (note
, 0), PATTERN (i2
)))
12716 /* This can show up in several ways -- either directly in the
12717 pattern, or hidden off in the constant pool with (or without?)
12718 a REG_EQUAL note. */
12719 /* ??? Ignore the without-reg_equal-note problem for now. */
12720 if (reg_mentioned_p (XEXP (note
, 0), PATTERN (i3
))
12721 || ((tem
= find_reg_note (i3
, REG_EQUAL
, NULL_RTX
))
12722 && GET_CODE (XEXP (tem
, 0)) == LABEL_REF
12723 && XEXP (XEXP (tem
, 0), 0) == XEXP (note
, 0)))
12727 && (reg_mentioned_p (XEXP (note
, 0), PATTERN (i2
))
12728 || ((tem
= find_reg_note (i2
, REG_EQUAL
, NULL_RTX
))
12729 && GET_CODE (XEXP (tem
, 0)) == LABEL_REF
12730 && XEXP (XEXP (tem
, 0), 0) == XEXP (note
, 0))))
12738 /* Don't attach REG_LABEL note to a JUMP_INSN which has
12739 JUMP_LABEL already. Instead, decrement LABEL_NUSES. */
12740 if (place
&& GET_CODE (place
) == JUMP_INSN
&& JUMP_LABEL (place
))
12742 if (JUMP_LABEL (place
) != XEXP (note
, 0))
12744 if (GET_CODE (JUMP_LABEL (place
)) == CODE_LABEL
)
12745 LABEL_NUSES (JUMP_LABEL (place
))--;
12748 if (place2
&& GET_CODE (place2
) == JUMP_INSN
&& JUMP_LABEL (place2
))
12750 if (JUMP_LABEL (place2
) != XEXP (note
, 0))
12752 if (GET_CODE (JUMP_LABEL (place2
)) == CODE_LABEL
)
12753 LABEL_NUSES (JUMP_LABEL (place2
))--;
12760 /* These notes say something about the value of a register prior
12761 to the execution of an insn. It is too much trouble to see
12762 if the note is still correct in all situations. It is better
12763 to simply delete it. */
12767 /* If the insn previously containing this note still exists,
12768 put it back where it was. Otherwise move it to the previous
12769 insn. Adjust the corresponding REG_LIBCALL note. */
12770 if (GET_CODE (from_insn
) != NOTE
)
12774 tem
= find_reg_note (XEXP (note
, 0), REG_LIBCALL
, NULL_RTX
);
12775 place
= prev_real_insn (from_insn
);
12777 XEXP (tem
, 0) = place
;
12778 /* If we're deleting the last remaining instruction of a
12779 libcall sequence, don't add the notes. */
12780 else if (XEXP (note
, 0) == from_insn
)
12786 /* This is handled similarly to REG_RETVAL. */
12787 if (GET_CODE (from_insn
) != NOTE
)
12791 tem
= find_reg_note (XEXP (note
, 0), REG_RETVAL
, NULL_RTX
);
12792 place
= next_real_insn (from_insn
);
12794 XEXP (tem
, 0) = place
;
12795 /* If we're deleting the last remaining instruction of a
12796 libcall sequence, don't add the notes. */
12797 else if (XEXP (note
, 0) == from_insn
)
12803 /* If the register is used as an input in I3, it dies there.
12804 Similarly for I2, if it is nonzero and adjacent to I3.
12806 If the register is not used as an input in either I3 or I2
12807 and it is not one of the registers we were supposed to eliminate,
12808 there are two possibilities. We might have a non-adjacent I2
12809 or we might have somehow eliminated an additional register
12810 from a computation. For example, we might have had A & B where
12811 we discover that B will always be zero. In this case we will
12812 eliminate the reference to A.
12814 In both cases, we must search to see if we can find a previous
12815 use of A and put the death note there. */
12818 && GET_CODE (from_insn
) == CALL_INSN
12819 && find_reg_fusage (from_insn
, USE
, XEXP (note
, 0)))
12821 else if (reg_referenced_p (XEXP (note
, 0), PATTERN (i3
)))
12823 else if (i2
!= 0 && next_nonnote_insn (i2
) == i3
12824 && reg_referenced_p (XEXP (note
, 0), PATTERN (i2
)))
12827 if (rtx_equal_p (XEXP (note
, 0), elim_i2
)
12828 || rtx_equal_p (XEXP (note
, 0), elim_i1
))
12833 basic_block bb
= this_basic_block
;
12835 for (tem
= PREV_INSN (i3
); place
== 0; tem
= PREV_INSN (tem
))
12837 if (! INSN_P (tem
))
12839 if (tem
== bb
->head
)
12844 /* If the register is being set at TEM, see if that is all
12845 TEM is doing. If so, delete TEM. Otherwise, make this
12846 into a REG_UNUSED note instead. */
12847 if (reg_set_p (XEXP (note
, 0), PATTERN (tem
)))
12849 rtx set
= single_set (tem
);
12850 rtx inner_dest
= 0;
12852 rtx cc0_setter
= NULL_RTX
;
12856 for (inner_dest
= SET_DEST (set
);
12857 (GET_CODE (inner_dest
) == STRICT_LOW_PART
12858 || GET_CODE (inner_dest
) == SUBREG
12859 || GET_CODE (inner_dest
) == ZERO_EXTRACT
);
12860 inner_dest
= XEXP (inner_dest
, 0))
12863 /* Verify that it was the set, and not a clobber that
12864 modified the register.
12866 CC0 targets must be careful to maintain setter/user
12867 pairs. If we cannot delete the setter due to side
12868 effects, mark the user with an UNUSED note instead
12871 if (set
!= 0 && ! side_effects_p (SET_SRC (set
))
12872 && rtx_equal_p (XEXP (note
, 0), inner_dest
)
12874 && (! reg_mentioned_p (cc0_rtx
, SET_SRC (set
))
12875 || ((cc0_setter
= prev_cc0_setter (tem
)) != NULL
12876 && sets_cc0_p (PATTERN (cc0_setter
)) > 0))
12880 /* Move the notes and links of TEM elsewhere.
12881 This might delete other dead insns recursively.
12882 First set the pattern to something that won't use
12885 PATTERN (tem
) = pc_rtx
;
12887 distribute_notes (REG_NOTES (tem
), tem
, tem
,
12888 NULL_RTX
, NULL_RTX
, NULL_RTX
);
12889 distribute_links (LOG_LINKS (tem
));
12891 PUT_CODE (tem
, NOTE
);
12892 NOTE_LINE_NUMBER (tem
) = NOTE_INSN_DELETED
;
12893 NOTE_SOURCE_FILE (tem
) = 0;
12896 /* Delete the setter too. */
12899 PATTERN (cc0_setter
) = pc_rtx
;
12901 distribute_notes (REG_NOTES (cc0_setter
),
12902 cc0_setter
, cc0_setter
,
12903 NULL_RTX
, NULL_RTX
, NULL_RTX
);
12904 distribute_links (LOG_LINKS (cc0_setter
));
12906 PUT_CODE (cc0_setter
, NOTE
);
12907 NOTE_LINE_NUMBER (cc0_setter
)
12908 = NOTE_INSN_DELETED
;
12909 NOTE_SOURCE_FILE (cc0_setter
) = 0;
12913 /* If the register is both set and used here, put the
12914 REG_DEAD note here, but place a REG_UNUSED note
12915 here too unless there already is one. */
12916 else if (reg_referenced_p (XEXP (note
, 0),
12921 if (! find_regno_note (tem
, REG_UNUSED
,
12922 REGNO (XEXP (note
, 0))))
12924 = gen_rtx_EXPR_LIST (REG_UNUSED
, XEXP (note
, 0),
12929 PUT_REG_NOTE_KIND (note
, REG_UNUSED
);
12931 /* If there isn't already a REG_UNUSED note, put one
12933 if (! find_regno_note (tem
, REG_UNUSED
,
12934 REGNO (XEXP (note
, 0))))
12939 else if (reg_referenced_p (XEXP (note
, 0), PATTERN (tem
))
12940 || (GET_CODE (tem
) == CALL_INSN
12941 && find_reg_fusage (tem
, USE
, XEXP (note
, 0))))
12945 /* If we are doing a 3->2 combination, and we have a
12946 register which formerly died in i3 and was not used
12947 by i2, which now no longer dies in i3 and is used in
12948 i2 but does not die in i2, and place is between i2
12949 and i3, then we may need to move a link from place to
12951 if (i2
&& INSN_UID (place
) <= max_uid_cuid
12952 && INSN_CUID (place
) > INSN_CUID (i2
)
12954 && INSN_CUID (from_insn
) > INSN_CUID (i2
)
12955 && reg_referenced_p (XEXP (note
, 0), PATTERN (i2
)))
12957 rtx links
= LOG_LINKS (place
);
12958 LOG_LINKS (place
) = 0;
12959 distribute_links (links
);
12964 if (tem
== bb
->head
)
12968 /* We haven't found an insn for the death note and it
12969 is still a REG_DEAD note, but we have hit the beginning
12970 of the block. If the existing life info says the reg
12971 was dead, there's nothing left to do. Otherwise, we'll
12972 need to do a global life update after combine. */
12973 if (REG_NOTE_KIND (note
) == REG_DEAD
&& place
== 0
12974 && REGNO_REG_SET_P (bb
->global_live_at_start
,
12975 REGNO (XEXP (note
, 0))))
12976 SET_BIT (refresh_blocks
, this_basic_block
->index
);
12979 /* If the register is set or already dead at PLACE, we needn't do
12980 anything with this note if it is still a REG_DEAD note.
12981 We can here if it is set at all, not if is it totally replace,
12982 which is what `dead_or_set_p' checks, so also check for it being
12985 if (place
&& REG_NOTE_KIND (note
) == REG_DEAD
)
12987 unsigned int regno
= REGNO (XEXP (note
, 0));
12989 /* Similarly, if the instruction on which we want to place
12990 the note is a noop, we'll need do a global live update
12991 after we remove them in delete_noop_moves. */
12992 if (noop_move_p (place
))
12993 SET_BIT (refresh_blocks
, this_basic_block
->index
);
12995 if (dead_or_set_p (place
, XEXP (note
, 0))
12996 || reg_bitfield_target_p (XEXP (note
, 0), PATTERN (place
)))
12998 /* Unless the register previously died in PLACE, clear
12999 reg_last_death. [I no longer understand why this is
13001 if (reg_last_death
[regno
] != place
)
13002 reg_last_death
[regno
] = 0;
13006 reg_last_death
[regno
] = place
;
13008 /* If this is a death note for a hard reg that is occupying
13009 multiple registers, ensure that we are still using all
13010 parts of the object. If we find a piece of the object
13011 that is unused, we must arrange for an appropriate REG_DEAD
13012 note to be added for it. However, we can't just emit a USE
13013 and tag the note to it, since the register might actually
13014 be dead; so we recourse, and the recursive call then finds
13015 the previous insn that used this register. */
13017 if (place
&& regno
< FIRST_PSEUDO_REGISTER
13018 && HARD_REGNO_NREGS (regno
, GET_MODE (XEXP (note
, 0))) > 1)
13020 unsigned int endregno
13021 = regno
+ HARD_REGNO_NREGS (regno
,
13022 GET_MODE (XEXP (note
, 0)));
13026 for (i
= regno
; i
< endregno
; i
++)
13027 if ((! refers_to_regno_p (i
, i
+ 1, PATTERN (place
), 0)
13028 && ! find_regno_fusage (place
, USE
, i
))
13029 || dead_or_set_regno_p (place
, i
))
13034 /* Put only REG_DEAD notes for pieces that are
13035 not already dead or set. */
13037 for (i
= regno
; i
< endregno
;
13038 i
+= HARD_REGNO_NREGS (i
, reg_raw_mode
[i
]))
13040 rtx piece
= regno_reg_rtx
[i
];
13041 basic_block bb
= this_basic_block
;
13043 if (! dead_or_set_p (place
, piece
)
13044 && ! reg_bitfield_target_p (piece
,
13048 = gen_rtx_EXPR_LIST (REG_DEAD
, piece
, NULL_RTX
);
13050 distribute_notes (new_note
, place
, place
,
13051 NULL_RTX
, NULL_RTX
, NULL_RTX
);
13053 else if (! refers_to_regno_p (i
, i
+ 1,
13054 PATTERN (place
), 0)
13055 && ! find_regno_fusage (place
, USE
, i
))
13056 for (tem
= PREV_INSN (place
); ;
13057 tem
= PREV_INSN (tem
))
13059 if (! INSN_P (tem
))
13061 if (tem
== bb
->head
)
13063 SET_BIT (refresh_blocks
,
13064 this_basic_block
->index
);
13069 if (dead_or_set_p (tem
, piece
)
13070 || reg_bitfield_target_p (piece
,
13074 = gen_rtx_EXPR_LIST (REG_UNUSED
, piece
,
13089 /* Any other notes should not be present at this point in the
13096 XEXP (note
, 1) = REG_NOTES (place
);
13097 REG_NOTES (place
) = note
;
13099 else if ((REG_NOTE_KIND (note
) == REG_DEAD
13100 || REG_NOTE_KIND (note
) == REG_UNUSED
)
13101 && GET_CODE (XEXP (note
, 0)) == REG
)
13102 REG_N_DEATHS (REGNO (XEXP (note
, 0)))--;
13106 if ((REG_NOTE_KIND (note
) == REG_DEAD
13107 || REG_NOTE_KIND (note
) == REG_UNUSED
)
13108 && GET_CODE (XEXP (note
, 0)) == REG
)
13109 REG_N_DEATHS (REGNO (XEXP (note
, 0)))++;
13111 REG_NOTES (place2
) = gen_rtx_fmt_ee (GET_CODE (note
),
13112 REG_NOTE_KIND (note
),
13114 REG_NOTES (place2
));
13119 /* Similarly to above, distribute the LOG_LINKS that used to be present on
13120 I3, I2, and I1 to new locations. This is also called in one case to
13121 add a link pointing at I3 when I3's destination is changed. */
13124 distribute_links (links
)
13127 rtx link
, next_link
;
13129 for (link
= links
; link
; link
= next_link
)
13135 next_link
= XEXP (link
, 1);
13137 /* If the insn that this link points to is a NOTE or isn't a single
13138 set, ignore it. In the latter case, it isn't clear what we
13139 can do other than ignore the link, since we can't tell which
13140 register it was for. Such links wouldn't be used by combine
13143 It is not possible for the destination of the target of the link to
13144 have been changed by combine. The only potential of this is if we
13145 replace I3, I2, and I1 by I3 and I2. But in that case the
13146 destination of I2 also remains unchanged. */
13148 if (GET_CODE (XEXP (link
, 0)) == NOTE
13149 || (set
= single_set (XEXP (link
, 0))) == 0)
13152 reg
= SET_DEST (set
);
13153 while (GET_CODE (reg
) == SUBREG
|| GET_CODE (reg
) == ZERO_EXTRACT
13154 || GET_CODE (reg
) == SIGN_EXTRACT
13155 || GET_CODE (reg
) == STRICT_LOW_PART
)
13156 reg
= XEXP (reg
, 0);
13158 /* A LOG_LINK is defined as being placed on the first insn that uses
13159 a register and points to the insn that sets the register. Start
13160 searching at the next insn after the target of the link and stop
13161 when we reach a set of the register or the end of the basic block.
13163 Note that this correctly handles the link that used to point from
13164 I3 to I2. Also note that not much searching is typically done here
13165 since most links don't point very far away. */
13167 for (insn
= NEXT_INSN (XEXP (link
, 0));
13168 (insn
&& (this_basic_block
->next_bb
== EXIT_BLOCK_PTR
13169 || this_basic_block
->next_bb
->head
!= insn
));
13170 insn
= NEXT_INSN (insn
))
13171 if (INSN_P (insn
) && reg_overlap_mentioned_p (reg
, PATTERN (insn
)))
13173 if (reg_referenced_p (reg
, PATTERN (insn
)))
13177 else if (GET_CODE (insn
) == CALL_INSN
13178 && find_reg_fusage (insn
, USE
, reg
))
13184 /* If we found a place to put the link, place it there unless there
13185 is already a link to the same insn as LINK at that point. */
13191 for (link2
= LOG_LINKS (place
); link2
; link2
= XEXP (link2
, 1))
13192 if (XEXP (link2
, 0) == XEXP (link
, 0))
13197 XEXP (link
, 1) = LOG_LINKS (place
);
13198 LOG_LINKS (place
) = link
;
13200 /* Set added_links_insn to the earliest insn we added a
13202 if (added_links_insn
== 0
13203 || INSN_CUID (added_links_insn
) > INSN_CUID (place
))
13204 added_links_insn
= place
;
13210 /* Compute INSN_CUID for INSN, which is an insn made by combine. */
13216 while (insn
!= 0 && INSN_UID (insn
) > max_uid_cuid
13217 && GET_CODE (insn
) == INSN
&& GET_CODE (PATTERN (insn
)) == USE
)
13218 insn
= NEXT_INSN (insn
);
13220 if (INSN_UID (insn
) > max_uid_cuid
)
13223 return INSN_CUID (insn
);
13227 dump_combine_stats (file
)
13232 ";; Combiner statistics: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n\n",
13233 combine_attempts
, combine_merges
, combine_extras
, combine_successes
);
13237 dump_combine_total_stats (file
)
13242 "\n;; Combiner totals: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n",
13243 total_attempts
, total_merges
, total_extras
, total_successes
);