Hi Jim, Thank you for your reply. I've tried the following code on GCC for RVV extendsion, still met the same issue. ➜ vint16m1_t foo3(vint16m1_t a, vint16m1_t b){ vint16m1_t add = a+b; vint16m1_t mul = a*b; vsetvl_e8m1(32); return add + mul; }
the assembly is: ➜ foo3: li a4,32 vl1r.v v1,0(a1) vl1r.v v3,0(a2) vsetvli a4,a4,e8,m1 vsetvli x0,x0,e16,m1 vadd.vv v2,v1,v3 vmul.vv v1,v1,v3 vadd.vv v1,v2,v1 vs1r.v v1,0(a0) ret Unfortunately, the "vsetvl_e8m1" has been reordered. Have you ever encountered this problem? Has it been solved and how? Thanks again. Best, Jin ________________________________ 发件人: Jim Wilson <j...@sifive.com> 发送时间: 2020年9月30日 3:45 收件人: 夏 晋 <ilyply2...@hotmail.com> 抄送: gcc@gcc.gnu.org <gcc@gcc.gnu.org> 主题: Re: Is there a way to tell GCC not to reorder a specific instruction? On Tue, Sep 29, 2020 at 3:47 AM 夏 晋 via Gcc <gcc@gcc.gnu.org> wrote: > I tried to set the "vlen" after the add & multi, as shown in the following > code: > vf32 x3,x4; > void foo1(float16_t* input, float16_t* output, int vlen){ > vf32 add = x3 + x4; > vf32 mul = x3 * x4; > __builtin_riscv_vlen(vlen); //<---- > storevf(&output[0], add); > storevf(&output[4], mul); > } Not clear what __builtin_riscv_vlen is doing, or what exactly your target is, but the gcc port I did for the RISC-V draft V extension creates new fake vector type and vector length registers, like the existing fake fp and arg pointer registers, and the vsetvl{i} instruction sets the fake vector type and vector length registers, and all vector instructions read the fake vector type and vector length registers. That creates the dependence between the instructions that prevents reordering. It is a little more complicated than that, as you can have more than one vsetvl{i} instruction setting different vector type and/or vector length values, so we have to match on the expected values to make sure that vector instructions are tied to the right vsetvl{i} instruction. This is a work in progress, but overall it is working pretty well. This requires changes to the gcc port, as you have to add the new fake registers in gcc/config/riscv/riscv.h. This isn't something you can do with macros and extended asms. See for instance https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/Krhw8--wmi4/m/-3IPvT7JCgAJ Jim