From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id BAC793836E40 for ; Mon, 6 Jun 2022 13:50:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BAC793836E40 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wwymb+FS7DpaFDUXjo6VyKg88PhMzvDdj8EMZO18JiQ=; b=sPOk/FrLPRTJMlaf8vKsD2kFKB P/bFoHnNqNwi5gAZJGDtTKVO8mAb41sfOybL/2l5CilhsyhYQTXdFMEOWG10pidx7BULs0WQCM/ei 1dnFo3/FIywYfaaNo4j40Cw/wOemaKM35G/e1BPTGbUKlxtQ2nckPmgTZV0xIaQkZeLwX7mjlCkBm SaU3OafgRw6bmu4G1FWypL6b4KOjW9x3H+7NTW7QzNYYAvdhmNlEBOUrFfvbWxKICKK4WDKdIIR31 /pDNBkpV5JWP11+fAdU8BkWYMXpDZr9v45FYeN+yTKyY4p+VBpzj1dtc3qQmUFBVqXyZKCVMnQREx oUx8gqSg==; Received: from [185.62.158.67] (port=61732 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nyD7U-00067S-0V; Mon, 06 Jun 2022 09:50:12 -0400 From: "Roger Sayle" To: Subject: [PATCH] PR middle-end/105853: Call store_constructor directly from calls.cc. Date: Mon, 6 Jun 2022 14:50:11 +0100 Message-ID: <001601d879ac$584d33e0$08e79ba0$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0017_01D879B4.BA119BE0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adh5q2bBWLB3pk0fTVukGyF13tZ9Aw== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jun 2022 13:50:14 -0000 This is a multipart message in MIME format. ------=_NextPart_000_0017_01D879B4.BA119BE0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 important produces much better code generation than 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, #6 b func_19 This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new failures. I've also confirmed that on a cross-compiler to arm-linux-gnueabihf --with-arch=armv6 this fixes the target specific ICE in PR105856. The make check is currently running with --target_board=unix{-m32}, OK for mainline if that also passes? My sincere apologies for the inconvenience. 2022-06-06 Roger Sayle 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. Roger -- ------=_NextPart_000_0017_01D879B4.BA119BE0 Content-Type: text/plain; name="patchar.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchar.txt" diff --git a/gcc/calls.cc b/gcc/calls.cc=0A= index a4336c1..f4e1299 100644=0A= --- a/gcc/calls.cc=0A= +++ b/gcc/calls.cc=0A= @@ -2186,10 +2186,11 @@ load_register_parameters (struct arg_data *args, = int num_actuals,=0A= && immediate_const_ctor_p (DECL_INITIAL (tree_value)))=0A= {=0A= rtx target =3D gen_reg_rtx (word_mode);=0A= - rtx x =3D expand_expr (DECL_INITIAL (tree_value),=0A= - target, word_mode, EXPAND_NORMAL);=0A= + store_constructor (DECL_INITIAL (tree_value), target, 0,=0A= + int_expr_size (DECL_INITIAL (tree_value)),=0A= + false);=0A= reg =3D gen_rtx_REG (word_mode, REGNO (reg));=0A= - emit_move_insn (reg, x);=0A= + emit_move_insn (reg, target);=0A= }=0A= else if (partial =3D=3D 0 || args[i].pass_on_stack)=0A= {=0A= diff --git a/gcc/expr.cc b/gcc/expr.cc=0A= index fb062dc..85cb414 100644=0A= --- a/gcc/expr.cc=0A= +++ b/gcc/expr.cc=0A= @@ -84,7 +84,6 @@ static void emit_block_move_via_loop (rtx, rtx, rtx, = unsigned);=0A= static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);=0A= static rtx_insn *compress_float_constant (rtx, rtx);=0A= static rtx get_subtarget (rtx);=0A= -static void store_constructor (tree, rtx, int, poly_int64, bool);=0A= static rtx store_field (rtx, poly_int64, poly_int64, poly_uint64, = poly_uint64,=0A= machine_mode, tree, alias_set_type, bool, bool);=0A= =0A= @@ -100,7 +99,6 @@ static void do_tablejump (rtx, machine_mode, rtx, = rtx, rtx,=0A= profile_probability);=0A= static rtx const_vector_from_tree (tree);=0A= static tree tree_expr_size (const_tree);=0A= -static HOST_WIDE_INT int_expr_size (const_tree);=0A= static void convert_mode_scalar (rtx, rtx, int);=0A= =0A= =0C=0A= @@ -6757,7 +6755,7 @@ fields_length (const_tree type)=0A= which has been packed to exclude padding bits.=0A= If REVERSE is true, the store is to be done in reverse order. */=0A= =0A= -static void=0A= +void=0A= store_constructor (tree exp, rtx target, int cleared, poly_int64 size,=0A= bool reverse)=0A= {=0A= @@ -13209,7 +13207,7 @@ expr_size (tree exp)=0A= /* Return a wide integer for the size in bytes of the value of EXP, or = -1=0A= if the size can vary or is larger than an integer. */=0A= =0A= -static HOST_WIDE_INT=0A= +HOST_WIDE_INT=0A= int_expr_size (const_tree exp)=0A= {=0A= tree size;=0A= diff --git a/gcc/expr.h b/gcc/expr.h=0A= index d777c28..0351183 100644=0A= --- a/gcc/expr.h=0A= +++ b/gcc/expr.h=0A= @@ -339,6 +339,8 @@ extern bool categorize_ctor_elements (const_tree, = HOST_WIDE_INT *,=0A= HOST_WIDE_INT *, HOST_WIDE_INT *,=0A= bool *);=0A= extern bool immediate_const_ctor_p (const_tree, unsigned int words =3D = 1);=0A= +extern void store_constructor (tree, rtx, int, poly_int64, bool);=0A= +extern HOST_WIDE_INT int_expr_size (const_tree exp);=0A= =0A= extern void expand_operands (tree, tree, rtx, rtx*, rtx*,=0A= enum expand_modifier);=0A= diff --git a/gcc/testsuite/gcc.dg/pr105853.c = b/gcc/testsuite/gcc.dg/pr105853.c=0A= new file mode 100644=0A= index 0000000..4f234ac=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.dg/pr105853.c=0A= @@ -0,0 +1,11 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2" } */=0A= +=0A= +struct {=0A= + struct {=0A= + short e16[3];=0A= + }=0A= +} const eth_addr_zero =3D {{}}; /* { dg-warning "no semicolon at" } */=0A= +void compose_nd_na_ipv6_src() {=0A= + packet_set_nd(eth_addr_zero); /* { dg-warning "implicit declaration" = } */=0A= +}=0A= diff --git a/gcc/testsuite/gcc.dg/pr105856.c = b/gcc/testsuite/gcc.dg/pr105856.c=0A= new file mode 100644=0A= index 0000000..dd3aa2f=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.dg/pr105856.c=0A= @@ -0,0 +1,10 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2" } */=0A= +#pragma pack(1)=0A= +struct {=0A= + unsigned f0;=0A= +} static g_251 =3D {6};=0A= +void g_329_3() {=0A= + func_19(g_251); /* { dg-warning "implicit declaration" } */=0A= +}=0A= +=0A= ------=_NextPart_000_0017_01D879B4.BA119BE0--