+2016-07-15 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/71887
+ * tree-ssa-phiopt.c (absorbing_element_p): Add rhs arg and
+ verify it is not zero for division / modulo handling.
+ (value_replacement): Adjust.
+
2016-07-15 Virendra Pathak <virendra.pathak@broadcom.com>
Julian Brown <julian@codesourcery.com>
/* Returns true if ARG is an absorbing element for operation CODE. */
static bool
-absorbing_element_p (tree_code code, tree arg, bool right)
+absorbing_element_p (tree_code code, tree arg, bool right, tree rval)
{
switch (code)
{
case RSHIFT_EXPR:
case LROTATE_EXPR:
case RROTATE_EXPR:
+ return !right && integer_zerop (arg);
+
case TRUNC_DIV_EXPR:
case CEIL_DIV_EXPR:
case FLOOR_DIV_EXPR:
case CEIL_MOD_EXPR:
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
- return !right && integer_zerop (arg);
+ return (!right
+ && integer_zerop (arg)
+ && tree_single_nonzero_warnv_p (rval, NULL));
default:
return false;
&& neutral_element_p (code_def, cond_rhs, false))
|| (operand_equal_for_phi_arg_p (arg1, cond_rhs)
&& ((operand_equal_for_phi_arg_p (rhs2, cond_lhs)
- && absorbing_element_p (code_def, cond_rhs, true))
+ && absorbing_element_p (code_def, cond_rhs, true, rhs2))
|| (operand_equal_for_phi_arg_p (rhs1, cond_lhs)
- && absorbing_element_p (code_def, cond_rhs, false))))))
+ && absorbing_element_p (code_def,
+ cond_rhs, false, rhs2))))))
{
gsi = gsi_for_stmt (cond);
if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))