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] Make adjust_range_with_scev produce only simple bounds


Hello,

some parts of tree-vrp (for example, compare_values function) assume
that the bounds of ranges are simple expressions -- constants or ssa
names,  possibly offsetted by a constant.  However,
adjust_range_with_scev uses values coming from analyze_scalar_evolution
as these bounds, which causes problems, since analyze_scalar_evolution
may return an arbitrary expression.  I do not have a testcase for
mainline, but this causes a bootstrap failure with a patch I am
currently working on.  This patch makes us ensure that the value
we are going to use as a bound is simple.

Bootstrapped & regtested on x86_64.

Zdenek

	* tree-vrp.c (valid_value_p): New function.
	(adjust_range_with_scev): Fail if the value of bound is not
	simple.

Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 113891)
--- tree-vrp.c	(working copy)
*************** vrp_expr_computes_nonzero (tree expr)
*** 409,414 ****
--- 409,430 ----
    return false;
  }
  
+ /* Returns true if EXPR is a valid value (as expected by compare_values) --
+    a gimple invariant, or SSA_NAME +- CST.  */
+ 
+ static bool
+ valid_value_p (tree expr)
+ {
+   if (TREE_CODE (expr) == SSA_NAME)
+     return true;
+ 
+   if (TREE_CODE (expr) == PLUS_EXPR
+       || TREE_CODE (expr) == MINUS_EXPR)
+     return (TREE_CODE (TREE_OPERAND (expr, 0)) == SSA_NAME
+ 	    && TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST);
+   
+   return is_gimple_min_invariant (expr);
+ }
  
  /* Compare two values VAL1 and VAL2.  Return
     
*************** adjust_range_with_scev (value_range_t *v
*** 1974,1982 ****
    step = evolution_part_in_loop_num (chrec, loop->num);
  
    /* If STEP is symbolic, we can't know whether INIT will be the
!      minimum or maximum value in the range.  */
    if (step == NULL_TREE
!       || !is_gimple_min_invariant (step))
      return;
  
    /* Do not adjust ranges when chrec may wrap.  */
--- 1990,2001 ----
    step = evolution_part_in_loop_num (chrec, loop->num);
  
    /* If STEP is symbolic, we can't know whether INIT will be the
!      minimum or maximum value in the range.  Also, unless INIT is
!      a simple expression, compare_values and possibly other functions
!      in tree-vrp won't be able to handle it.  */
    if (step == NULL_TREE
!       || !is_gimple_min_invariant (step)
!       || !valid_value_p (init))
      return;
  
    /* Do not adjust ranges when chrec may wrap.  */


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