> Am 03.06.2025 um 04:51 schrieb Andrew Pinski <quic_apin...@quicinc.com>:
> 
> When we have a smallish CSWTCH, it could be placed in the rodata.cst16
> section so it can be merged with other constants across TUs.
> 
> The fix is simple; just mark the decl as mergable (DECL_MERGEABLE).
> DECL_MERGEABLE was added with r14-1500-g4d935f52b0d5c0 specifically
> to improve these kind of decls.

Ok

>    PR tree-optimization/120451
> 
> gcc/ChangeLog:
> 
>    * tree-switch-conversion.cc (switch_conversion::build_one_array): Mark
>    the newly created decl as mergable.
> 
> gcc/testsuite/ChangeLog:
> 
>    * gcc.dg/tree-ssa/cswtch-6.c: New test.
> 
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
> gcc/testsuite/gcc.dg/tree-ssa/cswtch-6.c | 43 ++++++++++++++++++++++++
> gcc/tree-switch-conversion.cc            |  3 ++
> 2 files changed, 46 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cswtch-6.c
> 
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cswtch-6.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/cswtch-6.c
> new file mode 100644
> index 00000000000..d765a03aa19
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/cswtch-6.c
> @@ -0,0 +1,43 @@
> +/* PR tree-optimization/120451 */
> +/* { dg-do compile { target elf } } */
> +/* { dg-options "-O2" } */
> +
> +void foo (int, int);
> +
> +__attribute__((noinline, noclone)) void
> +f1 (int v, int w)
> +{
> +  int i, j;
> +  if (w)
> +    {
> +      i = 129;
> +      j = i - 1;
> +      goto lab;
> +    }
> +  switch (v)
> +    {
> +    case 170:
> +      j = 7;
> +      i = 27;
> +      break;
> +    case 171:
> +      i = 8;
> +      j = 122;
> +      break;
> +    case 172:
> +      i = 21;
> +      j = -19;
> +      break;
> +    case 173:
> +      i = 18;
> +      j = 17;
> +      break;
> +    default:
> +      __builtin_abort ();
> +    }
> +
> + lab:
> +  foo (i, j);
> +}
> +
> +/* { dg-final { scan-assembler ".rodata.cst16" } } */
> diff --git a/gcc/tree-switch-conversion.cc b/gcc/tree-switch-conversion.cc
> index bd4de966892..d0882879e61 100644
> --- a/gcc/tree-switch-conversion.cc
> +++ b/gcc/tree-switch-conversion.cc
> @@ -1030,6 +1030,9 @@ switch_conversion::build_one_array (int num, tree 
> arr_index_type,
>       TREE_CONSTANT (decl) = 1;
>       TREE_READONLY (decl) = 1;
>       DECL_IGNORED_P (decl) = 1;
> +      /* The decl is mergable since we don't take the address ever and
> +     just reading from it. */
> +      DECL_MERGEABLE (decl) = 1;
>       if (offloading_function_p (cfun->decl))
>    DECL_ATTRIBUTES (decl)
>      = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
> --
> 2.43.0
> 

Reply via email to