public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-6140] tree-optimization/108816 - vect versioning check split confusion
Date: Mon, 20 Feb 2023 10:56:04 +0000 (GMT)	[thread overview]
Message-ID: <20230220105604.90E543836E96@sourceware.org> (raw)

https://gcc.gnu.org/g:63471c5008819bbf6ec32a6f4d8701fe57b96fa9

commit r13-6140-g63471c5008819bbf6ec32a6f4d8701fe57b96fa9
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 20 10:59:15 2023 +0100

    tree-optimization/108816 - vect versioning check split confusion
    
    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.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr108816.c | 18 ++++++++++++++++++
 gcc/tree-vect-loop-manip.cc             |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr108816.c b/gcc/testsuite/gcc.dg/torture/pr108816.c
new file mode 100644
index 00000000000..4c24d5584c1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108816.c
@@ -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;
+    }
+}
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index c04fcf40c44..6aa3d2ed0bf 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -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);

                 reply	other threads:[~2023-02-20 10:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230220105604.90E543836E96@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).