public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: ams@gcc.gnu.org
Subject: [PATCH] tree-optimization/108888 - call if-conversion
Date: Thu, 23 Feb 2023 11:10:14 +0100 (CET)	[thread overview]
Message-ID: <20230223101014.B2D2E13928@imap2.suse-dmz.suse.de> (raw)

The following makes sure to only predicate calls necessary.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/108888
	* tree-if-conv.cc (if_convertible_stmt_p): Set PLF_2 on
	calls to predicate.
	(predicate_statements): Only predicate calls with PLF_2.

	* g++.dg/torture/pr108888.C: New testcase.
---
 gcc/testsuite/g++.dg/torture/pr108888.C | 18 ++++++++++++++++++
 gcc/tree-if-conv.cc                     | 17 ++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr108888.C

diff --git a/gcc/testsuite/g++.dg/torture/pr108888.C b/gcc/testsuite/g++.dg/torture/pr108888.C
new file mode 100644
index 00000000000..29a22e21102
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr108888.C
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+int scaleValueSaturate_scalefactor, scaleValueSaturate___trans_tmp_2,
+    scaleValuesSaturate_i;
+int scaleValueSaturate(int value) {
+  int result = __builtin_clz(value);
+  if (value)
+    if (-result <= scaleValueSaturate_scalefactor)
+      return 0;
+  return scaleValueSaturate___trans_tmp_2;
+}
+short scaleValuesSaturate_dst;
+short *scaleValuesSaturate_src;
+void scaleValuesSaturate() {
+  for (; scaleValuesSaturate_i; scaleValuesSaturate_i++)
+    scaleValuesSaturate_dst =
+        scaleValueSaturate(scaleValuesSaturate_src[scaleValuesSaturate_i]);
+}
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index a7a8406374d..0e384e36394 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -1099,6 +1099,7 @@ if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
 		   n = n->simdclone->next_clone)
 		if (n->simdclone->inbranch)
 		  {
+		    gimple_set_plf (stmt, GF_PLF_2, true);
 		    need_to_predicate = true;
 		    return true;
 		  }
@@ -2541,7 +2542,8 @@ predicate_statements (loop_p loop)
 	      release_defs (stmt);
 	      continue;
 	    }
-	  else if (gimple_plf (stmt, GF_PLF_2))
+	  else if (gimple_plf (stmt, GF_PLF_2)
+		   && is_gimple_assign (stmt))
 	    {
 	      tree lhs = gimple_assign_lhs (stmt);
 	      tree mask;
@@ -2625,13 +2627,14 @@ predicate_statements (loop_p loop)
 	      gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi));
 	      update_stmt (stmt);
 	    }
-
-	  /* Convert functions that have a SIMD clone to IFN_MASK_CALL.  This
-	     will cause the vectorizer to match the "in branch" clone variants,
-	     and serves to build the mask vector in a natural way.  */
-	  gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
-	  if (call && !gimple_call_internal_p (call))
+	  else if (gimple_plf (stmt, GF_PLF_2)
+		   && is_gimple_call (stmt))
 	    {
+	      /* Convert functions that have a SIMD clone to IFN_MASK_CALL.
+		 This will cause the vectorizer to match the "in branch"
+		 clone variants, and serves to build the mask vector
+		 in a natural way.  */
+	      gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
 	      tree orig_fn = gimple_call_fn (call);
 	      int orig_nargs = gimple_call_num_args (call);
 	      auto_vec<tree> args;
-- 
2.35.3

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 10:10 Richard Biener [this message]
2023-04-05  9:07 ` Andre Vieira (lists)
2023-04-11  8:48   ` Richard Biener

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=20230223101014.B2D2E13928@imap2.suse-dmz.suse.de \
    --to=rguenther@suse.de \
    --cc=ams@gcc.gnu.org \
    --cc=gcc-patches@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).