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.
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_apinski@quicinc.com>
--- /dev/null
+/* 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" } } */
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,