1 /* Alias analysis for GNU C
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by John Carr (jfc@mit.edu).
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "hard-reg-set.h"
29 static rtx canon_rtx PROTO((rtx));
30 static int rtx_equal_for_memref_p PROTO((rtx, rtx));
31 static rtx find_symbolic_term PROTO((rtx));
32 static int memrefs_conflict_p PROTO((int, rtx, int, rtx,
35 /* Set up all info needed to perform alias analysis on memory references. */
37 #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X)))
39 /* reg_base_value[N] gives an address to which register N is related.
40 If all sets after the first add or subtract to the current value
41 or otherwise modify it so it does not point to a different top level
42 object, reg_base_value[N] is equal to the address part of the source
43 of the first set. The value will be a SYMBOL_REF, a LABEL_REF, or
44 (address (reg)) to indicate that the address is derived from an
45 argument or fixed register. */
47 unsigned int reg_base_value_size; /* size of reg_base_value array */
48 #define REG_BASE_VALUE(X) \
49 (REGNO (X) < reg_base_value_size ? reg_base_value[REGNO (X)] : 0)
51 /* Vector indexed by N giving the initial (unchanging) value known
52 for pseudo-register N. */
55 /* Indicates number of valid entries in reg_known_value. */
56 static int reg_known_value_size;
58 /* Vector recording for each reg_known_value whether it is due to a
59 REG_EQUIV note. Future passes (viz., reload) may replace the
60 pseudo with the equivalent expression and so we account for the
61 dependences that would be introduced if that happens. */
62 /* ??? This is a problem only on the Convex. The REG_EQUIV notes created in
63 assign_parms mention the arg pointer, and there are explicit insns in the
64 RTL that modify the arg pointer. Thus we must ensure that such insns don't
65 get scheduled across each other because that would invalidate the REG_EQUIV
66 notes. One could argue that the REG_EQUIV notes are wrong, but solving
67 the problem in the scheduler will likely give better code, so we do it
69 char *reg_known_equiv_p;
71 /* Inside SRC, the source of a SET, find a base address. */
73 /* When copying arguments into pseudo-registers, record the (ADDRESS)
74 expression for the argument directly so that even if the argument
75 register is changed later (e.g. for a function call) the original
77 static int copying_arguments;
83 switch (GET_CODE (src))
90 if (copying_arguments && REGNO (src) < FIRST_PSEUDO_REGISTER)
91 return reg_base_value[REGNO (src)];
95 /* Check for an argument passed in memory. Only record in the
96 copying-arguments block; it is too hard to track changes
99 && (XEXP (src, 0) == arg_pointer_rtx
100 || (GET_CODE (XEXP (src, 0)) == PLUS
101 && XEXP (XEXP (src, 0), 0) == arg_pointer_rtx)))
102 return gen_rtx (ADDRESS, VOIDmode, src);
107 if (GET_CODE (src) != PLUS && GET_CODE (src) != MINUS)
112 /* Guess which operand to set the register equivalent to. */
113 /* If the first operand is a symbol or the second operand is
114 an integer, the first operand is the base address. */
115 if (GET_CODE (XEXP (src, 0)) == SYMBOL_REF
116 || GET_CODE (XEXP (src, 0)) == LABEL_REF
117 || GET_CODE (XEXP (src, 1)) == CONST_INT)
118 return XEXP (src, 0);
119 /* If an operand is a register marked as a pointer, it is the base. */
120 if (GET_CODE (XEXP (src, 0)) == REG
121 && REGNO_POINTER_FLAG (REGNO (XEXP (src, 0))))
123 else if (GET_CODE (XEXP (src, 1)) == REG
124 && REGNO_POINTER_FLAG (REGNO (XEXP (src, 1))))
128 if (copying_arguments && REGNO (src) < FIRST_PSEUDO_REGISTER)
129 return reg_base_value[REGNO (src)];
133 /* If the second operand is constant set the base
134 address to the first operand. */
135 if (GET_CODE (XEXP (src, 1)) == CONST_INT
136 && GET_CODE (XEXP (src, 0)) == REG)
139 if (copying_arguments && REGNO (src) < FIRST_PSEUDO_REGISTER)
140 return reg_base_value[REGNO (src)];
146 return XEXP (src, 0);
152 /* Called from init_alias_analysis indirectly through note_stores. */
154 /* while scanning insns to find base values, reg_seen[N] is nonzero if
155 register N has been set in this function. */
156 static char *reg_seen;
159 void record_set (dest, set)
165 if (GET_CODE (dest) != REG)
168 regno = REGNO (dest);
172 /* A CLOBBER wipes out any old value but does not prevent a previously
173 unset register from acquiring a base address (i.e. reg_seen is not
175 if (GET_CODE (set) == CLOBBER)
177 reg_base_value[regno] = 0;
184 static int unique_id;
187 reg_base_value[regno] = 0;
191 reg_base_value[regno] = gen_rtx (ADDRESS, Pmode,
192 GEN_INT (unique_id++));
196 /* This is not the first set. If the new value is not related to the
197 old value, forget the base value. Note that the following code is
199 extern int x, y; int *p = &x; p += (&y-&x);
200 ANSI C does not allow computing the difference of addresses
201 of distinct top level objects. */
202 if (reg_base_value[regno])
203 switch (GET_CODE (src))
207 if (XEXP (src, 0) != dest && XEXP (src, 1) != dest)
208 reg_base_value[regno] = 0;
211 if (XEXP (src, 0) != dest || GET_CODE (XEXP (src, 1)) != CONST_INT)
212 reg_base_value[regno] = 0;
215 if (XEXP (src, 0) != dest)
216 reg_base_value[regno] = 0;
219 reg_base_value[regno] = 0;
222 /* If this is the first set of a register, record the value. */
223 else if ((regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
224 && ! reg_seen[regno] && reg_base_value[regno] == 0)
225 reg_base_value[regno] = find_base_value (src);
230 /* Called from loop optimization when a new pseudo-register is created. */
232 record_base_value (regno, val)
236 if (!flag_alias_check || regno >= reg_base_value_size)
238 if (GET_CODE (val) == REG)
240 if (REGNO (val) < reg_base_value_size)
241 reg_base_value[regno] = reg_base_value[REGNO (val)];
244 reg_base_value[regno] = find_base_value (val);
251 /* Recursively look for equivalences. */
252 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
253 && REGNO (x) < reg_known_value_size)
254 return reg_known_value[REGNO (x)] == x
255 ? x : canon_rtx (reg_known_value[REGNO (x)]);
256 else if (GET_CODE (x) == PLUS)
258 rtx x0 = canon_rtx (XEXP (x, 0));
259 rtx x1 = canon_rtx (XEXP (x, 1));
261 if (x0 != XEXP (x, 0) || x1 != XEXP (x, 1))
263 /* We can tolerate LO_SUMs being offset here; these
264 rtl are used for nothing other than comparisons. */
265 if (GET_CODE (x0) == CONST_INT)
266 return plus_constant_for_output (x1, INTVAL (x0));
267 else if (GET_CODE (x1) == CONST_INT)
268 return plus_constant_for_output (x0, INTVAL (x1));
269 return gen_rtx (PLUS, GET_MODE (x), x0, x1);
272 /* This gives us much better alias analysis when called from
273 the loop optimizer. Note we want to leave the original
274 MEM alone, but need to return the canonicalized MEM with
275 all the flags with their original values. */
276 else if (GET_CODE (x) == MEM)
278 rtx addr = canon_rtx (XEXP (x, 0));
279 if (addr != XEXP (x, 0))
281 rtx new = gen_rtx (MEM, GET_MODE (x), addr);
282 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
283 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
284 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
291 /* Return 1 if X and Y are identical-looking rtx's.
293 We use the data in reg_known_value above to see if two registers with
294 different numbers are, in fact, equivalent. */
297 rtx_equal_for_memref_p (x, y)
302 register enum rtx_code code;
305 if (x == 0 && y == 0)
307 if (x == 0 || y == 0)
316 /* Rtx's of different codes cannot be equal. */
317 if (code != GET_CODE (y))
320 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
321 (REG:SI x) and (REG:HI x) are NOT equivalent. */
323 if (GET_MODE (x) != GET_MODE (y))
326 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
329 return REGNO (x) == REGNO (y);
330 if (code == LABEL_REF)
331 return XEXP (x, 0) == XEXP (y, 0);
332 if (code == SYMBOL_REF)
333 return XSTR (x, 0) == XSTR (y, 0);
335 /* For commutative operations, the RTX match if the operand match in any
336 order. Also handle the simple binary and unary cases without a loop. */
337 if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c')
338 return ((rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
339 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)))
340 || (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 1))
341 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 0))));
342 else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2')
343 return (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
344 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)));
345 else if (GET_RTX_CLASS (code) == '1')
346 return rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0));
348 /* Compare the elements. If any pair of corresponding elements
349 fail to match, return 0 for the whole things. */
351 fmt = GET_RTX_FORMAT (code);
352 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
357 if (XWINT (x, i) != XWINT (y, i))
363 if (XINT (x, i) != XINT (y, i))
369 /* Two vectors must have the same length. */
370 if (XVECLEN (x, i) != XVECLEN (y, i))
373 /* And the corresponding elements must match. */
374 for (j = 0; j < XVECLEN (x, i); j++)
375 if (rtx_equal_for_memref_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
380 if (rtx_equal_for_memref_p (XEXP (x, i), XEXP (y, i)) == 0)
386 if (strcmp (XSTR (x, i), XSTR (y, i)))
391 /* These are just backpointers, so they don't matter. */
397 /* It is believed that rtx's at this level will never
398 contain anything but integers and other rtx's,
399 except for within LABEL_REFs and SYMBOL_REFs. */
407 /* Given an rtx X, find a SYMBOL_REF or LABEL_REF within
408 X and return it, or return 0 if none found. */
411 find_symbolic_term (x)
415 register enum rtx_code code;
419 if (code == SYMBOL_REF || code == LABEL_REF)
421 if (GET_RTX_CLASS (code) == 'o')
424 fmt = GET_RTX_FORMAT (code);
425 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
431 t = find_symbolic_term (XEXP (x, i));
435 else if (fmt[i] == 'E')
445 switch (GET_CODE (x))
448 return REG_BASE_VALUE (x);
451 return find_base_term (XEXP (x, 0));
455 if (GET_CODE (x) != PLUS && GET_CODE (x) != MINUS)
462 rtx tmp = find_base_term (XEXP (x, 0));
465 return find_base_term (XEXP (x, 1));
469 if (GET_CODE (XEXP (x, 0)) == REG && GET_CODE (XEXP (x, 1)) == CONST_INT)
470 return REG_BASE_VALUE (XEXP (x, 0));
482 /* Return 0 if the addresses X and Y are known to point to different
483 objects, 1 if they might be pointers to the same object. */
486 base_alias_check (x, y)
489 rtx x_base = find_base_term (x);
490 rtx y_base = find_base_term (y);
492 /* If either base address is unknown or the base addresses are equal,
493 nothing is known about aliasing. */
495 if (x_base == 0 || y_base == 0 || rtx_equal_p (x_base, y_base))
498 /* The base addresses of the read and write are different
499 expressions. If they are both symbols there is no
501 if (GET_CODE (x_base) != ADDRESS && GET_CODE (y_base) != ADDRESS)
504 /* If one address is a stack reference there can be no alias:
505 stack references using different base registers do not alias,
506 a stack reference can not alias a parameter, and a stack reference
507 can not alias a global. */
508 if ((GET_CODE (x_base) == ADDRESS && GET_MODE (x_base) == Pmode)
509 || (GET_CODE (y_base) == ADDRESS && GET_MODE (y_base) == Pmode))
512 if (! flag_argument_noalias)
515 if (flag_argument_noalias > 1)
518 /* Weak noalias assertion (arguments are distinct, but may match globals). */
519 return ! (GET_MODE (x_base) == VOIDmode && GET_MODE (y_base) == VOIDmode);
522 /* Return nonzero if X and Y (memory addresses) could reference the
523 same location in memory. C is an offset accumulator. When
524 C is nonzero, we are testing aliases between X and Y + C.
525 XSIZE is the size in bytes of the X reference,
526 similarly YSIZE is the size in bytes for Y.
528 If XSIZE or YSIZE is zero, we do not know the amount of memory being
529 referenced (the reference was BLKmode), so make the most pessimistic
532 We recognize the following cases of non-conflicting memory:
534 (1) addresses involving the frame pointer cannot conflict
535 with addresses involving static variables.
536 (2) static variables with different addresses cannot conflict.
538 Nice to notice that varying addresses cannot conflict with fp if no
539 local variables had their addresses taken, but that's too hard now. */
543 memrefs_conflict_p (xsize, x, ysize, y, c)
548 if (GET_CODE (x) == HIGH)
550 else if (GET_CODE (x) == LO_SUM)
554 if (GET_CODE (y) == HIGH)
556 else if (GET_CODE (y) == LO_SUM)
561 if (rtx_equal_for_memref_p (x, y))
563 if (xsize == 0 || ysize == 0)
565 if (c >= 0 && xsize > c)
567 if (c < 0 && ysize+c > 0)
572 if (y == frame_pointer_rtx || y == hard_frame_pointer_rtx
573 || y == stack_pointer_rtx)
577 y = x; ysize = xsize;
578 x = t; xsize = tsize;
581 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
582 || x == stack_pointer_rtx)
589 if (GET_CODE (y) == PLUS
590 && canon_rtx (XEXP (y, 0)) == x
591 && (y1 = canon_rtx (XEXP (y, 1)))
592 && GET_CODE (y1) == CONST_INT)
595 return (xsize == 0 || ysize == 0
596 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
599 if (GET_CODE (y) == PLUS
600 && (y1 = canon_rtx (XEXP (y, 0)))
607 if (GET_CODE (x) == PLUS)
609 /* The fact that X is canonicalized means that this
610 PLUS rtx is canonicalized. */
611 rtx x0 = XEXP (x, 0);
612 rtx x1 = XEXP (x, 1);
614 if (GET_CODE (y) == PLUS)
616 /* The fact that Y is canonicalized means that this
617 PLUS rtx is canonicalized. */
618 rtx y0 = XEXP (y, 0);
619 rtx y1 = XEXP (y, 1);
621 if (rtx_equal_for_memref_p (x1, y1))
622 return memrefs_conflict_p (xsize, x0, ysize, y0, c);
623 if (rtx_equal_for_memref_p (x0, y0))
624 return memrefs_conflict_p (xsize, x1, ysize, y1, c);
625 if (GET_CODE (x1) == CONST_INT)
626 if (GET_CODE (y1) == CONST_INT)
627 return memrefs_conflict_p (xsize, x0, ysize, y0,
628 c - INTVAL (x1) + INTVAL (y1));
630 return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
631 else if (GET_CODE (y1) == CONST_INT)
632 return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
634 /* Handle case where we cannot understand iteration operators,
635 but we notice that the base addresses are distinct objects. */
636 /* ??? Is this still necessary? */
637 x = find_symbolic_term (x);
640 y = find_symbolic_term (y);
643 return rtx_equal_for_memref_p (x, y);
645 else if (GET_CODE (x1) == CONST_INT)
646 return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
648 else if (GET_CODE (y) == PLUS)
650 /* The fact that Y is canonicalized means that this
651 PLUS rtx is canonicalized. */
652 rtx y0 = XEXP (y, 0);
653 rtx y1 = XEXP (y, 1);
655 if (GET_CODE (y1) == CONST_INT)
656 return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
661 if (GET_CODE (x) == GET_CODE (y))
662 switch (GET_CODE (x))
666 /* Handle cases where we expect the second operands to be the
667 same, and check only whether the first operand would conflict
670 rtx x1 = canon_rtx (XEXP (x, 1));
671 rtx y1 = canon_rtx (XEXP (y, 1));
672 if (! rtx_equal_for_memref_p (x1, y1))
674 x0 = canon_rtx (XEXP (x, 0));
675 y0 = canon_rtx (XEXP (y, 0));
676 if (rtx_equal_for_memref_p (x0, y0))
677 return (xsize == 0 || ysize == 0
678 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
680 /* Can't properly adjust our sizes. */
681 if (GET_CODE (x1) != CONST_INT)
683 xsize /= INTVAL (x1);
684 ysize /= INTVAL (x1);
686 return memrefs_conflict_p (xsize, x0, ysize, y0, c);
690 /* Treat an access through an AND (e.g. a subword access on an Alpha)
691 as an access with indeterminate size. */
692 if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT)
693 return memrefs_conflict_p (0, XEXP (x, 0), ysize, y, c);
694 if (GET_CODE (y) == AND && GET_CODE (XEXP (y, 1)) == CONST_INT)
695 return memrefs_conflict_p (xsize, x, 0, XEXP (y, 0), c);
699 if (GET_CODE (x) == CONST_INT && GET_CODE (y) == CONST_INT)
701 c += (INTVAL (y) - INTVAL (x));
702 return (xsize == 0 || ysize == 0
703 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
706 if (GET_CODE (x) == CONST)
708 if (GET_CODE (y) == CONST)
709 return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
710 ysize, canon_rtx (XEXP (y, 0)), c);
712 return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
715 if (GET_CODE (y) == CONST)
716 return memrefs_conflict_p (xsize, x, ysize,
717 canon_rtx (XEXP (y, 0)), c);
720 return (rtx_equal_for_memref_p (x, y)
721 && (xsize == 0 || ysize == 0
722 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0)));
729 /* Functions to compute memory dependencies.
731 Since we process the insns in execution order, we can build tables
732 to keep track of what registers are fixed (and not aliased), what registers
733 are varying in known ways, and what registers are varying in unknown
736 If both memory references are volatile, then there must always be a
737 dependence between the two references, since their order can not be
738 changed. A volatile and non-volatile reference can be interchanged
741 A MEM_IN_STRUCT reference at a non-QImode varying address can never
742 conflict with a non-MEM_IN_STRUCT reference at a fixed address. We must
743 allow QImode aliasing because the ANSI C standard allows character
744 pointers to alias anything. We are assuming that characters are
745 always QImode here. */
747 /* Read dependence: X is read after read in MEM takes place. There can
748 only be a dependence here if both reads are volatile. */
751 read_dependence (mem, x)
755 return MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem);
758 /* True dependence: X is read after store in MEM takes place. */
761 true_dependence (mem, mem_mode, x, varies)
763 enum machine_mode mem_mode;
767 rtx x_addr, mem_addr;
769 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
772 x_addr = XEXP (x, 0);
773 mem_addr = XEXP (mem, 0);
775 if (flag_alias_check && ! base_alias_check (x_addr, mem_addr))
778 /* If X is an unchanging read, then it can't possibly conflict with any
779 non-unchanging store. It may conflict with an unchanging write though,
780 because there may be a single store to this address to initialize it.
781 Just fall through to the code below to resolve the case where we have
782 both an unchanging read and an unchanging write. This won't handle all
783 cases optimally, but the possible performance loss should be
785 if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem))
788 x_addr = canon_rtx (x_addr);
789 mem_addr = canon_rtx (mem_addr);
790 if (mem_mode == VOIDmode)
791 mem_mode = GET_MODE (mem);
793 if (! memrefs_conflict_p (mem_mode, mem_addr, SIZE_FOR_MODE (x), x_addr, 0))
796 /* If both references are struct references, or both are not, nothing
797 is known about aliasing.
799 If either reference is QImode or BLKmode, ANSI C permits aliasing.
801 If both addresses are constant, or both are not, nothing is known
803 if (MEM_IN_STRUCT_P (x) == MEM_IN_STRUCT_P (mem)
804 || mem_mode == QImode || mem_mode == BLKmode
805 || GET_MODE (x) == QImode || GET_MODE (mem) == BLKmode
806 || varies (x_addr) == varies (mem_addr))
809 /* One memory reference is to a constant address, one is not.
810 One is to a structure, the other is not.
812 If either memory reference is a variable structure the other is a
813 fixed scalar and there is no aliasing. */
814 if ((MEM_IN_STRUCT_P (mem) && varies (mem_addr))
815 || (MEM_IN_STRUCT_P (x) && varies (x)))
821 /* Anti dependence: X is written after read in MEM takes place. */
824 anti_dependence (mem, x)
828 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
831 if (flag_alias_check && ! base_alias_check (XEXP (x, 0), XEXP (mem, 0)))
834 /* If MEM is an unchanging read, then it can't possibly conflict with
835 the store to X, because there is at most one store to MEM, and it must
836 have occurred somewhere before MEM. */
838 mem = canon_rtx (mem);
839 if (RTX_UNCHANGING_P (mem))
842 return (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
843 SIZE_FOR_MODE (x), XEXP (x, 0), 0)
844 && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
845 && GET_MODE (mem) != QImode
846 && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
847 && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
848 && GET_MODE (x) != QImode
849 && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem)));
852 /* Output dependence: X is written after store in MEM takes place. */
855 output_dependence (mem, x)
859 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
862 if (flag_alias_check && !base_alias_check (XEXP (x, 0), XEXP (mem, 0)))
866 mem = canon_rtx (mem);
867 return (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
868 SIZE_FOR_MODE (x), XEXP (x, 0), 0)
869 && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
870 && GET_MODE (mem) != QImode
871 && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
872 && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
873 && GET_MODE (x) != QImode
874 && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem)));
878 init_alias_analysis ()
880 int maxreg = max_reg_num ();
887 reg_known_value_size = maxreg;
890 = (rtx *) oballoc ((maxreg - FIRST_PSEUDO_REGISTER) * sizeof (rtx))
891 - FIRST_PSEUDO_REGISTER;
893 oballoc (maxreg - FIRST_PSEUDO_REGISTER) - FIRST_PSEUDO_REGISTER;
894 bzero ((char *) (reg_known_value + FIRST_PSEUDO_REGISTER),
895 (maxreg-FIRST_PSEUDO_REGISTER) * sizeof (rtx));
896 bzero (reg_known_equiv_p + FIRST_PSEUDO_REGISTER,
897 (maxreg - FIRST_PSEUDO_REGISTER) * sizeof (char));
899 if (flag_alias_check)
901 /* Overallocate reg_base_value to allow some growth during loop
902 optimization. Loop unrolling can create a large number of
904 reg_base_value_size = maxreg * 2;
905 reg_base_value = (rtx *)oballoc (reg_base_value_size * sizeof (rtx));
906 reg_seen = (char *)alloca (reg_base_value_size);
907 bzero (reg_base_value, reg_base_value_size * sizeof (rtx));
908 bzero (reg_seen, reg_base_value_size);
910 /* Mark all hard registers which may contain an address.
911 The stack, frame and argument pointers may contain an address.
912 An argument register which can hold a Pmode value may contain
913 an address even if it is not in BASE_REGS.
915 The address expression is VOIDmode for an argument and
916 Pmode for other registers. */
917 #ifndef OUTGOING_REGNO
918 #define OUTGOING_REGNO(N) N
920 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
921 /* Check whether this register can hold an incoming pointer
922 argument. FUNCTION_ARG_REGNO_P tests outgoing register
923 numbers, so translate if necessary due to register windows. */
924 if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (i)) && HARD_REGNO_MODE_OK (i, Pmode))
925 reg_base_value[i] = gen_rtx (ADDRESS, VOIDmode,
926 gen_rtx (REG, Pmode, i));
928 reg_base_value[STACK_POINTER_REGNUM]
929 = gen_rtx (ADDRESS, Pmode, stack_pointer_rtx);
930 reg_base_value[ARG_POINTER_REGNUM]
931 = gen_rtx (ADDRESS, Pmode, arg_pointer_rtx);
932 reg_base_value[FRAME_POINTER_REGNUM]
933 = gen_rtx (ADDRESS, Pmode, frame_pointer_rtx);
934 reg_base_value[HARD_FRAME_POINTER_REGNUM]
935 = gen_rtx (ADDRESS, Pmode, hard_frame_pointer_rtx);
938 copying_arguments = 1;
939 /* Fill in the entries with known constant values. */
940 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
942 if (flag_alias_check && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
944 /* If this insn has a noalias note, process it, Otherwise,
945 scan for sets. A simple set will have no side effects
946 which could change the base value of any other register. */
948 if (GET_CODE (PATTERN (insn)) == SET
949 && (noalias_note = find_reg_note (insn, REG_NOALIAS, NULL_RTX)))
950 record_set (SET_DEST (PATTERN (insn)), 0);
952 note_stores (PATTERN (insn), record_set);
954 else if (GET_CODE (insn) == NOTE
955 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
956 copying_arguments = 0;
958 if ((set = single_set (insn)) != 0
959 && GET_CODE (SET_DEST (set)) == REG
960 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
961 && (((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
962 && REG_N_SETS (REGNO (SET_DEST (set))) == 1)
963 || (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0)
964 && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
966 int regno = REGNO (SET_DEST (set));
967 reg_known_value[regno] = XEXP (note, 0);
968 reg_known_equiv_p[regno] = REG_NOTE_KIND (note) == REG_EQUIV;
972 /* Fill in the remaining entries. */
973 for (i = FIRST_PSEUDO_REGISTER; i < maxreg; i++)
974 if (reg_known_value[i] == 0)
975 reg_known_value[i] = regno_reg_rtx[i];
977 if (! flag_alias_check)
980 /* Simplify the reg_base_value array so that no register refers to
981 another register, except to special registers indirectly through
984 In theory this loop can take as long as O(registers^2), but unless
985 there are very long dependency chains it will run in close to linear
990 for (i = 0; i < reg_base_value_size; i++)
992 rtx base = reg_base_value[i];
993 if (base && GET_CODE (base) == REG)
995 int base_regno = REGNO (base);
996 if (base_regno == i) /* register set from itself */
997 reg_base_value[i] = 0;
999 reg_base_value[i] = reg_base_value[base_regno];
1010 end_alias_analysis ()
1012 reg_known_value = 0;
1014 reg_base_value_size = 0;