poly_int64 size = 0;
HOST_WIDE_INT const_size = 0;
rtx_insn *before_arg = get_last_insn ();
- tree type = TREE_TYPE (args[i].tree_value);
+ tree tree_value = args[i].tree_value;
+ tree type = TREE_TYPE (tree_value);
if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type))
type = TREE_TYPE (first_field (type));
/* Set non-negative if we must move a word at a time, even if
emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
args[i].aligned_regs[j]);
+ /* If we need a single register and the source is a constant
+ VAR_DECL with a simple constructor, expand that constructor
+ via a pseudo rather than read from (possibly misaligned)
+ memory. PR middle-end/95126. */
+ else if (nregs == 1
+ && partial == 0
+ && !args[i].pass_on_stack
+ && VAR_P (tree_value)
+ && TREE_READONLY (tree_value)
+ && !TREE_SIDE_EFFECTS (tree_value)
+ && immediate_const_ctor_p (DECL_INITIAL (tree_value)))
+ {
+ rtx target = gen_reg_rtx (word_mode);
+ rtx x = expand_expr (DECL_INITIAL (tree_value),
+ target, word_mode, EXPAND_NORMAL);
+ reg = gen_rtx_REG (word_mode, REGNO (reg));
+ emit_move_insn (reg, x);
+ }
else if (partial == 0 || args[i].pass_on_stack)
{
/* SIZE and CONST_SIZE are 0 for partial arguments and
profile_probability);
static rtx const_vector_from_tree (tree);
static tree tree_expr_size (const_tree);
-static HOST_WIDE_INT int_expr_size (tree);
+static HOST_WIDE_INT int_expr_size (const_tree);
static void convert_mode_scalar (rtx, rtx, int);
\f
return false;
}
}
- emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
+
+ /* If source is a constant VAR_DECL with a simple constructor,
+ store the constructor to the stack instead of moving it. */
+ const_tree decl;
+ if (partial == 0
+ && MEM_P (xinner)
+ && SYMBOL_REF_P (XEXP (xinner, 0))
+ && (decl = SYMBOL_REF_DECL (XEXP (xinner, 0))) != NULL_TREE
+ && VAR_P (decl)
+ && TREE_READONLY (decl)
+ && !TREE_SIDE_EFFECTS (decl)
+ && immediate_const_ctor_p (DECL_INITIAL (decl), 2))
+ store_constructor (DECL_INITIAL (decl), target, 0,
+ int_expr_size (DECL_INITIAL (decl)), false);
+ else
+ emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
}
}
else if (partial > 0)
p_init_elts, p_complete);
}
+/* Return true if constructor CTOR is simple enough to be materialized
+ in an integer mode register. Limit the size to WORDS words, which
+ is 1 by default. */
+
+bool
+immediate_const_ctor_p (const_tree ctor, unsigned int words)
+{
+ /* Allow function to be called with a VAR_DECL's DECL_INITIAL. */
+ if (!ctor || TREE_CODE (ctor) != CONSTRUCTOR)
+ return false;
+
+ return TREE_CONSTANT (ctor)
+ && !TREE_ADDRESSABLE (ctor)
+ && CONSTRUCTOR_NELTS (ctor)
+ && TREE_CODE (TREE_TYPE (ctor)) != ARRAY_TYPE
+ && int_expr_size (ctor) <= words * UNITS_PER_WORD
+ && initializer_constant_valid_for_bitfield_p (ctor);
+}
+
/* TYPE is initialized by a constructor with NUM_ELTS elements, the last
of which had type LAST_TYPE. Each element was itself a complete
initializer, in the sense that every meaningful byte was explicitly
if (temp)
return temp;
}
+ /* Expand const VAR_DECLs with CONSTRUCTOR initializers that
+ have scalar integer modes to a reg via store_constructor. */
+ if (TREE_READONLY (exp)
+ && !TREE_SIDE_EFFECTS (exp)
+ && (modifier == EXPAND_NORMAL || modifier == EXPAND_STACK_PARM)
+ && immediate_const_ctor_p (DECL_INITIAL (exp))
+ && SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (exp)))
+ && crtl->emit.regno_pointer_align_length
+ && !target)
+ {
+ target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
+ store_constructor (DECL_INITIAL (exp), target, 0,
+ int_expr_size (DECL_INITIAL (exp)), false);
+ return target;
+ }
/* ... fall through ... */
case PARM_DECL:
if the size can vary or is larger than an integer. */
static HOST_WIDE_INT
-int_expr_size (tree exp)
+int_expr_size (const_tree exp)
{
tree size;
extern bool categorize_ctor_elements (const_tree, HOST_WIDE_INT *,
HOST_WIDE_INT *, HOST_WIDE_INT *,
bool *);
+extern bool immediate_const_ctor_p (const_tree, unsigned int words = 1);
extern void expand_operands (tree, tree, rtx, rtx*, rtx*,
enum expand_modifier);
--- /dev/null
+/* { dg-do compile { target { ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a,b; signed char c; };
+
+void call_func(void)
+{
+ extern int func(struct small X);
+ static struct small const s = { 1,2,0 };
+ func(s);
+}
+
+/* { dg-final { scan-assembler "movl\[ \\t]*\\\$" } } */
+/* { dg-final { scan-assembler "movb\[ \\t]*\\\$0, " } } */
+/* { dg-final { scan-assembler-not "movzwl" } } */
+
--- /dev/null
+/* { dg-do compile { target { ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a,b; signed char c; };
+static const struct small s = { 1,2,0 };
+extern int func(struct small X);
+
+void call_func(void)
+{
+ func(s);
+}
+
+/* { dg-final { scan-assembler "movl\[ \\t]*\\\$" } } */
+/* { dg-final { scan-assembler "movb\[ \\t]*\\\$0, " } } */
+/* { dg-final { scan-assembler-not "movzwl" } } */
+
--- /dev/null
+/* { dg-do compile { target { ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a; };
+
+void call_func(void)
+{
+ extern int func(struct small X);
+ static struct small const s = { 2 };
+ func(s);
+}
+
+/* { dg-final { scan-assembler "pushl\[ \\t]*\\\$2" } } */
+/* { dg-final { scan-assembler-not "movzwl" } } */
+
--- /dev/null
+/* { dg-do compile { target { ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a,b; };
+
+void call_func(void)
+{
+ extern int func(struct small X);
+ static struct small const s = { 1,2 };
+ func(s);
+}
+
+/* { dg-final { scan-assembler "pushl\[ \\t]*\\\$131073" } } */
--- /dev/null
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a,b; signed char c; };
+
+void call_func(void)
+{
+ extern int func(struct small X);
+ static struct small const s = { 1,2,0 };
+ func(s);
+}
+
+/* { dg-final { scan-assembler "movl\[ \\t]*\\\$131073, " } } */
+/* { dg-final { scan-assembler-not "movzwl" } } */
+/* { dg-final { scan-assembler-not "salq" } } */
+/* { dg-final { scan-assembler-not "orq" } } */
+
--- /dev/null
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a,b; signed char c; };
+static const struct small s = { 1,2,0 };
+extern int func(struct small X);
+
+void call_func(void)
+{
+ func(s);
+}
+
+/* { dg-final { scan-assembler "movl\[ \\t]*\\\$131073, " } } */
+/* { dg-final { scan-assembler-not "movzwl" } } */
+/* { dg-final { scan-assembler-not "salq" } } */
+/* { dg-final { scan-assembler-not "orq" } } */
+
--- /dev/null
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a; };
+
+void call_func(void)
+{
+ extern int func(struct small X);
+ static struct small const s = { 2 };
+ func(s);
+}
+
+/* { dg-final { scan-assembler "movl\[ \\t]*\\\$2, " } } */
+/* { dg-final { scan-assembler-not "movzwl" } } */
--- /dev/null
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2" } */
+
+struct small{ short a,b; };
+
+void call_func(void)
+{
+ extern int func(struct small X);
+ static struct small const s = { 1,2 };
+ func(s);
+}
+
+/* { dg-final { scan-assembler "movl\[ \\t]*\\\$131073, " } } */
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. */
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))
/* Return true if VALUE is a valid constant-valued expression
for use in initializing a static bit-field; one that can be
an element of a "constant" initializer. */
-extern bool initializer_constant_valid_for_bitfield_p (tree);
+extern bool initializer_constant_valid_for_bitfield_p (const_tree);
/* Whether a constructor CTOR is a valid static constant initializer if all
its elements are. This used to be internal to initializer_constant_valid_p