diff mbox series

RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

Message ID 8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn
State New
Headers show
Series RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305] | expand

Commit Message

Zhijin Zeng Aug. 14, 2024, 6:06 a.m. UTC
This patch is to fix the bug (BugId:116305) introduced by the commit
bd93ef for risc-v target.

The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
equal.

Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
register value in riscv_legitimize_poly_move, and dwarf2cfi will also
get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
to calculate the number of times to multiply the vlenb register value.

So need to change the factor from riscv_bytes_per_vector_chunk to
BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
information. The incorrect example as follow:

```
csrr    t0,vlenb
slli    t1,t0,1
sub     sp,sp,t1

.cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
```

The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
the literal 4, '0x1e' means the multiply operation. But in fact, the
vlenb register value just need to multiply the literal 2.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
---
 gcc/config/riscv/riscv.cc                     |  4 +--
 .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

--
2.34.1


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。

Comments

Kito Cheng Aug. 16, 2024, 7:48 a.m. UTC | #1
LGTM, thanks for fixing that :)

On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
>
> This patch is to fix the bug (BugId:116305) introduced by the commit
> bd93ef for risc-v target.
>
> The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> equal.
>
> Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> to calculate the number of times to multiply the vlenb register value.
>
> So need to change the factor from riscv_bytes_per_vector_chunk to
> BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> information. The incorrect example as follow:
>
> ```
> csrr    t0,vlenb
> slli    t1,t0,1
> sub     sp,sp,t1
>
> .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> ```
>
> The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> the literal 4, '0x1e' means the multiply operation. But in fact, the
> vlenb register value just need to multiply the literal 2.
>
> gcc/ChangeLog:
>
>         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
>
> Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> ---
>  gcc/config/riscv/riscv.cc                     |  4 +--
>  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 5fe4273beb7..e740fc159dd 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -10773,12 +10773,12 @@ static unsigned int
>  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
>                                       int *offset)
>  {
> -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
>       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
>       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
>    */
>    gcc_assert (i == 1);
> -  *factor = riscv_bytes_per_vector_chunk;
> +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
>    *offset = 1;
>    return RISCV_DWARF_VLENB;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> new file mode 100644
> index 00000000000..184da10caf3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> +
> +#include "riscv_vector.h"
> +
> +#define PI_2 1.570796326795
> +
> +extern void func(float *result);
> +
> +void test(const float *ys, const float *xs, float *result, size_t length) {
> +    size_t gvl = __riscv_vsetvlmax_e32m2();
> +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> +
> +    for(size_t i = 0; i < length;) {
> +        gvl = __riscv_vsetvl_e32m2(length - i);
> +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> +
> +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> +
> +        func(result);
> +
> +        i += gvl;
> +        ys += gvl;
> +        xs += gvl;
> +        result += gvl;
> +    }
> +}
> --
> 2.34.1
>
>
> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
>
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Li, Pan2 Aug. 16, 2024, 12:15 p.m. UTC | #2
Hi there,

Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.

Pan


-----Original Message-----
From: Kito Cheng <kito.cheng@gmail.com> 
Sent: Friday, August 16, 2024 3:48 PM
To: 曾治金 <zhijin.zeng@spacemit.com>
Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

LGTM, thanks for fixing that :)

On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
>
> This patch is to fix the bug (BugId:116305) introduced by the commit
> bd93ef for risc-v target.
>
> The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> equal.
>
> Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> to calculate the number of times to multiply the vlenb register value.
>
> So need to change the factor from riscv_bytes_per_vector_chunk to
> BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> information. The incorrect example as follow:
>
> ```
> csrr    t0,vlenb
> slli    t1,t0,1
> sub     sp,sp,t1
>
> .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> ```
>
> The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> the literal 4, '0x1e' means the multiply operation. But in fact, the
> vlenb register value just need to multiply the literal 2.
>
> gcc/ChangeLog:
>
>         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
>
> Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> ---
>  gcc/config/riscv/riscv.cc                     |  4 +--
>  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 5fe4273beb7..e740fc159dd 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -10773,12 +10773,12 @@ static unsigned int
>  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
>                                       int *offset)
>  {
> -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
>       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
>       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
>    */
>    gcc_assert (i == 1);
> -  *factor = riscv_bytes_per_vector_chunk;
> +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
>    *offset = 1;
>    return RISCV_DWARF_VLENB;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> new file mode 100644
> index 00000000000..184da10caf3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> +
> +#include "riscv_vector.h"
> +
> +#define PI_2 1.570796326795
> +
> +extern void func(float *result);
> +
> +void test(const float *ys, const float *xs, float *result, size_t length) {
> +    size_t gvl = __riscv_vsetvlmax_e32m2();
> +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> +
> +    for(size_t i = 0; i < length;) {
> +        gvl = __riscv_vsetvl_e32m2(length - i);
> +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> +
> +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> +
> +        func(result);
> +
> +        i += gvl;
> +        ys += gvl;
> +        xs += gvl;
> +        result += gvl;
> +    }
> +}
> --
> 2.34.1
>
>
> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
>
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Zhijin Zeng Aug. 16, 2024, 12:47 p.m. UTC | #3
Hi Pan,
I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
Zhijin

> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Fri, Aug 16, 2024, 20:15
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "曾治金"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Hi there,

> Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.

> Pan


> -----Original Message-----
> From: Kito Cheng <kito.cheng@gmail.com> 
> Sent: Friday, August 16, 2024 3:48 PM
> To: 曾治金 <zhijin.zeng@spacemit.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> LGTM, thanks for fixing that :)

> On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> >
> > This patch is to fix the bug (BugId:116305) introduced by the commit
> > bd93ef for risc-v target.
> >
> > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > equal.
> >
> > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > to calculate the number of times to multiply the vlenb register value.
> >
> > So need to change the factor from riscv_bytes_per_vector_chunk to
> > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > information. The incorrect example as follow:
> >
> > ```
> > csrr    t0,vlenb
> > slli    t1,t0,1
> > sub     sp,sp,t1
> >
> > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > ```
> >
> > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > vlenb register value just need to multiply the literal 2.
> >
> > gcc/ChangeLog:
> >
> >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> >
> > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > ---
> >  gcc/config/riscv/riscv.cc                     |  4 +--
> >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> >  2 files changed, 34 insertions(+), 2 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> >
> > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > index 5fe4273beb7..e740fc159dd 100644
> > --- a/gcc/config/riscv/riscv.cc
> > +++ b/gcc/config/riscv/riscv.cc
> > @@ -10773,12 +10773,12 @@ static unsigned int
> >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> >                                       int *offset)
> >  {
> > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> >    */
> >    gcc_assert (i == 1);
> > -  *factor = riscv_bytes_per_vector_chunk;
> > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> >    *offset = 1;
> >    return RISCV_DWARF_VLENB;
> >  }
> > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > new file mode 100644
> > index 00000000000..184da10caf3
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > @@ -0,0 +1,32 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > +
> > +#include "riscv_vector.h"
> > +
> > +#define PI_2 1.570796326795
> > +
> > +extern void func(float *result);
> > +
> > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > +
> > +    for(size_t i = 0; i < length;) {
> > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > +
> > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > +
> > +        func(result);
> > +
> > +        i += gvl;
> > +        ys += gvl;
> > +        xs += gvl;
> > +        result += gvl;
> > +    }
> > +}
> > --
> > 2.34.1
> >
> >
> > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> >
> > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Li, Pan2 Aug. 16, 2024, 1:05 p.m. UTC | #4
Is this you newest version?
https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/

If so, you may need to rebase upstream, I got conflict when git am.

Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
error: corrupt patch at line 20
Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Pan

-----Original Message-----
From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
Sent: Friday, August 16, 2024 8:47 PM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

Hi Pan,
I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
Zhijin

> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Fri, Aug 16, 2024, 20:15
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "曾治金"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Hi there,

> Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.

> Pan


> -----Original Message-----
> From: Kito Cheng <kito.cheng@gmail.com> 
> Sent: Friday, August 16, 2024 3:48 PM
> To: 曾治金 <zhijin.zeng@spacemit.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> LGTM, thanks for fixing that :)

> On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> >
> > This patch is to fix the bug (BugId:116305) introduced by the commit
> > bd93ef for risc-v target.
> >
> > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > equal.
> >
> > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > to calculate the number of times to multiply the vlenb register value.
> >
> > So need to change the factor from riscv_bytes_per_vector_chunk to
> > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > information. The incorrect example as follow:
> >
> > ```
> > csrr    t0,vlenb
> > slli    t1,t0,1
> > sub     sp,sp,t1
> >
> > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > ```
> >
> > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > vlenb register value just need to multiply the literal 2.
> >
> > gcc/ChangeLog:
> >
> >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> >
> > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > ---
> >  gcc/config/riscv/riscv.cc                     |  4 +--
> >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> >  2 files changed, 34 insertions(+), 2 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> >
> > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > index 5fe4273beb7..e740fc159dd 100644
> > --- a/gcc/config/riscv/riscv.cc
> > +++ b/gcc/config/riscv/riscv.cc
> > @@ -10773,12 +10773,12 @@ static unsigned int
> >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> >                                       int *offset)
> >  {
> > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> >    */
> >    gcc_assert (i == 1);
> > -  *factor = riscv_bytes_per_vector_chunk;
> > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> >    *offset = 1;
> >    return RISCV_DWARF_VLENB;
> >  }
> > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > new file mode 100644
> > index 00000000000..184da10caf3
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > @@ -0,0 +1,32 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > +
> > +#include "riscv_vector.h"
> > +
> > +#define PI_2 1.570796326795
> > +
> > +extern void func(float *result);
> > +
> > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > +
> > +    for(size_t i = 0; i < length;) {
> > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > +
> > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > +
> > +        func(result);
> > +
> > +        i += gvl;
> > +        ys += gvl;
> > +        xs += gvl;
> > +        result += gvl;
> > +    }
> > +}
> > --
> > 2.34.1
> >
> >
> > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> >
> > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Zhijin Zeng Aug. 16, 2024, 1:29 p.m. UTC | #5
Sorry, the line number changed. The newest version as follow,

This patch is to fix the bug (BugId:116305) introduced by the commit
bd93ef for risc-v target.

The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
equal.

Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
register value in riscv_legitimize_poly_move, and dwarf2cfi will also
get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
to calculate the number of times to multiply the vlenb register value.

So need to change the factor from riscv_bytes_per_vector_chunk to
BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
information. The incorrect example as follow:

```
csrr    t0,vlenb
slli    t1,t0,1
sub     sp,sp,t1

.cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
```

The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
the literal 4, '0x1e' means the multiply operation. But in fact, the
vlenb register value just need to multiply the literal 2.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
---
 gcc/config/riscv/riscv.cc                     |  4 +--
 .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1f60d8f9711..8b7123e043e 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11010,12 +11010,12 @@ static unsigned int
 riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
                                      int *offset)
 {
-  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
+  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
      1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
      2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
   */
   gcc_assert (i == 1);
-  *factor = riscv_bytes_per_vector_chunk;
+  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
   *offset = 1;
   return RISCV_DWARF_VLENB;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
new file mode 100644
index 00000000000..184da10caf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
+
+#include "riscv_vector.h"
+
+#define PI_2 1.570796326795
+
+extern void func(float *result);
+
+void test(const float *ys, const float *xs, float *result, size_t length) {
+    size_t gvl = __riscv_vsetvlmax_e32m2();
+    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
+
+    for(size_t i = 0; i < length;) {
+        gvl = __riscv_vsetvl_e32m2(length - i);
+        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
+        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
+        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
+        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
+
+        __riscv_vse32_v_f32m2(result, fixpi, gvl);
+
+        func(result);
+
+        i += gvl;
+        ys += gvl;
+        xs += gvl;
+        result += gvl;
+    }
+}
--
2.34.1

> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Fri, Aug 16, 2024, 21:05
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Is this you newest version?
> https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/

> If so, you may need to rebase upstream, I got conflict when git am.

> Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> error: corrupt patch at line 20
> Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".

> Pan

> -----Original Message-----
> From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> Sent: Friday, August 16, 2024 8:47 PM
> To: Li, Pan2 <pan2.li@intel.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> Hi Pan,
> I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
> Zhijin

> > From: "Li, Pan2"<pan2.li@intel.com>
> > Date:  Fri, Aug 16, 2024, 20:15
> > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > To: "曾治金"<zhijin.zeng@spacemit.com>
> > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > Hi there,
> > 
> > Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.
> > 
> > Pan
> > 
> > 
> > -----Original Message-----
> > From: Kito Cheng <kito.cheng@gmail.com> 
> > Sent: Friday, August 16, 2024 3:48 PM
> > To: 曾治金 <zhijin.zeng@spacemit.com>
> > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > 
> > LGTM, thanks for fixing that :)
> > 
> > On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> > >
> > > This patch is to fix the bug (BugId:116305) introduced by the commit
> > > bd93ef for risc-v target.
> > >
> > > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > > equal.
> > >
> > > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > > to calculate the number of times to multiply the vlenb register value.
> > >
> > > So need to change the factor from riscv_bytes_per_vector_chunk to
> > > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > > information. The incorrect example as follow:
> > >
> > > ```
> > > csrr    t0,vlenb
> > > slli    t1,t0,1
> > > sub     sp,sp,t1
> > >
> > > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > > ```
> > >
> > > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > > vlenb register value just need to multiply the literal 2.
> > >
> > > gcc/ChangeLog:
> > >
> > >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > >
> > > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > > ---
> > >  gcc/config/riscv/riscv.cc                     |  4 +--
> > >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> > >  2 files changed, 34 insertions(+), 2 deletions(-)
> > >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > >
> > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > > index 5fe4273beb7..e740fc159dd 100644
> > > --- a/gcc/config/riscv/riscv.cc
> > > +++ b/gcc/config/riscv/riscv.cc
> > > @@ -10773,12 +10773,12 @@ static unsigned int
> > >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> > >                                       int *offset)
> > >  {
> > > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> > >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> > >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> > >    */
> > >    gcc_assert (i == 1);
> > > -  *factor = riscv_bytes_per_vector_chunk;
> > > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> > >    *offset = 1;
> > >    return RISCV_DWARF_VLENB;
> > >  }
> > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > new file mode 100644
> > > index 00000000000..184da10caf3
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > @@ -0,0 +1,32 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > > +
> > > +#include "riscv_vector.h"
> > > +
> > > +#define PI_2 1.570796326795
> > > +
> > > +extern void func(float *result);
> > > +
> > > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > > +
> > > +    for(size_t i = 0; i < length;) {
> > > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > > +
> > > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > > +
> > > +        func(result);
> > > +
> > > +        i += gvl;
> > > +        ys += gvl;
> > > +        xs += gvl;
> > > +        result += gvl;
> > > +    }
> > > +}
> > > --
> > > 2.34.1
> > >
> > >
> > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> > >
> > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
>  
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Li, Pan2 Aug. 17, 2024, 1:20 a.m. UTC | #6
Never mind, looks still conflict, could you please help to double check about it?
Current upstream should be 3c9c93f3c923c4a0ccd42db4fd26a944a3c91458.

└─(09:18:27 on master ✭)──> git apply tmp.patch                                                                                                                                                                             ──(Sat,Aug17)─┘
error: patch failed: gcc/config/riscv/riscv.cc:11010
error: gcc/config/riscv/riscv.cc: patch does not apply

Pan

-----Original Message-----
From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
Sent: Friday, August 16, 2024 9:30 PM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

Sorry, the line number changed. The newest version as follow,

This patch is to fix the bug (BugId:116305) introduced by the commit
bd93ef for risc-v target.

The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
equal.

Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
register value in riscv_legitimize_poly_move, and dwarf2cfi will also
get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
to calculate the number of times to multiply the vlenb register value.

So need to change the factor from riscv_bytes_per_vector_chunk to
BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
information. The incorrect example as follow:

```
csrr    t0,vlenb
slli    t1,t0,1
sub     sp,sp,t1

.cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
```

The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
the literal 4, '0x1e' means the multiply operation. But in fact, the
vlenb register value just need to multiply the literal 2.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
---
 gcc/config/riscv/riscv.cc                     |  4 +--
 .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1f60d8f9711..8b7123e043e 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11010,12 +11010,12 @@ static unsigned int
 riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
                                      int *offset)
 {
-  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
+  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
      1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
      2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
   */
   gcc_assert (i == 1);
-  *factor = riscv_bytes_per_vector_chunk;
+  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
   *offset = 1;
   return RISCV_DWARF_VLENB;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
new file mode 100644
index 00000000000..184da10caf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
+
+#include "riscv_vector.h"
+
+#define PI_2 1.570796326795
+
+extern void func(float *result);
+
+void test(const float *ys, const float *xs, float *result, size_t length) {
+    size_t gvl = __riscv_vsetvlmax_e32m2();
+    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
+
+    for(size_t i = 0; i < length;) {
+        gvl = __riscv_vsetvl_e32m2(length - i);
+        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
+        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
+        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
+        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
+
+        __riscv_vse32_v_f32m2(result, fixpi, gvl);
+
+        func(result);
+
+        i += gvl;
+        ys += gvl;
+        xs += gvl;
+        result += gvl;
+    }
+}
--
2.34.1

> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Fri, Aug 16, 2024, 21:05
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Is this you newest version?
> https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/

> If so, you may need to rebase upstream, I got conflict when git am.

> Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> error: corrupt patch at line 20
> Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".

> Pan

> -----Original Message-----
> From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> Sent: Friday, August 16, 2024 8:47 PM
> To: Li, Pan2 <pan2.li@intel.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> Hi Pan,
> I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
> Zhijin

> > From: "Li, Pan2"<pan2.li@intel.com>
> > Date:  Fri, Aug 16, 2024, 20:15
> > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > To: "曾治金"<zhijin.zeng@spacemit.com>
> > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > Hi there,
> > 
> > Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.
> > 
> > Pan
> > 
> > 
> > -----Original Message-----
> > From: Kito Cheng <kito.cheng@gmail.com> 
> > Sent: Friday, August 16, 2024 3:48 PM
> > To: 曾治金 <zhijin.zeng@spacemit.com>
> > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > 
> > LGTM, thanks for fixing that :)
> > 
> > On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> > >
> > > This patch is to fix the bug (BugId:116305) introduced by the commit
> > > bd93ef for risc-v target.
> > >
> > > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > > equal.
> > >
> > > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > > to calculate the number of times to multiply the vlenb register value.
> > >
> > > So need to change the factor from riscv_bytes_per_vector_chunk to
> > > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > > information. The incorrect example as follow:
> > >
> > > ```
> > > csrr    t0,vlenb
> > > slli    t1,t0,1
> > > sub     sp,sp,t1
> > >
> > > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > > ```
> > >
> > > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > > vlenb register value just need to multiply the literal 2.
> > >
> > > gcc/ChangeLog:
> > >
> > >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > >
> > > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > > ---
> > >  gcc/config/riscv/riscv.cc                     |  4 +--
> > >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> > >  2 files changed, 34 insertions(+), 2 deletions(-)
> > >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > >
> > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > > index 5fe4273beb7..e740fc159dd 100644
> > > --- a/gcc/config/riscv/riscv.cc
> > > +++ b/gcc/config/riscv/riscv.cc
> > > @@ -10773,12 +10773,12 @@ static unsigned int
> > >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> > >                                       int *offset)
> > >  {
> > > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> > >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> > >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> > >    */
> > >    gcc_assert (i == 1);
> > > -  *factor = riscv_bytes_per_vector_chunk;
> > > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> > >    *offset = 1;
> > >    return RISCV_DWARF_VLENB;
> > >  }
> > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > new file mode 100644
> > > index 00000000000..184da10caf3
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > @@ -0,0 +1,32 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > > +
> > > +#include "riscv_vector.h"
> > > +
> > > +#define PI_2 1.570796326795
> > > +
> > > +extern void func(float *result);
> > > +
> > > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > > +
> > > +    for(size_t i = 0; i < length;) {
> > > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > > +
> > > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > > +
> > > +        func(result);
> > > +
> > > +        i += gvl;
> > > +        ys += gvl;
> > > +        xs += gvl;
> > > +        result += gvl;
> > > +    }
> > > +}
> > > --
> > > 2.34.1
> > >
> > >
> > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> > >
> > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
>  
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Zhijin Zeng Aug. 17, 2024, 2:45 a.m. UTC | #7
The patch for 3c9c93 as follow. But it's a little strange that this patch hasn't changed and I don't know why it apply fail. May you directly modify the riscv.cc if this version still conflict? The riscv.cc just changed two lines. Thank you again.
Zhijjin

This patch is to fix the bug (BugId:116305) introduced by the commit
bd93ef for risc-v target.

The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
equal.

Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
register value in riscv_legitimize_poly_move, and dwarf2cfi will also
get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
to calculate the number of times to multiply the vlenb register value.

So need to change the factor from riscv_bytes_per_vector_chunk to
BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
information. The incorrect example as follow:

```
csrr    t0,vlenb
slli    t1,t0,1
sub     sp,sp,t1

.cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
```

The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
the literal 4, '0x1e' means the multiply operation. But in fact, the
vlenb register value just need to multiply the literal 2.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
---
 gcc/config/riscv/riscv.cc                     |  4 +--
 .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1f60d8f9711..8b7123e043e 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11010,12 +11010,12 @@ static unsigned int
 riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
                                      int *offset)
 {
-  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
+  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
      1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
      2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
   */
   gcc_assert (i == 1);
-  *factor = riscv_bytes_per_vector_chunk;
+  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
   *offset = 1;
   return RISCV_DWARF_VLENB;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
new file mode 100644
index 00000000000..184da10caf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
+
+#include "riscv_vector.h"
+
+#define PI_2 1.570796326795
+
+extern void func(float *result);
+
+void test(const float *ys, const float *xs, float *result, size_t length) {
+    size_t gvl = __riscv_vsetvlmax_e32m2();
+    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
+
+    for(size_t i = 0; i < length;) {
+        gvl = __riscv_vsetvl_e32m2(length - i);
+        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
+        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
+        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
+        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
+
+        __riscv_vse32_v_f32m2(result, fixpi, gvl);
+
+        func(result);
+
+        i += gvl;
+        ys += gvl;
+        xs += gvl;
+        result += gvl;
+    }
+}
--
2.34.1


> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Sat, Aug 17, 2024, 09:20
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Never mind, looks still conflict, could you please help to double check about it?
> Current upstream should be 3c9c93f3c923c4a0ccd42db4fd26a944a3c91458.

> └─(09:18:27 on master ✭)──> git apply tmp.patch                                                                                                                                                                             ──(Sat,Aug17)─┘
> error: patch failed: gcc/config/riscv/riscv.cc:11010
> error: gcc/config/riscv/riscv.cc: patch does not apply

> Pan

> -----Original Message-----
> From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> Sent: Friday, August 16, 2024 9:30 PM
> To: Li, Pan2 <pan2.li@intel.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> Sorry, the line number changed. The newest version as follow,

> This patch is to fix the bug (BugId:116305) introduced by the commit
> bd93ef for risc-v target.

> The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> equal.

> Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> to calculate the number of times to multiply the vlenb register value.

> So need to change the factor from riscv_bytes_per_vector_chunk to
> BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> information. The incorrect example as follow:

> ```
> csrr    t0,vlenb
> slli    t1,t0,1
> sub     sp,sp,t1

> .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> ```

> The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> the literal 4, '0x1e' means the multiply operation. But in fact, the
> vlenb register value just need to multiply the literal 2.

> gcc/ChangeLog:

>         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

> gcc/testsuite/ChangeLog:

>         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

> Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> ---
>  gcc/config/riscv/riscv.cc                     |  4 +--
>  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 1f60d8f9711..8b7123e043e 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -11010,12 +11010,12 @@ static unsigned int
>  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
>                                       int *offset)
>  {
> -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
>       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
>       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
>    */
>    gcc_assert (i == 1);
> -  *factor = riscv_bytes_per_vector_chunk;
> +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
>    *offset = 1;
>    return RISCV_DWARF_VLENB;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> new file mode 100644
> index 00000000000..184da10caf3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> +
> +#include "riscv_vector.h"
> +
> +#define PI_2 1.570796326795
> +
> +extern void func(float *result);
> +
> +void test(const float *ys, const float *xs, float *result, size_t length) {
> +    size_t gvl = __riscv_vsetvlmax_e32m2();
> +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> +
> +    for(size_t i = 0; i < length;) {
> +        gvl = __riscv_vsetvl_e32m2(length - i);
> +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> +
> +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> +
> +        func(result);
> +
> +        i += gvl;
> +        ys += gvl;
> +        xs += gvl;
> +        result += gvl;
> +    }
> +}
> --
> 2.34.1

> > From: "Li, Pan2"<pan2.li@intel.com>
> > Date:  Fri, Aug 16, 2024, 21:05
> > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > Is this you newest version?
> > https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/
> > 
> > If so, you may need to rebase upstream, I got conflict when git am.
> > 
> > Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > error: corrupt patch at line 20
> > Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > hint: Use 'git am --show-current-patch=diff' to see the failed patch
> > When you have resolved this problem, run "git am --continue".
> > If you prefer to skip this patch, run "git am --skip" instead.
> > To restore the original branch and stop patching, run "git am --abort".
> > 
> > Pan
> > 
> > -----Original Message-----
> > From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> > Sent: Friday, August 16, 2024 8:47 PM
> > To: Li, Pan2 <pan2.li@intel.com>
> > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > 
> > Hi Pan,
> > I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
> > Zhijin
> > 
> > > From: "Li, Pan2"<pan2.li@intel.com>
> > > Date:  Fri, Aug 16, 2024, 20:15
> > > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > To: "曾治金"<zhijin.zeng@spacemit.com>
> > > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > > Hi there,
> > > 
> > > Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.
> > > 
> > > Pan
> > > 
> > > 
> > > -----Original Message-----
> > > From: Kito Cheng <kito.cheng@gmail.com> 
> > > Sent: Friday, August 16, 2024 3:48 PM
> > > To: 曾治金 <zhijin.zeng@spacemit.com>
> > > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> > > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > 
> > > LGTM, thanks for fixing that :)
> > > 
> > > On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> > > >
> > > > This patch is to fix the bug (BugId:116305) introduced by the commit
> > > > bd93ef for risc-v target.
> > > >
> > > > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > > > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > > > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > > > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > > > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > > > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > > > equal.
> > > >
> > > > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > > > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > > > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > > > to calculate the number of times to multiply the vlenb register value.
> > > >
> > > > So need to change the factor from riscv_bytes_per_vector_chunk to
> > > > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > > > information. The incorrect example as follow:
> > > >
> > > > ```
> > > > csrr    t0,vlenb
> > > > slli    t1,t0,1
> > > > sub     sp,sp,t1
> > > >
> > > > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > > > ```
> > > >
> > > > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > > > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > > > vlenb register value just need to multiply the literal 2.
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > > >
> > > > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > > > ---
> > > >  gcc/config/riscv/riscv.cc                     |  4 +--
> > > >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> > > >  2 files changed, 34 insertions(+), 2 deletions(-)
> > > >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > >
> > > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > > > index 5fe4273beb7..e740fc159dd 100644
> > > > --- a/gcc/config/riscv/riscv.cc
> > > > +++ b/gcc/config/riscv/riscv.cc
> > > > @@ -10773,12 +10773,12 @@ static unsigned int
> > > >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> > > >                                       int *offset)
> > > >  {
> > > > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > > > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> > > >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> > > >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> > > >    */
> > > >    gcc_assert (i == 1);
> > > > -  *factor = riscv_bytes_per_vector_chunk;
> > > > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> > > >    *offset = 1;
> > > >    return RISCV_DWARF_VLENB;
> > > >  }
> > > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > new file mode 100644
> > > > index 00000000000..184da10caf3
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > @@ -0,0 +1,32 @@
> > > > +/* { dg-do compile } */
> > > > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > > > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > > > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > > > +
> > > > +#include "riscv_vector.h"
> > > > +
> > > > +#define PI_2 1.570796326795
> > > > +
> > > > +extern void func(float *result);
> > > > +
> > > > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > > > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > > > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > > > +
> > > > +    for(size_t i = 0; i < length;) {
> > > > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > > > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > > > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > > > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > > > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > > > +
> > > > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > > > +
> > > > +        func(result);
> > > > +
> > > > +        i += gvl;
> > > > +        ys += gvl;
> > > > +        xs += gvl;
> > > > +        result += gvl;
> > > > +    }
> > > > +}
> > > > --
> > > > 2.34.1
> > > >
> > > >
> > > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> > > >
> > > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
> > 
> > 
> > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
> >  
> > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
>  
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Li, Pan2 Aug. 17, 2024, 3:44 a.m. UTC | #8
Ok, I will commit it if no surprise from test as manually changing.

Pan

-----Original Message-----
From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
Sent: Saturday, August 17, 2024 10:46 AM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

The patch for 3c9c93 as follow. But it's a little strange that this patch hasn't changed and I don't know why it apply fail. May you directly modify the riscv.cc if this version still conflict? The riscv.cc just changed two lines. Thank you again.
Zhijjin

This patch is to fix the bug (BugId:116305) introduced by the commit
bd93ef for risc-v target.

The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
equal.

Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
register value in riscv_legitimize_poly_move, and dwarf2cfi will also
get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
to calculate the number of times to multiply the vlenb register value.

So need to change the factor from riscv_bytes_per_vector_chunk to
BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
information. The incorrect example as follow:

```
csrr    t0,vlenb
slli    t1,t0,1
sub     sp,sp,t1

.cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
```

The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
the literal 4, '0x1e' means the multiply operation. But in fact, the
vlenb register value just need to multiply the literal 2.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
---
 gcc/config/riscv/riscv.cc                     |  4 +--
 .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1f60d8f9711..8b7123e043e 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11010,12 +11010,12 @@ static unsigned int
 riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
                                      int *offset)
 {
-  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
+  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
      1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
      2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
   */
   gcc_assert (i == 1);
-  *factor = riscv_bytes_per_vector_chunk;
+  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
   *offset = 1;
   return RISCV_DWARF_VLENB;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
new file mode 100644
index 00000000000..184da10caf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
+
+#include "riscv_vector.h"
+
+#define PI_2 1.570796326795
+
+extern void func(float *result);
+
+void test(const float *ys, const float *xs, float *result, size_t length) {
+    size_t gvl = __riscv_vsetvlmax_e32m2();
+    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
+
+    for(size_t i = 0; i < length;) {
+        gvl = __riscv_vsetvl_e32m2(length - i);
+        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
+        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
+        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
+        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
+
+        __riscv_vse32_v_f32m2(result, fixpi, gvl);
+
+        func(result);
+
+        i += gvl;
+        ys += gvl;
+        xs += gvl;
+        result += gvl;
+    }
+}
--
2.34.1


> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Sat, Aug 17, 2024, 09:20
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Never mind, looks still conflict, could you please help to double check about it?
> Current upstream should be 3c9c93f3c923c4a0ccd42db4fd26a944a3c91458.

> └─(09:18:27 on master ✭)──> git apply tmp.patch                                                                                                                                                                             ──(Sat,Aug17)─┘
> error: patch failed: gcc/config/riscv/riscv.cc:11010
> error: gcc/config/riscv/riscv.cc: patch does not apply

> Pan

> -----Original Message-----
> From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> Sent: Friday, August 16, 2024 9:30 PM
> To: Li, Pan2 <pan2.li@intel.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> Sorry, the line number changed. The newest version as follow,

> This patch is to fix the bug (BugId:116305) introduced by the commit
> bd93ef for risc-v target.

> The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> equal.

> Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> to calculate the number of times to multiply the vlenb register value.

> So need to change the factor from riscv_bytes_per_vector_chunk to
> BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> information. The incorrect example as follow:

> ```
> csrr    t0,vlenb
> slli    t1,t0,1
> sub     sp,sp,t1

> .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> ```

> The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> the literal 4, '0x1e' means the multiply operation. But in fact, the
> vlenb register value just need to multiply the literal 2.

> gcc/ChangeLog:

>         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

> gcc/testsuite/ChangeLog:

>         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

> Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> ---
>  gcc/config/riscv/riscv.cc                     |  4 +--
>  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 1f60d8f9711..8b7123e043e 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -11010,12 +11010,12 @@ static unsigned int
>  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
>                                       int *offset)
>  {
> -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
>       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
>       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
>    */
>    gcc_assert (i == 1);
> -  *factor = riscv_bytes_per_vector_chunk;
> +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
>    *offset = 1;
>    return RISCV_DWARF_VLENB;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> new file mode 100644
> index 00000000000..184da10caf3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> +
> +#include "riscv_vector.h"
> +
> +#define PI_2 1.570796326795
> +
> +extern void func(float *result);
> +
> +void test(const float *ys, const float *xs, float *result, size_t length) {
> +    size_t gvl = __riscv_vsetvlmax_e32m2();
> +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> +
> +    for(size_t i = 0; i < length;) {
> +        gvl = __riscv_vsetvl_e32m2(length - i);
> +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> +
> +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> +
> +        func(result);
> +
> +        i += gvl;
> +        ys += gvl;
> +        xs += gvl;
> +        result += gvl;
> +    }
> +}
> --
> 2.34.1

> > From: "Li, Pan2"<pan2.li@intel.com>
> > Date:  Fri, Aug 16, 2024, 21:05
> > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > Is this you newest version?
> > https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/
> > 
> > If so, you may need to rebase upstream, I got conflict when git am.
> > 
> > Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > error: corrupt patch at line 20
> > Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > hint: Use 'git am --show-current-patch=diff' to see the failed patch
> > When you have resolved this problem, run "git am --continue".
> > If you prefer to skip this patch, run "git am --skip" instead.
> > To restore the original branch and stop patching, run "git am --abort".
> > 
> > Pan
> > 
> > -----Original Message-----
> > From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> > Sent: Friday, August 16, 2024 8:47 PM
> > To: Li, Pan2 <pan2.li@intel.com>
> > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > 
> > Hi Pan,
> > I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
> > Zhijin
> > 
> > > From: "Li, Pan2"<pan2.li@intel.com>
> > > Date:  Fri, Aug 16, 2024, 20:15
> > > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > To: "曾治金"<zhijin.zeng@spacemit.com>
> > > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > > Hi there,
> > > 
> > > Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.
> > > 
> > > Pan
> > > 
> > > 
> > > -----Original Message-----
> > > From: Kito Cheng <kito.cheng@gmail.com> 
> > > Sent: Friday, August 16, 2024 3:48 PM
> > > To: 曾治金 <zhijin.zeng@spacemit.com>
> > > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> > > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > 
> > > LGTM, thanks for fixing that :)
> > > 
> > > On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> > > >
> > > > This patch is to fix the bug (BugId:116305) introduced by the commit
> > > > bd93ef for risc-v target.
> > > >
> > > > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > > > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > > > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > > > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > > > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > > > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > > > equal.
> > > >
> > > > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > > > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > > > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > > > to calculate the number of times to multiply the vlenb register value.
> > > >
> > > > So need to change the factor from riscv_bytes_per_vector_chunk to
> > > > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > > > information. The incorrect example as follow:
> > > >
> > > > ```
> > > > csrr    t0,vlenb
> > > > slli    t1,t0,1
> > > > sub     sp,sp,t1
> > > >
> > > > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > > > ```
> > > >
> > > > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > > > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > > > vlenb register value just need to multiply the literal 2.
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > > >
> > > > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > > > ---
> > > >  gcc/config/riscv/riscv.cc                     |  4 +--
> > > >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> > > >  2 files changed, 34 insertions(+), 2 deletions(-)
> > > >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > >
> > > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > > > index 5fe4273beb7..e740fc159dd 100644
> > > > --- a/gcc/config/riscv/riscv.cc
> > > > +++ b/gcc/config/riscv/riscv.cc
> > > > @@ -10773,12 +10773,12 @@ static unsigned int
> > > >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> > > >                                       int *offset)
> > > >  {
> > > > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > > > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> > > >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> > > >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> > > >    */
> > > >    gcc_assert (i == 1);
> > > > -  *factor = riscv_bytes_per_vector_chunk;
> > > > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> > > >    *offset = 1;
> > > >    return RISCV_DWARF_VLENB;
> > > >  }
> > > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > new file mode 100644
> > > > index 00000000000..184da10caf3
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > @@ -0,0 +1,32 @@
> > > > +/* { dg-do compile } */
> > > > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > > > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > > > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > > > +
> > > > +#include "riscv_vector.h"
> > > > +
> > > > +#define PI_2 1.570796326795
> > > > +
> > > > +extern void func(float *result);
> > > > +
> > > > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > > > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > > > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > > > +
> > > > +    for(size_t i = 0; i < length;) {
> > > > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > > > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > > > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > > > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > > > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > > > +
> > > > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > > > +
> > > > +        func(result);
> > > > +
> > > > +        i += gvl;
> > > > +        ys += gvl;
> > > > +        xs += gvl;
> > > > +        result += gvl;
> > > > +    }
> > > > +}
> > > > --
> > > > 2.34.1
> > > >
> > > >
> > > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> > > >
> > > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
> > 
> > 
> > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
> >  
> > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
>  
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Li, Pan2 Aug. 17, 2024, 4:15 a.m. UTC | #9
Should be in upstream already.

Pan

-----Original Message-----
From: Li, Pan2 <pan2.li@intel.com> 
Sent: Saturday, August 17, 2024 11:45 AM
To: Zhijin Zeng <zhijin.zeng@spacemit.com>
Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
Subject: RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

Ok, I will commit it if no surprise from test as manually changing.

Pan

-----Original Message-----
From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
Sent: Saturday, August 17, 2024 10:46 AM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

The patch for 3c9c93 as follow. But it's a little strange that this patch hasn't changed and I don't know why it apply fail. May you directly modify the riscv.cc if this version still conflict? The riscv.cc just changed two lines. Thank you again.
Zhijjin

This patch is to fix the bug (BugId:116305) introduced by the commit
bd93ef for risc-v target.

The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
equal.

Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
register value in riscv_legitimize_poly_move, and dwarf2cfi will also
get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
to calculate the number of times to multiply the vlenb register value.

So need to change the factor from riscv_bytes_per_vector_chunk to
BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
information. The incorrect example as follow:

```
csrr    t0,vlenb
slli    t1,t0,1
sub     sp,sp,t1

.cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
```

The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
the literal 4, '0x1e' means the multiply operation. But in fact, the
vlenb register value just need to multiply the literal 2.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
---
 gcc/config/riscv/riscv.cc                     |  4 +--
 .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1f60d8f9711..8b7123e043e 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11010,12 +11010,12 @@ static unsigned int
 riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
                                      int *offset)
 {
-  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
+  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
      1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
      2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
   */
   gcc_assert (i == 1);
-  *factor = riscv_bytes_per_vector_chunk;
+  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
   *offset = 1;
   return RISCV_DWARF_VLENB;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
new file mode 100644
index 00000000000..184da10caf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
+
+#include "riscv_vector.h"
+
+#define PI_2 1.570796326795
+
+extern void func(float *result);
+
+void test(const float *ys, const float *xs, float *result, size_t length) {
+    size_t gvl = __riscv_vsetvlmax_e32m2();
+    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
+
+    for(size_t i = 0; i < length;) {
+        gvl = __riscv_vsetvl_e32m2(length - i);
+        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
+        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
+        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
+        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
+
+        __riscv_vse32_v_f32m2(result, fixpi, gvl);
+
+        func(result);
+
+        i += gvl;
+        ys += gvl;
+        xs += gvl;
+        result += gvl;
+    }
+}
--
2.34.1


> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Sat, Aug 17, 2024, 09:20
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Never mind, looks still conflict, could you please help to double check about it?
> Current upstream should be 3c9c93f3c923c4a0ccd42db4fd26a944a3c91458.

> └─(09:18:27 on master ✭)──> git apply tmp.patch                                                                                                                                                                             ──(Sat,Aug17)─┘
> error: patch failed: gcc/config/riscv/riscv.cc:11010
> error: gcc/config/riscv/riscv.cc: patch does not apply

> Pan

> -----Original Message-----
> From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> Sent: Friday, August 16, 2024 9:30 PM
> To: Li, Pan2 <pan2.li@intel.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> Sorry, the line number changed. The newest version as follow,

> This patch is to fix the bug (BugId:116305) introduced by the commit
> bd93ef for risc-v target.

> The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> equal.

> Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> to calculate the number of times to multiply the vlenb register value.

> So need to change the factor from riscv_bytes_per_vector_chunk to
> BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> information. The incorrect example as follow:

> ```
> csrr    t0,vlenb
> slli    t1,t0,1
> sub     sp,sp,t1

> .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> ```

> The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> the literal 4, '0x1e' means the multiply operation. But in fact, the
> vlenb register value just need to multiply the literal 2.

> gcc/ChangeLog:

>         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

> gcc/testsuite/ChangeLog:

>         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

> Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> ---
>  gcc/config/riscv/riscv.cc                     |  4 +--
>  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 1f60d8f9711..8b7123e043e 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -11010,12 +11010,12 @@ static unsigned int
>  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
>                                       int *offset)
>  {
> -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
>       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
>       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
>    */
>    gcc_assert (i == 1);
> -  *factor = riscv_bytes_per_vector_chunk;
> +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
>    *offset = 1;
>    return RISCV_DWARF_VLENB;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> new file mode 100644
> index 00000000000..184da10caf3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> +
> +#include "riscv_vector.h"
> +
> +#define PI_2 1.570796326795
> +
> +extern void func(float *result);
> +
> +void test(const float *ys, const float *xs, float *result, size_t length) {
> +    size_t gvl = __riscv_vsetvlmax_e32m2();
> +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> +
> +    for(size_t i = 0; i < length;) {
> +        gvl = __riscv_vsetvl_e32m2(length - i);
> +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> +
> +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> +
> +        func(result);
> +
> +        i += gvl;
> +        ys += gvl;
> +        xs += gvl;
> +        result += gvl;
> +    }
> +}
> --
> 2.34.1

> > From: "Li, Pan2"<pan2.li@intel.com>
> > Date:  Fri, Aug 16, 2024, 21:05
> > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > Is this you newest version?
> > https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/
> > 
> > If so, you may need to rebase upstream, I got conflict when git am.
> > 
> > Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > error: corrupt patch at line 20
> > Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > hint: Use 'git am --show-current-patch=diff' to see the failed patch
> > When you have resolved this problem, run "git am --continue".
> > If you prefer to skip this patch, run "git am --skip" instead.
> > To restore the original branch and stop patching, run "git am --abort".
> > 
> > Pan
> > 
> > -----Original Message-----
> > From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> > Sent: Friday, August 16, 2024 8:47 PM
> > To: Li, Pan2 <pan2.li@intel.com>
> > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > 
> > Hi Pan,
> > I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
> > Zhijin
> > 
> > > From: "Li, Pan2"<pan2.li@intel.com>
> > > Date:  Fri, Aug 16, 2024, 20:15
> > > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > To: "曾治金"<zhijin.zeng@spacemit.com>
> > > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > > Hi there,
> > > 
> > > Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.
> > > 
> > > Pan
> > > 
> > > 
> > > -----Original Message-----
> > > From: Kito Cheng <kito.cheng@gmail.com> 
> > > Sent: Friday, August 16, 2024 3:48 PM
> > > To: 曾治金 <zhijin.zeng@spacemit.com>
> > > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> > > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > 
> > > LGTM, thanks for fixing that :)
> > > 
> > > On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> > > >
> > > > This patch is to fix the bug (BugId:116305) introduced by the commit
> > > > bd93ef for risc-v target.
> > > >
> > > > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > > > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > > > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > > > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > > > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > > > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > > > equal.
> > > >
> > > > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > > > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > > > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > > > to calculate the number of times to multiply the vlenb register value.
> > > >
> > > > So need to change the factor from riscv_bytes_per_vector_chunk to
> > > > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > > > information. The incorrect example as follow:
> > > >
> > > > ```
> > > > csrr    t0,vlenb
> > > > slli    t1,t0,1
> > > > sub     sp,sp,t1
> > > >
> > > > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > > > ```
> > > >
> > > > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > > > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > > > vlenb register value just need to multiply the literal 2.
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > > >
> > > > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > > > ---
> > > >  gcc/config/riscv/riscv.cc                     |  4 +--
> > > >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> > > >  2 files changed, 34 insertions(+), 2 deletions(-)
> > > >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > >
> > > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > > > index 5fe4273beb7..e740fc159dd 100644
> > > > --- a/gcc/config/riscv/riscv.cc
> > > > +++ b/gcc/config/riscv/riscv.cc
> > > > @@ -10773,12 +10773,12 @@ static unsigned int
> > > >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> > > >                                       int *offset)
> > > >  {
> > > > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > > > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> > > >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> > > >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> > > >    */
> > > >    gcc_assert (i == 1);
> > > > -  *factor = riscv_bytes_per_vector_chunk;
> > > > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> > > >    *offset = 1;
> > > >    return RISCV_DWARF_VLENB;
> > > >  }
> > > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > new file mode 100644
> > > > index 00000000000..184da10caf3
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > @@ -0,0 +1,32 @@
> > > > +/* { dg-do compile } */
> > > > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > > > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > > > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > > > +
> > > > +#include "riscv_vector.h"
> > > > +
> > > > +#define PI_2 1.570796326795
> > > > +
> > > > +extern void func(float *result);
> > > > +
> > > > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > > > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > > > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > > > +
> > > > +    for(size_t i = 0; i < length;) {
> > > > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > > > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > > > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > > > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > > > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > > > +
> > > > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > > > +
> > > > +        func(result);
> > > > +
> > > > +        i += gvl;
> > > > +        ys += gvl;
> > > > +        xs += gvl;
> > > > +        result += gvl;
> > > > +    }
> > > > +}
> > > > --
> > > > 2.34.1
> > > >
> > > >
> > > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> > > >
> > > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
> > 
> > 
> > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
> >  
> > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
>  
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Zhijin Zeng Aug. 17, 2024, 5 a.m. UTC | #10
This is my first time submitting a patch to gcc and sincerely thank you all for your help.
Zhijin

> From: "Li, Pan2"<pan2.li@intel.com>
> Date:  Sat, Aug 17, 2024, 12:15
> Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> To: "Li, Pan2"<pan2.li@intel.com>, "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> Should be in upstream already.

> Pan

> -----Original Message-----
> From: Li, Pan2 <pan2.li@intel.com> 
> Sent: Saturday, August 17, 2024 11:45 AM
> To: Zhijin Zeng <zhijin.zeng@spacemit.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> Ok, I will commit it if no surprise from test as manually changing.

> Pan

> -----Original Message-----
> From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> Sent: Saturday, August 17, 2024 10:46 AM
> To: Li, Pan2 <pan2.li@intel.com>
> Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]

> The patch for 3c9c93 as follow. But it's a little strange that this patch hasn't changed and I don't know why it apply fail. May you directly modify the riscv.cc if this version still conflict? The riscv.cc just changed two lines. Thank you again.
> Zhijjin

> This patch is to fix the bug (BugId:116305) introduced by the commit
> bd93ef for risc-v target.

> The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> equal.

> Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> to calculate the number of times to multiply the vlenb register value.

> So need to change the factor from riscv_bytes_per_vector_chunk to
> BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> information. The incorrect example as follow:

> ```
> csrr    t0,vlenb
> slli    t1,t0,1
> sub     sp,sp,t1

> .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> ```

> The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> the literal 4, '0x1e' means the multiply operation. But in fact, the
> vlenb register value just need to multiply the literal 2.

> gcc/ChangeLog:

>         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):

> gcc/testsuite/ChangeLog:

>         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.

> Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> ---
>  gcc/config/riscv/riscv.cc                     |  4 +--
>  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
>  2 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c

> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 1f60d8f9711..8b7123e043e 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -11010,12 +11010,12 @@ static unsigned int
>  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
>                                       int *offset)
>  {
> -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
>       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
>       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
>    */
>    gcc_assert (i == 1);
> -  *factor = riscv_bytes_per_vector_chunk;
> +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
>    *offset = 1;
>    return RISCV_DWARF_VLENB;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> new file mode 100644
> index 00000000000..184da10caf3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> +
> +#include "riscv_vector.h"
> +
> +#define PI_2 1.570796326795
> +
> +extern void func(float *result);
> +
> +void test(const float *ys, const float *xs, float *result, size_t length) {
> +    size_t gvl = __riscv_vsetvlmax_e32m2();
> +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> +
> +    for(size_t i = 0; i < length;) {
> +        gvl = __riscv_vsetvl_e32m2(length - i);
> +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> +
> +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> +
> +        func(result);
> +
> +        i += gvl;
> +        ys += gvl;
> +        xs += gvl;
> +        result += gvl;
> +    }
> +}
> --
> 2.34.1


> > From: "Li, Pan2"<pan2.li@intel.com>
> > Date:  Sat, Aug 17, 2024, 09:20
> > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > Never mind, looks still conflict, could you please help to double check about it?
> > Current upstream should be 3c9c93f3c923c4a0ccd42db4fd26a944a3c91458.
> > 
> > └─(09:18:27 on master ✭)──> git apply tmp.patch                                                                                                                                                                             ──(Sat,Aug17)─┘
> > error: patch failed: gcc/config/riscv/riscv.cc:11010
> > error: gcc/config/riscv/riscv.cc: patch does not apply
> > 
> > Pan
> > 
> > -----Original Message-----
> > From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> > Sent: Friday, August 16, 2024 9:30 PM
> > To: Li, Pan2 <pan2.li@intel.com>
> > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > 
> > Sorry, the line number changed. The newest version as follow,
> > 
> > This patch is to fix the bug (BugId:116305) introduced by the commit
> > bd93ef for risc-v target.
> > 
> > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > equal.
> > 
> > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > to calculate the number of times to multiply the vlenb register value.
> > 
> > So need to change the factor from riscv_bytes_per_vector_chunk to
> > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > information. The incorrect example as follow:
> > 
> > ```
> > csrr    t0,vlenb
> > slli    t1,t0,1
> > sub     sp,sp,t1
> > 
> > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > ```
> > 
> > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > vlenb register value just need to multiply the literal 2.
> > 
> > gcc/ChangeLog:
> > 
> >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > 
> > gcc/testsuite/ChangeLog:
> > 
> >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > 
> > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > ---
> >  gcc/config/riscv/riscv.cc                     |  4 +--
> >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> >  2 files changed, 34 insertions(+), 2 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > 
> > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > index 1f60d8f9711..8b7123e043e 100644
> > --- a/gcc/config/riscv/riscv.cc
> > +++ b/gcc/config/riscv/riscv.cc
> > @@ -11010,12 +11010,12 @@ static unsigned int
> >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> >                                       int *offset)
> >  {
> > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> >    */
> >    gcc_assert (i == 1);
> > -  *factor = riscv_bytes_per_vector_chunk;
> > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> >    *offset = 1;
> >    return RISCV_DWARF_VLENB;
> >  }
> > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > new file mode 100644
> > index 00000000000..184da10caf3
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > @@ -0,0 +1,32 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > +
> > +#include "riscv_vector.h"
> > +
> > +#define PI_2 1.570796326795
> > +
> > +extern void func(float *result);
> > +
> > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > +
> > +    for(size_t i = 0; i < length;) {
> > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > +
> > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > +
> > +        func(result);
> > +
> > +        i += gvl;
> > +        ys += gvl;
> > +        xs += gvl;
> > +        result += gvl;
> > +    }
> > +}
> > --
> > 2.34.1
> > 
> > > From: "Li, Pan2"<pan2.li@intel.com>
> > > Date:  Fri, Aug 16, 2024, 21:05
> > > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > To: "Zhijin Zeng"<zhijin.zeng@spacemit.com>
> > > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > > Is this you newest version?
> > > https://patchwork.sourceware.org/project/gcc/patch/8fd4328940034d8778cca67eaad54e5a2c2b1a6c.1c2f51e1.0a9a.4367.9762.9b6eccc3b634@feishu.cn/
> > > 
> > > If so, you may need to rebase upstream, I got conflict when git am.
> > > 
> > > Applying: RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > error: corrupt patch at line 20
> > > Patch failed at 0001 RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > hint: Use 'git am --show-current-patch=diff' to see the failed patch
> > > When you have resolved this problem, run "git am --continue".
> > > If you prefer to skip this patch, run "git am --skip" instead.
> > > To restore the original branch and stop patching, run "git am --abort".
> > > 
> > > Pan
> > > 
> > > -----Original Message-----
> > > From: Zhijin Zeng <zhijin.zeng@spacemit.com> 
> > > Sent: Friday, August 16, 2024 8:47 PM
> > > To: Li, Pan2 <pan2.li@intel.com>
> > > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org; Kito Cheng <kito.cheng@gmail.com>
> > > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > 
> > > Hi Pan,
> > > I am a new guy for GCC and don't have authority to commit. Please help to commit this patch. Thank you very much.
> > > Zhijin
> > > 
> > > > From: "Li, Pan2"<pan2.li@intel.com>
> > > > Date:  Fri, Aug 16, 2024, 20:15
> > > > Subject:  RE: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > > To: "曾治金"<zhijin.zeng@spacemit.com>
> > > > Cc: "gcc-patches@gcc.gnu.org"<gcc-patches@gcc.gnu.org>, "gcc-bugs@gcc.gnu.org"<gcc-bugs@gcc.gnu.org>, "Kito Cheng"<kito.cheng@gmail.com>
> > > > Hi there,
> > > > 
> > > > Please feel free to let me know if you don't have authority to commit it. I can help to commit this patch.
> > > > 
> > > > Pan
> > > > 
> > > > 
> > > > -----Original Message-----
> > > > From: Kito Cheng <kito.cheng@gmail.com> 
> > > > Sent: Friday, August 16, 2024 3:48 PM
> > > > To: 曾治金 <zhijin.zeng@spacemit.com>
> > > > Cc: gcc-patches@gcc.gnu.org; gcc-bugs@gcc.gnu.org
> > > > Subject: Re: [PATCH] RISC-V: Fix factor in dwarf_poly_indeterminate_value [PR116305]
> > > > 
> > > > LGTM, thanks for fixing that :)
> > > > 
> > > > On Wed, Aug 14, 2024 at 2:06 PM 曾治金 <zhijin.zeng@spacemit.com> wrote:
> > > > >
> > > > > This patch is to fix the bug (BugId:116305) introduced by the commit
> > > > > bd93ef for risc-v target.
> > > > >
> > > > > The commit bd93ef changes the chunk_num from 1 to TARGET_MIN_VLEN/128
> > > > > if TARGET_MIN_VLEN is larger than 128 in riscv_convert_vector_bits. So
> > > > > it changes the value of BYTES_PER_RISCV_VECTOR. For example, before
> > > > > merging the commit bd93ef and if TARGET_MIN_VLEN is 256, the value
> > > > > of BYTES_PER_RISCV_VECTOR should be [8, 8], but now [16, 16]. The value
> > > > > of riscv_bytes_per_vector_chunk and BYTES_PER_RISCV_VECTOR are no longer
> > > > > equal.
> > > > >
> > > > > Prologue will use BYTES_PER_RISCV_VECTOR.coeffs[1] to estimate the vlenb
> > > > > register value in riscv_legitimize_poly_move, and dwarf2cfi will also
> > > > > get the estimated vlenb register value in riscv_dwarf_poly_indeterminate_value
> > > > > to calculate the number of times to multiply the vlenb register value.
> > > > >
> > > > > So need to change the factor from riscv_bytes_per_vector_chunk to
> > > > > BYTES_PER_RISCV_VECTOR, otherwise we will get the incorrect dwarf
> > > > > information. The incorrect example as follow:
> > > > >
> > > > > ```
> > > > > csrr    t0,vlenb
> > > > > slli    t1,t0,1
> > > > > sub     sp,sp,t1
> > > > >
> > > > > .cfi_escape 0xf,0xb,0x72,0,0x92,0xa2,0x38,0,0x34,0x1e,0x23,0x50,0x22
> > > > > ```
> > > > >
> > > > > The sequence '0x92,0xa2,0x38,0' means the vlenb register, '0x34' means
> > > > > the literal 4, '0x1e' means the multiply operation. But in fact, the
> > > > > vlenb register value just need to multiply the literal 2.
> > > > >
> > > > > gcc/ChangeLog:
> > > > >
> > > > >         * config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value):
> > > > >
> > > > > gcc/testsuite/ChangeLog:
> > > > >
> > > > >         * gcc.target/riscv/rvv/base/scalable_vector_cfi.c: New test.
> > > > >
> > > > > Signed-off-by: Zhijin Zeng <zhijin.zeng@spacemit.com>
> > > > > ---
> > > > >  gcc/config/riscv/riscv.cc                     |  4 +--
> > > > >  .../riscv/rvv/base/scalable_vector_cfi.c      | 32 +++++++++++++++++++
> > > > >  2 files changed, 34 insertions(+), 2 deletions(-)
> > > > >  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > >
> > > > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> > > > > index 5fe4273beb7..e740fc159dd 100644
> > > > > --- a/gcc/config/riscv/riscv.cc
> > > > > +++ b/gcc/config/riscv/riscv.cc
> > > > > @@ -10773,12 +10773,12 @@ static unsigned int
> > > > >  riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
> > > > >                                       int *offset)
> > > > >  {
> > > > > -  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
> > > > > +  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
> > > > >       1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
> > > > >       2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
> > > > >    */
> > > > >    gcc_assert (i == 1);
> > > > > -  *factor = riscv_bytes_per_vector_chunk;
> > > > > +  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
> > > > >    *offset = 1;
> > > > >    return RISCV_DWARF_VLENB;
> > > > >  }
> > > > > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > > new file mode 100644
> > > > > index 00000000000..184da10caf3
> > > > > --- /dev/null
> > > > > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
> > > > > @@ -0,0 +1,32 @@
> > > > > +/* { dg-do compile } */
> > > > > +/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
> > > > > +/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
> > > > > +/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
> > > > > +
> > > > > +#include "riscv_vector.h"
> > > > > +
> > > > > +#define PI_2 1.570796326795
> > > > > +
> > > > > +extern void func(float *result);
> > > > > +
> > > > > +void test(const float *ys, const float *xs, float *result, size_t length) {
> > > > > +    size_t gvl = __riscv_vsetvlmax_e32m2();
> > > > > +    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
> > > > > +
> > > > > +    for(size_t i = 0; i < length;) {
> > > > > +        gvl = __riscv_vsetvl_e32m2(length - i);
> > > > > +        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
> > > > > +        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
> > > > > +        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
> > > > > +        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
> > > > > +
> > > > > +        __riscv_vse32_v_f32m2(result, fixpi, gvl);
> > > > > +
> > > > > +        func(result);
> > > > > +
> > > > > +        i += gvl;
> > > > > +        ys += gvl;
> > > > > +        xs += gvl;
> > > > > +        result += gvl;
> > > > > +    }
> > > > > +}
> > > > > --
> > > > > 2.34.1
> > > > >
> > > > >
> > > > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
> > > > >
> > > > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
> > > 
> > > 
> > > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
> > >  
> > > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
> > 
> > 
> > This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
> >  
> > 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


> This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
>  
> 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。


This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 
 
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
Jonathan Wakely Aug. 19, 2024, 8:28 a.m. UTC | #11
Hi,

It's not useful to CC the gcc-bugs list with patches. Please just send
the patch to the gcc-patches list (and any other appropriate lists,
like libstdc++ or fortran, if appropriate). If you want to update the
bugzilla report, you can manually add a comment to it with the URL of
the patch submission from the gcc-patches mailing list archive.

Thanks!
diff mbox series

Patch

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 5fe4273beb7..e740fc159dd 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -10773,12 +10773,12 @@  static unsigned int
 riscv_dwarf_poly_indeterminate_value (unsigned int i, unsigned int *factor,
                                      int *offset)
 {
-  /* Polynomial invariant 1 == (VLENB / riscv_bytes_per_vector_chunk) - 1.
+  /* Polynomial invariant 1 == (VLENB / BYTES_PER_RISCV_VECTOR) - 1.
      1. TARGET_MIN_VLEN == 32, polynomial invariant 1 == (VLENB / 4) - 1.
      2. TARGET_MIN_VLEN > 32, polynomial invariant 1 == (VLENB / 8) - 1.
   */
   gcc_assert (i == 1);
-  *factor = riscv_bytes_per_vector_chunk;
+  *factor = BYTES_PER_RISCV_VECTOR.coeffs[1];
   *offset = 1;
   return RISCV_DWARF_VLENB;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
new file mode 100644
index 00000000000..184da10caf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/scalable_vector_cfi.c
@@ -0,0 +1,32 @@ 
+/* { dg-do compile } */
+/* { dg-options "-g -O3 -march=rv64gcv -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler {cfi_escape .*0x92,0xa2,0x38,0,0x32,0x1e} } } */
+
+#include "riscv_vector.h"
+
+#define PI_2 1.570796326795
+
+extern void func(float *result);
+
+void test(const float *ys, const float *xs, float *result, size_t length) {
+    size_t gvl = __riscv_vsetvlmax_e32m2();
+    vfloat32m2_t vpi2 = __riscv_vfmv_v_f_f32m2(PI_2, gvl);
+
+    for(size_t i = 0; i < length;) {
+        gvl = __riscv_vsetvl_e32m2(length - i);
+        vfloat32m2_t y = __riscv_vle32_v_f32m2(ys, gvl);
+        vfloat32m2_t x = __riscv_vle32_v_f32m2(xs, gvl);
+        vbool16_t mask0  = __riscv_vmflt_vv_f32m2_b16(x, y, gvl);
+        vfloat32m2_t fixpi = __riscv_vfrsub_vf_f32m2_mu(mask0, vpi2, vpi2, 0, gvl);
+
+        __riscv_vse32_v_f32m2(result, fixpi, gvl);
+
+        func(result);
+
+        i += gvl;
+        ys += gvl;
+        xs += gvl;
+        result += gvl;
+    }
+}