This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] for PR18463


On Tue, 2005-09-20 at 08:53 -0400, Daniel Berlin wrote:
> On Mon, 2005-09-19 at 17:03 +0200, Zdenek Dvorak wrote:
> > Hello,
> > 
> > Sebastian's recent changes to chrec_convert cause this testcase (as well
> > as some of spec benchmarks) regress on i686.  The reason is the
> > following.  We have loop (obtained by expanding pointer arithmetics) like
> > 
> > unsigned i, j;
> > float *p, *a, *o;
> > 
> > for (i = 0; i < n; i++)
> >   {
> >     j = 4 * i;
> >     o = (float *) j;
> >     p = a + o;
> > 
> >     *p = something;
> >   }
> > 
> > With the changes to chrec_convert, since we cannot prove that j does not
> > wrap, we set the evolution of o to chrec_dont_know. 
> 
> 
> Actually, scev_probably_wraps_p should return "doesn't wrap" for this
> case, because pointers don't wrap and the only use of this variable is
> in pointer arithmetic.

Just a followup.

We *do* actually determine it doesn't wrap when you give it the
statement.

The real problem here is that we pass a NULL statement:

/* Helper recursive function.  */

static tree
analyze_scalar_evolution_1 (struct loop *loop, tree var, tree res)
{
  tree def, type = TREE_TYPE (var);
  basic_block bb;
  struct loop *def_loop;

  if (loop == NULL)
    return chrec_dont_know;

  if (TREE_CODE (var) != SSA_NAME)
    return interpret_rhs_modify_expr (loop, NULL_TREE, var, type);
^^^^^^^^^^^^^^^ here 

(second argument).

This causes scev_probably_wrap to fail to return the correct answer.

The attached should fix the problem without the code you added, by
giving it as much of the statement as we have, which is still enough to
determine non-wrappingness in the pointer case.

Can you verify the attached patch fixes your problem?

Index: tree-scalar-evolution.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-scalar-evolution.c,v
retrieving revision 2.36.2.1
diff -u -p -r2.36.2.1 tree-scalar-evolution.c
--- tree-scalar-evolution.c	14 Sep 2005 21:22:54 -0000	2.36.2.1
+++ tree-scalar-evolution.c	20 Sep 2005 13:11:00 -0000
@@ -1653,6 +1653,9 @@ interpret_rhs_modify_expr (struct loop *
 {
   tree res, opnd10, opnd11, chrec10, chrec11;
 
+  if (at_stmt == NULL)
+    at_stmt = opnd1;
+  
   if (is_gimple_min_invariant (opnd1))
     return chrec_convert (type, opnd1, at_stmt);
 
Index: tree-ssa-loop-niter.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-niter.c,v
retrieving revision 2.38.2.2
diff -u -p -r2.38.2.2 tree-ssa-loop-niter.c
--- tree-ssa-loop-niter.c	14 Sep 2005 21:22:56 -0000	2.38.2.2
+++ tree-ssa-loop-niter.c	20 Sep 2005 13:11:00 -0000
@@ -1826,6 +1826,13 @@ scev_probably_wraps_p (tree type, tree b
   tree base_plus_step, bpsps;
   int cps, cpsps;
 
+  if (at_stmt && TREE_CODE (at_stmt) != MODIFY_EXPR 
+      && POINTER_TYPE_P (TREE_TYPE (at_stmt)))
+    {
+      *unknown_max = true;
+      return false;
+    }
+
   /* FIXME: The following code will not be used anymore once
      http://gcc.gnu.org/ml/gcc-patches/2005-06/msg02025.html is
      committed.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]