[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-26 Thread rguenth at gcc dot gnu dot org


--- Comment #34 from rguenth at gcc dot gnu dot org  2007-04-26 10:02 
---
I'll bootstrap  regtest that thing and commit it.


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
   |dot org |org
 Status|NEW |ASSIGNED
   Last reconfirmed|2007-02-26 04:38:22 |2007-04-26 10:02:33
   date||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-26 Thread rguenth at gcc dot gnu dot org


--- Comment #35 from rguenth at gcc dot gnu dot org  2007-04-26 12:15 
---
Subject: Bug 30567

Author: rguenth
Date: Thu Apr 26 12:15:16 2007
New Revision: 124184

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=124184
Log:
2007-04-26  Richard Guenther  [EMAIL PROTECTED]
Daniel Berlin  [EMAIL PROTECTED]

PR tree-optimization/30567
* tree-ssa-structalias.c (update_alias_info): Record dereference
also if ESCAPE_STORED_IN_GLOBAL.

* g++.dg/other/pr30567.C: New testcase.

Added:
branches/gcc-4_2-branch/gcc/testsuite/g++.dg/other/pr30567.C
Modified:
branches/gcc-4_2-branch/gcc/ChangeLog
branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
branches/gcc-4_2-branch/gcc/tree-ssa-structalias.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-26 Thread rguenth at gcc dot gnu dot org


--- Comment #36 from rguenth at gcc dot gnu dot org  2007-04-26 12:16 
---
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-26 Thread rguenth at gcc dot gnu dot org


--- Comment #37 from rguenth at gcc dot gnu dot org  2007-04-26 16:50 
---
Subject: Bug 30567

Author: rguenth
Date: Thu Apr 26 16:50:32 2007
New Revision: 124191

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=124191
Log:
2007-04-26  Richard Guenther  [EMAIL PROTECTED]
Daniel Berlin  [EMAIL PROTECTED]

PR tree-optimization/30567
* g++.dg/other/pr30567.C: New testcase.

Added:
trunk/gcc/testsuite/g++.dg/other/pr30567.C
Modified:
trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread rguenth at gcc dot gnu dot org


--- Comment #26 from rguenth at gcc dot gnu dot org  2007-04-25 14:22 
---
We fail to add the SFTs to the may_alias set of SMT.11, so add_virtual_operand
sees NULL may_aliases and doesn't add SFTs as clobbered.

I believe compute_flow_insensitive_aliasing is the culprit here as one can
easily
see that if we enter the

  for (i = 0; i  ai-num_pointers; i++)
{
  size_t j;
  struct alias_map_d *p_map1 = ai-pointers[i];
  tree tag1 = var_ann (p_map1-var)-symbol_mem_tag;
  bitmap may_aliases1 = p_map1-may_aliases;

  if (PTR_IS_REF_ALL (p_map1-var))
continue;

  for (j = i + 1; j  ai-num_pointers; j++)
{
  struct alias_map_d *p_map2 = ai-pointers[j];
  tree tag2 = var_ann (p_map2-var)-symbol_mem_tag;
  bitmap may_aliases2 = p_map2-may_aliases;


loop with may_aliases2 empty it will stay so.  So as a fix I suggest to
add may aliases symmetrically like with

Index: tree-ssa-alias.c
===
*** tree-ssa-alias.c(revision 124151)
--- tree-ssa-alias.c(working copy)
*** compute_flow_insensitive_aliasing (struc
*** 1287,1292 
--- 1287,1294 
  struct alias_map_d *p_map2 = ai-pointers[j];
  tree tag2 = var_ann (p_map2-var)-symbol_mem_tag;
  bitmap may_aliases2 = p_map2-may_aliases;
+ unsigned int k;
+ bitmap_iterator bi;

  if (PTR_IS_REF_ALL (p_map2-var))
continue;
*** compute_flow_insensitive_aliasing (struc
*** 1301,1323 
continue;

  if (!bitmap_empty_p (may_aliases2))
!   {
! unsigned int k;
! bitmap_iterator bi;
! 
! /* Add all the aliases for TAG2 into TAG1's alias set.
!FIXME, update grouping heuristic counters.  */
! EXECUTE_IF_SET_IN_BITMAP (may_aliases2, 0, k, bi)
!   add_may_alias (tag1, referenced_var (k));
! bitmap_ior_into (may_aliases1, may_aliases2);
!   }
  else
!   {
! /* Since TAG2 does not have any aliases of its own, add
!TAG2 itself to the alias set of TAG1.  */
! add_may_alias (tag1, tag2);
! bitmap_set_bit (may_aliases1, DECL_UID (tag2));
!   }
}
  }

--- 1303,1325 
continue;

  if (!bitmap_empty_p (may_aliases2))
!   /* Add all the aliases for TAG2 into TAG1's alias set.
!  FIXME, update grouping heuristic counters.  */
!   EXECUTE_IF_SET_IN_BITMAP (may_aliases2, 0, k, bi)
! add_may_alias (tag1, referenced_var (k));
! else
!   add_may_alias (tag1, tag2);
! 
! if (!bitmap_empty_p (may_aliases1))
!   /* Add all the aliases for TAG2 into TAG1's alias set.
!  FIXME, update grouping heuristic counters.  */
!   EXECUTE_IF_SET_IN_BITMAP (may_aliases1, 0, k, bi)
! add_may_alias (tag2, referenced_var (k));
  else
!   add_may_alias (tag2, tag1);
! 
! bitmap_ior_into (may_aliases2, may_aliases1);
! bitmap_ior_into (may_aliases1, may_aliases2);
}
  }



but I have no clue what I am doing here.  't looks like big mess.

I prepare the workaround as alternative ;)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread rguenth at gcc dot gnu dot org


--- Comment #27 from rguenth at gcc dot gnu dot org  2007-04-25 14:42 
---
The workaround doesn't work.  I'll test the patch in comment #26, otherwise
I'm out of ideas and clue on how it should work.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread rguenth at gcc dot gnu dot org


--- Comment #28 from rguenth at gcc dot gnu dot org  2007-04-25 15:04 
---
Created an attachment (id=13439)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13439action=view)
prototype patch

I'm testing this one.  It'll make aliasing slower and more conservative, so I
bet it's not the right or the best fix.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread rguenth at gcc dot gnu dot org


--- Comment #29 from rguenth at gcc dot gnu dot org  2007-04-25 16:32 
---
Oh, btw. why the may_aliases bitmap for SMT.11 is empty on entry to the loops
computing the transitive closure (it tries to, right?) is that SFT.0 is not
considered stored to in the first nested loop over pointers and addressable
vars.  Shouldn't we add the vars NMT aliases to ai-written_vars in
compute_flow_sensitive_aliasing?  This also seems to fix the problem:

Index: tree-ssa-alias.c
===
*** tree-ssa-alias.c(revision 124151)
--- tree-ssa-alias.c(working copy)
*** compute_flow_sensitive_aliasing (struct 
*** 1142,1152 
 one).  Note that only pointers that have been dereferenced will
 have a name memory tag.  */
if (pi-name_mem_tag  pi-pt_vars)
!   EXECUTE_IF_SET_IN_BITMAP (pi-pt_vars, 0, j, bi)
! {
!   add_may_alias (pi-name_mem_tag, referenced_var (j));
!   add_may_alias (v_ann-symbol_mem_tag, referenced_var (j));
! }
  }
  }

--- 1142,1159 
 one).  Note that only pointers that have been dereferenced will
 have a name memory tag.  */
if (pi-name_mem_tag  pi-pt_vars)
!   {
! bool stored_to = bitmap_bit_p (ai-dereferenced_ptrs_store,
!DECL_UID (SSA_NAME_VAR (ptr)));
! EXECUTE_IF_SET_IN_BITMAP (pi-pt_vars, 0, j, bi)
!   {
! add_may_alias (pi-name_mem_tag, referenced_var (j));
! if (stored_to)
!   bitmap_set_bit (ai-written_vars,
!   DECL_UID (referenced_var (j)));
! add_may_alias (v_ann-symbol_mem_tag, referenced_var (j));
!   }
!   }
  }
  }



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread rguenth at gcc dot gnu dot org


--- Comment #30 from rguenth at gcc dot gnu dot org  2007-04-25 16:42 
---
Created an attachment (id=13441)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13441action=view)
a patch I like more

this one attached, bootstrap/testing in progress.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread dberlin at dberlin dot org


--- Comment #31 from dberlin at gcc dot gnu dot org  2007-04-25 17:01 
---
Subject: Re:  [4.2 Regression] -O3 optimizer bug

On 25 Apr 2007 15:32:41 -, rguenth at gcc dot gnu dot org
[EMAIL PROTECTED] wrote:


 --- Comment #29 from rguenth at gcc dot gnu dot org  2007-04-25 16:32 
 ---
 Oh, btw. why the may_aliases bitmap for SMT.11 is empty on entry to the loops
 computing the transitive closure (it tries to, right?) is that SFT.0 is not
 considered stored to in the first nested loop over pointers and addressable
 vars.  Shouldn't we add the vars NMT aliases to ai-written_vars in
 compute_flow_sensitive_aliasing?

This is a better fix.
The other fix is just a hack.  Aliasing is not symmetric, so we
shouldn't make the two points-to sets equal.

However, I bet if you look at where we initially add written vars,
you'll discover we are missing it there for some reason, and don't
need to post-add it like you do here.

I think i fixed something like this in 4.3 where we didn't consider
stores to globals or arguments to be written or somesuch when we were
initially generating written vars.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread rguenth at gcc dot gnu dot org


--- Comment #32 from rguenth at gcc dot gnu dot org  2007-04-25 17:13 
---
No idea.  The only place I found was setup_pointers_and_addressables, but that
hits the path only if

  /* Add pointer variables that have been dereferenced to the POINTERS
 array and create a symbol memory tag for them.  */
  if (POINTER_TYPE_P (TREE_TYPE (var)))
{

but we don't have a pointer through which SMT we do store to SFT.0, and we
don't seem to care about NMTs and their aliases in this loop at all.

(I'm lost here now, I'll post the patch and the result of bootstrap  test
tomorrow -- I'd love to see a better approach to fixing this ;)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-25 Thread dberlin at gcc dot gnu dot org


--- Comment #33 from dberlin at gcc dot gnu dot org  2007-04-25 19:45 
---
I think richi said on IRC that the following backport from 4.3 will fix it (if
so, it's the correct fix here)

Index: tree-ssa-structalias.c
===
--- tree-ssa-structalias.c  (revision 122853)
+++ tree-ssa-structalias.c  (working copy)
@@ -3228,7 +3228,8 @@ update_alias_info (tree stmt, struct ali
  /* If the statement makes a function call, assume
 that pointer OP will be dereferenced in a store
 operation inside the called function.  */
- if (get_call_expr_in (stmt))
+ if (get_call_expr_in (stmt)
+  || stmt_escape_type == ESCAPE_STORED_IN_GLOBAL)
{
  bitmap_set_bit (ai-dereferenced_ptrs_store, DECL_UID (var));
  pi-is_dereferenced = 1;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-24 Thread mmitchel at gcc dot gnu dot org


-- 

mmitchel at gcc dot gnu dot org changed:

   What|Removed |Added

   Priority|P3  |P1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-24 Thread dberlin at gcc dot gnu dot org


--- Comment #25 from dberlin at gcc dot gnu dot org  2007-04-25 03:14 
---
(In reply to comment #23)
 This is a regression.  Danny?
 

It actually should get assigned anything as a points-to set, so the bad
constraints are correct.

We should also always get correct aliasing even if everything was assigned
ANYTHING as a variable.
Sadly, we don't in 4.2.0, as this case shows.

I'm not going to get a chance to look at this for at least week, I have
something taking priority this week.

If you want to tackle it before then, I would suggest trying to see why we
decide not to give the SFT's to the variable marked with anything.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-21 Thread rguenth at gcc dot gnu dot org


--- Comment #23 from rguenth at gcc dot gnu dot org  2007-04-21 18:07 
---
This is a regression.  Danny?


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||rguenth at gcc dot gnu dot
   ||org
  Known to work||4.1.3 4.3.0
Summary|-O3 optimizer bug   |[4.2 Regression] -O3
   ||optimizer bug


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567



[Bug tree-optimization/30567] [4.2 Regression] -O3 optimizer bug

2007-04-21 Thread rguenth at gcc dot gnu dot org


--- Comment #24 from rguenth at gcc dot gnu dot org  2007-04-21 18:38 
---
Actually the handle_ptr_arith change made a difference as we (luckily?)
for D.2147_17 = D.2144_14 + D.2146_16

  D.2144_14 = a_11-begin;
  D.2145_15 = i_1 * 4;
  D.2146_16 = (const int *) D.2145_15;
  D.2147_17 = D.2144_14 + D.2146_16;

add a constraint for offset zero (that's pure luck) for D.2144_14.  So, the
difference in constraints good vs. bad is

@@ -26,10 +26,10 @@
 D.2144_14 = *a_11
 D.2146_16 = ANYTHING
 D.2147_17 = D.2144_14
+D.2147_17 = D.2146_16
 ESCAPED_VARS = D.2092_25

 Collapsing static cycles and doing variable substitution:
-Collapsing D.2147_17 into D.2144_14
 Collapsing this_7 into D.2140_6
 Collapsing NONLOCAL.8 into ESCAPED_VARS

@@ -54,7 +54,7 @@
 a_11 = { D.2142 }
 D.2144_14 = { D.2141 D.2141.32 }
 D.2146_16 = { ANYTHING }
-D.2147_17 = { D.2141 D.2141.32 }
+D.2147_17 = { ANYTHING D.2141 D.2141.32 }
 D.2092_25 = { }

 main: Total number of aliased vops: 3


Unrelated to this the following resolves possible problems in handle_ptr_arith:

Index: tree-ssa-structalias.c
===
--- tree-ssa-structalias.c  (revision 124018)
+++ tree-ssa-structalias.c  (working copy)
@@ -3287,7 +3287,7 @@ handle_ptr_arith (VEC (ce_s, heap) *lhsc
   unsigned int i = 0;
   unsigned int j = 0;
   VEC (ce_s, heap) *temp = NULL;
-  unsigned int rhsoffset = 0;
+  unsigned HOST_WIDE_INT rhsoffset = 0;

   if (TREE_CODE (expr) != PLUS_EXPR
TREE_CODE (expr) != MINUS_EXPR)
@@ -3298,8 +3298,10 @@ handle_ptr_arith (VEC (ce_s, heap) *lhsc

   get_constraint_for (op0, temp);
   if (POINTER_TYPE_P (TREE_TYPE (op0))
-   TREE_CODE (op1) == INTEGER_CST
-   TREE_CODE (expr) == PLUS_EXPR)
+   host_integerp (op1, 0)
+   TREE_CODE (expr) == PLUS_EXPR
+  /* Make sure the pointer offset is positive.  */
+   tree_int_cst_msb (op1) == 0)
 {
   rhsoffset = TREE_INT_CST_LOW (op1) * BITS_PER_UNIT;
 }

though that last multiplication may still overflow.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30567