]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Add ASHIFTRT handling for shrn pattern
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Tue, 6 Jun 2023 22:42:48 +0000 (23:42 +0100)
committerKyrylo Tkachov <kyrylo.tkachov@arm.com>
Fri, 16 Jun 2023 12:52:23 +0000 (13:52 +0100)
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.

gcc/config/aarch64/aarch64-simd.md
gcc/config/aarch64/aarch64.h
gcc/config/aarch64/iterators.md

index bbb54344eb73f1f54877d6a8993a22332e9b9d7d..ce5885e7bb1dce22953fccf3d0df2e5c15b210c4 100644 (file)
   [(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")]
 )
index 801f9ebc57211d09da9ec4b6b0e7c4955b73349a..a01f1ee99d85917941ffba55bc3b4dcac87b41f6 100644 (file)
@@ -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 */
index acc7a3ec46ecd0ec47f4433e086b535fd33d854e..15436c8ef37a07d4cafdd855351cac1a6723f8f9 100644 (file)
 ;; 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")])