re PR tree-optimization/71887 (wrong code (SIGFPE) at -O1 and above on x86_64-linux-gnu (in both 32-bit and 64-bit modes))

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.

	* gcc.dg/torture/pr71887.c: New testcase.

From-SVN: r238373
This commit is contained in:
Richard Biener 2016-07-15 12:56:17 +00:00 committed by Richard Biener
parent ad611a4c84
commit 9513d5fbca
4 changed files with 32 additions and 4 deletions

View File

@ -1,3 +1,10 @@
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>

View File

@ -1,3 +1,8 @@
2016-07-15 Richard Biener <rguenther@suse.de>
PR tree-optimization/71887
* gcc.dg/torture/pr71887.c: New testcase.
2016-07-15 Jakub Jelinek <jakub@redhat.com>
PR c/71858

View File

@ -0,0 +1,11 @@
/* { dg-do run } */
char a;
int b;
int main ()
{
unsigned char c = a, d = a;
b = d == 0 ? c : c % d;
return 0;
}

View File

@ -812,7 +812,7 @@ neutral_element_p (tree_code code, tree arg, bool right)
/* 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)
{
@ -827,6 +827,8 @@ absorbing_element_p (tree_code code, tree arg, bool right)
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:
@ -836,7 +838,9 @@ absorbing_element_p (tree_code code, tree arg, bool right)
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;
@ -1010,9 +1014,10 @@ value_replacement (basic_block cond_bb, basic_block middle_bb,
&& 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)))