aboutsummaryrefslogtreecommitdiff
path: root/gcc/config
diff options
context:
space:
mode:
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>2022-05-13 22:33:59 +0900
committerMax Filippov <jcmvbkbc@gmail.com>2022-05-26 21:55:01 -0700
commit9aad2b22436d5346fa224e5c14439dcef36cf3dd (patch)
treee6ff7162be5e9985613ebdbe41d859fe692a1613 /gcc/config
parent6454b4a8f5d90dd355c3c7e31a592a439223b645 (diff)
downloadgcc-9aad2b22436d5346fa224e5c14439dcef36cf3dd.zip
gcc-9aad2b22436d5346fa224e5c14439dcef36cf3dd.tar.gz
gcc-9aad2b22436d5346fa224e5c14439dcef36cf3dd.tar.bz2
xtensa: Improve bswap[sd]i2 insn patterns
This patch makes bswap[sd]i2 better register allocation, and reconstructs bswapsi2 in order to take advantage of GIMPLE manual byte-swapping recognition. gcc/ChangeLog: * config/xtensa/xtensa.md (bswapsi2): New expansion pattern. (bswapsi2_internal): Revise the template and condition, and add detection code for preceding the same insn in order to omit a "SSAI 8" instruction of the latter. (bswapdi2): Suppress built-in insn expansion with the corresponding library call when optimizing for size. gcc/testsuite/ChangeLog: * gcc.target/xtensa/bswap.c: Remove test. * gcc.target/xtensa/bswap-O1.c: New. * gcc.target/xtensa/bswap-O2.c: Ditto. * gcc.target/xtensa/bswap-Os.c: Ditto.
Diffstat (limited to 'gcc/config')
-rw-r--r--gcc/config/xtensa/xtensa.md77
1 files changed, 61 insertions, 16 deletions
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 2d146b7..6f5cbc5 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -471,23 +471,68 @@
;; Byte swap.
-(define_insn "bswapsi2"
- [(set (match_operand:SI 0 "register_operand" "=&a")
- (bswap:SI (match_operand:SI 1 "register_operand" "r")))]
- "!optimize_size"
- "ssai\t8\;srli\t%0, %1, 16\;src\t%0, %0, %1\;src\t%0, %0, %0\;src\t%0, %1, %0"
- [(set_attr "type" "arith")
- (set_attr "mode" "SI")
- (set_attr "length" "15")])
+(define_expand "bswapsi2"
+ [(set (match_operand:SI 0 "register_operand" "")
+ (bswap:SI (match_operand:SI 1 "register_operand" "")))]
+ "!optimize_debug && optimize > 1"
+{
+ /* GIMPLE manual byte-swapping recognition is now activated.
+ For both built-in and manual bswaps, emit corresponding library call
+ if optimizing for size, or a series of dedicated machine instructions
+ if otherwise. */
+ if (optimize_size)
+ emit_library_call_value (optab_libfunc (bswap_optab, SImode),
+ operands[0], LCT_NORMAL, SImode,
+ operands[1], SImode);
+ else
+ emit_insn (gen_bswapsi2_internal (operands[0], operands[1]));
+ DONE;
+})
-(define_insn "bswapdi2"
- [(set (match_operand:DI 0 "register_operand" "=&a")
- (bswap:DI (match_operand:DI 1 "register_operand" "r")))]
- "!optimize_size"
- "ssai\t8\;srli\t%0, %D1, 16\;src\t%0, %0, %D1\;src\t%0, %0, %0\;src\t%0, %D1, %0\;srli\t%D0, %1, 16\;src\t%D0, %D0, %1\;src\t%D0, %D0, %D0\;src\t%D0, %1, %D0"
- [(set_attr "type" "arith")
- (set_attr "mode" "DI")
- (set_attr "length" "27")])
+(define_insn "bswapsi2_internal"
+ [(set (match_operand:SI 0 "register_operand" "=a,&a")
+ (bswap:SI (match_operand:SI 1 "register_operand" "0,r")))
+ (clobber (match_scratch:SI 2 "=&a,X"))]
+ "!optimize_debug && optimize > 1 && !optimize_size"
+{
+ rtx_insn *prev_insn = prev_nonnote_nondebug_insn (insn);
+ const char *init = "ssai\t8\;";
+ static char result[64];
+ if (prev_insn && NONJUMP_INSN_P (prev_insn))
+ {
+ rtx x = PATTERN (prev_insn);
+ if (GET_CODE (x) == PARALLEL && XVECLEN (x, 0) == 2
+ && GET_CODE (XVECEXP (x, 0, 0)) == SET
+ && GET_CODE (XVECEXP (x, 0, 1)) == CLOBBER)
+ {
+ x = XEXP (XVECEXP (x, 0, 0), 1);
+ if (GET_CODE (x) == BSWAP && GET_MODE (x) == SImode)
+ init = "";
+ }
+ }
+ sprintf (result,
+ (which_alternative == 0)
+ ? "%s" "srli\t%%2, %%1, 16\;src\t%%2, %%2, %%1\;src\t%%2, %%2, %%2\;src\t%%0, %%1, %%2"
+ : "%s" "srli\t%%0, %%1, 16\;src\t%%0, %%0, %%1\;src\t%%0, %%0, %%0\;src\t%%0, %%1, %%0",
+ init);
+ return result;
+}
+ [(set_attr "type" "arith,arith")
+ (set_attr "mode" "SI")
+ (set_attr "length" "15,15")])
+
+(define_expand "bswapdi2"
+ [(set (match_operand:DI 0 "register_operand" "")
+ (bswap:DI (match_operand:DI 1 "register_operand" "")))]
+ "!optimize_debug && optimize > 1 && optimize_size"
+{
+ /* Replace with a single DImode library call.
+ Without this, two SImode library calls are emitted. */
+ emit_library_call_value (optab_libfunc (bswap_optab, DImode),
+ operands[0], LCT_NORMAL, DImode,
+ operands[1], DImode);
+ DONE;
+})
;; Negation and one's complement.