]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const: Fix division folding with vector operands [PR94412]
authorJakub Jelinek <jakub@redhat.com>
Tue, 31 Mar 2020 09:06:43 +0000 (11:06 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 7 Apr 2020 19:00:35 +0000 (21:00 +0200)
The following testcase is miscompiled since 4.9, we treat unsigned
vector types as if they were signed and "optimize" negations across it.

2020-03-31  Marc Glisse  <marc.glisse@inria.fr>
    Jakub Jelinek  <jakub@redhat.com>

PR middle-end/94412
* fold-const.c (fold_binary_loc) <case TRUNC_DIV_EXPR>: Use
ANY_INTEGRAL_TYPE_P instead of INTEGRAL_TYPE_P.

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

Co-authored-by: Marc Glisse <marc.glisse@inria.fr>
gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr94412.c [new file with mode: 0644]

index ed82d0694b83aa69702481d0b8adb2e756139932..e3e5d86275be5486ece48c7a0a3fc5fb1435ec98 100644 (file)
@@ -1,6 +1,15 @@
 2020-04-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2020-03-31  Marc Glisse  <marc.glisse@inria.fr>
+                   Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/94412
+       * fold-const.c (fold_binary_loc) <case TRUNC_DIV_EXPR>: Use
+       ANY_INTEGRAL_TYPE_P instead of INTEGRAL_TYPE_P.
+
+2020-04-07  Jakub Jelinek  <jakub@redhat.com>
+
        2020-03-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/93069
index c717f24501e376ba7afd94946158287f02fd5117..64273c1c6bc5e64b68cdead36095d89a450e9950 100644 (file)
@@ -10376,11 +10376,11 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 
       /* Convert -A / -B to A / B when the type is signed and overflow is
         undefined.  */
-      if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
+      if ((!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
          && TREE_CODE (op0) == NEGATE_EXPR
          && negate_expr_p (op1))
        {
-         if (INTEGRAL_TYPE_P (type))
+         if (ANY_INTEGRAL_TYPE_P (type))
            fold_overflow_warning (("assuming signed overflow does not occur "
                                    "when distributing negation across "
                                    "division"),
@@ -10390,11 +10390,11 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
                                                    TREE_OPERAND (arg0, 0)),
                                  negate_expr (op1));
        }
-      if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
+      if ((!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
          && TREE_CODE (arg1) == NEGATE_EXPR
          && negate_expr_p (op0))
        {
-         if (INTEGRAL_TYPE_P (type))
+         if (ANY_INTEGRAL_TYPE_P (type))
            fold_overflow_warning (("assuming signed overflow does not occur "
                                    "when distributing negation across "
                                    "division"),
index c32e6a86b8baadb01c5e88de5617980adb0d94bd..0c09c9ee12f77092e5c9ad6ea09631c8c6ee3580 100644 (file)
@@ -1,6 +1,11 @@
 2020-04-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2020-03-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/94412
+       * gcc.c-torture/execute/pr94412.c: New test.
+
        2020-03-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/94385
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr94412.c b/gcc/testsuite/gcc.c-torture/execute/pr94412.c
new file mode 100644 (file)
index 0000000..6c806bb
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR middle-end/94412 */
+
+typedef unsigned V __attribute__ ((__vector_size__ (sizeof (unsigned) * 2)));
+
+void
+foo (V *v, V *w)
+{
+  *w = -*v / 11;
+}
+
+void
+bar (V *v, V *w)
+{
+  *w = -18 / -*v;
+}
+
+int
+main ()
+{
+  V a = (V) { 1, 0 };
+  V b = (V) { 3, __INT_MAX__ };
+  V c, d;
+  foo (&a, &c);
+  bar (&b, &d);
+  if (c[0] != -1U / 11 || c[1] != 0 || d[0] != 0 || d[1] != -18U / -__INT_MAX__)
+    __builtin_abort ();
+  return 0;
+}