public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kyrylo Tkachov <Kyrylo.Tkachov@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH][3/5] aarch64: Add ASHIFTRT handling for shrn pattern
Date: Fri, 16 Jun 2023 13:07:19 +0000	[thread overview]
Message-ID: <PAXPR08MB69267F15D4B26F9940BF84EE9358A@PAXPR08MB6926.eurprd08.prod.outlook.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]

The first patch in the series has some fallout in the testsuite,
particularly gcc.target/aarch64/shrn-combine-2.c.
Our previous patterns for SHRN matched both
(truncate (ashiftrt (x) (N))) and (truncate (lshiftrt (x) (N))
as these are equivalent for the shift amounts involved.
In our refactoring, however, we mapped shrn to truncate+lshiftrt.

The fix here is to iterate over ashiftrt,lshiftrt in the pattern for it.
However, we don't want to allow ashiftrt for us_truncate or lshiftrt for
ss_truncate from the ALL_TRUNC iterator.

This patch addds a AARCH64_VALID_SHRN_OP helper to gate the valid
combinations of truncations and shifts.

Bootstrapped and tested on aarch64-none-linux-gnu and
aarch64_be-none-elf.

gcc/ChangeLog:

	* config/aarch64/aarch64.h (AARCH64_VALID_SHRN_OP): Define.
	* config/aarch64/aarch64-simd.md
	(*aarch64_<shrn_op>shrn_n<mode>_insn<vczle><vczbe>): Rename to...
	(*aarch64_<shrn_op><shrn_s>shrn_n<mode>_insn<vczle><vczbe>): ... This.
	Use SHIFTRT iterator and add AARCH64_VALID_SHRN_OP to condition.
	* config/aarch64/iterators.md (shrn_s): New code attribute.

[-- Attachment #2: s3.patch --]
[-- Type: application/octet-stream, Size: 3474 bytes --]

commit 207db5d92f9cc533627c6bd5b3ebae9128b49741
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date:   Tue Jun 6 23:42:48 2023 +0100

    aarch64: Add ASHIFTRT handling for shrn pattern
    
    The first patch in the series has some fallout in the testsuite,
    particularly gcc.target/aarch64/shrn-combine-2.c.
    Our previous patterns for SHRN matched both
    (truncate (ashiftrt (x) (N))) and (truncate (lshiftrt (x) (N))
    as these are equivalent for the shift amounts involved.
    In our refactoring, however, we mapped shrn to truncate+lshiftrt.
    
    The fix here is to iterate over ashiftrt,lshiftrt in the pattern for it.
    However, we don't want to allow ashiftrt for us_truncate or lshiftrt for
    ss_truncate from the ALL_TRUNC iterator.
    
    This patch addds a AARCH64_VALID_SHRN_OP helper to gate the valid
    combinations of truncations and shifts.
    
    Bootstrapped and tested on aarch64-none-linux-gnu and
    aarch64_be-none-elf.
    
    gcc/ChangeLog:
    
            * config/aarch64/aarch64.h (AARCH64_VALID_SHRN_OP): Define.
            * config/aarch64/aarch64-simd.md
            (*aarch64_<shrn_op>shrn_n<mode>_insn<vczle><vczbe>): Rename to...
            (*aarch64_<shrn_op><shrn_s>shrn_n<mode>_insn<vczle><vczbe>): ... This.
            Use SHIFTRT iterator and add AARCH64_VALID_SHRN_OP to condition.
            * config/aarch64/iterators.md (shrn_s): New code attribute.

diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md
index bbb54344eb7..ce5885e7bb1 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -6665,13 +6665,13 @@ (define_insn "aarch64_<shrn_op>shrn_n<mode>"
   [(set_attr "type" "neon_shift_imm_narrow_q")]
 )
 
-(define_insn "*aarch64_<shrn_op>shrn_n<mode>_insn<vczle><vczbe>"
+(define_insn "*aarch64_<shrn_op><shrn_s>shrn_n<mode>_insn<vczle><vczbe>"
   [(set (match_operand:<VNARROWQ> 0 "register_operand" "=w")
 	(ALL_TRUNC:<VNARROWQ>
-	  (<TRUNC_SHIFT>:VQN
+	  (SHIFTRT:VQN
 	    (match_operand:VQN 1 "register_operand" "w")
 	    (match_operand:VQN 2 "aarch64_simd_shift_imm_vec_<vn_mode>"))))]
-  "TARGET_SIMD"
+  "TARGET_SIMD && AARCH64_VALID_SHRN_OP (<ALL_TRUNC:CODE>, <SHIFTRT:CODE>)"
   "<shrn_op>shrn\t%<vn2>0<Vmntype>, %<v>1<Vmtype>, %2"
   [(set_attr "type" "neon_shift_imm_narrow_q")]
 )
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 801f9ebc572..a01f1ee99d8 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -1297,4 +1297,9 @@ extern poly_uint16 aarch64_sve_vg;
 #define REG_ALLOC_ORDER {}
 #define ADJUST_REG_ALLOC_ORDER aarch64_adjust_reg_alloc_order ()
 
+#define AARCH64_VALID_SHRN_OP(T,S)			\
+((T) == TRUNCATE					\
+ || ((T) == US_TRUNCATE && (S) == LSHIFTRT)		\
+ || ((T) == SS_TRUNCATE && (S) == ASHIFTRT))
+
 #endif /* GCC_AARCH64_H */
diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md
index acc7a3ec46e..15436c8ef37 100644
--- a/gcc/config/aarch64/iterators.md
+++ b/gcc/config/aarch64/iterators.md
@@ -2398,6 +2398,8 @@ (define_code_attr sra_op [(ashiftrt "s") (lshiftrt "u")])
 ;; op prefix for shift right and narrow.
 (define_code_attr srn_op [(ashiftrt "r") (lshiftrt "")])
 
+(define_code_attr shrn_s [(ashiftrt "s") (lshiftrt "")])
+
 ;; Map shift operators onto underlying bit-field instructions
 (define_code_attr bfshift [(ashift "ubfiz") (ashiftrt "sbfx")
 			   (lshiftrt "ubfx") (rotatert "extr")])

                 reply	other threads:[~2023-06-16 13:07 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=PAXPR08MB69267F15D4B26F9940BF84EE9358A@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).