From: Kyrylo Tkachov <Kyrylo.Tkachov@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH][committed] aarch64: Optimise ADDP with same source operands
Date: Tue, 20 Jun 2023 10:03:37 +0000 [thread overview]
Message-ID: <PAXPR08MB6926A4B4D8A9E94A6E96ACEA935CA@PAXPR08MB6926.eurprd08.prod.outlook.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
Hi all,
We've been asked to optimise the testcase in this patch of a 64-bit ADDP with
the low and high halves of the same 128-bit vector. This can be done by a
single .4s ADDP followed by just reading the bottom 64 bits. A splitter for
this is quite straightforward now that all the vec_concat stuff is collapsed
by simplify-rtx.
With this patch we generate a single:
addp v0.4s, v0.4s, v0.4s
instead of:
dup d31, v0.d[1]
addp v0.2s, v0.2s, v31.2s
ret
Bootstrapped and tested on aarch64-none-linux-gnu and aarch64_be-none-elf.
Pushing to trunk.
Thanks,
Kyrill
gcc/ChangeLog:
* config/aarch64/aarch64-simd.md (*aarch64_addp_same_reg<mode>):
New define_insn_and_split.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/simd/addp-same-low_1.c: New test.
[-- Attachment #2: addp-q.patch --]
[-- Type: application/octet-stream, Size: 2303 bytes --]
diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md
index 5622d84cf3781b07e9a4f6780e56aa3f74c194a5..c17f21f688267394df34001c55027e4f1ecc56f3 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -7327,6 +7327,36 @@ (define_insn "aarch64_addp<mode><vczle><vczbe>_insn"
[(set_attr "type" "neon_reduc_add<q>")]
)
+;; A common usecase of 64-bit ADDP is to have both operands come from the same
+;; 128-bit vector and produce the pairwise addition results in the lower half.
+;; Split into the 128-bit ADDP form and extract the low half.
+(define_insn_and_split "*aarch64_addp_same_reg<mode>"
+ [(set (match_operand:<VHALF> 0 "register_operand" "=w")
+ (plus:<VHALF>
+ (vec_select:<VHALF>
+ (match_operand:VQ_I 1 "register_operand" "w")
+ (match_operand:VQ_I 2 "vect_par_cnst_even_or_odd_half"))
+ (vec_select:<VHALF>
+ (match_dup 1)
+ (match_operand:VQ_I 3 "vect_par_cnst_even_or_odd_half"))))]
+ "TARGET_SIMD && !rtx_equal_p (operands[2], operands[3])"
+ "#"
+ "&& 1"
+ [(const_int 0)]
+ {
+ rtx scratch;
+ if (can_create_pseudo_p ())
+ scratch = gen_reg_rtx (<MODE>mode);
+ else
+ scratch = lowpart_subreg (<MODE>mode, operands[0], <VHALF>mode);
+
+ emit_insn (gen_aarch64_addp<mode>_insn (scratch, operands[1], operands[1],
+ operands[2], operands[3]));
+ emit_move_insn (operands[0], gen_lowpart (<VHALF>mode, scratch));
+ DONE;
+ }
+)
+
(define_expand "aarch64_addp<mode>"
[(match_operand:VDQ_I 0 "register_operand")
(match_operand:VDQ_I 1 "register_operand")
diff --git a/gcc/testsuite/gcc.target/aarch64/simd/addp-same-low_1.c b/gcc/testsuite/gcc.target/aarch64/simd/addp-same-low_1.c
new file mode 100644
index 0000000000000000000000000000000000000000..42d8db77f1c91748f543507aa9f1316b242ffd8b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/simd/addp-same-low_1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O" } */
+/* { dg-require-effective-target aarch64_little_endian } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+#include <arm_neon.h>
+
+
+/*
+** foo:
+** addp v0\.4s, v0\.4s, v0\.4s
+** ret
+*/
+
+int32x2_t
+foo (int32x4_t a)
+{
+ return vpadd_s32 (vget_low_s32(a), vget_high_s32(a));
+}
+
reply other threads:[~2023-06-20 10:03 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=PAXPR08MB6926A4B4D8A9E94A6E96ACEA935CA@PAXPR08MB6926.eurprd08.prod.outlook.com \
--to=kyrylo.tkachov@arm.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).