diff options
-rw-r--r-- | gcc/config/riscv/bitmanip.md | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/zbs-bexti.c | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index fb062f6..0dd6ebb 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -429,3 +429,16 @@ (const_int 1) (match_dup 2))) (set (match_dup 0) (xor:X (match_dup 0) (const_int 1)))]) + +;; We can create a polarity-reversed mask (i.e. bit N -> { set = 0, clear = -1 }) +;; using a bext(i) followed by an addi instruction. +;; This splits the canonical representation of "(a & (1 << BIT_NO)) ? 0 : -1". +(define_split + [(set (match_operand:GPR 0 "register_operand") + (neg:GPR (eq:GPR (zero_extract:GPR (match_operand:GPR 1 "register_operand") + (const_int 1) + (match_operand 2)) + (const_int 0))))] + "TARGET_ZBS" + [(set (match_dup 0) (zero_extract:GPR (match_dup 1) (const_int 1) (match_dup 2))) + (set (match_dup 0) (plus:GPR (match_dup 0) (const_int -1)))]) diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bexti.c b/gcc/testsuite/gcc.target/riscv/zbs-bexti.c index c15098e..d7a8963 100644 --- a/gcc/testsuite/gcc.target/riscv/zbs-bexti.c +++ b/gcc/testsuite/gcc.target/riscv/zbs-bexti.c @@ -26,6 +26,6 @@ long bexti64_4(long a, char bitno) } /* { dg-final { scan-assembler-times "bexti\t" 4 } } */ -/* { dg-final { scan-assembler-times "xori\t|snez\t" 1 } } */ +/* { dg-final { scan-assembler-times "xori\t" 1 } } */ /* { dg-final { scan-assembler-times "addi\t" 1 } } */ /* { dg-final { scan-assembler-times "neg\t" 1 } } */ |