diff options
author | Jivan Hakobyan <jivanhakobyan9@gmail.com> | 2023-05-17 13:00:28 -0600 |
---|---|---|
committer | Jeff Law <jlaw@ventanamicro.com> | 2023-05-17 13:04:35 -0600 |
commit | 6da6ed95c9ca247d405da3dfb737b743686fe5e6 (patch) | |
tree | bbe8b754bd425be1b1f8e0451187f1b6d758fe61 /gcc/config/riscv/riscv.md | |
parent | 98827c53ed38886795b1f479c1d997fd89011c38 (diff) | |
download | gcc-6da6ed95c9ca247d405da3dfb737b743686fe5e6.zip gcc-6da6ed95c9ca247d405da3dfb737b743686fe5e6.tar.gz gcc-6da6ed95c9ca247d405da3dfb737b743686fe5e6.tar.bz2 |
RISC-V: Remove masking third operand of rotate instructions
Rotate instructions do not need to mask the third operand.
For example, RV64 the following code:
unsigned long foo1(unsigned long rs1, unsigned long rs2)
{
long shamt = rs2 & (64 - 1);
return (rs1 << shamt) | (rs1 >> ((64 - shamt) & (64 - 1)));
}
Compiles to:
foo1:
andi a1,a1,63
rol a0,a0,a1
ret
This patch removes unnecessary masking.
Besides, I have merged masking insns for shifts that were written before.
gcc/ChangeLog:
* config/riscv/riscv.md (*<optab><GPR:mode>3_mask): New pattern,
combined from ...
(*<optab>si3_mask, *<optab>di3_mask): Here.
(*<optab>si3_mask_1, *<optab>di3_mask_1): And here.
* config/riscv/bitmanip.md (*<bitmanip_optab><GPR:mode>3_mask): New
pattern.
(*<bitmanip_optab>si3_sext_mask): Likewise.
* config/riscv/iterators.md (shiftm1): Use const_si_mask_operand
and const_di_mask_operand.
(bitmanip_rotate): New iterator.
(bitmanip_optab): Add rotates.
* config/riscv/predicates.md (const_si_mask_operand): Renamed
from const31_operand. Generalize to handle more mask constants.
(const_di_mask_operand): Similarly.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/shift-and-2.c: Fixed test
* gcc.target/riscv/zbb-rol-ror-01.c: New test
* gcc.target/riscv/zbb-rol-ror-02.c: New test
* gcc.target/riscv/zbb-rol-ror-03.c: New test
* gcc.target/riscv/zbb-rol-ror-04.c: New test
* gcc.target/riscv/zbb-rol-ror-05.c: New test
* gcc.target/riscv/zbb-rol-ror-06.c: New test
* gcc.target/riscv/zbb-rol-ror-07.c: New test
Diffstat (limited to 'gcc/config/riscv/riscv.md')
-rw-r--r-- | gcc/config/riscv/riscv.md | 113 |
1 files changed, 14 insertions, 99 deletions
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index a917993..e773bc7 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2048,45 +2048,6 @@ [(set_attr "type" "shift") (set_attr "mode" "SI")]) -(define_insn_and_split "*<optab>si3_mask" - [(set (match_operand:SI 0 "register_operand" "= r") - (any_shift:SI - (match_operand:SI 1 "register_operand" " r") - (match_operator 4 "subreg_lowpart_operator" - [(and:SI - (match_operand:SI 2 "register_operand" "r") - (match_operand 3 "const_int_operand"))])))] - "(INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1)) - == GET_MODE_BITSIZE (SImode)-1" - "#" - "&& 1" - [(set (match_dup 0) - (any_shift:SI (match_dup 1) - (match_dup 2)))] - "operands[2] = gen_lowpart (QImode, operands[2]);" - [(set_attr "type" "shift") - (set_attr "mode" "SI")]) - -(define_insn_and_split "*<optab>si3_mask_1" - [(set (match_operand:SI 0 "register_operand" "= r") - (any_shift:SI - (match_operand:SI 1 "register_operand" " r") - (match_operator 4 "subreg_lowpart_operator" - [(and:DI - (match_operand:DI 2 "register_operand" "r") - (match_operand 3 "const_int_operand"))])))] - "TARGET_64BIT - && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1)) - == GET_MODE_BITSIZE (SImode)-1" - "#" - "&& 1" - [(set (match_dup 0) - (any_shift:SI (match_dup 1) - (match_dup 2)))] - "operands[2] = gen_lowpart (QImode, operands[2]);" - [(set_attr "type" "shift") - (set_attr "mode" "SI")]) - (define_insn "<optab>di3" [(set (match_operand:DI 0 "register_operand" "= r") (any_shift:DI @@ -2103,45 +2064,23 @@ [(set_attr "type" "shift") (set_attr "mode" "DI")]) -(define_insn_and_split "*<optab>di3_mask" - [(set (match_operand:DI 0 "register_operand" "= r") - (any_shift:DI - (match_operand:DI 1 "register_operand" " r") +(define_insn_and_split "*<optab><GPR:mode>3_mask_1" + [(set (match_operand:GPR 0 "register_operand" "= r") + (any_shift:GPR + (match_operand:GPR 1 "register_operand" " r") (match_operator 4 "subreg_lowpart_operator" - [(and:SI - (match_operand:SI 2 "register_operand" "r") - (match_operand 3 "const_int_operand"))])))] - "TARGET_64BIT - && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (DImode)-1)) - == GET_MODE_BITSIZE (DImode)-1" - "#" - "&& 1" - [(set (match_dup 0) - (any_shift:DI (match_dup 1) - (match_dup 2)))] - "operands[2] = gen_lowpart (QImode, operands[2]);" - [(set_attr "type" "shift") - (set_attr "mode" "DI")]) - -(define_insn_and_split "*<optab>di3_mask_1" - [(set (match_operand:DI 0 "register_operand" "= r") - (any_shift:DI - (match_operand:DI 1 "register_operand" " r") - (match_operator 4 "subreg_lowpart_operator" - [(and:DI - (match_operand:DI 2 "register_operand" "r") - (match_operand 3 "const_int_operand"))])))] - "TARGET_64BIT - && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (DImode)-1)) - == GET_MODE_BITSIZE (DImode)-1" + [(and:GPR2 + (match_operand:GPR2 2 "register_operand" "r") + (match_operand 3 "<GPR:shiftm1>"))])))] + "" "#" "&& 1" [(set (match_dup 0) - (any_shift:DI (match_dup 1) + (any_shift:GPR (match_dup 1) (match_dup 2)))] "operands[2] = gen_lowpart (QImode, operands[2]);" [(set_attr "type" "shift") - (set_attr "mode" "DI")]) + (set_attr "mode" "<GPR:MODE>")]) (define_insn "*<optab>si3_extend" [(set (match_operand:DI 0 "register_operand" "= r") @@ -2164,34 +2103,10 @@ (any_shift:SI (match_operand:SI 1 "register_operand" " r") (match_operator 4 "subreg_lowpart_operator" - [(and:SI - (match_operand:SI 2 "register_operand" " r") - (match_operand 3 "const_int_operand"))]))))] - "TARGET_64BIT - && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1)) - == GET_MODE_BITSIZE (SImode)-1" - "#" - "&& 1" - [(set (match_dup 0) - (sign_extend:DI - (any_shift:SI (match_dup 1) - (match_dup 2))))] - "operands[2] = gen_lowpart (QImode, operands[2]);" - [(set_attr "type" "shift") - (set_attr "mode" "SI")]) - -(define_insn_and_split "*<optab>si3_extend_mask_1" - [(set (match_operand:DI 0 "register_operand" "= r") - (sign_extend:DI - (any_shift:SI - (match_operand:SI 1 "register_operand" " r") - (match_operator 4 "subreg_lowpart_operator" - [(and:DI - (match_operand:DI 2 "register_operand" " r") - (match_operand 3 "const_int_operand"))]))))] - "TARGET_64BIT - && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1)) - == GET_MODE_BITSIZE (SImode)-1" + [(and:GPR + (match_operand:GPR 2 "register_operand" " r") + (match_operand 3 "const_si_mask_operand"))]))))] + "TARGET_64BIT" "#" "&& 1" [(set (match_dup 0) |