]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/108314 - avoid BIT_NOT optimization for extract-last
authorRichard Biener <rguenther@suse.de>
Tue, 10 Jan 2023 09:42:21 +0000 (10:42 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 10 Jan 2023 12:08:35 +0000 (13:08 +0100)
The extract-last reduction internal function expects the then and
else clause as vector and scalar and thus we cannot perform optimization
of the inversion of the condition by swapping the then/else clauses.

PR tree-optimization/108314
* tree-vect-stmts.cc (vectorizable_condition): Do not
perform BIT_NOT_EXPR optimization for EXTRACT_LAST_REDUCTION.

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

gcc/testsuite/gcc.dg/vect/pr108314.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr108314.c b/gcc/testsuite/gcc.dg/vect/pr108314.c
new file mode 100644 (file)
index 0000000..07260e0
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv9-a" { target aarch64-*-* } } */
+
+int x, y, z;
+
+void f(void)
+{
+  int t = 4;
+  for (; x; x++)
+    {
+      if (y)
+       continue;
+      t = 0;
+    }
+  z = t;
+}
index 6ddd41fb4733dfb86db62c1a29f965944c9370bf..eb4ca1f184e374d177eb43d5eb93acf6e6a8fde9 100644 (file)
@@ -10677,7 +10677,8 @@ vectorizable_condition (vec_info *vinfo,
              vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
              if (bitop2 == NOP_EXPR)
                vec_compare = new_temp;
-             else if (bitop2 == BIT_NOT_EXPR)
+             else if (bitop2 == BIT_NOT_EXPR
+                      && reduction_type != EXTRACT_LAST_REDUCTION)
                {
                  /* Instead of doing ~x ? y : z do x ? z : y.  */
                  vec_compare = new_temp;
@@ -10686,9 +10687,13 @@ vectorizable_condition (vec_info *vinfo,
              else
                {
                  vec_compare = make_ssa_name (vec_cmp_type);
-                 new_stmt
-                   = gimple_build_assign (vec_compare, bitop2,
-                                          vec_cond_lhs, new_temp);
+                 if (bitop2 == BIT_NOT_EXPR)
+                   new_stmt
+                     = gimple_build_assign (vec_compare, bitop2, new_temp);
+                 else
+                   new_stmt
+                     = gimple_build_assign (vec_compare, bitop2,
+                                            vec_cond_lhs, new_temp);
                  vect_finish_stmt_generation (vinfo, stmt_info,
                                               new_stmt, gsi);
                }