Go to file
Roger Sayle ed6fd2aed5 PR middle-end/95126: Expand small const structs as immediate constants.
This patch resolves PR middle-end/95126 which is a code quality regression,
by teaching the RTL expander to emit small const structs/unions as integer
immediate constants.

The motivating example from the bugzilla PR is:

struct small{ short a,b; signed char c; };
extern int func(struct small X);
void call_func(void)
{
    static struct small const s = { 1, 2, 0 };
    func(s);
}

which on x86_64 is currently compiled to:

call_func:
        movzwl  s.0+2(%rip), %eax
        movzwl  s.0(%rip), %edx
        movzwl  s.0+4(%rip), %edi
        salq    $16, %rax
        orq     %rdx, %rax
        salq    $32, %rdi
        orq     %rax, %rdi
        jmp     func

but with this patch is now optimized to:

call_func:
        movl    $131073, %edi
        jmp     func

2022-06-04  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	PR middle-end/95126
	* calls.cc (load_register_parameters): When loading a suitable
	immediate_const_ctor_p VAR_DECL into a single word_mode register,
	construct it directly in a pseudo rather than read it (by parts)
	from memory.
	* expr.cc (int_expr_size): Make tree argument a const_tree.
	(immediate_const_ctor_p): Helper predicate.  Return true for
	simple constructors that may be materialized in a register.
	(expand_expr_real_1) [VAR_DECL]: When expanding a constant
	VAR_DECL with a suitable immediate_const_ctor_p constructor
	use store_constructor to materialize it directly in a pseudo.
	* expr.h (immediate_const_ctor_p): Prototype here.
	* varasm.cc (initializer_constant_valid_for_bitfield_p): Change
	VALUE argument from tree to const_tree.
	* varasm.h (initializer_constant_valid_for_bitfield_p): Update
	prototype.

gcc/testsuite/ChangeLog
	PR middle-end/95126
	* gcc.target/i386/pr95126-m32-1.c: New test case.
	* gcc.target/i386/pr95126-m32-2.c: New test case.
	* gcc.target/i386/pr95126-m32-3.c: New test case.
	* gcc.target/i386/pr95126-m32-4.c: New test case.
	* gcc.target/i386/pr95126-m64-1.c: New test case.
	* gcc.target/i386/pr95126-m64-2.c: New test case.
	* gcc.target/i386/pr95126-m64-3.c: New test case.
	* gcc.target/i386/pr95126-m64-4.c: New test case.
2022-06-04 12:21:51 +01:00
c++tools Daily bump. 2022-03-19 00:16:22 +00:00
config Daily bump. 2022-06-02 00:16:32 +00:00
contrib Daily bump. 2022-05-28 00:16:40 +00:00
fixincludes Daily bump. 2022-02-28 00:16:17 +00:00
gcc PR middle-end/95126: Expand small const structs as immediate constants. 2022-06-04 12:21:51 +01:00
gnattools
gotools
include Daily bump. 2022-06-01 00:16:34 +00:00
INSTALL
intl
libada
libatomic Daily bump. 2022-06-03 00:16:40 +00:00
libbacktrace Daily bump. 2022-05-29 00:16:31 +00:00
libcc1 Daily bump. 2022-06-02 00:16:32 +00:00
libcody Daily bump. 2022-06-04 00:16:27 +00:00
libcpp Daily bump. 2022-05-30 00:16:21 +00:00
libdecnumber Daily bump. 2022-05-21 00:16:32 +00:00
libffi
libgcc Daily bump. 2022-06-02 00:16:32 +00:00
libgfortran
libgo runtime: use correct field name for PPC32 GLIBC registers 2022-04-20 17:49:44 -07:00
libgomp Daily bump. 2022-06-04 00:16:27 +00:00
libiberty Daily bump. 2022-05-24 00:17:03 +00:00
libitm Daily bump. 2022-06-03 00:16:40 +00:00
libobjc
liboffloadmic
libphobos Daily bump. 2022-06-03 00:16:40 +00:00
libquadmath
libsanitizer Daily bump. 2022-05-06 00:16:26 +00:00
libssp
libstdc++-v3 Daily bump. 2022-05-28 00:16:40 +00:00
libvtv
lto-plugin Daily bump. 2022-05-05 00:16:29 +00:00
maintainer-scripts Daily bump. 2022-05-21 00:16:32 +00:00
zlib
.dir-locals.el
.gitattributes
.gitignore Vim swap files not ignored 2022-05-28 09:38:29 -06:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2022-05-29 00:16:31 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure LoongArch Port: Regenerate configure 2022-03-29 17:43:32 +08:00
configure.ac LoongArch Port: Regenerate configure 2022-03-29 17:43:32 +08:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Add myself to write after approval 2022-05-13 09:30:38 -05:00
Makefile.def toplevel: Makefile.def: Make configure-sim depend on all-readline 2022-03-09 20:54:37 +01:00
Makefile.in toplevel: Makefile.def: Make configure-sim depend on all-readline 2022-03-09 20:54:37 +01:00
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.