]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Replace not + bitwise_imm with li + bitwise_not
authorJivan Hakobyan <jivanhakobyan9@gmail.com>
Fri, 29 Sep 2023 19:41:48 +0000 (13:41 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Fri, 29 Sep 2023 19:42:47 +0000 (13:42 -0600)
commit51d09e67df52164c2025afa24531cf79820ff4c8
tree22d5d7a20c87c83b7ac605652cc2bf5effbce24d
parenteaa41a6dc127d8d8a38646aaadc37681691fc311
RISC-V: Replace not + bitwise_imm with li + bitwise_not

In the case when we have C code like this

int foo (int a) {
   return 100 & ~a;
}

GCC generates the following instruction sequence

foo:
     not     a0,a0
     andi    a0,a0,100
     ret

This patch replaces that with this sequence
foo:
     li a5,100
     andn a0,a5,a0
     ret

The profitability comes from an out-of-order processor being able to
issue the "li a5, 100" at any time after it's fetched while "not a0, a0" has
to wait until any prior setter of a0 has reached completion.

gcc/ChangeLog:
* config/riscv/bitmanip.md (*<optab>_not_const<mode>): New split
pattern.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/zbb-andn-orn-01.c: New test.
* gcc.target/riscv/zbb-andn-orn-02.c: Likewise.
gcc/config/riscv/bitmanip.md
gcc/testsuite/gcc.target/riscv/zbb-andn-orn-01.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/zbb-andn-orn-02.c [new file with mode: 0644]