re PR tree-optimization/71887 (wrong code (SIGFPE) at -O1 and above on x86_64-linux...
authorRichard Biener <rguenther@suse.de>
Fri, 15 Jul 2016 12:56:17 +0000 (12:56 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 15 Jul 2016 12:56:17 +0000 (12:56 +0000)
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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr71887.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.c

index dc1d9ee987202c06358915d2dcbedc6e804abaec..318baa2041136dac98a9cd6ba4841404096ee7fe 100644 (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>
 
index 939fef3af757ebbdf862baa04329f77c3a3596fc..b4892fcd51518b2dbc01124a4b856dea8fe4f314 100644 (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
diff --git a/gcc/testsuite/gcc.dg/torture/pr71887.c b/gcc/testsuite/gcc.dg/torture/pr71887.c
new file mode 100644 (file)
index 0000000..2df816a
--- /dev/null
@@ -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;
+}
index dd9aa0195fad67aaf902a5c9014c951838a3fe8f..dd3837d0da1e127aceca022ed1f9736299df8e15 100644 (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)))