aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.cc
diff options
context:
space:
mode:
authorRoger Sayle <roger@nextmovesoftware.com>2022-06-04 12:21:51 +0100
committerRoger Sayle <roger@nextmovesoftware.com>2022-06-04 12:21:51 +0100
commited6fd2aed58f2cca99f15331bf68999c0e6df370 (patch)
treef45d2ecac85e6636ee9ec5ce1ecbe7b3fc771e5c /gcc/varasm.cc
parent53718316afa45eb0d1c236fbbf2fc0959b08510f (diff)
downloadgcc-ed6fd2aed58f2cca99f15331bf68999c0e6df370.zip
gcc-ed6fd2aed58f2cca99f15331bf68999c0e6df370.tar.gz
gcc-ed6fd2aed58f2cca99f15331bf68999c0e6df370.tar.bz2
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.
Diffstat (limited to 'gcc/varasm.cc')
-rw-r--r--gcc/varasm.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 6454f1c..826a9ca 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -5069,7 +5069,7 @@ initializer_constant_valid_p (tree value, tree endtype, bool reverse)
an element of a "constant" initializer. */
bool
-initializer_constant_valid_for_bitfield_p (tree value)
+initializer_constant_valid_for_bitfield_p (const_tree value)
{
/* For bitfields we support integer constants or possibly nested aggregates
of such. */
@@ -5078,7 +5078,7 @@ initializer_constant_valid_for_bitfield_p (tree value)
case CONSTRUCTOR:
{
unsigned HOST_WIDE_INT idx;
- tree elt;
+ const_tree elt;
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
if (!initializer_constant_valid_for_bitfield_p (elt))