xref: /dragonfly/contrib/gcc-4.7/gcc/alias.c (revision 95d28233)
1e4b17023SJohn Marino /* Alias analysis for GNU C
2e4b17023SJohn Marino    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3e4b17023SJohn Marino    2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4e4b17023SJohn Marino    Contributed by John Carr (jfc@mit.edu).
5e4b17023SJohn Marino 
6e4b17023SJohn Marino This file is part of GCC.
7e4b17023SJohn Marino 
8e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11e4b17023SJohn Marino version.
12e4b17023SJohn Marino 
13e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16e4b17023SJohn Marino for more details.
17e4b17023SJohn Marino 
18e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
20e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
21e4b17023SJohn Marino 
22e4b17023SJohn Marino #include "config.h"
23e4b17023SJohn Marino #include "system.h"
24e4b17023SJohn Marino #include "coretypes.h"
25e4b17023SJohn Marino #include "tm.h"
26e4b17023SJohn Marino #include "rtl.h"
27e4b17023SJohn Marino #include "tree.h"
28e4b17023SJohn Marino #include "tm_p.h"
29e4b17023SJohn Marino #include "function.h"
30e4b17023SJohn Marino #include "alias.h"
31e4b17023SJohn Marino #include "emit-rtl.h"
32e4b17023SJohn Marino #include "regs.h"
33e4b17023SJohn Marino #include "hard-reg-set.h"
34e4b17023SJohn Marino #include "basic-block.h"
35e4b17023SJohn Marino #include "flags.h"
36e4b17023SJohn Marino #include "output.h"
37e4b17023SJohn Marino #include "diagnostic-core.h"
38e4b17023SJohn Marino #include "cselib.h"
39e4b17023SJohn Marino #include "splay-tree.h"
40e4b17023SJohn Marino #include "ggc.h"
41e4b17023SJohn Marino #include "langhooks.h"
42e4b17023SJohn Marino #include "timevar.h"
43e4b17023SJohn Marino #include "target.h"
44e4b17023SJohn Marino #include "cgraph.h"
45e4b17023SJohn Marino #include "tree-pass.h"
46e4b17023SJohn Marino #include "df.h"
47e4b17023SJohn Marino #include "tree-ssa-alias.h"
48e4b17023SJohn Marino #include "pointer-set.h"
49e4b17023SJohn Marino #include "tree-flow.h"
50e4b17023SJohn Marino 
51e4b17023SJohn Marino /* The aliasing API provided here solves related but different problems:
52e4b17023SJohn Marino 
53e4b17023SJohn Marino    Say there exists (in c)
54e4b17023SJohn Marino 
55e4b17023SJohn Marino    struct X {
56e4b17023SJohn Marino      struct Y y1;
57e4b17023SJohn Marino      struct Z z2;
58e4b17023SJohn Marino    } x1, *px1,  *px2;
59e4b17023SJohn Marino 
60e4b17023SJohn Marino    struct Y y2, *py;
61e4b17023SJohn Marino    struct Z z2, *pz;
62e4b17023SJohn Marino 
63e4b17023SJohn Marino 
64e4b17023SJohn Marino    py = &px1.y1;
65e4b17023SJohn Marino    px2 = &x1;
66e4b17023SJohn Marino 
67e4b17023SJohn Marino    Consider the four questions:
68e4b17023SJohn Marino 
69e4b17023SJohn Marino    Can a store to x1 interfere with px2->y1?
70e4b17023SJohn Marino    Can a store to x1 interfere with px2->z2?
71e4b17023SJohn Marino    (*px2).z2
72e4b17023SJohn Marino    Can a store to x1 change the value pointed to by with py?
73e4b17023SJohn Marino    Can a store to x1 change the value pointed to by with pz?
74e4b17023SJohn Marino 
75e4b17023SJohn Marino    The answer to these questions can be yes, yes, yes, and maybe.
76e4b17023SJohn Marino 
77e4b17023SJohn Marino    The first two questions can be answered with a simple examination
78e4b17023SJohn Marino    of the type system.  If structure X contains a field of type Y then
79e4b17023SJohn Marino    a store thru a pointer to an X can overwrite any field that is
80e4b17023SJohn Marino    contained (recursively) in an X (unless we know that px1 != px2).
81e4b17023SJohn Marino 
82e4b17023SJohn Marino    The last two of the questions can be solved in the same way as the
83e4b17023SJohn Marino    first two questions but this is too conservative.  The observation
84e4b17023SJohn Marino    is that in some cases analysis we can know if which (if any) fields
85e4b17023SJohn Marino    are addressed and if those addresses are used in bad ways.  This
86e4b17023SJohn Marino    analysis may be language specific.  In C, arbitrary operations may
87e4b17023SJohn Marino    be applied to pointers.  However, there is some indication that
88e4b17023SJohn Marino    this may be too conservative for some C++ types.
89e4b17023SJohn Marino 
90e4b17023SJohn Marino    The pass ipa-type-escape does this analysis for the types whose
91e4b17023SJohn Marino    instances do not escape across the compilation boundary.
92e4b17023SJohn Marino 
93e4b17023SJohn Marino    Historically in GCC, these two problems were combined and a single
94e4b17023SJohn Marino    data structure was used to represent the solution to these
95e4b17023SJohn Marino    problems.  We now have two similar but different data structures,
96e4b17023SJohn Marino    The data structure to solve the last two question is similar to the
97e4b17023SJohn Marino    first, but does not contain have the fields in it whose address are
98e4b17023SJohn Marino    never taken.  For types that do escape the compilation unit, the
99e4b17023SJohn Marino    data structures will have identical information.
100e4b17023SJohn Marino */
101e4b17023SJohn Marino 
102e4b17023SJohn Marino /* The alias sets assigned to MEMs assist the back-end in determining
103e4b17023SJohn Marino    which MEMs can alias which other MEMs.  In general, two MEMs in
104e4b17023SJohn Marino    different alias sets cannot alias each other, with one important
105e4b17023SJohn Marino    exception.  Consider something like:
106e4b17023SJohn Marino 
107e4b17023SJohn Marino      struct S { int i; double d; };
108e4b17023SJohn Marino 
109e4b17023SJohn Marino    a store to an `S' can alias something of either type `int' or type
110e4b17023SJohn Marino    `double'.  (However, a store to an `int' cannot alias a `double'
111e4b17023SJohn Marino    and vice versa.)  We indicate this via a tree structure that looks
112e4b17023SJohn Marino    like:
113e4b17023SJohn Marino 	   struct S
114e4b17023SJohn Marino 	    /   \
115e4b17023SJohn Marino 	   /     \
116e4b17023SJohn Marino 	 |/_     _\|
117e4b17023SJohn Marino 	 int    double
118e4b17023SJohn Marino 
119e4b17023SJohn Marino    (The arrows are directed and point downwards.)
120e4b17023SJohn Marino     In this situation we say the alias set for `struct S' is the
121e4b17023SJohn Marino    `superset' and that those for `int' and `double' are `subsets'.
122e4b17023SJohn Marino 
123e4b17023SJohn Marino    To see whether two alias sets can point to the same memory, we must
124e4b17023SJohn Marino    see if either alias set is a subset of the other. We need not trace
125e4b17023SJohn Marino    past immediate descendants, however, since we propagate all
126e4b17023SJohn Marino    grandchildren up one level.
127e4b17023SJohn Marino 
128e4b17023SJohn Marino    Alias set zero is implicitly a superset of all other alias sets.
129e4b17023SJohn Marino    However, this is no actual entry for alias set zero.  It is an
130e4b17023SJohn Marino    error to attempt to explicitly construct a subset of zero.  */
131e4b17023SJohn Marino 
132e4b17023SJohn Marino struct GTY(()) alias_set_entry_d {
133e4b17023SJohn Marino   /* The alias set number, as stored in MEM_ALIAS_SET.  */
134e4b17023SJohn Marino   alias_set_type alias_set;
135e4b17023SJohn Marino 
136e4b17023SJohn Marino   /* Nonzero if would have a child of zero: this effectively makes this
137e4b17023SJohn Marino      alias set the same as alias set zero.  */
138e4b17023SJohn Marino   int has_zero_child;
139e4b17023SJohn Marino 
140e4b17023SJohn Marino   /* The children of the alias set.  These are not just the immediate
141e4b17023SJohn Marino      children, but, in fact, all descendants.  So, if we have:
142e4b17023SJohn Marino 
143e4b17023SJohn Marino        struct T { struct S s; float f; }
144e4b17023SJohn Marino 
145e4b17023SJohn Marino      continuing our example above, the children here will be all of
146e4b17023SJohn Marino      `int', `double', `float', and `struct S'.  */
147e4b17023SJohn Marino   splay_tree GTY((param1_is (int), param2_is (int))) children;
148e4b17023SJohn Marino };
149e4b17023SJohn Marino typedef struct alias_set_entry_d *alias_set_entry;
150e4b17023SJohn Marino 
151e4b17023SJohn Marino static int rtx_equal_for_memref_p (const_rtx, const_rtx);
152e4b17023SJohn Marino static int memrefs_conflict_p (int, rtx, int, rtx, HOST_WIDE_INT);
153e4b17023SJohn Marino static void record_set (rtx, const_rtx, void *);
154e4b17023SJohn Marino static int base_alias_check (rtx, rtx, enum machine_mode,
155e4b17023SJohn Marino 			     enum machine_mode);
156e4b17023SJohn Marino static rtx find_base_value (rtx);
157e4b17023SJohn Marino static int mems_in_disjoint_alias_sets_p (const_rtx, const_rtx);
158e4b17023SJohn Marino static int insert_subset_children (splay_tree_node, void*);
159e4b17023SJohn Marino static alias_set_entry get_alias_set_entry (alias_set_type);
160e4b17023SJohn Marino static int aliases_everything_p (const_rtx);
161e4b17023SJohn Marino static bool nonoverlapping_component_refs_p (const_tree, const_tree);
162e4b17023SJohn Marino static tree decl_for_component_ref (tree);
163e4b17023SJohn Marino static int write_dependence_p (const_rtx, const_rtx, int);
164e4b17023SJohn Marino 
165e4b17023SJohn Marino static void memory_modified_1 (rtx, const_rtx, void *);
166e4b17023SJohn Marino 
167e4b17023SJohn Marino /* Set up all info needed to perform alias analysis on memory references.  */
168e4b17023SJohn Marino 
169e4b17023SJohn Marino /* Returns the size in bytes of the mode of X.  */
170e4b17023SJohn Marino #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X)))
171e4b17023SJohn Marino 
172e4b17023SJohn Marino /* Returns nonzero if MEM1 and MEM2 do not alias because they are in
173e4b17023SJohn Marino    different alias sets.  We ignore alias sets in functions making use
174e4b17023SJohn Marino    of variable arguments because the va_arg macros on some systems are
175e4b17023SJohn Marino    not legal ANSI C.  */
176e4b17023SJohn Marino #define DIFFERENT_ALIAS_SETS_P(MEM1, MEM2)			\
177e4b17023SJohn Marino   mems_in_disjoint_alias_sets_p (MEM1, MEM2)
178e4b17023SJohn Marino 
179e4b17023SJohn Marino /* Cap the number of passes we make over the insns propagating alias
180e4b17023SJohn Marino    information through set chains.   10 is a completely arbitrary choice.  */
181e4b17023SJohn Marino #define MAX_ALIAS_LOOP_PASSES 10
182e4b17023SJohn Marino 
183e4b17023SJohn Marino /* reg_base_value[N] gives an address to which register N is related.
184e4b17023SJohn Marino    If all sets after the first add or subtract to the current value
185e4b17023SJohn Marino    or otherwise modify it so it does not point to a different top level
186e4b17023SJohn Marino    object, reg_base_value[N] is equal to the address part of the source
187e4b17023SJohn Marino    of the first set.
188e4b17023SJohn Marino 
189e4b17023SJohn Marino    A base address can be an ADDRESS, SYMBOL_REF, or LABEL_REF.  ADDRESS
190e4b17023SJohn Marino    expressions represent certain special values: function arguments and
191e4b17023SJohn Marino    the stack, frame, and argument pointers.
192e4b17023SJohn Marino 
193e4b17023SJohn Marino    The contents of an ADDRESS is not normally used, the mode of the
194e4b17023SJohn Marino    ADDRESS determines whether the ADDRESS is a function argument or some
195e4b17023SJohn Marino    other special value.  Pointer equality, not rtx_equal_p, determines whether
196e4b17023SJohn Marino    two ADDRESS expressions refer to the same base address.
197e4b17023SJohn Marino 
198e4b17023SJohn Marino    The only use of the contents of an ADDRESS is for determining if the
199e4b17023SJohn Marino    current function performs nonlocal memory memory references for the
200e4b17023SJohn Marino    purposes of marking the function as a constant function.  */
201e4b17023SJohn Marino 
202e4b17023SJohn Marino static GTY(()) VEC(rtx,gc) *reg_base_value;
203e4b17023SJohn Marino static rtx *new_reg_base_value;
204e4b17023SJohn Marino 
205e4b17023SJohn Marino /* We preserve the copy of old array around to avoid amount of garbage
206e4b17023SJohn Marino    produced.  About 8% of garbage produced were attributed to this
207e4b17023SJohn Marino    array.  */
208e4b17023SJohn Marino static GTY((deletable)) VEC(rtx,gc) *old_reg_base_value;
209e4b17023SJohn Marino 
210e4b17023SJohn Marino #define static_reg_base_value \
211e4b17023SJohn Marino   (this_target_rtl->x_static_reg_base_value)
212e4b17023SJohn Marino 
213e4b17023SJohn Marino #define REG_BASE_VALUE(X)				\
214e4b17023SJohn Marino   (REGNO (X) < VEC_length (rtx, reg_base_value)		\
215e4b17023SJohn Marino    ? VEC_index (rtx, reg_base_value, REGNO (X)) : 0)
216e4b17023SJohn Marino 
217e4b17023SJohn Marino /* Vector indexed by N giving the initial (unchanging) value known for
218e4b17023SJohn Marino    pseudo-register N.  This array is initialized in init_alias_analysis,
219e4b17023SJohn Marino    and does not change until end_alias_analysis is called.  */
220e4b17023SJohn Marino static GTY((length("reg_known_value_size"))) rtx *reg_known_value;
221e4b17023SJohn Marino 
222e4b17023SJohn Marino /* Indicates number of valid entries in reg_known_value.  */
223e4b17023SJohn Marino static GTY(()) unsigned int reg_known_value_size;
224e4b17023SJohn Marino 
225e4b17023SJohn Marino /* Vector recording for each reg_known_value whether it is due to a
226e4b17023SJohn Marino    REG_EQUIV note.  Future passes (viz., reload) may replace the
227e4b17023SJohn Marino    pseudo with the equivalent expression and so we account for the
228e4b17023SJohn Marino    dependences that would be introduced if that happens.
229e4b17023SJohn Marino 
230e4b17023SJohn Marino    The REG_EQUIV notes created in assign_parms may mention the arg
231e4b17023SJohn Marino    pointer, and there are explicit insns in the RTL that modify the
232e4b17023SJohn Marino    arg pointer.  Thus we must ensure that such insns don't get
233e4b17023SJohn Marino    scheduled across each other because that would invalidate the
234e4b17023SJohn Marino    REG_EQUIV notes.  One could argue that the REG_EQUIV notes are
235e4b17023SJohn Marino    wrong, but solving the problem in the scheduler will likely give
236e4b17023SJohn Marino    better code, so we do it here.  */
237e4b17023SJohn Marino static bool *reg_known_equiv_p;
238e4b17023SJohn Marino 
239e4b17023SJohn Marino /* True when scanning insns from the start of the rtl to the
240e4b17023SJohn Marino    NOTE_INSN_FUNCTION_BEG note.  */
241e4b17023SJohn Marino static bool copying_arguments;
242e4b17023SJohn Marino 
243e4b17023SJohn Marino DEF_VEC_P(alias_set_entry);
244e4b17023SJohn Marino DEF_VEC_ALLOC_P(alias_set_entry,gc);
245e4b17023SJohn Marino 
246e4b17023SJohn Marino /* The splay-tree used to store the various alias set entries.  */
247e4b17023SJohn Marino static GTY (()) VEC(alias_set_entry,gc) *alias_sets;
248e4b17023SJohn Marino 
249e4b17023SJohn Marino /* Build a decomposed reference object for querying the alias-oracle
250e4b17023SJohn Marino    from the MEM rtx and store it in *REF.
251e4b17023SJohn Marino    Returns false if MEM is not suitable for the alias-oracle.  */
252e4b17023SJohn Marino 
253e4b17023SJohn Marino static bool
ao_ref_from_mem(ao_ref * ref,const_rtx mem)254e4b17023SJohn Marino ao_ref_from_mem (ao_ref *ref, const_rtx mem)
255e4b17023SJohn Marino {
256e4b17023SJohn Marino   tree expr = MEM_EXPR (mem);
257e4b17023SJohn Marino   tree base;
258e4b17023SJohn Marino 
259e4b17023SJohn Marino   if (!expr)
260e4b17023SJohn Marino     return false;
261e4b17023SJohn Marino 
262e4b17023SJohn Marino   ao_ref_init (ref, expr);
263e4b17023SJohn Marino 
264e4b17023SJohn Marino   /* Get the base of the reference and see if we have to reject or
265e4b17023SJohn Marino      adjust it.  */
266e4b17023SJohn Marino   base = ao_ref_base (ref);
267e4b17023SJohn Marino   if (base == NULL_TREE)
268e4b17023SJohn Marino     return false;
269e4b17023SJohn Marino 
270e4b17023SJohn Marino   /* The tree oracle doesn't like to have these.  */
271e4b17023SJohn Marino   if (TREE_CODE (base) == FUNCTION_DECL
272e4b17023SJohn Marino       || TREE_CODE (base) == LABEL_DECL)
273e4b17023SJohn Marino     return false;
274e4b17023SJohn Marino 
275e4b17023SJohn Marino   /* If this is a pointer dereference of a non-SSA_NAME punt.
276e4b17023SJohn Marino      ???  We could replace it with a pointer to anything.  */
277e4b17023SJohn Marino   if ((INDIRECT_REF_P (base)
278e4b17023SJohn Marino        || TREE_CODE (base) == MEM_REF)
279e4b17023SJohn Marino       && TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME)
280e4b17023SJohn Marino     return false;
281e4b17023SJohn Marino   if (TREE_CODE (base) == TARGET_MEM_REF
282e4b17023SJohn Marino       && TMR_BASE (base)
283e4b17023SJohn Marino       && TREE_CODE (TMR_BASE (base)) != SSA_NAME)
284e4b17023SJohn Marino     return false;
285e4b17023SJohn Marino 
286e4b17023SJohn Marino   /* If this is a reference based on a partitioned decl replace the
287e4b17023SJohn Marino      base with an INDIRECT_REF of the pointer representative we
288e4b17023SJohn Marino      created during stack slot partitioning.  */
289e4b17023SJohn Marino   if (TREE_CODE (base) == VAR_DECL
290e4b17023SJohn Marino       && ! TREE_STATIC (base)
291e4b17023SJohn Marino       && cfun->gimple_df->decls_to_pointers != NULL)
292e4b17023SJohn Marino     {
293e4b17023SJohn Marino       void *namep;
294e4b17023SJohn Marino       namep = pointer_map_contains (cfun->gimple_df->decls_to_pointers, base);
295e4b17023SJohn Marino       if (namep)
296e4b17023SJohn Marino 	ref->base = build_simple_mem_ref (*(tree *)namep);
297e4b17023SJohn Marino     }
298e4b17023SJohn Marino   else if (TREE_CODE (base) == TARGET_MEM_REF
299e4b17023SJohn Marino 	   && TREE_CODE (TMR_BASE (base)) == ADDR_EXPR
300e4b17023SJohn Marino 	   && TREE_CODE (TREE_OPERAND (TMR_BASE (base), 0)) == VAR_DECL
301e4b17023SJohn Marino 	   && ! TREE_STATIC (TREE_OPERAND (TMR_BASE (base), 0))
302e4b17023SJohn Marino 	   && cfun->gimple_df->decls_to_pointers != NULL)
303e4b17023SJohn Marino     {
304e4b17023SJohn Marino       void *namep;
305e4b17023SJohn Marino       namep = pointer_map_contains (cfun->gimple_df->decls_to_pointers,
306e4b17023SJohn Marino 				    TREE_OPERAND (TMR_BASE (base), 0));
307e4b17023SJohn Marino       if (namep)
308e4b17023SJohn Marino 	ref->base = build_simple_mem_ref (*(tree *)namep);
309e4b17023SJohn Marino     }
310e4b17023SJohn Marino 
311e4b17023SJohn Marino   ref->ref_alias_set = MEM_ALIAS_SET (mem);
312e4b17023SJohn Marino 
313e4b17023SJohn Marino   /* If MEM_OFFSET or MEM_SIZE are unknown we have to punt.
314e4b17023SJohn Marino      Keep points-to related information though.  */
315e4b17023SJohn Marino   if (!MEM_OFFSET_KNOWN_P (mem)
316e4b17023SJohn Marino       || !MEM_SIZE_KNOWN_P (mem))
317e4b17023SJohn Marino     {
318e4b17023SJohn Marino       ref->ref = NULL_TREE;
319e4b17023SJohn Marino       ref->offset = 0;
320e4b17023SJohn Marino       ref->size = -1;
321e4b17023SJohn Marino       ref->max_size = -1;
322e4b17023SJohn Marino       return true;
323e4b17023SJohn Marino     }
324e4b17023SJohn Marino 
325e4b17023SJohn Marino   /* If the base decl is a parameter we can have negative MEM_OFFSET in
326e4b17023SJohn Marino      case of promoted subregs on bigendian targets.  Trust the MEM_EXPR
327e4b17023SJohn Marino      here.  */
328e4b17023SJohn Marino   if (MEM_OFFSET (mem) < 0
329e4b17023SJohn Marino       && (MEM_SIZE (mem) + MEM_OFFSET (mem)) * BITS_PER_UNIT == ref->size)
330e4b17023SJohn Marino     return true;
331e4b17023SJohn Marino 
332e4b17023SJohn Marino   ref->offset += MEM_OFFSET (mem) * BITS_PER_UNIT;
333e4b17023SJohn Marino   ref->size = MEM_SIZE (mem) * BITS_PER_UNIT;
334e4b17023SJohn Marino 
335e4b17023SJohn Marino   /* The MEM may extend into adjacent fields, so adjust max_size if
336e4b17023SJohn Marino      necessary.  */
337e4b17023SJohn Marino   if (ref->max_size != -1
338e4b17023SJohn Marino       && ref->size > ref->max_size)
339e4b17023SJohn Marino     ref->max_size = ref->size;
340e4b17023SJohn Marino 
341e4b17023SJohn Marino   /* If MEM_OFFSET and MEM_SIZE get us outside of the base object of
342e4b17023SJohn Marino      the MEM_EXPR punt.  This happens for STRICT_ALIGNMENT targets a lot.  */
343e4b17023SJohn Marino   if (MEM_EXPR (mem) != get_spill_slot_decl (false)
344e4b17023SJohn Marino       && (ref->offset < 0
345e4b17023SJohn Marino 	  || (DECL_P (ref->base)
346e4b17023SJohn Marino 	      && (!host_integerp (DECL_SIZE (ref->base), 1)
347e4b17023SJohn Marino 		  || (TREE_INT_CST_LOW (DECL_SIZE ((ref->base)))
348e4b17023SJohn Marino 		      < (unsigned HOST_WIDE_INT)(ref->offset + ref->size))))))
349e4b17023SJohn Marino     return false;
350e4b17023SJohn Marino 
351e4b17023SJohn Marino   return true;
352e4b17023SJohn Marino }
353e4b17023SJohn Marino 
354e4b17023SJohn Marino /* Query the alias-oracle on whether the two memory rtx X and MEM may
355e4b17023SJohn Marino    alias.  If TBAA_P is set also apply TBAA.  Returns true if the
356e4b17023SJohn Marino    two rtxen may alias, false otherwise.  */
357e4b17023SJohn Marino 
358e4b17023SJohn Marino static bool
rtx_refs_may_alias_p(const_rtx x,const_rtx mem,bool tbaa_p)359e4b17023SJohn Marino rtx_refs_may_alias_p (const_rtx x, const_rtx mem, bool tbaa_p)
360e4b17023SJohn Marino {
361e4b17023SJohn Marino   ao_ref ref1, ref2;
362e4b17023SJohn Marino 
363e4b17023SJohn Marino   if (!ao_ref_from_mem (&ref1, x)
364e4b17023SJohn Marino       || !ao_ref_from_mem (&ref2, mem))
365e4b17023SJohn Marino     return true;
366e4b17023SJohn Marino 
367e4b17023SJohn Marino   return refs_may_alias_p_1 (&ref1, &ref2,
368e4b17023SJohn Marino 			     tbaa_p
369e4b17023SJohn Marino 			     && MEM_ALIAS_SET (x) != 0
370e4b17023SJohn Marino 			     && MEM_ALIAS_SET (mem) != 0);
371e4b17023SJohn Marino }
372e4b17023SJohn Marino 
373e4b17023SJohn Marino /* Returns a pointer to the alias set entry for ALIAS_SET, if there is
374e4b17023SJohn Marino    such an entry, or NULL otherwise.  */
375e4b17023SJohn Marino 
376e4b17023SJohn Marino static inline alias_set_entry
get_alias_set_entry(alias_set_type alias_set)377e4b17023SJohn Marino get_alias_set_entry (alias_set_type alias_set)
378e4b17023SJohn Marino {
379e4b17023SJohn Marino   return VEC_index (alias_set_entry, alias_sets, alias_set);
380e4b17023SJohn Marino }
381e4b17023SJohn Marino 
382e4b17023SJohn Marino /* Returns nonzero if the alias sets for MEM1 and MEM2 are such that
383e4b17023SJohn Marino    the two MEMs cannot alias each other.  */
384e4b17023SJohn Marino 
385e4b17023SJohn Marino static inline int
mems_in_disjoint_alias_sets_p(const_rtx mem1,const_rtx mem2)386e4b17023SJohn Marino mems_in_disjoint_alias_sets_p (const_rtx mem1, const_rtx mem2)
387e4b17023SJohn Marino {
388e4b17023SJohn Marino /* Perform a basic sanity check.  Namely, that there are no alias sets
389e4b17023SJohn Marino    if we're not using strict aliasing.  This helps to catch bugs
390e4b17023SJohn Marino    whereby someone uses PUT_CODE, but doesn't clear MEM_ALIAS_SET, or
391e4b17023SJohn Marino    where a MEM is allocated in some way other than by the use of
392e4b17023SJohn Marino    gen_rtx_MEM, and the MEM_ALIAS_SET is not cleared.  If we begin to
393e4b17023SJohn Marino    use alias sets to indicate that spilled registers cannot alias each
394e4b17023SJohn Marino    other, we might need to remove this check.  */
395e4b17023SJohn Marino   gcc_assert (flag_strict_aliasing
396e4b17023SJohn Marino 	      || (!MEM_ALIAS_SET (mem1) && !MEM_ALIAS_SET (mem2)));
397e4b17023SJohn Marino 
398e4b17023SJohn Marino   return ! alias_sets_conflict_p (MEM_ALIAS_SET (mem1), MEM_ALIAS_SET (mem2));
399e4b17023SJohn Marino }
400e4b17023SJohn Marino 
401e4b17023SJohn Marino /* Insert the NODE into the splay tree given by DATA.  Used by
402e4b17023SJohn Marino    record_alias_subset via splay_tree_foreach.  */
403e4b17023SJohn Marino 
404e4b17023SJohn Marino static int
insert_subset_children(splay_tree_node node,void * data)405e4b17023SJohn Marino insert_subset_children (splay_tree_node node, void *data)
406e4b17023SJohn Marino {
407e4b17023SJohn Marino   splay_tree_insert ((splay_tree) data, node->key, node->value);
408e4b17023SJohn Marino 
409e4b17023SJohn Marino   return 0;
410e4b17023SJohn Marino }
411e4b17023SJohn Marino 
412e4b17023SJohn Marino /* Return true if the first alias set is a subset of the second.  */
413e4b17023SJohn Marino 
414e4b17023SJohn Marino bool
alias_set_subset_of(alias_set_type set1,alias_set_type set2)415e4b17023SJohn Marino alias_set_subset_of (alias_set_type set1, alias_set_type set2)
416e4b17023SJohn Marino {
417e4b17023SJohn Marino   alias_set_entry ase;
418e4b17023SJohn Marino 
419e4b17023SJohn Marino   /* Everything is a subset of the "aliases everything" set.  */
420e4b17023SJohn Marino   if (set2 == 0)
421e4b17023SJohn Marino     return true;
422e4b17023SJohn Marino 
423e4b17023SJohn Marino   /* Otherwise, check if set1 is a subset of set2.  */
424e4b17023SJohn Marino   ase = get_alias_set_entry (set2);
425e4b17023SJohn Marino   if (ase != 0
426e4b17023SJohn Marino       && (ase->has_zero_child
427e4b17023SJohn Marino 	  || splay_tree_lookup (ase->children,
428e4b17023SJohn Marino 			        (splay_tree_key) set1)))
429e4b17023SJohn Marino     return true;
430e4b17023SJohn Marino   return false;
431e4b17023SJohn Marino }
432e4b17023SJohn Marino 
433e4b17023SJohn Marino /* Return 1 if the two specified alias sets may conflict.  */
434e4b17023SJohn Marino 
435e4b17023SJohn Marino int
alias_sets_conflict_p(alias_set_type set1,alias_set_type set2)436e4b17023SJohn Marino alias_sets_conflict_p (alias_set_type set1, alias_set_type set2)
437e4b17023SJohn Marino {
438e4b17023SJohn Marino   alias_set_entry ase;
439e4b17023SJohn Marino 
440e4b17023SJohn Marino   /* The easy case.  */
441e4b17023SJohn Marino   if (alias_sets_must_conflict_p (set1, set2))
442e4b17023SJohn Marino     return 1;
443e4b17023SJohn Marino 
444e4b17023SJohn Marino   /* See if the first alias set is a subset of the second.  */
445e4b17023SJohn Marino   ase = get_alias_set_entry (set1);
446e4b17023SJohn Marino   if (ase != 0
447e4b17023SJohn Marino       && (ase->has_zero_child
448e4b17023SJohn Marino 	  || splay_tree_lookup (ase->children,
449e4b17023SJohn Marino 				(splay_tree_key) set2)))
450e4b17023SJohn Marino     return 1;
451e4b17023SJohn Marino 
452e4b17023SJohn Marino   /* Now do the same, but with the alias sets reversed.  */
453e4b17023SJohn Marino   ase = get_alias_set_entry (set2);
454e4b17023SJohn Marino   if (ase != 0
455e4b17023SJohn Marino       && (ase->has_zero_child
456e4b17023SJohn Marino 	  || splay_tree_lookup (ase->children,
457e4b17023SJohn Marino 				(splay_tree_key) set1)))
458e4b17023SJohn Marino     return 1;
459e4b17023SJohn Marino 
460e4b17023SJohn Marino   /* The two alias sets are distinct and neither one is the
461e4b17023SJohn Marino      child of the other.  Therefore, they cannot conflict.  */
462e4b17023SJohn Marino   return 0;
463e4b17023SJohn Marino }
464e4b17023SJohn Marino 
465e4b17023SJohn Marino /* Return 1 if the two specified alias sets will always conflict.  */
466e4b17023SJohn Marino 
467e4b17023SJohn Marino int
alias_sets_must_conflict_p(alias_set_type set1,alias_set_type set2)468e4b17023SJohn Marino alias_sets_must_conflict_p (alias_set_type set1, alias_set_type set2)
469e4b17023SJohn Marino {
470e4b17023SJohn Marino   if (set1 == 0 || set2 == 0 || set1 == set2)
471e4b17023SJohn Marino     return 1;
472e4b17023SJohn Marino 
473e4b17023SJohn Marino   return 0;
474e4b17023SJohn Marino }
475e4b17023SJohn Marino 
476e4b17023SJohn Marino /* Return 1 if any MEM object of type T1 will always conflict (using the
477e4b17023SJohn Marino    dependency routines in this file) with any MEM object of type T2.
478e4b17023SJohn Marino    This is used when allocating temporary storage.  If T1 and/or T2 are
479e4b17023SJohn Marino    NULL_TREE, it means we know nothing about the storage.  */
480e4b17023SJohn Marino 
481e4b17023SJohn Marino int
objects_must_conflict_p(tree t1,tree t2)482e4b17023SJohn Marino objects_must_conflict_p (tree t1, tree t2)
483e4b17023SJohn Marino {
484e4b17023SJohn Marino   alias_set_type set1, set2;
485e4b17023SJohn Marino 
486e4b17023SJohn Marino   /* If neither has a type specified, we don't know if they'll conflict
487e4b17023SJohn Marino      because we may be using them to store objects of various types, for
488e4b17023SJohn Marino      example the argument and local variables areas of inlined functions.  */
489e4b17023SJohn Marino   if (t1 == 0 && t2 == 0)
490e4b17023SJohn Marino     return 0;
491e4b17023SJohn Marino 
492e4b17023SJohn Marino   /* If they are the same type, they must conflict.  */
493e4b17023SJohn Marino   if (t1 == t2
494e4b17023SJohn Marino       /* Likewise if both are volatile.  */
495e4b17023SJohn Marino       || (t1 != 0 && TYPE_VOLATILE (t1) && t2 != 0 && TYPE_VOLATILE (t2)))
496e4b17023SJohn Marino     return 1;
497e4b17023SJohn Marino 
498e4b17023SJohn Marino   set1 = t1 ? get_alias_set (t1) : 0;
499e4b17023SJohn Marino   set2 = t2 ? get_alias_set (t2) : 0;
500e4b17023SJohn Marino 
501e4b17023SJohn Marino   /* We can't use alias_sets_conflict_p because we must make sure
502e4b17023SJohn Marino      that every subtype of t1 will conflict with every subtype of
503e4b17023SJohn Marino      t2 for which a pair of subobjects of these respective subtypes
504e4b17023SJohn Marino      overlaps on the stack.  */
505e4b17023SJohn Marino   return alias_sets_must_conflict_p (set1, set2);
506e4b17023SJohn Marino }
507e4b17023SJohn Marino 
508e4b17023SJohn Marino /* Return true if all nested component references handled by
509e4b17023SJohn Marino    get_inner_reference in T are such that we should use the alias set
510e4b17023SJohn Marino    provided by the object at the heart of T.
511e4b17023SJohn Marino 
512e4b17023SJohn Marino    This is true for non-addressable components (which don't have their
513e4b17023SJohn Marino    own alias set), as well as components of objects in alias set zero.
514e4b17023SJohn Marino    This later point is a special case wherein we wish to override the
515e4b17023SJohn Marino    alias set used by the component, but we don't have per-FIELD_DECL
516e4b17023SJohn Marino    assignable alias sets.  */
517e4b17023SJohn Marino 
518e4b17023SJohn Marino bool
component_uses_parent_alias_set(const_tree t)519e4b17023SJohn Marino component_uses_parent_alias_set (const_tree t)
520e4b17023SJohn Marino {
521e4b17023SJohn Marino   while (1)
522e4b17023SJohn Marino     {
523e4b17023SJohn Marino       /* If we're at the end, it vacuously uses its own alias set.  */
524e4b17023SJohn Marino       if (!handled_component_p (t))
525e4b17023SJohn Marino 	return false;
526e4b17023SJohn Marino 
527e4b17023SJohn Marino       switch (TREE_CODE (t))
528e4b17023SJohn Marino 	{
529e4b17023SJohn Marino 	case COMPONENT_REF:
530e4b17023SJohn Marino 	  if (DECL_NONADDRESSABLE_P (TREE_OPERAND (t, 1)))
531e4b17023SJohn Marino 	    return true;
532e4b17023SJohn Marino 	  break;
533e4b17023SJohn Marino 
534e4b17023SJohn Marino 	case ARRAY_REF:
535e4b17023SJohn Marino 	case ARRAY_RANGE_REF:
536e4b17023SJohn Marino 	  if (TYPE_NONALIASED_COMPONENT (TREE_TYPE (TREE_OPERAND (t, 0))))
537e4b17023SJohn Marino 	    return true;
538e4b17023SJohn Marino 	  break;
539e4b17023SJohn Marino 
540e4b17023SJohn Marino 	case REALPART_EXPR:
541e4b17023SJohn Marino 	case IMAGPART_EXPR:
542e4b17023SJohn Marino 	  break;
543e4b17023SJohn Marino 
544e4b17023SJohn Marino 	default:
545e4b17023SJohn Marino 	  /* Bitfields and casts are never addressable.  */
546e4b17023SJohn Marino 	  return true;
547e4b17023SJohn Marino 	}
548e4b17023SJohn Marino 
549e4b17023SJohn Marino       t = TREE_OPERAND (t, 0);
550e4b17023SJohn Marino       if (get_alias_set (TREE_TYPE (t)) == 0)
551e4b17023SJohn Marino 	return true;
552e4b17023SJohn Marino     }
553e4b17023SJohn Marino }
554e4b17023SJohn Marino 
555e4b17023SJohn Marino /* Return the alias set for the memory pointed to by T, which may be
556e4b17023SJohn Marino    either a type or an expression.  Return -1 if there is nothing
557e4b17023SJohn Marino    special about dereferencing T.  */
558e4b17023SJohn Marino 
559e4b17023SJohn Marino static alias_set_type
get_deref_alias_set_1(tree t)560e4b17023SJohn Marino get_deref_alias_set_1 (tree t)
561e4b17023SJohn Marino {
562e4b17023SJohn Marino   /* If we're not doing any alias analysis, just assume everything
563e4b17023SJohn Marino      aliases everything else.  */
564e4b17023SJohn Marino   if (!flag_strict_aliasing)
565e4b17023SJohn Marino     return 0;
566e4b17023SJohn Marino 
567e4b17023SJohn Marino   /* All we care about is the type.  */
568e4b17023SJohn Marino   if (! TYPE_P (t))
569e4b17023SJohn Marino     t = TREE_TYPE (t);
570e4b17023SJohn Marino 
571e4b17023SJohn Marino   /* If we have an INDIRECT_REF via a void pointer, we don't
572e4b17023SJohn Marino      know anything about what that might alias.  Likewise if the
573e4b17023SJohn Marino      pointer is marked that way.  */
574e4b17023SJohn Marino   if (TREE_CODE (TREE_TYPE (t)) == VOID_TYPE
575e4b17023SJohn Marino       || TYPE_REF_CAN_ALIAS_ALL (t))
576e4b17023SJohn Marino     return 0;
577e4b17023SJohn Marino 
578e4b17023SJohn Marino   return -1;
579e4b17023SJohn Marino }
580e4b17023SJohn Marino 
581e4b17023SJohn Marino /* Return the alias set for the memory pointed to by T, which may be
582e4b17023SJohn Marino    either a type or an expression.  */
583e4b17023SJohn Marino 
584e4b17023SJohn Marino alias_set_type
get_deref_alias_set(tree t)585e4b17023SJohn Marino get_deref_alias_set (tree t)
586e4b17023SJohn Marino {
587e4b17023SJohn Marino   alias_set_type set = get_deref_alias_set_1 (t);
588e4b17023SJohn Marino 
589e4b17023SJohn Marino   /* Fall back to the alias-set of the pointed-to type.  */
590e4b17023SJohn Marino   if (set == -1)
591e4b17023SJohn Marino     {
592e4b17023SJohn Marino       if (! TYPE_P (t))
593e4b17023SJohn Marino 	t = TREE_TYPE (t);
594e4b17023SJohn Marino       set = get_alias_set (TREE_TYPE (t));
595e4b17023SJohn Marino     }
596e4b17023SJohn Marino 
597e4b17023SJohn Marino   return set;
598e4b17023SJohn Marino }
599e4b17023SJohn Marino 
600e4b17023SJohn Marino /* Return the alias set for T, which may be either a type or an
601e4b17023SJohn Marino    expression.  Call language-specific routine for help, if needed.  */
602e4b17023SJohn Marino 
603e4b17023SJohn Marino alias_set_type
get_alias_set(tree t)604e4b17023SJohn Marino get_alias_set (tree t)
605e4b17023SJohn Marino {
606e4b17023SJohn Marino   alias_set_type set;
607e4b17023SJohn Marino 
608e4b17023SJohn Marino   /* If we're not doing any alias analysis, just assume everything
609e4b17023SJohn Marino      aliases everything else.  Also return 0 if this or its type is
610e4b17023SJohn Marino      an error.  */
611e4b17023SJohn Marino   if (! flag_strict_aliasing || t == error_mark_node
612e4b17023SJohn Marino       || (! TYPE_P (t)
613e4b17023SJohn Marino 	  && (TREE_TYPE (t) == 0 || TREE_TYPE (t) == error_mark_node)))
614e4b17023SJohn Marino     return 0;
615e4b17023SJohn Marino 
616e4b17023SJohn Marino   /* We can be passed either an expression or a type.  This and the
617e4b17023SJohn Marino      language-specific routine may make mutually-recursive calls to each other
618e4b17023SJohn Marino      to figure out what to do.  At each juncture, we see if this is a tree
619e4b17023SJohn Marino      that the language may need to handle specially.  First handle things that
620e4b17023SJohn Marino      aren't types.  */
621e4b17023SJohn Marino   if (! TYPE_P (t))
622e4b17023SJohn Marino     {
623e4b17023SJohn Marino       tree inner;
624e4b17023SJohn Marino 
625e4b17023SJohn Marino       /* Give the language a chance to do something with this tree
626e4b17023SJohn Marino 	 before we look at it.  */
627e4b17023SJohn Marino       STRIP_NOPS (t);
628e4b17023SJohn Marino       set = lang_hooks.get_alias_set (t);
629e4b17023SJohn Marino       if (set != -1)
630e4b17023SJohn Marino 	return set;
631e4b17023SJohn Marino 
632e4b17023SJohn Marino       /* Get the base object of the reference.  */
633e4b17023SJohn Marino       inner = t;
634e4b17023SJohn Marino       while (handled_component_p (inner))
635e4b17023SJohn Marino 	{
636e4b17023SJohn Marino 	  /* If there is a VIEW_CONVERT_EXPR in the chain we cannot use
637e4b17023SJohn Marino 	     the type of any component references that wrap it to
638e4b17023SJohn Marino 	     determine the alias-set.  */
639e4b17023SJohn Marino 	  if (TREE_CODE (inner) == VIEW_CONVERT_EXPR)
640e4b17023SJohn Marino 	    t = TREE_OPERAND (inner, 0);
641e4b17023SJohn Marino 	  inner = TREE_OPERAND (inner, 0);
642e4b17023SJohn Marino 	}
643e4b17023SJohn Marino 
644e4b17023SJohn Marino       /* Handle pointer dereferences here, they can override the
645e4b17023SJohn Marino 	 alias-set.  */
646e4b17023SJohn Marino       if (INDIRECT_REF_P (inner))
647e4b17023SJohn Marino 	{
648e4b17023SJohn Marino 	  set = get_deref_alias_set_1 (TREE_OPERAND (inner, 0));
649e4b17023SJohn Marino 	  if (set != -1)
650e4b17023SJohn Marino 	    return set;
651e4b17023SJohn Marino 	}
652e4b17023SJohn Marino       else if (TREE_CODE (inner) == TARGET_MEM_REF)
653e4b17023SJohn Marino 	return get_deref_alias_set (TMR_OFFSET (inner));
654e4b17023SJohn Marino       else if (TREE_CODE (inner) == MEM_REF)
655e4b17023SJohn Marino 	{
656e4b17023SJohn Marino 	  set = get_deref_alias_set_1 (TREE_OPERAND (inner, 1));
657e4b17023SJohn Marino 	  if (set != -1)
658e4b17023SJohn Marino 	    return set;
659e4b17023SJohn Marino 	}
660e4b17023SJohn Marino 
661e4b17023SJohn Marino       /* If the innermost reference is a MEM_REF that has a
662e4b17023SJohn Marino 	 conversion embedded treat it like a VIEW_CONVERT_EXPR above,
663e4b17023SJohn Marino 	 using the memory access type for determining the alias-set.  */
664e4b17023SJohn Marino      if (TREE_CODE (inner) == MEM_REF
665e4b17023SJohn Marino 	 && TYPE_MAIN_VARIANT (TREE_TYPE (inner))
666e4b17023SJohn Marino 	    != TYPE_MAIN_VARIANT
667e4b17023SJohn Marino 	       (TREE_TYPE (TREE_TYPE (TREE_OPERAND (inner, 1)))))
668e4b17023SJohn Marino        return get_deref_alias_set (TREE_OPERAND (inner, 1));
669e4b17023SJohn Marino 
670e4b17023SJohn Marino       /* Otherwise, pick up the outermost object that we could have a pointer
671e4b17023SJohn Marino 	 to, processing conversions as above.  */
672e4b17023SJohn Marino       while (component_uses_parent_alias_set (t))
673e4b17023SJohn Marino 	{
674e4b17023SJohn Marino 	  t = TREE_OPERAND (t, 0);
675e4b17023SJohn Marino 	  STRIP_NOPS (t);
676e4b17023SJohn Marino 	}
677e4b17023SJohn Marino 
678e4b17023SJohn Marino       /* If we've already determined the alias set for a decl, just return
679e4b17023SJohn Marino 	 it.  This is necessary for C++ anonymous unions, whose component
680e4b17023SJohn Marino 	 variables don't look like union members (boo!).  */
681e4b17023SJohn Marino       if (TREE_CODE (t) == VAR_DECL
682e4b17023SJohn Marino 	  && DECL_RTL_SET_P (t) && MEM_P (DECL_RTL (t)))
683e4b17023SJohn Marino 	return MEM_ALIAS_SET (DECL_RTL (t));
684e4b17023SJohn Marino 
685e4b17023SJohn Marino       /* Now all we care about is the type.  */
686e4b17023SJohn Marino       t = TREE_TYPE (t);
687e4b17023SJohn Marino     }
688e4b17023SJohn Marino 
689e4b17023SJohn Marino   /* Variant qualifiers don't affect the alias set, so get the main
690e4b17023SJohn Marino      variant.  */
691e4b17023SJohn Marino   t = TYPE_MAIN_VARIANT (t);
692e4b17023SJohn Marino 
693e4b17023SJohn Marino   /* Always use the canonical type as well.  If this is a type that
694e4b17023SJohn Marino      requires structural comparisons to identify compatible types
695e4b17023SJohn Marino      use alias set zero.  */
696e4b17023SJohn Marino   if (TYPE_STRUCTURAL_EQUALITY_P (t))
697e4b17023SJohn Marino     {
698e4b17023SJohn Marino       /* Allow the language to specify another alias set for this
699e4b17023SJohn Marino 	 type.  */
700e4b17023SJohn Marino       set = lang_hooks.get_alias_set (t);
701e4b17023SJohn Marino       if (set != -1)
702e4b17023SJohn Marino 	return set;
703e4b17023SJohn Marino       return 0;
704e4b17023SJohn Marino     }
705e4b17023SJohn Marino 
706e4b17023SJohn Marino   t = TYPE_CANONICAL (t);
707e4b17023SJohn Marino 
708e4b17023SJohn Marino   /* The canonical type should not require structural equality checks.  */
709e4b17023SJohn Marino   gcc_checking_assert (!TYPE_STRUCTURAL_EQUALITY_P (t));
710e4b17023SJohn Marino 
711e4b17023SJohn Marino   /* If this is a type with a known alias set, return it.  */
712e4b17023SJohn Marino   if (TYPE_ALIAS_SET_KNOWN_P (t))
713e4b17023SJohn Marino     return TYPE_ALIAS_SET (t);
714e4b17023SJohn Marino 
715e4b17023SJohn Marino   /* We don't want to set TYPE_ALIAS_SET for incomplete types.  */
716e4b17023SJohn Marino   if (!COMPLETE_TYPE_P (t))
717e4b17023SJohn Marino     {
718e4b17023SJohn Marino       /* For arrays with unknown size the conservative answer is the
719e4b17023SJohn Marino 	 alias set of the element type.  */
720e4b17023SJohn Marino       if (TREE_CODE (t) == ARRAY_TYPE)
721e4b17023SJohn Marino 	return get_alias_set (TREE_TYPE (t));
722e4b17023SJohn Marino 
723e4b17023SJohn Marino       /* But return zero as a conservative answer for incomplete types.  */
724e4b17023SJohn Marino       return 0;
725e4b17023SJohn Marino     }
726e4b17023SJohn Marino 
727e4b17023SJohn Marino   /* See if the language has special handling for this type.  */
728e4b17023SJohn Marino   set = lang_hooks.get_alias_set (t);
729e4b17023SJohn Marino   if (set != -1)
730e4b17023SJohn Marino     return set;
731e4b17023SJohn Marino 
732e4b17023SJohn Marino   /* There are no objects of FUNCTION_TYPE, so there's no point in
733e4b17023SJohn Marino      using up an alias set for them.  (There are, of course, pointers
734e4b17023SJohn Marino      and references to functions, but that's different.)  */
735e4b17023SJohn Marino   else if (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE)
736e4b17023SJohn Marino     set = 0;
737e4b17023SJohn Marino 
738e4b17023SJohn Marino   /* Unless the language specifies otherwise, let vector types alias
739e4b17023SJohn Marino      their components.  This avoids some nasty type punning issues in
740e4b17023SJohn Marino      normal usage.  And indeed lets vectors be treated more like an
741e4b17023SJohn Marino      array slice.  */
742e4b17023SJohn Marino   else if (TREE_CODE (t) == VECTOR_TYPE)
743e4b17023SJohn Marino     set = get_alias_set (TREE_TYPE (t));
744e4b17023SJohn Marino 
745e4b17023SJohn Marino   /* Unless the language specifies otherwise, treat array types the
746e4b17023SJohn Marino      same as their components.  This avoids the asymmetry we get
747e4b17023SJohn Marino      through recording the components.  Consider accessing a
748e4b17023SJohn Marino      character(kind=1) through a reference to a character(kind=1)[1:1].
749e4b17023SJohn Marino      Or consider if we want to assign integer(kind=4)[0:D.1387] and
750e4b17023SJohn Marino      integer(kind=4)[4] the same alias set or not.
751e4b17023SJohn Marino      Just be pragmatic here and make sure the array and its element
752e4b17023SJohn Marino      type get the same alias set assigned.  */
753e4b17023SJohn Marino   else if (TREE_CODE (t) == ARRAY_TYPE && !TYPE_NONALIASED_COMPONENT (t))
754e4b17023SJohn Marino     set = get_alias_set (TREE_TYPE (t));
755e4b17023SJohn Marino 
756e4b17023SJohn Marino   /* From the former common C and C++ langhook implementation:
757e4b17023SJohn Marino 
758e4b17023SJohn Marino      Unfortunately, there is no canonical form of a pointer type.
759e4b17023SJohn Marino      In particular, if we have `typedef int I', then `int *', and
760e4b17023SJohn Marino      `I *' are different types.  So, we have to pick a canonical
761e4b17023SJohn Marino      representative.  We do this below.
762e4b17023SJohn Marino 
763e4b17023SJohn Marino      Technically, this approach is actually more conservative that
764e4b17023SJohn Marino      it needs to be.  In particular, `const int *' and `int *'
765e4b17023SJohn Marino      should be in different alias sets, according to the C and C++
766e4b17023SJohn Marino      standard, since their types are not the same, and so,
767e4b17023SJohn Marino      technically, an `int **' and `const int **' cannot point at
768e4b17023SJohn Marino      the same thing.
769e4b17023SJohn Marino 
770e4b17023SJohn Marino      But, the standard is wrong.  In particular, this code is
771e4b17023SJohn Marino      legal C++:
772e4b17023SJohn Marino 
773e4b17023SJohn Marino      int *ip;
774e4b17023SJohn Marino      int **ipp = &ip;
775e4b17023SJohn Marino      const int* const* cipp = ipp;
776e4b17023SJohn Marino      And, it doesn't make sense for that to be legal unless you
777e4b17023SJohn Marino      can dereference IPP and CIPP.  So, we ignore cv-qualifiers on
778e4b17023SJohn Marino      the pointed-to types.  This issue has been reported to the
779e4b17023SJohn Marino      C++ committee.
780e4b17023SJohn Marino 
781e4b17023SJohn Marino      In addition to the above canonicalization issue, with LTO
782e4b17023SJohn Marino      we should also canonicalize `T (*)[]' to `T *' avoiding
783e4b17023SJohn Marino      alias issues with pointer-to element types and pointer-to
784e4b17023SJohn Marino      array types.
785e4b17023SJohn Marino 
786e4b17023SJohn Marino      Likewise we need to deal with the situation of incomplete
787e4b17023SJohn Marino      pointed-to types and make `*(struct X **)&a' and
788e4b17023SJohn Marino      `*(struct X {} **)&a' alias.  Otherwise we will have to
789e4b17023SJohn Marino      guarantee that all pointer-to incomplete type variants
790e4b17023SJohn Marino      will be replaced by pointer-to complete type variants if
791e4b17023SJohn Marino      they are available.
792e4b17023SJohn Marino 
793e4b17023SJohn Marino      With LTO the convenient situation of using `void *' to
794e4b17023SJohn Marino      access and store any pointer type will also become
795e4b17023SJohn Marino      more apparent (and `void *' is just another pointer-to
796e4b17023SJohn Marino      incomplete type).  Assigning alias-set zero to `void *'
797e4b17023SJohn Marino      and all pointer-to incomplete types is a not appealing
798e4b17023SJohn Marino      solution.  Assigning an effective alias-set zero only
799e4b17023SJohn Marino      affecting pointers might be - by recording proper subset
800e4b17023SJohn Marino      relationships of all pointer alias-sets.
801e4b17023SJohn Marino 
802e4b17023SJohn Marino      Pointer-to function types are another grey area which
803e4b17023SJohn Marino      needs caution.  Globbing them all into one alias-set
804e4b17023SJohn Marino      or the above effective zero set would work.
805e4b17023SJohn Marino 
806e4b17023SJohn Marino      For now just assign the same alias-set to all pointers.
807e4b17023SJohn Marino      That's simple and avoids all the above problems.  */
808e4b17023SJohn Marino   else if (POINTER_TYPE_P (t)
809e4b17023SJohn Marino 	   && t != ptr_type_node)
810e4b17023SJohn Marino     set = get_alias_set (ptr_type_node);
811e4b17023SJohn Marino 
812e4b17023SJohn Marino   /* Otherwise make a new alias set for this type.  */
813e4b17023SJohn Marino   else
814e4b17023SJohn Marino     {
815e4b17023SJohn Marino       /* Each canonical type gets its own alias set, so canonical types
816e4b17023SJohn Marino 	 shouldn't form a tree.  It doesn't really matter for types
817e4b17023SJohn Marino 	 we handle specially above, so only check it where it possibly
818e4b17023SJohn Marino 	 would result in a bogus alias set.  */
819e4b17023SJohn Marino       gcc_checking_assert (TYPE_CANONICAL (t) == t);
820e4b17023SJohn Marino 
821e4b17023SJohn Marino       set = new_alias_set ();
822e4b17023SJohn Marino     }
823e4b17023SJohn Marino 
824e4b17023SJohn Marino   TYPE_ALIAS_SET (t) = set;
825e4b17023SJohn Marino 
826e4b17023SJohn Marino   /* If this is an aggregate type or a complex type, we must record any
827e4b17023SJohn Marino      component aliasing information.  */
828e4b17023SJohn Marino   if (AGGREGATE_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
829e4b17023SJohn Marino     record_component_aliases (t);
830e4b17023SJohn Marino 
831e4b17023SJohn Marino   return set;
832e4b17023SJohn Marino }
833e4b17023SJohn Marino 
834e4b17023SJohn Marino /* Return a brand-new alias set.  */
835e4b17023SJohn Marino 
836e4b17023SJohn Marino alias_set_type
new_alias_set(void)837e4b17023SJohn Marino new_alias_set (void)
838e4b17023SJohn Marino {
839e4b17023SJohn Marino   if (flag_strict_aliasing)
840e4b17023SJohn Marino     {
841e4b17023SJohn Marino       if (alias_sets == 0)
842e4b17023SJohn Marino 	VEC_safe_push (alias_set_entry, gc, alias_sets, 0);
843e4b17023SJohn Marino       VEC_safe_push (alias_set_entry, gc, alias_sets, 0);
844e4b17023SJohn Marino       return VEC_length (alias_set_entry, alias_sets) - 1;
845e4b17023SJohn Marino     }
846e4b17023SJohn Marino   else
847e4b17023SJohn Marino     return 0;
848e4b17023SJohn Marino }
849e4b17023SJohn Marino 
850e4b17023SJohn Marino /* Indicate that things in SUBSET can alias things in SUPERSET, but that
851e4b17023SJohn Marino    not everything that aliases SUPERSET also aliases SUBSET.  For example,
852e4b17023SJohn Marino    in C, a store to an `int' can alias a load of a structure containing an
853e4b17023SJohn Marino    `int', and vice versa.  But it can't alias a load of a 'double' member
854e4b17023SJohn Marino    of the same structure.  Here, the structure would be the SUPERSET and
855e4b17023SJohn Marino    `int' the SUBSET.  This relationship is also described in the comment at
856e4b17023SJohn Marino    the beginning of this file.
857e4b17023SJohn Marino 
858e4b17023SJohn Marino    This function should be called only once per SUPERSET/SUBSET pair.
859e4b17023SJohn Marino 
860e4b17023SJohn Marino    It is illegal for SUPERSET to be zero; everything is implicitly a
861e4b17023SJohn Marino    subset of alias set zero.  */
862e4b17023SJohn Marino 
863e4b17023SJohn Marino void
record_alias_subset(alias_set_type superset,alias_set_type subset)864e4b17023SJohn Marino record_alias_subset (alias_set_type superset, alias_set_type subset)
865e4b17023SJohn Marino {
866e4b17023SJohn Marino   alias_set_entry superset_entry;
867e4b17023SJohn Marino   alias_set_entry subset_entry;
868e4b17023SJohn Marino 
869e4b17023SJohn Marino   /* It is possible in complex type situations for both sets to be the same,
870e4b17023SJohn Marino      in which case we can ignore this operation.  */
871e4b17023SJohn Marino   if (superset == subset)
872e4b17023SJohn Marino     return;
873e4b17023SJohn Marino 
874e4b17023SJohn Marino   gcc_assert (superset);
875e4b17023SJohn Marino 
876e4b17023SJohn Marino   superset_entry = get_alias_set_entry (superset);
877e4b17023SJohn Marino   if (superset_entry == 0)
878e4b17023SJohn Marino     {
879e4b17023SJohn Marino       /* Create an entry for the SUPERSET, so that we have a place to
880e4b17023SJohn Marino 	 attach the SUBSET.  */
881e4b17023SJohn Marino       superset_entry = ggc_alloc_cleared_alias_set_entry_d ();
882e4b17023SJohn Marino       superset_entry->alias_set = superset;
883e4b17023SJohn Marino       superset_entry->children
884e4b17023SJohn Marino 	= splay_tree_new_ggc (splay_tree_compare_ints,
885e4b17023SJohn Marino 			      ggc_alloc_splay_tree_scalar_scalar_splay_tree_s,
886e4b17023SJohn Marino 			      ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s);
887e4b17023SJohn Marino       superset_entry->has_zero_child = 0;
888e4b17023SJohn Marino       VEC_replace (alias_set_entry, alias_sets, superset, superset_entry);
889e4b17023SJohn Marino     }
890e4b17023SJohn Marino 
891e4b17023SJohn Marino   if (subset == 0)
892e4b17023SJohn Marino     superset_entry->has_zero_child = 1;
893e4b17023SJohn Marino   else
894e4b17023SJohn Marino     {
895e4b17023SJohn Marino       subset_entry = get_alias_set_entry (subset);
896e4b17023SJohn Marino       /* If there is an entry for the subset, enter all of its children
897e4b17023SJohn Marino 	 (if they are not already present) as children of the SUPERSET.  */
898e4b17023SJohn Marino       if (subset_entry)
899e4b17023SJohn Marino 	{
900e4b17023SJohn Marino 	  if (subset_entry->has_zero_child)
901e4b17023SJohn Marino 	    superset_entry->has_zero_child = 1;
902e4b17023SJohn Marino 
903e4b17023SJohn Marino 	  splay_tree_foreach (subset_entry->children, insert_subset_children,
904e4b17023SJohn Marino 			      superset_entry->children);
905e4b17023SJohn Marino 	}
906e4b17023SJohn Marino 
907e4b17023SJohn Marino       /* Enter the SUBSET itself as a child of the SUPERSET.  */
908e4b17023SJohn Marino       splay_tree_insert (superset_entry->children,
909e4b17023SJohn Marino 			 (splay_tree_key) subset, 0);
910e4b17023SJohn Marino     }
911e4b17023SJohn Marino }
912e4b17023SJohn Marino 
913e4b17023SJohn Marino /* Record that component types of TYPE, if any, are part of that type for
914e4b17023SJohn Marino    aliasing purposes.  For record types, we only record component types
915e4b17023SJohn Marino    for fields that are not marked non-addressable.  For array types, we
916e4b17023SJohn Marino    only record the component type if it is not marked non-aliased.  */
917e4b17023SJohn Marino 
918e4b17023SJohn Marino void
record_component_aliases(tree type)919e4b17023SJohn Marino record_component_aliases (tree type)
920e4b17023SJohn Marino {
921e4b17023SJohn Marino   alias_set_type superset = get_alias_set (type);
922e4b17023SJohn Marino   tree field;
923e4b17023SJohn Marino 
924e4b17023SJohn Marino   if (superset == 0)
925e4b17023SJohn Marino     return;
926e4b17023SJohn Marino 
927e4b17023SJohn Marino   switch (TREE_CODE (type))
928e4b17023SJohn Marino     {
929e4b17023SJohn Marino     case RECORD_TYPE:
930e4b17023SJohn Marino     case UNION_TYPE:
931e4b17023SJohn Marino     case QUAL_UNION_TYPE:
932e4b17023SJohn Marino       /* Recursively record aliases for the base classes, if there are any.  */
933e4b17023SJohn Marino       if (TYPE_BINFO (type))
934e4b17023SJohn Marino 	{
935e4b17023SJohn Marino 	  int i;
936e4b17023SJohn Marino 	  tree binfo, base_binfo;
937e4b17023SJohn Marino 
938e4b17023SJohn Marino 	  for (binfo = TYPE_BINFO (type), i = 0;
939e4b17023SJohn Marino 	       BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
940e4b17023SJohn Marino 	    record_alias_subset (superset,
941e4b17023SJohn Marino 				 get_alias_set (BINFO_TYPE (base_binfo)));
942e4b17023SJohn Marino 	}
943e4b17023SJohn Marino       for (field = TYPE_FIELDS (type); field != 0; field = DECL_CHAIN (field))
944e4b17023SJohn Marino 	if (TREE_CODE (field) == FIELD_DECL && !DECL_NONADDRESSABLE_P (field))
945e4b17023SJohn Marino 	  record_alias_subset (superset, get_alias_set (TREE_TYPE (field)));
946e4b17023SJohn Marino       break;
947e4b17023SJohn Marino 
948e4b17023SJohn Marino     case COMPLEX_TYPE:
949e4b17023SJohn Marino       record_alias_subset (superset, get_alias_set (TREE_TYPE (type)));
950e4b17023SJohn Marino       break;
951e4b17023SJohn Marino 
952e4b17023SJohn Marino     /* VECTOR_TYPE and ARRAY_TYPE share the alias set with their
953e4b17023SJohn Marino        element type.  */
954e4b17023SJohn Marino 
955e4b17023SJohn Marino     default:
956e4b17023SJohn Marino       break;
957e4b17023SJohn Marino     }
958e4b17023SJohn Marino }
959e4b17023SJohn Marino 
960e4b17023SJohn Marino /* Allocate an alias set for use in storing and reading from the varargs
961e4b17023SJohn Marino    spill area.  */
962e4b17023SJohn Marino 
963e4b17023SJohn Marino static GTY(()) alias_set_type varargs_set = -1;
964e4b17023SJohn Marino 
965e4b17023SJohn Marino alias_set_type
get_varargs_alias_set(void)966e4b17023SJohn Marino get_varargs_alias_set (void)
967e4b17023SJohn Marino {
968e4b17023SJohn Marino #if 1
969e4b17023SJohn Marino   /* We now lower VA_ARG_EXPR, and there's currently no way to attach the
970e4b17023SJohn Marino      varargs alias set to an INDIRECT_REF (FIXME!), so we can't
971e4b17023SJohn Marino      consistently use the varargs alias set for loads from the varargs
972e4b17023SJohn Marino      area.  So don't use it anywhere.  */
973e4b17023SJohn Marino   return 0;
974e4b17023SJohn Marino #else
975e4b17023SJohn Marino   if (varargs_set == -1)
976e4b17023SJohn Marino     varargs_set = new_alias_set ();
977e4b17023SJohn Marino 
978e4b17023SJohn Marino   return varargs_set;
979e4b17023SJohn Marino #endif
980e4b17023SJohn Marino }
981e4b17023SJohn Marino 
982e4b17023SJohn Marino /* Likewise, but used for the fixed portions of the frame, e.g., register
983e4b17023SJohn Marino    save areas.  */
984e4b17023SJohn Marino 
985e4b17023SJohn Marino static GTY(()) alias_set_type frame_set = -1;
986e4b17023SJohn Marino 
987e4b17023SJohn Marino alias_set_type
get_frame_alias_set(void)988e4b17023SJohn Marino get_frame_alias_set (void)
989e4b17023SJohn Marino {
990e4b17023SJohn Marino   if (frame_set == -1)
991e4b17023SJohn Marino     frame_set = new_alias_set ();
992e4b17023SJohn Marino 
993e4b17023SJohn Marino   return frame_set;
994e4b17023SJohn Marino }
995e4b17023SJohn Marino 
996e4b17023SJohn Marino /* Inside SRC, the source of a SET, find a base address.  */
997e4b17023SJohn Marino 
998e4b17023SJohn Marino static rtx
find_base_value(rtx src)999e4b17023SJohn Marino find_base_value (rtx src)
1000e4b17023SJohn Marino {
1001e4b17023SJohn Marino   unsigned int regno;
1002e4b17023SJohn Marino 
1003e4b17023SJohn Marino #if defined (FIND_BASE_TERM)
1004e4b17023SJohn Marino   /* Try machine-dependent ways to find the base term.  */
1005e4b17023SJohn Marino   src = FIND_BASE_TERM (src);
1006e4b17023SJohn Marino #endif
1007e4b17023SJohn Marino 
1008e4b17023SJohn Marino   switch (GET_CODE (src))
1009e4b17023SJohn Marino     {
1010e4b17023SJohn Marino     case SYMBOL_REF:
1011e4b17023SJohn Marino     case LABEL_REF:
1012e4b17023SJohn Marino       return src;
1013e4b17023SJohn Marino 
1014e4b17023SJohn Marino     case REG:
1015e4b17023SJohn Marino       regno = REGNO (src);
1016e4b17023SJohn Marino       /* At the start of a function, argument registers have known base
1017e4b17023SJohn Marino 	 values which may be lost later.  Returning an ADDRESS
1018e4b17023SJohn Marino 	 expression here allows optimization based on argument values
1019e4b17023SJohn Marino 	 even when the argument registers are used for other purposes.  */
1020e4b17023SJohn Marino       if (regno < FIRST_PSEUDO_REGISTER && copying_arguments)
1021e4b17023SJohn Marino 	return new_reg_base_value[regno];
1022e4b17023SJohn Marino 
1023e4b17023SJohn Marino       /* If a pseudo has a known base value, return it.  Do not do this
1024e4b17023SJohn Marino 	 for non-fixed hard regs since it can result in a circular
1025e4b17023SJohn Marino 	 dependency chain for registers which have values at function entry.
1026e4b17023SJohn Marino 
1027e4b17023SJohn Marino 	 The test above is not sufficient because the scheduler may move
1028e4b17023SJohn Marino 	 a copy out of an arg reg past the NOTE_INSN_FUNCTION_BEGIN.  */
1029e4b17023SJohn Marino       if ((regno >= FIRST_PSEUDO_REGISTER || fixed_regs[regno])
1030e4b17023SJohn Marino 	  && regno < VEC_length (rtx, reg_base_value))
1031e4b17023SJohn Marino 	{
1032e4b17023SJohn Marino 	  /* If we're inside init_alias_analysis, use new_reg_base_value
1033e4b17023SJohn Marino 	     to reduce the number of relaxation iterations.  */
1034e4b17023SJohn Marino 	  if (new_reg_base_value && new_reg_base_value[regno]
1035e4b17023SJohn Marino 	      && DF_REG_DEF_COUNT (regno) == 1)
1036e4b17023SJohn Marino 	    return new_reg_base_value[regno];
1037e4b17023SJohn Marino 
1038e4b17023SJohn Marino 	  if (VEC_index (rtx, reg_base_value, regno))
1039e4b17023SJohn Marino 	    return VEC_index (rtx, reg_base_value, regno);
1040e4b17023SJohn Marino 	}
1041e4b17023SJohn Marino 
1042e4b17023SJohn Marino       return 0;
1043e4b17023SJohn Marino 
1044e4b17023SJohn Marino     case MEM:
1045e4b17023SJohn Marino       /* Check for an argument passed in memory.  Only record in the
1046e4b17023SJohn Marino 	 copying-arguments block; it is too hard to track changes
1047e4b17023SJohn Marino 	 otherwise.  */
1048e4b17023SJohn Marino       if (copying_arguments
1049e4b17023SJohn Marino 	  && (XEXP (src, 0) == arg_pointer_rtx
1050e4b17023SJohn Marino 	      || (GET_CODE (XEXP (src, 0)) == PLUS
1051e4b17023SJohn Marino 		  && XEXP (XEXP (src, 0), 0) == arg_pointer_rtx)))
1052e4b17023SJohn Marino 	return gen_rtx_ADDRESS (VOIDmode, src);
1053e4b17023SJohn Marino       return 0;
1054e4b17023SJohn Marino 
1055e4b17023SJohn Marino     case CONST:
1056e4b17023SJohn Marino       src = XEXP (src, 0);
1057e4b17023SJohn Marino       if (GET_CODE (src) != PLUS && GET_CODE (src) != MINUS)
1058e4b17023SJohn Marino 	break;
1059e4b17023SJohn Marino 
1060e4b17023SJohn Marino       /* ... fall through ...  */
1061e4b17023SJohn Marino 
1062e4b17023SJohn Marino     case PLUS:
1063e4b17023SJohn Marino     case MINUS:
1064e4b17023SJohn Marino       {
1065e4b17023SJohn Marino 	rtx temp, src_0 = XEXP (src, 0), src_1 = XEXP (src, 1);
1066e4b17023SJohn Marino 
1067e4b17023SJohn Marino 	/* If either operand is a REG that is a known pointer, then it
1068e4b17023SJohn Marino 	   is the base.  */
1069e4b17023SJohn Marino 	if (REG_P (src_0) && REG_POINTER (src_0))
1070e4b17023SJohn Marino 	  return find_base_value (src_0);
1071e4b17023SJohn Marino 	if (REG_P (src_1) && REG_POINTER (src_1))
1072e4b17023SJohn Marino 	  return find_base_value (src_1);
1073e4b17023SJohn Marino 
1074e4b17023SJohn Marino 	/* If either operand is a REG, then see if we already have
1075e4b17023SJohn Marino 	   a known value for it.  */
1076e4b17023SJohn Marino 	if (REG_P (src_0))
1077e4b17023SJohn Marino 	  {
1078e4b17023SJohn Marino 	    temp = find_base_value (src_0);
1079e4b17023SJohn Marino 	    if (temp != 0)
1080e4b17023SJohn Marino 	      src_0 = temp;
1081e4b17023SJohn Marino 	  }
1082e4b17023SJohn Marino 
1083e4b17023SJohn Marino 	if (REG_P (src_1))
1084e4b17023SJohn Marino 	  {
1085e4b17023SJohn Marino 	    temp = find_base_value (src_1);
1086e4b17023SJohn Marino 	    if (temp!= 0)
1087e4b17023SJohn Marino 	      src_1 = temp;
1088e4b17023SJohn Marino 	  }
1089e4b17023SJohn Marino 
1090e4b17023SJohn Marino 	/* If either base is named object or a special address
1091e4b17023SJohn Marino 	   (like an argument or stack reference), then use it for the
1092e4b17023SJohn Marino 	   base term.  */
1093e4b17023SJohn Marino 	if (src_0 != 0
1094e4b17023SJohn Marino 	    && (GET_CODE (src_0) == SYMBOL_REF
1095e4b17023SJohn Marino 		|| GET_CODE (src_0) == LABEL_REF
1096e4b17023SJohn Marino 		|| (GET_CODE (src_0) == ADDRESS
1097e4b17023SJohn Marino 		    && GET_MODE (src_0) != VOIDmode)))
1098e4b17023SJohn Marino 	  return src_0;
1099e4b17023SJohn Marino 
1100e4b17023SJohn Marino 	if (src_1 != 0
1101e4b17023SJohn Marino 	    && (GET_CODE (src_1) == SYMBOL_REF
1102e4b17023SJohn Marino 		|| GET_CODE (src_1) == LABEL_REF
1103e4b17023SJohn Marino 		|| (GET_CODE (src_1) == ADDRESS
1104e4b17023SJohn Marino 		    && GET_MODE (src_1) != VOIDmode)))
1105e4b17023SJohn Marino 	  return src_1;
1106e4b17023SJohn Marino 
1107e4b17023SJohn Marino 	/* Guess which operand is the base address:
1108e4b17023SJohn Marino 	   If either operand is a symbol, then it is the base.  If
1109e4b17023SJohn Marino 	   either operand is a CONST_INT, then the other is the base.  */
1110e4b17023SJohn Marino 	if (CONST_INT_P (src_1) || CONSTANT_P (src_0))
1111e4b17023SJohn Marino 	  return find_base_value (src_0);
1112e4b17023SJohn Marino 	else if (CONST_INT_P (src_0) || CONSTANT_P (src_1))
1113e4b17023SJohn Marino 	  return find_base_value (src_1);
1114e4b17023SJohn Marino 
1115e4b17023SJohn Marino 	return 0;
1116e4b17023SJohn Marino       }
1117e4b17023SJohn Marino 
1118e4b17023SJohn Marino     case LO_SUM:
1119e4b17023SJohn Marino       /* The standard form is (lo_sum reg sym) so look only at the
1120e4b17023SJohn Marino 	 second operand.  */
1121e4b17023SJohn Marino       return find_base_value (XEXP (src, 1));
1122e4b17023SJohn Marino 
1123e4b17023SJohn Marino     case AND:
1124e4b17023SJohn Marino       /* If the second operand is constant set the base
1125e4b17023SJohn Marino 	 address to the first operand.  */
1126e4b17023SJohn Marino       if (CONST_INT_P (XEXP (src, 1)) && INTVAL (XEXP (src, 1)) != 0)
1127e4b17023SJohn Marino 	return find_base_value (XEXP (src, 0));
1128e4b17023SJohn Marino       return 0;
1129e4b17023SJohn Marino 
1130e4b17023SJohn Marino     case TRUNCATE:
1131e4b17023SJohn Marino       /* As we do not know which address space the pointer is refering to, we can
1132e4b17023SJohn Marino 	 handle this only if the target does not support different pointer or
1133e4b17023SJohn Marino 	 address modes depending on the address space.  */
1134e4b17023SJohn Marino       if (!target_default_pointer_address_modes_p ())
1135e4b17023SJohn Marino 	break;
1136e4b17023SJohn Marino       if (GET_MODE_SIZE (GET_MODE (src)) < GET_MODE_SIZE (Pmode))
1137e4b17023SJohn Marino 	break;
1138e4b17023SJohn Marino       /* Fall through.  */
1139e4b17023SJohn Marino     case HIGH:
1140e4b17023SJohn Marino     case PRE_INC:
1141e4b17023SJohn Marino     case PRE_DEC:
1142e4b17023SJohn Marino     case POST_INC:
1143e4b17023SJohn Marino     case POST_DEC:
1144e4b17023SJohn Marino     case PRE_MODIFY:
1145e4b17023SJohn Marino     case POST_MODIFY:
1146e4b17023SJohn Marino       return find_base_value (XEXP (src, 0));
1147e4b17023SJohn Marino 
1148e4b17023SJohn Marino     case ZERO_EXTEND:
1149e4b17023SJohn Marino     case SIGN_EXTEND:	/* used for NT/Alpha pointers */
1150e4b17023SJohn Marino       /* As we do not know which address space the pointer is refering to, we can
1151e4b17023SJohn Marino 	 handle this only if the target does not support different pointer or
1152e4b17023SJohn Marino 	 address modes depending on the address space.  */
1153e4b17023SJohn Marino       if (!target_default_pointer_address_modes_p ())
1154e4b17023SJohn Marino 	break;
1155e4b17023SJohn Marino 
1156e4b17023SJohn Marino       {
1157e4b17023SJohn Marino 	rtx temp = find_base_value (XEXP (src, 0));
1158e4b17023SJohn Marino 
1159e4b17023SJohn Marino 	if (temp != 0 && CONSTANT_P (temp))
1160e4b17023SJohn Marino 	  temp = convert_memory_address (Pmode, temp);
1161e4b17023SJohn Marino 
1162e4b17023SJohn Marino 	return temp;
1163e4b17023SJohn Marino       }
1164e4b17023SJohn Marino 
1165e4b17023SJohn Marino     default:
1166e4b17023SJohn Marino       break;
1167e4b17023SJohn Marino     }
1168e4b17023SJohn Marino 
1169e4b17023SJohn Marino   return 0;
1170e4b17023SJohn Marino }
1171e4b17023SJohn Marino 
1172e4b17023SJohn Marino /* Called from init_alias_analysis indirectly through note_stores.  */
1173e4b17023SJohn Marino 
1174e4b17023SJohn Marino /* While scanning insns to find base values, reg_seen[N] is nonzero if
1175e4b17023SJohn Marino    register N has been set in this function.  */
1176e4b17023SJohn Marino static char *reg_seen;
1177e4b17023SJohn Marino 
1178e4b17023SJohn Marino /* Addresses which are known not to alias anything else are identified
1179e4b17023SJohn Marino    by a unique integer.  */
1180e4b17023SJohn Marino static int unique_id;
1181e4b17023SJohn Marino 
1182e4b17023SJohn Marino static void
record_set(rtx dest,const_rtx set,void * data ATTRIBUTE_UNUSED)1183e4b17023SJohn Marino record_set (rtx dest, const_rtx set, void *data ATTRIBUTE_UNUSED)
1184e4b17023SJohn Marino {
1185e4b17023SJohn Marino   unsigned regno;
1186e4b17023SJohn Marino   rtx src;
1187e4b17023SJohn Marino   int n;
1188e4b17023SJohn Marino 
1189e4b17023SJohn Marino   if (!REG_P (dest))
1190e4b17023SJohn Marino     return;
1191e4b17023SJohn Marino 
1192e4b17023SJohn Marino   regno = REGNO (dest);
1193e4b17023SJohn Marino 
1194e4b17023SJohn Marino   gcc_checking_assert (regno < VEC_length (rtx, reg_base_value));
1195e4b17023SJohn Marino 
1196e4b17023SJohn Marino   /* If this spans multiple hard registers, then we must indicate that every
1197e4b17023SJohn Marino      register has an unusable value.  */
1198e4b17023SJohn Marino   if (regno < FIRST_PSEUDO_REGISTER)
1199e4b17023SJohn Marino     n = hard_regno_nregs[regno][GET_MODE (dest)];
1200e4b17023SJohn Marino   else
1201e4b17023SJohn Marino     n = 1;
1202e4b17023SJohn Marino   if (n != 1)
1203e4b17023SJohn Marino     {
1204e4b17023SJohn Marino       while (--n >= 0)
1205e4b17023SJohn Marino 	{
1206e4b17023SJohn Marino 	  reg_seen[regno + n] = 1;
1207e4b17023SJohn Marino 	  new_reg_base_value[regno + n] = 0;
1208e4b17023SJohn Marino 	}
1209e4b17023SJohn Marino       return;
1210e4b17023SJohn Marino     }
1211e4b17023SJohn Marino 
1212e4b17023SJohn Marino   if (set)
1213e4b17023SJohn Marino     {
1214e4b17023SJohn Marino       /* A CLOBBER wipes out any old value but does not prevent a previously
1215e4b17023SJohn Marino 	 unset register from acquiring a base address (i.e. reg_seen is not
1216e4b17023SJohn Marino 	 set).  */
1217e4b17023SJohn Marino       if (GET_CODE (set) == CLOBBER)
1218e4b17023SJohn Marino 	{
1219e4b17023SJohn Marino 	  new_reg_base_value[regno] = 0;
1220e4b17023SJohn Marino 	  return;
1221e4b17023SJohn Marino 	}
1222e4b17023SJohn Marino       src = SET_SRC (set);
1223e4b17023SJohn Marino     }
1224e4b17023SJohn Marino   else
1225e4b17023SJohn Marino     {
1226e4b17023SJohn Marino       if (reg_seen[regno])
1227e4b17023SJohn Marino 	{
1228e4b17023SJohn Marino 	  new_reg_base_value[regno] = 0;
1229e4b17023SJohn Marino 	  return;
1230e4b17023SJohn Marino 	}
1231e4b17023SJohn Marino       reg_seen[regno] = 1;
1232e4b17023SJohn Marino       new_reg_base_value[regno] = gen_rtx_ADDRESS (Pmode,
1233e4b17023SJohn Marino 						   GEN_INT (unique_id++));
1234e4b17023SJohn Marino       return;
1235e4b17023SJohn Marino     }
1236e4b17023SJohn Marino 
1237e4b17023SJohn Marino   /* If this is not the first set of REGNO, see whether the new value
1238e4b17023SJohn Marino      is related to the old one.  There are two cases of interest:
1239e4b17023SJohn Marino 
1240e4b17023SJohn Marino 	(1) The register might be assigned an entirely new value
1241e4b17023SJohn Marino 	    that has the same base term as the original set.
1242e4b17023SJohn Marino 
1243e4b17023SJohn Marino 	(2) The set might be a simple self-modification that
1244e4b17023SJohn Marino 	    cannot change REGNO's base value.
1245e4b17023SJohn Marino 
1246e4b17023SJohn Marino      If neither case holds, reject the original base value as invalid.
1247e4b17023SJohn Marino      Note that the following situation is not detected:
1248e4b17023SJohn Marino 
1249e4b17023SJohn Marino 	 extern int x, y;  int *p = &x; p += (&y-&x);
1250e4b17023SJohn Marino 
1251e4b17023SJohn Marino      ANSI C does not allow computing the difference of addresses
1252e4b17023SJohn Marino      of distinct top level objects.  */
1253e4b17023SJohn Marino   if (new_reg_base_value[regno] != 0
1254e4b17023SJohn Marino       && find_base_value (src) != new_reg_base_value[regno])
1255e4b17023SJohn Marino     switch (GET_CODE (src))
1256e4b17023SJohn Marino       {
1257e4b17023SJohn Marino       case LO_SUM:
1258e4b17023SJohn Marino       case MINUS:
1259e4b17023SJohn Marino 	if (XEXP (src, 0) != dest && XEXP (src, 1) != dest)
1260e4b17023SJohn Marino 	  new_reg_base_value[regno] = 0;
1261e4b17023SJohn Marino 	break;
1262e4b17023SJohn Marino       case PLUS:
1263e4b17023SJohn Marino 	/* If the value we add in the PLUS is also a valid base value,
1264e4b17023SJohn Marino 	   this might be the actual base value, and the original value
1265e4b17023SJohn Marino 	   an index.  */
1266e4b17023SJohn Marino 	{
1267e4b17023SJohn Marino 	  rtx other = NULL_RTX;
1268e4b17023SJohn Marino 
1269e4b17023SJohn Marino 	  if (XEXP (src, 0) == dest)
1270e4b17023SJohn Marino 	    other = XEXP (src, 1);
1271e4b17023SJohn Marino 	  else if (XEXP (src, 1) == dest)
1272e4b17023SJohn Marino 	    other = XEXP (src, 0);
1273e4b17023SJohn Marino 
1274e4b17023SJohn Marino 	  if (! other || find_base_value (other))
1275e4b17023SJohn Marino 	    new_reg_base_value[regno] = 0;
1276e4b17023SJohn Marino 	  break;
1277e4b17023SJohn Marino 	}
1278e4b17023SJohn Marino       case AND:
1279e4b17023SJohn Marino 	if (XEXP (src, 0) != dest || !CONST_INT_P (XEXP (src, 1)))
1280e4b17023SJohn Marino 	  new_reg_base_value[regno] = 0;
1281e4b17023SJohn Marino 	break;
1282e4b17023SJohn Marino       default:
1283e4b17023SJohn Marino 	new_reg_base_value[regno] = 0;
1284e4b17023SJohn Marino 	break;
1285e4b17023SJohn Marino       }
1286e4b17023SJohn Marino   /* If this is the first set of a register, record the value.  */
1287e4b17023SJohn Marino   else if ((regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
1288e4b17023SJohn Marino 	   && ! reg_seen[regno] && new_reg_base_value[regno] == 0)
1289e4b17023SJohn Marino     new_reg_base_value[regno] = find_base_value (src);
1290e4b17023SJohn Marino 
1291e4b17023SJohn Marino   reg_seen[regno] = 1;
1292e4b17023SJohn Marino }
1293e4b17023SJohn Marino 
1294e4b17023SJohn Marino /* Return REG_BASE_VALUE for REGNO.  Selective scheduler uses this to avoid
1295e4b17023SJohn Marino    using hard registers with non-null REG_BASE_VALUE for renaming.  */
1296e4b17023SJohn Marino rtx
get_reg_base_value(unsigned int regno)1297e4b17023SJohn Marino get_reg_base_value (unsigned int regno)
1298e4b17023SJohn Marino {
1299e4b17023SJohn Marino   return VEC_index (rtx, reg_base_value, regno);
1300e4b17023SJohn Marino }
1301e4b17023SJohn Marino 
1302e4b17023SJohn Marino /* If a value is known for REGNO, return it.  */
1303e4b17023SJohn Marino 
1304e4b17023SJohn Marino rtx
get_reg_known_value(unsigned int regno)1305e4b17023SJohn Marino get_reg_known_value (unsigned int regno)
1306e4b17023SJohn Marino {
1307e4b17023SJohn Marino   if (regno >= FIRST_PSEUDO_REGISTER)
1308e4b17023SJohn Marino     {
1309e4b17023SJohn Marino       regno -= FIRST_PSEUDO_REGISTER;
1310e4b17023SJohn Marino       if (regno < reg_known_value_size)
1311e4b17023SJohn Marino 	return reg_known_value[regno];
1312e4b17023SJohn Marino     }
1313e4b17023SJohn Marino   return NULL;
1314e4b17023SJohn Marino }
1315e4b17023SJohn Marino 
1316e4b17023SJohn Marino /* Set it.  */
1317e4b17023SJohn Marino 
1318e4b17023SJohn Marino static void
set_reg_known_value(unsigned int regno,rtx val)1319e4b17023SJohn Marino set_reg_known_value (unsigned int regno, rtx val)
1320e4b17023SJohn Marino {
1321e4b17023SJohn Marino   if (regno >= FIRST_PSEUDO_REGISTER)
1322e4b17023SJohn Marino     {
1323e4b17023SJohn Marino       regno -= FIRST_PSEUDO_REGISTER;
1324e4b17023SJohn Marino       if (regno < reg_known_value_size)
1325e4b17023SJohn Marino 	reg_known_value[regno] = val;
1326e4b17023SJohn Marino     }
1327e4b17023SJohn Marino }
1328e4b17023SJohn Marino 
1329e4b17023SJohn Marino /* Similarly for reg_known_equiv_p.  */
1330e4b17023SJohn Marino 
1331e4b17023SJohn Marino bool
get_reg_known_equiv_p(unsigned int regno)1332e4b17023SJohn Marino get_reg_known_equiv_p (unsigned int regno)
1333e4b17023SJohn Marino {
1334e4b17023SJohn Marino   if (regno >= FIRST_PSEUDO_REGISTER)
1335e4b17023SJohn Marino     {
1336e4b17023SJohn Marino       regno -= FIRST_PSEUDO_REGISTER;
1337e4b17023SJohn Marino       if (regno < reg_known_value_size)
1338e4b17023SJohn Marino 	return reg_known_equiv_p[regno];
1339e4b17023SJohn Marino     }
1340e4b17023SJohn Marino   return false;
1341e4b17023SJohn Marino }
1342e4b17023SJohn Marino 
1343e4b17023SJohn Marino static void
set_reg_known_equiv_p(unsigned int regno,bool val)1344e4b17023SJohn Marino set_reg_known_equiv_p (unsigned int regno, bool val)
1345e4b17023SJohn Marino {
1346e4b17023SJohn Marino   if (regno >= FIRST_PSEUDO_REGISTER)
1347e4b17023SJohn Marino     {
1348e4b17023SJohn Marino       regno -= FIRST_PSEUDO_REGISTER;
1349e4b17023SJohn Marino       if (regno < reg_known_value_size)
1350e4b17023SJohn Marino 	reg_known_equiv_p[regno] = val;
1351e4b17023SJohn Marino     }
1352e4b17023SJohn Marino }
1353e4b17023SJohn Marino 
1354e4b17023SJohn Marino 
1355e4b17023SJohn Marino /* Returns a canonical version of X, from the point of view alias
1356e4b17023SJohn Marino    analysis.  (For example, if X is a MEM whose address is a register,
1357e4b17023SJohn Marino    and the register has a known value (say a SYMBOL_REF), then a MEM
1358e4b17023SJohn Marino    whose address is the SYMBOL_REF is returned.)  */
1359e4b17023SJohn Marino 
1360e4b17023SJohn Marino rtx
canon_rtx(rtx x)1361e4b17023SJohn Marino canon_rtx (rtx x)
1362e4b17023SJohn Marino {
1363e4b17023SJohn Marino   /* Recursively look for equivalences.  */
1364e4b17023SJohn Marino   if (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER)
1365e4b17023SJohn Marino     {
1366e4b17023SJohn Marino       rtx t = get_reg_known_value (REGNO (x));
1367e4b17023SJohn Marino       if (t == x)
1368e4b17023SJohn Marino 	return x;
1369e4b17023SJohn Marino       if (t)
1370e4b17023SJohn Marino 	return canon_rtx (t);
1371e4b17023SJohn Marino     }
1372e4b17023SJohn Marino 
1373e4b17023SJohn Marino   if (GET_CODE (x) == PLUS)
1374e4b17023SJohn Marino     {
1375e4b17023SJohn Marino       rtx x0 = canon_rtx (XEXP (x, 0));
1376e4b17023SJohn Marino       rtx x1 = canon_rtx (XEXP (x, 1));
1377e4b17023SJohn Marino 
1378e4b17023SJohn Marino       if (x0 != XEXP (x, 0) || x1 != XEXP (x, 1))
1379e4b17023SJohn Marino 	{
1380e4b17023SJohn Marino 	  if (CONST_INT_P (x0))
1381e4b17023SJohn Marino 	    return plus_constant (x1, INTVAL (x0));
1382e4b17023SJohn Marino 	  else if (CONST_INT_P (x1))
1383e4b17023SJohn Marino 	    return plus_constant (x0, INTVAL (x1));
1384e4b17023SJohn Marino 	  return gen_rtx_PLUS (GET_MODE (x), x0, x1);
1385e4b17023SJohn Marino 	}
1386e4b17023SJohn Marino     }
1387e4b17023SJohn Marino 
1388e4b17023SJohn Marino   /* This gives us much better alias analysis when called from
1389e4b17023SJohn Marino      the loop optimizer.   Note we want to leave the original
1390e4b17023SJohn Marino      MEM alone, but need to return the canonicalized MEM with
1391e4b17023SJohn Marino      all the flags with their original values.  */
1392e4b17023SJohn Marino   else if (MEM_P (x))
1393e4b17023SJohn Marino     x = replace_equiv_address_nv (x, canon_rtx (XEXP (x, 0)));
1394e4b17023SJohn Marino 
1395e4b17023SJohn Marino   return x;
1396e4b17023SJohn Marino }
1397e4b17023SJohn Marino 
1398e4b17023SJohn Marino /* Return 1 if X and Y are identical-looking rtx's.
1399e4b17023SJohn Marino    Expect that X and Y has been already canonicalized.
1400e4b17023SJohn Marino 
1401e4b17023SJohn Marino    We use the data in reg_known_value above to see if two registers with
1402e4b17023SJohn Marino    different numbers are, in fact, equivalent.  */
1403e4b17023SJohn Marino 
1404e4b17023SJohn Marino static int
rtx_equal_for_memref_p(const_rtx x,const_rtx y)1405e4b17023SJohn Marino rtx_equal_for_memref_p (const_rtx x, const_rtx y)
1406e4b17023SJohn Marino {
1407e4b17023SJohn Marino   int i;
1408e4b17023SJohn Marino   int j;
1409e4b17023SJohn Marino   enum rtx_code code;
1410e4b17023SJohn Marino   const char *fmt;
1411e4b17023SJohn Marino 
1412e4b17023SJohn Marino   if (x == 0 && y == 0)
1413e4b17023SJohn Marino     return 1;
1414e4b17023SJohn Marino   if (x == 0 || y == 0)
1415e4b17023SJohn Marino     return 0;
1416e4b17023SJohn Marino 
1417e4b17023SJohn Marino   if (x == y)
1418e4b17023SJohn Marino     return 1;
1419e4b17023SJohn Marino 
1420e4b17023SJohn Marino   code = GET_CODE (x);
1421e4b17023SJohn Marino   /* Rtx's of different codes cannot be equal.  */
1422e4b17023SJohn Marino   if (code != GET_CODE (y))
1423e4b17023SJohn Marino     return 0;
1424e4b17023SJohn Marino 
1425e4b17023SJohn Marino   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
1426e4b17023SJohn Marino      (REG:SI x) and (REG:HI x) are NOT equivalent.  */
1427e4b17023SJohn Marino 
1428e4b17023SJohn Marino   if (GET_MODE (x) != GET_MODE (y))
1429e4b17023SJohn Marino     return 0;
1430e4b17023SJohn Marino 
1431e4b17023SJohn Marino   /* Some RTL can be compared without a recursive examination.  */
1432e4b17023SJohn Marino   switch (code)
1433e4b17023SJohn Marino     {
1434e4b17023SJohn Marino     case REG:
1435e4b17023SJohn Marino       return REGNO (x) == REGNO (y);
1436e4b17023SJohn Marino 
1437e4b17023SJohn Marino     case LABEL_REF:
1438e4b17023SJohn Marino       return XEXP (x, 0) == XEXP (y, 0);
1439e4b17023SJohn Marino 
1440e4b17023SJohn Marino     case SYMBOL_REF:
1441e4b17023SJohn Marino       return XSTR (x, 0) == XSTR (y, 0);
1442e4b17023SJohn Marino 
1443e4b17023SJohn Marino     case VALUE:
1444e4b17023SJohn Marino     case CONST_INT:
1445e4b17023SJohn Marino     case CONST_DOUBLE:
1446e4b17023SJohn Marino     case CONST_FIXED:
1447e4b17023SJohn Marino       /* There's no need to compare the contents of CONST_DOUBLEs or
1448e4b17023SJohn Marino 	 CONST_INTs because pointer equality is a good enough
1449e4b17023SJohn Marino 	 comparison for these nodes.  */
1450e4b17023SJohn Marino       return 0;
1451e4b17023SJohn Marino 
1452e4b17023SJohn Marino     default:
1453e4b17023SJohn Marino       break;
1454e4b17023SJohn Marino     }
1455e4b17023SJohn Marino 
1456e4b17023SJohn Marino   /* canon_rtx knows how to handle plus.  No need to canonicalize.  */
1457e4b17023SJohn Marino   if (code == PLUS)
1458e4b17023SJohn Marino     return ((rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
1459e4b17023SJohn Marino 	     && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)))
1460e4b17023SJohn Marino 	    || (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 1))
1461e4b17023SJohn Marino 		&& rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 0))));
1462e4b17023SJohn Marino   /* For commutative operations, the RTX match if the operand match in any
1463e4b17023SJohn Marino      order.  Also handle the simple binary and unary cases without a loop.  */
1464e4b17023SJohn Marino   if (COMMUTATIVE_P (x))
1465e4b17023SJohn Marino     {
1466e4b17023SJohn Marino       rtx xop0 = canon_rtx (XEXP (x, 0));
1467e4b17023SJohn Marino       rtx yop0 = canon_rtx (XEXP (y, 0));
1468e4b17023SJohn Marino       rtx yop1 = canon_rtx (XEXP (y, 1));
1469e4b17023SJohn Marino 
1470e4b17023SJohn Marino       return ((rtx_equal_for_memref_p (xop0, yop0)
1471e4b17023SJohn Marino 	       && rtx_equal_for_memref_p (canon_rtx (XEXP (x, 1)), yop1))
1472e4b17023SJohn Marino 	      || (rtx_equal_for_memref_p (xop0, yop1)
1473e4b17023SJohn Marino 		  && rtx_equal_for_memref_p (canon_rtx (XEXP (x, 1)), yop0)));
1474e4b17023SJohn Marino     }
1475e4b17023SJohn Marino   else if (NON_COMMUTATIVE_P (x))
1476e4b17023SJohn Marino     {
1477e4b17023SJohn Marino       return (rtx_equal_for_memref_p (canon_rtx (XEXP (x, 0)),
1478e4b17023SJohn Marino 				      canon_rtx (XEXP (y, 0)))
1479e4b17023SJohn Marino 	      && rtx_equal_for_memref_p (canon_rtx (XEXP (x, 1)),
1480e4b17023SJohn Marino 					 canon_rtx (XEXP (y, 1))));
1481e4b17023SJohn Marino     }
1482e4b17023SJohn Marino   else if (UNARY_P (x))
1483e4b17023SJohn Marino     return rtx_equal_for_memref_p (canon_rtx (XEXP (x, 0)),
1484e4b17023SJohn Marino 				   canon_rtx (XEXP (y, 0)));
1485e4b17023SJohn Marino 
1486e4b17023SJohn Marino   /* Compare the elements.  If any pair of corresponding elements
1487e4b17023SJohn Marino      fail to match, return 0 for the whole things.
1488e4b17023SJohn Marino 
1489e4b17023SJohn Marino      Limit cases to types which actually appear in addresses.  */
1490e4b17023SJohn Marino 
1491e4b17023SJohn Marino   fmt = GET_RTX_FORMAT (code);
1492e4b17023SJohn Marino   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1493e4b17023SJohn Marino     {
1494e4b17023SJohn Marino       switch (fmt[i])
1495e4b17023SJohn Marino 	{
1496e4b17023SJohn Marino 	case 'i':
1497e4b17023SJohn Marino 	  if (XINT (x, i) != XINT (y, i))
1498e4b17023SJohn Marino 	    return 0;
1499e4b17023SJohn Marino 	  break;
1500e4b17023SJohn Marino 
1501e4b17023SJohn Marino 	case 'E':
1502e4b17023SJohn Marino 	  /* Two vectors must have the same length.  */
1503e4b17023SJohn Marino 	  if (XVECLEN (x, i) != XVECLEN (y, i))
1504e4b17023SJohn Marino 	    return 0;
1505e4b17023SJohn Marino 
1506e4b17023SJohn Marino 	  /* And the corresponding elements must match.  */
1507e4b17023SJohn Marino 	  for (j = 0; j < XVECLEN (x, i); j++)
1508e4b17023SJohn Marino 	    if (rtx_equal_for_memref_p (canon_rtx (XVECEXP (x, i, j)),
1509e4b17023SJohn Marino 					canon_rtx (XVECEXP (y, i, j))) == 0)
1510e4b17023SJohn Marino 	      return 0;
1511e4b17023SJohn Marino 	  break;
1512e4b17023SJohn Marino 
1513e4b17023SJohn Marino 	case 'e':
1514e4b17023SJohn Marino 	  if (rtx_equal_for_memref_p (canon_rtx (XEXP (x, i)),
1515e4b17023SJohn Marino 				      canon_rtx (XEXP (y, i))) == 0)
1516e4b17023SJohn Marino 	    return 0;
1517e4b17023SJohn Marino 	  break;
1518e4b17023SJohn Marino 
1519e4b17023SJohn Marino 	  /* This can happen for asm operands.  */
1520e4b17023SJohn Marino 	case 's':
1521e4b17023SJohn Marino 	  if (strcmp (XSTR (x, i), XSTR (y, i)))
1522e4b17023SJohn Marino 	    return 0;
1523e4b17023SJohn Marino 	  break;
1524e4b17023SJohn Marino 
1525e4b17023SJohn Marino 	/* This can happen for an asm which clobbers memory.  */
1526e4b17023SJohn Marino 	case '0':
1527e4b17023SJohn Marino 	  break;
1528e4b17023SJohn Marino 
1529e4b17023SJohn Marino 	  /* It is believed that rtx's at this level will never
1530e4b17023SJohn Marino 	     contain anything but integers and other rtx's,
1531e4b17023SJohn Marino 	     except for within LABEL_REFs and SYMBOL_REFs.  */
1532e4b17023SJohn Marino 	default:
1533e4b17023SJohn Marino 	  gcc_unreachable ();
1534e4b17023SJohn Marino 	}
1535e4b17023SJohn Marino     }
1536e4b17023SJohn Marino   return 1;
1537e4b17023SJohn Marino }
1538e4b17023SJohn Marino 
1539e4b17023SJohn Marino rtx
find_base_term(rtx x)1540e4b17023SJohn Marino find_base_term (rtx x)
1541e4b17023SJohn Marino {
1542e4b17023SJohn Marino   cselib_val *val;
1543e4b17023SJohn Marino   struct elt_loc_list *l, *f;
1544e4b17023SJohn Marino   rtx ret;
1545e4b17023SJohn Marino 
1546e4b17023SJohn Marino #if defined (FIND_BASE_TERM)
1547e4b17023SJohn Marino   /* Try machine-dependent ways to find the base term.  */
1548e4b17023SJohn Marino   x = FIND_BASE_TERM (x);
1549e4b17023SJohn Marino #endif
1550e4b17023SJohn Marino 
1551e4b17023SJohn Marino   switch (GET_CODE (x))
1552e4b17023SJohn Marino     {
1553e4b17023SJohn Marino     case REG:
1554e4b17023SJohn Marino       return REG_BASE_VALUE (x);
1555e4b17023SJohn Marino 
1556e4b17023SJohn Marino     case TRUNCATE:
1557e4b17023SJohn Marino       /* As we do not know which address space the pointer is refering to, we can
1558e4b17023SJohn Marino 	 handle this only if the target does not support different pointer or
1559e4b17023SJohn Marino 	 address modes depending on the address space.  */
1560e4b17023SJohn Marino       if (!target_default_pointer_address_modes_p ())
1561e4b17023SJohn Marino 	return 0;
1562e4b17023SJohn Marino       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (Pmode))
1563e4b17023SJohn Marino 	return 0;
1564e4b17023SJohn Marino       /* Fall through.  */
1565e4b17023SJohn Marino     case HIGH:
1566e4b17023SJohn Marino     case PRE_INC:
1567e4b17023SJohn Marino     case PRE_DEC:
1568e4b17023SJohn Marino     case POST_INC:
1569e4b17023SJohn Marino     case POST_DEC:
1570e4b17023SJohn Marino     case PRE_MODIFY:
1571e4b17023SJohn Marino     case POST_MODIFY:
1572e4b17023SJohn Marino       return find_base_term (XEXP (x, 0));
1573e4b17023SJohn Marino 
1574e4b17023SJohn Marino     case ZERO_EXTEND:
1575e4b17023SJohn Marino     case SIGN_EXTEND:	/* Used for Alpha/NT pointers */
1576e4b17023SJohn Marino       /* As we do not know which address space the pointer is refering to, we can
1577e4b17023SJohn Marino 	 handle this only if the target does not support different pointer or
1578e4b17023SJohn Marino 	 address modes depending on the address space.  */
1579e4b17023SJohn Marino       if (!target_default_pointer_address_modes_p ())
1580e4b17023SJohn Marino 	return 0;
1581e4b17023SJohn Marino 
1582e4b17023SJohn Marino       {
1583e4b17023SJohn Marino 	rtx temp = find_base_term (XEXP (x, 0));
1584e4b17023SJohn Marino 
1585e4b17023SJohn Marino 	if (temp != 0 && CONSTANT_P (temp))
1586e4b17023SJohn Marino 	  temp = convert_memory_address (Pmode, temp);
1587e4b17023SJohn Marino 
1588e4b17023SJohn Marino 	return temp;
1589e4b17023SJohn Marino       }
1590e4b17023SJohn Marino 
1591e4b17023SJohn Marino     case VALUE:
1592e4b17023SJohn Marino       val = CSELIB_VAL_PTR (x);
1593e4b17023SJohn Marino       ret = NULL_RTX;
1594e4b17023SJohn Marino 
1595e4b17023SJohn Marino       if (!val)
1596e4b17023SJohn Marino 	return ret;
1597e4b17023SJohn Marino 
1598e4b17023SJohn Marino       f = val->locs;
1599e4b17023SJohn Marino       /* Temporarily reset val->locs to avoid infinite recursion.  */
1600e4b17023SJohn Marino       val->locs = NULL;
1601e4b17023SJohn Marino 
1602e4b17023SJohn Marino       for (l = f; l; l = l->next)
1603e4b17023SJohn Marino 	if (GET_CODE (l->loc) == VALUE
1604e4b17023SJohn Marino 	    && CSELIB_VAL_PTR (l->loc)->locs
1605e4b17023SJohn Marino 	    && !CSELIB_VAL_PTR (l->loc)->locs->next
1606e4b17023SJohn Marino 	    && CSELIB_VAL_PTR (l->loc)->locs->loc == x)
1607e4b17023SJohn Marino 	  continue;
1608e4b17023SJohn Marino 	else if ((ret = find_base_term (l->loc)) != 0)
1609e4b17023SJohn Marino 	  break;
1610e4b17023SJohn Marino 
1611e4b17023SJohn Marino       val->locs = f;
1612e4b17023SJohn Marino       return ret;
1613e4b17023SJohn Marino 
1614e4b17023SJohn Marino     case LO_SUM:
1615e4b17023SJohn Marino       /* The standard form is (lo_sum reg sym) so look only at the
1616e4b17023SJohn Marino          second operand.  */
1617e4b17023SJohn Marino       return find_base_term (XEXP (x, 1));
1618e4b17023SJohn Marino 
1619e4b17023SJohn Marino     case CONST:
1620e4b17023SJohn Marino       x = XEXP (x, 0);
1621e4b17023SJohn Marino       if (GET_CODE (x) != PLUS && GET_CODE (x) != MINUS)
1622e4b17023SJohn Marino 	return 0;
1623e4b17023SJohn Marino       /* Fall through.  */
1624e4b17023SJohn Marino     case PLUS:
1625e4b17023SJohn Marino     case MINUS:
1626e4b17023SJohn Marino       {
1627e4b17023SJohn Marino 	rtx tmp1 = XEXP (x, 0);
1628e4b17023SJohn Marino 	rtx tmp2 = XEXP (x, 1);
1629e4b17023SJohn Marino 
1630e4b17023SJohn Marino 	/* This is a little bit tricky since we have to determine which of
1631e4b17023SJohn Marino 	   the two operands represents the real base address.  Otherwise this
1632e4b17023SJohn Marino 	   routine may return the index register instead of the base register.
1633e4b17023SJohn Marino 
1634e4b17023SJohn Marino 	   That may cause us to believe no aliasing was possible, when in
1635e4b17023SJohn Marino 	   fact aliasing is possible.
1636e4b17023SJohn Marino 
1637e4b17023SJohn Marino 	   We use a few simple tests to guess the base register.  Additional
1638e4b17023SJohn Marino 	   tests can certainly be added.  For example, if one of the operands
1639e4b17023SJohn Marino 	   is a shift or multiply, then it must be the index register and the
1640e4b17023SJohn Marino 	   other operand is the base register.  */
1641e4b17023SJohn Marino 
1642e4b17023SJohn Marino 	if (tmp1 == pic_offset_table_rtx && CONSTANT_P (tmp2))
1643e4b17023SJohn Marino 	  return find_base_term (tmp2);
1644e4b17023SJohn Marino 
1645e4b17023SJohn Marino 	/* If either operand is known to be a pointer, then use it
1646e4b17023SJohn Marino 	   to determine the base term.  */
1647e4b17023SJohn Marino 	if (REG_P (tmp1) && REG_POINTER (tmp1))
1648e4b17023SJohn Marino 	  {
1649e4b17023SJohn Marino 	    rtx base = find_base_term (tmp1);
1650e4b17023SJohn Marino 	    if (base)
1651e4b17023SJohn Marino 	      return base;
1652e4b17023SJohn Marino 	  }
1653e4b17023SJohn Marino 
1654e4b17023SJohn Marino 	if (REG_P (tmp2) && REG_POINTER (tmp2))
1655e4b17023SJohn Marino 	  {
1656e4b17023SJohn Marino 	    rtx base = find_base_term (tmp2);
1657e4b17023SJohn Marino 	    if (base)
1658e4b17023SJohn Marino 	      return base;
1659e4b17023SJohn Marino 	  }
1660e4b17023SJohn Marino 
1661e4b17023SJohn Marino 	/* Neither operand was known to be a pointer.  Go ahead and find the
1662e4b17023SJohn Marino 	   base term for both operands.  */
1663e4b17023SJohn Marino 	tmp1 = find_base_term (tmp1);
1664e4b17023SJohn Marino 	tmp2 = find_base_term (tmp2);
1665e4b17023SJohn Marino 
1666e4b17023SJohn Marino 	/* If either base term is named object or a special address
1667e4b17023SJohn Marino 	   (like an argument or stack reference), then use it for the
1668e4b17023SJohn Marino 	   base term.  */
1669e4b17023SJohn Marino 	if (tmp1 != 0
1670e4b17023SJohn Marino 	    && (GET_CODE (tmp1) == SYMBOL_REF
1671e4b17023SJohn Marino 		|| GET_CODE (tmp1) == LABEL_REF
1672e4b17023SJohn Marino 		|| (GET_CODE (tmp1) == ADDRESS
1673e4b17023SJohn Marino 		    && GET_MODE (tmp1) != VOIDmode)))
1674e4b17023SJohn Marino 	  return tmp1;
1675e4b17023SJohn Marino 
1676e4b17023SJohn Marino 	if (tmp2 != 0
1677e4b17023SJohn Marino 	    && (GET_CODE (tmp2) == SYMBOL_REF
1678e4b17023SJohn Marino 		|| GET_CODE (tmp2) == LABEL_REF
1679e4b17023SJohn Marino 		|| (GET_CODE (tmp2) == ADDRESS
1680e4b17023SJohn Marino 		    && GET_MODE (tmp2) != VOIDmode)))
1681e4b17023SJohn Marino 	  return tmp2;
1682e4b17023SJohn Marino 
1683e4b17023SJohn Marino 	/* We could not determine which of the two operands was the
1684e4b17023SJohn Marino 	   base register and which was the index.  So we can determine
1685e4b17023SJohn Marino 	   nothing from the base alias check.  */
1686e4b17023SJohn Marino 	return 0;
1687e4b17023SJohn Marino       }
1688e4b17023SJohn Marino 
1689e4b17023SJohn Marino     case AND:
1690e4b17023SJohn Marino       if (CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) != 0)
1691e4b17023SJohn Marino 	return find_base_term (XEXP (x, 0));
1692e4b17023SJohn Marino       return 0;
1693e4b17023SJohn Marino 
1694e4b17023SJohn Marino     case SYMBOL_REF:
1695e4b17023SJohn Marino     case LABEL_REF:
1696e4b17023SJohn Marino       return x;
1697e4b17023SJohn Marino 
1698e4b17023SJohn Marino     default:
1699e4b17023SJohn Marino       return 0;
1700e4b17023SJohn Marino     }
1701e4b17023SJohn Marino }
1702e4b17023SJohn Marino 
1703e4b17023SJohn Marino /* Return 0 if the addresses X and Y are known to point to different
1704e4b17023SJohn Marino    objects, 1 if they might be pointers to the same object.  */
1705e4b17023SJohn Marino 
1706e4b17023SJohn Marino static int
base_alias_check(rtx x,rtx y,enum machine_mode x_mode,enum machine_mode y_mode)1707e4b17023SJohn Marino base_alias_check (rtx x, rtx y, enum machine_mode x_mode,
1708e4b17023SJohn Marino 		  enum machine_mode y_mode)
1709e4b17023SJohn Marino {
1710e4b17023SJohn Marino   rtx x_base = find_base_term (x);
1711e4b17023SJohn Marino   rtx y_base = find_base_term (y);
1712e4b17023SJohn Marino 
1713e4b17023SJohn Marino   /* If the address itself has no known base see if a known equivalent
1714e4b17023SJohn Marino      value has one.  If either address still has no known base, nothing
1715e4b17023SJohn Marino      is known about aliasing.  */
1716e4b17023SJohn Marino   if (x_base == 0)
1717e4b17023SJohn Marino     {
1718e4b17023SJohn Marino       rtx x_c;
1719e4b17023SJohn Marino 
1720e4b17023SJohn Marino       if (! flag_expensive_optimizations || (x_c = canon_rtx (x)) == x)
1721e4b17023SJohn Marino 	return 1;
1722e4b17023SJohn Marino 
1723e4b17023SJohn Marino       x_base = find_base_term (x_c);
1724e4b17023SJohn Marino       if (x_base == 0)
1725e4b17023SJohn Marino 	return 1;
1726e4b17023SJohn Marino     }
1727e4b17023SJohn Marino 
1728e4b17023SJohn Marino   if (y_base == 0)
1729e4b17023SJohn Marino     {
1730e4b17023SJohn Marino       rtx y_c;
1731e4b17023SJohn Marino       if (! flag_expensive_optimizations || (y_c = canon_rtx (y)) == y)
1732e4b17023SJohn Marino 	return 1;
1733e4b17023SJohn Marino 
1734e4b17023SJohn Marino       y_base = find_base_term (y_c);
1735e4b17023SJohn Marino       if (y_base == 0)
1736e4b17023SJohn Marino 	return 1;
1737e4b17023SJohn Marino     }
1738e4b17023SJohn Marino 
1739e4b17023SJohn Marino   /* If the base addresses are equal nothing is known about aliasing.  */
1740e4b17023SJohn Marino   if (rtx_equal_p (x_base, y_base))
1741e4b17023SJohn Marino     return 1;
1742e4b17023SJohn Marino 
1743e4b17023SJohn Marino   /* The base addresses are different expressions.  If they are not accessed
1744e4b17023SJohn Marino      via AND, there is no conflict.  We can bring knowledge of object
1745e4b17023SJohn Marino      alignment into play here.  For example, on alpha, "char a, b;" can
1746e4b17023SJohn Marino      alias one another, though "char a; long b;" cannot.  AND addesses may
1747e4b17023SJohn Marino      implicitly alias surrounding objects; i.e. unaligned access in DImode
1748e4b17023SJohn Marino      via AND address can alias all surrounding object types except those
1749e4b17023SJohn Marino      with aligment 8 or higher.  */
1750e4b17023SJohn Marino   if (GET_CODE (x) == AND && GET_CODE (y) == AND)
1751e4b17023SJohn Marino     return 1;
1752e4b17023SJohn Marino   if (GET_CODE (x) == AND
1753e4b17023SJohn Marino       && (!CONST_INT_P (XEXP (x, 1))
1754e4b17023SJohn Marino 	  || (int) GET_MODE_UNIT_SIZE (y_mode) < -INTVAL (XEXP (x, 1))))
1755e4b17023SJohn Marino     return 1;
1756e4b17023SJohn Marino   if (GET_CODE (y) == AND
1757e4b17023SJohn Marino       && (!CONST_INT_P (XEXP (y, 1))
1758e4b17023SJohn Marino 	  || (int) GET_MODE_UNIT_SIZE (x_mode) < -INTVAL (XEXP (y, 1))))
1759e4b17023SJohn Marino     return 1;
1760e4b17023SJohn Marino 
1761e4b17023SJohn Marino   /* Differing symbols not accessed via AND never alias.  */
1762e4b17023SJohn Marino   if (GET_CODE (x_base) != ADDRESS && GET_CODE (y_base) != ADDRESS)
1763e4b17023SJohn Marino     return 0;
1764e4b17023SJohn Marino 
1765e4b17023SJohn Marino   /* If one address is a stack reference there can be no alias:
1766e4b17023SJohn Marino      stack references using different base registers do not alias,
1767e4b17023SJohn Marino      a stack reference can not alias a parameter, and a stack reference
1768e4b17023SJohn Marino      can not alias a global.  */
1769e4b17023SJohn Marino   if ((GET_CODE (x_base) == ADDRESS && GET_MODE (x_base) == Pmode)
1770e4b17023SJohn Marino       || (GET_CODE (y_base) == ADDRESS && GET_MODE (y_base) == Pmode))
1771e4b17023SJohn Marino     return 0;
1772e4b17023SJohn Marino 
1773e4b17023SJohn Marino   return 1;
1774e4b17023SJohn Marino }
1775e4b17023SJohn Marino 
1776e4b17023SJohn Marino /* Callback for for_each_rtx, that returns 1 upon encountering a VALUE
1777e4b17023SJohn Marino    whose UID is greater than the int uid that D points to.  */
1778e4b17023SJohn Marino 
1779e4b17023SJohn Marino static int
refs_newer_value_cb(rtx * x,void * d)1780e4b17023SJohn Marino refs_newer_value_cb (rtx *x, void *d)
1781e4b17023SJohn Marino {
1782e4b17023SJohn Marino   if (GET_CODE (*x) == VALUE && CSELIB_VAL_PTR (*x)->uid > *(int *)d)
1783e4b17023SJohn Marino     return 1;
1784e4b17023SJohn Marino 
1785e4b17023SJohn Marino   return 0;
1786e4b17023SJohn Marino }
1787e4b17023SJohn Marino 
1788e4b17023SJohn Marino /* Return TRUE if EXPR refers to a VALUE whose uid is greater than
1789e4b17023SJohn Marino    that of V.  */
1790e4b17023SJohn Marino 
1791e4b17023SJohn Marino static bool
refs_newer_value_p(rtx expr,rtx v)1792e4b17023SJohn Marino refs_newer_value_p (rtx expr, rtx v)
1793e4b17023SJohn Marino {
1794e4b17023SJohn Marino   int minuid = CSELIB_VAL_PTR (v)->uid;
1795e4b17023SJohn Marino 
1796e4b17023SJohn Marino   return for_each_rtx (&expr, refs_newer_value_cb, &minuid);
1797e4b17023SJohn Marino }
1798e4b17023SJohn Marino 
1799e4b17023SJohn Marino /* Convert the address X into something we can use.  This is done by returning
1800e4b17023SJohn Marino    it unchanged unless it is a value; in the latter case we call cselib to get
1801e4b17023SJohn Marino    a more useful rtx.  */
1802e4b17023SJohn Marino 
1803e4b17023SJohn Marino rtx
get_addr(rtx x)1804e4b17023SJohn Marino get_addr (rtx x)
1805e4b17023SJohn Marino {
1806e4b17023SJohn Marino   cselib_val *v;
1807e4b17023SJohn Marino   struct elt_loc_list *l;
1808e4b17023SJohn Marino 
1809e4b17023SJohn Marino   if (GET_CODE (x) != VALUE)
1810e4b17023SJohn Marino     return x;
1811e4b17023SJohn Marino   v = CSELIB_VAL_PTR (x);
1812e4b17023SJohn Marino   if (v)
1813e4b17023SJohn Marino     {
1814e4b17023SJohn Marino       bool have_equivs = cselib_have_permanent_equivalences ();
1815e4b17023SJohn Marino       if (have_equivs)
1816e4b17023SJohn Marino 	v = canonical_cselib_val (v);
1817e4b17023SJohn Marino       for (l = v->locs; l; l = l->next)
1818e4b17023SJohn Marino 	if (CONSTANT_P (l->loc))
1819e4b17023SJohn Marino 	  return l->loc;
1820e4b17023SJohn Marino       for (l = v->locs; l; l = l->next)
1821e4b17023SJohn Marino 	if (!REG_P (l->loc) && !MEM_P (l->loc)
1822e4b17023SJohn Marino 	    /* Avoid infinite recursion when potentially dealing with
1823e4b17023SJohn Marino 	       var-tracking artificial equivalences, by skipping the
1824e4b17023SJohn Marino 	       equivalences themselves, and not choosing expressions
1825e4b17023SJohn Marino 	       that refer to newer VALUEs.  */
1826e4b17023SJohn Marino 	    && (!have_equivs
1827e4b17023SJohn Marino 		|| (GET_CODE (l->loc) != VALUE
1828e4b17023SJohn Marino 		    && !refs_newer_value_p (l->loc, x))))
1829e4b17023SJohn Marino 	  return l->loc;
1830e4b17023SJohn Marino       if (have_equivs)
1831e4b17023SJohn Marino 	{
1832e4b17023SJohn Marino 	  for (l = v->locs; l; l = l->next)
1833e4b17023SJohn Marino 	    if (REG_P (l->loc)
1834e4b17023SJohn Marino 		|| (GET_CODE (l->loc) != VALUE
1835e4b17023SJohn Marino 		    && !refs_newer_value_p (l->loc, x)))
1836e4b17023SJohn Marino 	      return l->loc;
1837e4b17023SJohn Marino 	  /* Return the canonical value.  */
1838e4b17023SJohn Marino 	  return v->val_rtx;
1839e4b17023SJohn Marino 	}
1840e4b17023SJohn Marino       if (v->locs)
1841e4b17023SJohn Marino 	return v->locs->loc;
1842e4b17023SJohn Marino     }
1843e4b17023SJohn Marino   return x;
1844e4b17023SJohn Marino }
1845e4b17023SJohn Marino 
1846e4b17023SJohn Marino /*  Return the address of the (N_REFS + 1)th memory reference to ADDR
1847e4b17023SJohn Marino     where SIZE is the size in bytes of the memory reference.  If ADDR
1848e4b17023SJohn Marino     is not modified by the memory reference then ADDR is returned.  */
1849e4b17023SJohn Marino 
1850e4b17023SJohn Marino static rtx
addr_side_effect_eval(rtx addr,int size,int n_refs)1851e4b17023SJohn Marino addr_side_effect_eval (rtx addr, int size, int n_refs)
1852e4b17023SJohn Marino {
1853e4b17023SJohn Marino   int offset = 0;
1854e4b17023SJohn Marino 
1855e4b17023SJohn Marino   switch (GET_CODE (addr))
1856e4b17023SJohn Marino     {
1857e4b17023SJohn Marino     case PRE_INC:
1858e4b17023SJohn Marino       offset = (n_refs + 1) * size;
1859e4b17023SJohn Marino       break;
1860e4b17023SJohn Marino     case PRE_DEC:
1861e4b17023SJohn Marino       offset = -(n_refs + 1) * size;
1862e4b17023SJohn Marino       break;
1863e4b17023SJohn Marino     case POST_INC:
1864e4b17023SJohn Marino       offset = n_refs * size;
1865e4b17023SJohn Marino       break;
1866e4b17023SJohn Marino     case POST_DEC:
1867e4b17023SJohn Marino       offset = -n_refs * size;
1868e4b17023SJohn Marino       break;
1869e4b17023SJohn Marino 
1870e4b17023SJohn Marino     default:
1871e4b17023SJohn Marino       return addr;
1872e4b17023SJohn Marino     }
1873e4b17023SJohn Marino 
1874e4b17023SJohn Marino   if (offset)
1875e4b17023SJohn Marino     addr = gen_rtx_PLUS (GET_MODE (addr), XEXP (addr, 0),
1876e4b17023SJohn Marino 			 GEN_INT (offset));
1877e4b17023SJohn Marino   else
1878e4b17023SJohn Marino     addr = XEXP (addr, 0);
1879e4b17023SJohn Marino   addr = canon_rtx (addr);
1880e4b17023SJohn Marino 
1881e4b17023SJohn Marino   return addr;
1882e4b17023SJohn Marino }
1883e4b17023SJohn Marino 
1884e4b17023SJohn Marino /* Return one if X and Y (memory addresses) reference the
1885e4b17023SJohn Marino    same location in memory or if the references overlap.
1886e4b17023SJohn Marino    Return zero if they do not overlap, else return
1887e4b17023SJohn Marino    minus one in which case they still might reference the same location.
1888e4b17023SJohn Marino 
1889e4b17023SJohn Marino    C is an offset accumulator.  When
1890e4b17023SJohn Marino    C is nonzero, we are testing aliases between X and Y + C.
1891e4b17023SJohn Marino    XSIZE is the size in bytes of the X reference,
1892e4b17023SJohn Marino    similarly YSIZE is the size in bytes for Y.
1893e4b17023SJohn Marino    Expect that canon_rtx has been already called for X and Y.
1894e4b17023SJohn Marino 
1895e4b17023SJohn Marino    If XSIZE or YSIZE is zero, we do not know the amount of memory being
1896e4b17023SJohn Marino    referenced (the reference was BLKmode), so make the most pessimistic
1897e4b17023SJohn Marino    assumptions.
1898e4b17023SJohn Marino 
1899e4b17023SJohn Marino    If XSIZE or YSIZE is negative, we may access memory outside the object
1900e4b17023SJohn Marino    being referenced as a side effect.  This can happen when using AND to
1901e4b17023SJohn Marino    align memory references, as is done on the Alpha.
1902e4b17023SJohn Marino 
1903e4b17023SJohn Marino    Nice to notice that varying addresses cannot conflict with fp if no
1904e4b17023SJohn Marino    local variables had their addresses taken, but that's too hard now.
1905e4b17023SJohn Marino 
1906e4b17023SJohn Marino    ???  Contrary to the tree alias oracle this does not return
1907e4b17023SJohn Marino    one for X + non-constant and Y + non-constant when X and Y are equal.
1908e4b17023SJohn Marino    If that is fixed the TBAA hack for union type-punning can be removed.  */
1909e4b17023SJohn Marino 
1910e4b17023SJohn Marino static int
memrefs_conflict_p(int xsize,rtx x,int ysize,rtx y,HOST_WIDE_INT c)1911e4b17023SJohn Marino memrefs_conflict_p (int xsize, rtx x, int ysize, rtx y, HOST_WIDE_INT c)
1912e4b17023SJohn Marino {
1913e4b17023SJohn Marino   if (GET_CODE (x) == VALUE)
1914e4b17023SJohn Marino     {
1915e4b17023SJohn Marino       if (REG_P (y))
1916e4b17023SJohn Marino 	{
1917e4b17023SJohn Marino 	  struct elt_loc_list *l = NULL;
1918e4b17023SJohn Marino 	  if (CSELIB_VAL_PTR (x))
1919e4b17023SJohn Marino 	    for (l = canonical_cselib_val (CSELIB_VAL_PTR (x))->locs;
1920e4b17023SJohn Marino 		 l; l = l->next)
1921e4b17023SJohn Marino 	      if (REG_P (l->loc) && rtx_equal_for_memref_p (l->loc, y))
1922e4b17023SJohn Marino 		break;
1923e4b17023SJohn Marino 	  if (l)
1924e4b17023SJohn Marino 	    x = y;
1925e4b17023SJohn Marino 	  else
1926e4b17023SJohn Marino 	    x = get_addr (x);
1927e4b17023SJohn Marino 	}
1928e4b17023SJohn Marino       /* Don't call get_addr if y is the same VALUE.  */
1929e4b17023SJohn Marino       else if (x != y)
1930e4b17023SJohn Marino 	x = get_addr (x);
1931e4b17023SJohn Marino     }
1932e4b17023SJohn Marino   if (GET_CODE (y) == VALUE)
1933e4b17023SJohn Marino     {
1934e4b17023SJohn Marino       if (REG_P (x))
1935e4b17023SJohn Marino 	{
1936e4b17023SJohn Marino 	  struct elt_loc_list *l = NULL;
1937e4b17023SJohn Marino 	  if (CSELIB_VAL_PTR (y))
1938e4b17023SJohn Marino 	    for (l = canonical_cselib_val (CSELIB_VAL_PTR (y))->locs;
1939e4b17023SJohn Marino 		 l; l = l->next)
1940e4b17023SJohn Marino 	      if (REG_P (l->loc) && rtx_equal_for_memref_p (l->loc, x))
1941e4b17023SJohn Marino 		break;
1942e4b17023SJohn Marino 	  if (l)
1943e4b17023SJohn Marino 	    y = x;
1944e4b17023SJohn Marino 	  else
1945e4b17023SJohn Marino 	    y = get_addr (y);
1946e4b17023SJohn Marino 	}
1947e4b17023SJohn Marino       /* Don't call get_addr if x is the same VALUE.  */
1948e4b17023SJohn Marino       else if (y != x)
1949e4b17023SJohn Marino 	y = get_addr (y);
1950e4b17023SJohn Marino     }
1951e4b17023SJohn Marino   if (GET_CODE (x) == HIGH)
1952e4b17023SJohn Marino     x = XEXP (x, 0);
1953e4b17023SJohn Marino   else if (GET_CODE (x) == LO_SUM)
1954e4b17023SJohn Marino     x = XEXP (x, 1);
1955e4b17023SJohn Marino   else
1956e4b17023SJohn Marino     x = addr_side_effect_eval (x, xsize, 0);
1957e4b17023SJohn Marino   if (GET_CODE (y) == HIGH)
1958e4b17023SJohn Marino     y = XEXP (y, 0);
1959e4b17023SJohn Marino   else if (GET_CODE (y) == LO_SUM)
1960e4b17023SJohn Marino     y = XEXP (y, 1);
1961e4b17023SJohn Marino   else
1962e4b17023SJohn Marino     y = addr_side_effect_eval (y, ysize, 0);
1963e4b17023SJohn Marino 
1964e4b17023SJohn Marino   if (rtx_equal_for_memref_p (x, y))
1965e4b17023SJohn Marino     {
1966e4b17023SJohn Marino       if (xsize <= 0 || ysize <= 0)
1967e4b17023SJohn Marino 	return 1;
1968e4b17023SJohn Marino       if (c >= 0 && xsize > c)
1969e4b17023SJohn Marino 	return 1;
1970e4b17023SJohn Marino       if (c < 0 && ysize+c > 0)
1971e4b17023SJohn Marino 	return 1;
1972e4b17023SJohn Marino       return 0;
1973e4b17023SJohn Marino     }
1974e4b17023SJohn Marino 
1975e4b17023SJohn Marino   /* This code used to check for conflicts involving stack references and
1976e4b17023SJohn Marino      globals but the base address alias code now handles these cases.  */
1977e4b17023SJohn Marino 
1978e4b17023SJohn Marino   if (GET_CODE (x) == PLUS)
1979e4b17023SJohn Marino     {
1980e4b17023SJohn Marino       /* The fact that X is canonicalized means that this
1981e4b17023SJohn Marino 	 PLUS rtx is canonicalized.  */
1982e4b17023SJohn Marino       rtx x0 = XEXP (x, 0);
1983e4b17023SJohn Marino       rtx x1 = XEXP (x, 1);
1984e4b17023SJohn Marino 
1985e4b17023SJohn Marino       if (GET_CODE (y) == PLUS)
1986e4b17023SJohn Marino 	{
1987e4b17023SJohn Marino 	  /* The fact that Y is canonicalized means that this
1988e4b17023SJohn Marino 	     PLUS rtx is canonicalized.  */
1989e4b17023SJohn Marino 	  rtx y0 = XEXP (y, 0);
1990e4b17023SJohn Marino 	  rtx y1 = XEXP (y, 1);
1991e4b17023SJohn Marino 
1992e4b17023SJohn Marino 	  if (rtx_equal_for_memref_p (x1, y1))
1993e4b17023SJohn Marino 	    return memrefs_conflict_p (xsize, x0, ysize, y0, c);
1994e4b17023SJohn Marino 	  if (rtx_equal_for_memref_p (x0, y0))
1995e4b17023SJohn Marino 	    return memrefs_conflict_p (xsize, x1, ysize, y1, c);
1996e4b17023SJohn Marino 	  if (CONST_INT_P (x1))
1997e4b17023SJohn Marino 	    {
1998e4b17023SJohn Marino 	      if (CONST_INT_P (y1))
1999e4b17023SJohn Marino 		return memrefs_conflict_p (xsize, x0, ysize, y0,
2000e4b17023SJohn Marino 					   c - INTVAL (x1) + INTVAL (y1));
2001e4b17023SJohn Marino 	      else
2002e4b17023SJohn Marino 		return memrefs_conflict_p (xsize, x0, ysize, y,
2003e4b17023SJohn Marino 					   c - INTVAL (x1));
2004e4b17023SJohn Marino 	    }
2005e4b17023SJohn Marino 	  else if (CONST_INT_P (y1))
2006e4b17023SJohn Marino 	    return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
2007e4b17023SJohn Marino 
2008e4b17023SJohn Marino 	  return -1;
2009e4b17023SJohn Marino 	}
2010e4b17023SJohn Marino       else if (CONST_INT_P (x1))
2011e4b17023SJohn Marino 	return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
2012e4b17023SJohn Marino     }
2013e4b17023SJohn Marino   else if (GET_CODE (y) == PLUS)
2014e4b17023SJohn Marino     {
2015e4b17023SJohn Marino       /* The fact that Y is canonicalized means that this
2016e4b17023SJohn Marino 	 PLUS rtx is canonicalized.  */
2017e4b17023SJohn Marino       rtx y0 = XEXP (y, 0);
2018e4b17023SJohn Marino       rtx y1 = XEXP (y, 1);
2019e4b17023SJohn Marino 
2020e4b17023SJohn Marino       if (CONST_INT_P (y1))
2021e4b17023SJohn Marino 	return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
2022e4b17023SJohn Marino       else
2023e4b17023SJohn Marino 	return -1;
2024e4b17023SJohn Marino     }
2025e4b17023SJohn Marino 
2026e4b17023SJohn Marino   if (GET_CODE (x) == GET_CODE (y))
2027e4b17023SJohn Marino     switch (GET_CODE (x))
2028e4b17023SJohn Marino       {
2029e4b17023SJohn Marino       case MULT:
2030e4b17023SJohn Marino 	{
2031e4b17023SJohn Marino 	  /* Handle cases where we expect the second operands to be the
2032e4b17023SJohn Marino 	     same, and check only whether the first operand would conflict
2033e4b17023SJohn Marino 	     or not.  */
2034e4b17023SJohn Marino 	  rtx x0, y0;
2035e4b17023SJohn Marino 	  rtx x1 = canon_rtx (XEXP (x, 1));
2036e4b17023SJohn Marino 	  rtx y1 = canon_rtx (XEXP (y, 1));
2037e4b17023SJohn Marino 	  if (! rtx_equal_for_memref_p (x1, y1))
2038e4b17023SJohn Marino 	    return -1;
2039e4b17023SJohn Marino 	  x0 = canon_rtx (XEXP (x, 0));
2040e4b17023SJohn Marino 	  y0 = canon_rtx (XEXP (y, 0));
2041e4b17023SJohn Marino 	  if (rtx_equal_for_memref_p (x0, y0))
2042e4b17023SJohn Marino 	    return (xsize == 0 || ysize == 0
2043e4b17023SJohn Marino 		    || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
2044e4b17023SJohn Marino 
2045e4b17023SJohn Marino 	  /* Can't properly adjust our sizes.  */
2046e4b17023SJohn Marino 	  if (!CONST_INT_P (x1))
2047e4b17023SJohn Marino 	    return -1;
2048e4b17023SJohn Marino 	  xsize /= INTVAL (x1);
2049e4b17023SJohn Marino 	  ysize /= INTVAL (x1);
2050e4b17023SJohn Marino 	  c /= INTVAL (x1);
2051e4b17023SJohn Marino 	  return memrefs_conflict_p (xsize, x0, ysize, y0, c);
2052e4b17023SJohn Marino 	}
2053e4b17023SJohn Marino 
2054e4b17023SJohn Marino       default:
2055e4b17023SJohn Marino 	break;
2056e4b17023SJohn Marino       }
2057e4b17023SJohn Marino 
2058e4b17023SJohn Marino   /* Treat an access through an AND (e.g. a subword access on an Alpha)
2059e4b17023SJohn Marino      as an access with indeterminate size.  Assume that references
2060e4b17023SJohn Marino      besides AND are aligned, so if the size of the other reference is
2061e4b17023SJohn Marino      at least as large as the alignment, assume no other overlap.  */
2062e4b17023SJohn Marino   if (GET_CODE (x) == AND && CONST_INT_P (XEXP (x, 1)))
2063e4b17023SJohn Marino     {
2064e4b17023SJohn Marino       if (GET_CODE (y) == AND || ysize < -INTVAL (XEXP (x, 1)))
2065e4b17023SJohn Marino 	xsize = -1;
2066e4b17023SJohn Marino       return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)), ysize, y, c);
2067e4b17023SJohn Marino     }
2068e4b17023SJohn Marino   if (GET_CODE (y) == AND && CONST_INT_P (XEXP (y, 1)))
2069e4b17023SJohn Marino     {
2070e4b17023SJohn Marino       /* ??? If we are indexing far enough into the array/structure, we
2071e4b17023SJohn Marino 	 may yet be able to determine that we can not overlap.  But we
2072e4b17023SJohn Marino 	 also need to that we are far enough from the end not to overlap
2073e4b17023SJohn Marino 	 a following reference, so we do nothing with that for now.  */
2074e4b17023SJohn Marino       if (GET_CODE (x) == AND || xsize < -INTVAL (XEXP (y, 1)))
2075e4b17023SJohn Marino 	ysize = -1;
2076e4b17023SJohn Marino       return memrefs_conflict_p (xsize, x, ysize, canon_rtx (XEXP (y, 0)), c);
2077e4b17023SJohn Marino     }
2078e4b17023SJohn Marino 
2079e4b17023SJohn Marino   if (CONSTANT_P (x))
2080e4b17023SJohn Marino     {
2081e4b17023SJohn Marino       if (CONST_INT_P (x) && CONST_INT_P (y))
2082e4b17023SJohn Marino 	{
2083e4b17023SJohn Marino 	  c += (INTVAL (y) - INTVAL (x));
2084e4b17023SJohn Marino 	  return (xsize <= 0 || ysize <= 0
2085e4b17023SJohn Marino 		  || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
2086e4b17023SJohn Marino 	}
2087e4b17023SJohn Marino 
2088e4b17023SJohn Marino       if (GET_CODE (x) == CONST)
2089e4b17023SJohn Marino 	{
2090e4b17023SJohn Marino 	  if (GET_CODE (y) == CONST)
2091e4b17023SJohn Marino 	    return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
2092e4b17023SJohn Marino 				       ysize, canon_rtx (XEXP (y, 0)), c);
2093e4b17023SJohn Marino 	  else
2094e4b17023SJohn Marino 	    return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
2095e4b17023SJohn Marino 				       ysize, y, c);
2096e4b17023SJohn Marino 	}
2097e4b17023SJohn Marino       if (GET_CODE (y) == CONST)
2098e4b17023SJohn Marino 	return memrefs_conflict_p (xsize, x, ysize,
2099e4b17023SJohn Marino 				   canon_rtx (XEXP (y, 0)), c);
2100e4b17023SJohn Marino 
2101e4b17023SJohn Marino       if (CONSTANT_P (y))
2102e4b17023SJohn Marino 	return (xsize <= 0 || ysize <= 0
2103e4b17023SJohn Marino 		|| (rtx_equal_for_memref_p (x, y)
2104e4b17023SJohn Marino 		    && ((c >= 0 && xsize > c) || (c < 0 && ysize+c > 0))));
2105e4b17023SJohn Marino 
2106e4b17023SJohn Marino       return -1;
2107e4b17023SJohn Marino     }
2108e4b17023SJohn Marino 
2109e4b17023SJohn Marino   return -1;
2110e4b17023SJohn Marino }
2111e4b17023SJohn Marino 
2112e4b17023SJohn Marino /* Functions to compute memory dependencies.
2113e4b17023SJohn Marino 
2114e4b17023SJohn Marino    Since we process the insns in execution order, we can build tables
2115e4b17023SJohn Marino    to keep track of what registers are fixed (and not aliased), what registers
2116e4b17023SJohn Marino    are varying in known ways, and what registers are varying in unknown
2117e4b17023SJohn Marino    ways.
2118e4b17023SJohn Marino 
2119e4b17023SJohn Marino    If both memory references are volatile, then there must always be a
2120e4b17023SJohn Marino    dependence between the two references, since their order can not be
2121e4b17023SJohn Marino    changed.  A volatile and non-volatile reference can be interchanged
2122e4b17023SJohn Marino    though.
2123e4b17023SJohn Marino 
2124e4b17023SJohn Marino    We also must allow AND addresses, because they may generate accesses
2125e4b17023SJohn Marino    outside the object being referenced.  This is used to generate aligned
2126e4b17023SJohn Marino    addresses from unaligned addresses, for instance, the alpha
2127e4b17023SJohn Marino    storeqi_unaligned pattern.  */
2128e4b17023SJohn Marino 
2129e4b17023SJohn Marino /* Read dependence: X is read after read in MEM takes place.  There can
2130e4b17023SJohn Marino    only be a dependence here if both reads are volatile, or if either is
2131e4b17023SJohn Marino    an explicit barrier.  */
2132e4b17023SJohn Marino 
2133e4b17023SJohn Marino int
read_dependence(const_rtx mem,const_rtx x)2134e4b17023SJohn Marino read_dependence (const_rtx mem, const_rtx x)
2135e4b17023SJohn Marino {
2136e4b17023SJohn Marino   if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2137e4b17023SJohn Marino     return true;
2138e4b17023SJohn Marino   if (MEM_ALIAS_SET (x) == ALIAS_SET_MEMORY_BARRIER
2139e4b17023SJohn Marino       || MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2140e4b17023SJohn Marino     return true;
2141e4b17023SJohn Marino   return false;
2142e4b17023SJohn Marino }
2143e4b17023SJohn Marino 
2144e4b17023SJohn Marino /* Returns nonzero if something about the mode or address format MEM1
2145e4b17023SJohn Marino    indicates that it might well alias *anything*.  */
2146e4b17023SJohn Marino 
2147e4b17023SJohn Marino static int
aliases_everything_p(const_rtx mem)2148e4b17023SJohn Marino aliases_everything_p (const_rtx mem)
2149e4b17023SJohn Marino {
2150e4b17023SJohn Marino   if (GET_CODE (XEXP (mem, 0)) == AND)
2151e4b17023SJohn Marino     /* If the address is an AND, it's very hard to know at what it is
2152e4b17023SJohn Marino        actually pointing.  */
2153e4b17023SJohn Marino     return 1;
2154e4b17023SJohn Marino 
2155e4b17023SJohn Marino   return 0;
2156e4b17023SJohn Marino }
2157e4b17023SJohn Marino 
2158e4b17023SJohn Marino /* Return true if we can determine that the fields referenced cannot
2159e4b17023SJohn Marino    overlap for any pair of objects.  */
2160e4b17023SJohn Marino 
2161e4b17023SJohn Marino static bool
nonoverlapping_component_refs_p(const_tree x,const_tree y)2162e4b17023SJohn Marino nonoverlapping_component_refs_p (const_tree x, const_tree y)
2163e4b17023SJohn Marino {
2164e4b17023SJohn Marino   const_tree fieldx, fieldy, typex, typey, orig_y;
2165e4b17023SJohn Marino 
2166e4b17023SJohn Marino   if (!flag_strict_aliasing)
2167e4b17023SJohn Marino     return false;
2168e4b17023SJohn Marino 
2169e4b17023SJohn Marino   do
2170e4b17023SJohn Marino     {
2171e4b17023SJohn Marino       /* The comparison has to be done at a common type, since we don't
2172e4b17023SJohn Marino 	 know how the inheritance hierarchy works.  */
2173e4b17023SJohn Marino       orig_y = y;
2174e4b17023SJohn Marino       do
2175e4b17023SJohn Marino 	{
2176e4b17023SJohn Marino 	  fieldx = TREE_OPERAND (x, 1);
2177e4b17023SJohn Marino 	  typex = TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldx));
2178e4b17023SJohn Marino 
2179e4b17023SJohn Marino 	  y = orig_y;
2180e4b17023SJohn Marino 	  do
2181e4b17023SJohn Marino 	    {
2182e4b17023SJohn Marino 	      fieldy = TREE_OPERAND (y, 1);
2183e4b17023SJohn Marino 	      typey = TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldy));
2184e4b17023SJohn Marino 
2185e4b17023SJohn Marino 	      if (typex == typey)
2186e4b17023SJohn Marino 		goto found;
2187e4b17023SJohn Marino 
2188e4b17023SJohn Marino 	      y = TREE_OPERAND (y, 0);
2189e4b17023SJohn Marino 	    }
2190e4b17023SJohn Marino 	  while (y && TREE_CODE (y) == COMPONENT_REF);
2191e4b17023SJohn Marino 
2192e4b17023SJohn Marino 	  x = TREE_OPERAND (x, 0);
2193e4b17023SJohn Marino 	}
2194e4b17023SJohn Marino       while (x && TREE_CODE (x) == COMPONENT_REF);
2195e4b17023SJohn Marino       /* Never found a common type.  */
2196e4b17023SJohn Marino       return false;
2197e4b17023SJohn Marino 
2198e4b17023SJohn Marino     found:
2199e4b17023SJohn Marino       /* If we're left with accessing different fields of a structure,
2200e4b17023SJohn Marino 	 then no overlap.  */
2201e4b17023SJohn Marino       if (TREE_CODE (typex) == RECORD_TYPE
2202e4b17023SJohn Marino 	  && fieldx != fieldy)
2203e4b17023SJohn Marino 	return true;
2204e4b17023SJohn Marino 
2205e4b17023SJohn Marino       /* The comparison on the current field failed.  If we're accessing
2206e4b17023SJohn Marino 	 a very nested structure, look at the next outer level.  */
2207e4b17023SJohn Marino       x = TREE_OPERAND (x, 0);
2208e4b17023SJohn Marino       y = TREE_OPERAND (y, 0);
2209e4b17023SJohn Marino     }
2210e4b17023SJohn Marino   while (x && y
2211e4b17023SJohn Marino 	 && TREE_CODE (x) == COMPONENT_REF
2212e4b17023SJohn Marino 	 && TREE_CODE (y) == COMPONENT_REF);
2213e4b17023SJohn Marino 
2214e4b17023SJohn Marino   return false;
2215e4b17023SJohn Marino }
2216e4b17023SJohn Marino 
2217e4b17023SJohn Marino /* Look at the bottom of the COMPONENT_REF list for a DECL, and return it.  */
2218e4b17023SJohn Marino 
2219e4b17023SJohn Marino static tree
decl_for_component_ref(tree x)2220e4b17023SJohn Marino decl_for_component_ref (tree x)
2221e4b17023SJohn Marino {
2222e4b17023SJohn Marino   do
2223e4b17023SJohn Marino     {
2224e4b17023SJohn Marino       x = TREE_OPERAND (x, 0);
2225e4b17023SJohn Marino     }
2226e4b17023SJohn Marino   while (x && TREE_CODE (x) == COMPONENT_REF);
2227e4b17023SJohn Marino 
2228e4b17023SJohn Marino   return x && DECL_P (x) ? x : NULL_TREE;
2229e4b17023SJohn Marino }
2230e4b17023SJohn Marino 
2231e4b17023SJohn Marino /* Walk up the COMPONENT_REF list in X and adjust *OFFSET to compensate
2232e4b17023SJohn Marino    for the offset of the field reference.  *KNOWN_P says whether the
2233e4b17023SJohn Marino    offset is known.  */
2234e4b17023SJohn Marino 
2235e4b17023SJohn Marino static void
adjust_offset_for_component_ref(tree x,bool * known_p,HOST_WIDE_INT * offset)2236e4b17023SJohn Marino adjust_offset_for_component_ref (tree x, bool *known_p,
2237e4b17023SJohn Marino 				 HOST_WIDE_INT *offset)
2238e4b17023SJohn Marino {
2239e4b17023SJohn Marino   if (!*known_p)
2240e4b17023SJohn Marino     return;
2241e4b17023SJohn Marino   do
2242e4b17023SJohn Marino     {
2243e4b17023SJohn Marino       tree xoffset = component_ref_field_offset (x);
2244e4b17023SJohn Marino       tree field = TREE_OPERAND (x, 1);
2245e4b17023SJohn Marino 
2246e4b17023SJohn Marino       if (! host_integerp (xoffset, 1))
2247e4b17023SJohn Marino 	{
2248e4b17023SJohn Marino 	  *known_p = false;
2249e4b17023SJohn Marino 	  return;
2250e4b17023SJohn Marino 	}
2251e4b17023SJohn Marino       *offset += (tree_low_cst (xoffset, 1)
2252e4b17023SJohn Marino 		  + (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
2253e4b17023SJohn Marino 		     / BITS_PER_UNIT));
2254e4b17023SJohn Marino 
2255e4b17023SJohn Marino       x = TREE_OPERAND (x, 0);
2256e4b17023SJohn Marino     }
2257e4b17023SJohn Marino   while (x && TREE_CODE (x) == COMPONENT_REF);
2258e4b17023SJohn Marino }
2259e4b17023SJohn Marino 
2260e4b17023SJohn Marino /* Return nonzero if we can determine the exprs corresponding to memrefs
2261e4b17023SJohn Marino    X and Y and they do not overlap.
2262e4b17023SJohn Marino    If LOOP_VARIANT is set, skip offset-based disambiguation */
2263e4b17023SJohn Marino 
2264e4b17023SJohn Marino int
nonoverlapping_memrefs_p(const_rtx x,const_rtx y,bool loop_invariant)2265e4b17023SJohn Marino nonoverlapping_memrefs_p (const_rtx x, const_rtx y, bool loop_invariant)
2266e4b17023SJohn Marino {
2267e4b17023SJohn Marino   tree exprx = MEM_EXPR (x), expry = MEM_EXPR (y);
2268e4b17023SJohn Marino   rtx rtlx, rtly;
2269e4b17023SJohn Marino   rtx basex, basey;
2270e4b17023SJohn Marino   bool moffsetx_known_p, moffsety_known_p;
2271e4b17023SJohn Marino   HOST_WIDE_INT moffsetx = 0, moffsety = 0;
2272e4b17023SJohn Marino   HOST_WIDE_INT offsetx = 0, offsety = 0, sizex, sizey, tem;
2273e4b17023SJohn Marino 
2274e4b17023SJohn Marino   /* Unless both have exprs, we can't tell anything.  */
2275e4b17023SJohn Marino   if (exprx == 0 || expry == 0)
2276e4b17023SJohn Marino     return 0;
2277e4b17023SJohn Marino 
2278e4b17023SJohn Marino   /* For spill-slot accesses make sure we have valid offsets.  */
2279e4b17023SJohn Marino   if ((exprx == get_spill_slot_decl (false)
2280e4b17023SJohn Marino        && ! MEM_OFFSET_KNOWN_P (x))
2281e4b17023SJohn Marino       || (expry == get_spill_slot_decl (false)
2282e4b17023SJohn Marino 	  && ! MEM_OFFSET_KNOWN_P (y)))
2283e4b17023SJohn Marino     return 0;
2284e4b17023SJohn Marino 
2285e4b17023SJohn Marino   /* If both are field references, we may be able to determine something.  */
2286e4b17023SJohn Marino   if (TREE_CODE (exprx) == COMPONENT_REF
2287e4b17023SJohn Marino       && TREE_CODE (expry) == COMPONENT_REF
2288e4b17023SJohn Marino       && nonoverlapping_component_refs_p (exprx, expry))
2289e4b17023SJohn Marino     return 1;
2290e4b17023SJohn Marino 
2291e4b17023SJohn Marino 
2292e4b17023SJohn Marino   /* If the field reference test failed, look at the DECLs involved.  */
2293e4b17023SJohn Marino   moffsetx_known_p = MEM_OFFSET_KNOWN_P (x);
2294e4b17023SJohn Marino   if (moffsetx_known_p)
2295e4b17023SJohn Marino     moffsetx = MEM_OFFSET (x);
2296e4b17023SJohn Marino   if (TREE_CODE (exprx) == COMPONENT_REF)
2297e4b17023SJohn Marino     {
2298e4b17023SJohn Marino       tree t = decl_for_component_ref (exprx);
2299e4b17023SJohn Marino       if (! t)
2300e4b17023SJohn Marino 	return 0;
2301e4b17023SJohn Marino       adjust_offset_for_component_ref (exprx, &moffsetx_known_p, &moffsetx);
2302e4b17023SJohn Marino       exprx = t;
2303e4b17023SJohn Marino     }
2304e4b17023SJohn Marino 
2305e4b17023SJohn Marino   moffsety_known_p = MEM_OFFSET_KNOWN_P (y);
2306e4b17023SJohn Marino   if (moffsety_known_p)
2307e4b17023SJohn Marino     moffsety = MEM_OFFSET (y);
2308e4b17023SJohn Marino   if (TREE_CODE (expry) == COMPONENT_REF)
2309e4b17023SJohn Marino     {
2310e4b17023SJohn Marino       tree t = decl_for_component_ref (expry);
2311e4b17023SJohn Marino       if (! t)
2312e4b17023SJohn Marino 	return 0;
2313e4b17023SJohn Marino       adjust_offset_for_component_ref (expry, &moffsety_known_p, &moffsety);
2314e4b17023SJohn Marino       expry = t;
2315e4b17023SJohn Marino     }
2316e4b17023SJohn Marino 
2317e4b17023SJohn Marino   if (! DECL_P (exprx) || ! DECL_P (expry))
2318e4b17023SJohn Marino     return 0;
2319e4b17023SJohn Marino 
2320e4b17023SJohn Marino   /* With invalid code we can end up storing into the constant pool.
2321e4b17023SJohn Marino      Bail out to avoid ICEing when creating RTL for this.
2322e4b17023SJohn Marino      See gfortran.dg/lto/20091028-2_0.f90.  */
2323e4b17023SJohn Marino   if (TREE_CODE (exprx) == CONST_DECL
2324e4b17023SJohn Marino       || TREE_CODE (expry) == CONST_DECL)
2325e4b17023SJohn Marino     return 1;
2326e4b17023SJohn Marino 
2327e4b17023SJohn Marino   rtlx = DECL_RTL (exprx);
2328e4b17023SJohn Marino   rtly = DECL_RTL (expry);
2329e4b17023SJohn Marino 
2330e4b17023SJohn Marino   /* If either RTL is not a MEM, it must be a REG or CONCAT, meaning they
2331e4b17023SJohn Marino      can't overlap unless they are the same because we never reuse that part
2332e4b17023SJohn Marino      of the stack frame used for locals for spilled pseudos.  */
2333e4b17023SJohn Marino   if ((!MEM_P (rtlx) || !MEM_P (rtly))
2334e4b17023SJohn Marino       && ! rtx_equal_p (rtlx, rtly))
2335e4b17023SJohn Marino     return 1;
2336e4b17023SJohn Marino 
2337e4b17023SJohn Marino   /* If we have MEMs refering to different address spaces (which can
2338e4b17023SJohn Marino      potentially overlap), we cannot easily tell from the addresses
2339e4b17023SJohn Marino      whether the references overlap.  */
2340e4b17023SJohn Marino   if (MEM_P (rtlx) && MEM_P (rtly)
2341e4b17023SJohn Marino       && MEM_ADDR_SPACE (rtlx) != MEM_ADDR_SPACE (rtly))
2342e4b17023SJohn Marino     return 0;
2343e4b17023SJohn Marino 
2344e4b17023SJohn Marino   /* Get the base and offsets of both decls.  If either is a register, we
2345e4b17023SJohn Marino      know both are and are the same, so use that as the base.  The only
2346e4b17023SJohn Marino      we can avoid overlap is if we can deduce that they are nonoverlapping
2347e4b17023SJohn Marino      pieces of that decl, which is very rare.  */
2348e4b17023SJohn Marino   basex = MEM_P (rtlx) ? XEXP (rtlx, 0) : rtlx;
2349e4b17023SJohn Marino   if (GET_CODE (basex) == PLUS && CONST_INT_P (XEXP (basex, 1)))
2350e4b17023SJohn Marino     offsetx = INTVAL (XEXP (basex, 1)), basex = XEXP (basex, 0);
2351e4b17023SJohn Marino 
2352e4b17023SJohn Marino   basey = MEM_P (rtly) ? XEXP (rtly, 0) : rtly;
2353e4b17023SJohn Marino   if (GET_CODE (basey) == PLUS && CONST_INT_P (XEXP (basey, 1)))
2354e4b17023SJohn Marino     offsety = INTVAL (XEXP (basey, 1)), basey = XEXP (basey, 0);
2355e4b17023SJohn Marino 
2356e4b17023SJohn Marino   /* If the bases are different, we know they do not overlap if both
2357e4b17023SJohn Marino      are constants or if one is a constant and the other a pointer into the
2358e4b17023SJohn Marino      stack frame.  Otherwise a different base means we can't tell if they
2359e4b17023SJohn Marino      overlap or not.  */
2360e4b17023SJohn Marino   if (! rtx_equal_p (basex, basey))
2361e4b17023SJohn Marino     return ((CONSTANT_P (basex) && CONSTANT_P (basey))
2362e4b17023SJohn Marino 	    || (CONSTANT_P (basex) && REG_P (basey)
2363e4b17023SJohn Marino 		&& REGNO_PTR_FRAME_P (REGNO (basey)))
2364e4b17023SJohn Marino 	    || (CONSTANT_P (basey) && REG_P (basex)
2365e4b17023SJohn Marino 		&& REGNO_PTR_FRAME_P (REGNO (basex))));
2366e4b17023SJohn Marino 
2367e4b17023SJohn Marino   /* Offset based disambiguation not appropriate for loop invariant */
2368e4b17023SJohn Marino   if (loop_invariant)
2369e4b17023SJohn Marino     return 0;
2370e4b17023SJohn Marino 
2371e4b17023SJohn Marino   sizex = (!MEM_P (rtlx) ? (int) GET_MODE_SIZE (GET_MODE (rtlx))
2372e4b17023SJohn Marino 	   : MEM_SIZE_KNOWN_P (rtlx) ? MEM_SIZE (rtlx)
2373e4b17023SJohn Marino 	   : -1);
2374e4b17023SJohn Marino   sizey = (!MEM_P (rtly) ? (int) GET_MODE_SIZE (GET_MODE (rtly))
2375e4b17023SJohn Marino 	   : MEM_SIZE_KNOWN_P (rtly) ? MEM_SIZE (rtly)
2376e4b17023SJohn Marino 	   : -1);
2377e4b17023SJohn Marino 
2378e4b17023SJohn Marino   /* If we have an offset for either memref, it can update the values computed
2379e4b17023SJohn Marino      above.  */
2380e4b17023SJohn Marino   if (moffsetx_known_p)
2381e4b17023SJohn Marino     offsetx += moffsetx, sizex -= moffsetx;
2382e4b17023SJohn Marino   if (moffsety_known_p)
2383e4b17023SJohn Marino     offsety += moffsety, sizey -= moffsety;
2384e4b17023SJohn Marino 
2385e4b17023SJohn Marino   /* If a memref has both a size and an offset, we can use the smaller size.
2386e4b17023SJohn Marino      We can't do this if the offset isn't known because we must view this
2387e4b17023SJohn Marino      memref as being anywhere inside the DECL's MEM.  */
2388e4b17023SJohn Marino   if (MEM_SIZE_KNOWN_P (x) && moffsetx_known_p)
2389e4b17023SJohn Marino     sizex = MEM_SIZE (x);
2390e4b17023SJohn Marino   if (MEM_SIZE_KNOWN_P (y) && moffsety_known_p)
2391e4b17023SJohn Marino     sizey = MEM_SIZE (y);
2392e4b17023SJohn Marino 
2393e4b17023SJohn Marino   /* Put the values of the memref with the lower offset in X's values.  */
2394e4b17023SJohn Marino   if (offsetx > offsety)
2395e4b17023SJohn Marino     {
2396e4b17023SJohn Marino       tem = offsetx, offsetx = offsety, offsety = tem;
2397e4b17023SJohn Marino       tem = sizex, sizex = sizey, sizey = tem;
2398e4b17023SJohn Marino     }
2399e4b17023SJohn Marino 
2400e4b17023SJohn Marino   /* If we don't know the size of the lower-offset value, we can't tell
2401e4b17023SJohn Marino      if they conflict.  Otherwise, we do the test.  */
2402e4b17023SJohn Marino   return sizex >= 0 && offsety >= offsetx + sizex;
2403e4b17023SJohn Marino }
2404e4b17023SJohn Marino 
2405e4b17023SJohn Marino /* Helper for true_dependence and canon_true_dependence.
2406e4b17023SJohn Marino    Checks for true dependence: X is read after store in MEM takes place.
2407e4b17023SJohn Marino 
2408e4b17023SJohn Marino    If MEM_CANONICALIZED is FALSE, then X_ADDR and MEM_ADDR should be
2409e4b17023SJohn Marino    NULL_RTX, and the canonical addresses of MEM and X are both computed
2410e4b17023SJohn Marino    here.  If MEM_CANONICALIZED, then MEM must be already canonicalized.
2411e4b17023SJohn Marino 
2412e4b17023SJohn Marino    If X_ADDR is non-NULL, it is used in preference of XEXP (x, 0).
2413e4b17023SJohn Marino 
2414e4b17023SJohn Marino    Returns 1 if there is a true dependence, 0 otherwise.  */
2415e4b17023SJohn Marino 
2416e4b17023SJohn Marino static int
true_dependence_1(const_rtx mem,enum machine_mode mem_mode,rtx mem_addr,const_rtx x,rtx x_addr,bool mem_canonicalized)2417e4b17023SJohn Marino true_dependence_1 (const_rtx mem, enum machine_mode mem_mode, rtx mem_addr,
2418e4b17023SJohn Marino 		   const_rtx x, rtx x_addr, bool mem_canonicalized)
2419e4b17023SJohn Marino {
2420e4b17023SJohn Marino   rtx base;
2421e4b17023SJohn Marino   int ret;
2422e4b17023SJohn Marino 
2423e4b17023SJohn Marino   gcc_checking_assert (mem_canonicalized ? (mem_addr != NULL_RTX)
2424e4b17023SJohn Marino 		       : (mem_addr == NULL_RTX && x_addr == NULL_RTX));
2425e4b17023SJohn Marino 
2426e4b17023SJohn Marino   if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2427e4b17023SJohn Marino     return 1;
2428e4b17023SJohn Marino 
2429e4b17023SJohn Marino   /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2430e4b17023SJohn Marino      This is used in epilogue deallocation functions, and in cselib.  */
2431e4b17023SJohn Marino   if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH)
2432e4b17023SJohn Marino     return 1;
2433e4b17023SJohn Marino   if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH)
2434e4b17023SJohn Marino     return 1;
2435e4b17023SJohn Marino   if (MEM_ALIAS_SET (x) == ALIAS_SET_MEMORY_BARRIER
2436e4b17023SJohn Marino       || MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2437e4b17023SJohn Marino     return 1;
2438e4b17023SJohn Marino 
2439e4b17023SJohn Marino   /* Read-only memory is by definition never modified, and therefore can't
2440e4b17023SJohn Marino      conflict with anything.  We don't expect to find read-only set on MEM,
2441e4b17023SJohn Marino      but stupid user tricks can produce them, so don't die.  */
2442e4b17023SJohn Marino   if (MEM_READONLY_P (x))
2443e4b17023SJohn Marino     return 0;
2444e4b17023SJohn Marino 
2445e4b17023SJohn Marino   /* If we have MEMs refering to different address spaces (which can
2446e4b17023SJohn Marino      potentially overlap), we cannot easily tell from the addresses
2447e4b17023SJohn Marino      whether the references overlap.  */
2448e4b17023SJohn Marino   if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x))
2449e4b17023SJohn Marino     return 1;
2450e4b17023SJohn Marino 
2451e4b17023SJohn Marino   if (! mem_addr)
2452e4b17023SJohn Marino     {
2453e4b17023SJohn Marino       mem_addr = XEXP (mem, 0);
2454e4b17023SJohn Marino       if (mem_mode == VOIDmode)
2455e4b17023SJohn Marino 	mem_mode = GET_MODE (mem);
2456e4b17023SJohn Marino     }
2457e4b17023SJohn Marino 
2458e4b17023SJohn Marino   if (! x_addr)
2459e4b17023SJohn Marino     {
2460e4b17023SJohn Marino       x_addr = XEXP (x, 0);
2461e4b17023SJohn Marino       if (!((GET_CODE (x_addr) == VALUE
2462e4b17023SJohn Marino 	     && GET_CODE (mem_addr) != VALUE
2463e4b17023SJohn Marino 	     && reg_mentioned_p (x_addr, mem_addr))
2464e4b17023SJohn Marino 	    || (GET_CODE (x_addr) != VALUE
2465e4b17023SJohn Marino 		&& GET_CODE (mem_addr) == VALUE
2466e4b17023SJohn Marino 		&& reg_mentioned_p (mem_addr, x_addr))))
2467e4b17023SJohn Marino 	{
2468e4b17023SJohn Marino 	  x_addr = get_addr (x_addr);
2469e4b17023SJohn Marino 	  if (! mem_canonicalized)
2470e4b17023SJohn Marino 	    mem_addr = get_addr (mem_addr);
2471e4b17023SJohn Marino 	}
2472e4b17023SJohn Marino     }
2473e4b17023SJohn Marino 
2474e4b17023SJohn Marino   base = find_base_term (x_addr);
2475e4b17023SJohn Marino   if (base && (GET_CODE (base) == LABEL_REF
2476e4b17023SJohn Marino 	       || (GET_CODE (base) == SYMBOL_REF
2477e4b17023SJohn Marino 		   && CONSTANT_POOL_ADDRESS_P (base))))
2478e4b17023SJohn Marino     return 0;
2479e4b17023SJohn Marino 
2480e4b17023SJohn Marino   if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode))
2481e4b17023SJohn Marino     return 0;
2482e4b17023SJohn Marino 
2483e4b17023SJohn Marino   x_addr = canon_rtx (x_addr);
2484e4b17023SJohn Marino   if (!mem_canonicalized)
2485e4b17023SJohn Marino     mem_addr = canon_rtx (mem_addr);
2486e4b17023SJohn Marino 
2487e4b17023SJohn Marino   if ((ret = memrefs_conflict_p (GET_MODE_SIZE (mem_mode), mem_addr,
2488e4b17023SJohn Marino 				 SIZE_FOR_MODE (x), x_addr, 0)) != -1)
2489e4b17023SJohn Marino     return ret;
2490e4b17023SJohn Marino 
2491e4b17023SJohn Marino   if (DIFFERENT_ALIAS_SETS_P (x, mem))
2492e4b17023SJohn Marino     return 0;
2493e4b17023SJohn Marino 
2494e4b17023SJohn Marino   if (nonoverlapping_memrefs_p (mem, x, false))
2495e4b17023SJohn Marino     return 0;
2496e4b17023SJohn Marino 
2497e4b17023SJohn Marino   if (aliases_everything_p (x))
2498e4b17023SJohn Marino     return 1;
2499e4b17023SJohn Marino 
2500e4b17023SJohn Marino   /* We cannot use aliases_everything_p to test MEM, since we must look
2501e4b17023SJohn Marino      at MEM_ADDR, rather than XEXP (mem, 0).  */
2502e4b17023SJohn Marino   if (GET_CODE (mem_addr) == AND)
2503e4b17023SJohn Marino     return 1;
2504e4b17023SJohn Marino 
2505e4b17023SJohn Marino   /* ??? In true_dependence we also allow BLKmode to alias anything.  Why
2506e4b17023SJohn Marino      don't we do this in anti_dependence and output_dependence?  */
2507e4b17023SJohn Marino   if (mem_mode == BLKmode || GET_MODE (x) == BLKmode)
2508e4b17023SJohn Marino     return 1;
2509e4b17023SJohn Marino 
2510e4b17023SJohn Marino   return rtx_refs_may_alias_p (x, mem, true);
2511e4b17023SJohn Marino }
2512e4b17023SJohn Marino 
2513e4b17023SJohn Marino /* True dependence: X is read after store in MEM takes place.  */
2514e4b17023SJohn Marino 
2515e4b17023SJohn Marino int
true_dependence(const_rtx mem,enum machine_mode mem_mode,const_rtx x)2516e4b17023SJohn Marino true_dependence (const_rtx mem, enum machine_mode mem_mode, const_rtx x)
2517e4b17023SJohn Marino {
2518e4b17023SJohn Marino   return true_dependence_1 (mem, mem_mode, NULL_RTX,
2519e4b17023SJohn Marino 			    x, NULL_RTX, /*mem_canonicalized=*/false);
2520e4b17023SJohn Marino }
2521e4b17023SJohn Marino 
2522e4b17023SJohn Marino /* Canonical true dependence: X is read after store in MEM takes place.
2523e4b17023SJohn Marino    Variant of true_dependence which assumes MEM has already been
2524e4b17023SJohn Marino    canonicalized (hence we no longer do that here).
2525e4b17023SJohn Marino    The mem_addr argument has been added, since true_dependence_1 computed
2526e4b17023SJohn Marino    this value prior to canonicalizing.  */
2527e4b17023SJohn Marino 
2528e4b17023SJohn Marino int
canon_true_dependence(const_rtx mem,enum machine_mode mem_mode,rtx mem_addr,const_rtx x,rtx x_addr)2529e4b17023SJohn Marino canon_true_dependence (const_rtx mem, enum machine_mode mem_mode, rtx mem_addr,
2530e4b17023SJohn Marino 		       const_rtx x, rtx x_addr)
2531e4b17023SJohn Marino {
2532e4b17023SJohn Marino   return true_dependence_1 (mem, mem_mode, mem_addr,
2533e4b17023SJohn Marino 			    x, x_addr, /*mem_canonicalized=*/true);
2534e4b17023SJohn Marino }
2535e4b17023SJohn Marino 
2536e4b17023SJohn Marino /* Returns nonzero if a write to X might alias a previous read from
2537e4b17023SJohn Marino    (or, if WRITEP is nonzero, a write to) MEM.  */
2538e4b17023SJohn Marino 
2539e4b17023SJohn Marino static int
write_dependence_p(const_rtx mem,const_rtx x,int writep)2540e4b17023SJohn Marino write_dependence_p (const_rtx mem, const_rtx x, int writep)
2541e4b17023SJohn Marino {
2542e4b17023SJohn Marino   rtx x_addr, mem_addr;
2543e4b17023SJohn Marino   rtx base;
2544e4b17023SJohn Marino   int ret;
2545e4b17023SJohn Marino 
2546e4b17023SJohn Marino   if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2547e4b17023SJohn Marino     return 1;
2548e4b17023SJohn Marino 
2549e4b17023SJohn Marino   /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2550e4b17023SJohn Marino      This is used in epilogue deallocation functions.  */
2551e4b17023SJohn Marino   if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH)
2552e4b17023SJohn Marino     return 1;
2553e4b17023SJohn Marino   if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH)
2554e4b17023SJohn Marino     return 1;
2555e4b17023SJohn Marino   if (MEM_ALIAS_SET (x) == ALIAS_SET_MEMORY_BARRIER
2556e4b17023SJohn Marino       || MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2557e4b17023SJohn Marino     return 1;
2558e4b17023SJohn Marino 
2559e4b17023SJohn Marino   /* A read from read-only memory can't conflict with read-write memory.  */
2560e4b17023SJohn Marino   if (!writep && MEM_READONLY_P (mem))
2561e4b17023SJohn Marino     return 0;
2562e4b17023SJohn Marino 
2563e4b17023SJohn Marino   /* If we have MEMs refering to different address spaces (which can
2564e4b17023SJohn Marino      potentially overlap), we cannot easily tell from the addresses
2565e4b17023SJohn Marino      whether the references overlap.  */
2566e4b17023SJohn Marino   if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x))
2567e4b17023SJohn Marino     return 1;
2568e4b17023SJohn Marino 
2569e4b17023SJohn Marino   x_addr = XEXP (x, 0);
2570e4b17023SJohn Marino   mem_addr = XEXP (mem, 0);
2571e4b17023SJohn Marino   if (!((GET_CODE (x_addr) == VALUE
2572e4b17023SJohn Marino 	 && GET_CODE (mem_addr) != VALUE
2573e4b17023SJohn Marino 	 && reg_mentioned_p (x_addr, mem_addr))
2574e4b17023SJohn Marino 	|| (GET_CODE (x_addr) != VALUE
2575e4b17023SJohn Marino 	    && GET_CODE (mem_addr) == VALUE
2576e4b17023SJohn Marino 	    && reg_mentioned_p (mem_addr, x_addr))))
2577e4b17023SJohn Marino     {
2578e4b17023SJohn Marino       x_addr = get_addr (x_addr);
2579e4b17023SJohn Marino       mem_addr = get_addr (mem_addr);
2580e4b17023SJohn Marino     }
2581e4b17023SJohn Marino 
2582e4b17023SJohn Marino   if (! writep)
2583e4b17023SJohn Marino     {
2584e4b17023SJohn Marino       base = find_base_term (mem_addr);
2585e4b17023SJohn Marino       if (base && (GET_CODE (base) == LABEL_REF
2586e4b17023SJohn Marino 		   || (GET_CODE (base) == SYMBOL_REF
2587e4b17023SJohn Marino 		       && CONSTANT_POOL_ADDRESS_P (base))))
2588e4b17023SJohn Marino 	return 0;
2589e4b17023SJohn Marino     }
2590e4b17023SJohn Marino 
2591e4b17023SJohn Marino   if (! base_alias_check (x_addr, mem_addr, GET_MODE (x),
2592e4b17023SJohn Marino 			  GET_MODE (mem)))
2593e4b17023SJohn Marino     return 0;
2594e4b17023SJohn Marino 
2595e4b17023SJohn Marino   x_addr = canon_rtx (x_addr);
2596e4b17023SJohn Marino   mem_addr = canon_rtx (mem_addr);
2597e4b17023SJohn Marino 
2598e4b17023SJohn Marino   if ((ret = memrefs_conflict_p (SIZE_FOR_MODE (mem), mem_addr,
2599e4b17023SJohn Marino 				 SIZE_FOR_MODE (x), x_addr, 0)) != -1)
2600e4b17023SJohn Marino     return ret;
2601e4b17023SJohn Marino 
2602e4b17023SJohn Marino   if (nonoverlapping_memrefs_p (x, mem, false))
2603e4b17023SJohn Marino     return 0;
2604e4b17023SJohn Marino 
2605e4b17023SJohn Marino   return rtx_refs_may_alias_p (x, mem, false);
2606e4b17023SJohn Marino }
2607e4b17023SJohn Marino 
2608e4b17023SJohn Marino /* Anti dependence: X is written after read in MEM takes place.  */
2609e4b17023SJohn Marino 
2610e4b17023SJohn Marino int
anti_dependence(const_rtx mem,const_rtx x)2611e4b17023SJohn Marino anti_dependence (const_rtx mem, const_rtx x)
2612e4b17023SJohn Marino {
2613e4b17023SJohn Marino   return write_dependence_p (mem, x, /*writep=*/0);
2614e4b17023SJohn Marino }
2615e4b17023SJohn Marino 
2616e4b17023SJohn Marino /* Output dependence: X is written after store in MEM takes place.  */
2617e4b17023SJohn Marino 
2618e4b17023SJohn Marino int
output_dependence(const_rtx mem,const_rtx x)2619e4b17023SJohn Marino output_dependence (const_rtx mem, const_rtx x)
2620e4b17023SJohn Marino {
2621e4b17023SJohn Marino   return write_dependence_p (mem, x, /*writep=*/1);
2622e4b17023SJohn Marino }
2623e4b17023SJohn Marino 
2624e4b17023SJohn Marino 
2625e4b17023SJohn Marino 
2626e4b17023SJohn Marino /* Check whether X may be aliased with MEM.  Don't do offset-based
2627e4b17023SJohn Marino   memory disambiguation & TBAA.  */
2628e4b17023SJohn Marino int
may_alias_p(const_rtx mem,const_rtx x)2629e4b17023SJohn Marino may_alias_p (const_rtx mem, const_rtx x)
2630e4b17023SJohn Marino {
2631e4b17023SJohn Marino   rtx x_addr, mem_addr;
2632e4b17023SJohn Marino 
2633e4b17023SJohn Marino   if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2634e4b17023SJohn Marino     return 1;
2635e4b17023SJohn Marino 
2636e4b17023SJohn Marino   /* ??? In true_dependence we also allow BLKmode to alias anything. */
2637e4b17023SJohn Marino   if (GET_MODE (mem) == BLKmode || GET_MODE (x) == BLKmode)
2638e4b17023SJohn Marino     return 1;
2639e4b17023SJohn Marino 
2640e4b17023SJohn Marino   if (MEM_ALIAS_SET (x) == ALIAS_SET_MEMORY_BARRIER
2641e4b17023SJohn Marino       || MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2642e4b17023SJohn Marino     return 1;
2643e4b17023SJohn Marino 
2644e4b17023SJohn Marino   /* Read-only memory is by definition never modified, and therefore can't
2645e4b17023SJohn Marino      conflict with anything.  We don't expect to find read-only set on MEM,
2646e4b17023SJohn Marino      but stupid user tricks can produce them, so don't die.  */
2647e4b17023SJohn Marino   if (MEM_READONLY_P (x))
2648e4b17023SJohn Marino     return 0;
2649e4b17023SJohn Marino 
2650e4b17023SJohn Marino   /* If we have MEMs refering to different address spaces (which can
2651e4b17023SJohn Marino      potentially overlap), we cannot easily tell from the addresses
2652e4b17023SJohn Marino      whether the references overlap.  */
2653e4b17023SJohn Marino   if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x))
2654e4b17023SJohn Marino     return 1;
2655e4b17023SJohn Marino 
2656e4b17023SJohn Marino   x_addr = XEXP (x, 0);
2657e4b17023SJohn Marino   mem_addr = XEXP (mem, 0);
2658e4b17023SJohn Marino   if (!((GET_CODE (x_addr) == VALUE
2659e4b17023SJohn Marino 	 && GET_CODE (mem_addr) != VALUE
2660e4b17023SJohn Marino 	 && reg_mentioned_p (x_addr, mem_addr))
2661e4b17023SJohn Marino 	|| (GET_CODE (x_addr) != VALUE
2662e4b17023SJohn Marino 	    && GET_CODE (mem_addr) == VALUE
2663e4b17023SJohn Marino 	    && reg_mentioned_p (mem_addr, x_addr))))
2664e4b17023SJohn Marino     {
2665e4b17023SJohn Marino       x_addr = get_addr (x_addr);
2666e4b17023SJohn Marino       mem_addr = get_addr (mem_addr);
2667e4b17023SJohn Marino     }
2668e4b17023SJohn Marino 
2669e4b17023SJohn Marino   if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), GET_MODE (mem_addr)))
2670e4b17023SJohn Marino     return 0;
2671e4b17023SJohn Marino 
2672e4b17023SJohn Marino   x_addr = canon_rtx (x_addr);
2673e4b17023SJohn Marino   mem_addr = canon_rtx (mem_addr);
2674e4b17023SJohn Marino 
2675e4b17023SJohn Marino   if (nonoverlapping_memrefs_p (mem, x, true))
2676e4b17023SJohn Marino     return 0;
2677e4b17023SJohn Marino 
2678e4b17023SJohn Marino   if (aliases_everything_p (x))
2679e4b17023SJohn Marino     return 1;
2680e4b17023SJohn Marino 
2681e4b17023SJohn Marino   /* We cannot use aliases_everything_p to test MEM, since we must look
2682e4b17023SJohn Marino      at MEM_ADDR, rather than XEXP (mem, 0).  */
2683e4b17023SJohn Marino   if (GET_CODE (mem_addr) == AND)
2684e4b17023SJohn Marino     return 1;
2685e4b17023SJohn Marino 
2686e4b17023SJohn Marino   /* TBAA not valid for loop_invarint */
2687e4b17023SJohn Marino   return rtx_refs_may_alias_p (x, mem, false);
2688e4b17023SJohn Marino }
2689e4b17023SJohn Marino 
2690e4b17023SJohn Marino void
init_alias_target(void)2691e4b17023SJohn Marino init_alias_target (void)
2692e4b17023SJohn Marino {
2693e4b17023SJohn Marino   int i;
2694e4b17023SJohn Marino 
2695e4b17023SJohn Marino   memset (static_reg_base_value, 0, sizeof static_reg_base_value);
2696e4b17023SJohn Marino 
2697e4b17023SJohn Marino   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2698e4b17023SJohn Marino     /* Check whether this register can hold an incoming pointer
2699e4b17023SJohn Marino        argument.  FUNCTION_ARG_REGNO_P tests outgoing register
2700e4b17023SJohn Marino        numbers, so translate if necessary due to register windows.  */
2701e4b17023SJohn Marino     if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (i))
2702e4b17023SJohn Marino 	&& HARD_REGNO_MODE_OK (i, Pmode))
2703e4b17023SJohn Marino       static_reg_base_value[i]
2704e4b17023SJohn Marino 	= gen_rtx_ADDRESS (VOIDmode, gen_rtx_REG (Pmode, i));
2705e4b17023SJohn Marino 
2706e4b17023SJohn Marino   static_reg_base_value[STACK_POINTER_REGNUM]
2707e4b17023SJohn Marino     = gen_rtx_ADDRESS (Pmode, stack_pointer_rtx);
2708e4b17023SJohn Marino   static_reg_base_value[ARG_POINTER_REGNUM]
2709e4b17023SJohn Marino     = gen_rtx_ADDRESS (Pmode, arg_pointer_rtx);
2710e4b17023SJohn Marino   static_reg_base_value[FRAME_POINTER_REGNUM]
2711e4b17023SJohn Marino     = gen_rtx_ADDRESS (Pmode, frame_pointer_rtx);
2712e4b17023SJohn Marino #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
2713e4b17023SJohn Marino   static_reg_base_value[HARD_FRAME_POINTER_REGNUM]
2714e4b17023SJohn Marino     = gen_rtx_ADDRESS (Pmode, hard_frame_pointer_rtx);
2715e4b17023SJohn Marino #endif
2716e4b17023SJohn Marino }
2717e4b17023SJohn Marino 
2718e4b17023SJohn Marino /* Set MEMORY_MODIFIED when X modifies DATA (that is assumed
2719e4b17023SJohn Marino    to be memory reference.  */
2720e4b17023SJohn Marino static bool memory_modified;
2721e4b17023SJohn Marino static void
memory_modified_1(rtx x,const_rtx pat ATTRIBUTE_UNUSED,void * data)2722e4b17023SJohn Marino memory_modified_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
2723e4b17023SJohn Marino {
2724e4b17023SJohn Marino   if (MEM_P (x))
2725e4b17023SJohn Marino     {
2726e4b17023SJohn Marino       if (anti_dependence (x, (const_rtx)data) || output_dependence (x, (const_rtx)data))
2727e4b17023SJohn Marino 	memory_modified = true;
2728e4b17023SJohn Marino     }
2729e4b17023SJohn Marino }
2730e4b17023SJohn Marino 
2731e4b17023SJohn Marino 
2732e4b17023SJohn Marino /* Return true when INSN possibly modify memory contents of MEM
2733e4b17023SJohn Marino    (i.e. address can be modified).  */
2734e4b17023SJohn Marino bool
memory_modified_in_insn_p(const_rtx mem,const_rtx insn)2735e4b17023SJohn Marino memory_modified_in_insn_p (const_rtx mem, const_rtx insn)
2736e4b17023SJohn Marino {
2737e4b17023SJohn Marino   if (!INSN_P (insn))
2738e4b17023SJohn Marino     return false;
2739e4b17023SJohn Marino   memory_modified = false;
2740e4b17023SJohn Marino   note_stores (PATTERN (insn), memory_modified_1, CONST_CAST_RTX(mem));
2741e4b17023SJohn Marino   return memory_modified;
2742e4b17023SJohn Marino }
2743e4b17023SJohn Marino 
2744e4b17023SJohn Marino /* Initialize the aliasing machinery.  Initialize the REG_KNOWN_VALUE
2745e4b17023SJohn Marino    array.  */
2746e4b17023SJohn Marino 
2747e4b17023SJohn Marino void
init_alias_analysis(void)2748e4b17023SJohn Marino init_alias_analysis (void)
2749e4b17023SJohn Marino {
2750e4b17023SJohn Marino   unsigned int maxreg = max_reg_num ();
2751e4b17023SJohn Marino   int changed, pass;
2752e4b17023SJohn Marino   int i;
2753e4b17023SJohn Marino   unsigned int ui;
2754e4b17023SJohn Marino   rtx insn;
2755e4b17023SJohn Marino 
2756e4b17023SJohn Marino   timevar_push (TV_ALIAS_ANALYSIS);
2757e4b17023SJohn Marino 
2758e4b17023SJohn Marino   reg_known_value_size = maxreg - FIRST_PSEUDO_REGISTER;
2759e4b17023SJohn Marino   reg_known_value = ggc_alloc_cleared_vec_rtx (reg_known_value_size);
2760e4b17023SJohn Marino   reg_known_equiv_p = XCNEWVEC (bool, reg_known_value_size);
2761e4b17023SJohn Marino 
2762e4b17023SJohn Marino   /* If we have memory allocated from the previous run, use it.  */
2763e4b17023SJohn Marino   if (old_reg_base_value)
2764e4b17023SJohn Marino     reg_base_value = old_reg_base_value;
2765e4b17023SJohn Marino 
2766e4b17023SJohn Marino   if (reg_base_value)
2767e4b17023SJohn Marino     VEC_truncate (rtx, reg_base_value, 0);
2768e4b17023SJohn Marino 
2769e4b17023SJohn Marino   VEC_safe_grow_cleared (rtx, gc, reg_base_value, maxreg);
2770e4b17023SJohn Marino 
2771e4b17023SJohn Marino   new_reg_base_value = XNEWVEC (rtx, maxreg);
2772e4b17023SJohn Marino   reg_seen = XNEWVEC (char, maxreg);
2773e4b17023SJohn Marino 
2774e4b17023SJohn Marino   /* The basic idea is that each pass through this loop will use the
2775e4b17023SJohn Marino      "constant" information from the previous pass to propagate alias
2776e4b17023SJohn Marino      information through another level of assignments.
2777e4b17023SJohn Marino 
2778e4b17023SJohn Marino      This could get expensive if the assignment chains are long.  Maybe
2779e4b17023SJohn Marino      we should throttle the number of iterations, possibly based on
2780e4b17023SJohn Marino      the optimization level or flag_expensive_optimizations.
2781e4b17023SJohn Marino 
2782e4b17023SJohn Marino      We could propagate more information in the first pass by making use
2783e4b17023SJohn Marino      of DF_REG_DEF_COUNT to determine immediately that the alias information
2784e4b17023SJohn Marino      for a pseudo is "constant".
2785e4b17023SJohn Marino 
2786e4b17023SJohn Marino      A program with an uninitialized variable can cause an infinite loop
2787e4b17023SJohn Marino      here.  Instead of doing a full dataflow analysis to detect such problems
2788e4b17023SJohn Marino      we just cap the number of iterations for the loop.
2789e4b17023SJohn Marino 
2790e4b17023SJohn Marino      The state of the arrays for the set chain in question does not matter
2791e4b17023SJohn Marino      since the program has undefined behavior.  */
2792e4b17023SJohn Marino 
2793e4b17023SJohn Marino   pass = 0;
2794e4b17023SJohn Marino   do
2795e4b17023SJohn Marino     {
2796e4b17023SJohn Marino       /* Assume nothing will change this iteration of the loop.  */
2797e4b17023SJohn Marino       changed = 0;
2798e4b17023SJohn Marino 
2799e4b17023SJohn Marino       /* We want to assign the same IDs each iteration of this loop, so
2800e4b17023SJohn Marino 	 start counting from zero each iteration of the loop.  */
2801e4b17023SJohn Marino       unique_id = 0;
2802e4b17023SJohn Marino 
2803e4b17023SJohn Marino       /* We're at the start of the function each iteration through the
2804e4b17023SJohn Marino 	 loop, so we're copying arguments.  */
2805e4b17023SJohn Marino       copying_arguments = true;
2806e4b17023SJohn Marino 
2807e4b17023SJohn Marino       /* Wipe the potential alias information clean for this pass.  */
2808e4b17023SJohn Marino       memset (new_reg_base_value, 0, maxreg * sizeof (rtx));
2809e4b17023SJohn Marino 
2810e4b17023SJohn Marino       /* Wipe the reg_seen array clean.  */
2811e4b17023SJohn Marino       memset (reg_seen, 0, maxreg);
2812e4b17023SJohn Marino 
2813*95d28233SJohn Marino       /* Initialize the alias information for this pass.  */
2814*95d28233SJohn Marino       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2815*95d28233SJohn Marino 	if (static_reg_base_value[i])
2816*95d28233SJohn Marino 	  {
2817*95d28233SJohn Marino 	    new_reg_base_value[i] = static_reg_base_value[i];
2818*95d28233SJohn Marino 	    reg_seen[i] = 1;
2819*95d28233SJohn Marino 	  }
2820e4b17023SJohn Marino 
2821e4b17023SJohn Marino       /* Walk the insns adding values to the new_reg_base_value array.  */
2822e4b17023SJohn Marino       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2823e4b17023SJohn Marino 	{
2824e4b17023SJohn Marino 	  if (INSN_P (insn))
2825e4b17023SJohn Marino 	    {
2826e4b17023SJohn Marino 	      rtx note, set;
2827e4b17023SJohn Marino 
2828e4b17023SJohn Marino #if defined (HAVE_prologue) || defined (HAVE_epilogue)
2829e4b17023SJohn Marino 	      /* The prologue/epilogue insns are not threaded onto the
2830e4b17023SJohn Marino 		 insn chain until after reload has completed.  Thus,
2831e4b17023SJohn Marino 		 there is no sense wasting time checking if INSN is in
2832e4b17023SJohn Marino 		 the prologue/epilogue until after reload has completed.  */
2833e4b17023SJohn Marino 	      if (reload_completed
2834e4b17023SJohn Marino 		  && prologue_epilogue_contains (insn))
2835e4b17023SJohn Marino 		continue;
2836e4b17023SJohn Marino #endif
2837e4b17023SJohn Marino 
2838e4b17023SJohn Marino 	      /* If this insn has a noalias note, process it,  Otherwise,
2839e4b17023SJohn Marino 		 scan for sets.  A simple set will have no side effects
2840e4b17023SJohn Marino 		 which could change the base value of any other register.  */
2841e4b17023SJohn Marino 
2842e4b17023SJohn Marino 	      if (GET_CODE (PATTERN (insn)) == SET
2843e4b17023SJohn Marino 		  && REG_NOTES (insn) != 0
2844e4b17023SJohn Marino 		  && find_reg_note (insn, REG_NOALIAS, NULL_RTX))
2845e4b17023SJohn Marino 		record_set (SET_DEST (PATTERN (insn)), NULL_RTX, NULL);
2846e4b17023SJohn Marino 	      else
2847e4b17023SJohn Marino 		note_stores (PATTERN (insn), record_set, NULL);
2848e4b17023SJohn Marino 
2849e4b17023SJohn Marino 	      set = single_set (insn);
2850e4b17023SJohn Marino 
2851e4b17023SJohn Marino 	      if (set != 0
2852e4b17023SJohn Marino 		  && REG_P (SET_DEST (set))
2853e4b17023SJohn Marino 		  && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER)
2854e4b17023SJohn Marino 		{
2855e4b17023SJohn Marino 		  unsigned int regno = REGNO (SET_DEST (set));
2856e4b17023SJohn Marino 		  rtx src = SET_SRC (set);
2857e4b17023SJohn Marino 		  rtx t;
2858e4b17023SJohn Marino 
2859e4b17023SJohn Marino 		  note = find_reg_equal_equiv_note (insn);
2860e4b17023SJohn Marino 		  if (note && REG_NOTE_KIND (note) == REG_EQUAL
2861e4b17023SJohn Marino 		      && DF_REG_DEF_COUNT (regno) != 1)
2862e4b17023SJohn Marino 		    note = NULL_RTX;
2863e4b17023SJohn Marino 
2864e4b17023SJohn Marino 		  if (note != NULL_RTX
2865e4b17023SJohn Marino 		      && GET_CODE (XEXP (note, 0)) != EXPR_LIST
2866e4b17023SJohn Marino 		      && ! rtx_varies_p (XEXP (note, 0), 1)
2867e4b17023SJohn Marino 		      && ! reg_overlap_mentioned_p (SET_DEST (set),
2868e4b17023SJohn Marino 						    XEXP (note, 0)))
2869e4b17023SJohn Marino 		    {
2870e4b17023SJohn Marino 		      set_reg_known_value (regno, XEXP (note, 0));
2871e4b17023SJohn Marino 		      set_reg_known_equiv_p (regno,
2872e4b17023SJohn Marino 			REG_NOTE_KIND (note) == REG_EQUIV);
2873e4b17023SJohn Marino 		    }
2874e4b17023SJohn Marino 		  else if (DF_REG_DEF_COUNT (regno) == 1
2875e4b17023SJohn Marino 			   && GET_CODE (src) == PLUS
2876e4b17023SJohn Marino 			   && REG_P (XEXP (src, 0))
2877e4b17023SJohn Marino 			   && (t = get_reg_known_value (REGNO (XEXP (src, 0))))
2878e4b17023SJohn Marino 			   && CONST_INT_P (XEXP (src, 1)))
2879e4b17023SJohn Marino 		    {
2880e4b17023SJohn Marino 		      t = plus_constant (t, INTVAL (XEXP (src, 1)));
2881e4b17023SJohn Marino 		      set_reg_known_value (regno, t);
2882e4b17023SJohn Marino 		      set_reg_known_equiv_p (regno, 0);
2883e4b17023SJohn Marino 		    }
2884e4b17023SJohn Marino 		  else if (DF_REG_DEF_COUNT (regno) == 1
2885e4b17023SJohn Marino 			   && ! rtx_varies_p (src, 1))
2886e4b17023SJohn Marino 		    {
2887e4b17023SJohn Marino 		      set_reg_known_value (regno, src);
2888e4b17023SJohn Marino 		      set_reg_known_equiv_p (regno, 0);
2889e4b17023SJohn Marino 		    }
2890e4b17023SJohn Marino 		}
2891e4b17023SJohn Marino 	    }
2892e4b17023SJohn Marino 	  else if (NOTE_P (insn)
2893e4b17023SJohn Marino 		   && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
2894e4b17023SJohn Marino 	    copying_arguments = false;
2895e4b17023SJohn Marino 	}
2896e4b17023SJohn Marino 
2897e4b17023SJohn Marino       /* Now propagate values from new_reg_base_value to reg_base_value.  */
2898e4b17023SJohn Marino       gcc_assert (maxreg == (unsigned int) max_reg_num ());
2899e4b17023SJohn Marino 
2900e4b17023SJohn Marino       for (ui = 0; ui < maxreg; ui++)
2901e4b17023SJohn Marino 	{
2902e4b17023SJohn Marino 	  if (new_reg_base_value[ui]
2903e4b17023SJohn Marino 	      && new_reg_base_value[ui] != VEC_index (rtx, reg_base_value, ui)
2904e4b17023SJohn Marino 	      && ! rtx_equal_p (new_reg_base_value[ui],
2905e4b17023SJohn Marino 				VEC_index (rtx, reg_base_value, ui)))
2906e4b17023SJohn Marino 	    {
2907e4b17023SJohn Marino 	      VEC_replace (rtx, reg_base_value, ui, new_reg_base_value[ui]);
2908e4b17023SJohn Marino 	      changed = 1;
2909e4b17023SJohn Marino 	    }
2910e4b17023SJohn Marino 	}
2911e4b17023SJohn Marino     }
2912e4b17023SJohn Marino   while (changed && ++pass < MAX_ALIAS_LOOP_PASSES);
2913e4b17023SJohn Marino 
2914e4b17023SJohn Marino   /* Fill in the remaining entries.  */
2915e4b17023SJohn Marino   for (i = 0; i < (int)reg_known_value_size; i++)
2916e4b17023SJohn Marino     if (reg_known_value[i] == 0)
2917e4b17023SJohn Marino       reg_known_value[i] = regno_reg_rtx[i + FIRST_PSEUDO_REGISTER];
2918e4b17023SJohn Marino 
2919e4b17023SJohn Marino   /* Clean up.  */
2920e4b17023SJohn Marino   free (new_reg_base_value);
2921e4b17023SJohn Marino   new_reg_base_value = 0;
2922e4b17023SJohn Marino   free (reg_seen);
2923e4b17023SJohn Marino   reg_seen = 0;
2924e4b17023SJohn Marino   timevar_pop (TV_ALIAS_ANALYSIS);
2925e4b17023SJohn Marino }
2926e4b17023SJohn Marino 
2927e4b17023SJohn Marino /* Equate REG_BASE_VALUE (reg1) to REG_BASE_VALUE (reg2).
2928e4b17023SJohn Marino    Special API for var-tracking pass purposes.  */
2929e4b17023SJohn Marino 
2930e4b17023SJohn Marino void
vt_equate_reg_base_value(const_rtx reg1,const_rtx reg2)2931e4b17023SJohn Marino vt_equate_reg_base_value (const_rtx reg1, const_rtx reg2)
2932e4b17023SJohn Marino {
2933e4b17023SJohn Marino   VEC_replace (rtx, reg_base_value, REGNO (reg1), REG_BASE_VALUE (reg2));
2934e4b17023SJohn Marino }
2935e4b17023SJohn Marino 
2936e4b17023SJohn Marino void
end_alias_analysis(void)2937e4b17023SJohn Marino end_alias_analysis (void)
2938e4b17023SJohn Marino {
2939e4b17023SJohn Marino   old_reg_base_value = reg_base_value;
2940e4b17023SJohn Marino   ggc_free (reg_known_value);
2941e4b17023SJohn Marino   reg_known_value = 0;
2942e4b17023SJohn Marino   reg_known_value_size = 0;
2943e4b17023SJohn Marino   free (reg_known_equiv_p);
2944e4b17023SJohn Marino   reg_known_equiv_p = 0;
2945e4b17023SJohn Marino }
2946e4b17023SJohn Marino 
2947e4b17023SJohn Marino #include "gt-alias.h"
2948