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]

[PATCH][1/2] Fix PR44688, set and preserve the maximum iterations of vectorizer prologue loops


Finally.

Boostrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2012-04-18  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/44688
	* cfgloop.h (record_niter_bound): Declare.
	* tree-ssa-loop-niter.c (record_niter_bound): Export.
	Update the estimation with the upper bound here...
	(estimate_numbers_of_iterations_loop): ... instead of here.
	Do not forcefully reset a recorded upper bound.
	* tree-vect-loop-manip.c (vect_do_peeling_for_alignment):
	Record the maximum number of loop iterations of the
	prologue loop.

Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c.orig	2012-04-18 10:55:55.000000000 +0200
--- gcc/tree-ssa-loop-niter.c	2012-04-18 11:39:25.368167852 +0200
*************** derive_constant_upper_bound_ops (tree ty
*** 2494,2505 ****
     of iterations.  UPPER is true if we are sure the loop iterates at most
     I_BOUND times.  */
  
! static void
  record_niter_bound (struct loop *loop, double_int i_bound, bool realistic,
  		    bool upper)
  {
!   /* Update the bounds only when there is no previous estimation, or when the current
!      estimation is smaller.  */
    if (upper
        && (!loop->any_upper_bound
  	  || double_int_ucmp (i_bound, loop->nb_iterations_upper_bound) < 0))
--- 2494,2505 ----
     of iterations.  UPPER is true if we are sure the loop iterates at most
     I_BOUND times.  */
  
! void
  record_niter_bound (struct loop *loop, double_int i_bound, bool realistic,
  		    bool upper)
  {
!   /* Update the bounds only when there is no previous estimation, or when the
!      current estimation is smaller.  */
    if (upper
        && (!loop->any_upper_bound
  	  || double_int_ucmp (i_bound, loop->nb_iterations_upper_bound) < 0))
*************** record_niter_bound (struct loop *loop, d
*** 2514,2519 ****
--- 2514,2527 ----
        loop->any_estimate = true;
        loop->nb_iterations_estimate = i_bound;
      }
+ 
+   /* If an upper bound is smaller than the realistic estimate of the
+      number of iterations, use the upper bound instead.  */
+   if (loop->any_upper_bound
+       && loop->any_estimate
+       && double_int_ucmp (loop->nb_iterations_upper_bound,
+ 			  loop->nb_iterations_estimate) < 0)
+     loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
  }
  
  /* Records that AT_STMT is executed at most BOUND + 1 times in LOOP.  IS_EXIT
*************** estimate_numbers_of_iterations_loop (str
*** 2962,2969 ****
    /* Give up if we already have tried to compute an estimation.  */
    if (loop->estimate_state != EST_NOT_COMPUTED)
      return;
    loop->estimate_state = EST_AVAILABLE;
!   loop->any_upper_bound = false;
    loop->any_estimate = false;
  
    exits = get_loop_exit_edges (loop);
--- 2970,2978 ----
    /* Give up if we already have tried to compute an estimation.  */
    if (loop->estimate_state != EST_NOT_COMPUTED)
      return;
+ 
    loop->estimate_state = EST_AVAILABLE;
!   /* Force estimate compuation but leave any existing upper bound in place.  */
    loop->any_estimate = false;
  
    exits = get_loop_exit_edges (loop);
*************** estimate_numbers_of_iterations_loop (str
*** 2994,3007 ****
        bound = gcov_type_to_double_int (nit);
        record_niter_bound (loop, bound, true, false);
      }
- 
-   /* If an upper bound is smaller than the realistic estimate of the
-      number of iterations, use the upper bound instead.  */
-   if (loop->any_upper_bound
-       && loop->any_estimate
-       && double_int_ucmp (loop->nb_iterations_upper_bound,
- 			  loop->nb_iterations_estimate) < 0)
-     loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
  }
  
  /* Sets NIT to the estimated number of executions of the latch of the
--- 3003,3008 ----
Index: gcc/tree-vect-loop-manip.c
===================================================================
*** gcc/tree-vect-loop-manip.c.orig	2012-04-17 12:59:22.000000000 +0200
--- gcc/tree-vect-loop-manip.c	2012-04-18 11:39:25.368167852 +0200
*************** vect_do_peeling_for_alignment (loop_vec_
*** 2167,2172 ****
--- 2167,2173 ----
    struct loop *new_loop;
    unsigned int th = 0;
    int min_profitable_iters;
+   int max_iter;
  
    if (vect_print_dump_info (REPORT_DETAILS))
      fprintf (vect_dump, "=== vect_do_peeling_for_alignment ===");
*************** vect_do_peeling_for_alignment (loop_vec_
*** 2192,2197 ****
--- 2193,2203 ----
  #ifdef ENABLE_CHECKING
    slpeel_verify_cfg_after_peeling (new_loop, loop);
  #endif
+   max_iter = MAX (LOOP_VINFO_VECT_FACTOR (loop_vinfo) - 1, (int) th);
+   record_niter_bound (new_loop, shwi_to_double_int (max_iter), false, true);
+   if (dump_file && (dump_flags & TDF_DETAILS))
+     fprintf (dump_file, "Setting upper bound of nb iterations for prologue "
+ 	     "loop to %d\n", max_iter);
  
    /* Update number of times loop executes.  */
    n_iters = LOOP_VINFO_NITERS (loop_vinfo);
Index: gcc/cfgloop.h
===================================================================
*** gcc/cfgloop.h.orig	2012-04-18 10:55:55.000000000 +0200
--- gcc/cfgloop.h	2012-04-18 11:39:49.936166250 +0200
*************** extern unsigned expected_loop_iterations
*** 279,284 ****
--- 279,285 ----
  extern rtx doloop_condition_get (rtx);
  
  void estimate_numbers_of_iterations_loop (struct loop *);
+ void record_niter_bound (struct loop *, double_int, bool, bool);
  bool estimated_loop_iterations (struct loop *, double_int *);
  bool max_loop_iterations (struct loop *, double_int *);
  HOST_WIDE_INT estimated_loop_iterations_int (struct loop *);


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