]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Use extension instructions instead of bitwise "and"
authorJivan Hakobyan <jivanhakobyan9@gmail.com>
Mon, 29 May 2023 13:55:29 +0000 (07:55 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 29 May 2023 13:57:20 +0000 (07:57 -0600)
commit10680bc36aca7bfaee542a653a78813cf0d4fb1f
tree70a71a3e79623feea2007741b9c64006fdca0f0e
parent6b828454246c5aef7f984bb6a2888699f8dcfb2d
RISC-V: Use extension instructions instead of bitwise "and"

In the case where the target supports extension instructions,
it is preferable to use that instead of doing the same in other ways.
For the following case

void foo (unsigned long a, unsigned long* ptr) {
    ptr[0] = a & 0xffffffffUL;
    ptr[1] &= 0xffffffffUL;
}

GCC generates
foo:
        li      a5,-1
        srli    a5,a5,32
        and     a0,a0,a5
        sd      a0,0(a1)
        ld      a4,8(a1)
        and     a5,a4,a5
        sd      a5,8(a1)
        ret

but it will be profitable to generate this one

foo:
  zext.w a0,a0
  sd a0,0(a1)
  lwu a5,8(a1)
  sd a5,8(a1)
  ret

This patch fixes mentioned issue.
It supports HI -> DI, HI->SI and SI -> DI extensions.

gcc/ChangeLog:
* config/riscv/riscv.md (and<mode>3): New expander.
(*and<mode>3) New pattern.
* config/riscv/predicates.md (arith_operand_or_mode_mask): New
predicate.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/and-extend-1.c: New test
* gcc.target/riscv/and-extend-2.c: New test
gcc/config/riscv/predicates.md
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/and-extend-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/and-extend-2.c [new file with mode: 0644]