PR c++/68795: fix uninitialized close_paren_loc in cp_parser_postfix_expression
[gcc.git] / gcc / tree-vrp.c
index 22587d00bc564239448c099f56ad723df9a076d4..920a9b1818dabc0521d62b2c74a10c2973e3c1a0 100644 (file)
@@ -1,5 +1,5 @@
 /* Support routines for Value Range Propagation (VRP).
-   Copyright (C) 2005-2015 Free Software Foundation, Inc.
+   Copyright (C) 2005-2016 Free Software Foundation, Inc.
    Contributed by Diego Novillo <dnovillo@redhat.com>.
 
 This file is part of GCC.
@@ -21,81 +21,47 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "flags.h"
-#include "hash-set.h"
-#include "machmode.h"
-#include "vec.h"
-#include "double-int.h"
-#include "input.h"
-#include "alias.h"
-#include "symtab.h"
-#include "wide-int.h"
-#include "inchash.h"
+#include "backend.h"
+#include "insn-codes.h"
+#include "rtl.h"
 #include "tree.h"
+#include "gimple.h"
+#include "cfghooks.h"
+#include "tree-pass.h"
+#include "ssa.h"
+#include "optabs-tree.h"
+#include "gimple-pretty-print.h"
+#include "diagnostic-core.h"
+#include "flags.h"
 #include "fold-const.h"
 #include "stor-layout.h"
 #include "calls.h"
-#include "predict.h"
-#include "hard-reg-set.h"
-#include "function.h"
-#include "dominance.h"
-#include "cfg.h"
 #include "cfganal.h"
-#include "basic-block.h"
-#include "tree-ssa-alias.h"
-#include "internal-fn.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-expr.h"
-#include "is-a.h"
-#include "gimple.h"
 #include "gimple-iterator.h"
 #include "gimple-walk.h"
-#include "gimple-ssa.h"
 #include "tree-cfg.h"
-#include "tree-phinodes.h"
-#include "ssa-iterators.h"
-#include "stringpool.h"
-#include "tree-ssanames.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-ssa-loop-niter.h"
 #include "tree-ssa-loop.h"
 #include "tree-into-ssa.h"
 #include "tree-ssa.h"
-#include "tree-pass.h"
-#include "tree-dump.h"
-#include "gimple-pretty-print.h"
-#include "diagnostic-core.h"
 #include "intl.h"
 #include "cfgloop.h"
 #include "tree-scalar-evolution.h"
 #include "tree-ssa-propagate.h"
 #include "tree-chrec.h"
 #include "tree-ssa-threadupdate.h"
-#include "hashtab.h"
-#include "rtl.h"
-#include "statistics.h"
-#include "real.h"
-#include "fixed-value.h"
-#include "insn-config.h"
-#include "expmed.h"
-#include "dojump.h"
-#include "explow.h"
-#include "emit-rtl.h"
-#include "varasm.h"
-#include "stmt.h"
-#include "expr.h"
-#include "insn-codes.h"
-#include "optabs.h"
 #include "tree-ssa-scopedtables.h"
 #include "tree-ssa-threadedge.h"
-
-
+#include "omp-low.h"
+#include "target.h"
+#include "case-cfn-macros.h"
 
 /* Range of values that can be associated with an SSA_NAME after VRP
    has executed.  */
-struct value_range_d
+struct value_range
 {
   /* Lattice value represented by this range.  */
   enum value_range_type type;
@@ -119,8 +85,6 @@ struct value_range_d
   bitmap equiv;
 };
 
-typedef struct value_range_d value_range_t;
-
 #define VR_INITIALIZER { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }
 
 /* Set of SSA names found live during the RPO traversal of the function
@@ -139,8 +103,8 @@ live_on_edge (edge e, tree name)
 /* Local functions.  */
 static int compare_values (tree val1, tree val2);
 static int compare_values_warnv (tree val1, tree val2, bool *);
-static void vrp_meet (value_range_t *, value_range_t *);
-static void vrp_intersect_ranges (value_range_t *, value_range_t *);
+static void vrp_meet (value_range *, value_range *);
+static void vrp_intersect_ranges (value_range *, value_range *);
 static tree vrp_evaluate_conditional_warnv_with_ops (enum tree_code,
                                                     tree, tree, bool, bool *,
                                                     bool *);
@@ -150,7 +114,7 @@ static tree vrp_evaluate_conditional_warnv_with_ops (enum tree_code,
    SSA name may have more than one assertion associated with it, these
    locations are kept in a linked list attached to the corresponding
    SSA name.  */
-struct assert_locus_d
+struct assert_locus
 {
   /* Basic block where the assertion would be inserted.  */
   basic_block bb;
@@ -172,11 +136,9 @@ struct assert_locus_d
   tree expr;
 
   /* Next node in the linked list.  */
-  struct assert_locus_d *next;
+  assert_locus *next;
 };
 
-typedef struct assert_locus_d *assert_locus_t;
-
 /* If bit I is present, it means that SSA name N_i has a list of
    assertions that should be inserted in the IL.  */
 static bitmap need_assert_for;
@@ -184,12 +146,12 @@ static bitmap need_assert_for;
 /* Array of locations lists where to insert assertions.  ASSERTS_FOR[I]
    holds a list of ASSERT_LOCUS_T nodes that describe where
    ASSERT_EXPRs for SSA name N_I should be inserted.  */
-static assert_locus_t *asserts_for;
+static assert_locus **asserts_for;
 
 /* Value range array.  After propagation, VR_VALUE[I] holds the range
    of values that SSA name N_I may take.  */
 static unsigned num_vr_values;
-static value_range_t **vr_value;
+static value_range **vr_value;
 static bool values_propagated;
 
 /* For a PHI node which sets SSA name N_I, VR_COUNTS[I] holds the
@@ -197,10 +159,10 @@ static bool values_propagated;
    node.  */
 static int *vr_phi_edge_counts;
 
-typedef struct {
+struct switch_update {
   gswitch *stmt;
   tree vec;
-} switch_update;
+};
 
 static vec<edge> to_remove_edges;
 static vec<switch_update> to_update_switch_stmts;
@@ -278,9 +240,7 @@ static inline bool
 supports_overflow_infinity (const_tree type)
 {
   tree min = vrp_val_min (type), max = vrp_val_max (type);
-#ifdef ENABLE_CHECKING
-  gcc_assert (needs_overflow_infinity (type));
-#endif
+  gcc_checking_assert (needs_overflow_infinity (type));
   return (min != NULL_TREE
          && CONSTANT_CLASS_P (min)
          && max != NULL_TREE
@@ -350,7 +310,7 @@ is_overflow_infinity (const_tree val)
 /* Return whether STMT has a constant rhs that is_overflow_infinity. */
 
 static inline bool
-stmt_overflow_infinity (gimple stmt)
+stmt_overflow_infinity (gimple *stmt)
 {
   if (is_gimple_assign (stmt)
       && get_gimple_rhs_class (gimple_assign_rhs_code (stmt)) ==
@@ -379,72 +339,10 @@ avoid_overflow_infinity (tree val)
 }
 
 
-/* Return true if ARG is marked with the nonnull attribute in the
-   current function signature.  */
-
-static bool
-nonnull_arg_p (const_tree arg)
-{
-  tree t, attrs, fntype;
-  unsigned HOST_WIDE_INT arg_num;
-
-  gcc_assert (TREE_CODE (arg) == PARM_DECL && POINTER_TYPE_P (TREE_TYPE (arg)));
-
-  /* The static chain decl is always non null.  */
-  if (arg == cfun->static_chain_decl)
-    return true;
-
-  /* THIS argument of method is always non-NULL.  */
-  if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
-      && arg == DECL_ARGUMENTS (current_function_decl)
-      && flag_delete_null_pointer_checks)
-    return true;
-
-  /* Values passed by reference are always non-NULL.  */
-  if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
-      && flag_delete_null_pointer_checks)
-    return true;
-
-  fntype = TREE_TYPE (current_function_decl);
-  for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
-    {
-      attrs = lookup_attribute ("nonnull", attrs);
-
-      /* If "nonnull" wasn't specified, we know nothing about the argument.  */
-      if (attrs == NULL_TREE)
-       return false;
-
-      /* If "nonnull" applies to all the arguments, then ARG is non-null.  */
-      if (TREE_VALUE (attrs) == NULL_TREE)
-       return true;
-
-      /* Get the position number for ARG in the function signature.  */
-      for (arg_num = 1, t = DECL_ARGUMENTS (current_function_decl);
-          t;
-          t = DECL_CHAIN (t), arg_num++)
-       {
-         if (t == arg)
-           break;
-       }
-
-      gcc_assert (t == arg);
-
-      /* Now see if ARG_NUM is mentioned in the nonnull list.  */
-      for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
-       {
-         if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
-           return true;
-       }
-    }
-
-  return false;
-}
-
-
 /* Set value range VR to VR_UNDEFINED.  */
 
 static inline void
-set_value_range_to_undefined (value_range_t *vr)
+set_value_range_to_undefined (value_range *vr)
 {
   vr->type = VR_UNDEFINED;
   vr->min = vr->max = NULL_TREE;
@@ -456,7 +354,7 @@ set_value_range_to_undefined (value_range_t *vr)
 /* Set value range VR to VR_VARYING.  */
 
 static inline void
-set_value_range_to_varying (value_range_t *vr)
+set_value_range_to_varying (value_range *vr)
 {
   vr->type = VR_VARYING;
   vr->min = vr->max = NULL_TREE;
@@ -468,12 +366,12 @@ set_value_range_to_varying (value_range_t *vr)
 /* Set value range VR to {T, MIN, MAX, EQUIV}.  */
 
 static void
-set_value_range (value_range_t *vr, enum value_range_type t, tree min,
+set_value_range (value_range *vr, enum value_range_type t, tree min,
                 tree max, bitmap equiv)
 {
-#if defined ENABLE_CHECKING
   /* Check the validity of the range.  */
-  if (t == VR_RANGE || t == VR_ANTI_RANGE)
+  if (flag_checking
+      && (t == VR_RANGE || t == VR_ANTI_RANGE))
     {
       int cmp;
 
@@ -493,12 +391,12 @@ set_value_range (value_range_t *vr, enum value_range_type t, tree min,
                    || !is_overflow_infinity (max));
     }
 
-  if (t == VR_UNDEFINED || t == VR_VARYING)
-    gcc_assert (min == NULL_TREE && max == NULL_TREE);
-
-  if (t == VR_UNDEFINED || t == VR_VARYING)
-    gcc_assert (equiv == NULL || bitmap_empty_p (equiv));
-#endif
+  if (flag_checking
+      && (t == VR_UNDEFINED || t == VR_VARYING))
+    {
+      gcc_assert (min == NULL_TREE && max == NULL_TREE);
+      gcc_assert (equiv == NULL || bitmap_empty_p (equiv));
+    }
 
   vr->type = t;
   vr->min = min;
@@ -530,7 +428,7 @@ set_value_range (value_range_t *vr, enum value_range_type t, tree min,
    extract ranges from var + CST op limit.  */
 
 static void
-set_and_canonicalize_value_range (value_range_t *vr, enum value_range_type t,
+set_and_canonicalize_value_range (value_range *vr, enum value_range_type t,
                                  tree min, tree max, bitmap equiv)
 {
   /* Use the canonical setters for VR_UNDEFINED and VR_VARYING.  */
@@ -643,7 +541,7 @@ set_and_canonicalize_value_range (value_range_t *vr, enum value_range_type t,
 /* Copy value range FROM into value range TO.  */
 
 static inline void
-copy_value_range (value_range_t *to, value_range_t *from)
+copy_value_range (value_range *to, value_range *from)
 {
   set_value_range (to, from->type, from->min, from->max, from->equiv);
 }
@@ -654,7 +552,7 @@ copy_value_range (value_range_t *to, value_range_t *from)
    infinity when we shouldn't.  */
 
 static inline void
-set_value_range_to_value (value_range_t *vr, tree val, bitmap equiv)
+set_value_range_to_value (value_range *vr, tree val, bitmap equiv)
 {
   gcc_assert (is_gimple_min_invariant (val));
   if (TREE_OVERFLOW_P (val))
@@ -669,7 +567,7 @@ set_value_range_to_value (value_range_t *vr, tree val, bitmap equiv)
    overflow does not occur.  */
 
 static inline void
-set_value_range_to_nonnegative (value_range_t *vr, tree type,
+set_value_range_to_nonnegative (value_range *vr, tree type,
                                bool overflow_infinity)
 {
   tree zero;
@@ -691,7 +589,7 @@ set_value_range_to_nonnegative (value_range_t *vr, tree type,
 /* Set value range VR to a non-NULL range of type TYPE.  */
 
 static inline void
-set_value_range_to_nonnull (value_range_t *vr, tree type)
+set_value_range_to_nonnull (value_range *vr, tree type)
 {
   tree zero = build_int_cst (type, 0);
   set_value_range (vr, VR_ANTI_RANGE, zero, zero, vr->equiv);
@@ -701,7 +599,7 @@ set_value_range_to_nonnull (value_range_t *vr, tree type)
 /* Set value range VR to a NULL range of type TYPE.  */
 
 static inline void
-set_value_range_to_null (value_range_t *vr, tree type)
+set_value_range_to_null (value_range *vr, tree type)
 {
   set_value_range_to_value (vr, build_int_cst (type, 0), vr->equiv);
 }
@@ -710,7 +608,7 @@ set_value_range_to_null (value_range_t *vr, tree type)
 /* Set value range VR to a range of a truthvalue of type TYPE.  */
 
 static inline void
-set_value_range_to_truthvalue (value_range_t *vr, tree type)
+set_value_range_to_truthvalue (value_range *vr, tree type)
 {
   if (TYPE_PRECISION (type) == 1)
     set_value_range_to_varying (vr);
@@ -725,7 +623,7 @@ set_value_range_to_truthvalue (value_range_t *vr, tree type)
    abs (min) >= abs (max), set VR to [-min, min].  */
 
 static void
-abs_extent_range (value_range_t *vr, tree min, tree max)
+abs_extent_range (value_range *vr, tree min, tree max)
 {
   int cmp;
 
@@ -762,12 +660,12 @@ abs_extent_range (value_range_t *vr, tree min, tree max)
    If we have no values ranges recorded (ie, VRP is not running), then
    return NULL.  Otherwise create an empty range if none existed for VAR.  */
 
-static value_range_t *
+static value_range *
 get_value_range (const_tree var)
 {
-  static const struct value_range_d vr_const_varying
+  static const value_range vr_const_varying
     = { VR_VARYING, NULL_TREE, NULL_TREE, NULL };
-  value_range_t *vr;
+  value_range *vr;
   tree sym;
   unsigned ver = SSA_NAME_VERSION (var);
 
@@ -779,7 +677,7 @@ get_value_range (const_tree var)
      We should get here at most from the substitute-and-fold stage which
      will never try to change values.  */
   if (ver >= num_vr_values)
-    return CONST_CAST (value_range_t *, &vr_const_varying);
+    return CONST_CAST (value_range *, &vr_const_varying);
 
   vr = vr_value[ver];
   if (vr)
@@ -787,10 +685,10 @@ get_value_range (const_tree var)
 
   /* After propagation finished do not allocate new value-ranges.  */
   if (values_propagated)
-    return CONST_CAST (value_range_t *, &vr_const_varying);
+    return CONST_CAST (value_range *, &vr_const_varying);
 
   /* Create a default value range.  */
-  vr_value[ver] = vr = XCNEW (value_range_t);
+  vr_value[ver] = vr = XCNEW (value_range);
 
   /* Defer allocating the equivalence set.  */
   vr->equiv = NULL;
@@ -854,9 +752,9 @@ vrp_bitmap_equal_p (const_bitmap b1, const_bitmap b2)
    is the range object associated with another SSA name.  */
 
 static inline bool
-update_value_range (const_tree var, value_range_t *new_vr)
+update_value_range (const_tree var, value_range *new_vr)
 {
-  value_range_t *old_vr;
+  value_range *old_vr;
   bool is_new;
 
   /* If there is a value-range on the SSA name from earlier analysis
@@ -867,7 +765,7 @@ update_value_range (const_tree var, value_range_t *new_vr)
       value_range_type rtype = get_range_info (var, &min, &max);
       if (rtype == VR_RANGE || rtype == VR_ANTI_RANGE)
        {
-         value_range_d nr;
+         value_range nr;
          nr.type = rtype;
          nr.min = wide_int_to_tree (TREE_TYPE (var), min);
          nr.max = wide_int_to_tree (TREE_TYPE (var), max);
@@ -916,7 +814,7 @@ static void
 add_equivalence (bitmap *equiv, const_tree var)
 {
   unsigned ver = SSA_NAME_VERSION (var);
-  value_range_t *vr = vr_value[ver];
+  value_range *vr = vr_value[ver];
 
   if (*equiv == NULL)
     *equiv = BITMAP_ALLOC (NULL);
@@ -929,7 +827,7 @@ add_equivalence (bitmap *equiv, const_tree var)
 /* Return true if VR is ~[0, 0].  */
 
 static inline bool
-range_is_nonnull (value_range_t *vr)
+range_is_nonnull (value_range *vr)
 {
   return vr->type == VR_ANTI_RANGE
         && integer_zerop (vr->min)
@@ -940,7 +838,7 @@ range_is_nonnull (value_range_t *vr)
 /* Return true if VR is [0, 0].  */
 
 static inline bool
-range_is_null (value_range_t *vr)
+range_is_null (value_range *vr)
 {
   return vr->type == VR_RANGE
         && integer_zerop (vr->min)
@@ -951,7 +849,7 @@ range_is_null (value_range_t *vr)
    a singleton.  */
 
 static inline bool
-range_int_cst_p (value_range_t *vr)
+range_int_cst_p (value_range *vr)
 {
   return (vr->type == VR_RANGE
          && TREE_CODE (vr->max) == INTEGER_CST
@@ -961,7 +859,7 @@ range_int_cst_p (value_range_t *vr)
 /* Return true if VR is a INTEGER_CST singleton.  */
 
 static inline bool
-range_int_cst_singleton_p (value_range_t *vr)
+range_int_cst_singleton_p (value_range *vr)
 {
   return (range_int_cst_p (vr)
          && !is_overflow_infinity (vr->min)
@@ -972,7 +870,7 @@ range_int_cst_singleton_p (value_range_t *vr)
 /* Return true if value range VR involves at least one symbol.  */
 
 static inline bool
-symbolic_range_p (value_range_t *vr)
+symbolic_range_p (value_range *vr)
 {
   return (!is_gimple_min_invariant (vr->min)
           || !is_gimple_min_invariant (vr->max));
@@ -1048,7 +946,7 @@ build_symbolic_expr (tree type, tree sym, bool neg, tree inv)
 /* Return true if value range VR involves exactly one symbol SYM.  */
 
 static bool
-symbolic_range_based_on_p (value_range_t *vr, const_tree sym)
+symbolic_range_based_on_p (value_range *vr, const_tree sym)
 {
   bool neg, min_has_symbol, max_has_symbol;
   tree inv;
@@ -1073,7 +971,7 @@ symbolic_range_based_on_p (value_range_t *vr, const_tree sym)
 /* Return true if value range VR uses an overflow infinity.  */
 
 static inline bool
-overflow_infinity_range_p (value_range_t *vr)
+overflow_infinity_range_p (value_range *vr)
 {
   return (vr->type == VR_RANGE
          && (is_overflow_infinity (vr->min)
@@ -1087,7 +985,7 @@ overflow_infinity_range_p (value_range_t *vr)
    uses an overflow infinity.  */
 
 static bool
-usable_range_p (value_range_t *vr, bool *strict_overflow_p)
+usable_range_p (value_range *vr, bool *strict_overflow_p)
 {
   gcc_assert (vr->type == VR_RANGE);
   if (is_overflow_infinity (vr->min))
@@ -1105,87 +1003,13 @@ usable_range_p (value_range_t *vr, bool *strict_overflow_p)
   return true;
 }
 
-
-/* Return true if the result of assignment STMT is know to be non-negative.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.*/
-
-static bool
-gimple_assign_nonnegative_warnv_p (gimple stmt, bool *strict_overflow_p)
-{
-  enum tree_code code = gimple_assign_rhs_code (stmt);
-  switch (get_gimple_rhs_class (code))
-    {
-    case GIMPLE_UNARY_RHS:
-      return tree_unary_nonnegative_warnv_p (gimple_assign_rhs_code (stmt),
-                                            gimple_expr_type (stmt),
-                                            gimple_assign_rhs1 (stmt),
-                                            strict_overflow_p);
-    case GIMPLE_BINARY_RHS:
-      return tree_binary_nonnegative_warnv_p (gimple_assign_rhs_code (stmt),
-                                             gimple_expr_type (stmt),
-                                             gimple_assign_rhs1 (stmt),
-                                             gimple_assign_rhs2 (stmt),
-                                             strict_overflow_p);
-    case GIMPLE_TERNARY_RHS:
-      return false;
-    case GIMPLE_SINGLE_RHS:
-      return tree_single_nonnegative_warnv_p (gimple_assign_rhs1 (stmt),
-                                             strict_overflow_p);
-    case GIMPLE_INVALID_RHS:
-      gcc_unreachable ();
-    default:
-      gcc_unreachable ();
-    }
-}
-
-/* Return true if return value of call STMT is know to be non-negative.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.*/
-
-static bool
-gimple_call_nonnegative_warnv_p (gimple stmt, bool *strict_overflow_p)
-{
-  tree arg0 = gimple_call_num_args (stmt) > 0 ?
-    gimple_call_arg (stmt, 0) : NULL_TREE;
-  tree arg1 = gimple_call_num_args (stmt) > 1 ?
-    gimple_call_arg (stmt, 1) : NULL_TREE;
-
-  return tree_call_nonnegative_warnv_p (gimple_expr_type (stmt),
-                                       gimple_call_fndecl (stmt),
-                                       arg0,
-                                       arg1,
-                                       strict_overflow_p);
-}
-
-/* Return true if STMT is know to to compute a non-negative value.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.*/
-
-static bool
-gimple_stmt_nonnegative_warnv_p (gimple stmt, bool *strict_overflow_p)
-{
-  switch (gimple_code (stmt))
-    {
-    case GIMPLE_ASSIGN:
-      return gimple_assign_nonnegative_warnv_p (stmt, strict_overflow_p);
-    case GIMPLE_CALL:
-      return gimple_call_nonnegative_warnv_p (stmt, strict_overflow_p);
-    default:
-      gcc_unreachable ();
-    }
-}
-
 /* Return true if the result of assignment STMT is know to be non-zero.
    If the return value is based on the assumption that signed overflow is
    undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
    *STRICT_OVERFLOW_P.*/
 
 static bool
-gimple_assign_nonzero_warnv_p (gimple stmt, bool *strict_overflow_p)
+gimple_assign_nonzero_warnv_p (gimple *stmt, bool *strict_overflow_p)
 {
   enum tree_code code = gimple_assign_rhs_code (stmt);
   switch (get_gimple_rhs_class (code))
@@ -1219,7 +1043,7 @@ gimple_assign_nonzero_warnv_p (gimple stmt, bool *strict_overflow_p)
    *STRICT_OVERFLOW_P.*/
 
 static bool
-gimple_stmt_nonzero_warnv_p (gimple stmt, bool *strict_overflow_p)
+gimple_stmt_nonzero_warnv_p (gimple *stmt, bool *strict_overflow_p)
 {
   switch (gimple_code (stmt))
     {
@@ -1252,7 +1076,7 @@ gimple_stmt_nonzero_warnv_p (gimple stmt, bool *strict_overflow_p)
    obtained so far.  */
 
 static bool
-vrp_stmt_computes_nonzero (gimple stmt, bool *strict_overflow_p)
+vrp_stmt_computes_nonzero (gimple *stmt, bool *strict_overflow_p)
 {
   if (gimple_stmt_nonzero_warnv_p (stmt, strict_overflow_p))
     return true;
@@ -1269,7 +1093,7 @@ vrp_stmt_computes_nonzero (gimple stmt, bool *strict_overflow_p)
          && TREE_CODE (base) == MEM_REF
          && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
        {
-         value_range_t *vr = get_value_range (TREE_OPERAND (base, 0));
+         value_range *vr = get_value_range (TREE_OPERAND (base, 0));
          if (range_is_nonnull (vr))
            return true;
        }
@@ -1593,7 +1417,7 @@ value_inside_range (tree val, tree min, tree max)
    */
 
 static inline bool
-value_ranges_intersect_p (value_range_t *vr0, value_range_t *vr1)
+value_ranges_intersect_p (value_range *vr0, value_range *vr1)
 {
   /* The value ranges do not intersect if the maximum of the first range is
      less than the minimum of the second range or vice versa.
@@ -1619,7 +1443,7 @@ range_includes_zero_p (tree min, tree max)
 /* Return true if *VR is know to only contain nonnegative values.  */
 
 static inline bool
-value_range_nonnegative_p (value_range_t *vr)
+value_range_nonnegative_p (value_range *vr)
 {
   /* Testing for VR_ANTI_RANGE is not useful here as any anti-range
      which would return a useful value should be encoded as a 
@@ -1637,7 +1461,7 @@ value_range_nonnegative_p (value_range_t *vr)
    otherwise return NULL_TREE.  */
 
 static tree
-value_range_constant_singleton (value_range_t *vr)
+value_range_constant_singleton (value_range *vr)
 {
   if (vr->type == VR_RANGE
       && operand_equal_p (vr->min, vr->max, 0)
@@ -1668,7 +1492,7 @@ op_with_constant_singleton_value_range (tree op)
 static bool
 op_with_boolean_value_range_p (tree op)
 {
-  value_range_t *vr;
+  value_range *vr;
 
   if (TYPE_PRECISION (TREE_TYPE (op)) == 1)
     return true;
@@ -1690,10 +1514,10 @@ op_with_boolean_value_range_p (tree op)
    it in *VR_P.  */
 
 static void
-extract_range_from_assert (value_range_t *vr_p, tree expr)
+extract_range_from_assert (value_range *vr_p, tree expr)
 {
   tree var, cond, limit, min, max, type;
-  value_range_t *limit_vr;
+  value_range *limit_vr;
   enum tree_code cond_code;
 
   var = ASSERT_EXPR_VAR (expr);
@@ -1973,9 +1797,9 @@ extract_range_from_assert (value_range_t *vr_p, tree expr)
     always false.  */
 
 static void
-extract_range_from_ssa_name (value_range_t *vr, tree var)
+extract_range_from_ssa_name (value_range *vr, tree var)
 {
-  value_range_t *var_vr = get_value_range (var);
+  value_range *var_vr = get_value_range (var);
 
   if (var_vr->type != VR_VARYING)
     copy_value_range (vr, var_vr);
@@ -2145,7 +1969,7 @@ vrp_int_const_binop (enum tree_code code, tree val1, tree val2)
 
 static bool
 zero_nonzero_bits_from_vr (const tree expr_type,
-                          value_range_t *vr,
+                          value_range *vr,
                           wide_int *may_be_nonzero,
                           wide_int *must_be_nonzero)
 {
@@ -2185,8 +2009,8 @@ zero_nonzero_bits_from_vr (const tree expr_type,
    *VR1 will be VR_UNDEFINED.  */
 
 static bool
-ranges_from_anti_range (value_range_t *ar,
-                       value_range_t *vr0, value_range_t *vr1)
+ranges_from_anti_range (value_range *ar,
+                       value_range *vr0, value_range *vr1)
 {
   tree type = TREE_TYPE (ar->min);
 
@@ -2225,9 +2049,9 @@ ranges_from_anti_range (value_range_t *ar,
    *VR0 CODE *VR1.  */
 
 static void
-extract_range_from_multiplicative_op_1 (value_range_t *vr,
+extract_range_from_multiplicative_op_1 (value_range *vr,
                                        enum tree_code code,
-                                       value_range_t *vr0, value_range_t *vr1)
+                                       value_range *vr0, value_range *vr1)
 {
   enum value_range_type type;
   tree val[4];
@@ -2380,12 +2204,12 @@ extract_range_from_multiplicative_op_1 (value_range_t *vr,
    type EXPR_TYPE.  The resulting range is stored in *VR.  */
 
 static void
-extract_range_from_binary_expr_1 (value_range_t *vr,
+extract_range_from_binary_expr_1 (value_range *vr,
                                  enum tree_code code, tree expr_type,
-                                 value_range_t *vr0_, value_range_t *vr1_)
+                                 value_range *vr0_, value_range *vr1_)
 {
-  value_range_t vr0 = *vr0_, vr1 = *vr1_;
-  value_range_t vrtem0 = VR_INITIALIZER, vrtem1 = VR_INITIALIZER;
+  value_range vr0 = *vr0_, vr1 = *vr1_;
+  value_range vrtem0 = VR_INITIALIZER, vrtem1 = VR_INITIALIZER;
   enum value_range_type type;
   tree min = NULL_TREE, max = NULL_TREE;
   int cmp;
@@ -2444,7 +2268,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
       extract_range_from_binary_expr_1 (vr, code, expr_type, &vrtem0, vr1_);
       if (vrtem1.type != VR_UNDEFINED)
        {
-         value_range_t vrres = VR_INITIALIZER;
+         value_range vrres = VR_INITIALIZER;
          extract_range_from_binary_expr_1 (&vrres, code, expr_type,
                                            &vrtem1, vr1_);
          vrp_meet (vr, &vrres);
@@ -2458,7 +2282,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
       extract_range_from_binary_expr_1 (vr, code, expr_type, vr0_, &vrtem0);
       if (vrtem1.type != VR_UNDEFINED)
        {
-         value_range_t vrres = VR_INITIALIZER;
+         value_range vrres = VR_INITIALIZER;
          extract_range_from_binary_expr_1 (&vrres, code, expr_type,
                                            vr0_, &vrtem1);
          vrp_meet (vr, &vrres);
@@ -2926,33 +2750,17 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
             prod3.  */
          /* min0min1 > max0max1 */
          if (wi::gts_p (prod0, prod3))
-           {
-             vrp_int tmp = prod3;
-             prod3 = prod0;
-             prod0 = tmp;
-           }
+           std::swap (prod0, prod3);
 
          /* min0max1 > max0min1 */
          if (wi::gts_p (prod1, prod2))
-           {
-             vrp_int tmp = prod2;
-             prod2 = prod1;
-             prod1 = tmp;
-           }
+           std::swap (prod1, prod2);
 
          if (wi::gts_p (prod0, prod1))
-           {
-             vrp_int tmp = prod1;
-             prod1 = prod0;
-             prod0 = tmp;
-           }
+           std::swap (prod0, prod1);
 
          if (wi::gts_p (prod2, prod3))
-           {
-             vrp_int tmp = prod3;
-             prod3 = prod2;
-             prod2 = tmp;
-           }
+           std::swap (prod2, prod3);
 
          /* diff = max - min.  */
          prod2 = prod3 - prod0;
@@ -3020,7 +2828,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
                   && range_int_cst_singleton_p (&vr1))
            {
              bool saved_flag_wrapv;
-             value_range_t vr1p = VR_INITIALIZER;
+             value_range vr1p = VR_INITIALIZER;
              vr1p.type = VR_RANGE;
              vr1p.min = (wide_int_to_tree
                          (expr_type,
@@ -3161,14 +2969,33 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
                 and all numbers from min to 0 for negative min.  */
              cmp = compare_values (vr0.max, zero);
              if (cmp == -1)
-               max = zero;
+               {
+                 /* When vr0.max < 0, vr1.min != 0 and value
+                    ranges for dividend and divisor are available.  */
+                 if (vr1.type == VR_RANGE
+                     && !symbolic_range_p (&vr0)
+                     && !symbolic_range_p (&vr1)
+                     && compare_values (vr1.min, zero) != 0)
+                   max = int_const_binop (code, vr0.max, vr1.min);
+                 else
+                   max = zero;
+               }
              else if (cmp == 0 || cmp == 1)
                max = vr0.max;
              else
                type = VR_VARYING;
              cmp = compare_values (vr0.min, zero);
              if (cmp == 1)
-               min = zero;
+               {
+                 /* For unsigned division when value ranges for dividend
+                    and divisor are available.  */
+                 if (vr1.type == VR_RANGE
+                     && !symbolic_range_p (&vr0)
+                     && !symbolic_range_p (&vr1))
+                   min = int_const_binop (code, vr0.min, vr1.max);
+                 else
+                   min = zero;
+               }
              else if (cmp == 0 || cmp == -1)
                min = vr0.min;
              else
@@ -3188,7 +3015,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
              return;
            }
        }
-      else
+      else if (!symbolic_range_p (&vr0) && !symbolic_range_p (&vr1))
        {
          extract_range_from_multiplicative_op_1 (vr, code, &vr0, &vr1);
          return;
@@ -3377,12 +3204,12 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
    The resulting range is stored in *VR.  */
 
 static void
-extract_range_from_binary_expr (value_range_t *vr,
+extract_range_from_binary_expr (value_range *vr,
                                enum tree_code code,
                                tree expr_type, tree op0, tree op1)
 {
-  value_range_t vr0 = VR_INITIALIZER;
-  value_range_t vr1 = VR_INITIALIZER;
+  value_range vr0 = VR_INITIALIZER;
+  value_range vr1 = VR_INITIALIZER;
 
   /* Get value ranges for each operand.  For constant operands, create
      a new value range with the operand to simplify processing.  */
@@ -3414,7 +3241,7 @@ extract_range_from_binary_expr (value_range_t *vr,
       && symbolic_range_based_on_p (&vr0, op1))
     {
       const bool minus_p = (code == MINUS_EXPR);
-      value_range_t n_vr1 = VR_INITIALIZER;
+      value_range n_vr1 = VR_INITIALIZER;
 
       /* Try with VR0 and [-INF, OP1].  */
       if (is_gimple_min_invariant (minus_p ? vr0.max : vr0.min))
@@ -3438,7 +3265,7 @@ extract_range_from_binary_expr (value_range_t *vr,
       && symbolic_range_based_on_p (&vr1, op0))
     {
       const bool minus_p = (code == MINUS_EXPR);
-      value_range_t n_vr0 = VR_INITIALIZER;
+      value_range n_vr0 = VR_INITIALIZER;
 
       /* Try with [-INF, OP0] and VR1.  */
       if (is_gimple_min_invariant (minus_p ? vr1.max : vr1.min))
@@ -3458,14 +3285,14 @@ extract_range_from_binary_expr (value_range_t *vr,
 
 /* Extract range information from a unary operation CODE based on
    the range of its operand *VR0 with type OP0_TYPE with resulting type TYPE.
-   The The resulting range is stored in *VR.  */
+   The resulting range is stored in *VR.  */
 
 static void
-extract_range_from_unary_expr_1 (value_range_t *vr,
+extract_range_from_unary_expr_1 (value_range *vr,
                                 enum tree_code code, tree type,
-                                value_range_t *vr0_, tree op0_type)
+                                value_range *vr0_, tree op0_type)
 {
-  value_range_t vr0 = *vr0_, vrtem0 = VR_INITIALIZER, vrtem1 = VR_INITIALIZER;
+  value_range vr0 = *vr0_, vrtem0 = VR_INITIALIZER, vrtem1 = VR_INITIALIZER;
 
   /* VRP only operates on integral and pointer types.  */
   if (!(INTEGRAL_TYPE_P (op0_type)
@@ -3495,7 +3322,7 @@ extract_range_from_unary_expr_1 (value_range_t *vr,
     {
       /* -X is simply 0 - X, so re-use existing code that also handles
          anti-ranges fine.  */
-      value_range_t zero = VR_INITIALIZER;
+      value_range zero = VR_INITIALIZER;
       set_value_range_to_value (&zero, build_int_cst (type, 0), NULL);
       extract_range_from_binary_expr_1 (vr, MINUS_EXPR, type, &zero, &vr0);
       return;
@@ -3504,7 +3331,7 @@ extract_range_from_unary_expr_1 (value_range_t *vr,
     {
       /* ~X is simply -1 - X, so re-use existing code that also handles
          anti-ranges fine.  */
-      value_range_t minusone = VR_INITIALIZER;
+      value_range minusone = VR_INITIALIZER;
       set_value_range_to_value (&minusone, build_int_cst (type, -1), NULL);
       extract_range_from_binary_expr_1 (vr, MINUS_EXPR,
                                        type, &minusone, &vr0);
@@ -3519,7 +3346,7 @@ extract_range_from_unary_expr_1 (value_range_t *vr,
       extract_range_from_unary_expr_1 (vr, code, type, &vrtem0, op0_type);
       if (vrtem1.type != VR_UNDEFINED)
        {
-         value_range_t vrres = VR_INITIALIZER;
+         value_range vrres = VR_INITIALIZER;
          extract_range_from_unary_expr_1 (&vrres, code, type,
                                           &vrtem1, op0_type);
          vrp_meet (vr, &vrres);
@@ -3735,11 +3562,7 @@ extract_range_from_unary_expr_1 (value_range_t *vr,
        {
           /* If the range was reversed, swap MIN and MAX.  */
          if (cmp == 1)
-           {
-             tree t = min;
-             min = max;
-             max = t;
-           }
+           std::swap (min, max);
        }
 
       cmp = compare_values (min, max);
@@ -3766,10 +3589,10 @@ extract_range_from_unary_expr_1 (value_range_t *vr,
    The resulting range is stored in *VR.  */
 
 static void
-extract_range_from_unary_expr (value_range_t *vr, enum tree_code code,
+extract_range_from_unary_expr (value_range *vr, enum tree_code code,
                               tree type, tree op0)
 {
-  value_range_t vr0 = VR_INITIALIZER;
+  value_range vr0 = VR_INITIALIZER;
 
   /* Get value ranges for the operand.  For constant operands, create
      a new value range with the operand to simplify processing.  */
@@ -3788,11 +3611,11 @@ extract_range_from_unary_expr (value_range_t *vr, enum tree_code code,
    the ranges of each of its operands and the expression code.  */
 
 static void
-extract_range_from_cond_expr (value_range_t *vr, gassign *stmt)
+extract_range_from_cond_expr (value_range *vr, gassign *stmt)
 {
   tree op0, op1;
-  value_range_t vr0 = VR_INITIALIZER;
-  value_range_t vr1 = VR_INITIALIZER;
+  value_range vr0 = VR_INITIALIZER;
+  value_range vr1 = VR_INITIALIZER;
 
   /* Get value ranges for each operand.  For constant operands, create
      a new value range with the operand to simplify processing.  */
@@ -3822,7 +3645,7 @@ extract_range_from_cond_expr (value_range_t *vr, gassign *stmt)
    on the range of its operand and the expression code.  */
 
 static void
-extract_range_from_comparison (value_range_t *vr, enum tree_code code,
+extract_range_from_comparison (value_range *vr, enum tree_code code,
                               tree type, tree op0, tree op1)
 {
   bool sop = false;
@@ -3862,8 +3685,8 @@ static bool
 check_for_binary_op_overflow (enum tree_code subcode, tree type,
                              tree op0, tree op1, bool *ovf)
 {
-  value_range_t vr0 = VR_INITIALIZER;
-  value_range_t vr1 = VR_INITIALIZER;
+  value_range vr0 = VR_INITIALIZER;
+  value_range vr1 = VR_INITIALIZER;
   if (TREE_CODE (op0) == SSA_NAME)
     vr0 = *get_value_range (op0);
   else if (TREE_CODE (op0) == INTEGER_CST)
@@ -3964,19 +3787,21 @@ check_for_binary_op_overflow (enum tree_code subcode, tree type,
    Store the result in *VR */
 
 static void
-extract_range_basic (value_range_t *vr, gimple stmt)
+extract_range_basic (value_range *vr, gimple *stmt)
 {
   bool sop = false;
   tree type = gimple_expr_type (stmt);
 
-  if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
+  if (is_gimple_call (stmt))
     {
-      tree fndecl = gimple_call_fndecl (stmt), arg;
+      tree arg;
       int mini, maxi, zerov = 0, prec;
+      enum tree_code subcode = ERROR_MARK;
+      combined_fn cfn = gimple_call_combined_fn (stmt);
 
-      switch (DECL_FUNCTION_CODE (fndecl))
+      switch (cfn)
        {
-       case BUILT_IN_CONSTANT_P:
+       case CFN_BUILT_IN_CONSTANT_P:
          /* If the call is __builtin_constant_p and the argument is a
             function parameter resolve it to false.  This avoids bogus
             array bound warnings.
@@ -3992,15 +3817,15 @@ extract_range_basic (value_range_t *vr, gimple stmt)
          break;
          /* Both __builtin_ffs* and __builtin_popcount return
             [0, prec].  */
-       CASE_INT_FN (BUILT_IN_FFS):
-       CASE_INT_FN (BUILT_IN_POPCOUNT):
+       CASE_CFN_FFS:
+       CASE_CFN_POPCOUNT:
          arg = gimple_call_arg (stmt, 0);
          prec = TYPE_PRECISION (TREE_TYPE (arg));
          mini = 0;
          maxi = prec;
          if (TREE_CODE (arg) == SSA_NAME)
            {
-             value_range_t *vr0 = get_value_range (arg);
+             value_range *vr0 = get_value_range (arg);
              /* If arg is non-zero, then ffs or popcount
                 are non-zero.  */
              if (((vr0->type == VR_RANGE
@@ -4021,7 +3846,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
            }
          goto bitop_builtin;
          /* __builtin_parity* returns [0, 1].  */
-       CASE_INT_FN (BUILT_IN_PARITY):
+       CASE_CFN_PARITY:
          mini = 0;
          maxi = 1;
          goto bitop_builtin;
@@ -4030,7 +3855,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
             On many targets where the CLZ RTL or optab value is defined
             for 0 the value is prec, so include that in the range
             by default.  */
-       CASE_INT_FN (BUILT_IN_CLZ):
+       CASE_CFN_CLZ:
          arg = gimple_call_arg (stmt, 0);
          prec = TYPE_PRECISION (TREE_TYPE (arg));
          mini = 0;
@@ -4046,7 +3871,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
            mini = -2;
          if (TREE_CODE (arg) == SSA_NAME)
            {
-             value_range_t *vr0 = get_value_range (arg);
+             value_range *vr0 = get_value_range (arg);
              /* From clz of VR_RANGE minimum we can compute
                 result maximum.  */
              if (vr0->type == VR_RANGE
@@ -4085,7 +3910,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
             If there is a ctz optab for this mode and
             CTZ_DEFINED_VALUE_AT_ZERO, include that in the range,
             otherwise just assume 0 won't be seen.  */
-       CASE_INT_FN (BUILT_IN_CTZ):
+       CASE_CFN_CTZ:
          arg = gimple_call_arg (stmt, 0);
          prec = TYPE_PRECISION (TREE_TYPE (arg));
          mini = 0;
@@ -4107,7 +3932,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
            }
          if (TREE_CODE (arg) == SSA_NAME)
            {
-             value_range_t *vr0 = get_value_range (arg);
+             value_range *vr0 = get_value_range (arg);
              /* If arg is non-zero, then use [0, prec - 1].  */
              if (((vr0->type == VR_RANGE
                    && integer_nonzerop (vr0->min))
@@ -4134,7 +3959,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
            break;
          goto bitop_builtin;
          /* __builtin_clrsb* returns [0, prec-1].  */
-       CASE_INT_FN (BUILT_IN_CLRSB):
+       CASE_CFN_CLRSB:
          arg = gimple_call_arg (stmt, 0);
          prec = TYPE_PRECISION (TREE_TYPE (arg));
          mini = 0;
@@ -4144,24 +3969,37 @@ extract_range_basic (value_range_t *vr, gimple stmt)
          set_value_range (vr, VR_RANGE, build_int_cst (type, mini),
                           build_int_cst (type, maxi), NULL);
          return;
-       default:
-         break;
-       }
-    }
-  else if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
-    {
-      enum tree_code subcode = ERROR_MARK;
-      switch (gimple_call_internal_fn (stmt))
-       {
-       case IFN_UBSAN_CHECK_ADD:
+       case CFN_UBSAN_CHECK_ADD:
          subcode = PLUS_EXPR;
          break;
-       case IFN_UBSAN_CHECK_SUB:
+       case CFN_UBSAN_CHECK_SUB:
          subcode = MINUS_EXPR;
          break;
-       case IFN_UBSAN_CHECK_MUL:
+       case CFN_UBSAN_CHECK_MUL:
          subcode = MULT_EXPR;
          break;
+       case CFN_GOACC_DIM_SIZE:
+       case CFN_GOACC_DIM_POS:
+         /* Optimizing these two internal functions helps the loop
+            optimizer eliminate outer comparisons.  Size is [1,N]
+            and pos is [0,N-1].  */
+         {
+           bool is_pos = cfn == CFN_GOACC_DIM_POS;
+           int axis = get_oacc_ifn_dim_arg (stmt);
+           int size = get_oacc_fn_dim_size (current_function_decl, axis);
+
+           if (!size)
+             /* If it's dynamic, the backend might know a hardware
+                limitation.  */
+             size = targetm.goacc.dim_limit (axis);
+
+           tree type = TREE_TYPE (gimple_call_lhs (stmt));
+           set_value_range (vr, VR_RANGE,
+                            build_int_cst (type, is_pos ? 0 : 1),
+                            size ? build_int_cst (type, size - is_pos)
+                                 : vrp_val_max (type), NULL);
+         }
+         return;
        default:
          break;
        }
@@ -4200,7 +4038,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
       tree op = gimple_assign_rhs1 (stmt);
       if (TREE_CODE (op) == code && TREE_CODE (TREE_OPERAND (op, 0)) == SSA_NAME)
        {
-         gimple g = SSA_NAME_DEF_STMT (TREE_OPERAND (op, 0));
+         gimple *g = SSA_NAME_DEF_STMT (TREE_OPERAND (op, 0));
          if (is_gimple_call (g) && gimple_call_internal_p (g))
            {
              enum tree_code subcode = ERROR_MARK;
@@ -4247,8 +4085,8 @@ extract_range_basic (value_range_t *vr, gimple stmt)
                    }
                  else
                    {
-                     value_range_t vr0 = VR_INITIALIZER;
-                     value_range_t vr1 = VR_INITIALIZER;
+                     value_range vr0 = VR_INITIALIZER;
+                     value_range vr1 = VR_INITIALIZER;
                      bool saved_flag_wrapv = flag_wrapv;
                      /* Pretend the arithmetics is wrapping.  If there is
                         any overflow, IMAGPART_EXPR will be set.  */
@@ -4282,7 +4120,7 @@ extract_range_basic (value_range_t *vr, gimple stmt)
    in *VR.  */
 
 static void
-extract_range_from_assignment (value_range_t *vr, gassign *stmt)
+extract_range_from_assignment (value_range *vr, gassign *stmt)
 {
   enum tree_code code = gimple_assign_rhs_code (stmt);
 
@@ -4321,8 +4159,8 @@ extract_range_from_assignment (value_range_t *vr, gassign *stmt)
    for VAR.  If so, update VR with the new limits.  */
 
 static void
-adjust_range_with_scev (value_range_t *vr, struct loop *loop,
-                       gimple stmt, tree var)
+adjust_range_with_scev (value_range *vr, struct loop *loop,
+                       gimple *stmt, tree var)
 {
   tree init, step, chrec, tmin, tmax, min, max, type, tem;
   enum ev_direction dir;
@@ -4399,7 +4237,7 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop,
         the number of latch executions is the correct thing to use.  */
       if (max_loop_iterations (loop, &nit))
        {
-         value_range_t maxvr = VR_INITIALIZER;
+         value_range maxvr = VR_INITIALIZER;
          signop sgn = TYPE_SIGN (TREE_TYPE (step));
          bool overflow;
 
@@ -4485,6 +4323,17 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop,
          && is_positive_overflow_infinity (max)))
     return;
 
+  /* Even for valid range info, sometimes overflow flag will leak in.
+     As GIMPLE IL should have no constants with TREE_OVERFLOW set, we
+     drop them except for +-overflow_infinity which still need special
+     handling in vrp pass.  */
+  if (TREE_OVERFLOW_P (min)
+      && ! is_negative_overflow_infinity (min))
+    min = drop_tree_overflow (min);
+  if (TREE_OVERFLOW_P (max)
+      && ! is_positive_overflow_infinity (max))
+    max = drop_tree_overflow (max);
+
   set_value_range (vr, VR_RANGE, min, max, vr->equiv);
 }
 
@@ -4504,7 +4353,7 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop,
 
 
 static tree
-compare_ranges (enum tree_code comp, value_range_t *vr0, value_range_t *vr1,
+compare_ranges (enum tree_code comp, value_range *vr0, value_range *vr1,
                bool *strict_overflow_p)
 {
   /* VARYING or UNDEFINED ranges cannot be compared.  */
@@ -4534,7 +4383,7 @@ compare_ranges (enum tree_code comp, value_range_t *vr0, value_range_t *vr1,
       if (vr0->type == VR_RANGE)
        {
          /* To simplify processing, make VR0 the anti-range.  */
-         value_range_t *tmp = vr0;
+         value_range *tmp = vr0;
          vr0 = vr1;
          vr1 = tmp;
        }
@@ -4658,7 +4507,7 @@ compare_ranges (enum tree_code comp, value_range_t *vr0, value_range_t *vr1,
    infinity was used in the test.  */
 
 static tree
-compare_range_with_value (enum tree_code comp, value_range_t *vr, tree val,
+compare_range_with_value (enum tree_code comp, value_range *vr, tree val,
                          bool *strict_overflow_p)
 {
   if (vr->type == VR_VARYING || vr->type == VR_UNDEFINED)
@@ -4780,8 +4629,8 @@ compare_range_with_value (enum tree_code comp, value_range_t *vr, tree val,
 
 /* Debugging dumps.  */
 
-void dump_value_range (FILE *, value_range_t *);
-void debug_value_range (value_range_t *);
+void dump_value_range (FILE *, value_range *);
+void debug_value_range (value_range *);
 void dump_all_value_ranges (FILE *);
 void debug_all_value_ranges (void);
 void dump_vr_equiv (FILE *, bitmap);
@@ -4791,7 +4640,7 @@ void debug_vr_equiv (bitmap);
 /* Dump value range VR to FILE.  */
 
 void
-dump_value_range (FILE *file, value_range_t *vr)
+dump_value_range (FILE *file, value_range *vr)
 {
   if (vr == NULL)
     fprintf (file, "[]");
@@ -4851,7 +4700,7 @@ dump_value_range (FILE *file, value_range_t *vr)
 /* Dump value range VR to stderr.  */
 
 DEBUG_FUNCTION void
-debug_value_range (value_range_t *vr)
+debug_value_range (value_range *vr)
 {
   dump_value_range (stderr, vr);
   fprintf (stderr, "\n");
@@ -4893,7 +4742,7 @@ debug_all_value_ranges (void)
    create a new SSA name N and return the assertion assignment
    'N = ASSERT_EXPR <V, V OP W>'.  */
 
-static gimple
+static gimple *
 build_assert_expr_for (tree cond, tree v)
 {
   tree a;
@@ -4919,7 +4768,7 @@ build_assert_expr_for (tree cond, tree v)
    point values.  */
 
 static inline bool
-fp_predicate (gimple stmt)
+fp_predicate (gimple *stmt)
 {
   GIMPLE_CHECK (stmt, GIMPLE_COND);
 
@@ -4932,7 +4781,7 @@ fp_predicate (gimple stmt)
    inferred.  */
 
 static bool
-infer_value_range (gimple stmt, tree op, enum tree_code *comp_code_p, tree *val_p)
+infer_value_range (gimple *stmt, tree op, tree_code *comp_code_p, tree *val_p)
 {
   *val_p = NULL_TREE;
   *comp_code_p = ERROR_MARK;
@@ -4963,7 +4812,7 @@ infer_value_range (gimple stmt, tree op, enum tree_code *comp_code_p, tree *val_
        return false;
     }
 
-  if (infer_nonnull_range (stmt, op, true, true))
+  if (infer_nonnull_range (stmt, op))
     {
       *val_p = build_int_cst (TREE_TYPE (op), 0);
       *comp_code_p = NE_EXPR;
@@ -4984,7 +4833,7 @@ void debug_all_asserts (void);
 void
 dump_asserts_for (FILE *file, tree name)
 {
-  assert_locus_t loc;
+  assert_locus *loc;
 
   fprintf (file, "Assertions to be inserted for ");
   print_generic_expr (file, name, 0);
@@ -5066,7 +4915,7 @@ register_new_assert_for (tree name, tree expr,
                         edge e,
                         gimple_stmt_iterator si)
 {
-  assert_locus_t n, loc, last_loc;
+  assert_locus *n, *loc, *last_loc;
   basic_block dest_bb;
 
   gcc_checking_assert (bb == NULL || e == NULL);
@@ -5141,7 +4990,7 @@ register_new_assert_for (tree name, tree expr,
   /* If we didn't find an assertion already registered for
      NAME COMP_CODE VAL, add a new one at the end of the list of
      assertions associated with NAME.  */
-  n = XNEW (struct assert_locus_d);
+  n = XNEW (struct assert_locus);
   n->bb = dest_bb;
   n->e = e;
   n->si = si;
@@ -5287,7 +5136,7 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi,
       && TREE_CODE (val) == INTEGER_CST
       && TYPE_UNSIGNED (TREE_TYPE (val)))
     {
-      gimple def_stmt = SSA_NAME_DEF_STMT (name);
+      gimple *def_stmt = SSA_NAME_DEF_STMT (name);
       tree cst2 = NULL_TREE, name2 = NULL_TREE, name3 = NULL_TREE;
 
       /* Extract CST2 from the (optional) addition.  */
@@ -5372,45 +5221,63 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi,
   /* In the case of post-in/decrement tests like if (i++) ... and uses
      of the in/decremented value on the edge the extra name we want to
      assert for is not on the def chain of the name compared.  Instead
-     it is in the set of use stmts.  */
+     it is in the set of use stmts.
+     Similar cases happen for conversions that were simplified through
+     fold_{sign_changed,widened}_comparison.  */
   if ((comp_code == NE_EXPR
        || comp_code == EQ_EXPR)
       && TREE_CODE (val) == INTEGER_CST)
     {
       imm_use_iterator ui;
-      gimple use_stmt;
+      gimple *use_stmt;
       FOR_EACH_IMM_USE_STMT (use_stmt, ui, name)
        {
-         /* Cut off to use-stmts that are in the predecessor.  */
-         if (gimple_bb (use_stmt) != e->src)
-           continue;
-
          if (!is_gimple_assign (use_stmt))
            continue;
 
-         enum tree_code code = gimple_assign_rhs_code (use_stmt);
-         if (code != PLUS_EXPR
-             && code != MINUS_EXPR)
+         /* Cut off to use-stmts that are dominating the predecessor.  */
+         if (!dominated_by_p (CDI_DOMINATORS, e->src, gimple_bb (use_stmt)))
            continue;
 
-         tree cst = gimple_assign_rhs2 (use_stmt);
-         if (TREE_CODE (cst) != INTEGER_CST)
+         tree name2 = gimple_assign_lhs (use_stmt);
+         if (TREE_CODE (name2) != SSA_NAME
+             || !live_on_edge (e, name2))
            continue;
 
-         tree name2 = gimple_assign_lhs (use_stmt);
-         if (live_on_edge (e, name2))
+         enum tree_code code = gimple_assign_rhs_code (use_stmt);
+         tree cst;
+         if (code == PLUS_EXPR
+             || code == MINUS_EXPR)
            {
+             cst = gimple_assign_rhs2 (use_stmt);
+             if (TREE_CODE (cst) != INTEGER_CST)
+               continue;
              cst = int_const_binop (code, val, cst);
-             register_new_assert_for (name2, name2, comp_code, cst,
-                                      NULL, e, bsi);
            }
+         else if (CONVERT_EXPR_CODE_P (code))
+           {
+             /* For truncating conversions we cannot record
+                an inequality.  */
+             if (comp_code == NE_EXPR
+                 && (TYPE_PRECISION (TREE_TYPE (name2))
+                     < TYPE_PRECISION (TREE_TYPE (name))))
+               continue;
+             cst = fold_convert (TREE_TYPE (name2), val);
+           }
+         else
+           continue;
+
+         if (TREE_OVERFLOW_P (cst))
+           cst = drop_tree_overflow (cst);
+         register_new_assert_for (name2, name2, comp_code, cst,
+                                  NULL, e, bsi);
        }
     }
  
   if (TREE_CODE_CLASS (comp_code) == tcc_comparison
       && TREE_CODE (val) == INTEGER_CST)
     {
-      gimple def_stmt = SSA_NAME_DEF_STMT (name);
+      gimple *def_stmt = SSA_NAME_DEF_STMT (name);
       tree name2 = NULL_TREE, names[2], cst2 = NULL_TREE;
       tree val2 = NULL_TREE;
       unsigned int prec = TYPE_PRECISION (TREE_TYPE (val));
@@ -5580,7 +5447,7 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi,
              && (nprec > 1
                  || TYPE_UNSIGNED (TREE_TYPE (val))))
            {
-             gimple def_stmt2 = SSA_NAME_DEF_STMT (name2);
+             gimple *def_stmt2 = SSA_NAME_DEF_STMT (name2);
              if (gimple_assign_cast_p (def_stmt2))
                {
                  names[1] = gimple_assign_rhs1 (def_stmt2);
@@ -5804,7 +5671,7 @@ static void
 register_edge_assert_for_1 (tree op, enum tree_code code,
                            edge e, gimple_stmt_iterator bsi)
 {
-  gimple op_def;
+  gimple *op_def;
   tree val;
   enum tree_code rhs_code;
 
@@ -5919,7 +5786,7 @@ register_edge_assert_for (tree name, edge e, gimple_stmt_iterator si,
   if (((comp_code == EQ_EXPR && integer_onep (val))
        || (comp_code == NE_EXPR && integer_zerop (val))))
     {
-      gimple def_stmt = SSA_NAME_DEF_STMT (name);
+      gimple *def_stmt = SSA_NAME_DEF_STMT (name);
 
       if (is_gimple_assign (def_stmt)
          && gimple_assign_rhs_code (def_stmt) == BIT_AND_EXPR)
@@ -5937,7 +5804,7 @@ register_edge_assert_for (tree name, edge e, gimple_stmt_iterator si,
   if (((comp_code == EQ_EXPR && integer_zerop (val))
        || (comp_code == NE_EXPR && integer_onep (val))))
     {
-      gimple def_stmt = SSA_NAME_DEF_STMT (name);
+      gimple *def_stmt = SSA_NAME_DEF_STMT (name);
 
       /* For BIT_IOR_EXPR only if NAME == 0 both operands have
         necessarily zero value, or if type-precision is one.  */
@@ -6174,7 +6041,7 @@ find_switch_asserts (basic_block bb, gswitch *last)
 static void
 find_assert_locations_1 (basic_block bb, sbitmap live)
 {
-  gimple last;
+  gimple *last;
 
   last = last_stmt (bb);
 
@@ -6198,7 +6065,7 @@ find_assert_locations_1 (basic_block bb, sbitmap live)
   for (gimple_stmt_iterator si = gsi_last_bb (bb); !gsi_end_p (si);
        gsi_prev (&si))
     {
-      gimple stmt;
+      gimple *stmt;
       tree op;
       ssa_op_iter i;
 
@@ -6232,7 +6099,7 @@ find_assert_locations_1 (basic_block bb, sbitmap live)
              if (comp_code == NE_EXPR && integer_zerop (value))
                {
                  tree t = op;
-                 gimple def_stmt = SSA_NAME_DEF_STMT (t);
+                 gimple *def_stmt = SSA_NAME_DEF_STMT (t);
 
                  while (is_gimple_assign (def_stmt)
                         && CONVERT_EXPR_CODE_P
@@ -6402,12 +6269,12 @@ find_assert_locations (void)
    indicated by LOC.  Return true if we made any edge insertions.  */
 
 static bool
-process_assert_insertions_for (tree name, assert_locus_t loc)
+process_assert_insertions_for (tree name, assert_locus *loc)
 {
   /* Build the comparison expression NAME_i COMP_CODE VAL.  */
-  gimple stmt;
+  gimple *stmt;
   tree cond;
-  gimple assert_stmt;
+  gimple *assert_stmt;
   edge_iterator ei;
   edge e;
 
@@ -6470,12 +6337,12 @@ process_assert_insertions (void)
 
   EXECUTE_IF_SET_IN_BITMAP (need_assert_for, 0, i, bi)
     {
-      assert_locus_t loc = asserts_for[i];
+      assert_locus *loc = asserts_for[i];
       gcc_assert (loc);
 
       while (loc)
        {
-         assert_locus_t next = loc->next;
+         assert_locus *next = loc->next;
          update_edges_p |= process_assert_insertions_for (ssa_name (i), loc);
          free (loc);
          loc = next;
@@ -6527,7 +6394,7 @@ static void
 insert_range_assertions (void)
 {
   need_assert_for = BITMAP_ALLOC (NULL);
-  asserts_for = XCNEWVEC (assert_locus_t, num_ssa_names);
+  asserts_for = XCNEWVEC (assert_locus *, num_ssa_names);
 
   calculate_dominance_info (CDI_DOMINATORS);
 
@@ -6558,7 +6425,7 @@ insert_range_assertions (void)
 static void
 check_array_ref (location_t location, tree ref, bool ignore_off_by_one)
 {
-  value_range_t* vr = NULL;
+  value_range *vr = NULL;
   tree low_sub, up_sub;
   tree low_bound, up_bound, up_bound_p1;
   tree base;
@@ -6791,15 +6658,16 @@ check_all_array_refs (void)
 
       for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
        {
-         gimple stmt = gsi_stmt (si);
+         gimple *stmt = gsi_stmt (si);
          struct walk_stmt_info wi;
          if (!gimple_has_location (stmt)
              || is_gimple_debug (stmt))
            continue;
 
          memset (&wi, 0, sizeof (wi));
-         wi.info = CONST_CAST (void *, (const void *)
-                               gimple_location_ptr (stmt));
+
+         location_t loc = gimple_location (stmt);
+         wi.info = &loc;
 
          walk_gimple_op (gsi_stmt (si),
                          check_array_bounds,
@@ -6813,7 +6681,7 @@ check_all_array_refs (void)
    in basic block COND_BB.  */
 
 static bool
-all_imm_uses_in_stmt_or_feed_cond (tree var, gimple stmt, basic_block cond_bb)
+all_imm_uses_in_stmt_or_feed_cond (tree var, gimple *stmt, basic_block cond_bb)
 {
   use_operand_p use_p, use2_p;
   imm_use_iterator iter;
@@ -6821,7 +6689,7 @@ all_imm_uses_in_stmt_or_feed_cond (tree var, gimple stmt, basic_block cond_bb)
   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
     if (USE_STMT (use_p) != stmt)
       {
-       gimple use_stmt = USE_STMT (use_p), use_stmt2;
+       gimple *use_stmt = USE_STMT (use_p), *use_stmt2;
        if (is_gimple_debug (use_stmt))
          continue;
        while (is_gimple_assign (use_stmt)
@@ -6855,7 +6723,7 @@ maybe_set_nonzero_bits (basic_block bb, tree var)
 {
   edge e = single_pred_edge (bb);
   basic_block cond_bb = e->src;
-  gimple stmt = last_stmt (cond_bb);
+  gimple *stmt = last_stmt (cond_bb);
   tree cst;
 
   if (stmt == NULL
@@ -6873,7 +6741,7 @@ maybe_set_nonzero_bits (basic_block bb, tree var)
     return;
   if (gimple_assign_rhs1 (stmt) != var)
     {
-      gimple stmt2;
+      gimple *stmt2;
 
       if (TREE_CODE (gimple_assign_rhs1 (stmt)) != SSA_NAME)
        return;
@@ -6929,8 +6797,8 @@ remove_range_assertions (void)
   FOR_EACH_BB_FN (bb, cfun)
     for (si = gsi_after_labels (bb), is_unreachable = -1; !gsi_end_p (si);)
       {
-       gimple stmt = gsi_stmt (si);
-       gimple use_stmt;
+       gimple *stmt = gsi_stmt (si);
+       gimple *use_stmt;
 
        if (is_gimple_assign (stmt)
            && gimple_assign_rhs_code (stmt) == ASSERT_EXPR)
@@ -6938,12 +6806,9 @@ remove_range_assertions (void)
            tree lhs = gimple_assign_lhs (stmt);
            tree rhs = gimple_assign_rhs1 (stmt);
            tree var;
-           tree cond = fold (ASSERT_EXPR_COND (rhs));
            use_operand_p use_p;
            imm_use_iterator iter;
 
-           gcc_assert (cond != boolean_false_node);
-
            var = ASSERT_EXPR_VAR (rhs);
            gcc_assert (TREE_CODE (var) == SSA_NAME);
 
@@ -6999,7 +6864,7 @@ remove_range_assertions (void)
 /* Return true if STMT is interesting for VRP.  */
 
 static bool
-stmt_interesting_for_vrp (gimple stmt)
+stmt_interesting_for_vrp (gimple *stmt)
 {
   if (gimple_code (stmt) == GIMPLE_PHI)
     {
@@ -7053,7 +6918,7 @@ vrp_initialize (void)
 
   values_propagated = false;
   num_vr_values = num_ssa_names;
-  vr_value = XCNEWVEC (value_range_t *, num_vr_values);
+  vr_value = XCNEWVEC (value_range *, num_vr_values);
   vr_phi_edge_counts = XCNEWVEC (int, num_ssa_names);
 
   FOR_EACH_BB_FN (bb, cfun)
@@ -7075,7 +6940,7 @@ vrp_initialize (void)
       for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
           gsi_next (&si))
         {
-         gimple stmt = gsi_stmt (si);
+         gimple *stmt = gsi_stmt (si);
 
          /* If the statement is a control insn, then we do not
             want to avoid simulating the statement once.  Failure
@@ -7103,7 +6968,7 @@ vrp_valueize (tree name)
 {
   if (TREE_CODE (name) == SSA_NAME)
     {
-      value_range_t *vr = get_value_range (name);
+      value_range *vr = get_value_range (name);
       if (vr->type == VR_RANGE
          && (vr->min == vr->max
              || operand_equal_p (vr->min, vr->max, 0)))
@@ -7123,11 +6988,11 @@ vrp_valueize_1 (tree name)
       /* If the definition may be simulated again we cannot follow
          this SSA edge as the SSA propagator does not necessarily
         re-visit the use.  */
-      gimple def_stmt = SSA_NAME_DEF_STMT (name);
+      gimple *def_stmt = SSA_NAME_DEF_STMT (name);
       if (!gimple_nop_p (def_stmt)
          && prop_simulate_again_p (def_stmt))
        return NULL_TREE;
-      value_range_t *vr = get_value_range (name);
+      value_range *vr = get_value_range (name);
       if (range_int_cst_singleton_p (vr))
        return vr->min;
     }
@@ -7138,7 +7003,7 @@ vrp_valueize_1 (tree name)
    the SSA name in *OUTPUT_P.  */
 
 static enum ssa_prop_result
-vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
+vrp_visit_assignment_or_call (gimple *stmt, tree *output_p)
 {
   tree def, lhs;
   ssa_op_iter iter;
@@ -7154,7 +7019,7 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
           && TYPE_MAX_VALUE (TREE_TYPE (lhs)))
          || POINTER_TYPE_P (TREE_TYPE (lhs))))
     {
-      value_range_t new_vr = VR_INITIALIZER;
+      value_range new_vr = VR_INITIALIZER;
 
       /* Try folding the statement to a constant first.  */
       tree tem = gimple_fold_stmt_to_constant_1 (stmt, vrp_valueize,
@@ -7207,7 +7072,7 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
 
            FOR_EACH_IMM_USE_FAST (use_p, iter, lhs)
              {
-               gimple use_stmt = USE_STMT (use_p);
+               gimple *use_stmt = USE_STMT (use_p);
                if (!is_gimple_assign (use_stmt))
                  continue;
                enum tree_code rhs_code = gimple_assign_rhs_code (use_stmt);
@@ -7232,9 +7097,9 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
                   SSA_PROP_NOT_INTERESTING.  If there are no
                   {REAL,IMAG}PART_EXPR uses at all,
                   return SSA_PROP_VARYING.  */
-               value_range_t new_vr = VR_INITIALIZER;
+               value_range new_vr = VR_INITIALIZER;
                extract_range_basic (&new_vr, use_stmt);
-               value_range_t *old_vr = get_value_range (use_lhs);
+               value_range *old_vr = get_value_range (use_lhs);
                if (old_vr->type != new_vr.type
                    || !vrp_operand_equal_p (old_vr->min, new_vr.min)
                    || !vrp_operand_equal_p (old_vr->max, new_vr.max)
@@ -7268,10 +7133,10 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
    or a symbolic range containing the SSA_NAME only if the value range
    is varying or undefined.  */
 
-static inline value_range_t
+static inline value_range
 get_vr_for_comparison (int i)
 {
-  value_range_t vr = *get_value_range (ssa_name (i));
+  value_range vr = *get_value_range (ssa_name (i));
 
   /* If name N_i does not have a valid range, use N_i as its own
      range.  This allows us to compare against names that may
@@ -7301,7 +7166,7 @@ compare_name_with_value (enum tree_code comp, tree var, tree val,
   tree retval, t;
   int used_strict_overflow;
   bool sop;
-  value_range_t equiv_vr;
+  value_range equiv_vr;
 
   /* Get the set of equivalences for VAR.  */
   e = get_value_range (var)->equiv;
@@ -7424,14 +7289,14 @@ compare_names (enum tree_code comp, tree n1, tree n2,
      of the loop just to check N1 and N2 ranges.  */
   EXECUTE_IF_SET_IN_BITMAP (e1, 0, i1, bi1)
     {
-      value_range_t vr1 = get_vr_for_comparison (i1);
+      value_range vr1 = get_vr_for_comparison (i1);
 
       t = retval = NULL_TREE;
       EXECUTE_IF_SET_IN_BITMAP (e2, 0, i2, bi2)
        {
          bool sop = false;
 
-         value_range_t vr2 = get_vr_for_comparison (i2);
+         value_range vr2 = get_vr_for_comparison (i2);
 
          t = compare_ranges (comp, &vr1, &vr2, &sop);
          if (t)
@@ -7473,14 +7338,15 @@ compare_names (enum tree_code comp, tree n1, tree n2,
   return NULL_TREE;
 }
 
-/* Helper function for vrp_evaluate_conditional_warnv.  */
+/* Helper function for vrp_evaluate_conditional_warnv & other
+   optimizers.  */
 
 static tree
 vrp_evaluate_conditional_warnv_with_ops_using_ranges (enum tree_code code,
                                                      tree op0, tree op1,
                                                      bool * strict_overflow_p)
 {
-  value_range_t *vr0, *vr1;
+  value_range *vr0, *vr1;
 
   vr0 = (TREE_CODE (op0) == SSA_NAME) ? get_value_range (op0) : NULL;
   vr1 = (TREE_CODE (op1) == SSA_NAME) ? get_value_range (op1) : NULL;
@@ -7541,7 +7407,7 @@ vrp_evaluate_conditional_warnv_with_ops (enum tree_code code, tree op0,
    appropriate.  */
 
 static tree
-vrp_evaluate_conditional (enum tree_code code, tree op0, tree op1, gimple stmt)
+vrp_evaluate_conditional (tree_code code, tree op0, tree op1, gimple *stmt)
 {
   bool sop;
   tree ret;
@@ -7600,7 +7466,7 @@ vrp_evaluate_conditional (enum tree_code code, tree op0, tree op1, gimple stmt)
         always fold regardless of the value of OP0.  If -Wtype-limits
         was specified, emit a warning.  */
       tree type = TREE_TYPE (op0);
-      value_range_t *vr0 = get_value_range (op0);
+      value_range *vr0 = get_value_range (op0);
 
       if (vr0->type == VR_RANGE
          && INTEGRAL_TYPE_P (type)
@@ -7855,7 +7721,7 @@ find_case_label_range (gswitch *stmt, tree min, tree max, size_t *min_idx,
    Returns true if the default label is not needed.  */
 
 static bool
-find_case_label_ranges (gswitch *stmt, value_range_t *vr, size_t *min_idx1,
+find_case_label_ranges (gswitch *stmt, value_range *vr, size_t *min_idx1,
                        size_t *max_idx1, size_t *min_idx2,
                        size_t *max_idx2)
 {
@@ -7936,7 +7802,7 @@ static enum ssa_prop_result
 vrp_visit_switch_stmt (gswitch *stmt, edge *taken_edge_p)
 {
   tree op, val;
-  value_range_t *vr;
+  value_range *vr;
   size_t i = 0, j = 0, k, l;
   bool take_default;
 
@@ -8030,7 +7896,7 @@ vrp_visit_switch_stmt (gswitch *stmt, edge *taken_edge_p)
    If STMT produces a varying value, return SSA_PROP_VARYING.  */
 
 static enum ssa_prop_result
-vrp_visit_stmt (gimple stmt, edge *taken_edge_p, tree *output_p)
+vrp_visit_stmt (gimple *stmt, edge *taken_edge_p, tree *output_p)
 {
   tree def;
   ssa_op_iter iter;
@@ -8609,9 +8475,9 @@ intersect_ranges (enum value_range_type *vr0type,
    in *VR0.  This may not be the smallest possible such range.  */
 
 static void
-vrp_intersect_ranges_1 (value_range_t *vr0, value_range_t *vr1)
+vrp_intersect_ranges_1 (value_range *vr0, value_range *vr1)
 {
-  value_range_t saved;
+  value_range saved;
 
   /* If either range is VR_VARYING the other one wins.  */
   if (vr1->type == VR_VARYING)
@@ -8661,7 +8527,7 @@ vrp_intersect_ranges_1 (value_range_t *vr0, value_range_t *vr1)
 }
 
 static void
-vrp_intersect_ranges (value_range_t *vr0, value_range_t *vr1)
+vrp_intersect_ranges (value_range *vr0, value_range *vr1)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
@@ -8685,9 +8551,9 @@ vrp_intersect_ranges (value_range_t *vr0, value_range_t *vr1)
    may not be the smallest possible such range.  */
 
 static void
-vrp_meet_1 (value_range_t *vr0, value_range_t *vr1)
+vrp_meet_1 (value_range *vr0, value_range *vr1)
 {
-  value_range_t saved;
+  value_range saved;
 
   if (vr0->type == VR_UNDEFINED)
     {
@@ -8758,7 +8624,7 @@ vrp_meet_1 (value_range_t *vr0, value_range_t *vr1)
 }
 
 static void
-vrp_meet (value_range_t *vr0, value_range_t *vr1)
+vrp_meet (value_range *vr0, value_range *vr1)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
@@ -8787,8 +8653,8 @@ vrp_visit_phi_node (gphi *phi)
 {
   size_t i;
   tree lhs = PHI_RESULT (phi);
-  value_range_t *lhs_vr = get_value_range (lhs);
-  value_range_t vr_result = VR_INITIALIZER;
+  value_range *lhs_vr = get_value_range (lhs);
+  value_range vr_result = VR_INITIALIZER;
   bool first = true;
   int edges, old_edges;
   struct loop *l;
@@ -8815,7 +8681,7 @@ vrp_visit_phi_node (gphi *phi)
       if (e->flags & EDGE_EXECUTABLE)
        {
          tree arg = PHI_ARG_DEF (phi, i);
-         value_range_t vr_arg;
+         value_range vr_arg;
 
          ++edges;
 
@@ -8918,7 +8784,7 @@ vrp_visit_phi_node (gphi *phi)
          && (cmp_min != 0 || cmp_max != 0))
        goto varying;
 
-      /* If the new minimum is larger than than the previous one
+      /* If the new minimum is larger than the previous one
         retain the old value.  If the new minimum value is smaller
         than the previous one and not -INF go all the way to -INF + 1.
         In the first case, to avoid infinite bouncing between different
@@ -8947,20 +8813,11 @@ vrp_visit_phi_node (gphi *phi)
 
       /* If we dropped either bound to +-INF then if this is a loop
         PHI node SCEV may known more about its value-range.  */
-      if ((cmp_min > 0 || cmp_min < 0
+      if (cmp_min > 0 || cmp_min < 0
           || cmp_max < 0 || cmp_max > 0)
-         && (l = loop_containing_stmt (phi))
-         && l->header == gimple_bb (phi))
-       adjust_range_with_scev (&vr_result, l, phi, lhs);
-
-      /* If we will end up with a (-INF, +INF) range, set it to
-        VARYING.  Same if the previous max value was invalid for
-        the type and we end up with vr_result.min > vr_result.max.  */
-      if ((vrp_val_is_max (vr_result.max)
-          && vrp_val_is_min (vr_result.min))
-         || compare_values (vr_result.min,
-                            vr_result.max) > 0)
-       goto varying;
+       goto scev_check;
+
+      goto infinite_check;
     }
 
   /* If the new range is different than the previous value, keep
@@ -8986,8 +8843,28 @@ update_range:
   /* Nothing changed, don't add outgoing edges.  */
   return SSA_PROP_NOT_INTERESTING;
 
-  /* No match found.  Set the LHS to VARYING.  */
 varying:
+  set_value_range_to_varying (&vr_result);
+
+scev_check:
+  /* If this is a loop PHI node SCEV may known more about its value-range.
+     scev_check can be reached from two paths, one is a fall through from above
+     "varying" label, the other is direct goto from code block which tries to
+     avoid infinite simulation.  */
+  if ((l = loop_containing_stmt (phi))
+      && l->header == gimple_bb (phi))
+    adjust_range_with_scev (&vr_result, l, phi, lhs);
+
+infinite_check:
+  /* If we will end up with a (-INF, +INF) range, set it to
+     VARYING.  Same if the previous max value was invalid for
+     the type and we end up with vr_result.min > vr_result.max.  */
+  if ((vr_result.type == VR_RANGE || vr_result.type == VR_ANTI_RANGE)
+      && !((vrp_val_is_max (vr_result.max) && vrp_val_is_min (vr_result.min))
+          || compare_values (vr_result.min, vr_result.max) > 0))
+    goto update_range;
+
+  /* No match found.  Set the LHS to VARYING.  */
   set_value_range_to_varying (lhs_vr);
   return SSA_PROP_VARYING;
 }
@@ -8995,7 +8872,7 @@ varying:
 /* Simplify boolean operations if the source is known
    to be already a boolean.  */
 static bool
-simplify_truth_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
+simplify_truth_ops_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt)
 {
   enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
   tree lhs, op0, op1;
@@ -9065,13 +8942,13 @@ simplify_truth_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
    modulo.  */
 
 static bool
-simplify_div_or_mod_using_ranges (gimple stmt)
+simplify_div_or_mod_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt)
 {
   enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
   tree val = NULL;
   tree op0 = gimple_assign_rhs1 (stmt);
   tree op1 = gimple_assign_rhs2 (stmt);
-  value_range_t *vr = get_value_range (op0);
+  value_range *vr = get_value_range (op0);
 
   if (rhs_code == TRUNC_MOD_EXPR
       && TREE_CODE (op1) == INTEGER_CST
@@ -9094,12 +8971,19 @@ simplify_div_or_mod_using_ranges (gimple stmt)
     }
 
   if (!integer_pow2p (op1))
-    return false;
-
-  if (TYPE_UNSIGNED (TREE_TYPE (op0)))
     {
-      val = integer_one_node;
+      /* X % -Y can be only optimized into X % Y either if
+        X is not INT_MIN, or Y is not -1.  Fold it now, as after
+        remove_range_assertions the range info might be not available
+        anymore.  */
+      if (rhs_code == TRUNC_MOD_EXPR
+         && fold_stmt (gsi, follow_single_use_edges))
+       return true;
+      return false;
     }
+
+  if (TYPE_UNSIGNED (TREE_TYPE (op0)))
+    val = integer_one_node;
   else
     {
       bool sop = false;
@@ -9152,44 +9036,80 @@ simplify_div_or_mod_using_ranges (gimple stmt)
   return false;
 }
 
+/* Simplify a min or max if the ranges of the two operands are
+   disjoint.   Return true if we do simplify.  */
+
+static bool
+simplify_min_or_max_using_ranges (gimple *stmt)
+{
+  tree op0 = gimple_assign_rhs1 (stmt);
+  tree op1 = gimple_assign_rhs2 (stmt);
+  bool sop = false;
+  tree val;
+
+  val = (vrp_evaluate_conditional_warnv_with_ops_using_ranges
+        (LE_EXPR, op0, op1, &sop));
+  if (!val)
+    {
+      sop = false;
+      val = (vrp_evaluate_conditional_warnv_with_ops_using_ranges
+            (LT_EXPR, op0, op1, &sop));
+    }
+
+  if (val)
+    {
+      if (sop && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_MISC))
+       {
+         location_t location;
+
+         if (!gimple_has_location (stmt))
+           location = input_location;
+         else
+           location = gimple_location (stmt);
+         warning_at (location, OPT_Wstrict_overflow,
+                     "assuming signed overflow does not occur when "
+                     "simplifying %<min/max (X,Y)%> to %<X%> or %<Y%>");
+       }
+
+      /* VAL == TRUE -> OP0 < or <= op1
+        VAL == FALSE -> OP0 > or >= op1.  */
+      tree res = ((gimple_assign_rhs_code (stmt) == MAX_EXPR)
+                 == integer_zerop (val)) ? op0 : op1;
+      gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+      gimple_assign_set_rhs_from_tree (&gsi, res);
+      update_stmt (stmt);
+      return true;
+    }
+
+  return false;
+}
+
 /* If the operand to an ABS_EXPR is >= 0, then eliminate the
    ABS_EXPR.  If the operand is <= 0, then simplify the
    ABS_EXPR into a NEGATE_EXPR.  */
 
 static bool
-simplify_abs_using_ranges (gimple stmt)
+simplify_abs_using_ranges (gimple *stmt)
 {
-  tree val = NULL;
   tree op = gimple_assign_rhs1 (stmt);
-  tree type = TREE_TYPE (op);
-  value_range_t *vr = get_value_range (op);
+  value_range *vr = get_value_range (op);
 
-  if (TYPE_UNSIGNED (type))
-    {
-      val = integer_zero_node;
-    }
-  else if (vr)
+  if (vr)
     {
+      tree val = NULL;
       bool sop = false;
 
       val = compare_range_with_value (LE_EXPR, vr, integer_zero_node, &sop);
       if (!val)
        {
+         /* The range is neither <= 0 nor > 0.  Now see if it is
+            either < 0 or >= 0.  */
          sop = false;
-         val = compare_range_with_value (GE_EXPR, vr, integer_zero_node,
+         val = compare_range_with_value (LT_EXPR, vr, integer_zero_node,
                                          &sop);
-
-         if (val)
-           {
-             if (integer_zerop (val))
-               val = integer_one_node;
-             else if (integer_onep (val))
-               val = integer_zero_node;
-           }
        }
 
-      if (val
-         && (integer_onep (val) || integer_zerop (val)))
+      if (val)
        {
          if (sop && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_MISC))
            {
@@ -9205,10 +9125,10 @@ simplify_abs_using_ranges (gimple stmt)
            }
 
          gimple_assign_set_rhs1 (stmt, op);
-         if (integer_onep (val))
-           gimple_assign_set_rhs_code (stmt, NEGATE_EXPR);
-         else
+         if (integer_zerop (val))
            gimple_assign_set_rhs_code (stmt, SSA_NAME);
+         else
+           gimple_assign_set_rhs_code (stmt, NEGATE_EXPR);
          update_stmt (stmt);
          return true;
        }
@@ -9224,13 +9144,13 @@ simplify_abs_using_ranges (gimple stmt)
    operation is redundant.  */
 
 static bool
-simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
+simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt)
 {
   tree op0 = gimple_assign_rhs1 (stmt);
   tree op1 = gimple_assign_rhs2 (stmt);
   tree op = NULL_TREE;
-  value_range_t vr0 = VR_INITIALIZER;
-  value_range_t vr1 = VR_INITIALIZER;
+  value_range vr0 = VR_INITIALIZER;
+  value_range vr1 = VR_INITIALIZER;
   wide_int may_be_nonzero0, may_be_nonzero1;
   wide_int must_be_nonzero0, must_be_nonzero1;
   wide_int mask;
@@ -9309,7 +9229,7 @@ simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
 
 static tree
 test_for_singularity (enum tree_code cond_code, tree op0,
-                     tree op1, value_range_t *vr,
+                     tree op1, value_range *vr,
                      bool *strict_overflow_p)
 {
   tree min = NULL;
@@ -9379,7 +9299,7 @@ test_for_singularity (enum tree_code cond_code, tree op0,
    by PRECISION and UNSIGNED_P.  */
 
 static bool
-range_fits_type_p (value_range_t *vr, unsigned dest_precision, signop dest_sgn)
+range_fits_type_p (value_range *vr, unsigned dest_precision, signop dest_sgn)
 {
   tree src_type;
   unsigned src_precision;
@@ -9444,7 +9364,7 @@ simplify_cond_using_ranges (gcond *stmt)
       && INTEGRAL_TYPE_P (TREE_TYPE (op0))
       && is_gimple_min_invariant (op1))
     {
-      value_range_t *vr = get_value_range (op0);
+      value_range *vr = get_value_range (op0);
 
       /* If we have range information for OP0, then we might be
         able to simplify this conditional. */
@@ -9547,7 +9467,7 @@ simplify_cond_using_ranges (gcond *stmt)
   if (TREE_CODE (op0) == SSA_NAME
       && TREE_CODE (op1) == INTEGER_CST)
     {
-      gimple def_stmt = SSA_NAME_DEF_STMT (op0);
+      gimple *def_stmt = SSA_NAME_DEF_STMT (op0);
       tree innerop;
 
       if (!is_gimple_assign (def_stmt)
@@ -9557,9 +9477,11 @@ simplify_cond_using_ranges (gcond *stmt)
       innerop = gimple_assign_rhs1 (def_stmt);
 
       if (TREE_CODE (innerop) == SSA_NAME
-         && !POINTER_TYPE_P (TREE_TYPE (innerop)))
+         && !POINTER_TYPE_P (TREE_TYPE (innerop))
+         && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop)
+         && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0)))
        {
-         value_range_t *vr = get_value_range (innerop);
+         value_range *vr = get_value_range (innerop);
 
          if (range_int_cst_p (vr)
              && range_fits_type_p (vr,
@@ -9588,8 +9510,8 @@ simplify_cond_using_ranges (gcond *stmt)
                  else
                    location = gimple_location (stmt);
                  warning_at (location, OPT_Wstrict_overflow,
-                     "assuming signed overflow does not occur when "
-                     "simplifying conditional");
+                             "assuming signed overflow does not occur when "
+                             "simplifying conditional");
                }
 
              tree newconst = fold_convert (TREE_TYPE (innerop), op1);
@@ -9610,7 +9532,7 @@ static bool
 simplify_switch_using_ranges (gswitch *stmt)
 {
   tree op = gimple_switch_index (stmt);
-  value_range_t *vr;
+  value_range *vr;
   bool take_default;
   edge e;
   edge_iterator ei;
@@ -9705,11 +9627,11 @@ simplify_switch_using_ranges (gswitch *stmt)
 /* Simplify an integral conversion from an SSA name in STMT.  */
 
 static bool
-simplify_conversion_using_ranges (gimple stmt)
+simplify_conversion_using_ranges (gimple *stmt)
 {
   tree innerop, middleop, finaltype;
-  gimple def_stmt;
-  value_range_t *innervr;
+  gimple *def_stmt;
+  value_range *innervr;
   signop inner_sgn, middle_sgn, final_sgn;
   unsigned inner_prec, middle_prec, final_prec;
   widest_int innermin, innermed, innermax, middlemin, middlemed, middlemax;
@@ -9784,10 +9706,11 @@ simplify_conversion_using_ranges (gimple stmt)
 /* Simplify a conversion from integral SSA name to float in STMT.  */
 
 static bool
-simplify_float_conversion_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
+simplify_float_conversion_using_ranges (gimple_stmt_iterator *gsi,
+                                       gimple *stmt)
 {
   tree rhs1 = gimple_assign_rhs1 (stmt);
-  value_range_t *vr = get_value_range (rhs1);
+  value_range *vr = get_value_range (rhs1);
   machine_mode fltmode = TYPE_MODE (TREE_TYPE (gimple_assign_lhs (stmt)));
   machine_mode mode;
   tree tem;
@@ -9849,7 +9772,7 @@ simplify_float_conversion_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
 /* Simplify an internal fn call using ranges if possible.  */
 
 static bool
-simplify_internal_call_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
+simplify_internal_call_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt)
 {
   enum tree_code subcode;
   bool is_ubsan = false;
@@ -9894,7 +9817,7 @@ simplify_internal_call_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
       || (is_ubsan && ovf))
     return false;
 
-  gimple g;
+  gimple *g;
   location_t loc = gimple_location (stmt);
   if (is_ubsan)
     g = gimple_build_assign (gimple_call_lhs (stmt), subcode, op0, op1);
@@ -9948,7 +9871,7 @@ simplify_internal_call_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
 static bool
 simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
 {
-  gimple stmt = gsi_stmt (*gsi);
+  gimple *stmt = gsi_stmt (*gsi);
   if (is_gimple_assign (stmt))
     {
       enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
@@ -9975,7 +9898,7 @@ simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
        case TRUNC_MOD_EXPR:
          if (TREE_CODE (rhs1) == SSA_NAME
              && INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
-           return simplify_div_or_mod_using_ranges (stmt);
+           return simplify_div_or_mod_using_ranges (gsi, stmt);
          break;
 
       /* Transform ABS (X) into X or -X as appropriate.  */
@@ -10006,6 +9929,11 @@ simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
            return simplify_float_conversion_using_ranges (gsi, stmt);
          break;
 
+       case MIN_EXPR:
+       case MAX_EXPR:
+         return simplify_min_or_max_using_ranges (stmt);
+         break;
+
        default:
          break;
        }
@@ -10030,7 +9958,7 @@ fold_predicate_in (gimple_stmt_iterator *si)
 {
   bool assignment_p = false;
   tree val;
-  gimple stmt = gsi_stmt (*si);
+  gimple *stmt = gsi_stmt (*si);
 
   if (is_gimple_assign (stmt)
       && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison)
@@ -10103,7 +10031,8 @@ const_and_copies *equiv_stack;
    for any overflow warnings.  */
 
 static tree
-simplify_stmt_for_jump_threading (gimple stmt, gimple within_stmt)
+simplify_stmt_for_jump_threading (gimple *stmt, gimple *within_stmt,
+    class avail_exprs_stack *avail_exprs_stack ATTRIBUTE_UNUSED)
 {
   if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
     return vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
@@ -10113,7 +10042,7 @@ simplify_stmt_for_jump_threading (gimple stmt, gimple within_stmt)
 
   if (gassign *assign_stmt = dyn_cast <gassign *> (stmt))
     {
-      value_range_t new_vr = VR_INITIALIZER;
+      value_range new_vr = VR_INITIALIZER;
       tree lhs = gimple_assign_lhs (assign_stmt);
 
       if (TREE_CODE (lhs) == SSA_NAME
@@ -10170,13 +10099,13 @@ identify_jump_threads (void)
   mark_dfs_back_edges ();
 
   /* Do not thread across edges we are about to remove.  Just marking
-     them as EDGE_DFS_BACK will do.  */
+     them as EDGE_IGNORE will do.  */
   FOR_EACH_VEC_ELT (to_remove_edges, i, e)
-    e->flags |= EDGE_DFS_BACK;
+    e->flags |= EDGE_IGNORE;
 
   /* Allocate our unwinder stack to unwind any temporary equivalences
      that might be recorded.  */
-  equiv_stack = new const_and_copies (dump_file, dump_flags);
+  equiv_stack = new const_and_copies ();
 
   /* To avoid lots of silly node creation, we create a single
      conditional and just modify it in-place when attempting to
@@ -10193,7 +10122,7 @@ identify_jump_threads (void)
      point in compilation.  */
   FOR_EACH_BB_FN (bb, cfun)
     {
-      gimple last;
+      gimple *last;
 
       /* If the generic jump threading code does not find this block
         interesting, then there is nothing to do.  */
@@ -10229,17 +10158,21 @@ identify_jump_threads (void)
             it to a specific successor.  */
          FOR_EACH_EDGE (e, ei, bb->preds)
            {
-             /* Do not thread across back edges or abnormal edges
-                in the CFG.  */
-             if (e->flags & (EDGE_DFS_BACK | EDGE_COMPLEX))
+             /* Do not thread across edges marked to ignoreor abnormal
+                edges in the CFG.  */
+             if (e->flags & (EDGE_IGNORE | EDGE_COMPLEX))
                continue;
 
-             thread_across_edge (dummy, e, true, equiv_stack,
+             thread_across_edge (dummy, e, true, equiv_stack, NULL,
                                  simplify_stmt_for_jump_threading);
            }
        }
     }
 
+  /* Clear EDGE_IGNORE.  */
+  FOR_EACH_VEC_ELT (to_remove_edges, i, e)
+    e->flags &= ~EDGE_IGNORE;
+
   /* We do not actually update the CFG or SSA graphs at this point as
      ASSERT_EXPRs are still in the IL and cfg cleanup code does not yet
      handle ASSERT_EXPRs gracefully.  */
@@ -10262,7 +10195,7 @@ finalize_jump_threads (void)
 /* Traverse all the blocks folding conditionals with known ranges.  */
 
 static void
-vrp_finalize (void)
+vrp_finalize (bool warn_array_bounds_p)
 {
   size_t i;
 
@@ -10275,16 +10208,6 @@ vrp_finalize (void)
       fprintf (dump_file, "\n");
     }
 
-  substitute_and_fold (op_with_constant_singleton_value_range,
-                      vrp_fold_stmt, false);
-
-  if (warn_array_bounds && first_pass_instance)
-    check_all_array_refs ();
-
-  /* We must identify jump threading opportunities before we release
-     the datastructures built by VRP.  */
-  identify_jump_threads ();
-
   /* Set value range to non pointer SSA_NAMEs.  */
   for (i  = 0; i < num_vr_values; i++)
     if (vr_value[i])
@@ -10305,6 +10228,16 @@ vrp_finalize (void)
                        vr_value[i]->max);
       }
 
+  substitute_and_fold (op_with_constant_singleton_value_range,
+                      vrp_fold_stmt, false);
+
+  if (warn_array_bounds && warn_array_bounds_p)
+    check_all_array_refs ();
+
+  /* We must identify jump threading opportunities before we release
+     the datastructures built by VRP.  */
+  identify_jump_threads ();
+
   /* Free allocated memory.  */
   for (i = 0; i < num_vr_values; i++)
     if (vr_value[i])
@@ -10368,7 +10301,7 @@ vrp_finalize (void)
    probabilities to aid branch prediction.  */
 
 static unsigned int
-execute_vrp (void)
+execute_vrp (bool warn_array_bounds_p)
 {
   int i;
   edge e;
@@ -10392,9 +10325,9 @@ execute_vrp (void)
 
   vrp_initialize ();
   ssa_propagate (vrp_visit_stmt, vrp_visit_phi_node);
-  vrp_finalize ();
+  vrp_finalize (warn_array_bounds_p);
 
-  free_numbers_of_iterations_estimates ();
+  free_numbers_of_iterations_estimates (cfun);
 
   /* ASSERT_EXPRs must be removed before finalizing jump threads
      as finalizing jump threads calls the CFG cleanup code which
@@ -10465,14 +10398,22 @@ class pass_vrp : public gimple_opt_pass
 {
 public:
   pass_vrp (gcc::context *ctxt)
-    : gimple_opt_pass (pass_data_vrp, ctxt)
+    : gimple_opt_pass (pass_data_vrp, ctxt), warn_array_bounds_p (false)
   {}
 
   /* opt_pass methods: */
   opt_pass * clone () { return new pass_vrp (m_ctxt); }
+  void set_pass_param (unsigned int n, bool param)
+    {
+      gcc_assert (n == 0);
+      warn_array_bounds_p = param;
+    }
   virtual bool gate (function *) { return flag_tree_vrp != 0; }
-  virtual unsigned int execute (function *) { return execute_vrp (); }
+  virtual unsigned int execute (function *)
+    { return execute_vrp (warn_array_bounds_p); }
 
+ private:
+  bool warn_array_bounds_p;
 }; // class pass_vrp
 
 } // anon namespace