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] Use all bells and whistles for number of iteration analysis in VRP


This patch reverts the change originally done when adding 
number-of-iteration analysis uses to VRP, to have a flag
to toggle whether to derive number of iterations from undefined
behavior.  To be able to do so one error in VRP has to be fixed - we
have to check for the number of stmt executions, not for the number
of latch block executions.  Otherwise we miscompile IRA during bootstrap.

Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu.

With this I can finally make the max loop bound preserved and
set it from loop version producers.  Yay.

Richard.

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

	* cfgloop.h (estimate_numbers_of_iterations_loop): Remove
	use_undefined_p parameter.
	* tree-flow.h (estimate_numbers_of_iterations): Likewise.
	* tree-ssa-loop-niter.c (estimate_numbers_of_iterations_loop):
	Likewise.
	(estimate_numbers_of_iterations): Likewise.
	(estimated_loop_iterations): Adjust.
	(max_loop_iterations): Likewise.
	(scev_probably_wraps_p): Likewise.
	* tree-ssa-loop.c (tree_ssa_loop_bounds): Likewise.
	* tree-vrp.c (adjust_range_with_scev): Use max_stmt_executions,
	not max_loop_iterations.
	(execute_vrp): Remove explicit number of iterations estimation.

Index: gcc/cfgloop.h
===================================================================
*** gcc/cfgloop.h	(revision 186526)
--- gcc/cfgloop.h	(working copy)
*************** gcov_type expected_loop_iterations_unbou
*** 278,284 ****
  extern unsigned expected_loop_iterations (const struct loop *);
  extern rtx doloop_condition_get (rtx);
  
! void estimate_numbers_of_iterations_loop (struct loop *, 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 *);
--- 278,284 ----
  extern unsigned expected_loop_iterations (const struct loop *);
  extern rtx doloop_condition_get (rtx);
  
! void estimate_numbers_of_iterations_loop (struct loop *);
  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: gcc/tree-flow.h
===================================================================
*** gcc/tree-flow.h	(revision 186527)
--- gcc/tree-flow.h	(working copy)
*************** bool number_of_iterations_exit (struct l
*** 685,691 ****
  tree find_loop_niter (struct loop *, edge *);
  tree loop_niter_by_eval (struct loop *, edge);
  tree find_loop_niter_by_eval (struct loop *, edge *);
! void estimate_numbers_of_iterations (bool);
  bool scev_probably_wraps_p (tree, tree, gimple, struct loop *, bool);
  bool convert_affine_scev (struct loop *, tree, tree *, tree *, gimple, bool);
  
--- 685,691 ----
  tree find_loop_niter (struct loop *, edge *);
  tree loop_niter_by_eval (struct loop *, edge);
  tree find_loop_niter_by_eval (struct loop *, edge *);
! void estimate_numbers_of_iterations (void);
  bool scev_probably_wraps_p (tree, tree, gimple, struct loop *, bool);
  bool convert_affine_scev (struct loop *, tree, tree *, tree *, gimple, bool);
  
Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c	(revision 186527)
--- gcc/tree-ssa-loop-niter.c	(working copy)
*************** gcov_type_to_double_int (gcov_type val)
*** 2950,2956 ****
     is true also use estimates derived from undefined behavior.  */
  
  void
! estimate_numbers_of_iterations_loop (struct loop *loop, bool use_undefined_p)
  {
    VEC (edge, heap) *exits;
    tree niter, type;
--- 2950,2956 ----
     is true also use estimates derived from undefined behavior.  */
  
  void
! estimate_numbers_of_iterations_loop (struct loop *loop)
  {
    VEC (edge, heap) *exits;
    tree niter, type;
*************** estimate_numbers_of_iterations_loop (str
*** 2984,2991 ****
      }
    VEC_free (edge, heap, exits);
  
!   if (use_undefined_p)
!     infer_loop_bounds_from_undefined (loop);
  
    /* If we have a measured profile, use it to estimate the number of
       iterations.  */
--- 2984,2990 ----
      }
    VEC_free (edge, heap, exits);
  
!   infer_loop_bounds_from_undefined (loop);
  
    /* If we have a measured profile, use it to estimate the number of
       iterations.  */
*************** estimate_numbers_of_iterations_loop (str
*** 3013,3019 ****
  bool
  estimated_loop_iterations (struct loop *loop, double_int *nit)
  {
!   estimate_numbers_of_iterations_loop (loop, true);
    if (!loop->any_estimate)
      return false;
  
--- 3012,3018 ----
  bool
  estimated_loop_iterations (struct loop *loop, double_int *nit)
  {
!   estimate_numbers_of_iterations_loop (loop);
    if (!loop->any_estimate)
      return false;
  
*************** estimated_loop_iterations (struct loop *
*** 3028,3034 ****
  bool
  max_loop_iterations (struct loop *loop, double_int *nit)
  {
!   estimate_numbers_of_iterations_loop (loop, true);
    if (!loop->any_upper_bound)
      return false;
  
--- 3027,3033 ----
  bool
  max_loop_iterations (struct loop *loop, double_int *nit)
  {
!   estimate_numbers_of_iterations_loop (loop);
    if (!loop->any_upper_bound)
      return false;
  
*************** estimated_stmt_executions (struct loop *
*** 3155,3161 ****
  /* Records estimates on numbers of iterations of loops.  */
  
  void
! estimate_numbers_of_iterations (bool use_undefined_p)
  {
    loop_iterator li;
    struct loop *loop;
--- 3154,3160 ----
  /* Records estimates on numbers of iterations of loops.  */
  
  void
! estimate_numbers_of_iterations (void)
  {
    loop_iterator li;
    struct loop *loop;
*************** estimate_numbers_of_iterations (bool use
*** 3166,3172 ****
  
    FOR_EACH_LOOP (li, loop, 0)
      {
!       estimate_numbers_of_iterations_loop (loop, use_undefined_p);
      }
  
    fold_undefer_and_ignore_overflow_warnings ();
--- 3165,3171 ----
  
    FOR_EACH_LOOP (li, loop, 0)
      {
!       estimate_numbers_of_iterations_loop (loop);
      }
  
    fold_undefer_and_ignore_overflow_warnings ();
*************** scev_probably_wraps_p (tree base, tree s
*** 3362,3368 ****
  
    valid_niter = fold_build2 (FLOOR_DIV_EXPR, unsigned_type, delta, step_abs);
  
!   estimate_numbers_of_iterations_loop (loop, true);
    for (bound = loop->bounds; bound; bound = bound->next)
      {
        if (n_of_executions_at_most (at_stmt, bound, valid_niter))
--- 3361,3367 ----
  
    valid_niter = fold_build2 (FLOOR_DIV_EXPR, unsigned_type, delta, step_abs);
  
!   estimate_numbers_of_iterations_loop (loop);
    for (bound = loop->bounds; bound; bound = bound->next)
      {
        if (n_of_executions_at_most (at_stmt, bound, valid_niter))
Index: gcc/tree-ssa-loop.c
===================================================================
*** gcc/tree-ssa-loop.c	(revision 186526)
--- gcc/tree-ssa-loop.c	(working copy)
*************** tree_ssa_loop_bounds (void)
*** 420,426 ****
    if (number_of_loops () <= 1)
      return 0;
  
!   estimate_numbers_of_iterations (true);
    scev_reset ();
    return 0;
  }
--- 420,426 ----
    if (number_of_loops () <= 1)
      return 0;
  
!   estimate_numbers_of_iterations ();
    scev_reset ();
    return 0;
  }
Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c	(revision 186526)
--- gcc/tree-vrp.c	(working copy)
*************** adjust_range_with_scev (value_range_t *v
*** 3420,3426 ****
      {
        double_int nit;
  
!       if (max_loop_iterations (loop, &nit))
  	{
  	  value_range_t maxvr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
  	  double_int dtmp;
--- 3420,3426 ----
      {
        double_int nit;
  
!       if (max_stmt_executions (loop, &nit))
  	{
  	  value_range_t maxvr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
  	  double_int dtmp;
*************** execute_vrp (void)
*** 8272,8283 ****
  
    insert_range_assertions ();
  
-   /* Estimate number of iterations - but do not use undefined behavior
-      for this.  We can't do this lazily as other functions may compute
-      this using undefined behavior.  */
-   free_numbers_of_iterations_estimates ();
-   estimate_numbers_of_iterations (false);
- 
    to_remove_edges = VEC_alloc (edge, heap, 10);
    to_update_switch_stmts = VEC_alloc (switch_update, heap, 5);
    threadedge_initialize_values ();
--- 8272,8277 ----


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