2016-03-24 Richard Henderson <rth@redhat.com>
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Mar 2016 17:52:11 +0000 (17:52 +0000)
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Mar 2016 17:52:11 +0000 (17:52 +0000)
PR middle-end/69845
* fold-const.c (extract_muldiv_1): Correct test for multiplication
overflow.

PR middle-end/69845
* gcc.dg/tree-ssa/pr69845-1.c: New test.
* gcc.dg/tree-ssa/pr69845-2.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234462 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr69845-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr69845-2.c [new file with mode: 0644]

index 72c3d7d..4a87cda 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-24  Richard Henderson  <rth@redhat.com>
+
+        PR middle-end/69845
+       * fold-const.c (extract_muldiv_1): Correct test for multiplication
+       overflow.
+
 2016-03-24  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.md (*anddi3_doubleword): Generate AND insn
index 9d861c6..44fe2a2 100644 (file)
@@ -6116,11 +6116,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
        {
          tree tem = const_binop (code, fold_convert (ctype, t),
                                  fold_convert (ctype, c));
-         /* If the multiplication overflowed to INT_MIN then we lost sign
-            information on it and a subsequent multiplication might
-            spuriously overflow.  See PR68142.  */
-         if (TREE_OVERFLOW (tem)
-             && wi::eq_p (tem, wi::min_value (TYPE_PRECISION (ctype), SIGNED)))
+         /* If the multiplication overflowed, we lost information on it.
+            See PR68142 and PR69845.  */
+         if (TREE_OVERFLOW (tem))
            return NULL_TREE;
          return tem;
        }
index 78d7ab8..8891090 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-24  Richard Henderson  <rth@redhat.com>
+
+       PR middle-end/69845
+       * gcc.dg/tree-ssa/pr69845-1.c: New test.
+       * gcc.dg/tree-ssa/pr69845-2.c: New test.
+
 2016-03-24  Tom de Vries  <tom@codesourcery.com>
 
        * gfortran.dg/goacc/host_data-tree.f95: Add missing initialization.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69845-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69845-1.c
new file mode 100644 (file)
index 0000000..92927ba
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int32 } */
+/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
+
+int
+main ()
+{
+  struct S { char s; } v;
+  v.s = 47;
+  int a = (int) v.s;
+  int b = (27005061 + (a + 680455));
+  int c = ((1207142401 * (((8 * b) + 9483541) - 230968044)) + 469069442);
+  if (c != 1676211843)
+    __builtin_abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "b \\\* 8" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69845-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69845-2.c
new file mode 100644 (file)
index 0000000..e0b38e9
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int32 } */
+/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
+
+int
+main ()
+{
+  struct S { char s; } v;
+  v.s = 47;
+  unsigned int a = (unsigned int) v.s;
+  unsigned int b = (27005061 + (a + 680455));
+  unsigned int c
+    = ((1207142401u * (((8u * b) + 9483541u) - 230968044u)) + 469069442u);
+  if (c != 1676211843u)
+    __builtin_abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "b \\\* 1067204616" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */