public inbox for
 help / color / mirror / Atom feed
From: Robin Dapp <>
To: GCC Patches <>
Subject: [RFC] postreload cse'ing vector constants
Date: Wed, 7 Sep 2022 16:40:02 +0200	[thread overview]
Message-ID: <> (raw)


I recently looked into a sequence like

 vzero %v0
 vlr   %v2, %v0
 vlr   %v3, %v0.

Ideally we would like to use vzero for all of these sets in order to not
create dependencies.

For some instances of this problem I found the offending snippet to be
the postreload cse pass. If there is a non hard reg whose value is
equivalent to an existing hard reg, it will replace the non hard reg.
The costs are only compared if the respective operand is a CONST_INT_P,
otherwise we always replace.

The comment before says:
   /* See if REGNO fits this alternative, and set it up as the

      replacement register if we don't have one for this

      alternative yet and the operand being replaced is not

      a cheap CONST_INT.  */

Now, in my case we have a CONST_VECTOR consisting of CONST_INTS (zeros).
 This is obviously no CONST_INT therefore the substitution takes place
resulting in a "vlr" instead of a "vzero".
Would it not make sense to always compare costs here? Some backends have
instructions for loading vector constants and there could also be
backends able to load floating point constants directly.

For my snippet getting rid of the CONST_INT check suffices because the
costs are similar and no replacement happens.  Was this originally a
shortcut for performance reasons?  I thought we were not checking that
many alternatives and only locally at this point anymore.

Any comments or ideas?



diff --git a/gcc/ b/gcc/
index 41f61d326482..934439733d52 100644
--- a/gcc/
+++ b/gcc/
@@ -558,13 +558,12 @@ reload_cse_simplify_operands (rtx_insn *insn, rtx
                  if (op_alt_regno[i][j] == -1
                      && TEST_BIT (preferred, j)
                      && reg_fits_class_p (testreg, rclass, 0, mode)
-                     && (!CONST_INT_P (recog_data.operand[i])
-                         || (set_src_cost (recog_data.operand[i], mode,
-                                           optimize_bb_for_speed_p
-                                            (BLOCK_FOR_INSN (insn)))
-                             > set_src_cost (testreg, mode,
-                                             optimize_bb_for_speed_p
-                                              (BLOCK_FOR_INSN (insn))))))
+                     && (set_src_cost (recog_data.operand[i], mode,
+                                       optimize_bb_for_speed_p
+                                        (BLOCK_FOR_INSN (insn)))
+                         > set_src_cost (testreg, mode,
+                                         optimize_bb_for_speed_p
+                                          (BLOCK_FOR_INSN (insn)))))
                      op_alt_regno[i][j] = regno;

             reply	other threads:[~2022-09-07 14:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 14:40 Robin Dapp [this message]
2022-09-07 15:06 ` Jeff Law
2022-09-07 15:33   ` Robin Dapp
2022-09-07 15:49     ` Jeff Law
2022-09-08 13:04       ` Robin Dapp
2022-09-27 17:40         ` Robin Dapp
2022-09-27 19:39           ` H.J. Lu
2022-09-28 16:48             ` Robin Dapp
2022-11-03 12:38               ` Robin Dapp
2022-11-20 16:40                 ` Jeff Law

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:

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

  git send-email \ \ \ \

* 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).