From: Richard Biener Date: Fri, 15 Jul 2016 12:56:17 +0000 (+0000) Subject: re PR tree-optimization/71887 (wrong code (SIGFPE) at -O1 and above on x86_64-linux... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9513d5fbcabaf84b5e8450e8bb16894b3d42ba96;p=gcc.git 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 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dc1d9ee9872..318baa20411 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-07-15 Richard Biener + + 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 Julian Brown diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 939fef3af75..b4892fcd515 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-07-15 Richard Biener + + PR tree-optimization/71887 + * gcc.dg/torture/pr71887.c: New testcase. + 2016-07-15 Jakub Jelinek PR c/71858 diff --git a/gcc/testsuite/gcc.dg/torture/pr71887.c b/gcc/testsuite/gcc.dg/torture/pr71887.c new file mode 100644 index 00000000000..2df816ae934 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr71887.c @@ -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; +} diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index dd9aa0195fa..dd3837d0da1 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -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)))