On Thu, Jul 11, 2024 at 2:14 PM YunQiang Su <[email protected]> wrote:
>
> From: YunQiang Su <[email protected]>
>
> Uninitialized internal temp variable may be useful in some case,
> such as for COND_LEN_MUL etc on RISC-V with V extension: If an
> const or pre-exists VAR is used, we have to use "undisturbed"
> policy; if an uninitialized VAR is used, we can use "agnostic".
> With "agnostic", the microarchitectures can omit copying part of
> the VAR.
No please, there's TREE_NO_WARNING already.
> gcc
> * tree-core.h(tree_base): Add u.bits.allow_uninitialized.
> * tree.h: Add new macro TREE_ALLOW_UNINITIALIZED.
> * tree-ssa-uninit.cc(warn_uninit): Don't warn if VAR is
> marked as allow_uninitialized.
> ---
> gcc/tree-core.h | 5 ++++-
> gcc/tree-ssa-uninit.cc | 4 ++++
> gcc/tree.h | 4 ++++
> 3 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-core.h b/gcc/tree-core.h
> index 27c569c7702..984201199f6 100644
> --- a/gcc/tree-core.h
> +++ b/gcc/tree-core.h
> @@ -1101,7 +1101,10 @@ struct GTY(()) tree_base {
> unsigned nameless_flag : 1;
> unsigned atomic_flag : 1;
> unsigned unavailable_flag : 1;
> - unsigned spare0 : 2;
> + /* Don't warn if uninitialized. RISC-V V has tail agnostic/undisturbed
> + policy, which may be get benifits if we use an uninitialized var. */
> + unsigned allow_uninitialized : 1;
> + unsigned spare0 : 1;
>
> unsigned spare1 : 8;
>
> diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc
> index 726684e472a..12861e1dbc9 100644
> --- a/gcc/tree-ssa-uninit.cc
> +++ b/gcc/tree-ssa-uninit.cc
> @@ -142,6 +142,10 @@ warn_uninit (opt_code opt, tree t, tree var, gimple
> *context,
> if (!has_undefined_value_p (t))
> return;
>
> + /* VAR may mark itself as allow_uninitialized. */
> + if (TREE_ALLOW_UNINITIALIZED (var))
> + return;
> +
> /* Ignore COMPLEX_EXPR as initializing only a part of a complex
> turns in a COMPLEX_EXPR with the not initialized part being
> set to its previous (undefined) value. */
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 28e8e71b036..381780fde2e 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -3311,6 +3311,10 @@ extern void decl_fini_priority_insert (tree,
> priority_type);
> #define VAR_DECL_IS_VIRTUAL_OPERAND(NODE) \
> (VAR_DECL_CHECK (NODE)->base.u.bits.saturating_flag)
>
> +/* In a VAR_DECL, nonzero if NODE is allowed to be uninitialized. */
> +#define TREE_ALLOW_UNINITIALIZED(NODE) \
> + (VAR_DECL_CHECK (NODE)->base.u.bits.allow_uninitialized)
> +
> /* In a VAR_DECL, nonzero if this is a non-local frame structure. */
> #define DECL_NONLOCAL_FRAME(NODE) \
> (VAR_DECL_CHECK (NODE)->base.default_def_flag)
> --
> 2.45.1
>