On Tue, Jun 3, 2025 at 10:43 PM H.J. Lu <hjl.to...@gmail.com> wrote: > > On Tue, Jun 3, 2025 at 10:51 AM Andrew Pinski <quic_apin...@quicinc.com> > wrote: > > > > 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_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 > > > > On x86-64/Linux, I got > > spawn -ignore SIGHUP > /export/build/gnu/tools-build/gcc-gitlab-test/build-x86_64-linux/gcc/xgcc > -B/export/build/gnu/tools-build/gcc-gitlab-test/build-x86_64-linux/gcc/ > /export/gnu/import/git/gitlab/x86-gcc-test/gcc/testsuite/gcc.dg/tree-ssa/cswtch-6.c > -m32 -fdiagnostics-plain-output -O2 -ffat-lto-objects -fno-ident -S -o > cswtch-6.s > PASS: gcc.dg/tree-ssa/cswtch-6.c (test for excess errors) > FAIL: gcc.dg/tree-ssa/cswtch-6.c scan-assembler .rodata.cst16
Yes I know it fails there, I already filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120523 for it and I am trying to figure out how the best way of improving the situtation and not have it fail on anything besides x86_64(!ia32). It is just a minor optimization you can ignore the testcase failure for now. I will have a fix by the end of July (I am on vacation/traveling the second half of June). Thanks, Andrew > > -- > H.J.