From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe30.google.com (mail-vs1-xe30.google.com [IPv6:2607:f8b0:4864:20::e30]) by sourceware.org (Postfix) with ESMTPS id 1A1633858CDA for ; Mon, 5 Sep 2022 16:05:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A1633858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vs1-xe30.google.com with SMTP id j6so9268689vsr.0 for ; Mon, 05 Sep 2022 09:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=aMJR5gSHMyUcsKqgLlywpQ1DjUB5tR2KjqWma8IMvvY=; b=FhDQlMlO3oiICIDkkjStzBQS46xBc5NxiY8nWdMtCu9XeeqxbkafDUsnvi97JrWkVU iILJDdgZoAKOQ7p/CX99Es2jjGxDWjxBQiiMMZs2s2duGM1gBWlgk3lgr7PIhRiPGel1 2sv7AlSUXsQO5z9M17FV4IYRllo5OlAWlCEHisoCUu8NMMklGrulmnTSDVu23RSeCZx5 bZ81TY34dmT4mSCfP9limaDn48l7CL+mTQSk3gnVecRgQ6YSqeKWxjaSK+B7E1wYSlvW g+BeduAM8eJnpFjEeC+CvEEkyQMEG95FjZvTJ9e4N9XM6TbbmLcNQeYJYUD/d3WwG5bD 0Cvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=aMJR5gSHMyUcsKqgLlywpQ1DjUB5tR2KjqWma8IMvvY=; b=qJLg9OeOi4N+2uWsxx6lw7RE5TdgsMOWOFev9S+wajZkrKL1CP0WqzFecFddOzAcbT cegUBNbvCozyF1zFHnfgJbmEvjJBdJpoWmHjFqLA9kv8/GTiDdta1rhyq0P84YHPDzyb 97e9bbTuwG/Vqxps8BwTxNpKM/SMwwnyT7zhRObNLh3++0ozsMGfPaocIY/D3hbR9NE6 ONkV7jORCcAYR3DcafptK2ZpX0JAa4IxqVIFs/Cfsy2aWkET4rB8vmFJNB67Sgx9UI1u MnEPUfjXgjzU4PYYc52QUNnOEdbcU++OomCvnpMmUNIBfkWE6idR8U0Dv86AhAmPiVTU zPRw== X-Gm-Message-State: ACgBeo1jXttiEFyIMonVxEJRqLYbwzmJ5zxmQJam4avzJ3zRhgMhmIc7 vRKxeBHEFx+VY5mH+DgZPh4LVZV5evmO+upfqfU= X-Google-Smtp-Source: AA6agR6lB3xABbi4G1OaRSp4mGBrdqcxJBDLVJUcpyMZqKcZOz/xLahzyUzQp1O8seNUR1GLPDJ9NfBJMoxZBOX2E54= X-Received: by 2002:a67:fbd1:0:b0:390:df68:b310 with SMTP id o17-20020a67fbd1000000b00390df68b310mr13567679vsr.85.1662393918407; Mon, 05 Sep 2022 09:05:18 -0700 (PDT) MIME-Version: 1.0 References: <912096ce-3910-dd5f-cfb3-f196bf5b9ae5@yahoo.co.jp> In-Reply-To: <912096ce-3910-dd5f-cfb3-f196bf5b9ae5@yahoo.co.jp> From: Max Filippov Date: Mon, 5 Sep 2022 09:05:06 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] xtensa: Eliminate unused stack frame allocation/freeing To: "Takayuki 'January June' Suwa" Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Suwa-san, On Fri, Sep 2, 2022 at 3:57 AM Takayuki 'January June' Suwa wrote: > > Changes from v1: > (xtensa_expand_epilogue): Fixed forgetting to consider hard_frame_point= er_rtx when sharing codes. > > --- > In the example below, 'x' is once placed on the stack frame and then read > into registers as the argument value of bar(): > > /* example */ > struct foo { > int a, b; > }; > extern struct foo bar(struct foo); > struct foo test(void) { > struct foo x =3D { 0, 1 }; > return bar(x); > } > > Thanks to the dead store elimination, the initialization of 'x' turns int= o > merely loading the immediates to registers, but corresponding stack frame > growth is not rolled back. As a result: > > ;; prereq: the CALL0 ABI > ;; before > test: > addi sp, sp, -16 // unused stack frame allocation/freeing > movi.n a2, 0 > movi.n a3, 1 > addi sp, sp, 16 // because no instructions that refer to > j.l bar, a9 // the stack pointer between the two > > This patch eliminates such unused stack frame allocation/freeing: > > ;; after > test: > movi.n a2, 0 > movi.n a3, 1 > j.l bar, a9 > > gcc/ChangeLog: > > * config/xtensa/xtensa.cc (machine_function): New member to track > the insns for stack pointer adjustment inside of the pro/epilogue= . > (xtensa_emit_adjust_stack_ptr): New function to share the common > codes and to record the insns for stack pointer adjustment. > (xtensa_expand_prologue): Change to use the function mentioned > above when using the CALL0 ABI. > (xtensa_expand_epilogue): Ditto. > And also change to cancel emitting the insns for the stack pointe= r > adjustment if only used for its own. > --- > gcc/config/xtensa/xtensa.cc | 230 ++++++++++++++++++------------------ > 1 file changed, 118 insertions(+), 112 deletions(-) With this change xtensa-linux-uclibc configured for call0 ABI produces ICE while building libgcc: gcc/libgcc/libgcc2.c: In function =E2=80=98__divdi3=E2=80=99: gcc/libgcc/libgcc2.c:1230:1: internal compiler error: Segmentation fault 1230 | } | ^ 0xea801f crash_signal gcc/gcc/toplev.cc:314 0x7f1fb4be5d5f ??? ./signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 0x9602e3 lookup_page_table_entry gcc/gcc/ggc-page.cc:630 0x9602e3 ggc_set_mark(void const*) gcc/gcc/ggc-page.cc:1550 0x121d7bd gt_ggc_mx_hash_set_rtx_insn__(void*) ./gt-xtensa.h:38 0xbe6187 gt_ggc_mx_function(void*) gcc-13-2434-g2f4d626e13dc-call0-le/gcc/gtype-desc.cc:1694 0xbe6187 gt_ggc_mx_function(void*) gcc-13-2434-g2f4d626e13dc-call0-le/gcc/gtype-desc.cc:1678 0x85634a gt_ggc_mx_lang_tree_node(void*) ./gt-c-c-decl.h:289 0xbe07d2 gt_ggc_mx_rtx_def(void*) gcc-13-2434-g2f4d626e13dc-call0-le/gcc/gtype-desc.cc:725 0xa47074 void gt_ggc_mx(vec*) gcc/gcc/vec.h:1363 0xa47074 gt_ggc_mx_vec_dw_attr_node_va_gc_(void*) ./gt-dwarf2out.h:261 0xa47074 gt_ggc_mx_vec_dw_attr_node_va_gc_(void*) ./gt-dwarf2out.h:256 0xa47074 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:45 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:27 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:47 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:27 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:47 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:27 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:47 0xa470d7 gt_ggc_mx_die_struct(void*) ./gt-dwarf2out.h:27 --=20 Thanks. -- Max