re PR tree-optimization/92324 (ICE in expand_direct_optab_fn, at internal-fn.c:2890)
authorRichard Biener <rguenther@suse.de>
Tue, 5 Nov 2019 11:00:24 +0000 (11:00 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 5 Nov 2019 11:00:24 +0000 (11:00 +0000)
2019-11-05  Richard Biener  <rguenther@suse.de>

PR tree-optimization/92324
* tree-vect-loop.c (check_reduction_path): For MIN/MAX require
all signed or unsigned operations.

* gcc.dg/vect/pr92324-3.c: New testcase.

From-SVN: r277822

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr92324-3.c [new file with mode: 0644]
gcc/tree-vect-loop.c

index cf4b36ff291729db42d45e6193ca24b1471267d3..562b69d1aabd653a5922a26dc7073fc27cac5591 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-05  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/92324
+       * tree-vect-loop.c (check_reduction_path): For MIN/MAX require
+       all signed or unsigned operations.
+
 2019-11-05  Jan Hubicka  <jh@suse.cz>
 
        * hsa-brig.c: Include alloc-pool.h
index 8a12ddc2c3a8dbeca470265995a05c5dee38c3bb..1e372eb4a0f691f1a0c177a8f9c475c1d17cd77c 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-05  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/92324
+       * gcc.dg/vect/pr92324-3.c: New testcase.
+
 2019-11-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/91945
diff --git a/gcc/testsuite/gcc.dg/vect/pr92324-3.c b/gcc/testsuite/gcc.dg/vect/pr92324-3.c
new file mode 100644 (file)
index 0000000..db5c399
--- /dev/null
@@ -0,0 +1,27 @@
+#include "tree-vect.h"
+
+int a[1024];
+unsigned b[1024];
+
+int __attribute__((noipa))
+foo (int n)
+{
+  int res = 0;
+  for (int i = 0; i < n; ++i)
+    {
+      res = res > a[i] ? res : a[i];
+      res = res > b[i] ? res : b[i];
+    }
+  return res;
+}
+
+int main ()
+{
+  check_vect ();
+  b[3] = (unsigned)__INT_MAX__ + 1;
+  if (foo (4) != -__INT_MAX__ - 1)
+    __builtin_abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "vectorized \[1-9\] loops" "vect" } } */
index 4064e9c0ff7cc2dcaeb5512a4cd59b1adc342128..3448b55fa1b14d8796b6bf411611a494e8e85938 100644 (file)
@@ -2740,6 +2740,7 @@ pop:
   /* Check whether the reduction path detected is valid.  */
   bool fail = path.length () == 0;
   bool neg = false;
+  int sign = -1;
   *code = ERROR_MARK;
   for (unsigned i = 1; i < path.length (); ++i)
     {
@@ -2783,12 +2784,22 @@ pop:
                                    TREE_TYPE (gimple_assign_rhs1 (use_stmt))))
        ;
       else if (*code == ERROR_MARK)
-       *code = use_code;
+       {
+         *code = use_code;
+         sign = TYPE_SIGN (TREE_TYPE (gimple_assign_lhs (use_stmt)));
+       }
       else if (use_code != *code)
        {
          fail = true;
          break;
        }
+      else if ((use_code == MIN_EXPR
+               || use_code == MAX_EXPR)
+              && sign != TYPE_SIGN (TREE_TYPE (gimple_assign_lhs (use_stmt))))
+       {
+         fail = true;
+         break;
+       }
     }
   return ! fail && ! neg && *code != ERROR_MARK;
 }