public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Robin Dapp <rdapp@linux.ibm.com>
To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com
Subject: [PATCH v3 7/7] ifcvt: Run second pass if it is possible to omit a temporary.
Date: Mon,  6 Dec 2021 19:43:52 +0100	[thread overview]
Message-ID: <20211206184352.42264-8-rdapp@linux.ibm.com> (raw)
In-Reply-To: <20211206184352.42264-1-rdapp@linux.ibm.com>

If one of the to-be-converted SETs requires the original comparison
(i.e. in order to generate a min/max insn) but no other insn after it
does, we can omit creating temporaries, thus facilitating costing.
---
 gcc/ifcvt.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index d1e7db1ee27..3be5bb131df 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -3262,6 +3262,11 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
 
   need_cmov_or_rewire (then_bb, &need_no_cmov, &rewired_src);
 
+  int last_needs_comparison = -1;
+  bool second_try = false;
+
+restart:
+
   FOR_BB_INSNS (then_bb, insn)
     {
       /* Skip over non-insns.  */
@@ -3305,8 +3310,12 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
 	 Therefore we introduce a temporary every time we are about to
 	 overwrite a variable used in the check.  Costing of a sequence with
 	 these is going to be inaccurate so only use temporaries when
-	 needed.  */
-      if (reg_overlap_mentioned_p (target, cond))
+	 needed.
+
+	 If performing a second try, we know how many insns require a
+	 temporary.  For the last of these, we can omit creating one.  */
+      if (reg_overlap_mentioned_p (target, cond)
+	  && (!second_try || count < last_needs_comparison))
 	temp = gen_reg_rtx (GET_MODE (target));
       else
 	temp = target;
@@ -3389,6 +3398,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
 	{
 	  seq = seq1;
 	  temp_dest = temp_dest1;
+	  if (!second_try)
+	    last_needs_comparison = count;
 	}
       else if (seq2 != NULL_RTX)
 	{
@@ -3412,6 +3423,24 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
       unmodified_insns.safe_push (insn);
     }
 
+    /* If there are insns that overwrite part of the initial
+       comparison, we can still omit creating temporaries for
+       the last of them.
+       As the second try will always create a less expensive,
+       valid sequence, we do not need to compare and can discard
+       the first one.  */
+    if (!second_try && last_needs_comparison >= 0)
+      {
+	end_sequence ();
+	start_sequence ();
+	count = 0;
+	targets.truncate (0);
+	temporaries.truncate (0);
+	unmodified_insns.truncate (0);
+	second_try = true;
+	goto restart;
+      }
+
   /* We must have seen some sort of insn to insert, otherwise we were
      given an empty BB to convert, and we can't handle that.  */
   gcc_assert (!unmodified_insns.is_empty ());
-- 
2.31.1


  parent reply	other threads:[~2021-12-06 18:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 18:43 [PATCH v3 0/7] ifcvt: Convert multiple Robin Dapp
2021-12-06 18:43 ` [PATCH v3 1/7] ifcvt: Check if cmovs are needed Robin Dapp
2021-12-09  1:26   ` Jeff Law
2022-01-10 11:17     ` Robin Dapp
2021-12-06 18:43 ` [PATCH v3 2/7] ifcvt: Allow constants for noce_convert_multiple Robin Dapp
2021-12-08 23:51   ` Jeff Law
2022-01-10 11:17     ` Robin Dapp
2021-12-06 18:43 ` [PATCH v3 3/7] ifcvt: Improve costs handling " Robin Dapp
2021-12-08 23:54   ` Jeff Law
2022-01-10 11:17     ` Robin Dapp
2021-12-06 18:43 ` [PATCH v3 4/7] ifcvt/optabs: Allow using a CC comparison for emit_conditional_move Robin Dapp
2021-12-09  0:11   ` Jeff Law
2021-12-09 17:20     ` Robin Dapp
2021-12-09 17:34       ` Jeff Law
2022-01-10 11:18     ` Robin Dapp
2021-12-06 18:43 ` [PATCH v3 5/7] ifcvt: Try re-using CC for conditional moves Robin Dapp
2021-12-09  1:18   ` Jeff Law
2022-01-10 11:18     ` Robin Dapp
2021-12-06 18:43 ` [PATCH v3 6/7] testsuite/s390: Add tests for noce_convert_multiple Robin Dapp
2021-12-08 23:48   ` Jeff Law
2022-01-10 11:18     ` Robin Dapp
2021-12-06 18:43 ` Robin Dapp [this message]
2021-12-09  1:24   ` [PATCH v3 7/7] ifcvt: Run second pass if it is possible to omit a temporary Jeff Law
2021-12-10 15:06     ` Robin Dapp
2021-12-15 20:24       ` Jeff Law
2022-01-10 11:18     ` Robin Dapp

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=20211206184352.42264-8-rdapp@linux.ibm.com \
    --to=rdapp@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.sandiford@arm.com \
    /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).