]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/108816 - vect versioning check split confusion
authorRichard Biener <rguenther@suse.de>
Mon, 20 Feb 2023 09:59:15 +0000 (10:59 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 20 Feb 2023 10:55:55 +0000 (11:55 +0100)
The split of the versioning condition assumes the definition is
in the condition block which is ensured by the versioning code.
But that only works when we actually have to insert any statements
for the versioning condition.  The following adjusts the guard
accordingly and asserts this condition.

PR tree-optimization/108816
* tree-vect-loop-manip.cc (vect_loop_versioning): Adjust
versioning condition split prerequesite, assert required
invariant.

* gcc.dg/torture/pr108816.c: New testcase.

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr108816.c b/gcc/testsuite/gcc.dg/torture/pr108816.c
new file mode 100644 (file)
index 0000000..4c24d55
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fvect-cost-model=dynamic" } */
+
+int m;
+
+void
+foo (int p[][16], unsigned int x)
+{
+  while (x < 4)
+    {
+      int j;
+
+      for (j = x * 4; j < (x + 1) * 4 - 2; j++)
+        p[0][j] = p[m][j];
+
+      ++x;
+    }
+}
index c04fcf40c44ec06f1149174d131c89981fc5e366..6aa3d2ed0bf87a61815e06c3168bfb0561630b33 100644 (file)
@@ -3477,7 +3477,7 @@ vect_loop_versioning (loop_vec_info loop_vinfo,
   tree cost_name = NULL_TREE;
   profile_probability prob2 = profile_probability::uninitialized ();
   if (cond_expr
-      && !integer_truep (cond_expr)
+      && EXPR_P (cond_expr)
       && (version_niter
          || version_align
          || version_alias
@@ -3711,6 +3711,7 @@ vect_loop_versioning (loop_vec_info loop_vinfo,
   if (cost_name && TREE_CODE (cost_name) == SSA_NAME)
     {
       gimple *def = SSA_NAME_DEF_STMT (cost_name);
+      gcc_assert (gimple_bb (def) == condition_bb);
       /* All uses of the cost check are 'true' after the check we
         are going to insert.  */
       replace_uses_by (cost_name, boolean_true_node);