comparison gcc/tree-ssa-alias.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
23 #include "system.h" 23 #include "system.h"
24 #include "coretypes.h" 24 #include "coretypes.h"
25 #include "tm.h" 25 #include "tm.h"
26 #include "tree.h" 26 #include "tree.h"
27 #include "tm_p.h" 27 #include "tm_p.h"
28 #include "target.h"
28 #include "basic-block.h" 29 #include "basic-block.h"
29 #include "timevar.h" 30 #include "timevar.h"
30 #include "expr.h"
31 #include "ggc.h" 31 #include "ggc.h"
32 #include "langhooks.h" 32 #include "langhooks.h"
33 #include "flags.h" 33 #include "flags.h"
34 #include "function.h" 34 #include "function.h"
35 #include "diagnostic.h"
36 #include "tree-pretty-print.h" 35 #include "tree-pretty-print.h"
37 #include "tree-dump.h" 36 #include "tree-dump.h"
38 #include "gimple.h" 37 #include "gimple.h"
39 #include "tree-flow.h" 38 #include "tree-flow.h"
40 #include "tree-inline.h" 39 #include "tree-inline.h"
165 static bool 164 static bool
166 ptr_deref_may_alias_decl_p (tree ptr, tree decl) 165 ptr_deref_may_alias_decl_p (tree ptr, tree decl)
167 { 166 {
168 struct ptr_info_def *pi; 167 struct ptr_info_def *pi;
169 168
170 gcc_assert ((TREE_CODE (ptr) == SSA_NAME 169 /* Conversions are irrelevant for points-to information and
171 || TREE_CODE (ptr) == ADDR_EXPR 170 data-dependence analysis can feed us those. */
172 || TREE_CODE (ptr) == INTEGER_CST) 171 STRIP_NOPS (ptr);
173 && (TREE_CODE (decl) == VAR_DECL 172
174 || TREE_CODE (decl) == PARM_DECL 173 /* Anything we do not explicilty handle aliases. */
175 || TREE_CODE (decl) == RESULT_DECL)); 174 if ((TREE_CODE (ptr) != SSA_NAME
176 175 && TREE_CODE (ptr) != ADDR_EXPR
177 /* Non-aliased variables can not be pointed to. */ 176 && TREE_CODE (ptr) != POINTER_PLUS_EXPR)
178 if (!may_be_aliased (decl)) 177 || !POINTER_TYPE_P (TREE_TYPE (ptr))
179 return false; 178 || (TREE_CODE (decl) != VAR_DECL
179 && TREE_CODE (decl) != PARM_DECL
180 && TREE_CODE (decl) != RESULT_DECL))
181 return true;
182
183 /* Disregard pointer offsetting. */
184 if (TREE_CODE (ptr) == POINTER_PLUS_EXPR)
185 {
186 do
187 {
188 ptr = TREE_OPERAND (ptr, 0);
189 }
190 while (TREE_CODE (ptr) == POINTER_PLUS_EXPR);
191 return ptr_deref_may_alias_decl_p (ptr, decl);
192 }
180 193
181 /* ADDR_EXPR pointers either just offset another pointer or directly 194 /* ADDR_EXPR pointers either just offset another pointer or directly
182 specify the pointed-to set. */ 195 specify the pointed-to set. */
183 if (TREE_CODE (ptr) == ADDR_EXPR) 196 if (TREE_CODE (ptr) == ADDR_EXPR)
184 { 197 {
185 tree base = get_base_address (TREE_OPERAND (ptr, 0)); 198 tree base = get_base_address (TREE_OPERAND (ptr, 0));
186 if (base 199 if (base
187 && INDIRECT_REF_P (base)) 200 && (INDIRECT_REF_P (base)
201 || TREE_CODE (base) == MEM_REF))
188 ptr = TREE_OPERAND (base, 0); 202 ptr = TREE_OPERAND (base, 0);
189 else if (base 203 else if (base
190 && SSA_VAR_P (base)) 204 && SSA_VAR_P (base))
191 return base == decl; 205 return base == decl;
192 else if (base 206 else if (base
194 return false; 208 return false;
195 else 209 else
196 return true; 210 return true;
197 } 211 }
198 212
199 /* We can end up with dereferencing constant pointers. 213 /* Non-aliased variables can not be pointed to. */
200 Just bail out in this case. */ 214 if (!may_be_aliased (decl))
201 if (TREE_CODE (ptr) == INTEGER_CST) 215 return false;
202 return true;
203 216
204 /* If we do not have useful points-to information for this pointer 217 /* If we do not have useful points-to information for this pointer
205 we cannot disambiguate anything else. */ 218 we cannot disambiguate anything else. */
206 pi = SSA_NAME_PTR_INFO (ptr); 219 pi = SSA_NAME_PTR_INFO (ptr);
207 if (!pi) 220 if (!pi)
220 233
221 /* Return true if dereferenced PTR1 and PTR2 may alias. 234 /* Return true if dereferenced PTR1 and PTR2 may alias.
222 The caller is responsible for applying TBAA to see if accesses 235 The caller is responsible for applying TBAA to see if accesses
223 through PTR1 and PTR2 may conflict at all. */ 236 through PTR1 and PTR2 may conflict at all. */
224 237
225 static bool 238 bool
226 ptr_derefs_may_alias_p (tree ptr1, tree ptr2) 239 ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
227 { 240 {
228 struct ptr_info_def *pi1, *pi2; 241 struct ptr_info_def *pi1, *pi2;
229 242
230 gcc_assert ((TREE_CODE (ptr1) == SSA_NAME 243 /* Conversions are irrelevant for points-to information and
231 || TREE_CODE (ptr1) == ADDR_EXPR 244 data-dependence analysis can feed us those. */
232 || TREE_CODE (ptr1) == INTEGER_CST) 245 STRIP_NOPS (ptr1);
233 && (TREE_CODE (ptr2) == SSA_NAME 246 STRIP_NOPS (ptr2);
234 || TREE_CODE (ptr2) == ADDR_EXPR 247
235 || TREE_CODE (ptr2) == INTEGER_CST)); 248 /* Anything we do not explicilty handle aliases. */
249 if ((TREE_CODE (ptr1) != SSA_NAME
250 && TREE_CODE (ptr1) != ADDR_EXPR
251 && TREE_CODE (ptr1) != POINTER_PLUS_EXPR)
252 || (TREE_CODE (ptr2) != SSA_NAME
253 && TREE_CODE (ptr2) != ADDR_EXPR
254 && TREE_CODE (ptr2) != POINTER_PLUS_EXPR)
255 || !POINTER_TYPE_P (TREE_TYPE (ptr1))
256 || !POINTER_TYPE_P (TREE_TYPE (ptr2)))
257 return true;
258
259 /* Disregard pointer offsetting. */
260 if (TREE_CODE (ptr1) == POINTER_PLUS_EXPR)
261 {
262 do
263 {
264 ptr1 = TREE_OPERAND (ptr1, 0);
265 }
266 while (TREE_CODE (ptr1) == POINTER_PLUS_EXPR);
267 return ptr_derefs_may_alias_p (ptr1, ptr2);
268 }
269 if (TREE_CODE (ptr2) == POINTER_PLUS_EXPR)
270 {
271 do
272 {
273 ptr2 = TREE_OPERAND (ptr2, 0);
274 }
275 while (TREE_CODE (ptr2) == POINTER_PLUS_EXPR);
276 return ptr_derefs_may_alias_p (ptr1, ptr2);
277 }
236 278
237 /* ADDR_EXPR pointers either just offset another pointer or directly 279 /* ADDR_EXPR pointers either just offset another pointer or directly
238 specify the pointed-to set. */ 280 specify the pointed-to set. */
239 if (TREE_CODE (ptr1) == ADDR_EXPR) 281 if (TREE_CODE (ptr1) == ADDR_EXPR)
240 { 282 {
241 tree base = get_base_address (TREE_OPERAND (ptr1, 0)); 283 tree base = get_base_address (TREE_OPERAND (ptr1, 0));
242 if (base 284 if (base
243 && INDIRECT_REF_P (base)) 285 && (INDIRECT_REF_P (base)
286 || TREE_CODE (base) == MEM_REF))
244 ptr1 = TREE_OPERAND (base, 0); 287 ptr1 = TREE_OPERAND (base, 0);
245 else if (base 288 else if (base
246 && SSA_VAR_P (base)) 289 && SSA_VAR_P (base))
247 return ptr_deref_may_alias_decl_p (ptr2, base); 290 return ptr_deref_may_alias_decl_p (ptr2, base);
248 else 291 else
250 } 293 }
251 if (TREE_CODE (ptr2) == ADDR_EXPR) 294 if (TREE_CODE (ptr2) == ADDR_EXPR)
252 { 295 {
253 tree base = get_base_address (TREE_OPERAND (ptr2, 0)); 296 tree base = get_base_address (TREE_OPERAND (ptr2, 0));
254 if (base 297 if (base
255 && INDIRECT_REF_P (base)) 298 && (INDIRECT_REF_P (base)
299 || TREE_CODE (base) == MEM_REF))
256 ptr2 = TREE_OPERAND (base, 0); 300 ptr2 = TREE_OPERAND (base, 0);
257 else if (base 301 else if (base
258 && SSA_VAR_P (base)) 302 && SSA_VAR_P (base))
259 return ptr_deref_may_alias_decl_p (ptr1, base); 303 return ptr_deref_may_alias_decl_p (ptr1, base);
260 else 304 else
261 return true; 305 return true;
262 } 306 }
263 307
264 /* We can end up with dereferencing constant pointers.
265 Just bail out in this case. */
266 if (TREE_CODE (ptr1) == INTEGER_CST
267 || TREE_CODE (ptr2) == INTEGER_CST)
268 return true;
269
270 /* We may end up with two empty points-to solutions for two same pointers. 308 /* We may end up with two empty points-to solutions for two same pointers.
271 In this case we still want to say both pointers alias, so shortcut 309 In this case we still want to say both pointers alias, so shortcut
272 that here. */ 310 that here. */
273 if (ptr1 == ptr2) 311 if (ptr1 == ptr2)
274 return true; 312 return true;
299 static bool 337 static bool
300 ptr_deref_may_alias_ref_p_1 (tree ptr, ao_ref *ref) 338 ptr_deref_may_alias_ref_p_1 (tree ptr, ao_ref *ref)
301 { 339 {
302 tree base = ao_ref_base (ref); 340 tree base = ao_ref_base (ref);
303 341
304 if (INDIRECT_REF_P (base)) 342 if (INDIRECT_REF_P (base)
343 || TREE_CODE (base) == MEM_REF)
305 return ptr_derefs_may_alias_p (ptr, TREE_OPERAND (base, 0)); 344 return ptr_derefs_may_alias_p (ptr, TREE_OPERAND (base, 0));
306 else if (SSA_VAR_P (base)) 345 else if (SSA_VAR_P (base))
307 return ptr_deref_may_alias_decl_p (ptr, base); 346 return ptr_deref_may_alias_decl_p (ptr, base);
308 347
309 return true; 348 return true;
323 362
324 fprintf (file, "\n\nAlias information for %s\n\n", funcname); 363 fprintf (file, "\n\nAlias information for %s\n\n", funcname);
325 364
326 fprintf (file, "Aliased symbols\n\n"); 365 fprintf (file, "Aliased symbols\n\n");
327 366
328 FOR_EACH_REFERENCED_VAR (var, rvi) 367 FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
329 { 368 {
330 if (may_be_aliased (var)) 369 if (may_be_aliased (var))
331 dump_variable (file, var); 370 dump_variable (file, var);
332 } 371 }
333 372
356 } 395 }
357 396
358 397
359 /* Dump alias information on stderr. */ 398 /* Dump alias information on stderr. */
360 399
361 void 400 DEBUG_FUNCTION void
362 debug_alias_info (void) 401 debug_alias_info (void)
363 { 402 {
364 dump_alias_info (stderr); 403 dump_alias_info (stderr);
365 } 404 }
366 405
367
368 /* Return the alias information associated with pointer T. It creates a
369 new instance if none existed. */
370
371 struct ptr_info_def *
372 get_ptr_info (tree t)
373 {
374 struct ptr_info_def *pi;
375
376 gcc_assert (POINTER_TYPE_P (TREE_TYPE (t)));
377
378 pi = SSA_NAME_PTR_INFO (t);
379 if (pi == NULL)
380 {
381 pi = GGC_CNEW (struct ptr_info_def);
382 pt_solution_reset (&pi->pt);
383 SSA_NAME_PTR_INFO (t) = pi;
384 }
385
386 return pi;
387 }
388 406
389 /* Dump the points-to set *PT into FILE. */ 407 /* Dump the points-to set *PT into FILE. */
390 408
391 void 409 void
392 dump_points_to_solution (FILE *file, struct pt_solution *pt) 410 dump_points_to_solution (FILE *file, struct pt_solution *pt)
435 } 453 }
436 454
437 455
438 /* Dump points-to information for VAR into stderr. */ 456 /* Dump points-to information for VAR into stderr. */
439 457
440 void 458 DEBUG_FUNCTION void
441 debug_points_to_info_for (tree var) 459 debug_points_to_info_for (tree var)
442 { 460 {
443 dump_points_to_info_for (stderr, var); 461 dump_points_to_info_for (stderr, var);
444 } 462 }
445 463
470 return ref->base; 488 return ref->base;
471 } 489 }
472 490
473 /* Returns the base object alias set of the memory reference *REF. */ 491 /* Returns the base object alias set of the memory reference *REF. */
474 492
475 static alias_set_type ATTRIBUTE_UNUSED 493 static alias_set_type
476 ao_ref_base_alias_set (ao_ref *ref) 494 ao_ref_base_alias_set (ao_ref *ref)
477 { 495 {
496 tree base_ref;
478 if (ref->base_alias_set != -1) 497 if (ref->base_alias_set != -1)
479 return ref->base_alias_set; 498 return ref->base_alias_set;
480 ref->base_alias_set = get_alias_set (ao_ref_base (ref)); 499 if (!ref->ref)
500 return 0;
501 base_ref = ref->ref;
502 while (handled_component_p (base_ref))
503 base_ref = TREE_OPERAND (base_ref, 0);
504 ref->base_alias_set = get_alias_set (base_ref);
481 return ref->base_alias_set; 505 return ref->base_alias_set;
482 } 506 }
483 507
484 /* Returns the reference alias set of the memory reference *REF. */ 508 /* Returns the reference alias set of the memory reference *REF. */
485 509
505 if (TREE_CODE (ptr) == ADDR_EXPR) 529 if (TREE_CODE (ptr) == ADDR_EXPR)
506 ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0), 530 ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0),
507 &ref->offset, &t1, &t2); 531 &ref->offset, &t1, &t2);
508 else 532 else
509 { 533 {
510 ref->base = build1 (INDIRECT_REF, char_type_node, ptr); 534 ref->base = build2 (MEM_REF, char_type_node,
535 ptr, null_pointer_node);
511 ref->offset = 0; 536 ref->offset = 0;
512 } 537 }
513 if (size 538 if (size
514 && host_integerp (size, 0) 539 && host_integerp (size, 0)
515 && TREE_INT_CST_LOW (size) * 8 / 8 == TREE_INT_CST_LOW (size)) 540 && TREE_INT_CST_LOW (size) * 8 / 8 == TREE_INT_CST_LOW (size))
561 return 0; 586 return 0;
562 } 587 }
563 588
564 /* Determine if the two component references REF1 and REF2 which are 589 /* Determine if the two component references REF1 and REF2 which are
565 based on access types TYPE1 and TYPE2 and of which at least one is based 590 based on access types TYPE1 and TYPE2 and of which at least one is based
566 on an indirect reference may alias. */ 591 on an indirect reference may alias. REF2 is the only one that can
592 be a decl in which case REF2_IS_DECL is true.
593 REF1_ALIAS_SET, BASE1_ALIAS_SET, REF2_ALIAS_SET and BASE2_ALIAS_SET
594 are the respective alias sets. */
567 595
568 static bool 596 static bool
569 aliasing_component_refs_p (tree ref1, tree type1, 597 aliasing_component_refs_p (tree ref1, tree type1,
598 alias_set_type ref1_alias_set,
599 alias_set_type base1_alias_set,
570 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, 600 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
571 tree ref2, tree type2, 601 tree ref2, tree type2,
572 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2) 602 alias_set_type ref2_alias_set,
603 alias_set_type base2_alias_set,
604 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
605 bool ref2_is_decl)
573 { 606 {
574 /* If one reference is a component references through pointers try to find a 607 /* If one reference is a component references through pointers try to find a
575 common base and apply offset based disambiguation. This handles 608 common base and apply offset based disambiguation. This handles
576 for example 609 for example
577 struct A { int i; int j; } *q; 610 struct A { int i; int j; } *q;
611 HOST_WIDE_INT offadj, sztmp, msztmp; 644 HOST_WIDE_INT offadj, sztmp, msztmp;
612 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp); 645 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
613 offset1 -= offadj; 646 offset1 -= offadj;
614 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); 647 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
615 } 648 }
649
616 /* If we have two type access paths B1.path1 and B2.path2 they may 650 /* If we have two type access paths B1.path1 and B2.path2 they may
617 only alias if either B1 is in B2.path2 or B2 is in B1.path1. */ 651 only alias if either B1 is in B2.path2 or B2 is in B1.path1.
652 But we can still have a path that goes B1.path1...B2.path2 with
653 a part that we do not see. So we can only disambiguate now
654 if there is no B2 in the tail of path1 and no B1 on the
655 tail of path2. */
656 if (base1_alias_set == ref2_alias_set
657 || alias_set_subset_of (base1_alias_set, ref2_alias_set))
658 return true;
659 /* If this is ptr vs. decl then we know there is no ptr ... decl path. */
660 if (!ref2_is_decl)
661 return (base2_alias_set == ref1_alias_set
662 || alias_set_subset_of (base2_alias_set, ref1_alias_set));
618 return false; 663 return false;
619 } 664 }
620 665
621 /* Return true if two memory references based on the variables BASE1 666 /* Return true if two memory references based on the variables BASE1
622 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and 667 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
645 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1 690 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
646 in which case they are computed on-demand. REF1 and REF2 691 in which case they are computed on-demand. REF1 and REF2
647 if non-NULL are the complete memory reference trees. */ 692 if non-NULL are the complete memory reference trees. */
648 693
649 static bool 694 static bool
650 indirect_ref_may_alias_decl_p (tree ref1, tree ptr1, 695 indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
651 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, 696 HOST_WIDE_INT offset1,
697 HOST_WIDE_INT max_size1 ATTRIBUTE_UNUSED,
698 alias_set_type ref1_alias_set,
652 alias_set_type base1_alias_set, 699 alias_set_type base1_alias_set,
653 tree ref2, tree base2, 700 tree ref2 ATTRIBUTE_UNUSED, tree base2,
654 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2, 701 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
655 alias_set_type base2_alias_set) 702 alias_set_type ref2_alias_set,
656 { 703 alias_set_type base2_alias_set, bool tbaa_p)
704 {
705 tree ptr1;
706 tree ptrtype1;
707 HOST_WIDE_INT offset1p = offset1, offset2p = offset2;
708
709 ptr1 = TREE_OPERAND (base1, 0);
710
711 /* The offset embedded in MEM_REFs can be negative. Bias them
712 so that the resulting offset adjustment is positive. */
713 if (TREE_CODE (base1) == MEM_REF
714 || TREE_CODE (base1) == TARGET_MEM_REF)
715 {
716 double_int moff = mem_ref_offset (base1);
717 moff = double_int_lshift (moff,
718 BITS_PER_UNIT == 8
719 ? 3 : exact_log2 (BITS_PER_UNIT),
720 HOST_BITS_PER_DOUBLE_INT, true);
721 if (double_int_negative_p (moff))
722 offset2p += double_int_neg (moff).low;
723 else
724 offset1p += moff.low;
725 }
726
657 /* If only one reference is based on a variable, they cannot alias if 727 /* If only one reference is based on a variable, they cannot alias if
658 the pointer access is beyond the extent of the variable access. 728 the pointer access is beyond the extent of the variable access.
659 (the pointer base cannot validly point to an offset less than zero 729 (the pointer base cannot validly point to an offset less than zero
660 of the variable). 730 of the variable).
661 They also cannot alias if the pointer may not point to the decl. */ 731 They also cannot alias if the pointer may not point to the decl. */
662 if (max_size2 != -1 732 if ((TREE_CODE (base1) != TARGET_MEM_REF
663 && !ranges_overlap_p (offset1, max_size1, 0, offset2 + max_size2)) 733 || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1)))
734 && !ranges_overlap_p (MAX (0, offset1p), -1, offset2p, max_size2))
664 return false; 735 return false;
665 if (!ptr_deref_may_alias_decl_p (ptr1, base2)) 736 if (!ptr_deref_may_alias_decl_p (ptr1, base2))
666 return false; 737 return false;
667 738
668 /* Disambiguations that rely on strict aliasing rules follow. */ 739 /* Disambiguations that rely on strict aliasing rules follow. */
669 if (!flag_strict_aliasing) 740 if (!flag_strict_aliasing || !tbaa_p)
670 return true; 741 return true;
742
743 if (TREE_CODE (base1) == MEM_REF)
744 ptrtype1 = TREE_TYPE (TREE_OPERAND (base1, 1));
745 else if (TREE_CODE (base1) == TARGET_MEM_REF)
746 ptrtype1 = TREE_TYPE (TMR_OFFSET (base1));
747 else
748 ptrtype1 = TREE_TYPE (ptr1);
671 749
672 /* If the alias set for a pointer access is zero all bets are off. */ 750 /* If the alias set for a pointer access is zero all bets are off. */
673 if (base1_alias_set == -1) 751 if (base1_alias_set == -1)
674 base1_alias_set = get_deref_alias_set (ptr1); 752 base1_alias_set = get_deref_alias_set (ptrtype1);
675 if (base1_alias_set == 0) 753 if (base1_alias_set == 0)
676 return true; 754 return true;
677 if (base2_alias_set == -1) 755 if (base2_alias_set == -1)
678 base2_alias_set = get_alias_set (base2); 756 base2_alias_set = get_alias_set (base2);
679 757
680 /* If both references are through the same type, they do not alias 758 /* If both references are through the same type, they do not alias
681 if the accesses do not overlap. This does extra disambiguation 759 if the accesses do not overlap. This does extra disambiguation
682 for mixed/pointer accesses but requires strict aliasing. */ 760 for mixed/pointer accesses but requires strict aliasing.
683 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1)), 761 For MEM_REFs we require that the component-ref offset we computed
684 TREE_TYPE (base2)) == 1) 762 is relative to the start of the type which we ensure by
763 comparing rvalue and access type and disregarding the constant
764 pointer offset. */
765 if ((TREE_CODE (base1) != TARGET_MEM_REF
766 || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1)))
767 && (TREE_CODE (base1) != MEM_REF
768 || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1)
769 && same_type_for_tbaa (TREE_TYPE (ptrtype1), TREE_TYPE (base2)) == 1)
685 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); 770 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
686 771
687 /* The only way to access a variable is through a pointer dereference 772 /* When we are trying to disambiguate an access with a pointer dereference
688 of the same alias set or a subset of it. */ 773 as base versus one with a decl as base we can use both the size
774 of the decl and its dynamic type for extra disambiguation.
775 ??? We do not know anything about the dynamic type of the decl
776 other than that its alias-set contains base2_alias_set as a subset
777 which does not help us here. */
778 /* As we know nothing useful about the dynamic type of the decl just
779 use the usual conflict check rather than a subset test.
780 ??? We could introduce -fvery-strict-aliasing when the language
781 does not allow decls to have a dynamic type that differs from their
782 static type. Then we can check
783 !alias_set_subset_of (base1_alias_set, base2_alias_set) instead. */
689 if (base1_alias_set != base2_alias_set 784 if (base1_alias_set != base2_alias_set
690 && !alias_set_subset_of (base1_alias_set, base2_alias_set)) 785 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
786 return false;
787 /* If the size of the access relevant for TBAA through the pointer
788 is bigger than the size of the decl we can't possibly access the
789 decl via that pointer. */
790 if (DECL_SIZE (base2) && COMPLETE_TYPE_P (TREE_TYPE (ptrtype1))
791 && TREE_CODE (DECL_SIZE (base2)) == INTEGER_CST
792 && TREE_CODE (TYPE_SIZE (TREE_TYPE (ptrtype1))) == INTEGER_CST
793 /* ??? This in turn may run afoul when a decl of type T which is
794 a member of union type U is accessed through a pointer to
795 type U and sizeof T is smaller than sizeof U. */
796 && TREE_CODE (TREE_TYPE (ptrtype1)) != UNION_TYPE
797 && TREE_CODE (TREE_TYPE (ptrtype1)) != QUAL_UNION_TYPE
798 && tree_int_cst_lt (DECL_SIZE (base2), TYPE_SIZE (TREE_TYPE (ptrtype1))))
691 return false; 799 return false;
692 800
693 /* Do access-path based disambiguation. */ 801 /* Do access-path based disambiguation. */
694 if (ref1 && ref2 802 if (ref1 && ref2
695 && handled_component_p (ref1) 803 && handled_component_p (ref1)
696 && handled_component_p (ref2)) 804 && handled_component_p (ref2)
697 return aliasing_component_refs_p (ref1, TREE_TYPE (TREE_TYPE (ptr1)), 805 && TREE_CODE (base1) != TARGET_MEM_REF
806 && (TREE_CODE (base1) != MEM_REF
807 || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1))
808 return aliasing_component_refs_p (ref1, TREE_TYPE (ptrtype1),
809 ref1_alias_set, base1_alias_set,
698 offset1, max_size1, 810 offset1, max_size1,
699 ref2, TREE_TYPE (base2), 811 ref2, TREE_TYPE
700 offset2, max_size2); 812 (reference_alias_ptr_type (ref2)),
813 ref2_alias_set, base2_alias_set,
814 offset2, max_size2, true);
701 815
702 return true; 816 return true;
703 } 817 }
704 818
705 /* Return true if two indirect references based on *PTR1 819 /* Return true if two indirect references based on *PTR1
708 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1 822 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
709 in which case they are computed on-demand. REF1 and REF2 823 in which case they are computed on-demand. REF1 and REF2
710 if non-NULL are the complete memory reference trees. */ 824 if non-NULL are the complete memory reference trees. */
711 825
712 static bool 826 static bool
713 indirect_refs_may_alias_p (tree ref1, tree ptr1, 827 indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
714 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, 828 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
829 alias_set_type ref1_alias_set,
715 alias_set_type base1_alias_set, 830 alias_set_type base1_alias_set,
716 tree ref2, tree ptr2, 831 tree ref2 ATTRIBUTE_UNUSED, tree base2,
717 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2, 832 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
718 alias_set_type base2_alias_set) 833 alias_set_type ref2_alias_set,
719 { 834 alias_set_type base2_alias_set, bool tbaa_p)
835 {
836 tree ptr1;
837 tree ptr2;
838 tree ptrtype1, ptrtype2;
839
840 ptr1 = TREE_OPERAND (base1, 0);
841 ptr2 = TREE_OPERAND (base2, 0);
842
720 /* If both bases are based on pointers they cannot alias if they may not 843 /* If both bases are based on pointers they cannot alias if they may not
721 point to the same memory object or if they point to the same object 844 point to the same memory object or if they point to the same object
722 and the accesses do not overlap. */ 845 and the accesses do not overlap. */
723 if (operand_equal_p (ptr1, ptr2, 0)) 846 if ((!cfun || gimple_in_ssa_p (cfun))
724 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); 847 && operand_equal_p (ptr1, ptr2, 0)
848 && (((TREE_CODE (base1) != TARGET_MEM_REF
849 || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1)))
850 && (TREE_CODE (base2) != TARGET_MEM_REF
851 || (!TMR_INDEX (base2) && !TMR_INDEX2 (base2))))
852 || (TREE_CODE (base1) == TARGET_MEM_REF
853 && TREE_CODE (base2) == TARGET_MEM_REF
854 && (TMR_STEP (base1) == TMR_STEP (base2)
855 || (TMR_STEP (base1) && TMR_STEP (base2)
856 && operand_equal_p (TMR_STEP (base1),
857 TMR_STEP (base2), 0)))
858 && (TMR_INDEX (base1) == TMR_INDEX (base2)
859 || (TMR_INDEX (base1) && TMR_INDEX (base2)
860 && operand_equal_p (TMR_INDEX (base1),
861 TMR_INDEX (base2), 0)))
862 && (TMR_INDEX2 (base1) == TMR_INDEX2 (base2)
863 || (TMR_INDEX2 (base1) && TMR_INDEX2 (base2)
864 && operand_equal_p (TMR_INDEX2 (base1),
865 TMR_INDEX2 (base2), 0))))))
866 {
867 /* The offset embedded in MEM_REFs can be negative. Bias them
868 so that the resulting offset adjustment is positive. */
869 if (TREE_CODE (base1) == MEM_REF
870 || TREE_CODE (base1) == TARGET_MEM_REF)
871 {
872 double_int moff = mem_ref_offset (base1);
873 moff = double_int_lshift (moff,
874 BITS_PER_UNIT == 8
875 ? 3 : exact_log2 (BITS_PER_UNIT),
876 HOST_BITS_PER_DOUBLE_INT, true);
877 if (double_int_negative_p (moff))
878 offset2 += double_int_neg (moff).low;
879 else
880 offset1 += moff.low;
881 }
882 if (TREE_CODE (base2) == MEM_REF
883 || TREE_CODE (base2) == TARGET_MEM_REF)
884 {
885 double_int moff = mem_ref_offset (base2);
886 moff = double_int_lshift (moff,
887 BITS_PER_UNIT == 8
888 ? 3 : exact_log2 (BITS_PER_UNIT),
889 HOST_BITS_PER_DOUBLE_INT, true);
890 if (double_int_negative_p (moff))
891 offset1 += double_int_neg (moff).low;
892 else
893 offset2 += moff.low;
894 }
895 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
896 }
725 if (!ptr_derefs_may_alias_p (ptr1, ptr2)) 897 if (!ptr_derefs_may_alias_p (ptr1, ptr2))
726 return false; 898 return false;
727 899
728 /* Disambiguations that rely on strict aliasing rules follow. */ 900 /* Disambiguations that rely on strict aliasing rules follow. */
729 if (!flag_strict_aliasing) 901 if (!flag_strict_aliasing || !tbaa_p)
730 return true; 902 return true;
903
904 if (TREE_CODE (base1) == MEM_REF)
905 ptrtype1 = TREE_TYPE (TREE_OPERAND (base1, 1));
906 else if (TREE_CODE (base1) == TARGET_MEM_REF)
907 ptrtype1 = TREE_TYPE (TMR_OFFSET (base1));
908 else
909 ptrtype1 = TREE_TYPE (ptr1);
910 if (TREE_CODE (base2) == MEM_REF)
911 ptrtype2 = TREE_TYPE (TREE_OPERAND (base2, 1));
912 else if (TREE_CODE (base2) == TARGET_MEM_REF)
913 ptrtype2 = TREE_TYPE (TMR_OFFSET (base2));
914 else
915 ptrtype2 = TREE_TYPE (ptr2);
731 916
732 /* If the alias set for a pointer access is zero all bets are off. */ 917 /* If the alias set for a pointer access is zero all bets are off. */
733 if (base1_alias_set == -1) 918 if (base1_alias_set == -1)
734 base1_alias_set = get_deref_alias_set (ptr1); 919 base1_alias_set = get_deref_alias_set (ptrtype1);
735 if (base1_alias_set == 0) 920 if (base1_alias_set == 0)
736 return true; 921 return true;
737 if (base2_alias_set == -1) 922 if (base2_alias_set == -1)
738 base2_alias_set = get_deref_alias_set (ptr2); 923 base2_alias_set = get_deref_alias_set (ptrtype2);
739 if (base2_alias_set == 0) 924 if (base2_alias_set == 0)
740 return true; 925 return true;
741 926
742 /* If both references are through the same type, they do not alias 927 /* If both references are through the same type, they do not alias
743 if the accesses do not overlap. This does extra disambiguation 928 if the accesses do not overlap. This does extra disambiguation
744 for mixed/pointer accesses but requires strict aliasing. */ 929 for mixed/pointer accesses but requires strict aliasing. */
745 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1)), 930 if ((TREE_CODE (base1) != TARGET_MEM_REF || !TMR_INDEX (base1))
746 TREE_TYPE (TREE_TYPE (ptr2))) == 1) 931 && (TREE_CODE (base2) != TARGET_MEM_REF || !TMR_INDEX (base2))
932 && (TREE_CODE (base1) != MEM_REF
933 || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1)
934 && (TREE_CODE (base2) != MEM_REF
935 || same_type_for_tbaa (TREE_TYPE (base2), TREE_TYPE (ptrtype2)) == 1)
936 && same_type_for_tbaa (TREE_TYPE (ptrtype1),
937 TREE_TYPE (ptrtype2)) == 1)
747 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); 938 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
748 939
749 /* Do type-based disambiguation. */ 940 /* Do type-based disambiguation. */
750 if (base1_alias_set != base2_alias_set 941 if (base1_alias_set != base2_alias_set
751 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set)) 942 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
752 return false; 943 return false;
753 944
754 /* Do access-path based disambiguation. */ 945 /* Do access-path based disambiguation. */
755 if (ref1 && ref2 946 if (ref1 && ref2
756 && handled_component_p (ref1) 947 && handled_component_p (ref1)
757 && handled_component_p (ref2)) 948 && handled_component_p (ref2)
758 return aliasing_component_refs_p (ref1, TREE_TYPE (TREE_TYPE (ptr1)), 949 && TREE_CODE (base1) != TARGET_MEM_REF
950 && TREE_CODE (base2) != TARGET_MEM_REF
951 && (TREE_CODE (base1) != MEM_REF
952 || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1)
953 && (TREE_CODE (base2) != MEM_REF
954 || same_type_for_tbaa (TREE_TYPE (base2), TREE_TYPE (ptrtype2)) == 1))
955 return aliasing_component_refs_p (ref1, TREE_TYPE (ptrtype1),
956 ref1_alias_set, base1_alias_set,
759 offset1, max_size1, 957 offset1, max_size1,
760 ref2, TREE_TYPE (TREE_TYPE (ptr2)), 958 ref2, TREE_TYPE (ptrtype2),
761 offset2, max_size2); 959 ref2_alias_set, base2_alias_set,
960 offset2, max_size2, false);
762 961
763 return true; 962 return true;
764 } 963 }
765 964
766 /* Return true, if the two memory references REF1 and REF2 may alias. */ 965 /* Return true, if the two memory references REF1 and REF2 may alias. */
770 { 969 {
771 tree base1, base2; 970 tree base1, base2;
772 HOST_WIDE_INT offset1 = 0, offset2 = 0; 971 HOST_WIDE_INT offset1 = 0, offset2 = 0;
773 HOST_WIDE_INT max_size1 = -1, max_size2 = -1; 972 HOST_WIDE_INT max_size1 = -1, max_size2 = -1;
774 bool var1_p, var2_p, ind1_p, ind2_p; 973 bool var1_p, var2_p, ind1_p, ind2_p;
775 alias_set_type set; 974
776 975 gcc_checking_assert ((!ref1->ref
777 gcc_assert ((!ref1->ref 976 || TREE_CODE (ref1->ref) == SSA_NAME
778 || SSA_VAR_P (ref1->ref) 977 || DECL_P (ref1->ref)
779 || handled_component_p (ref1->ref) 978 || TREE_CODE (ref1->ref) == STRING_CST
780 || INDIRECT_REF_P (ref1->ref) 979 || handled_component_p (ref1->ref)
781 || TREE_CODE (ref1->ref) == TARGET_MEM_REF 980 || INDIRECT_REF_P (ref1->ref)
782 || TREE_CODE (ref1->ref) == CONST_DECL) 981 || TREE_CODE (ref1->ref) == MEM_REF
783 && (!ref2->ref 982 || TREE_CODE (ref1->ref) == TARGET_MEM_REF)
784 || SSA_VAR_P (ref2->ref) 983 && (!ref2->ref
785 || handled_component_p (ref2->ref) 984 || TREE_CODE (ref2->ref) == SSA_NAME
786 || INDIRECT_REF_P (ref2->ref) 985 || DECL_P (ref2->ref)
787 || TREE_CODE (ref2->ref) == TARGET_MEM_REF 986 || TREE_CODE (ref2->ref) == STRING_CST
788 || TREE_CODE (ref2->ref) == CONST_DECL)); 987 || handled_component_p (ref2->ref)
988 || INDIRECT_REF_P (ref2->ref)
989 || TREE_CODE (ref2->ref) == MEM_REF
990 || TREE_CODE (ref2->ref) == TARGET_MEM_REF));
789 991
790 /* Decompose the references into their base objects and the access. */ 992 /* Decompose the references into their base objects and the access. */
791 base1 = ao_ref_base (ref1); 993 base1 = ao_ref_base (ref1);
792 offset1 = ref1->offset; 994 offset1 = ref1->offset;
793 max_size1 = ref1->max_size; 995 max_size1 = ref1->max_size;
797 999
798 /* We can end up with registers or constants as bases for example from 1000 /* We can end up with registers or constants as bases for example from
799 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59); 1001 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
800 which is seen as a struct copy. */ 1002 which is seen as a struct copy. */
801 if (TREE_CODE (base1) == SSA_NAME 1003 if (TREE_CODE (base1) == SSA_NAME
1004 || TREE_CODE (base1) == CONST_DECL
1005 || TREE_CODE (base1) == CONSTRUCTOR
1006 || TREE_CODE (base1) == ADDR_EXPR
1007 || CONSTANT_CLASS_P (base1)
802 || TREE_CODE (base2) == SSA_NAME 1008 || TREE_CODE (base2) == SSA_NAME
803 || TREE_CODE (base1) == CONST_DECL
804 || TREE_CODE (base2) == CONST_DECL 1009 || TREE_CODE (base2) == CONST_DECL
805 || is_gimple_min_invariant (base1) 1010 || TREE_CODE (base2) == CONSTRUCTOR
806 || is_gimple_min_invariant (base2)) 1011 || TREE_CODE (base2) == ADDR_EXPR
1012 || CONSTANT_CLASS_P (base2))
807 return false; 1013 return false;
808 1014
809 /* We can end up refering to code via function decls. As we likely 1015 /* We can end up refering to code via function and label decls.
810 do not properly track code aliases conservatively bail out. */ 1016 As we likely do not properly track code aliases conservatively
1017 bail out. */
811 if (TREE_CODE (base1) == FUNCTION_DECL 1018 if (TREE_CODE (base1) == FUNCTION_DECL
812 || TREE_CODE (base2) == FUNCTION_DECL) 1019 || TREE_CODE (base1) == LABEL_DECL
1020 || TREE_CODE (base2) == FUNCTION_DECL
1021 || TREE_CODE (base2) == LABEL_DECL)
813 return true; 1022 return true;
814 1023
815 /* Defer to simple offset based disambiguation if we have 1024 /* Defer to simple offset based disambiguation if we have
816 references based on two decls. Do this before defering to 1025 references based on two decls. Do this before defering to
817 TBAA to handle must-alias cases in conformance with the 1026 TBAA to handle must-alias cases in conformance with the
820 var2_p = SSA_VAR_P (base2); 1029 var2_p = SSA_VAR_P (base2);
821 if (var1_p && var2_p) 1030 if (var1_p && var2_p)
822 return decl_refs_may_alias_p (base1, offset1, max_size1, 1031 return decl_refs_may_alias_p (base1, offset1, max_size1,
823 base2, offset2, max_size2); 1032 base2, offset2, max_size2);
824 1033
825 ind1_p = INDIRECT_REF_P (base1); 1034 ind1_p = (INDIRECT_REF_P (base1)
826 ind2_p = INDIRECT_REF_P (base2); 1035 || (TREE_CODE (base1) == MEM_REF)
1036 || (TREE_CODE (base1) == TARGET_MEM_REF));
1037 ind2_p = (INDIRECT_REF_P (base2)
1038 || (TREE_CODE (base2) == MEM_REF)
1039 || (TREE_CODE (base2) == TARGET_MEM_REF));
1040
827 /* Canonicalize the pointer-vs-decl case. */ 1041 /* Canonicalize the pointer-vs-decl case. */
828 if (ind1_p && var2_p) 1042 if (ind1_p && var2_p)
829 { 1043 {
830 HOST_WIDE_INT tmp1; 1044 HOST_WIDE_INT tmp1;
831 tree tmp2; 1045 tree tmp2;
838 ind1_p = false; 1052 ind1_p = false;
839 var2_p = false; 1053 var2_p = false;
840 ind2_p = true; 1054 ind2_p = true;
841 } 1055 }
842 1056
843 /* If we are about to disambiguate pointer-vs-decl try harder to
844 see must-aliases and give leeway to some invalid cases.
845 This covers a pretty minimal set of cases only and does not
846 when called from the RTL oracle. It handles cases like
847
848 int i = 1;
849 return *(float *)&i;
850
851 and also fixes gfortran.dg/lto/pr40725. */
852 if (var1_p && ind2_p
853 && cfun
854 && gimple_in_ssa_p (cfun)
855 && TREE_CODE (TREE_OPERAND (base2, 0)) == SSA_NAME)
856 {
857 gimple def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (base2, 0));
858 while (is_gimple_assign (def_stmt)
859 && (gimple_assign_rhs_code (def_stmt) == SSA_NAME
860 || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))))
861 {
862 tree rhs = gimple_assign_rhs1 (def_stmt);
863 HOST_WIDE_INT offset, size, max_size;
864
865 /* Look through SSA name copies and pointer conversions. */
866 if (TREE_CODE (rhs) == SSA_NAME
867 && POINTER_TYPE_P (TREE_TYPE (rhs)))
868 {
869 def_stmt = SSA_NAME_DEF_STMT (rhs);
870 continue;
871 }
872 if (TREE_CODE (rhs) != ADDR_EXPR)
873 break;
874
875 /* If the pointer is defined as an address based on a decl
876 use plain offset disambiguation and ignore TBAA. */
877 rhs = TREE_OPERAND (rhs, 0);
878 rhs = get_ref_base_and_extent (rhs, &offset, &size, &max_size);
879 if (SSA_VAR_P (rhs))
880 {
881 base2 = rhs;
882 offset2 += offset;
883 if (size != max_size
884 || max_size == -1)
885 max_size2 = -1;
886 return decl_refs_may_alias_p (base1, offset1, max_size1,
887 base2, offset2, max_size2);
888 }
889
890 /* Do not continue looking through &p->x to limit time
891 complexity. */
892 break;
893 }
894 }
895
896 /* First defer to TBAA if possible. */ 1057 /* First defer to TBAA if possible. */
897 if (tbaa_p 1058 if (tbaa_p
898 && flag_strict_aliasing 1059 && flag_strict_aliasing
899 && !alias_sets_conflict_p (ao_ref_alias_set (ref1), 1060 && !alias_sets_conflict_p (ao_ref_alias_set (ref1),
900 ao_ref_alias_set (ref2))) 1061 ao_ref_alias_set (ref2)))
901 return false; 1062 return false;
902 1063
903 /* If one reference is a TARGET_MEM_REF weird things are allowed. Still
904 TBAA disambiguation based on the access type is possible, so bail
905 out only after that check. */
906 if ((ref1->ref && TREE_CODE (ref1->ref) == TARGET_MEM_REF)
907 || (ref2->ref && TREE_CODE (ref2->ref) == TARGET_MEM_REF))
908 return true;
909
910 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */ 1064 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */
911 set = tbaa_p ? -1 : 0;
912 if (var1_p && ind2_p) 1065 if (var1_p && ind2_p)
913 return indirect_ref_may_alias_decl_p (ref2->ref, TREE_OPERAND (base2, 0), 1066 return indirect_ref_may_alias_decl_p (ref2->ref, base2,
914 offset2, max_size2, set, 1067 offset2, max_size2,
1068 ao_ref_alias_set (ref2), -1,
915 ref1->ref, base1, 1069 ref1->ref, base1,
916 offset1, max_size1, set); 1070 offset1, max_size1,
1071 ao_ref_alias_set (ref1),
1072 ao_ref_base_alias_set (ref1),
1073 tbaa_p);
917 else if (ind1_p && ind2_p) 1074 else if (ind1_p && ind2_p)
918 return indirect_refs_may_alias_p (ref1->ref, TREE_OPERAND (base1, 0), 1075 return indirect_refs_may_alias_p (ref1->ref, base1,
919 offset1, max_size1, set, 1076 offset1, max_size1,
920 ref2->ref, TREE_OPERAND (base2, 0), 1077 ao_ref_alias_set (ref1), -1,
921 offset2, max_size2, set); 1078 ref2->ref, base2,
922 1079 offset2, max_size2,
1080 ao_ref_alias_set (ref2), -1,
1081 tbaa_p);
1082
1083 /* We really do not want to end up here, but returning true is safe. */
1084 #ifdef ENABLE_CHECKING
923 gcc_unreachable (); 1085 gcc_unreachable ();
1086 #else
1087 return true;
1088 #endif
924 } 1089 }
925 1090
926 bool 1091 bool
927 refs_may_alias_p (tree ref1, tree ref2) 1092 refs_may_alias_p (tree ref1, tree ref2)
928 { 1093 {
1050 case BUILT_IN_REMQUOL: 1215 case BUILT_IN_REMQUOL:
1051 case BUILT_IN_SINCOS: 1216 case BUILT_IN_SINCOS:
1052 case BUILT_IN_SINCOSF: 1217 case BUILT_IN_SINCOSF:
1053 case BUILT_IN_SINCOSL: 1218 case BUILT_IN_SINCOSL:
1054 return false; 1219 return false;
1220 /* __sync_* builtins and some OpenMP builtins act as threading
1221 barriers. */
1222 #undef DEF_SYNC_BUILTIN
1223 #define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM:
1224 #include "sync-builtins.def"
1225 #undef DEF_SYNC_BUILTIN
1226 case BUILT_IN_GOMP_ATOMIC_START:
1227 case BUILT_IN_GOMP_ATOMIC_END:
1228 case BUILT_IN_GOMP_BARRIER:
1229 case BUILT_IN_GOMP_TASKWAIT:
1230 case BUILT_IN_GOMP_CRITICAL_START:
1231 case BUILT_IN_GOMP_CRITICAL_END:
1232 case BUILT_IN_GOMP_CRITICAL_NAME_START:
1233 case BUILT_IN_GOMP_CRITICAL_NAME_END:
1234 case BUILT_IN_GOMP_LOOP_END:
1235 case BUILT_IN_GOMP_ORDERED_START:
1236 case BUILT_IN_GOMP_ORDERED_END:
1237 case BUILT_IN_GOMP_PARALLEL_END:
1238 case BUILT_IN_GOMP_SECTIONS_END:
1239 case BUILT_IN_GOMP_SINGLE_COPY_START:
1240 case BUILT_IN_GOMP_SINGLE_COPY_END:
1241 return true;
1055 1242
1056 default: 1243 default:
1057 /* Fallthru to general call handling. */; 1244 /* Fallthru to general call handling. */;
1058 } 1245 }
1059 1246
1075 if (DECL_P (base)) 1262 if (DECL_P (base))
1076 { 1263 {
1077 if (pt_solution_includes (gimple_call_use_set (call), base)) 1264 if (pt_solution_includes (gimple_call_use_set (call), base))
1078 return true; 1265 return true;
1079 } 1266 }
1080 else if (INDIRECT_REF_P (base) 1267 else if ((INDIRECT_REF_P (base)
1268 || TREE_CODE (base) == MEM_REF)
1081 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) 1269 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1082 { 1270 {
1083 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); 1271 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1084 if (!pi) 1272 if (!pi)
1085 return true; 1273 return true;
1234 } 1422 }
1235 /* Allocating memory does not have any side-effects apart from 1423 /* Allocating memory does not have any side-effects apart from
1236 being the definition point for the pointer. */ 1424 being the definition point for the pointer. */
1237 case BUILT_IN_MALLOC: 1425 case BUILT_IN_MALLOC:
1238 case BUILT_IN_CALLOC: 1426 case BUILT_IN_CALLOC:
1239 /* Unix98 specifies that errno is set on allocation failure. 1427 /* Unix98 specifies that errno is set on allocation failure. */
1240 Until we properly can track the errno location assume it
1241 is not a local decl but external or anonymous storage in
1242 a different translation unit. Also assume it is of
1243 type int as required by the standard. */
1244 if (flag_errno_math 1428 if (flag_errno_math
1245 && TREE_TYPE (base) == integer_type_node) 1429 && targetm.ref_may_alias_errno (ref))
1246 { 1430 return true;
1247 struct ptr_info_def *pi;
1248 if (DECL_P (base)
1249 && !TREE_STATIC (base))
1250 return true;
1251 else if (INDIRECT_REF_P (base)
1252 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
1253 && (pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))))
1254 return pi->pt.anything || pi->pt.nonlocal;
1255 }
1256 return false; 1431 return false;
1257 /* Freeing memory kills the pointed-to memory. More importantly 1432 /* Freeing memory kills the pointed-to memory. More importantly
1258 the call has to serve as a barrier for moving loads and stores 1433 the call has to serve as a barrier for moving loads and stores
1259 across it. */ 1434 across it. */
1260 case BUILT_IN_FREE: 1435 case BUILT_IN_FREE:
1304 tree sin = gimple_call_arg (call, 1); 1479 tree sin = gimple_call_arg (call, 1);
1305 tree cos = gimple_call_arg (call, 2); 1480 tree cos = gimple_call_arg (call, 2);
1306 return (ptr_deref_may_alias_ref_p_1 (sin, ref) 1481 return (ptr_deref_may_alias_ref_p_1 (sin, ref)
1307 || ptr_deref_may_alias_ref_p_1 (cos, ref)); 1482 || ptr_deref_may_alias_ref_p_1 (cos, ref));
1308 } 1483 }
1484 /* __sync_* builtins and some OpenMP builtins act as threading
1485 barriers. */
1486 #undef DEF_SYNC_BUILTIN
1487 #define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM:
1488 #include "sync-builtins.def"
1489 #undef DEF_SYNC_BUILTIN
1490 case BUILT_IN_GOMP_ATOMIC_START:
1491 case BUILT_IN_GOMP_ATOMIC_END:
1492 case BUILT_IN_GOMP_BARRIER:
1493 case BUILT_IN_GOMP_TASKWAIT:
1494 case BUILT_IN_GOMP_CRITICAL_START:
1495 case BUILT_IN_GOMP_CRITICAL_END:
1496 case BUILT_IN_GOMP_CRITICAL_NAME_START:
1497 case BUILT_IN_GOMP_CRITICAL_NAME_END:
1498 case BUILT_IN_GOMP_LOOP_END:
1499 case BUILT_IN_GOMP_ORDERED_START:
1500 case BUILT_IN_GOMP_ORDERED_END:
1501 case BUILT_IN_GOMP_PARALLEL_END:
1502 case BUILT_IN_GOMP_SECTIONS_END:
1503 case BUILT_IN_GOMP_SINGLE_COPY_START:
1504 case BUILT_IN_GOMP_SINGLE_COPY_END:
1505 return true;
1309 default: 1506 default:
1310 /* Fallthru to general call handling. */; 1507 /* Fallthru to general call handling. */;
1311 } 1508 }
1312 1509
1313 /* Check if base is a global static variable that is not written 1510 /* Check if base is a global static variable that is not written
1325 } 1522 }
1326 1523
1327 /* Check if the base variable is call-clobbered. */ 1524 /* Check if the base variable is call-clobbered. */
1328 if (DECL_P (base)) 1525 if (DECL_P (base))
1329 return pt_solution_includes (gimple_call_clobber_set (call), base); 1526 return pt_solution_includes (gimple_call_clobber_set (call), base);
1330 else if (INDIRECT_REF_P (base) 1527 else if ((INDIRECT_REF_P (base)
1528 || TREE_CODE (base) == MEM_REF)
1331 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) 1529 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1332 { 1530 {
1333 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); 1531 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1334 if (!pi) 1532 if (!pi)
1335 return true; 1533 return true;
1366 { 1564 {
1367 if (is_gimple_call (stmt)) 1565 if (is_gimple_call (stmt))
1368 { 1566 {
1369 tree lhs = gimple_call_lhs (stmt); 1567 tree lhs = gimple_call_lhs (stmt);
1370 if (lhs 1568 if (lhs
1371 && !is_gimple_reg (lhs)) 1569 && TREE_CODE (lhs) != SSA_NAME)
1372 { 1570 {
1373 ao_ref r; 1571 ao_ref r;
1374 ao_ref_init (&r, lhs); 1572 ao_ref_init (&r, lhs);
1375 if (refs_may_alias_p_1 (ref, &r, true)) 1573 if (refs_may_alias_p_1 (ref, &r, true))
1376 return true; 1574 return true;
1377 } 1575 }
1378 1576
1379 return call_may_clobber_ref_p_1 (stmt, ref); 1577 return call_may_clobber_ref_p_1 (stmt, ref);
1380 } 1578 }
1381 else if (is_gimple_assign (stmt)) 1579 else if (gimple_assign_single_p (stmt))
1382 { 1580 {
1383 ao_ref r; 1581 tree lhs = gimple_assign_lhs (stmt);
1384 ao_ref_init (&r, gimple_assign_lhs (stmt)); 1582 if (TREE_CODE (lhs) != SSA_NAME)
1385 return refs_may_alias_p_1 (ref, &r, true); 1583 {
1584 ao_ref r;
1585 ao_ref_init (&r, lhs);
1586 return refs_may_alias_p_1 (ref, &r, true);
1587 }
1386 } 1588 }
1387 else if (gimple_code (stmt) == GIMPLE_ASM) 1589 else if (gimple_code (stmt) == GIMPLE_ASM)
1388 return true; 1590 return true;
1389 1591
1390 return false; 1592 return false;
1394 stmt_may_clobber_ref_p (gimple stmt, tree ref) 1596 stmt_may_clobber_ref_p (gimple stmt, tree ref)
1395 { 1597 {
1396 ao_ref r; 1598 ao_ref r;
1397 ao_ref_init (&r, ref); 1599 ao_ref_init (&r, ref);
1398 return stmt_may_clobber_ref_p_1 (stmt, &r); 1600 return stmt_may_clobber_ref_p_1 (stmt, &r);
1601 }
1602
1603 /* If STMT kills the memory reference REF return true, otherwise
1604 return false. */
1605
1606 static bool
1607 stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref)
1608 {
1609 if (gimple_has_lhs (stmt)
1610 && TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
1611 {
1612 tree base, lhs = gimple_get_lhs (stmt);
1613 HOST_WIDE_INT size, offset, max_size;
1614 ao_ref_base (ref);
1615 base = get_ref_base_and_extent (lhs, &offset, &size, &max_size);
1616 /* We can get MEM[symbol: sZ, index: D.8862_1] here,
1617 so base == ref->base does not always hold. */
1618 if (base == ref->base)
1619 {
1620 /* For a must-alias check we need to be able to constrain
1621 the accesses properly. */
1622 if (size != -1 && size == max_size
1623 && ref->max_size != -1)
1624 {
1625 if (offset <= ref->offset
1626 && offset + size >= ref->offset + ref->max_size)
1627 return true;
1628 }
1629 }
1630 }
1631 return false;
1632 }
1633
1634 bool
1635 stmt_kills_ref_p (gimple stmt, tree ref)
1636 {
1637 ao_ref r;
1638 ao_ref_init (&r, ref);
1639 return stmt_kills_ref_p_1 (stmt, &r);
1399 } 1640 }
1400 1641
1401 1642
1402 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand 1643 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
1403 TARGET or a statement clobbering the memory reference REF in which 1644 TARGET or a statement clobbering the memory reference REF in which