]> gcc.gnu.org Git - gcc.git/commit
RISC-V: Make liveness estimation be aware of .vi variant
authorJuzhe-Zhong <juzhe.zhong@rivai.ai>
Thu, 4 Jan 2024 08:22:48 +0000 (16:22 +0800)
committerLehua Ding <lehua.ding@rivai.ai>
Thu, 4 Jan 2024 09:20:20 +0000 (17:20 +0800)
commitb1342247a44c410ad6a44dfd82813fafe2ea7c1d
tree66933ab506e46d5909fece8ff2ab782eace777c9
parent73a4f67b9c8c497d87fda44160953293bc4e11e5
RISC-V: Make liveness estimation be aware of .vi variant

Consider this following case:

void
f (int *restrict a, int *restrict b, int *restrict c, int *restrict d, int n)
{
  for (int i = 0; i < n; i++)
    {
      int tmp = b[i] + 15;
      int tmp2 = tmp + b[i];
      c[i] = tmp2 + b[i];
      d[i] = tmp + tmp2 + b[i];
    }
}

Current dynamic LMUL cost model choose LMUL = 4 because we count the "15" as
consuming 1 vector register group which is not accurate.

We teach the dynamic LMUL cost model be aware of the potential vi variant instructions
transformation, so that we can choose LMUL = 8 according to more accurate cost model.

After this patch:

f:
ble a4,zero,.L5
.L3:
vsetvli a5,a4,e32,m8,ta,ma
slli a0,a5,2
vle32.v v16,0(a1)
vadd.vi v24,v16,15
vadd.vv v8,v24,v16
vadd.vv v0,v8,v16
vse32.v v0,0(a2)
vadd.vv v8,v8,v24
vadd.vv v8,v8,v16
vse32.v v8,0(a3)
add a1,a1,a0
add a2,a2,a0
add a3,a3,a0
sub a4,a4,a5
bne a4,zero,.L3
.L5:
ret

Tested on both RV32 and RV64 no regression. Ok for trunk ?

gcc/ChangeLog:

* config/riscv/riscv-vector-costs.cc (variable_vectorized_p): Teach vi variant.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c: New test.
gcc/config/riscv/riscv-vector-costs.cc
gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c [new file with mode: 0644]
This page took 0.070648 seconds and 5 git commands to generate.