match.pd: When combining divisions exclude the degenerate case involving INT_MIN...
authorRichard Biener <rguenther@suse.de>
Tue, 2 Dec 2014 13:09:13 +0000 (13:09 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 2 Dec 2014 13:09:13 +0000 (13:09 +0000)
2014-12-02  Richard Biener  <rguenther@suse.de>

* match.pd: When combining divisions exclude the degenerate
case involving INT_MIN from overflow handling.

* gcc.dg/torture/20141202-1.c: New testcase.

From-SVN: r218269

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

index 09a541660c5745ecc35e3dcb9757f142b50e49d7..2bf3bce9b7b916b93fc1704947b0882f27eabe95 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-02  Richard Biener  <rguenther@suse.de>
+
+       * match.pd: When combining divisions exclude the degenerate
+       case involving INT_MIN from overflow handling.
+
 2014-12-02  Wilco Dijkstra  <wilco.dijkstra@arm.com>
 
        * ira-costs.c (scan_one_insn): Improve spill cost adjustment.
index b36aa2fe76a3c67e2e1e916a79e116deb2019d0c..6c225b483d26226eabef41df42f5dc76671fe148 100644 (file)
@@ -140,7 +140,9 @@ along with GCC; see the file COPYING3.  If not see
    }
    (if (!overflow_p)
     (div @0 { wide_int_to_tree (type, mul); }))
-   (if (overflow_p)
+   (if (overflow_p
+        && (TYPE_UNSIGNED (type)
+           || mul != wi::min_value (TYPE_PRECISION (type), SIGNED)))
     { build_zero_cst (type); }))))
 
 /* Optimize A / A to 1.0 if we don't care about
index 1410f10dacf3766c4575f1ddb8085160c2a79328..00da0bdbddec9a528905cb935a5db4f6f34bd536 100644 (file)
@@ -1,3 +1,7 @@
+2014-12-02  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/torture/20141202-1.c: New testcase.
+
 2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ipa/63814
diff --git a/gcc/testsuite/gcc.dg/torture/20141202-1.c b/gcc/testsuite/gcc.dg/torture/20141202-1.c
new file mode 100644 (file)
index 0000000..0ea6369
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+int foo (int x)
+{
+  return (x / 2) / ((-__INT_MAX__ - 1) / -2);
+}
+
+int main()
+{
+  if (foo (- __INT_MAX__ - 1) != -1)
+    abort ();
+  return 0;
+}