diff mbox series

[v2] RISC-V: NO_WARNING preferred else value for RVV

Message ID 20240711124354.46136-1-syq@gcc.gnu.org
State New
Headers show
Series [v2] RISC-V: NO_WARNING preferred else value for RVV | expand

Commit Message

YunQiang Su July 11, 2024, 12:43 p.m. UTC
From: YunQiang Su <yunqiang@isrc.iscas.ac.cn>

PR target/115840.

In riscv_preferred_else_value, we create an uninitialized tmp var
for else value, instead of the 0 (as default_preferred_else_value)
or the pre-exists VAR (as aarch64 does), so that we can use agnostic
policy.

The problem is that `warn_uninit` will emit a warning:
  '({anonymous})' may be used uninitialized

Let's mark this tmp var as NO_WARNING.

This problem is found when I try to build glibc with V extension.

gcc
        PR target/115840.
        * config/riscv/riscv.cc(riscv_preferred_else_value): Mark
        tmp_var as NO_WARNING.

gcc/testsuite
        * gcc.dg/vect/pr115840.c: New testcase.
---
 gcc/config/riscv/riscv.cc            |  6 +++++-
 gcc/testsuite/gcc.dg/vect/pr115840.c | 11 +++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr115840.c

Comments

Kito Cheng July 11, 2024, 2:02 p.m. UTC | #1
Lgtm, thanks :)

YunQiang Su <syq@gcc.gnu.org>於 2024年7月11日 週四,20:45寫道:

> From: YunQiang Su <yunqiang@isrc.iscas.ac.cn>
>
> PR target/115840.
>
> In riscv_preferred_else_value, we create an uninitialized tmp var
> for else value, instead of the 0 (as default_preferred_else_value)
> or the pre-exists VAR (as aarch64 does), so that we can use agnostic
> policy.
>
> The problem is that `warn_uninit` will emit a warning:
>   '({anonymous})' may be used uninitialized
>
> Let's mark this tmp var as NO_WARNING.
>
> This problem is found when I try to build glibc with V extension.
>
> gcc
>         PR target/115840.
>         * config/riscv/riscv.cc(riscv_preferred_else_value): Mark
>         tmp_var as NO_WARNING.
>
> gcc/testsuite
>         * gcc.dg/vect/pr115840.c: New testcase.
> ---
>  gcc/config/riscv/riscv.cc            |  6 +++++-
>  gcc/testsuite/gcc.dg/vect/pr115840.c | 11 +++++++++++
>  2 files changed, 16 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.dg/vect/pr115840.c
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 61fa74e9322..276998a992b 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -11431,7 +11431,11 @@ riscv_preferred_else_value (unsigned ifn, tree
> vectype, unsigned int nops,
>                             tree *ops)
>  {
>    if (riscv_v_ext_mode_p (TYPE_MODE (vectype)))
> -    return get_or_create_ssa_default_def (cfun, create_tmp_var (vectype));
> +    {
> +      tree tmp_var = create_tmp_var (vectype);
> +      TREE_NO_WARNING (tmp_var) = 1;
> +      return get_or_create_ssa_default_def (cfun, tmp_var);
> +    }
>
>    return default_preferred_else_value (ifn, vectype, nops, ops);
>  }
> diff --git a/gcc/testsuite/gcc.dg/vect/pr115840.c
> b/gcc/testsuite/gcc.dg/vect/pr115840.c
> new file mode 100644
> index 00000000000..09dc9e4eb7c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/pr115840.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-additional-options "-Wall -Werror" } */
> +
> +double loads[16];
> +
> +void
> +foo (double loadavg[], int count)
> +{
> +  for (int i = 0; i < count; i++)
> +    loadavg[i] = loads[i] / 1.5;
> +}
> --
> 2.45.1
>
>
diff mbox series

Patch

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 61fa74e9322..276998a992b 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11431,7 +11431,11 @@  riscv_preferred_else_value (unsigned ifn, tree vectype, unsigned int nops,
 			    tree *ops)
 {
   if (riscv_v_ext_mode_p (TYPE_MODE (vectype)))
-    return get_or_create_ssa_default_def (cfun, create_tmp_var (vectype));
+    {
+      tree tmp_var = create_tmp_var (vectype);
+      TREE_NO_WARNING (tmp_var) = 1;
+      return get_or_create_ssa_default_def (cfun, tmp_var);
+    }
 
   return default_preferred_else_value (ifn, vectype, nops, ops);
 }
diff --git a/gcc/testsuite/gcc.dg/vect/pr115840.c b/gcc/testsuite/gcc.dg/vect/pr115840.c
new file mode 100644
index 00000000000..09dc9e4eb7c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr115840.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-Wall -Werror" } */
+
+double loads[16];
+
+void
+foo (double loadavg[], int count)
+{
+  for (int i = 0; i < count; i++)
+    loadavg[i] = loads[i] / 1.5;
+}