]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/108724 - vectorized code getting piecewise expanded
authorRichard Biener <rguenther@suse.de>
Fri, 10 Feb 2023 10:07:30 +0000 (11:07 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 15 Mar 2023 09:07:42 +0000 (10:07 +0100)
This fixes an oversight to when removing the hard limits on using
generic vectors for the vectorizer to enable both SLP and BB
vectorization to use those.  The vectorizer relies on vector lowering
to expand plus, minus and negate to bit operations but vector
lowering has a hard limit on the minimum number of elements per
work item.  Vectorizer costs for the testcase at hand work out
to vectorize a loop with just two work items per vector and that
causes element wise expansion and spilling.

The fix for now is to re-instantiate the hard limit, matching what
vector lowering does.  For the future the way to go is to emit the
lowered sequence directly from the vectorizer instead.

PR tree-optimization/108724
* tree-vect-stmts.cc (vectorizable_operation): Avoid
using word_mode vectors when vector lowering will
decompose them to elementwise operations.

* gcc.target/i386/pr108724.c: New testcase.

(cherry picked from commit dc87e1391c55c666c7ff39d4f0dea87666f25468)

gcc/testsuite/gcc.target/i386/pr108724.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.target/i386/pr108724.c b/gcc/testsuite/gcc.target/i386/pr108724.c
new file mode 100644 (file)
index 0000000..c4e0e91
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mno-sse" } */
+
+int a[16], b[16], c[16];
+void foo()
+{
+  for (int i = 0; i < 16; i++) {
+    a[i] = b[i] + c[i];
+  }
+}
+
+/* When this is vectorized this shouldn't be expanded piecewise again
+   which will result in spilling for the upper half access.  */
+
+/* { dg-final { scan-assembler-not "\\\[er\\\]sp" } } */
index 2498948fad2c59f729a3b7a9279fda2386ef831d..1cc3e00f0a6bdaf8d7e5e8b9596a3ffd11f0ae08 100644 (file)
@@ -6274,6 +6274,20 @@ vectorizable_operation (vec_info *vinfo,
       return false;
     }
 
+  /* ???  We should instead expand the operations here, instead of
+     relying on vector lowering which has this hard cap on the number
+     of vector elements below it performs elementwise operations.  */
+  if (using_emulated_vectors_p
+      && (code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
+      && ((BITS_PER_WORD / vector_element_bits (vectype)) < 4
+         || maybe_lt (nunits_out, 4U)))
+    {
+      if (dump_enabled_p ())
+       dump_printf (MSG_NOTE, "not using word mode for +- and less than "
+                    "four vector elements\n");
+      return false;
+    }
+
   int reduc_idx = STMT_VINFO_REDUC_IDX (stmt_info);
   vec_loop_masks *masks = (loop_vinfo ? &LOOP_VINFO_MASKS (loop_vinfo) : NULL);
   internal_fn cond_fn = get_conditional_internal_fn (code);
This page took 0.090438 seconds and 5 git commands to generate.