]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/111764 - wrong reduction vectorization
authorRichard Biener <rguenther@suse.de>
Thu, 12 Oct 2023 07:09:46 +0000 (09:09 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 15 Dec 2023 12:17:33 +0000 (13:17 +0100)
The following removes a misguided attempt to allow x + x in a reduction
path, also allowing x * x which isn't valid.  x + x actually never
arrives this way but instead is canonicalized to 2 * x.  This makes
reduction path handling consistent with how we handle the single-stmt
reduction case.

PR tree-optimization/111764
* tree-vect-loop.c (check_reduction_path): Remove the attempt
to allow x + x via special-casing of assigns.

* gcc.dg/vect/pr111764.c: New testcase.

(cherry picked from commit 05f98310b54da95e468d799f4a910174320cccbb)

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

diff --git a/gcc/testsuite/gcc.dg/vect/pr111764.c b/gcc/testsuite/gcc.dg/vect/pr111764.c
new file mode 100644 (file)
index 0000000..f4e110f
--- /dev/null
@@ -0,0 +1,16 @@
+#include "tree-vect.h"
+
+short b = 2;
+
+int main()
+{
+  check_vect ();
+
+  for (int a = 1; a <= 9; a++)
+    b = b * b;
+  if (b != 0)
+    __builtin_abort ();
+
+  return 0;
+}
+
index 2f2346a366edb536e3139e28dd9f7c82864f1acb..76580c1e3dd7255a9dd9a0f5c83d039f31836aba 100644 (file)
@@ -3466,24 +3466,15 @@ pop:
         ???  We could relax this and handle arbitrary live stmts by
         forcing a scalar epilogue for example.  */
       imm_use_iterator imm_iter;
+      use_operand_p use_p;
       gimple *op_use_stmt;
       unsigned cnt = 0;
       FOR_EACH_IMM_USE_STMT (op_use_stmt, imm_iter, op)
        if (!is_gimple_debug (op_use_stmt)
            && (*code != ERROR_MARK
                || flow_bb_inside_loop_p (loop, gimple_bb (op_use_stmt))))
-         {
-           /* We want to allow x + x but not x < 1 ? x : 2.  */
-           if (is_gimple_assign (op_use_stmt)
-               && gimple_assign_rhs_code (op_use_stmt) == COND_EXPR)
-             {
-               use_operand_p use_p;
-               FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
-                 cnt++;
-             }
-           else
-             cnt++;
-         }
+         FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+           cnt++;
       if (cnt != 1)
        {
          fail = true;