GCC Middle and Back End API Reference
tree-vrp.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "ggc.h"
#include "flags.h"
#include "tree.h"
#include "basic-block.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-cfg.h"
#include "tree-phinodes.h"
#include "ssa-iterators.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 "expr.h"
#include "optabs.h"
#include "tree-ssa-threadedge.h"
Include dependency graph for tree-vrp.c:

Data Structures

struct  value_range_d
struct  assert_locus_d
struct  switch_update
struct  case_info

Macros

#define VR_INITIALIZER   { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }

Typedefs

typedef struct value_range_d value_range_t
typedef struct assert_locus_dassert_locus_t

Functions

static bool live_on_edge ()
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 tree vrp_evaluate_conditional_warnv_with_ops (enum tree_code, tree, tree, bool, bool *, bool *)
static tree vrp_val_max ()
static tree vrp_val_min ()
static bool vrp_val_is_max ()
static bool vrp_val_is_min ()
static bool needs_overflow_infinity ()
static bool supports_overflow_infinity ()
static tree make_overflow_infinity ()
static tree negative_overflow_infinity ()
static tree positive_overflow_infinity ()
static bool is_negative_overflow_infinity ()
static bool is_positive_overflow_infinity ()
static bool is_overflow_infinity ()
static bool stmt_overflow_infinity ()
static tree avoid_overflow_infinity ()
static bool nonnull_arg_p ()
static void set_value_range_to_undefined ()
static void set_value_range_to_varying ()
static void set_value_range (value_range_t *vr, enum value_range_type t, tree min, tree max, bitmap equiv)
static void set_and_canonicalize_value_range (value_range_t *vr, enum value_range_type t, tree min, tree max, bitmap equiv)
static void copy_value_range ()
static void set_value_range_to_value ()
static void set_value_range_to_nonnegative (value_range_t *vr, tree type, bool overflow_infinity)
static void set_value_range_to_nonnull ()
static void set_value_range_to_null ()
static void set_value_range_to_truthvalue ()
static void abs_extent_range ()
static value_range_tget_value_range ()
static bool vrp_operand_equal_p ()
static bool vrp_bitmap_equal_p ()
static bool update_value_range ()
static void add_equivalence ()
static bool range_is_nonnull ()
static bool range_is_null ()
static bool range_int_cst_p ()
static bool range_int_cst_singleton_p ()
static bool symbolic_range_p ()
static bool overflow_infinity_range_p ()
static bool usable_range_p ()
static bool gimple_assign_nonnegative_warnv_p ()
static bool gimple_call_nonnegative_warnv_p ()
static bool gimple_stmt_nonnegative_warnv_p ()
static bool gimple_assign_nonzero_warnv_p ()
static bool gimple_stmt_nonzero_warnv_p ()
static bool vrp_stmt_computes_nonzero ()
static bool valid_value_p ()
static int operand_less_p ()
static int compare_values_warnv ()
static int compare_values ()
static int value_inside_range ()
static bool value_ranges_intersect_p ()
static int range_includes_zero_p ()
static bool value_range_nonnegative_p ()
bool ssa_name_nonnegative_p ()
static tree value_range_constant_singleton ()
static tree op_with_constant_singleton_value_range ()
static bool op_with_boolean_value_range_p ()
static void extract_range_from_assert ()
static void extract_range_from_ssa_name ()
static tree vrp_int_const_binop ()
static bool zero_nonzero_bits_from_vr (value_range_t *vr, double_int *may_be_nonzero, double_int *must_be_nonzero)
static bool ranges_from_anti_range (value_range_t *ar, value_range_t *vr0, value_range_t *vr1)
static void extract_range_from_multiplicative_op_1 (value_range_t *vr, enum tree_code code, value_range_t *vr0, value_range_t *vr1)
static int quad_int_cmp (double_int l0, double_int h0, double_int l1, double_int h1, bool uns)
static void quad_int_pair_sort (double_int *l0, double_int *h0, double_int *l1, double_int *h1, bool uns)
static void extract_range_from_binary_expr_1 (value_range_t *vr, enum tree_code code, tree expr_type, value_range_t *vr0_, value_range_t *vr1_)
static void extract_range_from_binary_expr (value_range_t *vr, enum tree_code code, tree expr_type, tree op0, tree op1)
static void extract_range_from_unary_expr_1 (value_range_t *vr, enum tree_code code, tree type, value_range_t *vr0_, tree op0_type)
static void extract_range_from_unary_expr (value_range_t *vr, enum tree_code code, tree type, tree op0)
static void extract_range_from_cond_expr ()
static void extract_range_from_comparison (value_range_t *vr, enum tree_code code, tree type, tree op0, tree op1)
static void extract_range_basic ()
static void extract_range_from_assignment ()
static void adjust_range_with_scev (value_range_t *vr, struct loop *loop, gimple stmt, tree var)
static bool vrp_var_may_overflow ()
static tree compare_ranges (enum tree_code comp, value_range_t *vr0, value_range_t *vr1, bool *strict_overflow_p)
static tree compare_range_with_value (enum tree_code comp, value_range_t *vr, tree val, bool *strict_overflow_p)
void dump_value_range (FILE *, value_range_t *)
void debug_value_range (value_range_t *)
void dump_all_value_ranges (FILE *)
void debug_all_value_ranges (void)
void dump_vr_equiv (FILE *, bitmap)
void debug_vr_equiv (bitmap)
void dump_value_range ()
DEBUG_FUNCTION void debug_value_range ()
void dump_all_value_ranges ()
static gimple build_assert_expr_for ()
static bool fp_predicate ()
static bool infer_nonnull_range ()
static bool infer_value_range ()
void dump_asserts_for (FILE *, tree)
void debug_asserts_for (tree)
void dump_all_asserts (FILE *)
void debug_all_asserts (void)
void dump_asserts_for ()
DEBUG_FUNCTION void debug_asserts_for ()
void dump_all_asserts ()
static void register_new_assert_for (tree name, tree expr, enum tree_code comp_code, tree val, basic_block bb, edge e, gimple_stmt_iterator si)
static bool extract_code_and_val_from_cond_with_ops (tree name, enum tree_code cond_code, tree cond_op0, tree cond_op1, bool invert, enum tree_code *code_p, tree *val_p)
static double_int masked_increment (double_int val, double_int mask, double_int sgnbit, unsigned int prec)
static bool register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi, enum tree_code cond_code, tree cond_op0, tree cond_op1, bool invert)
static bool register_edge_assert_for_1 (tree op, enum tree_code code, edge e, gimple_stmt_iterator bsi)
static bool register_edge_assert_for (tree name, edge e, gimple_stmt_iterator si, enum tree_code cond_code, tree cond_op0, tree cond_op1)
static bool find_conditional_asserts ()
static int compare_case_labels ()
static bool find_switch_asserts ()
static bool find_assert_locations_1 ()
static bool find_assert_locations ()
static bool process_assert_insertions_for ()
static void process_assert_insertions ()
static void insert_range_assertions ()
static void check_array_ref ()
static void search_for_addr_array ()
static tree check_array_bounds ()
static void check_all_array_refs ()
static void remove_range_assertions ()
static bool stmt_interesting_for_vrp ()
static void vrp_initialize ()
static tree vrp_valueize ()
static enum ssa_prop_result vrp_visit_assignment_or_call ()
static value_range_t get_vr_for_comparison ()
static tree compare_name_with_value (enum tree_code comp, tree var, tree val, bool *strict_overflow_p)
static tree compare_names (enum tree_code comp, tree n1, tree n2, bool *strict_overflow_p)
static tree vrp_evaluate_conditional_warnv_with_ops_using_ranges (enum tree_code code, tree op0, tree op1, bool *strict_overflow_p)
static tree vrp_evaluate_conditional ()
static enum ssa_prop_result vrp_visit_cond_stmt ()
static bool find_case_label_index ()
static bool find_case_label_range (gimple stmt, tree min, tree max, size_t *min_idx, size_t *max_idx)
static bool find_case_label_ranges (gimple stmt, value_range_t *vr, size_t *min_idx1, size_t *max_idx1, size_t *min_idx2, size_t *max_idx2)
static enum ssa_prop_result vrp_visit_switch_stmt ()
static enum ssa_prop_result vrp_visit_stmt ()
static void union_ranges (enum value_range_type *vr0type, tree *vr0min, tree *vr0max, enum value_range_type vr1type, tree vr1min, tree vr1max)
static void intersect_ranges (enum value_range_type *vr0type, tree *vr0min, tree *vr0max, enum value_range_type vr1type, tree vr1min, tree vr1max)
static void vrp_intersect_ranges_1 ()
static void vrp_intersect_ranges ()
static void vrp_meet_1 ()
static void vrp_meet ()
static enum ssa_prop_result vrp_visit_phi_node ()
static bool simplify_truth_ops_using_ranges ()
static bool simplify_div_or_mod_using_ranges ()
static bool simplify_abs_using_ranges ()
static bool simplify_bit_ops_using_ranges ()
static tree test_for_singularity (enum tree_code cond_code, tree op0, tree op1, value_range_t *vr)
static bool range_fits_type_p ()
static bool simplify_cond_using_ranges ()
static bool simplify_switch_using_ranges ()
static bool simplify_conversion_using_ranges ()
static bool simplify_float_conversion_using_ranges ()
static bool simplify_stmt_using_ranges ()
static bool fold_predicate_in ()
static bool vrp_fold_stmt ()
static tree simplify_stmt_for_jump_threading ()
static void identify_jump_threads ()
static void finalize_jump_threads ()
static void vrp_finalize ()
static unsigned int execute_vrp ()
static bool gate_vrp ()
gimple_opt_passmake_pass_vrp ()

Variables

static sbitmaplive
static bitmap need_assert_for
static assert_locus_tasserts_for
static unsigned num_vr_values
static value_range_t ** vr_value
static bool values_propagated
static int * vr_phi_edge_counts
static vec< edgeto_remove_edges
static vec< switch_updateto_update_switch_stmts
static vec< treeequiv_stack

Macro Definition Documentation

#define VR_INITIALIZER   { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }

Typedef Documentation

typedef struct assert_locus_d* assert_locus_t
typedef struct value_range_d value_range_t

Function Documentation

static void abs_extent_range ( )
static

If abs (min) < abs (max), set VR to [-max, max], if abs (min) >= abs (max), set VR to [-min, min].

static void add_equivalence ( )
static

Add VAR and VAR's equivalence set to EQUIV. This is the central point where equivalence processing can be turned on/off.

References gcc_assert, is_overflow_infinity(), value_range_d::max, value_range_d::min, TREE_TYPE, value_range_d::type, TYPE_OVERFLOW_UNDEFINED, and VR_RANGE.

static void adjust_range_with_scev ( value_range_t vr,
struct loop loop,
gimple  stmt,
tree  var 
)
static

Given a range VR, a LOOP and a variable VAR, determine whether it would be profitable to adjust VR using scalar evolution information for VAR. If so, update VR with the new limits.

 TODO.  Don't adjust anti-ranges.  An anti-range may provide
 better opportunities than a regular range, but I'm not sure.   
 Like in PR19590, scev can return a constant function.   
 If STEP is symbolic, we can't know whether INIT will be the
 minimum or maximum value in the range.  Also, unless INIT is
 a simple expression, compare_values and possibly other functions
 in tree-vrp won't be able to handle it.   
     ... or if it may wrap.   
 We use TYPE_MIN_VALUE and TYPE_MAX_VALUE here instead of
 negative_overflow_infinity and positive_overflow_infinity,
 because we have concluded that the loop probably does not
 wrap.   
 Try to use estimated number of iterations for the loop to constrain the
 final value in the evolution.   
     We are only entering here for loop header PHI nodes, so using
     the number of latch executions is the correct thing to use.   
         If the multiplication overflowed we can't do a meaningful
         adjustment.  Likewise if the result doesn't fit in the type
         of the induction variable.  For a signed type we have to
         check whether the result has the expected signedness which
         is that of the step as number of iterations is unsigned.   
             Likewise if the addition did.   
     For VARYING or UNDEFINED ranges, just about anything we get
     from scalar evolutions should be better.   
     If we would create an invalid range, then just assume we
     know absolutely nothing.  This may be over-conservative,
     but it's clearly safe, and should happen only in unreachable
     parts of code, or for invalid programs.   
         INIT is the maximum value.  If INIT is lower than VR->MAX
         but no smaller than VR->MIN, set VR->MAX to INIT.   
         According to the loop information, the variable does not
         overflow.  If we think it does, probably because of an
         overflow due to arithmetic on a different INF value,
         reset now.   
         If INIT is bigger than VR->MIN, set VR->MIN to INIT.   
     If we just created an invalid range with the minimum
     greater than the maximum, we fail conservatively.
     This should happen only in unreachable
     parts of code, or for invalid programs.   
static tree avoid_overflow_infinity ( )
inlinestatic

If VAL is now an overflow infinity, return VAL. Otherwise, return the same value with TREE_OVERFLOW clear. This can be used to avoid confusing a regular value with an overflow value.

static gimple build_assert_expr_for ( )
static

Given a COND_EXPR COND of the form 'V OP W', and an SSA name V, create a new SSA name N and return the assertion assignment 'V = ASSERT_EXPR <V, V OP W>'.

The new ASSERT_EXPR, creates a new SSA name that replaces the operand of the ASSERT_EXPR. Create it so the new name and the old one are registered in the replacement table so that we can fix the SSA web after adding all the ASSERT_EXPRs.

static void check_all_array_refs ( )
static

Walk over all statements of all reachable BBs and call check_array_bounds on them.

Skip blocks that were found to be unreachable.

References bitmap_clear_bit(), NULL_TREE, and SSA_NAME_VERSION.

static tree check_array_bounds ( )
static

walk_tree() callback that checks if *TP is an ARRAY_REF inside an ADDR_EXPR (in which an array subscript one outside the valid range is allowed). Call check_array_ref for each ARRAY_REF found. The location is passed in DATA.

References bitmap_clear_bit(), boolean_false_node, boolean_true_node, and SSA_NAME_VERSION.

static void check_array_ref ( )
static

Checks one ARRAY_REF in REF, located at LOCUS. Ignores flexible arrays and "struct" hacks. If VRP can determine that the array subscript is a constant, check if it is outside valid range. If the array subscript is a RANGE, warn if it is non-overlapping with valid range. IGNORE_OFF_BY_ONE is true if the ARRAY_REF is inside a ADDR_EXPR.

 Can not check flexible arrays.   
 Accesses to trailing arrays via pointers may access storage
 beyond the types array bounds.   
     If this is the last field in a struct type or a field in a
     union type do not warn.   

References dump_file, dump_flags, dump_value_range(), extract_range_basic(), extract_range_from_assignment(), FOR_EACH_SSA_TREE_OPERAND, get_value_range(), gimple_fold_stmt_to_constant(), gimple_get_lhs(), INTEGRAL_TYPE_P, is_overflow_infinity(), NULL, POINTER_TYPE_P, print_generic_expr(), set_value_range(), set_value_range_to_varying(), SSA_OP_DEF, SSA_PROP_INTERESTING, SSA_PROP_NOT_INTERESTING, SSA_PROP_VARYING, TDF_DETAILS, TREE_CODE, TREE_TYPE, value_range_d::type, TYPE_MAX_VALUE, TYPE_MIN_VALUE, update_value_range(), VR_INITIALIZER, VR_RANGE, VR_VARYING, and vrp_valueize().

static int compare_case_labels ( )
static

Compare two case labels sorting first by the destination bb index and then by the case value.

Make sure the default label is first in a group.

static tree compare_name_with_value ( enum tree_code  comp,
tree  var,
tree  val,
bool strict_overflow_p 
)
static

Compare all the value ranges for names equivalent to VAR with VAL using comparison code COMP. Return the same value returned by compare_range_with_value, including the setting of *STRICT_OVERFLOW_P.

 Get the set of equivalences for VAR.   
 Start at -1.  Set it to 0 if we do a comparison without relying
 on overflow, or 1 if all comparisons rely on overflow.   
 Compare vars' value range with val.   
 If the equiv set is empty we have done all work we need to do.   
         If we get different answers from different members
         of the equivalence set this check must be in a dead
         code region.  Folding it to a trap representation
         would be correct here.  For now just return don't-know.   
static tree compare_names ( enum tree_code  comp,
tree  n1,
tree  n2,
bool strict_overflow_p 
)
static

Given a comparison code COMP and names N1 and N2, compare all the ranges equivalent to N1 against all the ranges equivalent to N2 to determine the value of N1 COMP N2. Return the same value returned by compare_ranges. Set *STRICT_OVERFLOW_P to indicate whether we relied on an overflow infinity in the comparison.

 Compare the ranges of every name equivalent to N1 against the
 ranges of every name equivalent to N2.   
 Use the fake bitmaps if e1 or e2 are not available.   
 Add N1 and N2 to their own set of equivalences to avoid
 duplicating the body of the loop just to check N1 and N2
 ranges.   
 If the equivalence sets have a common intersection, then the two
 names can be compared without checking their ranges.   
 Start at -1.  Set it to 0 if we do a comparison without relying
 on overflow, or 1 if all comparisons rely on overflow.   
 Otherwise, compare all the equivalent ranges.  First, add N1 and
 N2 to their own set of equivalences to avoid duplicating the body
 of the loop just to check N1 and N2 ranges.   
             If we get different answers from different members
             of the equivalence set this check must be in a dead
             code region.  Folding it to a trap representation
             would be correct here.  For now just return don't-know.   
 None of the equivalent ranges are useful in computing this
 comparison.   

References CASE_HIGH, CASE_LOW, find_case_label_range(), gcc_checking_assert, gimple_switch_label(), gimple_switch_num_labels(), value_range_d::max, value_range_d::min, NULL_TREE, tree_int_cst_compare(), value_range_d::type, VR_ANTI_RANGE, and VR_RANGE.

static tree compare_range_with_value ( enum tree_code  comp,
value_range_t vr,
tree  val,
bool strict_overflow_p 
)
static

Given a value range VR, a value VAL and a comparison code COMP, return BOOLEAN_TRUE_NODE if VR COMP VAL always returns true for all the values in VR. Return BOOLEAN_FALSE_NODE if the comparison always returns false. Return NULL_TREE if it is not always possible to determine the value of the comparison. Also set *STRICT_OVERFLOW_P to indicate whether a range with an overflow infinity was used in the test.

 Anti-ranges need to be handled separately.   
     For anti-ranges, the only predicates that we can compute at
     compile time are equality and inequality.   
     ~[VAL_1, VAL_2] OP VAL is known if VAL_1 <= VAL <= VAL_2.   
     EQ_EXPR may only be computed if VR represents exactly
     one value.   
     If VAL is not inside VR, then they are always different.   
     If VR represents exactly one value equal to VAL, then return
     false.   
     Otherwise, they may or may not be different.   
     If VR is to the left of VAL, return true.   
     If VR is to the right of VAL, return false.   
     Otherwise, we don't know.   
     If VR is to the right of VAL, return true.   
     If VR is to the left of VAL, return false.   
     Otherwise, we don't know.   

References build_int_cst(), EDGE_COUNT, infer_nonnull_range(), NULL_TREE, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, stmt_could_throw_p(), stmt_ends_bb_p(), and TREE_TYPE.

static tree compare_ranges ( enum tree_code  comp,
value_range_t vr0,
value_range_t vr1,
bool strict_overflow_p 
)
static

Given two numeric value ranges VR0, VR1 and a comparison code COMP:

  • Return BOOLEAN_TRUE_NODE if VR0 COMP VR1 always returns true for all the values in the ranges.
  • Return BOOLEAN_FALSE_NODE if the comparison always returns false.
  • Return NULL_TREE if it is not always possible to determine the value of the comparison.

Also set *STRICT_OVERFLOW_P to indicate whether a range with an overflow infinity was used in the test.

 VARYING or UNDEFINED ranges cannot be compared.   
 Anti-ranges need to be handled separately.   
     If both are anti-ranges, then we cannot compute any
     comparison.   
     These comparisons are never statically computable.   
     Equality can be computed only between a range and an
     anti-range.  ~[VAL1, VAL2] == [VAL1, VAL2] is always false.   
         To simplify processing, make VR0 the anti-range.   
 Simplify processing.  If COMP is GT_EXPR or GE_EXPR, switch the
 operands around and change the comparison code.   
     Equality may only be computed if both ranges represent
     exactly one value.   
     If [V0_MIN, V1_MAX] < [V1_MIN, V1_MAX] then V0 != V1.   
     If VR0 is completely to the left or completely to the right
     of VR1, they are always different.  Notice that we need to
     make sure that both comparisons yield similar results to
     avoid comparing values that cannot be compared at
     compile-time.   
     If VR0 and VR1 represent a single value and are identical,
     return false.   
     Otherwise, they may or may not be different.   
     If VR0 is to the left of VR1, return true.   
     If VR0 is to the right of VR1, return false.   
     Otherwise, we don't know.   
static int compare_values ( tree  val1,
tree  val2 
)
static

Local functions.

Referenced by vrp_meet_1().

static int compare_values ( )
static

Compare values like compare_values_warnv, but treat comparisons of nonconstants which rely on undefined overflow as incomparable.

static int compare_values_warnv ( tree  val1,
tree  val2,
bool  
)
static
static int compare_values_warnv ( )
static

Compare two values VAL1 and VAL2. Return

 -2 if VAL1 and VAL2 cannot be compared at compile-time,
 -1 if VAL1 < VAL2,
  0 if VAL1 == VAL2,
 +1 if VAL1 > VAL2, and
 +2 if VAL1 != VAL2

This is similar to tree_int_cst_compare but supports pointer values and values that cannot be compared at compile time.

If STRICT_OVERFLOW_P is not NULL, then set *STRICT_OVERFLOW_P to true if the return value is only valid if we assume that signed overflow is undefined.

 Below we rely on the fact that VAL1 and VAL2 are both pointers or
 both integers.   
 Convert the two values into the same type.  This is needed because
 sizetype causes sign extension even for unsigned types.   
     If VAL1 and VAL2 are of the form 'NAME [+-] CST' or 'NAME',
     return -1 or +1 accordingly.  If VAL1 and VAL2 don't use the
     same name, return -2.   
     Both values must use the same name.   
       NAME == NAME   
     If overflow is defined we cannot simplify more.   
           NAME < NAME + CST   
           NAME > NAME - CST   
           NAME + CST > NAME   
           NAME + CST1 > NAME + CST2, if CST1 > CST2   
           NAME + CST1 > NAME - CST2   
           NAME - CST < NAME   
           NAME - CST1 < NAME + CST2   
           NAME - CST1 > NAME - CST2, if CST1 < CST2.  Notice that
           C1 and C2 are swapped in the call to compare_values.   
 We cannot compare non-constants.   
     We cannot compare overflowed values, except for overflow
     infinities.   
     First see if VAL1 and VAL2 are not the same.   
     If VAL1 is a lower address than VAL2, return -1.   
     If VAL1 is a higher address than VAL2, return +1.   
     If VAL1 is different than VAL2, return +2.
     For integer constants we either have already returned -1 or 1
     or they are equivalent.  We still might succeed in proving
     something about non-trivial operands.   
static void copy_value_range ( )
inlinestatic

Copy value range FROM into value range TO.

References build_int_cst(), value_range_d::equiv, and set_value_range_to_value().

DEBUG_FUNCTION void debug_all_asserts ( )

Dump all the registered assertions for all the names to stderr.

DEBUG_FUNCTION void debug_all_value_ranges ( )

Dump all value ranges to stderr.

void debug_asserts_for ( tree  )
DEBUG_FUNCTION void debug_asserts_for ( )

Dump all the registered assertions for NAME to stderr.

void debug_value_range ( value_range_t )
DEBUG_FUNCTION void debug_value_range ( )

Dump value range VR to stderr.

void debug_vr_equiv ( bitmap  )
void dump_all_asserts ( FILE *  )

Referenced by find_switch_asserts().

void dump_all_asserts ( )

Dump all the registered assertions for all the names to FILE.

References FOR_EACH_IMM_USE_STMT, is_gimple_assign(), edge_def::src, and ui.

void dump_all_value_ranges ( FILE *  )
void dump_all_value_ranges ( )

Dump value ranges of all SSA_NAMEs to FILE.

void dump_asserts_for ( FILE *  ,
tree   
)
void dump_asserts_for ( )

Dump all the registered assertions for NAME to FILE.

References dump_file, and print_generic_expr().

void dump_value_range ( FILE *  ,
value_range_t  
)

Debugging dumps.

Referenced by check_array_ref().

void dump_vr_equiv ( FILE *  ,
bitmap   
)
static unsigned int execute_vrp ( )
static

Main entry point to VRP (Value Range Propagation). This pass is loosely based on J. R. C. Patterson, ``Accurate Static Branch Prediction by Value Range Propagation,'' in SIGPLAN Conference on Programming Language Design and Implementation, pp. 67-78, 1995. Also available at http://citeseer.ist.psu.edu/patterson95accurate.html

This is essentially an SSA-CCP pass modified to deal with ranges instead of constants.

While propagating ranges, we may find that two or more SSA name have equivalent, though distinct ranges. For instance,

1 x_9 = p_3->a; 2 p_4 = ASSERT_EXPR <p_3, p_3 != 0> 3 if (p_4 == q_2) 4 p_5 = ASSERT_EXPR <p_4, p_4 == q_2>; 5 endif 6 if (q_2)

In the code above, pointer p_5 has range [q_2, q_2], but from the code we can also determine that p_5 cannot be NULL and, if q_2 had a non-varying range, p_5's range should also be compatible with it.

These equivalences are created by two expressions: ASSERT_EXPR and copy operations. Since p_5 is an assertion on p_4, and p_4 was the result of another assertion, then we can use the fact that p_5 and p_4 are equivalent when evaluating p_5's range.

Together with value ranges, we also propagate these equivalences between names so that we can take advantage of information from multiple ranges when doing final replacement. Note that this equivalency relation is transitive but not symmetric.

In the example above, p_5 is equivalent to p_4, q_2 and p_3, but we cannot assert that q_2 is equivalent to p_5 because q_2 may be used in contexts where that assertion does not hold (e.g., in line 6).

TODO, the main difference between this pass and Patterson's is that we do not propagate edge probabilities. We only compute whether edges can be taken or not. That is, instead of having a spectrum of jump probabilities between 0 and 1, we only deal with 0, 1 and DON'T KNOW. In the future, it may be worthwhile to propagate probabilities to aid branch prediction.

 ???  This ends up using stale EDGE_DFS_BACK for liveness computation.
 Inserting assertions may split edges which will invalidate
 EDGE_DFS_BACK.   
 For visiting PHI nodes we need EDGE_DFS_BACK computed.   
 ASSERT_EXPRs must be removed before finalizing jump threads
 as finalizing jump threads calls the CFG cleanup code which
 does not properly handle ASSERT_EXPRs.   
 If we exposed any new variables, go ahead and put them into
 SSA form now, before we handle jump threading.  This simplifies
 interactions between rewriting of _DECL nodes into SSA form
 and rewriting SSA_NAME nodes into SSA form after block
 duplication and CFG manipulation.   
 Remove dead edges from SWITCH_EXPR optimization.  This leaves the
 CFG in a broken state and requires a cfg_cleanup run.   
 Update SWITCH_EXPR case label vector.   
     As we may have replaced the default label with a regular one
     make sure to make it a real default label again.  This ensures
     optimal expansion.   
static bool extract_code_and_val_from_cond_with_ops ( tree  name,
enum tree_code  cond_code,
tree  cond_op0,
tree  cond_op1,
bool  invert,
enum tree_code code_p,
tree val_p 
)
static

(COND_OP0 COND_CODE COND_OP1) is a predicate which uses NAME. Extract a suitable test code and value and store them into *CODE_P and *VAL_P so the predicate is normalized to NAME *CODE_P *VAL_P.

If no extraction was possible, return FALSE, otherwise return TRUE.

If INVERT is true, then we invert the result stored into *CODE_P.

 Otherwise, we have a comparison of the form NAME COMP VAL
 or VAL COMP NAME.   
     If the predicate is of the form VAL COMP NAME, flip
     COMP around because we need to register NAME as the
     first operand in the predicate.   
     The comparison is of the form NAME COMP VAL, so the
     comparison code remains unchanged.   
 Invert the comparison code as necessary.   
 VRP does not handle float types.   
 Do not register always-false predicates.
 FIXME:  this works around a limitation in fold() when dealing with
 enumerations.  Given 'enum { N1, N2 } x;', fold will not
 fold 'if (x > N2)' to 'if (0)'.   
static void extract_range_basic ( )
static

Try to derive a nonnegative or nonzero range out of STMT relying primarily on generic routines in fold in conjunction with range data. Store the result in *VR

         If the call is __builtin_constant_p and the argument is a
         function parameter resolve it to false.  This avoids bogus
         array bound warnings.
         ???  We could do this as early as inlining is finished.   
         Both __builtin_ffs* and __builtin_popcount return
         [0, prec].   
             If arg is non-zero, then ffs or popcount
             are non-zero.   
             If some high bits are known to be zero,
             we can decrease the maximum.   
         __builtin_parity* returns [0, 1].   
         __builtin_c[lt]z* return [0, prec-1], except for
         when the argument is 0, but that is undefined behavior.
         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.   
             Handle only the single common value.   
           Magic value to give up, unless vr0 proves
           arg is non-zero.   
             From clz of VR_RANGE minimum we can compute
             result maximum.   
             From clz of VR_RANGE maximum we can compute
             result minimum.   
         __builtin_ctz* return [0, prec-1], except for
         when the argument is 0, but that is undefined behavior.
         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.   
             Handle only the two common values.   
               Magic value to give up, unless vr0 proves
               arg is non-zero.   
             If arg is non-zero, then use [0, prec - 1].   
             If some high bits are known to be zero,
             we can decrease the result maximum.   
                 For vr0 [0, 0] give up.   
         __builtin_clrsb* returns [0, prec-1].   

Referenced by check_array_ref(), and extract_range_from_cond_expr().

static void extract_range_from_assert ( )
static

Extract value range information from an ASSERT_EXPR EXPR and store it in *VR_P.

 Find VAR in the ASSERT_EXPR conditional.   
     If the predicate is of the form VAR COMP LIMIT, then we just
     take LIMIT from the RHS and use the same comparison code.   
     If the predicate is of the form LIMIT COMP VAR, then we need
     to flip around the comparison code to create the proper range
     for VAR.   
 For pointer arithmetic, we only keep track of pointer equality
 and inequality.   
 If LIMIT is another SSA name and LIMIT has a range of its own,
 try to use LIMIT's range to avoid creating symbolic ranges
 unnecessarily.  
 LIMIT's range is only interesting if it has any useful information.   
 Initially, the new range has the same set of equivalences of
 VAR's range.  This will be revised before returning the final
 value.  Since assertions may be chained via mutually exclusive
 predicates, we will need to trim the set of equivalences before
 we are done.   
 Extract a new range based on the asserted comparison for VAR and
 LIMIT's value range.  Notice that if LIMIT has an anti-range, we
 will only use it for equality comparisons (EQ_EXPR).  For any
 other kind of assertion, we cannot derive a range from LIMIT's
 anti-range that can be used to describe the new range.  For
 instance, ASSERT_EXPR <x_2, x_2 <= b_4>.  If b_4 is ~[2, 10],
 then b_4 takes on the ranges [-INF, 1] and [11, +INF].  There is
 no single range for x_2 that could describe LE_EXPR, so we might
 as well build the range [b_4, +INF] for it.
 One special case we handle is extracting a range from a
 range test encoded as (unsigned)var + CST <= limit.   
     Make sure to not set TREE_OVERFLOW on the final type
     conversion.  We are willingly interpreting large positive
     unsigned values as negative singed values here.   
     We can transform a max, min range to an anti-range or
     vice-versa.  Use set_and_canonicalize_value_range which does
     this for us.   
     When asserting the equality VAR == LIMIT and LIMIT is another
     SSA name, the new range will also inherit the equivalence set
     from LIMIT.   
     As described above, when LIMIT's range is an anti-range and
     this assertion is an inequality (NE_EXPR), then we cannot
     derive anything from the anti-range.  For instance, if
     LIMIT's range was ~[0, 0], the assertion 'VAR != LIMIT' does
     not imply that VAR's range is [0, 0].  So, in the case of
     anti-ranges, we just assert the inequality using LIMIT and
     not its anti-range.

     If LIMIT_VR is a range, we can only use it to build a new
     anti-range if LIMIT_VR is a single-valued range.  For
     instance, if LIMIT_VR is [0, 1], the predicate
     VAR != [0, 1] does not mean that VAR's range is ~[0, 1].
     Rather, it means that for value 0 VAR should be ~[0, 0]
     and for value 1, VAR should be ~[1, 1].  We cannot
     represent these ranges.

     The only situation in which we can build a valid
     anti-range is when LIMIT_VR is a single-valued range
     (i.e., LIMIT_VR->MIN == LIMIT_VR->MAX).  In that case,
     build the anti-range ~[LIMIT_VR->MIN, LIMIT_VR->MAX].   
         In any other case, we cannot use LIMIT's range to build a
         valid anti-range.   
     If MIN and MAX cover the whole range for their type, then
     just use the original LIMIT.   
         If LIMIT_VR is of the form [N1, N2], we need to build the
         range [MIN, N2] for LE_EXPR and [MIN, N2 - 1] for
         LT_EXPR.   
     If the maximum value forces us to be out of bounds, simply punt.
     It would be pointless to try and do anything more since this
     all should be optimized away above us.   
         For LT_EXPR, we create the range [MIN, MAX - 1].   
         If LIMIT_VR is of the form [N1, N2], we need to build the
         range [N1, MAX] for GE_EXPR and [N1 + 1, MAX] for
         GT_EXPR.   
     If the minimum value forces us to be out of bounds, simply punt.
     It would be pointless to try and do anything more since this
     all should be optimized away above us.   
         For GT_EXPR, we create the range [MIN + 1, MAX].   
 Finally intersect the new range with what we already know about var.   

Referenced by extract_range_from_cond_expr().

static void extract_range_from_assignment ( )
static

Try to compute a useful range out of assignment STMT and store it in *VR.

Referenced by check_array_ref(), and range_fits_type_p().

static void extract_range_from_binary_expr ( value_range_t vr,
enum tree_code  code,
tree  expr_type,
tree  op0,
tree  op1 
)
static

Extract range information from a binary expression OP0 CODE OP1 based on the ranges of each of its operands with resulting type EXPR_TYPE. The resulting range is stored in *VR.

Get value ranges for each operand. For constant operands, create a new value range with the operand to simplify processing.

References set_value_range_to_varying().

Referenced by extract_range_from_cond_expr().

static void extract_range_from_binary_expr_1 ( value_range_t vr,
enum tree_code  code,
tree  expr_type,
value_range_t vr0_,
value_range_t vr1_ 
)
static

Extract range information from a binary operation CODE based on the ranges of each of its operands, *VR0 and *VR1 with resulting type EXPR_TYPE. The resulting range is stored in *VR.

 Not all binary expressions can be applied to ranges in a
 meaningful way.  Handle only arithmetic operations.   
 If both ranges are UNDEFINED, so is the result.   
 If one of the ranges is UNDEFINED drop it to VARYING for the following
 code.  At some point we may want to special-case operations that
 have UNDEFINED result for all or some value-ranges of the not UNDEFINED
 operand.   
 Now canonicalize anti-ranges to ranges when they are not symbolic
 and express ~[] op X as ([]' op X) U ([]'' op X).   
 Likewise for X op ~[].   
 The type of the resulting value range defaults to VR0.TYPE.   
 Refuse to operate on VARYING ranges, ranges of different kinds
 and symbolic ranges.  As an exception, we allow BIT_AND_EXPR
 because we may be able to derive a useful range even if one of
 the operands is VR_VARYING or symbolic range.  Similarly for
 divisions.  TODO, we may be able to derive anti-ranges in
 some cases.   
 Now evaluate the expression to determine the new range.   
         For MIN/MAX expressions with pointers, we only care about
         nullness, if both are non null, then the result is nonnull.
         If both are null, then the result is null. Otherwise they
         are varying.   
         For pointer types, we are really only interested in asserting
         whether the expression evaluates to non-NULL.   
         For pointer types, we are really only interested in asserting
         whether the expression evaluates to non-NULL.   
 For integer ranges, apply the operation to each end of the
 range and see what we end up with.   
     If we have a PLUS_EXPR with two VR_RANGE integer constant
     ranges compute the precise range for such case if possible.   
         We need as many bits as the possibly unsigned inputs.   
             Check for overflow in double_int.   
         For non-wrapping arithmetic look at possibly smaller
         value-ranges of the type.   
         Check for type overflow.   
             If overflow wraps, truncate the values and adjust the
             range kind and bounds appropriately.   
                 No overflow or both overflow or underflow.  The
                 range kind stays VR_RANGE.   
                 Underflow and overflow, drop to VR_VARYING.   
                 Min underflow or max overflow.  The range kind
                 changes to VR_ANTI_RANGE.   
                 If the anti-range would cover nothing, drop to varying.
                 Likewise if the anti-range bounds are outside of the
                 types values.   
             If overflow does not wrap, saturate to the types min/max
             value.   
         For other cases, for example if we have a PLUS_EXPR with two
         VR_ANTI_RANGEs, drop to VR_VARYING.  It would take more effort
         to compute a precise range for such a case.
         ???  General even mixed range kind operations can be expressed
         by for example transforming ~[3, 5] + [1, 2] to range-only
         operations and a union primitive:
           [-INF, 2] + [1, 2]  U  [5, +INF] + [1, 2]
               [-INF+1, 4]     U    [6, +INF(OVF)]
         though usually the union is not exactly representable with
         a single range or anti-range as the above is
             [-INF+1, +INF(OVF)] intersected with ~[5, 5]
         but one could use a scheme similar to equivalences for this.  
             For operations that make the resulting range directly
             proportional to the original ranges, apply the operation to
             the same end of each range.   
     Fancy code so that with unsigned, [-3,-1]*[-3,-1] does not
     drop to varying.   
         Canonicalize the intervals.   
         Sort the 4 products.   
         Max - min.   
             the range covers all values.   
         The following should handle the wrapping and selecting
         VR_ANTI_RANGE for us.   
     If we have an unsigned MULT_EXPR with two VR_ANTI_RANGEs,
     drop to VR_VARYING.  It would take more effort to compute a
     precise range for such a case.  For example, if we have
     op0 == 65536 and op1 == 65536 with their ranges both being
     ~[0,0] on a 32-bit machine, we would have op0 * op1 == 0, so
     we cannot claim that the product is in ~[0,0].  Note that we
     are guaranteed to have vr0.type == vr1.type at this
     point.   
     If we have a RSHIFT_EXPR with any shift values outside [0..prec-1],
     then drop to VR_VARYING.  Outside of this range we get undefined
     behavior from the shift operation.  We cannot even trust
     SHIFT_COUNT_TRUNCATED at this stage, because that applies to rtl
     shifts, and the operation at the tree level may be widened.   
         We can map lshifts by constants to MULT_EXPR handling.   
             We have to use a wrapping multiply though as signed overflow
             on lshifts is implementation defined in C89.   
             If bound_shift == HOST_BITS_PER_DOUBLE_INT, the llshift can
             overflow.  However, for that to happen, vr1.max needs to be
             zero, which means vr1 is a singleton range of zero, which
             means it should be handled by the previous LSHIFT_EXPR
             if-clause.   
                     [5, 6] << [1, 2] == [10, 24].   
                     We're shifting out only zeroes, the value increases
                     monotonically.   
                     [0xffffff00, 0xffffffff] << [1, 2]
                     == [0xfffffc00, 0xfffffffe].   
                     We're shifting out only ones, the value decreases
                     monotonically.   
                 [-1, 1] << [1, 2] == [-4, 4].   
                     For non-negative numbers, we're shifting out only
                     zeroes, the value increases monotonically.
                     For negative numbers, we're shifting out only ones, the
                     value decreases monotomically.   
         For division, if op1 has VR_RANGE but op0 does not, something
         can be deduced just from that range.  Say [min, max] / [4, max]
         gives [min / 4, max / 4] range.   
     For divisions, if flag_non_call_exceptions is true, we must
     not eliminate a division by zero.   
     For divisions, if op0 is VR_RANGE, we can deduce a range
     even if op1 is VR_VARYING, VR_ANTI_RANGE, symbolic or can
     include 0.   
             For unsigned division or when divisor is known
             to be non-negative, the range has to cover
             all numbers from 0 to max for positive max
             and all numbers from min to 0 for negative min.   
             Otherwise the range is -max .. max or min .. -min
             depending on which bound is bigger in absolute value,
             as the division can change the sign.   
     Compute MAX <|vr1.min|, |vr1.max|> - 1.   
     If the dividend is non-negative the modulus will be
     non-negative as well.   
         If both input ranges contain only negative values we can
         truncate the result range maximum to the minimum of the
         input range maxima.   
         If either input range contains only non-negative values
         we can truncate the result range maximum to the respective
         maximum of the input range.   
         If the input ranges contain only positive values we can
         truncate the minimum of the result range to the maximum
         of the input range minima.   
         If either input range contains only negative values
         we can truncate the minimum of the result range to the
         respective minimum range.   
         If the range has all positive or all negative values the
         result is better than VARYING.   
 If either MIN or MAX overflowed, then set the resulting range to
 VARYING.  But we do accept an overflow infinity
 representation.   
 We punt if:
 1) [-INF, +INF]
 2) [-INF, +-INF(OVF)]
 3) [+-INF(OVF), +INF]
 4) [+-INF(OVF), +-INF(OVF)]
 We learn nothing when we have INF and INF(OVF) on both sides.
 Note that we do accept [-INF, -INF] and [+INF, +INF] without
 overflow.   
     If the new range has its limits swapped around (MIN > MAX),
     then the operation caused one of them to wrap around, mark
     the new range VARYING.   
static void extract_range_from_comparison ( value_range_t vr,
enum tree_code  code,
tree  type,
tree  op0,
tree  op1 
)
static

Extract range information from a comparison expression EXPR based on the range of its operand and the expression code.

 A disadvantage of using a special infinity as an overflow
 representation is that we lose the ability to record overflow
 when we don't have an infinity.  So we have to ignore a result
 which relies on overflow.   
     Since this expression was found on the RHS of an assignment,
     its type may be different from _Bool.  Convert VAL to EXPR's
     type.   
   The result of a comparison is always true or false.   

References analyze_scalar_evolution(), value_range_d::equiv, evolution_part_in_loop_num(), initial_condition_in_loop_num(), instantiate_parameters(), is_gimple_min_invariant(), value_range_d::max, value_range_d::min, loop::num, op_with_constant_singleton_value_range(), set_value_range_to_value(), TREE_CODE, value_range_d::type, type(), and VR_ANTI_RANGE.

Referenced by extract_range_from_cond_expr().

static void extract_range_from_cond_expr ( )
static

Extract range information from a conditional expression STMT based on the ranges of each of its operands and the expression code.

Get value ranges for each operand. For constant operands, create a new value range with the operand to simplify processing.

 The resulting value range is the union of the operand ranges  

References extract_range_basic(), extract_range_from_assert(), extract_range_from_binary_expr(), extract_range_from_comparison(), extract_range_from_ssa_name(), extract_range_from_unary_expr(), get_gimple_rhs_class(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_expr_type(), GIMPLE_SINGLE_RHS, is_gimple_min_invariant(), NULL, set_value_range_to_value(), set_value_range_to_varying(), tcc_binary, tcc_comparison, tcc_unary, TREE_CODE_CLASS, value_range_d::type, and VR_VARYING.

static void extract_range_from_multiplicative_op_1 ( value_range_t vr,
enum tree_code  code,
value_range_t vr0,
value_range_t vr1 
)
static

Helper to extract a value-range *VR for a multiplicative operation *VR0 CODE *VR1.

 Multiplications, divisions and shifts are a bit tricky to handle,
 depending on the mix of signs we have in the two ranges, we
 need to operate on different values to get the minimum and
 maximum values for the new range.  One approach is to figure
 out all the variations of range combinations and do the
 operations.

 However, this involves several calls to compare_values and it
 is pretty convoluted.  It's simpler to do the 4 operations
 (MIN0 OP MIN1, MIN0 OP MAX1, MAX0 OP MIN1 and MAX0 OP MAX0 OP
 MAX1) and then figure the smallest and largest values to form
 the new range.   
 Compute the 4 cross operations.   
 Set MIN to the minimum of VAL[i] and MAX to the maximum
 of VAL[i].   
             If we found an overflowed value, set MIN and MAX
             to it so that we set the resulting range to
             VARYING.   
 If either MIN or MAX overflowed, then set the resulting range to
 VARYING.  But we do accept an overflow infinity
 representation.   
 We punt if:
 1) [-INF, +INF]
 2) [-INF, +-INF(OVF)]
 3) [+-INF(OVF), +INF]
 4) [+-INF(OVF), +-INF(OVF)]
 We learn nothing when we have INF and INF(OVF) on both sides.
 Note that we do accept [-INF, -INF] and [+INF, +INF] without
 overflow.   
     If the new range has its limits swapped around (MIN > MAX),
     then the operation caused one of them to wrap around, mark
     the new range VARYING.   
static void extract_range_from_ssa_name ( )
static

Extract range information from SSA name VAR and store it in VR. If VAR has an interesting range, use it. Otherwise, create the range [VAR, VAR] and return it. This is useful in situations where we may have conditionals testing values of VARYING names. For instance,

 x_3 = y_5;
 if (x_3 > y_5)
   ...

Even if y_5 is deemed VARYING, we can determine that x_3 > y_5 is always false.

Referenced by extract_range_from_cond_expr().

static void extract_range_from_unary_expr ( value_range_t vr,
enum tree_code  code,
tree  type,
tree  op0 
)
static

Extract range information from a unary expression CODE OP0 based on the range of its operand with resulting type TYPE. The resulting range is stored in *VR.

Get value ranges for the operand. For constant operands, create a new value range with the operand to simplify processing.

Referenced by extract_range_from_cond_expr().

static void extract_range_from_unary_expr_1 ( value_range_t vr,
enum tree_code  code,
tree  type,
value_range_t vr0_,
tree  op0_type 
)
static

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.

 VRP only operates on integral and pointer types.   
 If VR0 is UNDEFINED, so is the result.   
 Handle operations that we express in terms of others.   
     PAREN_EXPR is a simple copy.   
     -X is simply 0 - X, so re-use existing code that also handles
     anti-ranges fine.   
     ~X is simply -1 - X, so re-use existing code that also handles
     anti-ranges fine.   
 Now canonicalize anti-ranges to ranges when they are not symbolic
 and express op ~[]  as (op []') U (op []'').   
     If the expression evaluates to a pointer, we are only interested in
     determining if it evaluates to NULL [0, 0] or non-NULL (~[0, 0]).   
     If VR0 is varying and we increase the type precision, assume
     a full range for the following transformation.   
     If VR0 is a constant range or anti-range and the conversion is
     not truncating we can convert the min and max values and
     canonicalize the resulting range.  Otherwise we can do the
     conversion if the size of the range is less than what the
     precision of the target type can represent and the range is
     not an anti-range.   
     Pass through vr0 in the easy cases.   
     For the remaining varying or symbolic ranges we can't do anything
     useful.   
     -TYPE_MIN_VALUE = TYPE_MIN_VALUE with flag_wrapv so we can't get a
     useful range.   
     ABS_EXPR may flip the range around, if the original range
     included negative values.   
              We shouldn't generate [+INF, +INF] as set_value_range
              doesn't like this and ICEs.   
     If a VR_ANTI_RANGEs contains zero, then we have
     ~[-INF, min(MIN, MAX)].   
             Take the lower of the two values.   
             Create ~[-INF, min (abs(MIN), abs(MAX))]
             or ~[-INF + 1, min (abs(MIN), abs(MAX))] when
             flag_wrapv is set and the original anti-range doesn't include
             TYPE_MIN_VALUE, remember -TYPE_MIN_VALUE = TYPE_MIN_VALUE.   
             All else has failed, so create the range [0, INF], even for
             flag_wrapv since TYPE_MIN_VALUE is in the original
             anti-range.   
     If the range contains zero then we know that the minimum value in the
     range will be zero.   
         If the range was reversed, swap MIN and MAX.   
         If the new range has its limits swapped around (MIN > MAX),
         then the operation caused one of them to wrap around, mark
         the new range VARYING.   
 For unhandled operations fall back to varying.   
static void finalize_jump_threads ( )
static

We identified all the jump threading opportunities earlier, but could not transform the CFG at that time. This routine transforms the CFG and arranges for the dominator tree to be rebuilt if necessary.

Note the SSA graph update will occur during the normal TODO processing by the pass manager.

static bool find_assert_locations ( )
static

Do an RPO walk over the function computing SSA name liveness on-the-fly and deciding on assert expressions to insert. Returns true if there are assert expressions to be inserted.

     Process BB and update the live information with uses in
     this block.   
     Merge liveness into the predecessor blocks and free it.   
         Record the RPO number of the last visited block that needs
         live information from this block.   
     We can free all successors live bitmaps if all their
     predecessors have been visited already.   

References walk_stmt_info::info.

static bool find_assert_locations_1 ( )
static

Traverse all the statements in block BB looking for statements that may generate useful assertions for the SSA names in their operand. If a statement produces a useful assertion A for name N_i, then the list of assertions already generated for N_i is scanned to determine if A is actually needed.

If N_i already had the assertion A at a location dominating the current location, then nothing needs to be done. Otherwise, the new location for A is recorded instead.

1- For every statement S in BB, all the variables used by S are added to bitmap FOUND_IN_SUBGRAPH.

2- If statement S uses an operand N in a way that exposes a known value range for N, then if N was not already generated by an ASSERT_EXPR, create a new assert location for N. For instance, if N is a pointer and the statement dereferences it, we can assume that N is not NULL.

3- COND_EXPRs are a special case of #2. We can derive range information from the predicate but need to insert different ASSERT_EXPRs for each of the sub-graphs rooted at the conditional block. If the last statement of BB is a conditional expression of the form 'X op Y', then

a) Remove X and Y from the set FOUND_IN_SUBGRAPH.

b) If the conditional is the only entry point to the sub-graph corresponding to the THEN_CLAUSE, recurse into it. On return, if X and/or Y are marked in FOUND_IN_SUBGRAPH, then an ASSERT_EXPR is added for the corresponding variable.

c) Repeat step (b) on the ELSE_CLAUSE.

d) Mark X and Y in FOUND_IN_SUBGRAPH.

For instance,

  if (a == 9)
    b = a;
  else
    b = c + 1;
  In this case, an assertion on the THEN clause is useful to
  determine that 'a' is always 9 on that edge.  However, an assertion
  on the ELSE clause would be unnecessary.

4- If BB does not end in a conditional expression, then we recurse into BB's dominator children.

At the end of the recursive traversal, every SSA name will have a list of locations where ASSERT_EXPRs should be added. When a new location for name N is found, it is registered by calling register_new_assert_for. That function keeps track of all the registered assertions to prevent adding unnecessary assertions. For instance, if a pointer P_4 is dereferenced more than once in a dominator tree, only the location dominating all the dereference of P_4 will receive an ASSERT_EXPR.

If this function returns true, then it means that there are names for which we need to generate ASSERT_EXPRs. Those assertions are inserted by process_assert_insertions.

 If BB's last statement is a conditional statement involving integer
 operands, determine if we need to add ASSERT_EXPRs.   
 If BB's last statement is a switch statement involving integer
 operands, determine if we need to add ASSERT_EXPRs.   
 Traverse all the statements in BB marking used names and looking
 for statements that may infer assertions for their used operands.   
     See if we can derive an assertion for any of STMT's operands.   
         If op is not live beyond this stmt, do not bother to insert
         asserts for it.   
         If OP is used in such a way that we can infer a value
         range for it, and we don't find a previous assertion for
         it, create a new assertion location node for OP.   
             If we are able to infer a nonzero value range for OP,
             then walk backwards through the use-def chain to see if OP
             was set via a typecast.

             If so, then we can also infer a nonzero value range
             for the operand of the NOP_EXPR.   
                     Note we want to register the assert for the
                     operand of the NOP_EXPR after SI, not after the
                     conversion.   
     Update live.   
 Traverse all PHI nodes in BB, updating live.   

References TREE_NO_WARNING, and warning_at().

static bool find_case_label_index ( )
static

Searches the case label vector VEC for the index *IDX of the CASE_LABEL that includes the value VAL. The search is restricted to the range [START_IDX, n - 1] where n is the size of VEC.

If there is a CASE_LABEL for VAL, its index is placed in IDX and true is returned.

If there is no CASE_LABEL for VAL and there is one that is larger than VAL, it is placed in IDX and false is returned.

If VAL is larger than any CASE_LABEL, n is placed on IDX and false is returned.

 Find case label for minimum of the value range or the next one.
 At each iteration we are searching in [low, high - 1].  
     Note that i != high, so we never ask for n.  
     Cache the result of comparing CASE_LOW and val.   
         Ranges cannot be empty.  

References int_const_binop(), integer_one_node, and TREE_CODE.

static bool find_case_label_range ( gimple  stmt,
tree  min,
tree  max,
size_t *  min_idx,
size_t *  max_idx 
)
static

Searches the case label vector VEC for the range of CASE_LABELs that is used for values between MIN and MAX. The first index is placed in MIN_IDX. The last index is placed in MAX_IDX. If the range of CASE_LABELs is empty then MAX_IDX < MIN_IDX. Returns true if the default label is not needed.

Only the default case label reached. Return an empty range.

     If the case label range is continuous, we do not need
     the default case label.  Verify that.   

Referenced by compare_names().

static bool find_case_label_ranges ( gimple  stmt,
value_range_t vr,
size_t *  min_idx1,
size_t *  max_idx1,
size_t *  min_idx2,
size_t *  max_idx2 
)
static

Searches the case label vector VEC for the ranges of CASE_LABELs that are used in range VR. The indices are placed in MIN_IDX1, MAX_IDX, MIN_IDX2 and MAX_IDX2. If the ranges of CASE_LABELs are empty then MAX_IDX1 < MIN_IDX1. Returns true if the default label is not needed.

 Set second range to emtpy.   
 Set first range to all case labels.   
 Make sure all the values of case labels [i , j] are contained in
 range [MIN, MAX].   
 If the range spans case labels [i, j], the corresponding anti-range spans
 the labels [1, i - 1] and [j + 1, n -  1].   
static bool find_conditional_asserts ( )
static

Determine whether the outgoing edges of BB should receive an ASSERT_EXPR for each of the operands of BB's LAST statement. The last statement of BB must be a COND_EXPR.

If any of the sub-graphs rooted at BB have an interesting use of the predicate operands, an assert location node is added to the list of assertions for the corresponding operands.

Look for uses of the operands in each of the sub-graphs rooted at BB. We need to check each of the outgoing edges separately, so that we know what kind of ASSERT_EXPR to insert.

     Register the necessary assertions for each operand in the
     conditional predicate.   

Referenced by register_edge_assert_for_1().

static bool find_switch_asserts ( )
static

Determine whether the outgoing edges of BB should receive an ASSERT_EXPR for each of the operands of BB's LAST statement. The last statement of BB must be a SWITCH_EXPR.

If any of the sub-graphs rooted at BB have an interesting use of the predicate operands, an assert location node is added to the list of assertions for the corresponding operands.

 Work around GCC 3.4 bug (PR 37086).   
 Build a vector of case labels sorted by destination label.   
     If there are multiple case labels with the same destination
     we need to combine them to a single value range for the edge.   
         Skip labels until the last of the group.   
         Pick up the maximum of the case label range.   
     Nothing to do if the range includes the default label until we
     can register anti-ranges.   
     Find the edge to register the assert expr on.   
     Register the necessary assertions for the operand in the
     SWITCH_EXPR.   

References cfun, dump_all_asserts(), dump_file, dump_flags, EXECUTE_IF_SET_IN_BITMAP, gcc_assert, gsi_commit_edge_inserts(), assert_locus_d::next, process_assert_insertions_for(), ssa_name, statistics_counter_event(), and TDF_DETAILS.

Referenced by register_edge_assert_for_1().

static bool fold_predicate_in ( )
static

If the statement pointed by SI has a predicate whose value can be computed using the value range information computed by VRP, compute its value and return true. Otherwise, return false.

static bool fp_predicate ( )
inlinestatic

Return false if EXPR is a predicate expression involving floating point values.

Referenced by register_edge_assert_for_1().

static bool gate_vrp ( )
static
static value_range_t* get_value_range ( )
static

Return value range information for VAR.

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.

 If we have no recorded ranges, then return NULL.   
 If we query the range for a new SSA name return an unmodifiable VARYING.
 We should get here at most from the substitute-and-fold stage which
 will never try to change values.   
 After propagation finished do not allocate new value-ranges.   
 Create a default value range.   
 Defer allocating the equivalence set.   
 If VAR is a default definition of a parameter, the variable can
 take any value in VAR's type.   
         Try to use the "nonnull" attribute to create ~[0, 0]
         anti-ranges for pointers.  Note that this is only valid with
         default definitions of PARM_DECLs.   

Referenced by check_array_ref(), gimple_stmt_nonnegative_warnv_p(), insert_range_assertions(), value_inside_range(), and vrp_intersect_ranges_1().

static value_range_t get_vr_for_comparison ( )
inlinestatic

Helper that gets the value range of the SSA_NAME with version I or a symbolic range containing the SSA_NAME only if the value range is varying or undefined.

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 have N_i in their ranges.

References CASE_LOW, gimple_switch_label(), gimple_switch_num_labels(), and tree_int_cst_compare().

static bool gimple_assign_nonnegative_warnv_p ( )
static

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_nonzero_warnv_p ( )
static

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.

References is_gimple_min_invariant(), TREE_CODE, and TREE_OPERAND.

static bool gimple_call_nonnegative_warnv_p ( )
static

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_stmt_nonnegative_warnv_p ( )
static

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.

References get_base_address(), get_value_range(), gimple_assign_rhs1(), NULL_TREE, range_is_nonnull(), TREE_CODE, and TREE_OPERAND.

static bool gimple_stmt_nonzero_warnv_p ( )
static

Return true if STMT is known to compute a non-zero 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 void identify_jump_threads ( )
static

Blocks which have more than one predecessor and more than one successor present jump threading opportunities, i.e., when the block is reached from a specific predecessor, we may be able to determine which of the outgoing edges will be traversed. When this optimization applies, we are able to avoid conditionals at runtime and we may expose secondary optimization opportunities.

This routine is effectively a driver for the generic jump threading code. It basically just presents the generic code with edges that may be suitable for jump threading.

Unlike DOM, we do not iterate VRP if jump threading was successful. While iterating may expose new opportunities for VRP, it is expected those opportunities would be very limited and the compile time cost to expose those opportunities would be significant.

As jump threading opportunities are discovered, they are registered for later realization.

 Ugh.  When substituting values earlier in this pass we can
 wipe the dominance information.  So rebuild the dominator
 information as we need it within the jump threading code.   
 We do not allow VRP information to be used for jump threading
 across a back edge in the CFG.  Otherwise it becomes too
 difficult to avoid eliminating loop exit tests.  Of course
 EDGE_DFS_BACK is not accurate at this time so we have to
 recompute it.   
 Do not thread across edges we are about to remove.  Just marking
 them as EDGE_DFS_BACK will do.   
 Allocate our unwinder stack to unwind any temporary equivalences
 that might be recorded.   
 To avoid lots of silly node creation, we create a single
 conditional and just modify it in-place when attempting to
 thread jumps.   
 Walk through all the blocks finding those which present a
 potential jump threading opportunity.  We could set this up
 as a dominator walker and record data during the walk, but
 I doubt it's worth the effort for the classes of jump
 threading opportunities we are trying to identify at this
 point in compilation.   
     If the generic jump threading code does not find this block
     interesting, then there is nothing to do.   
     We only care about blocks ending in a COND_EXPR.  While there
     may be some value in handling SWITCH_EXPR here, I doubt it's
     terribly important.   
     We're basically looking for a switch or any kind of conditional with
     integral or pointer type arguments.  Note the type of the second
     argument will be the same as the first argument, so no need to
     check it explicitly.   
         We've got a block with multiple predecessors and multiple
         successors which also ends in a suitable conditional or
         switch statement.  For each predecessor, see if we can thread
         it to a specific successor.   
             Do not thread across back edges or abnormal edges
             in the CFG.   
 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.   
static bool infer_nonnull_range ( )
static

If OP can be inferred to be non-zero after STMT executes, return true.

 We can only assume that a pointer dereference will yield
 non-NULL if -fdelete-null-pointer-checks is enabled.   
         If "nonnull" wasn't specified, we know nothing about
         the argument.   
         If "nonnull" applies to all the arguments, then ARG
         is non-null.   
         Now see if op appears in the nonnull list.   

References double_int_one.

Referenced by compare_range_with_value().

static bool infer_value_range ( )
static

If the range of values taken by OP can be inferred after STMT executes, return the comparison code (COMP_CODE_P) and value (VAL_P) that describes the inferred range. Return true if a range could be inferred.

 Do not attempt to infer anything in names that flow through
 abnormal edges.   
 Similarly, don't infer anything from statements that may throw
 exceptions. ??? Relax this requirement?   
 If STMT is the last statement of a basic block with no
 successors, there is no point inferring anything about any of its
 operands.  We would not be able to find a proper insertion point
 for the assertion, anyway.   

References build1, build2, CONVERT_EXPR_CODE_P, dump_file, gimple_assign_cast_p(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_expr_type(), has_single_use(), INTEGRAL_TYPE_P, is_gimple_assign(), live_on_edge(), NULL_TREE, SSA_NAME_DEF_STMT, TREE_CODE, TREE_TYPE, TYPE_PRECISION, and TYPE_UNSIGNED.

Referenced by register_edge_assert_for_1().

static void insert_range_assertions ( )
static

Traverse the flowgraph looking for conditional jumps to insert range expressions. These range expressions are meant to provide information to optimizations that need to reason in terms of value ranges. They will not be expanded into RTL. For instance, given:

x = ... y = ... if (x < y) y = x - 2; else x = y + 3;

this pass will transform the code into:

x = ... y = ... if (x < y) { x = ASSERT_EXPR <x, x < y> y = x - 2 } else { y = ASSERT_EXPR <y, x <= y> x = y + 3 }

The idea is that once copy and constant propagation have run, other optimizations will be able to determine what ranges of values can 'x' take in different paths of the code, simply by checking the reaching definition of 'x'.

References FOR_EACH_SSA_TREE_OPERAND, get_value_range(), prop_set_simulate_again(), set_value_range_to_varying(), and SSA_OP_DEF.

static void intersect_ranges ( enum value_range_type vr0type,
tree vr0min,
tree vr0max,
enum value_range_type  vr1type,
tree  vr1min,
tree  vr1max 
)
static

Intersect the two value-ranges { *VR0TYPE, *VR0MIN, *VR0MAX } and { VR1TYPE, VR0MIN, VR0MAX } and store the result in { *VR0TYPE, *VR0MIN, *VR0MAX }. This may not be the smallest possible such range. The resulting range is not canonicalized.

 [] is vr0, () is vr1 in the following classification comments.   
     [(  )]  
       Nothing to do for equal ranges.   
         For anti-range with range intersection the result is empty.   
     [ ] ( ) or ( ) [ ]
     If the ranges have an empty intersection, the result of the
     intersect operation is the range for intersecting an
     anti-range with a range or empty when intersecting two ranges.   
         If the anti-ranges are adjacent to each other merge them.   
         Else arbitrarily take VR0.   
     [ (  ) ] or [(  ) ] or [ (  )]  
         If both are ranges the result is the inner one.   
         Choose the right gap if the left one is empty.   
         Choose the left gap if the right one is empty.   
         Choose the anti-range if the range is effectively varying.   
         Else choose the range.   
       If both are anti-ranges the result is the outer one.   
         The intersection is empty.   
     ( [  ] ) or ([  ] ) or ( [  ])  
       Choose the inner range.   
         Choose the right gap if the left is empty.   
         Choose the left gap if the right is empty.   
         Choose the anti-range if the range is effectively varying.   
         Else choose the range.   
         If both are anti-ranges the result is the outer one.   
         The intersection is empty.   
     [  (  ]  ) or [  ](  )  
     (  [  )  ] or (  )[  ]  
 As a fallback simply use { *VRTYPE, *VR0MIN, *VR0MAX } as
 result for the intersection.  That's always a conservative
 correct estimate.   
static bool is_negative_overflow_infinity ( )
inlinestatic
static bool is_overflow_infinity ( )
inlinestatic

Return whether VAL is a positive or negative overflow infinity.

References gcc_checking_assert, TREE_TYPE, vrp_val_is_min(), and vrp_val_min().

Referenced by add_equivalence(), check_array_ref(), is_negative_overflow_infinity(), is_positive_overflow_infinity(), and vrp_meet_1().

static bool is_positive_overflow_infinity ( )
inlinestatic

Return whether VAL is a positive overflow infinity.

References is_overflow_infinity(), TREE_TYPE, vrp_val_is_max(), and vrp_val_max().

static bool live_on_edge ( )
static

Return true if the SSA name NAME is live on the edge E.

Referenced by infer_value_range().

static tree make_overflow_infinity ( )
inlinestatic

VAL is the maximum or minimum value of a type. Return a corresponding overflow infinity.

References CONSTANT_CLASS_P, needs_overflow_infinity(), TREE_OVERFLOW, TREE_TYPE, and vrp_val_is_min().

Referenced by supports_overflow_infinity().

gimple_opt_pass* make_pass_vrp ( )
static double_int masked_increment ( double_int  val,
double_int  mask,
double_int  sgnbit,
unsigned int  prec 
)
static

Find out smallest RES where RES > VAL && (RES & MASK) == RES, if any (otherwise return VAL). VAL and MASK must be zero-extended for precision PREC. If SGNBIT is non-zero, first xor VAL with SGNBIT (to transform signed values into unsigned) and at the end xor SGNBIT back.

Referenced by register_edge_assert_for_2().

static bool needs_overflow_infinity ( )
inlinestatic

Return whether TYPE should use an overflow infinity distinct from TYPE_{MIN,MAX}_VALUE. We use an overflow infinity value to represent a signed overflow during VRP computations. An infinity is distinct from a half-range, which will go from some number to TYPE_{MIN,MAX}_VALUE.

References CONSTANT_CLASS_P, copy_node, gcc_checking_assert, NULL_TREE, and TREE_OVERFLOW.

Referenced by make_overflow_infinity(), negative_overflow_infinity(), positive_overflow_infinity(), and vrp_val_is_min().

static tree negative_overflow_infinity ( )
inlinestatic

Return a negative overflow infinity for TYPE.

References CONSTANT_CLASS_P, needs_overflow_infinity(), TREE_OVERFLOW, TREE_TYPE, and vrp_val_is_max().

static bool nonnull_arg_p ( )
static

Return true if ARG is marked with the nonnull attribute in the current function signature.

 The static chain decl is always non null.   
     If "nonnull" wasn't specified, we know nothing about the argument.   
     If "nonnull" applies to all the arguments, then ARG is non-null.   
     Get the position number for ARG in the function signature.   
     Now see if ARG_NUM is mentioned in the nonnull list.   

References compare_tree_int(), and TREE_VALUE.

static bool op_with_boolean_value_range_p ( )
static

Return true if op is in a boolean [0, 1] value-range.

static tree op_with_constant_singleton_value_range ( )
static

If OP has a value range with a single constant value return that, otherwise return NULL_TREE. This returns OP itself if OP is a constant.

Referenced by extract_range_from_comparison().

static int operand_less_p ( )
inlinestatic

Return 1 if VAL < VAL2 0 if !(VAL < VAL2) -2 if those are incomparable.

LT is folded faster than GE and others. Inline the common case.

 val >= val2, not considering overflow infinity.   
static bool overflow_infinity_range_p ( )
inlinestatic

Return true if value range VR uses an overflow infinity.

static tree positive_overflow_infinity ( )
inlinestatic

Return a positive overflow infinity for TYPE.

References CONSTANT_CLASS_P, needs_overflow_infinity(), TREE_OVERFLOW, TREE_TYPE, vrp_val_is_max(), and vrp_val_is_min().

static void process_assert_insertions ( )
static

Process all the insertions registered for every name N_i registered in NEED_ASSERT_FOR. The list of assertions to be inserted are found in ASSERTS_FOR[i].

References gimple_phi_result(), INTEGRAL_TYPE_P, POINTER_TYPE_P, TREE_TYPE, and virtual_operand_p().

static bool process_assert_insertions_for ( )
static

Create an ASSERT_EXPR for NAME and insert it in the location indicated by LOC. Return true if we made any edge insertions.

 Build the comparison expression NAME_i COMP_CODE VAL.   
 If we have X <=> X do not insert an assert expr for that.   
     We have been asked to insert the assertion on an edge.  This
     is used only by COND_EXPR and SWITCH_EXPR assertions.   
 Otherwise, we can insert right after LOC->SI iff the
 statement must not be the last statement in the block.   
 If STMT must be the last statement in BB, we can only insert new
 assertions on the non-abnormal edge out of BB.  Note that since
 STMT is not control flow, there may only be one non-abnormal edge
 out of BB.   

References ASSERT_EXPR_COND, ASSERT_EXPR_VAR, boolean_false_node, fold(), FOR_EACH_BB, FOR_EACH_IMM_USE_ON_STMT, FOR_EACH_IMM_USE_STMT, gcc_assert, gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs_code(), gsi_end_p(), gsi_next(), gsi_remove(), gsi_start_bb(), gsi_stmt(), is_gimple_assign(), release_defs(), SET_USE, si, and TREE_CODE.

Referenced by find_switch_asserts().

static int quad_int_cmp ( double_int  l0,
double_int  h0,
double_int  l1,
double_int  h1,
bool  uns 
)
static

Some quadruple precision helpers.

static void quad_int_pair_sort ( double_int l0,
double_int h0,
double_int l1,
double_int h1,
bool  uns 
)
static
static bool range_fits_type_p ( )
static

Return whether the value range *VR fits in an integer type specified by PRECISION and UNSIGNED_P.

 We can only handle integral and pointer types.   
 An extension is fine unless VR is signed and unsigned_p,
 and so is an identity transform.   
 Now we can only handle ranges with constant bounds.   
 For sign changes, the MSB of the double_int has to be clear.
 An unsigned value with its MSB set cannot be represented by
 a signed double_int, while a negative value cannot be represented
 by an unsigned double_int.   
 Then we can perform the conversion on both ends and compare
 the result for equality.   

References extract_range_from_assignment(), gimple_assign_lhs(), INTEGRAL_TYPE_P, value_range_d::min, POINTER_TYPE_P, range_int_cst_singleton_p(), TREE_CODE, TREE_TYPE, and VR_INITIALIZER.

static int range_includes_zero_p ( )
inlinestatic

Return 1 if [MIN, MAX] includes the value zero, 0 if it does not include the value zero, -2 if we cannot tell.

References swap_tree_comparison(), TREE_CODE, and TREE_OPERAND.

static bool range_int_cst_p ( )
inlinestatic

Return true if max and min of VR are INTEGER_CST. It's not necessary a singleton.

Referenced by quad_int_pair_sort().

static bool range_int_cst_singleton_p ( )
inlinestatic

Return true if VR is a INTEGER_CST singleton.

Referenced by range_fits_type_p().

static bool range_is_nonnull ( )
inlinestatic

Return true if VR is ~[0, 0].

Referenced by gimple_stmt_nonnegative_warnv_p().

static bool ranges_from_anti_range ( value_range_t ar,
value_range_t vr0,
value_range_t vr1 
)
static

Create two value-ranges in *VR0 and *VR1 from the anti-range *AR so that *VR0 U *VR1 == *AR. Returns true if that is possible, false otherwise. If *AR can be represented with a single range *VR1 will be VR_UNDEFINED.

References set_value_range_to_varying().

static bool register_edge_assert_for ( tree  name,
edge  e,
gimple_stmt_iterator  si,
enum tree_code  cond_code,
tree  cond_op0,
tree  cond_op1 
)
static

Try to register an edge assertion for SSA name NAME on edge E for the condition COND contributing to the conditional jump pointed to by SI. Return true if an assertion for NAME could be registered.

 Do not attempt to infer anything in names that flow through
 abnormal edges.   
 Register ASSERT_EXPRs for name.   
 If COND is effectively an equality test of an SSA_NAME against
 the value zero or one, then we may be able to assert values
 for SSA_NAMEs which flow into COND.   
 In the case of NAME == 1 or NAME != 0, for BIT_AND_EXPR defining
 statement of NAME we can assert both operands of the BIT_AND_EXPR
 have nonzero value.   
 In the case of NAME == 0 or NAME != 1, for BIT_IOR_EXPR defining
 statement of NAME we can assert both operands of the BIT_IOR_EXPR
 have zero value.   
     For BIT_IOR_EXPR only if NAME == 0 both operands have
     necessarily zero value, or if type-precision is one.   

References bitmap_clear_bit(), bitmap_set_bit, FOR_EACH_PHI_ARG, gimple_phi_result(), gsi_stmt(), SSA_NAME_VERSION, SSA_OP_USE, TREE_CODE, USE_FROM_PTR, and virtual_operand_p().

static bool register_edge_assert_for_1 ( tree  op,
enum tree_code  code,
edge  e,
gimple_stmt_iterator  bsi 
)
static

OP is an operand of a truth value expression which is known to have a particular value. Register any asserts for OP and for any operands in OP's defining statement.

If CODE is EQ_EXPR, then we want to register OP is zero (false), if CODE is NE_EXPR, then we want to register OP is nonzero (true).

 We only care about SSA_NAMEs.   
 We know that OP will have a zero or nonzero value.  If OP is used
 more than once go ahead and register an assert for OP.

 The FOUND_IN_SUBGRAPH support is not helpful in this situation as
 it will always be set for OP (because OP is used in a COND_EXPR in
 the subgraph).   
 Now look at how OP is set.  If it's set from a comparison,
 a truth operation or some bit operations, then we may be able
 to register information about the operands of that assignment.   
     Recurse on each operand.   
     Recurse, flipping CODE.   
     Recurse through the copy.   
     Recurse through the type conversion.   

References bitmap_bit_p, bitmap_set_bit, find_conditional_asserts(), find_switch_asserts(), FOR_EACH_SSA_TREE_OPERAND, fp_predicate(), gimple_assign_rhs1(), gimple_assign_rhs_code(), gsi_end_p(), gsi_last_bb(), gsi_prev(), gsi_stmt(), has_single_use(), infer_value_range(), integer_zerop(), is_gimple_assign(), is_gimple_debug(), last, last_stmt(), NULL, POINTER_TYPE_P, register_new_assert_for(), si, SSA_NAME_DEF_STMT, SSA_NAME_VERSION, SSA_OP_DEF, SSA_OP_USE, TREE_CODE, TREE_TYPE, and ZERO_SSA_OPERANDS.

static bool register_edge_assert_for_2 ( tree  name,
edge  e,
gimple_stmt_iterator  bsi,
enum tree_code  cond_code,
tree  cond_op0,
tree  cond_op1,
bool  invert 
)
static

Try to register an edge assertion for SSA name NAME on edge E for the condition COND contributing to the conditional jump pointed to by BSI. Invert the condition COND if INVERT is true. Return true if an assertion for NAME could be registered.

 Only register an ASSERT_EXPR if NAME was found in the sub-graph
 reachable from E.   
 In the case of NAME <= CST and NAME being defined as
 NAME = (unsigned) NAME2 + CST2 we can assert NAME2 >= -CST2
 and NAME2 <= CST - CST2.  We can do the same for NAME > CST.
 This catches range and anti-range tests.   
     Extract CST2 from the (optional) addition.   
     Extract NAME2 from the (optional) sign-changing cast.   
     If name3 is used later, create an ASSERT_EXPR for it.   
         Build an expression for the range test.   
     If name2 is used later, create an ASSERT_EXPR for it.   
         Build an expression for the range test.   
 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.   
         Cut off to use-stmts that are in the predecessor.   
     Add asserts for NAME cmp CST and NAME being defined
     as NAME = (int) NAME2.   
             Build an expression for the range test.   
     Add asserts for NAME cmp CST and NAME being defined as
     NAME = NAME2 >> CST2.

     Extract CST2 from the right shift.   
     Add asserts for NAME cmp CST and NAME being defined as
     NAME = NAME2 & CST2.

     Extract CST2 from the and.

     Also handle
     NAME = (unsigned) NAME2;
     casts where NAME's type is unsigned and has smaller precision
     than NAME2's type as if it was NAME = NAME2 & MASK.   
         If CST2 doesn't have most significant bit set,
         but VAL is negative, we have comparison like
         if ((x & 0x123) > -4) (always true).  Just give up.   
             Minimum unsigned value for equality is VAL & CST2
             (should be equal to VAL, otherwise we probably should
             have folded the comparison into false) and
             maximum unsigned value is VAL | ~CST2.   
             If VAL is 0, handle (X & CST2) != 0 as (X & CST2) > 0U.   
             If (VAL | ~CST2) is all ones, handle it as
             (X & CST2) < VAL.   
             Minimum unsigned value for >= if (VAL & CST2) == VAL
             is VAL and maximum unsigned value is ~0.  For signed
             comparison, if CST2 doesn't have most significant bit
             set, handle it similarly.  If CST2 has MSB set,
             the minimum is the same, and maximum is ~0U/2.   
                 If (VAL & CST2) != VAL, X & CST2 can't be equal to
                 VAL.   
             Find out smallest MINV where MINV > VAL
             && (MINV & CST2) == MINV, if any.  If VAL is signed and
             CST2 has MSB set, compute it biased by 1 << (nprec - 1).   
             Minimum unsigned value for <= is 0 and maximum
             unsigned value is VAL | ~CST2 if (VAL & CST2) == VAL.
             Otherwise, find smallest VAL2 where VAL2 > VAL
             && (VAL2 & CST2) == VAL2 and use (VAL2 - 1) | ~CST2
             as maximum.
             For signed comparison, if CST2 doesn't have most
             significant bit set, handle it similarly.  If CST2 has
             MSB set, the maximum is the same and minimum is INT_MIN.   
             Minimum unsigned value for < is 0 and maximum
             unsigned value is (VAL-1) | ~CST2 if (VAL & CST2) == VAL.
             Otherwise, find smallest VAL2 where VAL2 > VAL
             && (VAL2 & CST2) == VAL2 and use (VAL2 - 1) | ~CST2
             as maximum.
             For signed comparison, if CST2 doesn't have most
             significant bit set, handle it similarly.  If CST2 has
             MSB set, the maximum is the same and minimum is INT_MIN.   

References double_int_one, double_int_zero, double_int::is_zero(), double_int::llshift(), double_int::mask(), masked_increment(), and double_int::zext().

static void register_new_assert_for ( tree  name,
tree  expr,
enum tree_code  comp_code,
tree  val,
basic_block  bb,
edge  e,
gimple_stmt_iterator  si 
)
static

If NAME doesn't have an ASSERT_EXPR registered for asserting 'EXPR COMP_CODE VAL' at a location that dominates block BB or E->DEST, then register this location as a possible insertion point for ASSERT_EXPR <NAME, EXPR COMP_CODE VAL>.

BB, E and SI provide the exact insertion point for the new ASSERT_EXPR. If BB is NULL, then the ASSERT_EXPR is to be inserted on edge E. Otherwise, if E is NULL, the ASSERT_EXPR is inserted on BB. If SI points to a COND_EXPR or a SWITCH_EXPR statement, then E must not be NULL.

 Never build an assert comparing against an integer constant with
 TREE_OVERFLOW set.  This confuses our undefined overflow warning
 machinery.   
 The new assertion A will be inserted at BB or E.  We need to
 determine if the new location is dominated by a previously
 registered location for A.  If we are doing an edge insertion,
 assume that A will be inserted at E->DEST.  Note that this is not
 necessarily true.

 If E is a critical edge, it will be split.  But even if E is
 split, the new block will dominate the same set of blocks that
 E->DEST dominates.

 The reverse, however, is not true, blocks dominated by E->DEST
 will not be dominated by the new block created to split E.  So,
 if the insertion location is on a critical edge, we will not use
 the new location to move another assertion previously registered
 at a block dominated by E->DEST.   
 If NAME already has an ASSERT_EXPR registered for COMP_CODE and
 VAL at a block dominating DEST_BB, then we don't need to insert a new
 one.  Similarly, if the same assertion already exists at a block
 dominated by DEST_BB and the new location is not on a critical
 edge, then update the existing location for the assertion (i.e.,
 move the assertion up in the dominance tree).

 Note, this is implemented as a simple linked list because there
 should not be more than a handful of assertions registered per
 name.  If this becomes a performance problem, a table hashed by
 COMP_CODE and VAL could be implemented.   
         If E is not a critical edge and DEST_BB
         dominates the existing location for the assertion, move
         the assertion up in the dominance tree by updating its
         location information.   
     Update the last node of the list and move to the next one.   
 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.   

Referenced by register_edge_assert_for_1().

static void remove_range_assertions ( )
static

Convert range assertion expressions into the implied copies and copy propagate away the copies. Doing the trivial copy propagation here avoids the need to run the full copy propagation pass after VRP.

FIXME, this will eventually lead to copy propagation removing the names that had useful range information attached to them. For instance, if we had the assertion N_i = ASSERT_EXPR <N_j, N_j > 3>, then N_i will have the range [3, +INF].

However, by converting the assertion into the implied copy operation N_i = N_j, we will then copy-propagate N_j into the uses of N_i and lose the range information. We may want to hold on to ASSERT_EXPRs a little while longer as the ranges could be used in things like jump threading.

The problem with keeping ASSERT_EXPRs around is that passes after VRP need to handle them appropriately.

Another approach would be to make the range information a first class property of the SSA_NAME so that it can be queried from any pass. This is made somewhat more complex by the need for multiple ranges to be associated with one SSA_NAME.

 Note that the BSI iterator bump happens at the bottom of the
 loop and no bump is necessary if we're removing the statement
 referenced by the current BSI.   
           Propagate the RHS into every use of the LHS.   
           And finally, remove the copy, it is not needed.   
static void search_for_addr_array ( )
static

Searches if the expr T, located at LOCATION computes address of an ARRAY_REF, and call check_array_ref on it.

We are only interested in addresses of ARRAY_REF's.

 Check each ARRAY_REFs in the reference chain.  
static void set_and_canonicalize_value_range ( value_range_t vr,
enum value_range_type  t,
tree  min,
tree  max,
bitmap  equiv 
)
static

Set value range VR to the canonical form of {T, MIN, MAX, EQUIV}. This means adjusting T, MIN and MAX representing the case of a wrapping range with MAX < MIN covering [MIN, type_max] U [type_min, MAX] as anti-rage ~[MAX+1, MIN-1]. Likewise for wrapping anti-ranges. In corner cases where MAX+1 or MIN-1 wraps this will fall back to varying. This routine exists to ease canonicalization in the case where we extract ranges from var + CST op limit.

 Use the canonical setters for VR_UNDEFINED and VR_VARYING.   
 Nothing to canonicalize for symbolic ranges.   
 Wrong order for min and max, to swap them and the VR type we need
 to adjust them.   
     For one bit precision if max < min, then the swapped
     range covers all values, so for VR_RANGE it is varying and
     for VR_ANTI_RANGE empty range, so drop to varying as well.   
     There's one corner case, if we had [C+1, C] before we now have
     that again.  But this represents an empty value range, so drop
     to varying in this case.   
 Anti-ranges that can be represented as ranges should be so.   
         We cannot deal with empty ranges, drop to varying.
         ???  This could be VR_UNDEFINED instead.   
         Non-empty boolean ranges can always be represented
         as a singleton range.   
              As a special exception preserve non-null ranges.   
 Drop [-INF(OVF), +INF(OVF)] to varying.   

References set_value_range_to_varying().

static void set_value_range ( value_range_t vr,
enum value_range_type  t,
tree  min,
tree  max,
bitmap  equiv 
)
static

Set value range VR to {T, MIN, MAX, EQUIV}.

Since updating the equivalence set involves deep copying the bitmaps, only do it if absolutely necessary.

Referenced by check_array_ref().

static void set_value_range_to_nonnegative ( value_range_t vr,
tree  type,
bool  overflow_infinity 
)
inlinestatic

Set value range VR to a non-negative range of type TYPE. OVERFLOW_INFINITY indicates whether to use an overflow infinity rather than TYPE_MAX_VALUE; this should be true if we determine that the range is nonnegative based on the assumption that signed overflow does not occur.

static void set_value_range_to_nonnull ( )
inlinestatic

Set value range VR to a non-NULL range of type TYPE.

static void set_value_range_to_null ( )
inlinestatic

Set value range VR to a NULL range of type TYPE.

References NULL, NULL_TREE, SSA_NAME_VERSION, and VR_VARYING.

static void set_value_range_to_truthvalue ( )
inlinestatic

Set value range VR to a range of a truthvalue of type TYPE.

static void set_value_range_to_undefined ( )
inlinestatic

Set value range VR to VR_UNDEFINED.

static void set_value_range_to_value ( )
inlinestatic

Set value range VR to a single value. This function is only called with values we get from statements, and exists to clear the TREE_OVERFLOW flag so that we don't think we have an overflow infinity when we shouldn't.

Referenced by copy_value_range(), extract_range_from_comparison(), extract_range_from_cond_expr(), and vrp_intersect_ranges_1().

static void set_value_range_to_varying ( )
inlinestatic
static bool simplify_abs_using_ranges ( )
static

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_bit_ops_using_ranges ( )
static

Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR. If all the bits that are being cleared by & are already known to be zero from VR, or all the bits that are being set by | are already known to be one from VR, the bit operation is redundant.

static bool simplify_cond_using_ranges ( )
static

Simplify a conditional using a relational operator to an equality test if the range information indicates only one value can satisfy the original conditional.

     If we have range information for OP0, then we might be
     able to simplify this conditional.  
         Try again after inverting the condition.  We only deal
         with integral types here, so no need to worry about
         issues with inverting FP comparisons.   
 If we have a comparison of an SSA_NAME (OP0) against a constant,
 see if OP0 was set by a type conversion where the source of
 the conversion is another SSA_NAME with a range that fits
 into the range of OP0's type.

 If so, the conversion is redundant as the earlier SSA_NAME can be
 used for the comparison directly if we just massage the constant in the
 comparison.   
             The range must not have overflowed, or if it did overflow
             we must not be wrapping/trapping overflow and optimizing
             with strict overflow semantics.   
             If the range overflowed and the user has asked for warnings
             when strict overflow semantics were used to optimize code,
             issue an appropriate warning.   

References EDGE_COMPLEX, edge_def::flags, FOR_EACH_EDGE, gimple_cond_lhs(), gimple_cond_rhs(), gsi_last_bb(), gsi_stmt(), INTEGRAL_TYPE_P, is_gimple_min_invariant(), last, POINTER_TYPE_P, potentially_threadable_block(), simplify_stmt_for_jump_threading(), thread_across_edge(), TREE_CODE, and TREE_TYPE.

static bool simplify_conversion_using_ranges ( )
static

Simplify an integral conversion from an SSA name in STMT.

 Get the value-range of the inner operand.   
 Simulate the conversion chain to check if the result is equal if
 the middle conversion is removed.   
 If the first conversion is not injective, the second must not
 be widening.   
 We also want a medium value so that we can track the effect that
 narrowing conversions with sign change have.   
 Require that the final conversion applied to both the original
 and the intermediate range produces the same result.   
static bool simplify_div_or_mod_using_ranges ( )
static

Simplify a division or modulo operator to a right shift or bitwise and if the first operand is unsigned or is greater than zero and the second operand is an exact power of two.

static bool simplify_float_conversion_using_ranges ( )
static

Simplify a conversion from integral SSA name to float in STMT.

 We can only handle constant ranges.   
 First check if we can use a signed type in place of an unsigned.   
 If we can do the conversion in the current input mode do nothing.   
 Otherwise search for a mode we can use, starting from the narrowest
 integer mode available.   
         If we cannot do a signed conversion to float from mode
         or if the value-range does not fit in the signed type
         try with a wider mode.   
         But do not widen the input.  Instead leave that to the
         optabs expansion code.   
 It works, insert a truncation or sign-change before the
 float conversion.   
static tree simplify_stmt_for_jump_threading ( )
static

A trivial wrapper so that we can present the generic jump threading code with a simple API for simplifying statements. STMT is the statement we want to simplify, WITHIN_STMT provides the location for any overflow warnings.

Referenced by simplify_cond_using_ranges().

static bool simplify_stmt_using_ranges ( )
static

Simplify STMT using ranges if possible.

Transform EQ_EXPR, NE_EXPR into BIT_XOR_EXPR or identity
if the RHS is zero or one, and the LHS are known to be boolean
values.   
     Transform TRUNC_DIV_EXPR and TRUNC_MOD_EXPR into RSHIFT_EXPR
     and BIT_AND_EXPR respectively if the first operand is greater
     than zero and the second operand is an exact power of two.   


     Transform ABS (X) into X or -X as appropriate.   
         Optimize away BIT_AND_EXPR and BIT_IOR_EXPR
         if all the bits being cleared are already cleared or
         all the bits being set are already set.   
static bool simplify_switch_using_ranges ( )
static

Simplify a switch statement using the value range of the switch argument.

     We can only handle integer ranges.   
     Find case label for min/max of the value range.   
 Bail out if this is just all edges taken.   
 Build a new vector of taken case labels.   
 Add the default edge, if necessary.   
 Mark needed edges.   
 Queue not needed edges for later removal.   
 And queue an update for the stmt.   
static bool simplify_truth_ops_using_ranges ( )
static

Simplify boolean operations if the source is known to be already a boolean.

 We handle only !=/== case here.   
 Reduce number of cases to handle to NE_EXPR.  As there is no
 BIT_XNOR_EXPR we cannot replace A == B with a single statement.   
 Make sure to not sign-extend a 1-bit 1 when converting the result.   
 For A != 0 we can substitute A itself.   
 For A != B we substitute A ^ B.  Either with conversion.   
 Or without.   
bool ssa_name_nonnegative_p ( )

Return true if T, an SSA_NAME, is known to be nonnegative. Return false otherwise or if no value range information is available.

static bool stmt_interesting_for_vrp ( )
static

Return true if STMT is interesting for VRP.

In general, assignments with virtual operands are not useful for deriving ranges, with the obvious exception of calls to builtin functions.

static bool stmt_overflow_infinity ( )
inlinestatic

Return whether STMT has a constant rhs that is_overflow_infinity.

References cfun, gcc_assert, HOST_WIDE_INT, lookup_attribute(), POINTER_TYPE_P, TREE_CHAIN, TREE_CODE, TREE_TYPE, and TYPE_ATTRIBUTES.

static bool supports_overflow_infinity ( )
inlinestatic

Return whether TYPE can support our overflow infinity representation: we use the TREE_OVERFLOW flag, which only exists for constants. If TYPE doesn't support this, we don't optimize cases which would require signed overflow–we drop them to VARYING.

References gcc_checking_assert, make_overflow_infinity(), and vrp_val_min().

static bool symbolic_range_p ( )
inlinestatic

Return true if value range VR involves at least one symbol.

References gimple_call_arg(), gimple_call_fndecl(), gimple_call_num_args(), gimple_expr_type(), NULL_TREE, and tree_call_nonnegative_warnv_p().

static tree test_for_singularity ( enum tree_code  cond_code,
tree  op0,
tree  op1,
value_range_t vr 
)
static

We are comparing trees OP0 and OP1 using COND_CODE. OP0 has a known value range VR.

If there is one and only one value which will satisfy the conditional, then return that value. Else return NULL.

 Extract minimum/maximum values which satisfy the
 the conditional as it was written.   
     This should not be negative infinity; there is no overflow
     here.   
     This should not be positive infinity; there is no overflow
     here.   
 Now refine the minimum and maximum values using any
 value range information we have for op0.   
     If the new min/max values have converged to a single value,
     then there is only one value which can satisfy the condition,
     return that value.   

References dump_file, fold_convert, gcc_assert, gcc_unreachable, gimple_assign_set_rhs_from_tree(), gimple_cond_make_false(), gimple_cond_make_true(), gimple_expr_type(), integer_onep(), integer_zerop(), is_gimple_assign(), print_generic_expr(), and print_gimple_expr().

static void union_ranges ( enum value_range_type vr0type,
tree vr0min,
tree vr0max,
enum value_range_type  vr1type,
tree  vr1min,
tree  vr1max 
)
static

Union the two value-ranges { *VR0TYPE, *VR0MIN, *VR0MAX } and { VR1TYPE, VR0MIN, VR0MAX } and store the result in { *VR0TYPE, *VR0MIN, *VR0MAX }. This may not be the smallest possible such range. The resulting range is not canonicalized.

 [] is vr0, () is vr1 in the following classification comments.   
     [(  )]  
       Nothing to do for equal ranges.   
         For anti-range with range union the result is varying.   
     [ ] ( ) or ( ) [ ]
     If the ranges have an empty intersection, result of the union
     operation is the anti-range or if both are anti-ranges
     it covers all.   
         The result is the convex hull of both ranges.   
             If the result can be an anti-range, create one.   
             If the result can be an anti-range, create one.   
     [ (  ) ] or [(  ) ] or [ (  )]  
         Arbitrarily choose the right or left gap.   
       The result covers everything.   
     ( [  ] ) or ([  ] ) or ( [  ])  
       The result covers everything.   
     [  (  ]  ) or [   ](   )  
     (  [  )  ] or (   )[   ]  
static bool update_value_range ( )
inlinestatic

Update the value range and equivalence set for variable VAR to NEW_VR. Return true if NEW_VR is different from VAR's previous value.

NOTE: This function assumes that NEW_VR is a temporary value range object created for the sole purpose of updating VAR's range. The storage used by the equivalence set from NEW_VR will be freed by this function. Do not call update_value_range when NEW_VR is the range object associated with another SSA name.

Update the value range, if necessary.

     Do not allow transitions up the lattice.  The following
     is slightly more awkward than just new_vr->type < old_vr->type
     because VR_RANGE and VR_ANTI_RANGE need to be considered
     the same.  We may not have is_new when transitioning to
     UNDEFINED or from VARYING.   

References value_range_d::max, value_range_d::min, TREE_CODE, value_range_d::type, and VR_RANGE.

Referenced by check_array_ref().

static bool usable_range_p ( )
static

Return false if we can not make a valid comparison based on VR; this will be the case if it uses an overflow infinity and overflow is not undefined (i.e., -fno-strict-overflow is in effect). Otherwise return true, and set *STRICT_OVERFLOW_P to true if VR uses an overflow infinity.

static bool valid_value_p ( )
static

Returns true if EXPR is a valid value (as expected by compare_values) – a gimple invariant, or SSA_NAME +- CST.

References NULL_TREE, TREE_CODE, and TREE_OPERAND.

static int value_inside_range ( )
inlinestatic

Return 1 if VAL is inside value range MIN <= VAL <= MAX, 0 if VAL is not inside [MIN, MAX], -2 if we cannot tell either way.

Benchmark compile/20001226-1.c compilation time after changing this function.

References get_value_range(), integer_onep(), integer_zerop(), value_range_d::max, value_range_d::min, TREE_CODE, TREE_TYPE, value_range_d::type, TYPE_PRECISION, and VR_RANGE.

static tree value_range_constant_singleton ( )
static

If *VR has a value rante that is a single constant value return that, otherwise return NULL_TREE.

References fold_build1, int_const_binop(), TREE_CODE, TREE_OPERAND, and TREE_TYPE.

static bool value_range_nonnegative_p ( )
inlinestatic

Return true if *VR is know to only contain nonnegative values.

Testing for VR_ANTI_RANGE is not useful here as any anti-range which would return a useful value should be encoded as a VR_RANGE.

static bool value_ranges_intersect_p ( )
inlinestatic

Return true if value ranges VR0 and VR1 have a non-empty intersection.

Benchmark compile/20001226-1.c compilation time after changing this function.

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. When those relations are unknown, we can't do any better.

static bool vrp_bitmap_equal_p ( )
inlinestatic

Return true, if the bitmaps B1 and B2 are equal.

References integer_zerop(), value_range_d::max, value_range_d::min, value_range_d::type, and VR_ANTI_RANGE.

static tree vrp_evaluate_conditional ( )
static

Given (CODE OP0 OP1) within STMT, try to simplify it based on value range information. Return NULL if the conditional can not be evaluated. The ranges of all the names equivalent with the operands in COND will be used when trying to compute the value. If the result is based on undefined signed overflow, issue a warning if appropriate.

Some passes and foldings leak constants with overflow flag set into the IL. Avoid doing wrong things with these and bail out.

     If the comparison is being folded and the operand on the LHS
     is being compared against a constant value that is outside of
     the natural range of OP0's type, then the predicate will
     always fold regardless of the value of OP0.  If -Wtype-limits
     was specified, emit a warning.   

References dump_file, dump_flags, and print_gimple_stmt().

static tree vrp_evaluate_conditional_warnv_with_ops ( enum tree_code  code,
tree  op0,
tree  op1,
bool  use_equiv_p,
bool strict_overflow_p,
bool only_ranges 
)
static

Helper function for vrp_evaluate_conditional_warnv.

We only deal with integral and pointer types.

static tree vrp_evaluate_conditional_warnv_with_ops_using_ranges ( enum tree_code  code,
tree  op0,
tree  op1,
bool strict_overflow_p 
)
static

Helper function for vrp_evaluate_conditional_warnv.

static void vrp_finalize ( )
static

Traverse all the blocks folding conditionals with known ranges.

 We must identify jump threading opportunities before we release
 the datastructures built by VRP.   
 Set value range to non pointer SSA_NAMEs.   
               VR_ANTI_RANGE ~[min, max] is encoded compactly as
               [max + 1, min - 1] without additional attributes.
               When min value > max value, we know that it is
               VR_ANTI_RANGE; it is VR_RANGE otherwise.   
               ~[0,0] anti-range is represented as
               range.   
 Free allocated memory.   
 So that we can distinguish between VRP data being available
 and not available.   
static bool vrp_fold_stmt ( )
static

Callback for substitute_and_fold folding the stmt at *SI.

static void vrp_initialize ( )
static

Initialize local data structures for VRP.

If the statement is a control insn, then we do not want to avoid simulating the statement once. Failure to do so means that those edges will never get added.

References G_, gimple_has_location(), gimple_location(), input_location, integer_zerop(), and warning_at().

static tree vrp_int_const_binop ( )
static

Wrapper around int_const_binop. If the operation overflows and we are not using wrapping arithmetic, then adjust the result to be -INF or +INF depending on CODE, VAL1 and VAL2. This can return NULL_TREE if we need to use an overflow infinity representation but the type does not support it.

 If we are using unsigned arithmetic, operate symbolically
 on -INF and +INF as int_const_binop only handles signed overflow.   
     Ensure that res = val1 [+*] val2 >= val1
     or that res = val1 - val2 <= val1.   
     Checking for multiplication overflow is done by dividing the
     output of the multiplication by the first input of the
     multiplication.  If the result of that division operation is
     not equal to the second input of the multiplication, then the
     multiplication overflowed.   
   If the singed operation wraps then int_const_binop has done
   everything we want.   
     If the operation overflowed but neither VAL1 nor VAL2 are
     overflown, return -INF or +INF depending on the operation
     and the combination of signs of the operands.   
     We have to punt on adding infinities of different signs,
     since we can't tell what the sign of the result should be.
     Likewise for subtracting infinities of the same sign.   
     Don't try to handle division or shifting of infinities.   
     Notice that we only need to handle the restricted set of
     operations handled by extract_range_from_binary_expr.
     Among them, only multiplication, addition and subtraction
     can yield overflow without overflown operands because we
     are working with integral types only... except in the
     case VAL1 = -INF and VAL2 = -1 which overflows to +INF
     for division too.   
     For multiplication, the sign of the overflow is given
     by the comparison of the signs of the operands.   
         For addition, the operands must be of the same sign
         to yield an overflow.  Its sign is therefore that
         of one of the operands, for example the first.  For
         infinite operands X + -INF is negative, not positive.   
         For subtraction, non-infinite operands must be of
         different signs to yield an overflow.  Its sign is
         therefore that of the first operand or the opposite of
         that of the second operand.  A first operand of 0 counts
         as positive here, for the corner case 0 - (-INF), which
         overflows, but must yield +INF.  For infinite operands 0
         - INF is negative, not positive.   
         We only get in here with positive shift count, so the
         overflow direction is the same as the sign of val1.
         Actually rshift does not overflow at all, but we only
         handle the case of shifting overflowed -INF and +INF.   
         For division, the only case is -INF / -1 = +INF.   

References value_range_d::min, and tree_to_double_int().

static void vrp_intersect_ranges ( value_range_t ,
value_range_t  
)
static
static void vrp_intersect_ranges ( )
static
static void vrp_intersect_ranges_1 ( )
static

Intersect the two value-ranges *VR0 and *VR1 and store the result in *VR0. This may not be the smallest possible such range.

 If either range is VR_VARYING the other one wins.   
 When either range is VR_UNDEFINED the resulting range is
 VR_UNDEFINED, too.   
 Save the original vr0 so we can return it as conservative intersection
 result when our worker turns things to varying.   
 Make sure to canonicalize the result though as the inversion of a
 VR_RANGE can still be a VR_RANGE.   
 If that failed, use the saved original VR0.   
 If the result is VR_UNDEFINED there is no need to mess with
 the equivalencies.   
 The resulting set of equivalences for range intersection is the union of
 the two sets.   

References double_int::and_not(), get_value_range(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), is_gimple_min_invariant(), double_int::is_zero(), NULL, NULL_TREE, set_value_range_to_value(), TREE_CODE, VR_INITIALIZER, and zero_nonzero_bits_from_vr().

static void vrp_meet ( value_range_t ,
value_range_t  
)
static
static void vrp_meet ( )
static
static void vrp_meet_1 ( )
static

Meet operation for value ranges. Given two value ranges VR0 and VR1, store in VR0 a range that contains both VR0 and VR1. This may not be the smallest possible such range.

     VR0 already has the resulting range.   
     Nothing to do.  VR0 already has the resulting range.   
     Failed to find an efficient meet.  Before giving up and setting
     the result to VARYING, see if we can at least derive a useful
     anti-range.  FIXME, all this nonsense about distinguishing
     anti-ranges from ranges is necessary because of the odd
     semantics of range_includes_zero_p and friends.   
         Since this meet operation did not result from the meeting of
         two equivalent names, VR0 cannot have any equivalences.   
 The resulting set of equivalences is always the intersection of
 the two sets.   

References build_int_cst(), compare_values(), EXPR_P, fold_build2, is_gimple_min_invariant(), is_overflow_infinity(), value_range_d::max, value_range_d::min, NULL, operand_equal_p(), TREE_NO_WARNING, TREE_TYPE, TYPE_MAX_VALUE, and TYPE_MIN_VALUE.

static bool vrp_operand_equal_p ( )
inlinestatic

Return true, if VAL1 and VAL2 are equal values for VRP purposes.

References BITMAP_ALLOC, bitmap_ior_into(), bitmap_set_bit, value_range_d::equiv, NULL, and SSA_NAME_VERSION.

static bool vrp_stmt_computes_nonzero ( )
static

Like tree_expr_nonzero_warnv_p, but this function uses value ranges obtained so far.

If we have an expression of the form &X->a, then the expression is nonnull if X is nonnull.

References fold_convert, gcc_assert, POINTER_TYPE_P, STRIP_USELESS_TYPE_CONVERSION, TREE_CODE, and TREE_TYPE.

static bool vrp_val_is_max ( )
inlinestatic

Return whether VAL is equal to the maximum value of its type. This will be true for a positive overflow infinity. We can't do a simple equality comparison with TYPE_MAX_VALUE because C typedefs and Ada subtypes can produce types whose TYPE_MAX_VALUE is not == to the integer constant with the same value in the type.

References INTEGRAL_TYPE_P, and TYPE_OVERFLOW_WRAPS.

Referenced by is_positive_overflow_infinity(), negative_overflow_infinity(), and positive_overflow_infinity().

static bool vrp_val_is_min ( )
inlinestatic

Return whether VAL is equal to the minimum value of its type. This will be true for a negative overflow infinity.

References CONSTANT_CLASS_P, gcc_assert, needs_overflow_infinity(), NULL_TREE, vrp_val_max(), and vrp_val_min().

Referenced by is_overflow_infinity(), make_overflow_infinity(), and positive_overflow_infinity().

static tree vrp_val_max ( )
inlinestatic

Return the maximum value for TYPE.

References NULL_TREE, operand_equal_p(), and TREE_TYPE.

Referenced by is_positive_overflow_infinity(), and vrp_val_is_min().

static tree vrp_val_min ( )
inlinestatic

Return the minimum value for TYPE.

References NULL_TREE, operand_equal_p(), and TREE_TYPE.

Referenced by is_overflow_infinity(), supports_overflow_infinity(), and vrp_val_is_min().

static tree vrp_valueize ( )
inlinestatic

Return the singleton value-range for NAME or NAME.

Referenced by check_array_ref().

static bool vrp_var_may_overflow ( )
static

Return true if VAR may overflow at STMT. This checks any available loop information to see if we can determine that VAR does not overflow.

If we get here, we know something useful about VAR based on the loop information. If it wraps, it may overflow.

static enum ssa_prop_result vrp_visit_assignment_or_call ( )
static

Visit assignment STMT. If it produces an interesting range, record the SSA name in *OUTPUT_P.

 We only keep track of ranges in integral and pointer types.   
          It is valid to have NULL MIN/MAX values on a type.  See
          build_range_type.   
     Try folding the statement to a constant first.   
     Then dispatch to value-range extracting functions.   
 Every other statement produces no useful ranges.   
static enum ssa_prop_result vrp_visit_cond_stmt ( )
static

Visit conditional statement STMT. If we can determine which edge will be taken out of STMT's basic block, record it in *TAKEN_EDGE_P and return SSA_PROP_INTERESTING. Otherwise, return SSA_PROP_VARYING.

Compute the value of the predicate COND by checking the known ranges of each of its operands.

Note that we cannot evaluate all the equivalent ranges here because those ranges may not yet be final and with the current propagation strategy, we cannot determine when the value ranges of the names in the equivalence set have changed.

For instance, given the following code fragment

i_5 = PHI <8, i_13> ... i_14 = ASSERT_EXPR <i_5, i_5 != 0> if (i_14 == 1) ...

Assume that on the first visit to i_14, i_5 has the temporary range [8, 8] because the second argument to the PHI function is not yet executable. We derive the range ~[0, 0] for i_14 and the equivalence set { i_5 }. So, when we visit 'if (i_14 == 1)' for the first time, since i_14 is equivalent to the range [8, 8], we determine that the predicate is always false.

On the next round of propagation, i_13 is determined to be VARYING, which causes i_5 to drop down to VARYING. So, another visit to i_14 is scheduled. In this second visit, we compute the exact same range and equivalence set for i_14, namely ~[0, 0] and { i_5 }. But we did not have the previous range for i_5 registered, so vrp_visit_assignment thinks that the range for i_14 has not changed. Therefore, the predicate 'if (i_14 == 1)' is not visited again, which stops propagation from visiting statements in the THEN clause of that if().

To properly fix this we would need to keep the previous range value for the names in the equivalence set. This way we would've discovered that from one visit to the other i_5 changed from range [8, 8] to VR_VARYING.

However, fixing this apparent limitation may not be worth the additional checking. Testing on several code bases (GCC, DLV, MICO, TRAMP3D and SPEC2000) showed that doing this results in 4 more predicates folded in SPEC.

static enum ssa_prop_result vrp_visit_phi_node ( )
static

Visit all arguments for PHI node PHI that flow through executable edges. If a valid value range can be derived from all the incoming value ranges, set a new range for the LHS of PHI.

        Do not allow equivalences or symbolic ranges to leak in from
        backedges.  That creates invalid equivalencies.
        See PR53465 and PR54767.   
 To prevent infinite iterations in the algorithm, derive ranges
 when the new value is slightly bigger or smaller than the
 previous one.  We don't do this if we have seen a new executable
 edge; this helps us avoid an overflow infinity for conditionals
 which are not in a loop.  If the old value-range was VR_UNDEFINED
 use the updated range and iterate one more time.   


     For non VR_RANGE or for pointers fall back to varying if
     the range changed.   
     If the new minimum is smaller or larger than the previous
     one, go all the way to -INF.  In the first case, to avoid
     iterating millions of times to reach -INF, and in the
     other case to avoid infinite bouncing between different
     minimums.   
     Similarly, if the new maximum is smaller or larger than
     the previous one, go all the way to +INF.   
     If we dropped either bound to +-INF then if this is a loop
     PHI node SCEV may known more about its value-range.   
     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 the new range is different than the previous value, keep
 iterating.   
 Nothing changed, don't add outgoing edges.   
 No match found.  Set the LHS to VARYING.   
static enum ssa_prop_result vrp_visit_stmt ( )
static

Evaluate statement STMT. If the statement produces a useful range, return SSA_PROP_INTERESTING and record the SSA name with the interesting range into *OUTPUT_P.

If STMT is a conditional branch and we can determine its truth value, the taken edge is recorded in *TAKEN_EDGE_P.

If STMT produces a varying value, return SSA_PROP_VARYING.

All other statements produce nothing of interest for VRP, so mark their outputs varying and prevent further simulation.

static enum ssa_prop_result vrp_visit_switch_stmt ( )
static

Visit switch statement STMT. If we can determine which edge will be taken out of STMT's basic block, record it in *TAKEN_EDGE_P and return SSA_PROP_INTERESTING. Otherwise, return SSA_PROP_VARYING.

 Find the single edge that is taken from the switch expression.   
 Check if the range spans no CASE_LABEL. If so, we only reach the default
 label  
     Check if labels with index i to j and maybe the default label
     are all reaching the same label.   
static bool zero_nonzero_bits_from_vr ( value_range_t vr,
double_int may_be_nonzero,
double_int must_be_nonzero 
)
static

For range VR compute two double_int bitmasks. In *MAY_BE_NONZERO bitmask if some bit is unset, it means for all numbers in the range the bit is 0, otherwise it might be 0 or 1. In *MUST_BE_NONZERO bitmask if some bit is set, it means for all numbers in the range the bit is 1, otherwise it might be 0 or 1.

Referenced by vrp_intersect_ranges_1().


Variable Documentation

assert_locus_t* asserts_for
static

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.

vec<tree> equiv_stack
static

Stack of dest,src equivalency pairs that need to be restored after each attempt to thread a block's incoming edge to an outgoing edge.

A NULL entry is used to mark the end of pairs which need to be restored.

sbitmap* live
static

Set of SSA names found live during the RPO traversal of the function for still active basic-blocks.

Referenced by split_all_insns().

bitmap need_assert_for
static

If bit I is present, it means that SSA name N_i has a list of assertions that should be inserted in the IL.

unsigned num_vr_values
static

Value range array. After propagation, VR_VALUE[I] holds the range of values that SSA name N_I may take.

vec<edge> to_remove_edges
static
vec<switch_update> to_update_switch_stmts
static
bool values_propagated
static
int* vr_phi_edge_counts
static

For a PHI node which sets SSA name N_I, VR_COUNTS[I] holds the number of executable edges we saw the last time we visited the node.

value_range_t** vr_value
static