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] Fix PR26859


The following patch fixes PR26859 by avoiding a division by zero.
Part of the problem is that convert returns a step for which it sets the
overflow flag when converting unsigned ffffffe to int -2.  The patch resets
the overflow flag that has no sense for the step of a sequence.
Bootstrapped and tested on amd64-linux.  Ok for trunk?

Sebastian

	PR tree-optimization/26859
	* tree-ssa-loop-niter.c (infer_loop_bounds_from_undefined): Avoid
	division by zero.
	(convert_step): Remove TREE_OVERFLOW and TREE_CONSTANT_OVERFLOW flags
	for the step after fold_convert.
2006-03-28  Sebastian Pop  <pop@cri.ensmp.fr>

	PR tree-optimization/26859
	* tree-ssa-loop-niter.c (infer_loop_bounds_from_undefined): Avoid
	division by zero.
	(convert_step): Remove TREE_OVERFLOW and TREE_CONSTANT_OVERFLOW flags
	for the step after fold_convert.

Index: tree-ssa-loop-niter.c
===================================================================
*** tree-ssa-loop-niter.c	(revision 112485)
--- tree-ssa-loop-niter.c	(working copy)
*************** infer_loop_bounds_from_undefined (struct
*** 1582,1590 ****
  		      diff = fold_build2 (MINUS_EXPR, utype,
  					  TYPE_MAX_VALUE (type), init);
  
! 		    estimation = fold_build2 (CEIL_DIV_EXPR, utype, diff,
! 					      step);
! 		    record_estimate (loop, estimation, boolean_true_node, stmt);
  		  }
  
  		break;
--- 1582,1594 ----
  		      diff = fold_build2 (MINUS_EXPR, utype,
  					  TYPE_MAX_VALUE (type), init);
  
! 		    if (!integer_zerop (step))
! 		      {
! 			estimation = fold_build2 (CEIL_DIV_EXPR, utype, diff,
! 						  step);
! 			record_estimate (loop, estimation, boolean_true_node,
! 					 stmt);
! 		      }
  		  }
  
  		break;
*************** tree
*** 2090,2096 ****
  convert_step (struct loop *loop, tree new_type, tree base, tree step,
  	      tree at_stmt)
  {
!   tree base_type;
  
    if (chrec_contains_undetermined (base)
        || chrec_contains_undetermined (step))
--- 2094,2100 ----
  convert_step (struct loop *loop, tree new_type, tree base, tree step,
  	      tree at_stmt)
  {
!   tree res, base_type;
  
    if (chrec_contains_undetermined (base)
        || chrec_contains_undetermined (step))
*************** convert_step (struct loop *loop, tree ne
*** 2100,2111 ****
  
    /* When not using wrapping arithmetic, signed types don't wrap.  */
    if (!flag_wrapv && !TYPE_UNSIGNED (base_type))
!     return fold_convert (new_type, step);
  
    if (TYPE_PRECISION (new_type) > TYPE_PRECISION (base_type))
      return convert_step_widening (loop, new_type, base, step, at_stmt);
  
!   return fold_convert (new_type, step);
  }
  
  /* Frees the information on upper bounds on numbers of iterations of LOOP.  */
--- 2104,2125 ----
  
    /* When not using wrapping arithmetic, signed types don't wrap.  */
    if (!flag_wrapv && !TYPE_UNSIGNED (base_type))
!     goto do_convert_step;
  
    if (TYPE_PRECISION (new_type) > TYPE_PRECISION (base_type))
      return convert_step_widening (loop, new_type, base, step, at_stmt);
  
!  do_convert_step:
!   
!   res = fold_convert (new_type, step);
! 
!   if (TREE_CODE (res) == INTEGER_CST)
!     {
!       TREE_OVERFLOW (res) = 0;
!       TREE_CONSTANT_OVERFLOW (res) = 0;
!     }
! 
!   return res;
  }
  
  /* Frees the information on upper bounds on numbers of iterations of LOOP.  */


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