aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorLin Sinan <mynameisxiaou@gmail.com>2023-04-11 10:23:19 -0600
committerJeff Law <jlaw@ventanamicro>2023-04-11 10:26:59 -0600
commit0c5e64c4249322a178e1a0e843874e4d6b43b992 (patch)
tree901d215d9f283ce9c1d30d191d2e0b094d15de6e /gcc
parent40fc8e3d4f600d89e6b065d6f12db7a816269c8f (diff)
downloadgcc-0c5e64c4249322a178e1a0e843874e4d6b43b992.zip
gcc-0c5e64c4249322a178e1a0e843874e4d6b43b992.tar.gz
gcc-0c5e64c4249322a178e1a0e843874e4d6b43b992.tar.bz2
RISC-V: avoid splitting small constant in <or_optab>i<mode>_extrabit pattern
there is no need to split an xori/ori with an small constant. take the test case `int foo(int idx) { return idx|3; }` as an example, rv64im_zba generates: ori a0,a0,3 ret but, rv64im_zba_zbs generates: ori a0,a0,1 ori a0,a0,2 ret with this change, insn `ori r2,r1,3` will not be splitted in zbs. gcc/ * config/riscv/predicates.md (uimm_extra_bit_or_twobits): Adjust predicate to avoid splitting arith constants. gcc/testsuite * gcc.target/riscv/zbs-extra-bit-or-twobits.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/riscv/predicates.md2
-rw-r--r--gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c14
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md
index 0d9d770..8654dbc 100644
--- a/gcc/config/riscv/predicates.md
+++ b/gcc/config/riscv/predicates.md
@@ -399,7 +399,7 @@
(define_predicate "uimm_extra_bit_or_twobits"
(and (match_code "const_int")
(ior (match_operand 0 "uimm_extra_bit_operand")
- (match_operand 0 "const_twobits_operand"))))
+ (match_operand 0 "const_twobits_not_arith_operand"))))
;; A CONST_INT operand that fits into the negative half of a
;; signed-immediate after a single cleared top bit has been
diff --git a/gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c b/gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c
new file mode 100644
index 0000000..ef7ed60
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+int or_two_bit(int idx) {
+ return idx|3;
+}
+
+int xor_two_bit(int idx) {
+ return idx^3;
+}
+
+/* { dg-final { scan-assembler-times "\tori\t" 1 } } */
+/* { dg-final { scan-assembler-times "\txori\t" 1 } } */