+2017-02-14 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/79408
+ * tree-vrp.c (simplify_div_or_mod_using_ranges): Handle also the
+ case when on TRUNC_MOD_EXPR op0 is INTEGER_CST.
+ (simplify_stmt_using_ranges): Call simplify_div_or_mod_using_ranges
+ also if rhs1 is INTEGER_CST.
+
2017-02-14 Richard Biener <rguenther@suse.de>
PR middle-end/79432
tree val = NULL;
tree op0 = gimple_assign_rhs1 (stmt);
tree op1 = gimple_assign_rhs2 (stmt);
+ tree op0min = NULL_TREE, op0max = NULL_TREE;
tree op1min = op1;
- value_range *vr = get_value_range (op0);
+ value_range *vr = NULL;
+
+ if (TREE_CODE (op0) == INTEGER_CST)
+ {
+ op0min = op0;
+ op0max = op0;
+ }
+ else
+ {
+ vr = get_value_range (op0);
+ if (range_int_cst_p (vr))
+ {
+ op0min = vr->min;
+ op0max = vr->max;
+ }
+ }
if (rhs_code == TRUNC_MOD_EXPR
&& TREE_CODE (op1) == SSA_NAME)
if (rhs_code == TRUNC_MOD_EXPR
&& TREE_CODE (op1min) == INTEGER_CST
&& tree_int_cst_sgn (op1min) == 1
- && range_int_cst_p (vr)
- && tree_int_cst_lt (vr->max, op1min))
+ && op0max
+ && tree_int_cst_lt (op0max, op1min))
{
if (TYPE_UNSIGNED (TREE_TYPE (op0))
- || tree_int_cst_sgn (vr->min) >= 0
+ || tree_int_cst_sgn (op0min) >= 0
|| tree_int_cst_lt (fold_unary (NEGATE_EXPR, TREE_TYPE (op1min), op1min),
- vr->min))
+ op0min))
{
/* If op0 already has the range op0 % op1 has,
then TRUNC_MOD_EXPR won't change anything. */
}
}
+ if (TREE_CODE (op0) != SSA_NAME)
+ return false;
+
if (!integer_pow2p (op1))
{
/* X % -Y can be only optimized into X % Y either if
range. */
case TRUNC_DIV_EXPR:
case TRUNC_MOD_EXPR:
- if (TREE_CODE (rhs1) == SSA_NAME
+ if ((TREE_CODE (rhs1) == SSA_NAME
+ || TREE_CODE (rhs1) == INTEGER_CST)
&& INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
return simplify_div_or_mod_using_ranges (gsi, stmt);
break;