re PR middle-end/79818 (wrong code with -fwrapv and -Os/-O1/-O2/-O3)
authorRichard Biener <rguenther@suse.de>
Fri, 3 Mar 2017 08:08:08 +0000 (08:08 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 3 Mar 2017 08:08:08 +0000 (08:08 +0000)
2017-03-03  Richard Biener  <rguenther@suse.de>

PR middle-end/79818
* match.pd ( X +- C1 CMP C2 -> X CMP C2 -+ C1): Add missing
TYPE_OVERFLOW_UNDEFINED check.

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

From-SVN: r245860

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr79818.c [new file with mode: 0644]

index c8b375ecf5c00ed6aa7a5c9f60ecf5352fd1f676..73b2f215a791a4aae92e70c8ad1cdf7ab1e0d6f5 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-03  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/79818
+       * match.pd ( X +- C1 CMP C2 -> X CMP C2 -+ C1): Add missing
+       TYPE_OVERFLOW_UNDEFINED check.
+
 2017-03-02  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        * config/rs6000/vector.md (vector_ne_<mode>_p): Correct operand
index 7b9680094730bf793c6a65597184f0d54e0635fa..4e6f7199947719afe443740979dff139372606f2 100644 (file)
@@ -3688,7 +3688,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@0))
        && !TYPE_SATURATING (TREE_TYPE (@0)))
     (with { tree res = int_const_binop (rop, @2, @1); }
-     (if (TREE_OVERFLOW (res))
+     (if (TREE_OVERFLOW (res)
+         && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
       { constant_boolean_node (cmp == NE_EXPR, type); }
       (if (single_use (@3))
        (cmp @0 { res; }))))))))
index b0034ed4facaf9ad853246eadd17d6f7a5649909..e5a08ac0290b1c888e80ddb0be709459551f1c7f 100644 (file)
@@ -1,3 +1,8 @@
+2017-03-03  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/79818
+       * gcc.dg/torture/pr79818.c: New testcase.
+
 2017-03-02  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79782
diff --git a/gcc/testsuite/gcc.dg/torture/pr79818.c b/gcc/testsuite/gcc.dg/torture/pr79818.c
new file mode 100644 (file)
index 0000000..5c12089
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fwrapv" } */
+
+static void __attribute__((noinline,noclone))
+func(void)
+{
+  signed char c = 0;
+
+  for(; c >= 0; c++);
+
+  if(c != -128)
+    __builtin_abort();
+}
+
+int main(int argc, char* argv[])
+{
+  func();
+  return 0;
+}