From: Serval Martinot-Lagarde <serval.martinot-lagarde@sipearl.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: Etienne Renault <etienne.renault@sipearl.com>
Subject: [PATCH] aarch64: remove useless pairs of rev instructions
Date: Tue, 18 Jul 2023 09:50:18 +0000 [thread overview]
Message-ID: <c1412ccb5be14216ace46eb46cee29ab@ex13mbxc01n01.ikhex.ikoula.com> (raw)
SVE generates superflous rev instructions that can be replaced
by single mov instruction or a pair of (rev, mov) instructions
gcc/
* config/aarch64/aarch64-sve.md: New peephole2.
* testsuite/gcc.target/aarch64/sve/revrev.c: New dg test.
Signed-off-by: Serval Martinot-Lagarde <serval.martinot-lagarde@sipearl.com>
---
gcc/config/aarch64/aarch64-sve.md | 21 +++++++++++++++++++
gcc/testsuite/gcc.target/aarch64/sve/revrev.c | 13 ++++++++++++
2 files changed, 34 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/revrev.c
diff --git a/gcc/config/aarch64/aarch64-sve.md b/gcc/config/aarch64/aarch64-sve.md
index da5534c3e32..e5e0c7ddfc5 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -8836,6 +8836,27 @@
"TARGET_SVE"
"rev\t%0.<Vctype>, %1.<Vctype>")
+(define_peephole2
+ [(set (match_operand:SVE_ALL 0 "register_operand" "")
+ (unspec:SVE_ALL
+ [(match_operand:SVE_ALL 1 "register_operand" "")] UNSPEC_REV))
+ (set (match_operand:SVE_ALL 2 "register_operand" "")
+ (unspec:SVE_ALL
+ [(match_dup 0)] UNSPEC_REV))]
+ "TARGET_SVE"
+ [(const_int 0)]
+ {
+ if (REGNO (operands[2]) != REGNO (operands[0]))
+ {
+ emit_insn (gen_rtx_SET (operands[2], operands[1]));
+ rtx rev = gen_rtx_UNSPEC (<MODE>mode, gen_rtvec (1, operands[1]), UNSPEC_REV);
+ emit_insn (gen_rtx_SET (operands[0], rev));
+ }
+ else
+ emit_insn (gen_rtx_SET (operands[0], operands[1]));
+ DONE;
+ })
+
;; -------------------------------------------------------------------------
;; ---- [INT,FP] Special-purpose binary permutes
;; -------------------------------------------------------------------------
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/revrev.c b/gcc/testsuite/gcc.target/aarch64/sve/revrev.c
new file mode 100644
index 00000000000..04af6eed291
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/revrev.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+#include <stdint.h>
+
+void
+test (uint8_t a[], uint8_t b[], uint64_t N)
+{
+ for (uint64_t i = N; i > 0; i--)
+ a[i - 1] = b[i - 1];
+}
+
+/* { dg-final { scan-assembler-not {\trev\t(z[0-9]+\.h), \1\n\trev\t\1, \1\n} } } */
--
2.21.0
next reply other threads:[~2023-07-18 9:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 9:50 Serval Martinot-Lagarde [this message]
2023-07-18 10:53 ` Prathamesh Kulkarni
2023-07-18 13:38 ` Serval Martinot-Lagarde
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=c1412ccb5be14216ace46eb46cee29ab@ex13mbxc01n01.ikhex.ikoula.com \
--to=serval.martinot-lagarde@sipearl.com \
--cc=etienne.renault@sipearl.com \
--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).