The following patch makes initial steps of reducing the amount of
TREE_OVERFLOW constants in the GIMPLE IL (there should be zero such
constants).  Tree folding in the frontends (and also later
during optimization) introduces those so the following patches
the gimplifier to drop the flag from all constants in GENERIC.
The idea is that we can eventually verify no TREE_OVERFLOW is
set form the verifier (no, I won't arrive there with this series).

TREE_OVERFLOW in the GIMPLE IL seriously confuses VRP which uses
the flag for its own purposes (ick) and relies on fold-const
setting TREE_OVERFLOW on overflows (double ick).  So the patch
also replaces as many TREE_OVERFLOW checks in tree-vrp.c with
the appropriate is_overflow_infinity check.

This also introduces a helper to drop TREE_OVERFLOW.

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

Richard.

2013-11-06  Richard Biener  <rguent...@suse.de>

        * tree.c (drop_tree_overflow): New function.
        * tree.h (drop_tree_overflow): Declare.
        * gimplify.c (gimplify_expr): Drop TREE_OVERFLOW.
        * tree-vrp.c (range_int_cst_singleton_p): Use
        is_overflow_infinity instead of testing TREE_OVERFLOW.
        (extract_range_from_assert): Likewise.
        (zero_nonzero_bits_from_vr): Likewise.
        (extract_range_basic): Likewise.
        (register_new_assert_for): Use drop_tree_overflow.
        (vrp_visit_phi_node): Likewise.

Index: gcc/tree.c
===================================================================
*** gcc/tree.c  (revision 204449)
--- gcc/tree.c  (working copy)
*************** get_tree_code_name (enum tree_code code)
*** 12542,12545 ****
--- 12542,12564 ----
    return tree_code_name[code];
  }
  
+ /* Drops the TREE_OVERFLOW flag from T.  */
+ 
+ tree
+ drop_tree_overflow (tree t)
+ {
+   gcc_checking_assert (TREE_OVERFLOW (t));
+ 
+   /* For tree codes with a sharing machinery re-build the result.  */
+   if (TREE_CODE (t) == INTEGER_CST)
+     return build_int_cst_wide (TREE_TYPE (t),
+                              TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t));
+ 
+   /* Otherwise, as all tcc_constants are possibly shared, copy the node
+      and drop the flag.  */
+   t = copy_node (t);
+   TREE_OVERFLOW (t) = 0;
+   return t;
+ }
+ 
  #include "gt-tree.h"
Index: gcc/tree.h
===================================================================
*** gcc/tree.h  (revision 204449)
--- gcc/tree.h  (working copy)
*************** extern tree get_base_address (tree t);
*** 4800,4805 ****
--- 4800,4806 ----
  extern void mark_addressable (tree);
  
  /* In tree.c.  */
+ extern tree drop_tree_overflow (tree);
  extern int tree_map_base_eq (const void *, const void *);
  extern unsigned int tree_map_base_hash (const void *);
  extern int tree_map_base_marked_p (const void *);
Index: gcc/gimplify.c
===================================================================
*** gcc/gimplify.c      (revision 204449)
--- gcc/gimplify.c      (working copy)
*************** gimplify_expr (tree *expr_p, gimple_seq
*** 7897,7902 ****
--- 7897,7906 ----
        case STRING_CST:
        case COMPLEX_CST:
        case VECTOR_CST:
+         /* Drop the overflow flag on constants, we do not want
+            that in the GIMPLE IL.  */
+         if (TREE_OVERFLOW_P (*expr_p))
+           *expr_p = drop_tree_overflow (*expr_p);
          ret = GS_ALL_DONE;
          break;
  
Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c      (revision 204449)
--- gcc/tree-vrp.c      (working copy)
*************** static inline bool
*** 892,899 ****
  range_int_cst_singleton_p (value_range_t *vr)
  {
    return (range_int_cst_p (vr)
!         && !TREE_OVERFLOW (vr->min)
!         && !TREE_OVERFLOW (vr->max)
          && tree_int_cst_equal (vr->min, vr->max));
  }
  
--- 892,899 ----
  range_int_cst_singleton_p (value_range_t *vr)
  {
    return (range_int_cst_p (vr)
!         && !is_overflow_infinity (vr->min)
!         && !is_overflow_infinity (vr->max)
          && tree_int_cst_equal (vr->min, vr->max));
  }
  
*************** extract_range_from_assert (value_range_t
*** 1741,1747 ****
         all should be optimized away above us.  */
        if ((cond_code == LT_EXPR
           && compare_values (max, min) == 0)
!         || (CONSTANT_CLASS_P (max) && TREE_OVERFLOW (max)))
        set_value_range_to_varying (vr_p);
        else
        {
--- 1741,1747 ----
         all should be optimized away above us.  */
        if ((cond_code == LT_EXPR
           && compare_values (max, min) == 0)
!         || is_overflow_infinity (max))
        set_value_range_to_varying (vr_p);
        else
        {
*************** extract_range_from_assert (value_range_t
*** 1781,1787 ****
         all should be optimized away above us.  */
        if ((cond_code == GT_EXPR
           && compare_values (min, max) == 0)
!         || (CONSTANT_CLASS_P (min) && TREE_OVERFLOW (min)))
        set_value_range_to_varying (vr_p);
        else
        {
--- 1781,1787 ----
         all should be optimized away above us.  */
        if ((cond_code == GT_EXPR
           && compare_values (min, max) == 0)
!         || is_overflow_infinity (min))
        set_value_range_to_varying (vr_p);
        else
        {
*************** zero_nonzero_bits_from_vr (value_range_t
*** 1998,2005 ****
    *may_be_nonzero = double_int_minus_one;
    *must_be_nonzero = double_int_zero;
    if (!range_int_cst_p (vr)
!       || TREE_OVERFLOW (vr->min)
!       || TREE_OVERFLOW (vr->max))
      return false;
  
    if (range_int_cst_singleton_p (vr))
--- 1998,2005 ----
    *may_be_nonzero = double_int_minus_one;
    *must_be_nonzero = double_int_zero;
    if (!range_int_cst_p (vr)
!       || is_overflow_infinity (vr->min)
!       || is_overflow_infinity (vr->max))
      return false;
  
    if (range_int_cst_singleton_p (vr))
*************** extract_range_basic (value_range_t *vr,
*** 3623,3635 ****
                    && integer_nonzerop (vr0->min))
                   || (vr0->type == VR_ANTI_RANGE
                       && integer_zerop (vr0->min)))
!                 && !TREE_OVERFLOW (vr0->min))
                mini = 1;
              /* If some high bits are known to be zero,
                 we can decrease the maximum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->max) == INTEGER_CST
!                 && !TREE_OVERFLOW (vr0->max))
                maxi = tree_floor_log2 (vr0->max) + 1;
            }
          goto bitop_builtin;
--- 3623,3635 ----
                    && integer_nonzerop (vr0->min))
                   || (vr0->type == VR_ANTI_RANGE
                       && integer_zerop (vr0->min)))
!                 && !is_overflow_infinity (vr0->min))
                mini = 1;
              /* If some high bits are known to be zero,
                 we can decrease the maximum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->max) == INTEGER_CST
!                 && !is_overflow_infinity (vr0->max))
                maxi = tree_floor_log2 (vr0->max) + 1;
            }
          goto bitop_builtin;
*************** extract_range_basic (value_range_t *vr,
*** 3664,3670 ****
                 result maximum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->min) == INTEGER_CST
!                 && !TREE_OVERFLOW (vr0->min))
                {
                  maxi = prec - 1 - tree_floor_log2 (vr0->min);
                  if (maxi != prec)
--- 3664,3670 ----
                 result maximum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->min) == INTEGER_CST
!                 && !is_overflow_infinity (vr0->min))
                {
                  maxi = prec - 1 - tree_floor_log2 (vr0->min);
                  if (maxi != prec)
*************** extract_range_basic (value_range_t *vr,
*** 3672,3678 ****
                }
              else if (vr0->type == VR_ANTI_RANGE
                       && integer_zerop (vr0->min)
!                      && !TREE_OVERFLOW (vr0->min))
                {
                  maxi = prec - 1;
                  mini = 0;
--- 3672,3678 ----
                }
              else if (vr0->type == VR_ANTI_RANGE
                       && integer_zerop (vr0->min)
!                      && !is_overflow_infinity (vr0->min))
                {
                  maxi = prec - 1;
                  mini = 0;
*************** extract_range_basic (value_range_t *vr,
*** 3683,3689 ****
                 result minimum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->max) == INTEGER_CST
!                 && !TREE_OVERFLOW (vr0->max))
                {
                  mini = prec - 1 - tree_floor_log2 (vr0->max);
                  if (mini == prec)
--- 3683,3689 ----
                 result minimum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->max) == INTEGER_CST
!                 && !is_overflow_infinity (vr0->max))
                {
                  mini = prec - 1 - tree_floor_log2 (vr0->max);
                  if (mini == prec)
*************** extract_range_basic (value_range_t *vr,
*** 3726,3732 ****
                    && integer_nonzerop (vr0->min))
                   || (vr0->type == VR_ANTI_RANGE
                       && integer_zerop (vr0->min)))
!                 && !TREE_OVERFLOW (vr0->min))
                {
                  mini = 0;
                  maxi = prec - 1;
--- 3726,3732 ----
                    && integer_nonzerop (vr0->min))
                   || (vr0->type == VR_ANTI_RANGE
                       && integer_zerop (vr0->min)))
!                 && !is_overflow_infinity (vr0->min))
                {
                  mini = 0;
                  maxi = prec - 1;
*************** extract_range_basic (value_range_t *vr,
*** 3735,3741 ****
                 we can decrease the result maximum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->max) == INTEGER_CST
!                 && !TREE_OVERFLOW (vr0->max))
                {
                  maxi = tree_floor_log2 (vr0->max);
                  /* For vr0 [0, 0] give up.  */
--- 3735,3741 ----
                 we can decrease the result maximum.  */
              if (vr0->type == VR_RANGE
                  && TREE_CODE (vr0->max) == INTEGER_CST
!                 && !is_overflow_infinity (vr0->max))
                {
                  maxi = tree_floor_log2 (vr0->max);
                  /* For vr0 [0, 0] give up.  */
*************** register_new_assert_for (tree name, tree
*** 4619,4628 ****
    /* Never build an assert comparing against an integer constant with
       TREE_OVERFLOW set.  This confuses our undefined overflow warning
       machinery.  */
!   if (TREE_CODE (val) == INTEGER_CST
!       && TREE_OVERFLOW (val))
!     val = build_int_cst_wide (TREE_TYPE (val),
!                             TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val));
  
    /* The new assertion A will be inserted at BB or E.  We need to
       determine if the new location is dominated by a previously
--- 4619,4626 ----
    /* Never build an assert comparing against an integer constant with
       TREE_OVERFLOW set.  This confuses our undefined overflow warning
       machinery.  */
!   if (TREE_OVERFLOW_P (val))
!     val = drop_tree_overflow (val);
  
    /* The new assertion A will be inserted at BB or E.  We need to
       determine if the new location is dominated by a previously
*************** vrp_visit_phi_node (gimple phi)
*** 8320,8329 ****
          else
            {
              if (is_overflow_infinity (arg))
!               {
!                 arg = copy_node (arg);
!                 TREE_OVERFLOW (arg) = 0;
!               }
  
              vr_arg.type = VR_RANGE;
              vr_arg.min = arg;
--- 8318,8324 ----
          else
            {
              if (is_overflow_infinity (arg))
!               arg = drop_tree_overflow (arg);
  
              vr_arg.type = VR_RANGE;
              vr_arg.min = arg;

Reply via email to