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: [lno] some cleanups for scev


Hello,

this patch fixes some problems introduced by previous cleanups.

-- loop invariants are now again kept in symbolic form
-- compute_scalar_evolution_after_loop renamed back to
   compute_overall_effect_of_inner_loop.
-- compute_scalar_evolution_in_loop computes the evolution of expression
   returned by compute_overall_effect_of_inner_loop.
-- chrec_contains_symbols_defined_in_loop checks for non-strict
   nestedness of loops correctly
-- analyze_scalar_evolution_1 uses compute_scalar_evolution_in_loop
   when possible.

This patch introduces a regression in
gcc.dg/tree-ssa-chrec/ssa-chrec-27.c, since loop invariants kept in
symbolic form and instantiate_parameters does not seem to handle this
correctly; I will send a followup patch for this.

Zdenek

Index: ChangeLog.lno
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/ChangeLog.lno,v
retrieving revision 1.1.2.143
diff -c -3 -p -r1.1.2.143 ChangeLog.lno
*** ChangeLog.lno	22 Apr 2004 18:04:11 -0000	1.1.2.143
--- ChangeLog.lno	23 Apr 2004 09:43:40 -0000
***************
*** 1,3 ****
--- 1,19 ----
+ 2004-04-23  Zdenek Dvorak  <rakdver@atrey.karlin.mff.cuni.cz>
+ 
+ 	* tree-scalar-evolution.c (analyze_scalar_evolution_1): Keep
+ 	loop invariants in symbolic form.  Use
+ 	compute_scalar_evolution_in_loop for expressions defined in subloops.
+ 	(chrec_contains_symbols_defined_in_loop): Check for non-strict
+ 	nestedness.
+ 	(compute_scalar_evolution_after_loop): Renamed back to
+ 	compute_overall_effect_of_inner_loop.
+ 	(follow_ssa_edge_inner_loop_phi, interpret_loop_phi):
+ 	Changed due to the renaming.
+ 	(get_scalar_evolution): Return chrec_not_analyzed_yet for complicated
+ 	expressions.
+ 	(compute_scalar_evolution_in_loop): Compute the evolution of the
+ 	expression returned by compute_overall_effect_of_inner_loop.
+ 
  2004-04-22  Sebastian Pop  <sebastian.pop@ensmp.fr>
  
  	* tree-elim-check.c (prove_truth_value_gt, prove_truth_value_lt, 
Index: tree-scalar-evolution.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-scalar-evolution.c,v
retrieving revision 1.1.2.40
diff -c -3 -p -r1.1.2.40 tree-scalar-evolution.c
*** tree-scalar-evolution.c	22 Apr 2004 18:04:11 -0000	1.1.2.40
--- tree-scalar-evolution.c	23 Apr 2004 09:43:41 -0000
*************** Software Foundation, 59 Temple Place - S
*** 264,269 ****
--- 264,271 ----
  #include "tree-vectorizer.h"
  #include "flags.h"
  
+ static tree analyze_scalar_evolution_1 (struct loop *, tree, tree);
+ 
  /* The cached information about a ssa name VAR, claiming that inside LOOP,
     the value of VAR can be expressed as CHREC.  */
  
*************** chrec_contains_symbols_defined_in_loop (
*** 389,395 ****
        if (def_loop == NULL)
  	return false;
  
!       if (flow_loop_nested_p (loop, def_loop))
  	return true;
  
        return false;
--- 391,397 ----
        if (def_loop == NULL)
  	return false;
  
!       if (loop == def_loop || flow_loop_nested_p (loop, def_loop))
  	return true;
  
        return false;
*************** loop_phi_node_p (tree phi)
*** 469,475 ****
  */
   
  static tree 
! compute_scalar_evolution_after_loop (struct loop *loop, tree evolution_fn)
  {
    bool val = false;
  
--- 471,477 ----
  */
   
  static tree 
! compute_overall_effect_of_inner_loop (struct loop *loop, tree evolution_fn)
  {
    bool val = false;
  
*************** compute_scalar_evolution_after_loop (str
*** 502,508 ****
  	      res = chrec_apply (inner_loop->num, evolution_fn, nb_iter);
  	      
  	      /* Continue the computation until ending on a parent of LOOP. */
! 	      return compute_scalar_evolution_after_loop (loop, res);
  	    }
  	}
        else
--- 504,510 ----
  	      res = chrec_apply (inner_loop->num, evolution_fn, nb_iter);
  	      
  	      /* Continue the computation until ending on a parent of LOOP. */
! 	      return compute_overall_effect_of_inner_loop (loop, res);
  	    }
  	}
        else
*************** get_scalar_evolution (tree scalar)
*** 657,663 ****
        break;
  
      default:
!       res = chrec_top;
        break;
      }
    
--- 659,665 ----
        break;
  
      default:
!       res = chrec_not_analyzed_yet;
        break;
      }
    
*************** follow_ssa_edge_inner_loop_phi (struct l
*** 2327,2333 ****
      }
  
    /* Otherwise, compute the overall effect of the inner loop.  */
!   ev = compute_scalar_evolution_after_loop (loop, ev);
    return follow_ssa_edge_in_rhs (outer_loop, ev, halting_phi,
  				 evolution_of_loop);
  }
--- 2329,2335 ----
      }
  
    /* Otherwise, compute the overall effect of the inner loop.  */
!   ev = compute_overall_effect_of_inner_loop (loop, ev);
    return follow_ssa_edge_in_rhs (outer_loop, ev, halting_phi,
  				 evolution_of_loop);
  }
*************** interpret_loop_phi (struct loop *loop, t
*** 2550,2556 ****
        subloop = superloop_at_depth (phi_loop, loop->depth + 1);
  
        /* Interpret the subloop.  */
!       res = compute_scalar_evolution_after_loop (subloop, evolution_fn);
        return res;
      }
  
--- 2552,2558 ----
        subloop = superloop_at_depth (phi_loop, loop->depth + 1);
  
        /* Interpret the subloop.  */
!       res = compute_overall_effect_of_inner_loop (subloop, evolution_fn);
        return res;
      }
  
*************** compute_scalar_evolution_in_loop (struct
*** 2681,2723 ****
  				  struct loop *def_loop, 
  				  tree ev)
  {
    if (def_loop == wrto_loop)
      return ev;
  
    def_loop = superloop_at_depth (def_loop, wrto_loop->depth + 1);
!   return compute_scalar_evolution_after_loop (def_loop, ev);
  }
  
  /* 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;
  
    if (loop == NULL)
!     {
!       res = chrec_top;
!       set_scalar_evolution (var, res);
!       return res;
!     }
  
    if (TREE_CODE (var) != SSA_NAME)
!     {
!       if (res != chrec_top)
! 	/* Keep the symbolic form.  */
! 	return res;
! 
!       res = interpret_rhs_modify_expr (loop, var, type);
!       set_scalar_evolution (var, res);
!       return res;
!     }
  
    def = SSA_NAME_DEF_STMT (var);
    bb = bb_for_stmt (def);
  
!   if (bb == NULL)
      {
        /* Keep the symbolic form.  */
        res = var;
--- 2683,2719 ----
  				  struct loop *def_loop, 
  				  tree ev)
  {
+   tree res;
    if (def_loop == wrto_loop)
      return ev;
  
    def_loop = superloop_at_depth (def_loop, wrto_loop->depth + 1);
!   res = compute_overall_effect_of_inner_loop (def_loop, ev);
! 
!   return analyze_scalar_evolution_1 (wrto_loop, res, chrec_not_analyzed_yet);
  }
  
  /* 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_top;
  
    if (TREE_CODE (var) != SSA_NAME)
!     return interpret_rhs_modify_expr (loop, var, type);
  
    def = SSA_NAME_DEF_STMT (var);
    bb = bb_for_stmt (def);
+   def_loop = bb ? bb->loop_father : NULL;
  
!   if (bb == NULL
!       || !flow_bb_inside_loop_p (loop, bb))
      {
        /* Keep the symbolic form.  */
        res = var;
*************** analyze_scalar_evolution_1 (struct loop 
*** 2726,2799 ****
  
    if (res != chrec_not_analyzed_yet)
      {
!       if (res == chrec_top)
! 	{
! 	  /* Keep the symbolic form.  */
! 	  res = var;
! 	  goto set_and_end;
! 	}
! 
!       else if (res == var)
! 	return var;
! 
!       else if (loop != bb->loop_father)
  	res = compute_scalar_evolution_in_loop 
! 	  (find_common_loop (loop, bb->loop_father), bb->loop_father, res);
  
!       return res;
      }
  
!   if (!flow_bb_inside_loop_p (loop, bb))
      {
!       struct loop *def_loop = loop_of_stmt (def);
!       
!       if (def_loop == NULL)
! 	{
! 	  /* A parameter that has to be kept in symbolic form.  */
! 	  res = var;
! 	  goto set_and_end;
! 	}
!       else
! 	/* Analyze the variable in the loop of its definition, then
! 	   compute the evolution in the demanded loop.  */
! 	{
! 	  res = analyze_scalar_evolution_1 (def_loop, var, res);
! 	  return compute_scalar_evolution_in_loop 
! 	    (find_common_loop (loop, bb->loop_father), bb->loop_father, res);
! 	}
      }
  
    switch (TREE_CODE (def))
      {
      case MODIFY_EXPR:
!       {
! 	struct loop *def_loop = loop_of_stmt (def);
! 	if (loop != def_loop)
! 	  analyze_scalar_evolution_1 (def_loop, var, res);
! 	res = interpret_rhs_modify_expr (loop, TREE_OPERAND (def, 1), type);
! 	break;
!       }
  
      case PHI_NODE:
!       {
! 	struct loop *def_loop = loop_of_stmt (def);
! 	if (loop != def_loop)
! 	  analyze_scalar_evolution_1 (def_loop, var, res);
! 
! 	if (loop_phi_node_p (def))
! 	  res = interpret_loop_phi (loop, def);
! 	else
! 	  res = interpret_condition_phi (loop, def);
! 	break;
!       }
  
      default:
        res = chrec_top;
        break;
      }
  
!  set_and_end:;
!   if (loop == loop_of_stmt (def))
      set_scalar_evolution (var, res);
  
    return res;
--- 2722,2767 ----
  
    if (res != chrec_not_analyzed_yet)
      {
!       if (loop != bb->loop_father)
  	res = compute_scalar_evolution_in_loop 
! 	    (find_common_loop (loop, bb->loop_father), bb->loop_father, res);
  
!       goto set_and_end;
      }
  
!   if (loop != def_loop)
      {
!       res = analyze_scalar_evolution_1 (def_loop, var, chrec_not_analyzed_yet);
!       res = compute_scalar_evolution_in_loop (loop, def_loop, res);
! 
!       goto set_and_end;
      }
  
    switch (TREE_CODE (def))
      {
      case MODIFY_EXPR:
!       res = interpret_rhs_modify_expr (loop, TREE_OPERAND (def, 1), type);
!       break;
  
      case PHI_NODE:
!       if (loop_phi_node_p (def))
! 	res = interpret_loop_phi (loop, def);
!       else
! 	res = interpret_condition_phi (loop, def);
!       break;
  
      default:
        res = chrec_top;
        break;
      }
  
!  set_and_end:
! 
!   /* Keep the symbolic form.  */
!   if (res == chrec_top)
!     res = var;
! 
!   if (loop == def_loop)
      set_scalar_evolution (var, res);
  
    return res;


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