]> gcc.gnu.org Git - gcc.git/commit
RISC-V: Remove masking third operand of rotate instructions
authorJivan Hakobyan <jivanhakobyan9@gmail.com>
Wed, 17 May 2023 19:00:28 +0000 (13:00 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Wed, 17 May 2023 19:04:35 +0000 (13:04 -0600)
commit6da6ed95c9ca247d405da3dfb737b743686fe5e6
treebbe8b754bd425be1b1f8e0451187f1b6d758fe61
parent98827c53ed38886795b1f479c1d997fd89011c38
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
12 files changed:
gcc/config/riscv/bitmanip.md
gcc/config/riscv/iterators.md
gcc/config/riscv/predicates.md
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/shift-and-2.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-01.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-02.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-03.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-04.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-05.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-06.c
gcc/testsuite/gcc.target/riscv/zbb-rol-ror-07.c
This page took 0.06559 seconds and 5 git commands to generate.