]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/59014 (wrong code at -Os and above on x86_64-linux...
authorJakub Jelinek <jakub@redhat.com>
Wed, 7 May 2014 16:08:28 +0000 (18:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 7 May 2014 16:08:28 +0000 (18:08 +0200)
Backported from mainline
2013-11-27  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/59014
* gcc.c-torture/execute/pr59014-2.c: New test.

2013-11-26  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/59014
* tree-vrp.c (register_edge_assert_for_1): Don't look
through conversions from non-integral types or through
narrowing conversions.

* gcc.c-torture/execute/pr59014.c: New test.

From-SVN: r210177

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr59014-2.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr59014.c [new file with mode: 0644]
gcc/tree-vrp.c

index 710550042a11f1f6630364f1d5747d8074e0102f..c32f18179fe9e82593435ce174a1794e13f8eedd 100644 (file)
@@ -1,6 +1,13 @@
 2014-05-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/59014
+       * tree-vrp.c (register_edge_assert_for_1): Don't look
+       through conversions from non-integral types or through
+       narrowing conversions.
+
        2013-11-14  Jakub Jelinek  <jakub@redhat.com>
                    Uros Bizjak  <ubizjak@gmail.com>
 
index bc5ef8fe3f3df0ba26ef800420e4e7748069aaa5..4307f7197b1e39e34eca678bda35d63d15cd4d1e 100644 (file)
@@ -1,6 +1,16 @@
 2014-05-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/59014
+       * gcc.c-torture/execute/pr59014-2.c: New test.
+
+       2013-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/59014
+       * gcc.c-torture/execute/pr59014.c: New test.
+
        2013-11-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/59101
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c b/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c
new file mode 100644 (file)
index 0000000..18da005
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/59014 */
+
+__attribute__((noinline, noclone)) long long int
+foo (long long int x, long long int y)
+{
+  if (((int) x | (int) y) != 0)
+    return 6;
+  return x + y;
+}
+
+int
+main ()
+{
+  if (sizeof (long long) == sizeof (int))
+    return 0;
+  int shift_half = sizeof (int) * __CHAR_BIT__ / 2;
+  long long int x = (3LL << shift_half) << shift_half;
+  long long int y = (5LL << shift_half) << shift_half;
+  long long int z = foo (x, y);
+  if (z != ((8LL << shift_half) << shift_half))
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr59014.c b/gcc/testsuite/gcc.c-torture/execute/pr59014.c
new file mode 100644 (file)
index 0000000..10bf81a
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR tree-optimization/59014 */
+
+int a = 2, b, c, d;
+
+int
+foo ()
+{
+  for (;; c++)
+    if ((b > 0) | (a & 1))
+      ;
+    else
+      {
+       d = a;
+       return 0;
+      }
+}
+
+int
+main ()
+{
+  foo ();
+  if (d != 2)
+    __builtin_abort ();
+  return 0;
+}
index a65266c27fad020f2e0d11c7dad71d69812a4485..1bb1775f6979cc6ebf3ef18b8e81a9e7e11a4388 100644 (file)
@@ -4536,9 +4536,13 @@ register_edge_assert_for_1 (tree op, enum tree_code code,
     }
   else if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (op_def)))
     {
-      /* Recurse through the type conversion.  */
-      retval |= register_edge_assert_for_1 (gimple_assign_rhs1 (op_def),
-                                           code, e, bsi);
+      /* Recurse through the type conversion, unless it is a narrowing
+        conversion or conversion from non-integral type.  */
+      tree rhs = gimple_assign_rhs1 (op_def);
+      if (INTEGRAL_TYPE_P (TREE_TYPE (rhs))
+         && (TYPE_PRECISION (TREE_TYPE (rhs))
+             <= TYPE_PRECISION (TREE_TYPE (op))))
+       retval |= register_edge_assert_for_1 (rhs, code, e, bsi);
     }
 
   return retval;