Skip to content

Commit c00e1e3

Browse files
committed
PR middle-end/105853: Call store_constructor directly from calls.cc.
This patch fixes both ICE regressions PR middle-end/105853 and PR target/105856 caused by my recent patch to expand small const structs as immediate constants. That patch updated code generation in three places: two in expr.cc that call store_constructor directly, and the third in calls.cc's load_register_parameters that expands its CONSTRUCTOR via expand_expr, as store_constructor is local/static to expr.cc, and the "public" API, should usually simply forward the constructor to the appropriate store_constructor function. Alas, despite the clean regression testing on multiple targets, the above ICEs show that expand_expr isn't a suitable proxy for store_constructor, and things that (I'd assumed) shouldn't affect how/whether a struct is placed in a register [such as whether the struct is considered packed/ aligned or not] actually interfere with the optimization that is being attempted. The (proposed) solution is to export store_constructor (and it's helper function int_expr_size) from expr.cc, by removing their static qualifier and prototyping both functions in expr.h, so they can be called directly from load_register_parameters in calls.cc. This cures both ICEs, but almost as importantly improves code generation over GCC 12. For PR 105853, GCC 12 generates: compose_nd_na_ipv6_src: movzx eax, WORD PTR eth_addr_zero[rip+2] movzx edx, WORD PTR eth_addr_zero[rip] movzx edi, WORD PTR eth_addr_zero[rip+4] sal rax, 16 or rax, rdx sal rdi, 32 or rdi, rax xor eax, eax jmp packet_set_nd eth_addr_zero: .zero 6 where now (with this fix) GCC 13 generates: compose_nd_na_ipv6_src: xorl %edi, %edi xorl %eax, %eax jmp packet_set_nd Likewise, for PR 105856 on ARM, we'd previously generate: g_329_3: movw r3, #:lower16:.LANCHOR0 movt r3, #:upper16:.LANCHOR0 ldr r0, [r3] b func_19 but with this optimization we now generate: g_329_3: mov r0, gcc-mirror#6 b func_19 2022-06-07 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog PR middle-end/105853 PR target/105856 * calls.cc (load_register_parameters): Call store_constructor and int_expr_size directly instead of expanding via expand_expr. * expr.cc (static void store_constructor): Don't prototype here. (static HOST_WIDE_INT int_expr_size): Likewise. (store_constructor): No longer static. (int_expr_size): Likewise, no longer static. * expr.h (store_constructor): Prototype here. (int_expr_size): Prototype here. gcc/testsuite/ChangeLog PR middle-end/105853 PR target/105856 * gcc.dg/pr105853.c: New test case. * gcc.dg/pr105856.c: New test case.
1 parent cef3f69 commit c00e1e3

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

gcc/calls.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,10 +2186,11 @@ load_register_parameters (struct arg_data *args, int num_actuals,
21862186
&& immediate_const_ctor_p (DECL_INITIAL (tree_value)))
21872187
{
21882188
rtx target = gen_reg_rtx (word_mode);
2189-
rtx x = expand_expr (DECL_INITIAL (tree_value),
2190-
target, word_mode, EXPAND_NORMAL);
2189+
store_constructor (DECL_INITIAL (tree_value), target, 0,
2190+
int_expr_size (DECL_INITIAL (tree_value)),
2191+
false);
21912192
reg = gen_rtx_REG (word_mode, REGNO (reg));
2192-
emit_move_insn (reg, x);
2193+
emit_move_insn (reg, target);
21932194
}
21942195
else if (partial == 0 || args[i].pass_on_stack)
21952196
{

gcc/expr.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
8484
static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
8585
static rtx_insn *compress_float_constant (rtx, rtx);
8686
static rtx get_subtarget (rtx);
87-
static void store_constructor (tree, rtx, int, poly_int64, bool);
8887
static rtx store_field (rtx, poly_int64, poly_int64, poly_uint64, poly_uint64,
8988
machine_mode, tree, alias_set_type, bool, bool);
9089

@@ -100,7 +99,6 @@ static void do_tablejump (rtx, machine_mode, rtx, rtx, rtx,
10099
profile_probability);
101100
static rtx const_vector_from_tree (tree);
102101
static tree tree_expr_size (const_tree);
103-
static HOST_WIDE_INT int_expr_size (const_tree);
104102
static void convert_mode_scalar (rtx, rtx, int);
105103

106104

@@ -6757,7 +6755,7 @@ fields_length (const_tree type)
67576755
which has been packed to exclude padding bits.
67586756
If REVERSE is true, the store is to be done in reverse order. */
67596757

6760-
static void
6758+
void
67616759
store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
67626760
bool reverse)
67636761
{
@@ -13209,7 +13207,7 @@ expr_size (tree exp)
1320913207
/* Return a wide integer for the size in bytes of the value of EXP, or -1
1321013208
if the size can vary or is larger than an integer. */
1321113209

13212-
static HOST_WIDE_INT
13210+
HOST_WIDE_INT
1321313211
int_expr_size (const_tree exp)
1321413212
{
1321513213
tree size;

gcc/expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ extern bool categorize_ctor_elements (const_tree, HOST_WIDE_INT *,
339339
HOST_WIDE_INT *, HOST_WIDE_INT *,
340340
bool *);
341341
extern bool immediate_const_ctor_p (const_tree, unsigned int words = 1);
342+
extern void store_constructor (tree, rtx, int, poly_int64, bool);
343+
extern HOST_WIDE_INT int_expr_size (const_tree exp);
342344

343345
extern void expand_operands (tree, tree, rtx, rtx*, rtx*,
344346
enum expand_modifier);

gcc/testsuite/gcc.dg/pr105853.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2" } */
3+
4+
struct {
5+
struct {
6+
short e16[3];
7+
}
8+
} const eth_addr_zero = {{}}; /* { dg-warning "no semicolon at" } */
9+
void compose_nd_na_ipv6_src() {
10+
packet_set_nd(eth_addr_zero); /* { dg-warning "implicit declaration" } */
11+
}

gcc/testsuite/gcc.dg/pr105856.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2" } */
3+
#pragma pack(1)
4+
struct {
5+
unsigned f0;
6+
} static g_251 = {6};
7+
void g_329_3() {
8+
func_19(g_251); /* { dg-warning "implicit declaration" } */
9+
}
10+

0 commit comments

Comments
 (0)