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