]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: don't set range on partial vectors [PR120922]
authorTamar Christina <tamar.christina@arm.com>
Wed, 9 Jul 2025 07:39:35 +0000 (08:39 +0100)
committerTamar Christina <tamar.christina@arm.com>
Wed, 9 Jul 2025 07:40:49 +0000 (08:40 +0100)
Before the change in g:309dbcea2cabb31bde1a65cdfd30bb7f87b170a2 we would never
set a range for constant VF and requires partial vector loops.

I think a range could be set, since I think the number of latch executions is a
ceiling division of TYPE_MAX_VALUE / vf. To account for the partial iteration.

This would also then deal with the ICE cause in the PR where the chosen VF was
much higher than TYPE_MAX_VALUE and that a mask is relied upon to make it safe.

Since the patch was supposed to not change behavior I've added an additional
partial vector check on the const_vf > 0 check to make it explicit that we only
set it on non-partial vectors (alternative would have been to swap the order of
the vf.constant(&const_vf)) check, but that would have hidden the requirement
sneakily.

The second patch adds support for ranges for partial masks.

gcc/ChangeLog:

PR tree-optimization/120922
* tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Don't set range
for partial vectors.

gcc/testsuite/ChangeLog:

PR tree-optimization/120922
* gcc.dg/vect/pr120922.c: New test.

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

diff --git a/gcc/testsuite/gcc.dg/vect/pr120922.c b/gcc/testsuite/gcc.dg/vect/pr120922.c
new file mode 100644 (file)
index 0000000..1a7247a
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-fsigned-char -fno-strict-aliasing -fwrapv" } */
+/* { dg-additional-options "-march=rv64gcv_zvl1024b -mrvv-vector-bits=zvl -mrvv-max-lmul=m8 -O3" { target { riscv_v } } } */
+
+char g;
+unsigned char h;
+int i[9][6];
+int main() {
+  int k[5];
+  if (g)
+    goto l;
+  for (; h <= 5; h++)
+    i[0][h] = *k;
+l:
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "loop vectorized" "vect" { target riscv_v } } } */
index 469694377499d7502e894b3a77e798d4de7fa685..9c58a6a01d7c9c3d97a2f8595b1ea6cff2d653f6 100644 (file)
@@ -2857,7 +2857,9 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, tree niters,
         we set range information to make niters analyzer's life easier.
         Note the number of latch iteration value can be TYPE_MAX_VALUE so
         we have to represent the vector niter TYPE_MAX_VALUE + 1 / vf.  */
-      if (stmts != NULL && const_vf > 0)
+      if (stmts != NULL
+         && const_vf > 0
+         && !LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo))
        {
          if (niters_no_overflow)
            {