/* Support routines for Value Range Propagation (VRP).
- Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ Copyright (C) 2005-2016 Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@redhat.com>.
This file is part of GCC.
modulo. */
static bool
-simplify_div_or_mod_using_ranges (gimple *stmt)
+simplify_div_or_mod_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt)
{
enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
tree val = NULL;
}
if (!integer_pow2p (op1))
- return false;
-
- if (TYPE_UNSIGNED (TREE_TYPE (op0)))
{
- val = integer_one_node;
+ /* X % -Y can be only optimized into X % Y either if
+ X is not INT_MIN, or Y is not -1. Fold it now, as after
+ remove_range_assertions the range info might be not available
+ anymore. */
+ if (rhs_code == TRUNC_MOD_EXPR
+ && fold_stmt (gsi, follow_single_use_edges))
+ return true;
+ return false;
}
+
+ if (TYPE_UNSIGNED (TREE_TYPE (op0)))
+ val = integer_one_node;
else
{
bool sop = false;
if (TREE_CODE (innerop) == SSA_NAME
&& !POINTER_TYPE_P (TREE_TYPE (innerop))
- && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0)))
+ && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop)
+ && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0)))
{
value_range *vr = get_value_range (innerop);
else
location = gimple_location (stmt);
warning_at (location, OPT_Wstrict_overflow,
- "assuming signed overflow does not occur when "
- "simplifying conditional");
+ "assuming signed overflow does not occur when "
+ "simplifying conditional");
}
tree newconst = fold_convert (TREE_TYPE (innerop), op1);
case TRUNC_MOD_EXPR:
if (TREE_CODE (rhs1) == SSA_NAME
&& INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
- return simplify_div_or_mod_using_ranges (stmt);
+ return simplify_div_or_mod_using_ranges (gsi, stmt);
break;
/* Transform ABS (X) into X or -X as appropriate. */
fprintf (dump_file, "\n");
}
- substitute_and_fold (op_with_constant_singleton_value_range,
- vrp_fold_stmt, false);
-
- if (warn_array_bounds && warn_array_bounds_p)
- check_all_array_refs ();
-
- /* We must identify jump threading opportunities before we release
- the datastructures built by VRP. */
- identify_jump_threads ();
-
/* Set value range to non pointer SSA_NAMEs. */
for (i = 0; i < num_vr_values; i++)
if (vr_value[i])
vr_value[i]->max);
}
+ substitute_and_fold (op_with_constant_singleton_value_range,
+ vrp_fold_stmt, false);
+
+ if (warn_array_bounds && warn_array_bounds_p)
+ check_all_array_refs ();
+
+ /* We must identify jump threading opportunities before we release
+ the datastructures built by VRP. */
+ identify_jump_threads ();
+
/* Free allocated memory. */
for (i = 0; i < num_vr_values; i++)
if (vr_value[i])