1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 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
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
36 #include "basic-block.h"
41 /* Forward declarations */
42 static int global_reg_mentioned_p_1 (rtx
*, void *);
43 static void set_of_1 (rtx
, rtx
, void *);
44 static void insn_dependent_p_1 (rtx
, rtx
, void *);
45 static int rtx_referenced_p_1 (rtx
*, void *);
46 static int computed_jump_p_1 (rtx
);
47 static void parms_set (rtx
, rtx
, void *);
48 static bool hoist_test_store (rtx
, rtx
, regset
);
49 static void hoist_update_store (rtx
, rtx
*, rtx
, rtx
);
51 static unsigned HOST_WIDE_INT
cached_nonzero_bits (rtx
, enum machine_mode
,
52 rtx
, enum machine_mode
,
53 unsigned HOST_WIDE_INT
);
54 static unsigned HOST_WIDE_INT
nonzero_bits1 (rtx
, enum machine_mode
, rtx
,
56 unsigned HOST_WIDE_INT
);
57 static unsigned int cached_num_sign_bit_copies (rtx
, enum machine_mode
, rtx
,
60 static unsigned int num_sign_bit_copies1 (rtx
, enum machine_mode
, rtx
,
61 enum machine_mode
, unsigned int);
63 /* Bit flags that specify the machine subtype we are compiling for.
64 Bits are tested using macros TARGET_... defined in the tm.h file
65 and set by `-m...' switches. Must be defined in rtlanal.c. */
69 /* Return 1 if the value of X is unstable
70 (would be different at a different point in the program).
71 The frame pointer, arg pointer, etc. are considered stable
72 (within one function) and so is anything marked `unchanging'. */
75 rtx_unstable_p (rtx x
)
77 RTX_CODE code
= GET_CODE (x
);
84 return ! RTX_UNCHANGING_P (x
) || rtx_unstable_p (XEXP (x
, 0));
99 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
100 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
101 /* The arg pointer varies if it is not a fixed register. */
102 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
])
103 || RTX_UNCHANGING_P (x
))
105 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
106 /* ??? When call-clobbered, the value is stable modulo the restore
107 that must happen after a call. This currently screws up local-alloc
108 into believing that the restore is not needed. */
109 if (x
== pic_offset_table_rtx
)
115 if (MEM_VOLATILE_P (x
))
124 fmt
= GET_RTX_FORMAT (code
);
125 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
128 if (rtx_unstable_p (XEXP (x
, i
)))
131 else if (fmt
[i
] == 'E')
134 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
135 if (rtx_unstable_p (XVECEXP (x
, i
, j
)))
142 /* Return 1 if X has a value that can vary even between two
143 executions of the program. 0 means X can be compared reliably
144 against certain constants or near-constants.
145 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
146 zero, we are slightly more conservative.
147 The frame pointer and the arg pointer are considered constant. */
150 rtx_varies_p (rtx x
, int for_alias
)
163 return ! RTX_UNCHANGING_P (x
) || rtx_varies_p (XEXP (x
, 0), for_alias
);
177 /* This will resolve to some offset from the frame pointer. */
181 /* Note that we have to test for the actual rtx used for the frame
182 and arg pointers and not just the register number in case we have
183 eliminated the frame and/or arg pointer and are using it
185 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
186 /* The arg pointer varies if it is not a fixed register. */
187 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
189 if (x
== pic_offset_table_rtx
190 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
191 /* ??? When call-clobbered, the value is stable modulo the restore
192 that must happen after a call. This currently screws up
193 local-alloc into believing that the restore is not needed, so we
194 must return 0 only if we are called from alias analysis. */
202 /* The operand 0 of a LO_SUM is considered constant
203 (in fact it is related specifically to operand 1)
204 during alias analysis. */
205 return (! for_alias
&& rtx_varies_p (XEXP (x
, 0), for_alias
))
206 || rtx_varies_p (XEXP (x
, 1), for_alias
);
209 if (MEM_VOLATILE_P (x
))
218 fmt
= GET_RTX_FORMAT (code
);
219 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
222 if (rtx_varies_p (XEXP (x
, i
), for_alias
))
225 else if (fmt
[i
] == 'E')
228 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
229 if (rtx_varies_p (XVECEXP (x
, i
, j
), for_alias
))
236 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
239 rtx_addr_can_trap_p (rtx x
)
241 enum rtx_code code
= GET_CODE (x
);
246 return SYMBOL_REF_WEAK (x
);
252 /* This will resolve to some offset from the frame pointer. */
256 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
257 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
258 || x
== stack_pointer_rtx
259 /* The arg pointer varies if it is not a fixed register. */
260 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
262 /* All of the virtual frame registers are stack references. */
263 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
264 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
269 return rtx_addr_can_trap_p (XEXP (x
, 0));
272 /* An address is assumed not to trap if it is an address that can't
273 trap plus a constant integer or it is the pic register plus a
275 return ! ((! rtx_addr_can_trap_p (XEXP (x
, 0))
276 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
277 || (XEXP (x
, 0) == pic_offset_table_rtx
278 && CONSTANT_P (XEXP (x
, 1))));
282 return rtx_addr_can_trap_p (XEXP (x
, 1));
289 return rtx_addr_can_trap_p (XEXP (x
, 0));
295 /* If it isn't one of the case above, it can cause a trap. */
299 /* Return true if X is an address that is known to not be zero. */
302 nonzero_address_p (rtx x
)
304 enum rtx_code code
= GET_CODE (x
);
309 return !SYMBOL_REF_WEAK (x
);
315 /* This will resolve to some offset from the frame pointer. */
319 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
320 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
321 || x
== stack_pointer_rtx
322 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
324 /* All of the virtual frame registers are stack references. */
325 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
326 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
331 return nonzero_address_p (XEXP (x
, 0));
334 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
336 /* Pointers aren't allowed to wrap. If we've got a register
337 that is known to be a pointer, and a positive offset, then
338 the composite can't be zero. */
339 if (INTVAL (XEXP (x
, 1)) > 0
340 && REG_P (XEXP (x
, 0))
341 && REG_POINTER (XEXP (x
, 0)))
344 return nonzero_address_p (XEXP (x
, 0));
346 /* Handle PIC references. */
347 else if (XEXP (x
, 0) == pic_offset_table_rtx
348 && CONSTANT_P (XEXP (x
, 1)))
353 /* Similar to the above; allow positive offsets. Further, since
354 auto-inc is only allowed in memories, the register must be a
356 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
357 && INTVAL (XEXP (x
, 1)) > 0)
359 return nonzero_address_p (XEXP (x
, 0));
362 /* Similarly. Further, the offset is always positive. */
369 return nonzero_address_p (XEXP (x
, 0));
372 return nonzero_address_p (XEXP (x
, 1));
378 /* If it isn't one of the case above, might be zero. */
382 /* Return 1 if X refers to a memory location whose address
383 cannot be compared reliably with constant addresses,
384 or if X refers to a BLKmode memory object.
385 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
386 zero, we are slightly more conservative. */
389 rtx_addr_varies_p (rtx x
, int for_alias
)
400 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0), for_alias
);
402 fmt
= GET_RTX_FORMAT (code
);
403 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
406 if (rtx_addr_varies_p (XEXP (x
, i
), for_alias
))
409 else if (fmt
[i
] == 'E')
412 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
413 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
), for_alias
))
419 /* Return the value of the integer term in X, if one is apparent;
421 Only obvious integer terms are detected.
422 This is used in cse.c with the `related_value' field. */
425 get_integer_term (rtx x
)
427 if (GET_CODE (x
) == CONST
)
430 if (GET_CODE (x
) == MINUS
431 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
432 return - INTVAL (XEXP (x
, 1));
433 if (GET_CODE (x
) == PLUS
434 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
435 return INTVAL (XEXP (x
, 1));
439 /* If X is a constant, return the value sans apparent integer term;
441 Only obvious integer terms are detected. */
444 get_related_value (rtx x
)
446 if (GET_CODE (x
) != CONST
)
449 if (GET_CODE (x
) == PLUS
450 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
452 else if (GET_CODE (x
) == MINUS
453 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
458 /* Given a tablejump insn INSN, return the RTL expression for the offset
459 into the jump table. If the offset cannot be determined, then return
462 If EARLIEST is nonzero, it is a pointer to a place where the earliest
463 insn used in locating the offset was found. */
466 get_jump_table_offset (rtx insn
, rtx
*earliest
)
478 if (!tablejump_p (insn
, &label
, &table
) || !(set
= single_set (insn
)))
483 /* Some targets (eg, ARM) emit a tablejump that also
484 contains the out-of-range target. */
485 if (GET_CODE (x
) == IF_THEN_ELSE
486 && GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
489 /* Search backwards and locate the expression stored in X. */
490 for (old_x
= NULL_RTX
; REG_P (x
) && x
!= old_x
;
491 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
494 /* If X is an expression using a relative address then strip
495 off the addition / subtraction of PC, PIC_OFFSET_TABLE_REGNUM,
496 or the jump table label. */
497 if (GET_CODE (PATTERN (table
)) == ADDR_DIFF_VEC
498 && (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
))
500 for (i
= 0; i
< 2; i
++)
505 if (y
== pc_rtx
|| y
== pic_offset_table_rtx
)
508 for (old_y
= NULL_RTX
; REG_P (y
) && y
!= old_y
;
509 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
512 if ((GET_CODE (y
) == LABEL_REF
&& XEXP (y
, 0) == label
))
521 for (old_x
= NULL_RTX
; REG_P (x
) && x
!= old_x
;
522 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
526 /* Strip off any sign or zero extension. */
527 if (GET_CODE (x
) == SIGN_EXTEND
|| GET_CODE (x
) == ZERO_EXTEND
)
531 for (old_x
= NULL_RTX
; REG_P (x
) && x
!= old_x
;
532 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
536 /* If X isn't a MEM then this isn't a tablejump we understand. */
537 if (GET_CODE (x
) != MEM
)
540 /* Strip off the MEM. */
543 for (old_x
= NULL_RTX
; REG_P (x
) && x
!= old_x
;
544 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
547 /* If X isn't a PLUS than this isn't a tablejump we understand. */
548 if (GET_CODE (x
) != PLUS
)
551 /* At this point we should have an expression representing the jump table
552 plus an offset. Examine each operand in order to determine which one
553 represents the jump table. Knowing that tells us that the other operand
554 must represent the offset. */
555 for (i
= 0; i
< 2; i
++)
560 for (old_y
= NULL_RTX
; REG_P (y
) && y
!= old_y
;
561 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
564 if ((GET_CODE (y
) == CONST
|| GET_CODE (y
) == LABEL_REF
)
565 && reg_mentioned_p (label
, y
))
574 /* Strip off the addition / subtraction of PIC_OFFSET_TABLE_REGNUM. */
575 if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
)
576 for (i
= 0; i
< 2; i
++)
577 if (XEXP (x
, i
) == pic_offset_table_rtx
)
586 /* Return the RTL expression representing the offset. */
590 /* A subroutine of global_reg_mentioned_p, returns 1 if *LOC mentions
591 a global register. */
594 global_reg_mentioned_p_1 (rtx
*loc
, void *data ATTRIBUTE_UNUSED
)
602 switch (GET_CODE (x
))
605 if (REG_P (SUBREG_REG (x
)))
607 if (REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
608 && global_regs
[subreg_regno (x
)])
616 if (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
630 /* A non-constant call might use a global register. */
640 /* Returns nonzero if X mentions a global register. */
643 global_reg_mentioned_p (rtx x
)
647 if (GET_CODE (x
) == CALL_INSN
)
649 if (! CONST_OR_PURE_CALL_P (x
))
651 x
= CALL_INSN_FUNCTION_USAGE (x
);
659 return for_each_rtx (&x
, global_reg_mentioned_p_1
, NULL
);
662 /* Return the number of places FIND appears within X. If COUNT_DEST is
663 zero, we do not count occurrences inside the destination of a SET. */
666 count_occurrences (rtx x
, rtx find
, int count_dest
)
670 const char *format_ptr
;
691 if (GET_CODE (find
) == MEM
&& rtx_equal_p (x
, find
))
696 if (SET_DEST (x
) == find
&& ! count_dest
)
697 return count_occurrences (SET_SRC (x
), find
, count_dest
);
704 format_ptr
= GET_RTX_FORMAT (code
);
707 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
709 switch (*format_ptr
++)
712 count
+= count_occurrences (XEXP (x
, i
), find
, count_dest
);
716 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
717 count
+= count_occurrences (XVECEXP (x
, i
, j
), find
, count_dest
);
724 /* Nonzero if register REG appears somewhere within IN.
725 Also works if REG is not a register; in this case it checks
726 for a subexpression of IN that is Lisp "equal" to REG. */
729 reg_mentioned_p (rtx reg
, rtx in
)
741 if (GET_CODE (in
) == LABEL_REF
)
742 return reg
== XEXP (in
, 0);
744 code
= GET_CODE (in
);
748 /* Compare registers by number. */
750 return REG_P (reg
) && REGNO (in
) == REGNO (reg
);
752 /* These codes have no constituent expressions
762 /* These are kept unique for a given value. */
769 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
772 fmt
= GET_RTX_FORMAT (code
);
774 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
779 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
780 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
783 else if (fmt
[i
] == 'e'
784 && reg_mentioned_p (reg
, XEXP (in
, i
)))
790 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
791 no CODE_LABEL insn. */
794 no_labels_between_p (rtx beg
, rtx end
)
799 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
800 if (GET_CODE (p
) == CODE_LABEL
)
805 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
806 no JUMP_INSN insn. */
809 no_jumps_between_p (rtx beg
, rtx end
)
812 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
813 if (GET_CODE (p
) == JUMP_INSN
)
818 /* Nonzero if register REG is used in an insn between
819 FROM_INSN and TO_INSN (exclusive of those two). */
822 reg_used_between_p (rtx reg
, rtx from_insn
, rtx to_insn
)
826 if (from_insn
== to_insn
)
829 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
831 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
832 || (GET_CODE (insn
) == CALL_INSN
833 && (find_reg_fusage (insn
, USE
, reg
)
834 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
839 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
840 is entirely replaced by a new value and the only use is as a SET_DEST,
841 we do not consider it a reference. */
844 reg_referenced_p (rtx x
, rtx body
)
848 switch (GET_CODE (body
))
851 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
854 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
855 of a REG that occupies all of the REG, the insn references X if
856 it is mentioned in the destination. */
857 if (GET_CODE (SET_DEST (body
)) != CC0
858 && GET_CODE (SET_DEST (body
)) != PC
859 && !REG_P (SET_DEST (body
))
860 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
861 && REG_P (SUBREG_REG (SET_DEST (body
)))
862 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
863 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
864 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
865 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
866 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
871 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
872 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
879 return reg_overlap_mentioned_p (x
, body
);
882 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
885 return reg_overlap_mentioned_p (x
, XEXP (body
, 0));
888 case UNSPEC_VOLATILE
:
889 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
890 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
895 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
896 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
901 if (GET_CODE (XEXP (body
, 0)) == MEM
)
902 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
907 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
909 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
916 /* Nonzero if register REG is referenced in an insn between
917 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
921 reg_referenced_between_p (rtx reg
, rtx from_insn
, rtx to_insn
)
925 if (from_insn
== to_insn
)
928 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
930 && (reg_referenced_p (reg
, PATTERN (insn
))
931 || (GET_CODE (insn
) == CALL_INSN
932 && find_reg_fusage (insn
, USE
, reg
))))
937 /* Nonzero if register REG is set or clobbered in an insn between
938 FROM_INSN and TO_INSN (exclusive of those two). */
941 reg_set_between_p (rtx reg
, rtx from_insn
, rtx to_insn
)
945 if (from_insn
== to_insn
)
948 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
949 if (INSN_P (insn
) && reg_set_p (reg
, insn
))
954 /* Internals of reg_set_between_p. */
956 reg_set_p (rtx reg
, rtx insn
)
958 /* We can be passed an insn or part of one. If we are passed an insn,
959 check if a side-effect of the insn clobbers REG. */
961 && (FIND_REG_INC_NOTE (insn
, reg
)
962 || (GET_CODE (insn
) == CALL_INSN
963 /* We'd like to test call_used_regs here, but rtlanal.c can't
964 reference that variable due to its use in genattrtab. So
965 we'll just be more conservative.
967 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
968 information holds all clobbered registers. */
970 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
971 || GET_CODE (reg
) == MEM
972 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
975 return set_of (reg
, insn
) != NULL_RTX
;
978 /* Similar to reg_set_between_p, but check all registers in X. Return 0
979 only if none of them are modified between START and END. Do not
980 consider non-registers one way or the other. */
983 regs_set_between_p (rtx x
, rtx start
, rtx end
)
985 enum rtx_code code
= GET_CODE (x
);
1002 return reg_set_between_p (x
, start
, end
);
1008 fmt
= GET_RTX_FORMAT (code
);
1009 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1011 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
1014 else if (fmt
[i
] == 'E')
1015 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1016 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
1023 /* Similar to reg_set_between_p, but check all registers in X. Return 0
1024 only if none of them are modified between START and END. Return 1 if
1025 X contains a MEM; this routine does usememory aliasing. */
1028 modified_between_p (rtx x
, rtx start
, rtx end
)
1030 enum rtx_code code
= GET_CODE (x
);
1053 if (RTX_UNCHANGING_P (x
))
1055 if (modified_between_p (XEXP (x
, 0), start
, end
))
1057 for (insn
= NEXT_INSN (start
); insn
!= end
; insn
= NEXT_INSN (insn
))
1058 if (memory_modified_in_insn_p (x
, insn
))
1064 return reg_set_between_p (x
, start
, end
);
1070 fmt
= GET_RTX_FORMAT (code
);
1071 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1073 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
1076 else if (fmt
[i
] == 'E')
1077 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1078 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
1085 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
1086 of them are modified in INSN. Return 1 if X contains a MEM; this routine
1087 does use memory aliasing. */
1090 modified_in_p (rtx x
, rtx insn
)
1092 enum rtx_code code
= GET_CODE (x
);
1111 if (RTX_UNCHANGING_P (x
))
1113 if (modified_in_p (XEXP (x
, 0), insn
))
1115 if (memory_modified_in_insn_p (x
, insn
))
1121 return reg_set_p (x
, insn
);
1127 fmt
= GET_RTX_FORMAT (code
);
1128 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1130 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
1133 else if (fmt
[i
] == 'E')
1134 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1135 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
1142 /* Return true if anything in insn X is (anti,output,true) dependent on
1143 anything in insn Y. */
1146 insn_dependent_p (rtx x
, rtx y
)
1150 if (! INSN_P (x
) || ! INSN_P (y
))
1154 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
1155 if (tmp
== NULL_RTX
)
1159 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
1160 if (tmp
== NULL_RTX
)
1166 /* A helper routine for insn_dependent_p called through note_stores. */
1169 insn_dependent_p_1 (rtx x
, rtx pat ATTRIBUTE_UNUSED
, void *data
)
1171 rtx
* pinsn
= (rtx
*) data
;
1173 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
1177 /* Helper function for set_of. */
1185 set_of_1 (rtx x
, rtx pat
, void *data1
)
1187 struct set_of_data
*data
= (struct set_of_data
*) (data1
);
1188 if (rtx_equal_p (x
, data
->pat
)
1189 || (GET_CODE (x
) != MEM
&& reg_overlap_mentioned_p (data
->pat
, x
)))
1193 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
1194 (either directly or via STRICT_LOW_PART and similar modifiers). */
1196 set_of (rtx pat
, rtx insn
)
1198 struct set_of_data data
;
1199 data
.found
= NULL_RTX
;
1201 note_stores (INSN_P (insn
) ? PATTERN (insn
) : insn
, set_of_1
, &data
);
1205 /* Given an INSN, return a SET expression if this insn has only a single SET.
1206 It may also have CLOBBERs, USEs, or SET whose output
1207 will not be used, which we ignore. */
1210 single_set_2 (rtx insn
, rtx pat
)
1213 int set_verified
= 1;
1216 if (GET_CODE (pat
) == PARALLEL
)
1218 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1220 rtx sub
= XVECEXP (pat
, 0, i
);
1221 switch (GET_CODE (sub
))
1228 /* We can consider insns having multiple sets, where all
1229 but one are dead as single set insns. In common case
1230 only single set is present in the pattern so we want
1231 to avoid checking for REG_UNUSED notes unless necessary.
1233 When we reach set first time, we just expect this is
1234 the single set we are looking for and only when more
1235 sets are found in the insn, we check them. */
1238 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (set
))
1239 && !side_effects_p (set
))
1245 set
= sub
, set_verified
= 0;
1246 else if (!find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
1247 || side_effects_p (sub
))
1259 /* Given an INSN, return nonzero if it has more than one SET, else return
1263 multiple_sets (rtx insn
)
1268 /* INSN must be an insn. */
1269 if (! INSN_P (insn
))
1272 /* Only a PARALLEL can have multiple SETs. */
1273 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1275 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1276 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1278 /* If we have already found a SET, then return now. */
1286 /* Either zero or one SET. */
1290 /* Return nonzero if the destination of SET equals the source
1291 and there are no side effects. */
1294 set_noop_p (rtx set
)
1296 rtx src
= SET_SRC (set
);
1297 rtx dst
= SET_DEST (set
);
1299 if (dst
== pc_rtx
&& src
== pc_rtx
)
1302 if (GET_CODE (dst
) == MEM
&& GET_CODE (src
) == MEM
)
1303 return rtx_equal_p (dst
, src
) && !side_effects_p (dst
);
1305 if (GET_CODE (dst
) == SIGN_EXTRACT
1306 || GET_CODE (dst
) == ZERO_EXTRACT
)
1307 return rtx_equal_p (XEXP (dst
, 0), src
)
1308 && ! BYTES_BIG_ENDIAN
&& XEXP (dst
, 2) == const0_rtx
1309 && !side_effects_p (src
);
1311 if (GET_CODE (dst
) == STRICT_LOW_PART
)
1312 dst
= XEXP (dst
, 0);
1314 if (GET_CODE (src
) == SUBREG
&& GET_CODE (dst
) == SUBREG
)
1316 if (SUBREG_BYTE (src
) != SUBREG_BYTE (dst
))
1318 src
= SUBREG_REG (src
);
1319 dst
= SUBREG_REG (dst
);
1322 return (REG_P (src
) && REG_P (dst
)
1323 && REGNO (src
) == REGNO (dst
));
1326 /* Return nonzero if an insn consists only of SETs, each of which only sets a
1330 noop_move_p (rtx insn
)
1332 rtx pat
= PATTERN (insn
);
1334 if (INSN_CODE (insn
) == NOOP_MOVE_INSN_CODE
)
1337 /* Insns carrying these notes are useful later on. */
1338 if (find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1341 /* For now treat an insn with a REG_RETVAL note as a
1342 a special insn which should not be considered a no-op. */
1343 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
1346 if (GET_CODE (pat
) == SET
&& set_noop_p (pat
))
1349 if (GET_CODE (pat
) == PARALLEL
)
1352 /* If nothing but SETs of registers to themselves,
1353 this insn can also be deleted. */
1354 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1356 rtx tem
= XVECEXP (pat
, 0, i
);
1358 if (GET_CODE (tem
) == USE
1359 || GET_CODE (tem
) == CLOBBER
)
1362 if (GET_CODE (tem
) != SET
|| ! set_noop_p (tem
))
1372 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
1373 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
1374 If the object was modified, if we hit a partial assignment to X, or hit a
1375 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
1376 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
1380 find_last_value (rtx x
, rtx
*pinsn
, rtx valid_to
, int allow_hwreg
)
1384 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
1388 rtx set
= single_set (p
);
1389 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
1391 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
1393 rtx src
= SET_SRC (set
);
1395 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
1396 src
= XEXP (note
, 0);
1398 if ((valid_to
== NULL_RTX
1399 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
1400 /* Reject hard registers because we don't usually want
1401 to use them; we'd rather use a pseudo. */
1403 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
1410 /* If set in non-simple way, we don't have a value. */
1411 if (reg_set_p (x
, p
))
1418 /* Return nonzero if register in range [REGNO, ENDREGNO)
1419 appears either explicitly or implicitly in X
1420 other than being stored into.
1422 References contained within the substructure at LOC do not count.
1423 LOC may be zero, meaning don't ignore anything. */
1426 refers_to_regno_p (unsigned int regno
, unsigned int endregno
, rtx x
,
1430 unsigned int x_regno
;
1435 /* The contents of a REG_NONNEG note is always zero, so we must come here
1436 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1440 code
= GET_CODE (x
);
1445 x_regno
= REGNO (x
);
1447 /* If we modifying the stack, frame, or argument pointer, it will
1448 clobber a virtual register. In fact, we could be more precise,
1449 but it isn't worth it. */
1450 if ((x_regno
== STACK_POINTER_REGNUM
1451 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1452 || x_regno
== ARG_POINTER_REGNUM
1454 || x_regno
== FRAME_POINTER_REGNUM
)
1455 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
1458 return (endregno
> x_regno
1459 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
1460 ? hard_regno_nregs
[x_regno
][GET_MODE (x
)]
1464 /* If this is a SUBREG of a hard reg, we can see exactly which
1465 registers are being modified. Otherwise, handle normally. */
1466 if (REG_P (SUBREG_REG (x
))
1467 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
1469 unsigned int inner_regno
= subreg_regno (x
);
1470 unsigned int inner_endregno
1471 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
1472 ? hard_regno_nregs
[inner_regno
][GET_MODE (x
)] : 1);
1474 return endregno
> inner_regno
&& regno
< inner_endregno
;
1480 if (&SET_DEST (x
) != loc
1481 /* Note setting a SUBREG counts as referring to the REG it is in for
1482 a pseudo but not for hard registers since we can
1483 treat each word individually. */
1484 && ((GET_CODE (SET_DEST (x
)) == SUBREG
1485 && loc
!= &SUBREG_REG (SET_DEST (x
))
1486 && REG_P (SUBREG_REG (SET_DEST (x
)))
1487 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
1488 && refers_to_regno_p (regno
, endregno
,
1489 SUBREG_REG (SET_DEST (x
)), loc
))
1490 || (!REG_P (SET_DEST (x
))
1491 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
1494 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
1503 /* X does not match, so try its subexpressions. */
1505 fmt
= GET_RTX_FORMAT (code
);
1506 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1508 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
1516 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
1519 else if (fmt
[i
] == 'E')
1522 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1523 if (loc
!= &XVECEXP (x
, i
, j
)
1524 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
1531 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1532 we check if any register number in X conflicts with the relevant register
1533 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1534 contains a MEM (we don't bother checking for memory addresses that can't
1535 conflict because we expect this to be a rare case. */
1538 reg_overlap_mentioned_p (rtx x
, rtx in
)
1540 unsigned int regno
, endregno
;
1542 /* If either argument is a constant, then modifying X can not
1543 affect IN. Here we look at IN, we can profitably combine
1544 CONSTANT_P (x) with the switch statement below. */
1545 if (CONSTANT_P (in
))
1549 switch (GET_CODE (x
))
1551 case STRICT_LOW_PART
:
1554 /* Overly conservative. */
1559 regno
= REGNO (SUBREG_REG (x
));
1560 if (regno
< FIRST_PSEUDO_REGISTER
)
1561 regno
= subreg_regno (x
);
1567 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1568 ? hard_regno_nregs
[regno
][GET_MODE (x
)] : 1);
1569 return refers_to_regno_p (regno
, endregno
, in
, (rtx
*) 0);
1576 if (GET_CODE (in
) == MEM
)
1579 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1580 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1581 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1590 return reg_mentioned_p (x
, in
);
1596 /* If any register in here refers to it we return true. */
1597 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1598 if (XEXP (XVECEXP (x
, 0, i
), 0) != 0
1599 && reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1605 #ifdef ENABLE_CHECKING
1606 if (!CONSTANT_P (x
))
1614 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1615 (X would be the pattern of an insn).
1616 FUN receives two arguments:
1617 the REG, MEM, CC0 or PC being stored in or clobbered,
1618 the SET or CLOBBER rtx that does the store.
1620 If the item being stored in or clobbered is a SUBREG of a hard register,
1621 the SUBREG will be passed. */
1624 note_stores (rtx x
, void (*fun
) (rtx
, rtx
, void *), void *data
)
1628 if (GET_CODE (x
) == COND_EXEC
)
1629 x
= COND_EXEC_CODE (x
);
1631 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1633 rtx dest
= SET_DEST (x
);
1635 while ((GET_CODE (dest
) == SUBREG
1636 && (!REG_P (SUBREG_REG (dest
))
1637 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1638 || GET_CODE (dest
) == ZERO_EXTRACT
1639 || GET_CODE (dest
) == SIGN_EXTRACT
1640 || GET_CODE (dest
) == STRICT_LOW_PART
)
1641 dest
= XEXP (dest
, 0);
1643 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1644 each of whose first operand is a register. */
1645 if (GET_CODE (dest
) == PARALLEL
)
1647 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1648 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
1649 (*fun
) (XEXP (XVECEXP (dest
, 0, i
), 0), x
, data
);
1652 (*fun
) (dest
, x
, data
);
1655 else if (GET_CODE (x
) == PARALLEL
)
1656 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1657 note_stores (XVECEXP (x
, 0, i
), fun
, data
);
1660 /* Like notes_stores, but call FUN for each expression that is being
1661 referenced in PBODY, a pointer to the PATTERN of an insn. We only call
1662 FUN for each expression, not any interior subexpressions. FUN receives a
1663 pointer to the expression and the DATA passed to this function.
1665 Note that this is not quite the same test as that done in reg_referenced_p
1666 since that considers something as being referenced if it is being
1667 partially set, while we do not. */
1670 note_uses (rtx
*pbody
, void (*fun
) (rtx
*, void *), void *data
)
1675 switch (GET_CODE (body
))
1678 (*fun
) (&COND_EXEC_TEST (body
), data
);
1679 note_uses (&COND_EXEC_CODE (body
), fun
, data
);
1683 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1684 note_uses (&XVECEXP (body
, 0, i
), fun
, data
);
1688 (*fun
) (&XEXP (body
, 0), data
);
1692 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
1693 (*fun
) (&ASM_OPERANDS_INPUT (body
, i
), data
);
1697 (*fun
) (&TRAP_CONDITION (body
), data
);
1701 (*fun
) (&XEXP (body
, 0), data
);
1705 case UNSPEC_VOLATILE
:
1706 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1707 (*fun
) (&XVECEXP (body
, 0, i
), data
);
1711 if (GET_CODE (XEXP (body
, 0)) == MEM
)
1712 (*fun
) (&XEXP (XEXP (body
, 0), 0), data
);
1717 rtx dest
= SET_DEST (body
);
1719 /* For sets we replace everything in source plus registers in memory
1720 expression in store and operands of a ZERO_EXTRACT. */
1721 (*fun
) (&SET_SRC (body
), data
);
1723 if (GET_CODE (dest
) == ZERO_EXTRACT
)
1725 (*fun
) (&XEXP (dest
, 1), data
);
1726 (*fun
) (&XEXP (dest
, 2), data
);
1729 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
)
1730 dest
= XEXP (dest
, 0);
1732 if (GET_CODE (dest
) == MEM
)
1733 (*fun
) (&XEXP (dest
, 0), data
);
1738 /* All the other possibilities never store. */
1739 (*fun
) (pbody
, data
);
1744 /* Return nonzero if X's old contents don't survive after INSN.
1745 This will be true if X is (cc0) or if X is a register and
1746 X dies in INSN or because INSN entirely sets X.
1748 "Entirely set" means set directly and not through a SUBREG,
1749 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1750 Likewise, REG_INC does not count.
1752 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1753 but for this use that makes no difference, since regs don't overlap
1754 during their lifetimes. Therefore, this function may be used
1755 at any time after deaths have been computed (in flow.c).
1757 If REG is a hard reg that occupies multiple machine registers, this
1758 function will only return 1 if each of those registers will be replaced
1762 dead_or_set_p (rtx insn
, rtx x
)
1764 unsigned int regno
, last_regno
;
1767 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1768 if (GET_CODE (x
) == CC0
)
1775 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1776 : regno
+ hard_regno_nregs
[regno
][GET_MODE (x
)] - 1);
1778 for (i
= regno
; i
<= last_regno
; i
++)
1779 if (! dead_or_set_regno_p (insn
, i
))
1785 /* Utility function for dead_or_set_p to check an individual register. Also
1786 called from flow.c. */
1789 dead_or_set_regno_p (rtx insn
, unsigned int test_regno
)
1791 unsigned int regno
, endregno
;
1794 /* See if there is a death note for something that includes TEST_REGNO. */
1795 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1798 if (GET_CODE (insn
) == CALL_INSN
1799 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1802 pattern
= PATTERN (insn
);
1804 if (GET_CODE (pattern
) == COND_EXEC
)
1805 pattern
= COND_EXEC_CODE (pattern
);
1807 if (GET_CODE (pattern
) == SET
)
1809 rtx dest
= SET_DEST (pattern
);
1811 /* A value is totally replaced if it is the destination or the
1812 destination is a SUBREG of REGNO that does not change the number of
1814 if (GET_CODE (dest
) == SUBREG
1815 && (((GET_MODE_SIZE (GET_MODE (dest
))
1816 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1817 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1818 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1819 dest
= SUBREG_REG (dest
);
1824 regno
= REGNO (dest
);
1825 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1826 : regno
+ hard_regno_nregs
[regno
][GET_MODE (dest
)]);
1828 return (test_regno
>= regno
&& test_regno
< endregno
);
1830 else if (GET_CODE (pattern
) == PARALLEL
)
1834 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1836 rtx body
= XVECEXP (pattern
, 0, i
);
1838 if (GET_CODE (body
) == COND_EXEC
)
1839 body
= COND_EXEC_CODE (body
);
1841 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1843 rtx dest
= SET_DEST (body
);
1845 if (GET_CODE (dest
) == SUBREG
1846 && (((GET_MODE_SIZE (GET_MODE (dest
))
1847 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1848 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1849 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1850 dest
= SUBREG_REG (dest
);
1855 regno
= REGNO (dest
);
1856 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1857 : regno
+ hard_regno_nregs
[regno
][GET_MODE (dest
)]);
1859 if (test_regno
>= regno
&& test_regno
< endregno
)
1868 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1869 If DATUM is nonzero, look for one whose datum is DATUM. */
1872 find_reg_note (rtx insn
, enum reg_note kind
, rtx datum
)
1876 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1877 if (! INSN_P (insn
))
1881 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1882 if (REG_NOTE_KIND (link
) == kind
)
1887 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1888 if (REG_NOTE_KIND (link
) == kind
&& datum
== XEXP (link
, 0))
1893 /* Return the reg-note of kind KIND in insn INSN which applies to register
1894 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1895 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1896 it might be the case that the note overlaps REGNO. */
1899 find_regno_note (rtx insn
, enum reg_note kind
, unsigned int regno
)
1903 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1904 if (! INSN_P (insn
))
1907 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1908 if (REG_NOTE_KIND (link
) == kind
1909 /* Verify that it is a register, so that scratch and MEM won't cause a
1911 && REG_P (XEXP (link
, 0))
1912 && REGNO (XEXP (link
, 0)) <= regno
1913 && ((REGNO (XEXP (link
, 0))
1914 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1915 : hard_regno_nregs
[REGNO (XEXP (link
, 0))]
1916 [GET_MODE (XEXP (link
, 0))]))
1922 /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
1926 find_reg_equal_equiv_note (rtx insn
)
1932 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1933 if (REG_NOTE_KIND (link
) == REG_EQUAL
1934 || REG_NOTE_KIND (link
) == REG_EQUIV
)
1936 if (single_set (insn
) == 0)
1943 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1944 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1947 find_reg_fusage (rtx insn
, enum rtx_code code
, rtx datum
)
1949 /* If it's not a CALL_INSN, it can't possibly have a
1950 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1951 if (GET_CODE (insn
) != CALL_INSN
)
1961 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1963 link
= XEXP (link
, 1))
1964 if (GET_CODE (XEXP (link
, 0)) == code
1965 && rtx_equal_p (datum
, XEXP (XEXP (link
, 0), 0)))
1970 unsigned int regno
= REGNO (datum
);
1972 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1973 to pseudo registers, so don't bother checking. */
1975 if (regno
< FIRST_PSEUDO_REGISTER
)
1977 unsigned int end_regno
1978 = regno
+ hard_regno_nregs
[regno
][GET_MODE (datum
)];
1981 for (i
= regno
; i
< end_regno
; i
++)
1982 if (find_regno_fusage (insn
, code
, i
))
1990 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1991 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1994 find_regno_fusage (rtx insn
, enum rtx_code code
, unsigned int regno
)
1998 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1999 to pseudo registers, so don't bother checking. */
2001 if (regno
>= FIRST_PSEUDO_REGISTER
2002 || GET_CODE (insn
) != CALL_INSN
)
2005 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2007 unsigned int regnote
;
2010 if (GET_CODE (op
= XEXP (link
, 0)) == code
2011 && REG_P (reg
= XEXP (op
, 0))
2012 && (regnote
= REGNO (reg
)) <= regno
2013 && regnote
+ hard_regno_nregs
[regnote
][GET_MODE (reg
)] > regno
)
2020 /* Return true if INSN is a call to a pure function. */
2023 pure_call_p (rtx insn
)
2027 if (GET_CODE (insn
) != CALL_INSN
|| ! CONST_OR_PURE_CALL_P (insn
))
2030 /* Look for the note that differentiates const and pure functions. */
2031 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2035 if (GET_CODE (u
= XEXP (link
, 0)) == USE
2036 && GET_CODE (m
= XEXP (u
, 0)) == MEM
&& GET_MODE (m
) == BLKmode
2037 && GET_CODE (XEXP (m
, 0)) == SCRATCH
)
2044 /* Remove register note NOTE from the REG_NOTES of INSN. */
2047 remove_note (rtx insn
, rtx note
)
2051 if (note
== NULL_RTX
)
2054 if (REG_NOTES (insn
) == note
)
2056 REG_NOTES (insn
) = XEXP (note
, 1);
2060 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2061 if (XEXP (link
, 1) == note
)
2063 XEXP (link
, 1) = XEXP (note
, 1);
2070 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2071 return 1 if it is found. A simple equality test is used to determine if
2075 in_expr_list_p (rtx listp
, rtx node
)
2079 for (x
= listp
; x
; x
= XEXP (x
, 1))
2080 if (node
== XEXP (x
, 0))
2086 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2087 remove that entry from the list if it is found.
2089 A simple equality test is used to determine if NODE matches. */
2092 remove_node_from_expr_list (rtx node
, rtx
*listp
)
2095 rtx prev
= NULL_RTX
;
2099 if (node
== XEXP (temp
, 0))
2101 /* Splice the node out of the list. */
2103 XEXP (prev
, 1) = XEXP (temp
, 1);
2105 *listp
= XEXP (temp
, 1);
2111 temp
= XEXP (temp
, 1);
2115 /* Nonzero if X contains any volatile instructions. These are instructions
2116 which may cause unpredictable machine state instructions, and thus no
2117 instructions should be moved or combined across them. This includes
2118 only volatile asms and UNSPEC_VOLATILE instructions. */
2121 volatile_insn_p (rtx x
)
2125 code
= GET_CODE (x
);
2145 case UNSPEC_VOLATILE
:
2146 /* case TRAP_IF: This isn't clear yet. */
2151 if (MEM_VOLATILE_P (x
))
2158 /* Recursively scan the operands of this expression. */
2161 const char *fmt
= GET_RTX_FORMAT (code
);
2164 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2168 if (volatile_insn_p (XEXP (x
, i
)))
2171 else if (fmt
[i
] == 'E')
2174 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2175 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
2183 /* Nonzero if X contains any volatile memory references
2184 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
2187 volatile_refs_p (rtx x
)
2191 code
= GET_CODE (x
);
2209 case UNSPEC_VOLATILE
:
2215 if (MEM_VOLATILE_P (x
))
2222 /* Recursively scan the operands of this expression. */
2225 const char *fmt
= GET_RTX_FORMAT (code
);
2228 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2232 if (volatile_refs_p (XEXP (x
, i
)))
2235 else if (fmt
[i
] == 'E')
2238 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2239 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
2247 /* Similar to above, except that it also rejects register pre- and post-
2251 side_effects_p (rtx x
)
2255 code
= GET_CODE (x
);
2273 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
2274 when some combination can't be done. If we see one, don't think
2275 that we can simplify the expression. */
2276 return (GET_MODE (x
) != VOIDmode
);
2285 case UNSPEC_VOLATILE
:
2286 /* case TRAP_IF: This isn't clear yet. */
2292 if (MEM_VOLATILE_P (x
))
2299 /* Recursively scan the operands of this expression. */
2302 const char *fmt
= GET_RTX_FORMAT (code
);
2305 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2309 if (side_effects_p (XEXP (x
, i
)))
2312 else if (fmt
[i
] == 'E')
2315 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2316 if (side_effects_p (XVECEXP (x
, i
, j
)))
2324 /* Return nonzero if evaluating rtx X might cause a trap. */
2335 code
= GET_CODE (x
);
2338 /* Handle these cases quickly. */
2352 case UNSPEC_VOLATILE
:
2357 return MEM_VOLATILE_P (x
);
2359 /* Memory ref can trap unless it's a static var or a stack slot. */
2361 if (MEM_NOTRAP_P (x
))
2363 return rtx_addr_can_trap_p (XEXP (x
, 0));
2365 /* Division by a non-constant might trap. */
2370 if (HONOR_SNANS (GET_MODE (x
)))
2372 if (! CONSTANT_P (XEXP (x
, 1))
2373 || (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2374 && flag_trapping_math
))
2376 if (XEXP (x
, 1) == const0_rtx
)
2381 /* An EXPR_LIST is used to represent a function call. This
2382 certainly may trap. */
2390 /* Some floating point comparisons may trap. */
2391 if (!flag_trapping_math
)
2393 /* ??? There is no machine independent way to check for tests that trap
2394 when COMPARE is used, though many targets do make this distinction.
2395 For instance, sparc uses CCFPE for compares which generate exceptions
2396 and CCFP for compares which do not generate exceptions. */
2397 if (HONOR_NANS (GET_MODE (x
)))
2399 /* But often the compare has some CC mode, so check operand
2401 if (HONOR_NANS (GET_MODE (XEXP (x
, 0)))
2402 || HONOR_NANS (GET_MODE (XEXP (x
, 1))))
2408 if (HONOR_SNANS (GET_MODE (x
)))
2410 /* Often comparison is CC mode, so check operand modes. */
2411 if (HONOR_SNANS (GET_MODE (XEXP (x
, 0)))
2412 || HONOR_SNANS (GET_MODE (XEXP (x
, 1))))
2417 /* Conversion of floating point might trap. */
2418 if (flag_trapping_math
&& HONOR_NANS (GET_MODE (XEXP (x
, 0))))
2424 /* These operations don't trap even with floating point. */
2428 /* Any floating arithmetic may trap. */
2429 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2430 && flag_trapping_math
)
2434 fmt
= GET_RTX_FORMAT (code
);
2435 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2439 if (may_trap_p (XEXP (x
, i
)))
2442 else if (fmt
[i
] == 'E')
2445 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2446 if (may_trap_p (XVECEXP (x
, i
, j
)))
2453 /* Return nonzero if X contains a comparison that is not either EQ or NE,
2454 i.e., an inequality. */
2457 inequality_comparisons_p (rtx x
)
2461 enum rtx_code code
= GET_CODE (x
);
2491 len
= GET_RTX_LENGTH (code
);
2492 fmt
= GET_RTX_FORMAT (code
);
2494 for (i
= 0; i
< len
; i
++)
2498 if (inequality_comparisons_p (XEXP (x
, i
)))
2501 else if (fmt
[i
] == 'E')
2504 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2505 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
2513 /* Replace any occurrence of FROM in X with TO. The function does
2514 not enter into CONST_DOUBLE for the replace.
2516 Note that copying is not done so X must not be shared unless all copies
2517 are to be modified. */
2520 replace_rtx (rtx x
, rtx from
, rtx to
)
2525 /* The following prevents loops occurrence when we change MEM in
2526 CONST_DOUBLE onto the same CONST_DOUBLE. */
2527 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
2533 /* Allow this function to make replacements in EXPR_LISTs. */
2537 if (GET_CODE (x
) == SUBREG
)
2539 rtx
new = replace_rtx (SUBREG_REG (x
), from
, to
);
2541 if (GET_CODE (new) == CONST_INT
)
2543 x
= simplify_subreg (GET_MODE (x
), new,
2544 GET_MODE (SUBREG_REG (x
)),
2550 SUBREG_REG (x
) = new;
2554 else if (GET_CODE (x
) == ZERO_EXTEND
)
2556 rtx
new = replace_rtx (XEXP (x
, 0), from
, to
);
2558 if (GET_CODE (new) == CONST_INT
)
2560 x
= simplify_unary_operation (ZERO_EXTEND
, GET_MODE (x
),
2561 new, GET_MODE (XEXP (x
, 0)));
2571 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2572 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2575 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
2576 else if (fmt
[i
] == 'E')
2577 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2578 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
2584 /* Throughout the rtx X, replace many registers according to REG_MAP.
2585 Return the replacement for X (which may be X with altered contents).
2586 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2587 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2589 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2590 should not be mapped to pseudos or vice versa since validate_change
2593 If REPLACE_DEST is 1, replacements are also done in destinations;
2594 otherwise, only sources are replaced. */
2597 replace_regs (rtx x
, rtx
*reg_map
, unsigned int nregs
, int replace_dest
)
2606 code
= GET_CODE (x
);
2621 /* Verify that the register has an entry before trying to access it. */
2622 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
2624 /* SUBREGs can't be shared. Always return a copy to ensure that if
2625 this replacement occurs more than once then each instance will
2626 get distinct rtx. */
2627 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2628 return copy_rtx (reg_map
[REGNO (x
)]);
2629 return reg_map
[REGNO (x
)];
2634 /* Prevent making nested SUBREGs. */
2635 if (REG_P (SUBREG_REG (x
)) && REGNO (SUBREG_REG (x
)) < nregs
2636 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2637 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2639 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2640 return simplify_gen_subreg (GET_MODE (x
), map_val
,
2641 GET_MODE (SUBREG_REG (x
)),
2648 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2650 else if (GET_CODE (SET_DEST (x
)) == MEM
2651 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2652 /* Even if we are not to replace destinations, replace register if it
2653 is CONTAINED in destination (destination is memory or
2654 STRICT_LOW_PART). */
2655 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2657 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2658 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2661 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2668 fmt
= GET_RTX_FORMAT (code
);
2669 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2672 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2673 else if (fmt
[i
] == 'E')
2676 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2677 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2678 nregs
, replace_dest
);
2684 /* Replace occurrences of the old label in *X with the new one.
2685 DATA is a REPLACE_LABEL_DATA containing the old and new labels. */
2688 replace_label (rtx
*x
, void *data
)
2691 rtx old_label
= ((replace_label_data
*) data
)->r1
;
2692 rtx new_label
= ((replace_label_data
*) data
)->r2
;
2693 bool update_label_nuses
= ((replace_label_data
*) data
)->update_label_nuses
;
2698 if (GET_CODE (l
) == SYMBOL_REF
2699 && CONSTANT_POOL_ADDRESS_P (l
))
2701 rtx c
= get_pool_constant (l
);
2702 if (rtx_referenced_p (old_label
, c
))
2705 replace_label_data
*d
= (replace_label_data
*) data
;
2707 /* Create a copy of constant C; replace the label inside
2708 but do not update LABEL_NUSES because uses in constant pool
2710 new_c
= copy_rtx (c
);
2711 d
->update_label_nuses
= false;
2712 for_each_rtx (&new_c
, replace_label
, data
);
2713 d
->update_label_nuses
= update_label_nuses
;
2715 /* Add the new constant NEW_C to constant pool and replace
2716 the old reference to constant by new reference. */
2717 new_l
= XEXP (force_const_mem (get_pool_mode (l
), new_c
), 0);
2718 *x
= replace_rtx (l
, l
, new_l
);
2723 /* If this is a JUMP_INSN, then we also need to fix the JUMP_LABEL
2724 field. This is not handled by for_each_rtx because it doesn't
2725 handle unprinted ('0') fields. */
2726 if (GET_CODE (l
) == JUMP_INSN
&& JUMP_LABEL (l
) == old_label
)
2727 JUMP_LABEL (l
) = new_label
;
2729 if ((GET_CODE (l
) == LABEL_REF
2730 || GET_CODE (l
) == INSN_LIST
)
2731 && XEXP (l
, 0) == old_label
)
2733 XEXP (l
, 0) = new_label
;
2734 if (update_label_nuses
)
2736 ++LABEL_NUSES (new_label
);
2737 --LABEL_NUSES (old_label
);
2745 /* When *BODY is equal to X or X is directly referenced by *BODY
2746 return nonzero, thus FOR_EACH_RTX stops traversing and returns nonzero
2747 too, otherwise FOR_EACH_RTX continues traversing *BODY. */
2750 rtx_referenced_p_1 (rtx
*body
, void *x
)
2754 if (*body
== NULL_RTX
)
2755 return y
== NULL_RTX
;
2757 /* Return true if a label_ref *BODY refers to label Y. */
2758 if (GET_CODE (*body
) == LABEL_REF
&& GET_CODE (y
) == CODE_LABEL
)
2759 return XEXP (*body
, 0) == y
;
2761 /* If *BODY is a reference to pool constant traverse the constant. */
2762 if (GET_CODE (*body
) == SYMBOL_REF
2763 && CONSTANT_POOL_ADDRESS_P (*body
))
2764 return rtx_referenced_p (y
, get_pool_constant (*body
));
2766 /* By default, compare the RTL expressions. */
2767 return rtx_equal_p (*body
, y
);
2770 /* Return true if X is referenced in BODY. */
2773 rtx_referenced_p (rtx x
, rtx body
)
2775 return for_each_rtx (&body
, rtx_referenced_p_1
, x
);
2778 /* If INSN is a tablejump return true and store the label (before jump table) to
2779 *LABELP and the jump table to *TABLEP. LABELP and TABLEP may be NULL. */
2782 tablejump_p (rtx insn
, rtx
*labelp
, rtx
*tablep
)
2786 if (GET_CODE (insn
) == JUMP_INSN
2787 && (label
= JUMP_LABEL (insn
)) != NULL_RTX
2788 && (table
= next_active_insn (label
)) != NULL_RTX
2789 && GET_CODE (table
) == JUMP_INSN
2790 && (GET_CODE (PATTERN (table
)) == ADDR_VEC
2791 || GET_CODE (PATTERN (table
)) == ADDR_DIFF_VEC
))
2802 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2803 constant that is not in the constant pool and not in the condition
2804 of an IF_THEN_ELSE. */
2807 computed_jump_p_1 (rtx x
)
2809 enum rtx_code code
= GET_CODE (x
);
2828 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2829 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2832 return (computed_jump_p_1 (XEXP (x
, 1))
2833 || computed_jump_p_1 (XEXP (x
, 2)));
2839 fmt
= GET_RTX_FORMAT (code
);
2840 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2843 && computed_jump_p_1 (XEXP (x
, i
)))
2846 else if (fmt
[i
] == 'E')
2847 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2848 if (computed_jump_p_1 (XVECEXP (x
, i
, j
)))
2855 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2857 Tablejumps and casesi insns are not considered indirect jumps;
2858 we can recognize them by a (use (label_ref)). */
2861 computed_jump_p (rtx insn
)
2864 if (GET_CODE (insn
) == JUMP_INSN
)
2866 rtx pat
= PATTERN (insn
);
2868 if (find_reg_note (insn
, REG_LABEL
, NULL_RTX
))
2870 else if (GET_CODE (pat
) == PARALLEL
)
2872 int len
= XVECLEN (pat
, 0);
2873 int has_use_labelref
= 0;
2875 for (i
= len
- 1; i
>= 0; i
--)
2876 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2877 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2879 has_use_labelref
= 1;
2881 if (! has_use_labelref
)
2882 for (i
= len
- 1; i
>= 0; i
--)
2883 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2884 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2885 && computed_jump_p_1 (SET_SRC (XVECEXP (pat
, 0, i
))))
2888 else if (GET_CODE (pat
) == SET
2889 && SET_DEST (pat
) == pc_rtx
2890 && computed_jump_p_1 (SET_SRC (pat
)))
2896 /* Traverse X via depth-first search, calling F for each
2897 sub-expression (including X itself). F is also passed the DATA.
2898 If F returns -1, do not traverse sub-expressions, but continue
2899 traversing the rest of the tree. If F ever returns any other
2900 nonzero value, stop the traversal, and return the value returned
2901 by F. Otherwise, return 0. This function does not traverse inside
2902 tree structure that contains RTX_EXPRs, or into sub-expressions
2903 whose format code is `0' since it is not known whether or not those
2904 codes are actually RTL.
2906 This routine is very general, and could (should?) be used to
2907 implement many of the other routines in this file. */
2910 for_each_rtx (rtx
*x
, rtx_function f
, void *data
)
2918 result
= (*f
) (x
, data
);
2920 /* Do not traverse sub-expressions. */
2922 else if (result
!= 0)
2923 /* Stop the traversal. */
2927 /* There are no sub-expressions. */
2930 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2931 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2933 for (i
= 0; i
< length
; ++i
)
2938 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2945 if (XVEC (*x
, i
) != 0)
2948 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2950 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2958 /* Nothing to do. */
2967 /* Searches X for any reference to REGNO, returning the rtx of the
2968 reference found if any. Otherwise, returns NULL_RTX. */
2971 regno_use_in (unsigned int regno
, rtx x
)
2977 if (REG_P (x
) && REGNO (x
) == regno
)
2980 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2981 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2985 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2988 else if (fmt
[i
] == 'E')
2989 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2990 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2997 /* Return a value indicating whether OP, an operand of a commutative
2998 operation, is preferred as the first or second operand. The higher
2999 the value, the stronger the preference for being the first operand.
3000 We use negative values to indicate a preference for the first operand
3001 and positive values for the second operand. */
3004 commutative_operand_precedence (rtx op
)
3006 enum rtx_code code
= GET_CODE (op
);
3008 /* Constants always come the second operand. Prefer "nice" constants. */
3009 if (code
== CONST_INT
)
3011 if (code
== CONST_DOUBLE
)
3013 op
= avoid_constant_pool_reference (op
);
3015 switch (GET_RTX_CLASS (code
))
3018 if (code
== CONST_INT
)
3020 if (code
== CONST_DOUBLE
)
3025 /* SUBREGs of objects should come second. */
3026 if (code
== SUBREG
&& OBJECT_P (SUBREG_REG (op
)))
3029 if (!CONSTANT_P (op
))
3032 /* As for RTX_CONST_OBJ. */
3036 /* Complex expressions should be the first, so decrease priority
3040 case RTX_COMM_ARITH
:
3041 /* Prefer operands that are themselves commutative to be first.
3042 This helps to make things linear. In particular,
3043 (and (and (reg) (reg)) (not (reg))) is canonical. */
3047 /* If only one operand is a binary expression, it will be the first
3048 operand. In particular, (plus (minus (reg) (reg)) (neg (reg)))
3049 is canonical, although it will usually be further simplified. */
3053 /* Then prefer NEG and NOT. */
3054 if (code
== NEG
|| code
== NOT
)
3062 /* Return 1 iff it is necessary to swap operands of commutative operation
3063 in order to canonicalize expression. */
3066 swap_commutative_operands_p (rtx x
, rtx y
)
3068 return (commutative_operand_precedence (x
)
3069 < commutative_operand_precedence (y
));
3072 /* Return 1 if X is an autoincrement side effect and the register is
3073 not the stack pointer. */
3077 switch (GET_CODE (x
))
3085 /* There are no REG_INC notes for SP. */
3086 if (XEXP (x
, 0) != stack_pointer_rtx
)
3094 /* Return 1 if the sequence of instructions beginning with FROM and up
3095 to and including TO is safe to move. If NEW_TO is non-NULL, and
3096 the sequence is not already safe to move, but can be easily
3097 extended to a sequence which is safe, then NEW_TO will point to the
3098 end of the extended sequence.
3100 For now, this function only checks that the region contains whole
3101 exception regions, but it could be extended to check additional
3102 conditions as well. */
3105 insns_safe_to_move_p (rtx from
, rtx to
, rtx
*new_to
)
3107 int eh_region_count
= 0;
3111 /* By default, assume the end of the region will be what was
3118 if (GET_CODE (r
) == NOTE
)
3120 switch (NOTE_LINE_NUMBER (r
))
3122 case NOTE_INSN_EH_REGION_BEG
:
3126 case NOTE_INSN_EH_REGION_END
:
3127 if (eh_region_count
== 0)
3128 /* This sequence of instructions contains the end of
3129 an exception region, but not he beginning. Moving
3130 it will cause chaos. */
3141 /* If we've passed TO, and we see a non-note instruction, we
3142 can't extend the sequence to a movable sequence. */
3148 /* It's OK to move the sequence if there were matched sets of
3149 exception region notes. */
3150 return eh_region_count
== 0;
3155 /* It's OK to move the sequence if there were matched sets of
3156 exception region notes. */
3157 if (past_to_p
&& eh_region_count
== 0)
3163 /* Go to the next instruction. */
3170 /* Return nonzero if IN contains a piece of rtl that has the address LOC. */
3172 loc_mentioned_in_p (rtx
*loc
, rtx in
)
3174 enum rtx_code code
= GET_CODE (in
);
3175 const char *fmt
= GET_RTX_FORMAT (code
);
3178 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3180 if (loc
== &in
->u
.fld
[i
].rtx
)
3184 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
3187 else if (fmt
[i
] == 'E')
3188 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
3189 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))
3195 /* Helper function for subreg_lsb. Given a subreg's OUTER_MODE, INNER_MODE,
3196 and SUBREG_BYTE, return the bit offset where the subreg begins
3197 (counting from the least significant bit of the operand). */
3200 subreg_lsb_1 (enum machine_mode outer_mode
,
3201 enum machine_mode inner_mode
,
3202 unsigned int subreg_byte
)
3204 unsigned int bitpos
;
3208 /* A paradoxical subreg begins at bit position 0. */
3209 if (GET_MODE_BITSIZE (outer_mode
) > GET_MODE_BITSIZE (inner_mode
))
3212 if (WORDS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
3213 /* If the subreg crosses a word boundary ensure that
3214 it also begins and ends on a word boundary. */
3215 if ((subreg_byte
% UNITS_PER_WORD
3216 + GET_MODE_SIZE (outer_mode
)) > UNITS_PER_WORD
3217 && (subreg_byte
% UNITS_PER_WORD
3218 || GET_MODE_SIZE (outer_mode
) % UNITS_PER_WORD
))
3221 if (WORDS_BIG_ENDIAN
)
3222 word
= (GET_MODE_SIZE (inner_mode
)
3223 - (subreg_byte
+ GET_MODE_SIZE (outer_mode
))) / UNITS_PER_WORD
;
3225 word
= subreg_byte
/ UNITS_PER_WORD
;
3226 bitpos
= word
* BITS_PER_WORD
;
3228 if (BYTES_BIG_ENDIAN
)
3229 byte
= (GET_MODE_SIZE (inner_mode
)
3230 - (subreg_byte
+ GET_MODE_SIZE (outer_mode
))) % UNITS_PER_WORD
;
3232 byte
= subreg_byte
% UNITS_PER_WORD
;
3233 bitpos
+= byte
* BITS_PER_UNIT
;
3238 /* Given a subreg X, return the bit offset where the subreg begins
3239 (counting from the least significant bit of the reg). */
3244 return subreg_lsb_1 (GET_MODE (x
), GET_MODE (SUBREG_REG (x
)),
3248 /* This function returns the regno offset of a subreg expression.
3249 xregno - A regno of an inner hard subreg_reg (or what will become one).
3250 xmode - The mode of xregno.
3251 offset - The byte offset.
3252 ymode - The mode of a top level SUBREG (or what may become one).
3253 RETURN - The regno offset which would be used. */
3255 subreg_regno_offset (unsigned int xregno
, enum machine_mode xmode
,
3256 unsigned int offset
, enum machine_mode ymode
)
3258 int nregs_xmode
, nregs_ymode
;
3259 int mode_multiple
, nregs_multiple
;
3262 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3265 nregs_xmode
= hard_regno_nregs
[xregno
][xmode
];
3266 nregs_ymode
= hard_regno_nregs
[xregno
][ymode
];
3268 /* If this is a big endian paradoxical subreg, which uses more actual
3269 hard registers than the original register, we must return a negative
3270 offset so that we find the proper highpart of the register. */
3272 && nregs_ymode
> nregs_xmode
3273 && (GET_MODE_SIZE (ymode
) > UNITS_PER_WORD
3274 ? WORDS_BIG_ENDIAN
: BYTES_BIG_ENDIAN
))
3275 return nregs_xmode
- nregs_ymode
;
3277 if (offset
== 0 || nregs_xmode
== nregs_ymode
)
3280 /* size of ymode must not be greater than the size of xmode. */
3281 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3282 if (mode_multiple
== 0)
3285 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3286 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3287 return (y_offset
/ (mode_multiple
/ nregs_multiple
)) * nregs_ymode
;
3290 /* This function returns true when the offset is representable via
3291 subreg_offset in the given regno.
3292 xregno - A regno of an inner hard subreg_reg (or what will become one).
3293 xmode - The mode of xregno.
3294 offset - The byte offset.
3295 ymode - The mode of a top level SUBREG (or what may become one).
3296 RETURN - The regno offset which would be used. */
3298 subreg_offset_representable_p (unsigned int xregno
, enum machine_mode xmode
,
3299 unsigned int offset
, enum machine_mode ymode
)
3301 int nregs_xmode
, nregs_ymode
;
3302 int mode_multiple
, nregs_multiple
;
3305 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3308 nregs_xmode
= hard_regno_nregs
[xregno
][xmode
];
3309 nregs_ymode
= hard_regno_nregs
[xregno
][ymode
];
3311 /* Paradoxical subregs are always valid. */
3313 && nregs_ymode
> nregs_xmode
3314 && (GET_MODE_SIZE (ymode
) > UNITS_PER_WORD
3315 ? WORDS_BIG_ENDIAN
: BYTES_BIG_ENDIAN
))
3318 /* Lowpart subregs are always valid. */
3319 if (offset
== subreg_lowpart_offset (ymode
, xmode
))
3322 #ifdef ENABLE_CHECKING
3323 /* This should always pass, otherwise we don't know how to verify the
3324 constraint. These conditions may be relaxed but subreg_offset would
3325 need to be redesigned. */
3326 if (GET_MODE_SIZE (xmode
) % GET_MODE_SIZE (ymode
)
3327 || GET_MODE_SIZE (ymode
) % nregs_ymode
3328 || nregs_xmode
% nregs_ymode
)
3332 /* The XMODE value can be seen as a vector of NREGS_XMODE
3333 values. The subreg must represent a lowpart of given field.
3334 Compute what field it is. */
3335 offset
-= subreg_lowpart_offset (ymode
,
3336 mode_for_size (GET_MODE_BITSIZE (xmode
)
3340 /* size of ymode must not be greater than the size of xmode. */
3341 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3342 if (mode_multiple
== 0)
3345 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3346 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3347 #ifdef ENABLE_CHECKING
3348 if (offset
% GET_MODE_SIZE (ymode
)
3349 || mode_multiple
% nregs_multiple
)
3352 return (!(y_offset
% (mode_multiple
/ nregs_multiple
)));
3355 /* Return the final regno that a subreg expression refers to. */
3357 subreg_regno (rtx x
)
3360 rtx subreg
= SUBREG_REG (x
);
3361 int regno
= REGNO (subreg
);
3363 ret
= regno
+ subreg_regno_offset (regno
,
3370 struct parms_set_data
3376 /* Helper function for noticing stores to parameter registers. */
3378 parms_set (rtx x
, rtx pat ATTRIBUTE_UNUSED
, void *data
)
3380 struct parms_set_data
*d
= data
;
3381 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
3382 && TEST_HARD_REG_BIT (d
->regs
, REGNO (x
)))
3384 CLEAR_HARD_REG_BIT (d
->regs
, REGNO (x
));
3389 /* Look backward for first parameter to be loaded.
3390 Do not skip BOUNDARY. */
3392 find_first_parameter_load (rtx call_insn
, rtx boundary
)
3394 struct parms_set_data parm
;
3397 /* Since different machines initialize their parameter registers
3398 in different orders, assume nothing. Collect the set of all
3399 parameter registers. */
3400 CLEAR_HARD_REG_SET (parm
.regs
);
3402 for (p
= CALL_INSN_FUNCTION_USAGE (call_insn
); p
; p
= XEXP (p
, 1))
3403 if (GET_CODE (XEXP (p
, 0)) == USE
3404 && REG_P (XEXP (XEXP (p
, 0), 0)))
3406 if (REGNO (XEXP (XEXP (p
, 0), 0)) >= FIRST_PSEUDO_REGISTER
)
3409 /* We only care about registers which can hold function
3411 if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p
, 0), 0))))
3414 SET_HARD_REG_BIT (parm
.regs
, REGNO (XEXP (XEXP (p
, 0), 0)));
3419 /* Search backward for the first set of a register in this set. */
3420 while (parm
.nregs
&& before
!= boundary
)
3422 before
= PREV_INSN (before
);
3424 /* It is possible that some loads got CSEed from one call to
3425 another. Stop in that case. */
3426 if (GET_CODE (before
) == CALL_INSN
)
3429 /* Our caller needs either ensure that we will find all sets
3430 (in case code has not been optimized yet), or take care
3431 for possible labels in a way by setting boundary to preceding
3433 if (GET_CODE (before
) == CODE_LABEL
)
3435 if (before
!= boundary
)
3440 if (INSN_P (before
))
3441 note_stores (PATTERN (before
), parms_set
, &parm
);
3446 /* Return true if we should avoid inserting code between INSN and preceding
3447 call instruction. */
3450 keep_with_call_p (rtx insn
)
3454 if (INSN_P (insn
) && (set
= single_set (insn
)) != NULL
)
3456 if (REG_P (SET_DEST (set
))
3457 && REGNO (SET_DEST (set
)) < FIRST_PSEUDO_REGISTER
3458 && fixed_regs
[REGNO (SET_DEST (set
))]
3459 && general_operand (SET_SRC (set
), VOIDmode
))
3461 if (REG_P (SET_SRC (set
))
3462 && FUNCTION_VALUE_REGNO_P (REGNO (SET_SRC (set
)))
3463 && REG_P (SET_DEST (set
))
3464 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
3466 /* There may be a stack pop just after the call and before the store
3467 of the return register. Search for the actual store when deciding
3468 if we can break or not. */
3469 if (SET_DEST (set
) == stack_pointer_rtx
)
3471 rtx i2
= next_nonnote_insn (insn
);
3472 if (i2
&& keep_with_call_p (i2
))
3479 /* Return true when store to register X can be hoisted to the place
3480 with LIVE registers (can be NULL). Value VAL contains destination
3481 whose value will be used. */
3484 hoist_test_store (rtx x
, rtx val
, regset live
)
3486 if (GET_CODE (x
) == SCRATCH
)
3489 if (rtx_equal_p (x
, val
))
3492 /* Allow subreg of X in case it is not writing just part of multireg pseudo.
3493 Then we would need to update all users to care hoisting the store too.
3494 Caller may represent that by specifying whole subreg as val. */
3496 if (GET_CODE (x
) == SUBREG
&& rtx_equal_p (SUBREG_REG (x
), val
))
3498 if (GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) > UNITS_PER_WORD
3499 && GET_MODE_BITSIZE (GET_MODE (x
)) <
3500 GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))))
3504 if (GET_CODE (x
) == SUBREG
)
3507 /* Anything except register store is not hoistable. This includes the
3508 partial stores to registers. */
3513 /* Pseudo registers can be always replaced by another pseudo to avoid
3514 the side effect, for hard register we must ensure that they are dead.
3515 Eventually we may want to add code to try turn pseudos to hards, but it
3516 is unlikely useful. */
3518 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
3520 int regno
= REGNO (x
);
3521 int n
= hard_regno_nregs
[regno
][GET_MODE (x
)];
3525 if (REGNO_REG_SET_P (live
, regno
))
3528 if (REGNO_REG_SET_P (live
, regno
+ n
))
3535 /* Return true if INSN can be hoisted to place with LIVE hard registers
3536 (LIVE can be NULL when unknown). VAL is expected to be stored by the insn
3537 and used by the hoisting pass. */
3540 can_hoist_insn_p (rtx insn
, rtx val
, regset live
)
3542 rtx pat
= PATTERN (insn
);
3545 /* It probably does not worth the complexity to handle multiple
3547 if (!single_set (insn
))
3549 /* We can move CALL_INSN, but we need to check that all caller clobbered
3551 if (GET_CODE (insn
) == CALL_INSN
)
3553 /* In future we will handle hoisting of libcall sequences, but
3555 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
3557 switch (GET_CODE (pat
))
3560 if (!hoist_test_store (SET_DEST (pat
), val
, live
))
3564 /* USES do have sick semantics, so do not move them. */
3568 if (!hoist_test_store (XEXP (pat
, 0), val
, live
))
3572 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3574 rtx x
= XVECEXP (pat
, 0, i
);
3575 switch (GET_CODE (x
))
3578 if (!hoist_test_store (SET_DEST (x
), val
, live
))
3582 /* We need to fix callers to really ensure availability
3583 of all values insn uses, but for now it is safe to prohibit
3584 hoisting of any insn having such a hidden uses. */
3588 if (!hoist_test_store (SET_DEST (x
), val
, live
))
3602 /* Update store after hoisting - replace all stores to pseudo registers
3603 by new ones to avoid clobbering of values except for store to VAL that will
3604 be updated to NEW. */
3607 hoist_update_store (rtx insn
, rtx
*xp
, rtx val
, rtx
new)
3611 if (GET_CODE (x
) == SCRATCH
)
3614 if (GET_CODE (x
) == SUBREG
&& SUBREG_REG (x
) == val
)
3615 validate_change (insn
, xp
,
3616 simplify_gen_subreg (GET_MODE (x
), new, GET_MODE (new),
3617 SUBREG_BYTE (x
)), 1);
3618 if (rtx_equal_p (x
, val
))
3620 validate_change (insn
, xp
, new, 1);
3623 if (GET_CODE (x
) == SUBREG
)
3625 xp
= &SUBREG_REG (x
);
3632 /* We've verified that hard registers are dead, so we may keep the side
3633 effect. Otherwise replace it by new pseudo. */
3634 if (REGNO (x
) >= FIRST_PSEUDO_REGISTER
)
3635 validate_change (insn
, xp
, gen_reg_rtx (GET_MODE (x
)), 1);
3637 = alloc_EXPR_LIST (REG_UNUSED
, *xp
, REG_NOTES (insn
));
3640 /* Create a copy of INSN after AFTER replacing store of VAL to NEW
3641 and each other side effect to pseudo register by new pseudo register. */
3644 hoist_insn_after (rtx insn
, rtx after
, rtx val
, rtx
new)
3650 insn
= emit_copy_of_insn_after (insn
, after
);
3651 pat
= PATTERN (insn
);
3653 /* Remove REG_UNUSED notes as we will re-emit them. */
3654 while ((note
= find_reg_note (insn
, REG_UNUSED
, NULL_RTX
)))
3655 remove_note (insn
, note
);
3657 /* To get this working callers must ensure to move everything referenced
3658 by REG_EQUAL/REG_EQUIV notes too. Lets remove them, it is probably
3660 while ((note
= find_reg_note (insn
, REG_EQUAL
, NULL_RTX
)))
3661 remove_note (insn
, note
);
3662 while ((note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
)))
3663 remove_note (insn
, note
);
3665 /* Remove REG_DEAD notes as they might not be valid anymore in case
3666 we create redundancy. */
3667 while ((note
= find_reg_note (insn
, REG_DEAD
, NULL_RTX
)))
3668 remove_note (insn
, note
);
3669 switch (GET_CODE (pat
))
3672 hoist_update_store (insn
, &SET_DEST (pat
), val
, new);
3677 hoist_update_store (insn
, &XEXP (pat
, 0), val
, new);
3680 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3682 rtx x
= XVECEXP (pat
, 0, i
);
3683 switch (GET_CODE (x
))
3686 hoist_update_store (insn
, &SET_DEST (x
), val
, new);
3691 hoist_update_store (insn
, &SET_DEST (x
), val
, new);
3701 if (!apply_change_group ())
3708 hoist_insn_to_edge (rtx insn
, edge e
, rtx val
, rtx
new)
3712 /* We cannot insert instructions on an abnormal critical edge.
3713 It will be easier to find the culprit if we die now. */
3714 if ((e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
3717 /* Do not use emit_insn_on_edge as we want to preserve notes and similar
3718 stuff. We also emit CALL_INSNS and firends. */
3719 if (e
->insns
.r
== NULL_RTX
)
3722 emit_note (NOTE_INSN_DELETED
);
3725 push_to_sequence (e
->insns
.r
);
3727 new_insn
= hoist_insn_after (insn
, get_last_insn (), val
, new);
3729 e
->insns
.r
= get_insns ();
3734 /* Return true if LABEL is a target of JUMP_INSN. This applies only
3735 to non-complex jumps. That is, direct unconditional, conditional,
3736 and tablejumps, but not computed jumps or returns. It also does
3737 not apply to the fallthru case of a conditional jump. */
3740 label_is_jump_target_p (rtx label
, rtx jump_insn
)
3742 rtx tmp
= JUMP_LABEL (jump_insn
);
3747 if (tablejump_p (jump_insn
, NULL
, &tmp
))
3749 rtvec vec
= XVEC (PATTERN (tmp
),
3750 GET_CODE (PATTERN (tmp
)) == ADDR_DIFF_VEC
);
3751 int i
, veclen
= GET_NUM_ELEM (vec
);
3753 for (i
= 0; i
< veclen
; ++i
)
3754 if (XEXP (RTVEC_ELT (vec
, i
), 0) == label
)
3762 /* Return an estimate of the cost of computing rtx X.
3763 One use is in cse, to decide which expression to keep in the hash table.
3764 Another is in rtl generation, to pick the cheapest way to multiply.
3765 Other uses like the latter are expected in the future. */
3768 rtx_cost (rtx x
, enum rtx_code outer_code ATTRIBUTE_UNUSED
)
3778 /* Compute the default costs of certain things.
3779 Note that targetm.rtx_costs can override the defaults. */
3781 code
= GET_CODE (x
);
3785 total
= COSTS_N_INSNS (5);
3791 total
= COSTS_N_INSNS (7);
3794 /* Used in loop.c and combine.c as a marker. */
3798 total
= COSTS_N_INSNS (1);
3807 /* If we can't tie these modes, make this expensive. The larger
3808 the mode, the more expensive it is. */
3809 if (! MODES_TIEABLE_P (GET_MODE (x
), GET_MODE (SUBREG_REG (x
))))
3810 return COSTS_N_INSNS (2
3811 + GET_MODE_SIZE (GET_MODE (x
)) / UNITS_PER_WORD
);
3815 if (targetm
.rtx_costs (x
, code
, outer_code
, &total
))
3820 /* Sum the costs of the sub-rtx's, plus cost of this operation,
3821 which is already in total. */
3823 fmt
= GET_RTX_FORMAT (code
);
3824 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3826 total
+= rtx_cost (XEXP (x
, i
), code
);
3827 else if (fmt
[i
] == 'E')
3828 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3829 total
+= rtx_cost (XVECEXP (x
, i
, j
), code
);
3834 /* Return cost of address expression X.
3835 Expect that X is properly formed address reference. */
3838 address_cost (rtx x
, enum machine_mode mode
)
3840 /* The address_cost target hook does not deal with ADDRESSOF nodes. But,
3841 during CSE, such nodes are present. Using an ADDRESSOF node which
3842 refers to the address of a REG is a good thing because we can then
3843 turn (MEM (ADDRESSOF (REG))) into just plain REG. */
3845 if (GET_CODE (x
) == ADDRESSOF
&& REG_P (XEXP ((x
), 0)))
3848 /* We may be asked for cost of various unusual addresses, such as operands
3849 of push instruction. It is not worthwhile to complicate writing
3850 of the target hook by such cases. */
3852 if (!memory_address_p (mode
, x
))
3855 return targetm
.address_cost (x
);
3858 /* If the target doesn't override, compute the cost as with arithmetic. */
3861 default_address_cost (rtx x
)
3863 return rtx_cost (x
, MEM
);
3867 unsigned HOST_WIDE_INT
3868 nonzero_bits (rtx x
, enum machine_mode mode
)
3870 return cached_nonzero_bits (x
, mode
, NULL_RTX
, VOIDmode
, 0);
3874 num_sign_bit_copies (rtx x
, enum machine_mode mode
)
3876 return cached_num_sign_bit_copies (x
, mode
, NULL_RTX
, VOIDmode
, 0);
3879 /* The function cached_nonzero_bits is a wrapper around nonzero_bits1.
3880 It avoids exponential behavior in nonzero_bits1 when X has
3881 identical subexpressions on the first or the second level. */
3883 static unsigned HOST_WIDE_INT
3884 cached_nonzero_bits (rtx x
, enum machine_mode mode
, rtx known_x
,
3885 enum machine_mode known_mode
,
3886 unsigned HOST_WIDE_INT known_ret
)
3888 if (x
== known_x
&& mode
== known_mode
)
3891 /* Try to find identical subexpressions. If found call
3892 nonzero_bits1 on X with the subexpressions as KNOWN_X and the
3893 precomputed value for the subexpression as KNOWN_RET. */
3895 if (ARITHMETIC_P (x
))
3897 rtx x0
= XEXP (x
, 0);
3898 rtx x1
= XEXP (x
, 1);
3900 /* Check the first level. */
3902 return nonzero_bits1 (x
, mode
, x0
, mode
,
3903 cached_nonzero_bits (x0
, mode
, known_x
,
3904 known_mode
, known_ret
));
3906 /* Check the second level. */
3907 if (ARITHMETIC_P (x0
)
3908 && (x1
== XEXP (x0
, 0) || x1
== XEXP (x0
, 1)))
3909 return nonzero_bits1 (x
, mode
, x1
, mode
,
3910 cached_nonzero_bits (x1
, mode
, known_x
,
3911 known_mode
, known_ret
));
3913 if (ARITHMETIC_P (x1
)
3914 && (x0
== XEXP (x1
, 0) || x0
== XEXP (x1
, 1)))
3915 return nonzero_bits1 (x
, mode
, x0
, mode
,
3916 cached_nonzero_bits (x0
, mode
, known_x
,
3917 known_mode
, known_ret
));
3920 return nonzero_bits1 (x
, mode
, known_x
, known_mode
, known_ret
);
3923 /* We let num_sign_bit_copies recur into nonzero_bits as that is useful.
3924 We don't let nonzero_bits recur into num_sign_bit_copies, because that
3925 is less useful. We can't allow both, because that results in exponential
3926 run time recursion. There is a nullstone testcase that triggered
3927 this. This macro avoids accidental uses of num_sign_bit_copies. */
3928 #define cached_num_sign_bit_copies sorry_i_am_preventing_exponential_behavior
3930 /* Given an expression, X, compute which bits in X can be nonzero.
3931 We don't care about bits outside of those defined in MODE.
3933 For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
3934 an arithmetic operation, we can do better. */
3936 static unsigned HOST_WIDE_INT
3937 nonzero_bits1 (rtx x
, enum machine_mode mode
, rtx known_x
,
3938 enum machine_mode known_mode
,
3939 unsigned HOST_WIDE_INT known_ret
)
3941 unsigned HOST_WIDE_INT nonzero
= GET_MODE_MASK (mode
);
3942 unsigned HOST_WIDE_INT inner_nz
;
3944 unsigned int mode_width
= GET_MODE_BITSIZE (mode
);
3946 /* For floating-point values, assume all bits are needed. */
3947 if (FLOAT_MODE_P (GET_MODE (x
)) || FLOAT_MODE_P (mode
))
3950 /* If X is wider than MODE, use its mode instead. */
3951 if (GET_MODE_BITSIZE (GET_MODE (x
)) > mode_width
)
3953 mode
= GET_MODE (x
);
3954 nonzero
= GET_MODE_MASK (mode
);
3955 mode_width
= GET_MODE_BITSIZE (mode
);
3958 if (mode_width
> HOST_BITS_PER_WIDE_INT
)
3959 /* Our only callers in this case look for single bit values. So
3960 just return the mode mask. Those tests will then be false. */
3963 #ifndef WORD_REGISTER_OPERATIONS
3964 /* If MODE is wider than X, but both are a single word for both the host
3965 and target machines, we can compute this from which bits of the
3966 object might be nonzero in its own mode, taking into account the fact
3967 that on many CISC machines, accessing an object in a wider mode
3968 causes the high-order bits to become undefined. So they are
3969 not known to be zero. */
3971 if (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != mode
3972 && GET_MODE_BITSIZE (GET_MODE (x
)) <= BITS_PER_WORD
3973 && GET_MODE_BITSIZE (GET_MODE (x
)) <= HOST_BITS_PER_WIDE_INT
3974 && GET_MODE_BITSIZE (mode
) > GET_MODE_BITSIZE (GET_MODE (x
)))
3976 nonzero
&= cached_nonzero_bits (x
, GET_MODE (x
),
3977 known_x
, known_mode
, known_ret
);
3978 nonzero
|= GET_MODE_MASK (mode
) & ~GET_MODE_MASK (GET_MODE (x
));
3983 code
= GET_CODE (x
);
3987 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
3988 /* If pointers extend unsigned and this is a pointer in Pmode, say that
3989 all the bits above ptr_mode are known to be zero. */
3990 if (POINTERS_EXTEND_UNSIGNED
&& GET_MODE (x
) == Pmode
3992 nonzero
&= GET_MODE_MASK (ptr_mode
);
3995 /* Include declared information about alignment of pointers. */
3996 /* ??? We don't properly preserve REG_POINTER changes across
3997 pointer-to-integer casts, so we can't trust it except for
3998 things that we know must be pointers. See execute/960116-1.c. */
3999 if ((x
== stack_pointer_rtx
4000 || x
== frame_pointer_rtx
4001 || x
== arg_pointer_rtx
)
4002 && REGNO_POINTER_ALIGN (REGNO (x
)))
4004 unsigned HOST_WIDE_INT alignment
4005 = REGNO_POINTER_ALIGN (REGNO (x
)) / BITS_PER_UNIT
;
4007 #ifdef PUSH_ROUNDING
4008 /* If PUSH_ROUNDING is defined, it is possible for the
4009 stack to be momentarily aligned only to that amount,
4010 so we pick the least alignment. */
4011 if (x
== stack_pointer_rtx
&& PUSH_ARGS
)
4012 alignment
= MIN ((unsigned HOST_WIDE_INT
) PUSH_ROUNDING (1),
4016 nonzero
&= ~(alignment
- 1);
4020 unsigned HOST_WIDE_INT nonzero_for_hook
= nonzero
;
4021 rtx
new = rtl_hooks
.reg_nonzero_bits (x
, mode
, known_x
,
4022 known_mode
, known_ret
,
4026 nonzero_for_hook
&= cached_nonzero_bits (new, mode
, known_x
,
4027 known_mode
, known_ret
);
4029 return nonzero_for_hook
;
4033 #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
4034 /* If X is negative in MODE, sign-extend the value. */
4035 if (INTVAL (x
) > 0 && mode_width
< BITS_PER_WORD
4036 && 0 != (INTVAL (x
) & ((HOST_WIDE_INT
) 1 << (mode_width
- 1))))
4037 return (INTVAL (x
) | ((HOST_WIDE_INT
) (-1) << mode_width
));
4043 #ifdef LOAD_EXTEND_OP
4044 /* In many, if not most, RISC machines, reading a byte from memory
4045 zeros the rest of the register. Noticing that fact saves a lot
4046 of extra zero-extends. */
4047 if (LOAD_EXTEND_OP (GET_MODE (x
)) == ZERO_EXTEND
)
4048 nonzero
&= GET_MODE_MASK (GET_MODE (x
));
4053 case UNEQ
: case LTGT
:
4054 case GT
: case GTU
: case UNGT
:
4055 case LT
: case LTU
: case UNLT
:
4056 case GE
: case GEU
: case UNGE
:
4057 case LE
: case LEU
: case UNLE
:
4058 case UNORDERED
: case ORDERED
:
4060 /* If this produces an integer result, we know which bits are set.
4061 Code here used to clear bits outside the mode of X, but that is
4064 if (GET_MODE_CLASS (mode
) == MODE_INT
4065 && mode_width
<= HOST_BITS_PER_WIDE_INT
)
4066 nonzero
= STORE_FLAG_VALUE
;
4071 /* Disabled to avoid exponential mutual recursion between nonzero_bits
4072 and num_sign_bit_copies. */
4073 if (num_sign_bit_copies (XEXP (x
, 0), GET_MODE (x
))
4074 == GET_MODE_BITSIZE (GET_MODE (x
)))
4078 if (GET_MODE_SIZE (GET_MODE (x
)) < mode_width
)
4079 nonzero
|= (GET_MODE_MASK (mode
) & ~GET_MODE_MASK (GET_MODE (x
)));
4084 /* Disabled to avoid exponential mutual recursion between nonzero_bits
4085 and num_sign_bit_copies. */
4086 if (num_sign_bit_copies (XEXP (x
, 0), GET_MODE (x
))
4087 == GET_MODE_BITSIZE (GET_MODE (x
)))
4093 nonzero
&= (cached_nonzero_bits (XEXP (x
, 0), mode
,
4094 known_x
, known_mode
, known_ret
)
4095 & GET_MODE_MASK (mode
));
4099 nonzero
&= cached_nonzero_bits (XEXP (x
, 0), mode
,
4100 known_x
, known_mode
, known_ret
);
4101 if (GET_MODE (XEXP (x
, 0)) != VOIDmode
)
4102 nonzero
&= GET_MODE_MASK (GET_MODE (XEXP (x
, 0)));
4106 /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
4107 Otherwise, show all the bits in the outer mode but not the inner
4109 inner_nz
= cached_nonzero_bits (XEXP (x
, 0), mode
,
4110 known_x
, known_mode
, known_ret
);
4111 if (GET_MODE (XEXP (x
, 0)) != VOIDmode
)
4113 inner_nz
&= GET_MODE_MASK (GET_MODE (XEXP (x
, 0)));
4115 & (((HOST_WIDE_INT
) 1
4116 << (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0))) - 1))))
4117 inner_nz
|= (GET_MODE_MASK (mode
)
4118 & ~GET_MODE_MASK (GET_MODE (XEXP (x
, 0))));
4121 nonzero
&= inner_nz
;
4125 nonzero
&= cached_nonzero_bits (XEXP (x
, 0), mode
,
4126 known_x
, known_mode
, known_ret
)
4127 & cached_nonzero_bits (XEXP (x
, 1), mode
,
4128 known_x
, known_mode
, known_ret
);
4132 case UMIN
: case UMAX
: case SMIN
: case SMAX
:
4134 unsigned HOST_WIDE_INT nonzero0
=
4135 cached_nonzero_bits (XEXP (x
, 0), mode
,
4136 known_x
, known_mode
, known_ret
);
4138 /* Don't call nonzero_bits for the second time if it cannot change
4140 if ((nonzero
& nonzero0
) != nonzero
)
4142 | cached_nonzero_bits (XEXP (x
, 1), mode
,
4143 known_x
, known_mode
, known_ret
);
4147 case PLUS
: case MINUS
:
4149 case DIV
: case UDIV
:
4150 case MOD
: case UMOD
:
4151 /* We can apply the rules of arithmetic to compute the number of
4152 high- and low-order zero bits of these operations. We start by
4153 computing the width (position of the highest-order nonzero bit)
4154 and the number of low-order zero bits for each value. */
4156 unsigned HOST_WIDE_INT nz0
=
4157 cached_nonzero_bits (XEXP (x
, 0), mode
,
4158 known_x
, known_mode
, known_ret
);
4159 unsigned HOST_WIDE_INT nz1
=
4160 cached_nonzero_bits (XEXP (x
, 1), mode
,
4161 known_x
, known_mode
, known_ret
);
4162 int sign_index
= GET_MODE_BITSIZE (GET_MODE (x
)) - 1;
4163 int width0
= floor_log2 (nz0
) + 1;
4164 int width1
= floor_log2 (nz1
) + 1;
4165 int low0
= floor_log2 (nz0
& -nz0
);
4166 int low1
= floor_log2 (nz1
& -nz1
);
4167 HOST_WIDE_INT op0_maybe_minusp
4168 = (nz0
& ((HOST_WIDE_INT
) 1 << sign_index
));
4169 HOST_WIDE_INT op1_maybe_minusp
4170 = (nz1
& ((HOST_WIDE_INT
) 1 << sign_index
));
4171 unsigned int result_width
= mode_width
;
4177 result_width
= MAX (width0
, width1
) + 1;
4178 result_low
= MIN (low0
, low1
);
4181 result_low
= MIN (low0
, low1
);
4184 result_width
= width0
+ width1
;
4185 result_low
= low0
+ low1
;
4190 if (! op0_maybe_minusp
&& ! op1_maybe_minusp
)
4191 result_width
= width0
;
4196 result_width
= width0
;
4201 if (! op0_maybe_minusp
&& ! op1_maybe_minusp
)
4202 result_width
= MIN (width0
, width1
);
4203 result_low
= MIN (low0
, low1
);
4208 result_width
= MIN (width0
, width1
);
4209 result_low
= MIN (low0
, low1
);
4215 if (result_width
< mode_width
)
4216 nonzero
&= ((HOST_WIDE_INT
) 1 << result_width
) - 1;
4219 nonzero
&= ~(((HOST_WIDE_INT
) 1 << result_low
) - 1);
4221 #ifdef POINTERS_EXTEND_UNSIGNED
4222 /* If pointers extend unsigned and this is an addition or subtraction
4223 to a pointer in Pmode, all the bits above ptr_mode are known to be
4225 if (POINTERS_EXTEND_UNSIGNED
> 0 && GET_MODE (x
) == Pmode
4226 && (code
== PLUS
|| code
== MINUS
)
4227 && REG_P (XEXP (x
, 0)) && REG_POINTER (XEXP (x
, 0)))
4228 nonzero
&= GET_MODE_MASK (ptr_mode
);
4234 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
4235 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
)
4236 nonzero
&= ((HOST_WIDE_INT
) 1 << INTVAL (XEXP (x
, 1))) - 1;
4240 /* If this is a SUBREG formed for a promoted variable that has
4241 been zero-extended, we know that at least the high-order bits
4242 are zero, though others might be too. */
4244 if (SUBREG_PROMOTED_VAR_P (x
) && SUBREG_PROMOTED_UNSIGNED_P (x
) > 0)
4245 nonzero
= GET_MODE_MASK (GET_MODE (x
))
4246 & cached_nonzero_bits (SUBREG_REG (x
), GET_MODE (x
),
4247 known_x
, known_mode
, known_ret
);
4249 /* If the inner mode is a single word for both the host and target
4250 machines, we can compute this from which bits of the inner
4251 object might be nonzero. */
4252 if (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))) <= BITS_PER_WORD
4253 && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
)))
4254 <= HOST_BITS_PER_WIDE_INT
))
4256 nonzero
&= cached_nonzero_bits (SUBREG_REG (x
), mode
,
4257 known_x
, known_mode
, known_ret
);
4259 #if defined (WORD_REGISTER_OPERATIONS) && defined (LOAD_EXTEND_OP)
4260 /* If this is a typical RISC machine, we only have to worry
4261 about the way loads are extended. */
4262 if ((LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x
))) == SIGN_EXTEND
4264 & (((unsigned HOST_WIDE_INT
) 1
4265 << (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))) - 1))))
4267 : LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x
))) != ZERO_EXTEND
)
4268 || GET_CODE (SUBREG_REG (x
)) != MEM
)
4271 /* On many CISC machines, accessing an object in a wider mode
4272 causes the high-order bits to become undefined. So they are
4273 not known to be zero. */
4274 if (GET_MODE_SIZE (GET_MODE (x
))
4275 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
4276 nonzero
|= (GET_MODE_MASK (GET_MODE (x
))
4277 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (x
))));
4286 /* The nonzero bits are in two classes: any bits within MODE
4287 that aren't in GET_MODE (x) are always significant. The rest of the
4288 nonzero bits are those that are significant in the operand of
4289 the shift when shifted the appropriate number of bits. This
4290 shows that high-order bits are cleared by the right shift and
4291 low-order bits by left shifts. */
4292 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
4293 && INTVAL (XEXP (x
, 1)) >= 0
4294 && INTVAL (XEXP (x
, 1)) < HOST_BITS_PER_WIDE_INT
)
4296 enum machine_mode inner_mode
= GET_MODE (x
);
4297 unsigned int width
= GET_MODE_BITSIZE (inner_mode
);
4298 int count
= INTVAL (XEXP (x
, 1));
4299 unsigned HOST_WIDE_INT mode_mask
= GET_MODE_MASK (inner_mode
);
4300 unsigned HOST_WIDE_INT op_nonzero
=
4301 cached_nonzero_bits (XEXP (x
, 0), mode
,
4302 known_x
, known_mode
, known_ret
);
4303 unsigned HOST_WIDE_INT inner
= op_nonzero
& mode_mask
;
4304 unsigned HOST_WIDE_INT outer
= 0;
4306 if (mode_width
> width
)
4307 outer
= (op_nonzero
& nonzero
& ~mode_mask
);
4309 if (code
== LSHIFTRT
)
4311 else if (code
== ASHIFTRT
)
4315 /* If the sign bit may have been nonzero before the shift, we
4316 need to mark all the places it could have been copied to
4317 by the shift as possibly nonzero. */
4318 if (inner
& ((HOST_WIDE_INT
) 1 << (width
- 1 - count
)))
4319 inner
|= (((HOST_WIDE_INT
) 1 << count
) - 1) << (width
- count
);
4321 else if (code
== ASHIFT
)
4324 inner
= ((inner
<< (count
% width
)
4325 | (inner
>> (width
- (count
% width
)))) & mode_mask
);
4327 nonzero
&= (outer
| inner
);
4333 /* This is at most the number of bits in the mode. */
4334 nonzero
= ((HOST_WIDE_INT
) 2 << (floor_log2 (mode_width
))) - 1;
4338 /* If CLZ has a known value at zero, then the nonzero bits are
4339 that value, plus the number of bits in the mode minus one. */
4340 if (CLZ_DEFINED_VALUE_AT_ZERO (mode
, nonzero
))
4341 nonzero
|= ((HOST_WIDE_INT
) 1 << (floor_log2 (mode_width
))) - 1;
4347 /* If CTZ has a known value at zero, then the nonzero bits are
4348 that value, plus the number of bits in the mode minus one. */
4349 if (CTZ_DEFINED_VALUE_AT_ZERO (mode
, nonzero
))
4350 nonzero
|= ((HOST_WIDE_INT
) 1 << (floor_log2 (mode_width
))) - 1;
4361 unsigned HOST_WIDE_INT nonzero_true
=
4362 cached_nonzero_bits (XEXP (x
, 1), mode
,
4363 known_x
, known_mode
, known_ret
);
4365 /* Don't call nonzero_bits for the second time if it cannot change
4367 if ((nonzero
& nonzero_true
) != nonzero
)
4368 nonzero
&= nonzero_true
4369 | cached_nonzero_bits (XEXP (x
, 2), mode
,
4370 known_x
, known_mode
, known_ret
);
4381 /* See the macro definition above. */
4382 #undef cached_num_sign_bit_copies
4385 /* The function cached_num_sign_bit_copies is a wrapper around
4386 num_sign_bit_copies1. It avoids exponential behavior in
4387 num_sign_bit_copies1 when X has identical subexpressions on the
4388 first or the second level. */
4391 cached_num_sign_bit_copies (rtx x
, enum machine_mode mode
, rtx known_x
,
4392 enum machine_mode known_mode
,
4393 unsigned int known_ret
)
4395 if (x
== known_x
&& mode
== known_mode
)
4398 /* Try to find identical subexpressions. If found call
4399 num_sign_bit_copies1 on X with the subexpressions as KNOWN_X and
4400 the precomputed value for the subexpression as KNOWN_RET. */
4402 if (ARITHMETIC_P (x
))
4404 rtx x0
= XEXP (x
, 0);
4405 rtx x1
= XEXP (x
, 1);
4407 /* Check the first level. */
4410 num_sign_bit_copies1 (x
, mode
, x0
, mode
,
4411 cached_num_sign_bit_copies (x0
, mode
, known_x
,
4415 /* Check the second level. */
4416 if (ARITHMETIC_P (x0
)
4417 && (x1
== XEXP (x0
, 0) || x1
== XEXP (x0
, 1)))
4419 num_sign_bit_copies1 (x
, mode
, x1
, mode
,
4420 cached_num_sign_bit_copies (x1
, mode
, known_x
,
4424 if (ARITHMETIC_P (x1
)
4425 && (x0
== XEXP (x1
, 0) || x0
== XEXP (x1
, 1)))
4427 num_sign_bit_copies1 (x
, mode
, x0
, mode
,
4428 cached_num_sign_bit_copies (x0
, mode
, known_x
,
4433 return num_sign_bit_copies1 (x
, mode
, known_x
, known_mode
, known_ret
);
4436 /* Return the number of bits at the high-order end of X that are known to
4437 be equal to the sign bit. X will be used in mode MODE; if MODE is
4438 VOIDmode, X will be used in its own mode. The returned value will always
4439 be between 1 and the number of bits in MODE. */
4442 num_sign_bit_copies1 (rtx x
, enum machine_mode mode
, rtx known_x
,
4443 enum machine_mode known_mode
,
4444 unsigned int known_ret
)
4446 enum rtx_code code
= GET_CODE (x
);
4447 unsigned int bitwidth
= GET_MODE_BITSIZE (mode
);
4448 int num0
, num1
, result
;
4449 unsigned HOST_WIDE_INT nonzero
;
4451 /* If we weren't given a mode, use the mode of X. If the mode is still
4452 VOIDmode, we don't know anything. Likewise if one of the modes is
4455 if (mode
== VOIDmode
)
4456 mode
= GET_MODE (x
);
4458 if (mode
== VOIDmode
|| FLOAT_MODE_P (mode
) || FLOAT_MODE_P (GET_MODE (x
)))
4461 /* For a smaller object, just ignore the high bits. */
4462 if (bitwidth
< GET_MODE_BITSIZE (GET_MODE (x
)))
4464 num0
= cached_num_sign_bit_copies (x
, GET_MODE (x
),
4465 known_x
, known_mode
, known_ret
);
4467 num0
- (int) (GET_MODE_BITSIZE (GET_MODE (x
)) - bitwidth
));
4470 if (GET_MODE (x
) != VOIDmode
&& bitwidth
> GET_MODE_BITSIZE (GET_MODE (x
)))
4472 #ifndef WORD_REGISTER_OPERATIONS
4473 /* If this machine does not do all register operations on the entire
4474 register and MODE is wider than the mode of X, we can say nothing
4475 at all about the high-order bits. */
4478 /* Likewise on machines that do, if the mode of the object is smaller
4479 than a word and loads of that size don't sign extend, we can say
4480 nothing about the high order bits. */
4481 if (GET_MODE_BITSIZE (GET_MODE (x
)) < BITS_PER_WORD
4482 #ifdef LOAD_EXTEND_OP
4483 && LOAD_EXTEND_OP (GET_MODE (x
)) != SIGN_EXTEND
4494 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
4495 /* If pointers extend signed and this is a pointer in Pmode, say that
4496 all the bits above ptr_mode are known to be sign bit copies. */
4497 if (! POINTERS_EXTEND_UNSIGNED
&& GET_MODE (x
) == Pmode
&& mode
== Pmode
4499 return GET_MODE_BITSIZE (Pmode
) - GET_MODE_BITSIZE (ptr_mode
) + 1;
4503 unsigned int copies_for_hook
= 1, copies
= 1;
4504 rtx
new = rtl_hooks
.reg_num_sign_bit_copies (x
, mode
, known_x
,
4505 known_mode
, known_ret
,
4509 copies
= cached_num_sign_bit_copies (new, mode
, known_x
,
4510 known_mode
, known_ret
);
4512 if (copies
> 1 || copies_for_hook
> 1)
4513 return MAX (copies
, copies_for_hook
);
4515 /* Else, use nonzero_bits to guess num_sign_bit_copies (see below). */
4520 #ifdef LOAD_EXTEND_OP
4521 /* Some RISC machines sign-extend all loads of smaller than a word. */
4522 if (LOAD_EXTEND_OP (GET_MODE (x
)) == SIGN_EXTEND
)
4523 return MAX (1, ((int) bitwidth
4524 - (int) GET_MODE_BITSIZE (GET_MODE (x
)) + 1));
4529 /* If the constant is negative, take its 1's complement and remask.
4530 Then see how many zero bits we have. */
4531 nonzero
= INTVAL (x
) & GET_MODE_MASK (mode
);
4532 if (bitwidth
<= HOST_BITS_PER_WIDE_INT
4533 && (nonzero
& ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
4534 nonzero
= (~nonzero
) & GET_MODE_MASK (mode
);
4536 return (nonzero
== 0 ? bitwidth
: bitwidth
- floor_log2 (nonzero
) - 1);
4539 /* If this is a SUBREG for a promoted object that is sign-extended
4540 and we are looking at it in a wider mode, we know that at least the
4541 high-order bits are known to be sign bit copies. */
4543 if (SUBREG_PROMOTED_VAR_P (x
) && ! SUBREG_PROMOTED_UNSIGNED_P (x
))
4545 num0
= cached_num_sign_bit_copies (SUBREG_REG (x
), mode
,
4546 known_x
, known_mode
, known_ret
);
4547 return MAX ((int) bitwidth
4548 - (int) GET_MODE_BITSIZE (GET_MODE (x
)) + 1,
4552 /* For a smaller object, just ignore the high bits. */
4553 if (bitwidth
<= GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))))
4555 num0
= cached_num_sign_bit_copies (SUBREG_REG (x
), VOIDmode
,
4556 known_x
, known_mode
, known_ret
);
4557 return MAX (1, (num0
4558 - (int) (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
)))
4562 #ifdef WORD_REGISTER_OPERATIONS
4563 #ifdef LOAD_EXTEND_OP
4564 /* For paradoxical SUBREGs on machines where all register operations
4565 affect the entire register, just look inside. Note that we are
4566 passing MODE to the recursive call, so the number of sign bit copies
4567 will remain relative to that mode, not the inner mode. */
4569 /* This works only if loads sign extend. Otherwise, if we get a
4570 reload for the inner part, it may be loaded from the stack, and
4571 then we lose all sign bit copies that existed before the store
4574 if ((GET_MODE_SIZE (GET_MODE (x
))
4575 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
4576 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x
))) == SIGN_EXTEND
4577 && GET_CODE (SUBREG_REG (x
)) == MEM
)
4578 return cached_num_sign_bit_copies (SUBREG_REG (x
), mode
,
4579 known_x
, known_mode
, known_ret
);
4585 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
4586 return MAX (1, (int) bitwidth
- INTVAL (XEXP (x
, 1)));
4590 return (bitwidth
- GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
4591 + cached_num_sign_bit_copies (XEXP (x
, 0), VOIDmode
,
4592 known_x
, known_mode
, known_ret
));
4595 /* For a smaller object, just ignore the high bits. */
4596 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), VOIDmode
,
4597 known_x
, known_mode
, known_ret
);
4598 return MAX (1, (num0
- (int) (GET_MODE_BITSIZE (GET_MODE (XEXP (x
, 0)))
4602 return cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4603 known_x
, known_mode
, known_ret
);
4605 case ROTATE
: case ROTATERT
:
4606 /* If we are rotating left by a number of bits less than the number
4607 of sign bit copies, we can just subtract that amount from the
4609 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
4610 && INTVAL (XEXP (x
, 1)) >= 0
4611 && INTVAL (XEXP (x
, 1)) < (int) bitwidth
)
4613 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4614 known_x
, known_mode
, known_ret
);
4615 return MAX (1, num0
- (code
== ROTATE
? INTVAL (XEXP (x
, 1))
4616 : (int) bitwidth
- INTVAL (XEXP (x
, 1))));
4621 /* In general, this subtracts one sign bit copy. But if the value
4622 is known to be positive, the number of sign bit copies is the
4623 same as that of the input. Finally, if the input has just one bit
4624 that might be nonzero, all the bits are copies of the sign bit. */
4625 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4626 known_x
, known_mode
, known_ret
);
4627 if (bitwidth
> HOST_BITS_PER_WIDE_INT
)
4628 return num0
> 1 ? num0
- 1 : 1;
4630 nonzero
= nonzero_bits (XEXP (x
, 0), mode
);
4635 && (((HOST_WIDE_INT
) 1 << (bitwidth
- 1)) & nonzero
))
4640 case IOR
: case AND
: case XOR
:
4641 case SMIN
: case SMAX
: case UMIN
: case UMAX
:
4642 /* Logical operations will preserve the number of sign-bit copies.
4643 MIN and MAX operations always return one of the operands. */
4644 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4645 known_x
, known_mode
, known_ret
);
4646 num1
= cached_num_sign_bit_copies (XEXP (x
, 1), mode
,
4647 known_x
, known_mode
, known_ret
);
4648 return MIN (num0
, num1
);
4650 case PLUS
: case MINUS
:
4651 /* For addition and subtraction, we can have a 1-bit carry. However,
4652 if we are subtracting 1 from a positive number, there will not
4653 be such a carry. Furthermore, if the positive number is known to
4654 be 0 or 1, we know the result is either -1 or 0. */
4656 if (code
== PLUS
&& XEXP (x
, 1) == constm1_rtx
4657 && bitwidth
<= HOST_BITS_PER_WIDE_INT
)
4659 nonzero
= nonzero_bits (XEXP (x
, 0), mode
);
4660 if ((((HOST_WIDE_INT
) 1 << (bitwidth
- 1)) & nonzero
) == 0)
4661 return (nonzero
== 1 || nonzero
== 0 ? bitwidth
4662 : bitwidth
- floor_log2 (nonzero
) - 1);
4665 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4666 known_x
, known_mode
, known_ret
);
4667 num1
= cached_num_sign_bit_copies (XEXP (x
, 1), mode
,
4668 known_x
, known_mode
, known_ret
);
4669 result
= MAX (1, MIN (num0
, num1
) - 1);
4671 #ifdef POINTERS_EXTEND_UNSIGNED
4672 /* If pointers extend signed and this is an addition or subtraction
4673 to a pointer in Pmode, all the bits above ptr_mode are known to be
4675 if (! POINTERS_EXTEND_UNSIGNED
&& GET_MODE (x
) == Pmode
4676 && (code
== PLUS
|| code
== MINUS
)
4677 && REG_P (XEXP (x
, 0)) && REG_POINTER (XEXP (x
, 0)))
4678 result
= MAX ((int) (GET_MODE_BITSIZE (Pmode
)
4679 - GET_MODE_BITSIZE (ptr_mode
) + 1),
4685 /* The number of bits of the product is the sum of the number of
4686 bits of both terms. However, unless one of the terms if known
4687 to be positive, we must allow for an additional bit since negating
4688 a negative number can remove one sign bit copy. */
4690 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4691 known_x
, known_mode
, known_ret
);
4692 num1
= cached_num_sign_bit_copies (XEXP (x
, 1), mode
,
4693 known_x
, known_mode
, known_ret
);
4695 result
= bitwidth
- (bitwidth
- num0
) - (bitwidth
- num1
);
4697 && (bitwidth
> HOST_BITS_PER_WIDE_INT
4698 || (((nonzero_bits (XEXP (x
, 0), mode
)
4699 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
4700 && ((nonzero_bits (XEXP (x
, 1), mode
)
4701 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0))))
4704 return MAX (1, result
);
4707 /* The result must be <= the first operand. If the first operand
4708 has the high bit set, we know nothing about the number of sign
4710 if (bitwidth
> HOST_BITS_PER_WIDE_INT
)
4712 else if ((nonzero_bits (XEXP (x
, 0), mode
)
4713 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
4716 return cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4717 known_x
, known_mode
, known_ret
);
4720 /* The result must be <= the second operand. */
4721 return cached_num_sign_bit_copies (XEXP (x
, 1), mode
,
4722 known_x
, known_mode
, known_ret
);
4725 /* Similar to unsigned division, except that we have to worry about
4726 the case where the divisor is negative, in which case we have
4728 result
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4729 known_x
, known_mode
, known_ret
);
4731 && (bitwidth
> HOST_BITS_PER_WIDE_INT
4732 || (nonzero_bits (XEXP (x
, 1), mode
)
4733 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0))
4739 result
= cached_num_sign_bit_copies (XEXP (x
, 1), mode
,
4740 known_x
, known_mode
, known_ret
);
4742 && (bitwidth
> HOST_BITS_PER_WIDE_INT
4743 || (nonzero_bits (XEXP (x
, 1), mode
)
4744 & ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0))
4750 /* Shifts by a constant add to the number of bits equal to the
4752 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4753 known_x
, known_mode
, known_ret
);
4754 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
4755 && INTVAL (XEXP (x
, 1)) > 0)
4756 num0
= MIN ((int) bitwidth
, num0
+ INTVAL (XEXP (x
, 1)));
4761 /* Left shifts destroy copies. */
4762 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
4763 || INTVAL (XEXP (x
, 1)) < 0
4764 || INTVAL (XEXP (x
, 1)) >= (int) bitwidth
)
4767 num0
= cached_num_sign_bit_copies (XEXP (x
, 0), mode
,
4768 known_x
, known_mode
, known_ret
);
4769 return MAX (1, num0
- INTVAL (XEXP (x
, 1)));
4772 num0
= cached_num_sign_bit_copies (XEXP (x
, 1), mode
,
4773 known_x
, known_mode
, known_ret
);
4774 num1
= cached_num_sign_bit_copies (XEXP (x
, 2), mode
,
4775 known_x
, known_mode
, known_ret
);
4776 return MIN (num0
, num1
);
4778 case EQ
: case NE
: case GE
: case GT
: case LE
: case LT
:
4779 case UNEQ
: case LTGT
: case UNGE
: case UNGT
: case UNLE
: case UNLT
:
4780 case GEU
: case GTU
: case LEU
: case LTU
:
4781 case UNORDERED
: case ORDERED
:
4782 /* If the constant is negative, take its 1's complement and remask.
4783 Then see how many zero bits we have. */
4784 nonzero
= STORE_FLAG_VALUE
;
4785 if (bitwidth
<= HOST_BITS_PER_WIDE_INT
4786 && (nonzero
& ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))) != 0)
4787 nonzero
= (~nonzero
) & GET_MODE_MASK (mode
);
4789 return (nonzero
== 0 ? bitwidth
: bitwidth
- floor_log2 (nonzero
) - 1);
4795 /* If we haven't been able to figure it out by one of the above rules,
4796 see if some of the high-order bits are known to be zero. If so,
4797 count those bits and return one less than that amount. If we can't
4798 safely compute the mask for this mode, always return BITWIDTH. */
4800 bitwidth
= GET_MODE_BITSIZE (mode
);
4801 if (bitwidth
> HOST_BITS_PER_WIDE_INT
)
4804 nonzero
= nonzero_bits (x
, mode
);
4805 return nonzero
& ((HOST_WIDE_INT
) 1 << (bitwidth
- 1))
4806 ? 1 : bitwidth
- floor_log2 (nonzero
) - 1;