https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120523
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:f1c8014764178335e3b949e06b894ff5775beae5 commit r16-2595-gf1c8014764178335e3b949e06b894ff5775beae5 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Fri Jul 25 16:16:36 2025 -0700 Improve mergability of CSWTCH [PR120523] When I did r16-1067-gaa935ce40a7, I thought it would be enough to mark the decl as mergable to get it to merge on all targets. Turns out a few things needed to be changed to support it being mergable on all targets. The first thing is improve the selecting of the mergable section and instead of basing it on the DECL's mode, it should be based on the size instead. The second thing that needed to be happen is change the alignment of the CSWTCH decl to be aligned to the next power of 2 compared to the size if the size is less than 32bytes (the max mergable size that is supported). With these changes, cswtch-6.c passes on ia32 and other targets. And the new testcase cswtch-7.c will pass now too. Note I noticed the darwin's darwin_mergeable_constant_section could be "fixed" up to use DECL_SIZE instead of the DECL_MODE but I am not sure it makes a huge difference. Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/120523 gcc/ChangeLog: * output.h (mergeable_constant_section): New declaration taking unsigned HOST_WIDE_INT for the size. * tree-switch-conversion.cc (switch_conversion::build_one_array): Increase the alignment of CSWTCH for sizes less than 32bytes. * varasm.cc (mergeable_constant_section): Split out twice. One that takes the size in unsigned HOST_WIDE_INT and the other size in a tree. (default_elf_select_section): Pass DECL_SIZE instead of DECL_MODE to mergeable_constant_section. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/cswtch-7.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>