From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by sourceware.org (Postfix) with ESMTPS id 26F8F3856DFB for ; Thu, 16 Jun 2022 00:01:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 26F8F3856DFB Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-fb6b4da1dfso38148fac.4 for ; Wed, 15 Jun 2022 17:01:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wwbXftYjQIJQKWpO/JNjytZHAm85AoMLbORdnbWUvhA=; b=mvwNHQmI2A8cGnY3qcBEBUsF91rjg6RagrIOxwFNeXwinAMOaocsBcQ672/9l3hXdP ujCrDo8H0Vs4iQjtmYwLstNs2sMIcPZerV4vz7VebX6dql0iVZznYcEIHasn+9zJ0YtA 5TaN1Qs6i89Cnet96jzjc3p9hFbAgM7RUWMaAoeHjDYQPf5IwEBfnFovnDZxdzw4PwaX lgdyEuvSEZFv+dlPh+xc4uQQdXCXryfskywdRyP831B0+tJ9TJmWAEL6nS2uapCijTpt rWf5j8tyxmy8kH07mWIaLzdDIEftTYm7sexEcdBRRyhUbrDHv1a/EYHmc4qLPpaebMrQ H9hw== X-Gm-Message-State: AJIora/RkFAnxEbqbqFhtnBfUfLeGo1I9vbjdMwzGdrgj5js+RtkGzkO 44OfQfg6NwmDa7sx1bFtYFf8jAvMhn3yxMbDjr4= X-Google-Smtp-Source: AGRyM1vfcgOcMflwHzR4PiZOzh8xzFzOPP3zDJQR4MkDiwni0svZ/9EGlttj+BXMtlKm5Gp8gKQzYuavSt+UZdc2+0g= X-Received: by 2002:a05:6870:e616:b0:fe:9f2:2a76 with SMTP id q22-20020a056870e61600b000fe09f22a76mr1266624oag.55.1655337662420; Wed, 15 Jun 2022 17:01:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Max Filippov Date: Wed, 15 Jun 2022 17:00:52 -0700 Message-ID: Subject: Re: [PATCH v2 2/5] xtensa: Add support for sibling call optimization To: "Takayuki 'January June' Suwa" Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.4 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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: Thu, 16 Jun 2022 00:01:07 -0000 On Wed, Jun 15, 2022 at 5:23 AM Takayuki 'January June' Suwa wrote: > > On 2022/06/15 5:17, Max Filippov wrote: > > Hi Suwa-san, > hi! > > > This change results in a bunch of new regression test failures: > > The code generated for e.g. gcc.c-torture/execute/921208-2.c looks like this: > oh, PICed... > > indirect (incl. via function pointer, virtual functions and of course PIC ones in Xtensa ISA) sibcalls must be avoided if pointer to the target cannot be retained during function epilogue. > otherwise, it will be look like this: > > callx0 a14 > > l32i.n a0, sp, 12 > > l32i.n a14, sp, 0 // restored by the epilogue because A14 is callee-saved > > mov.n a4, a12 > > mov.n a5, a13 > > l32i.n a12, sp, 8 > > l32i.n a13, sp, 4 > > l32r a3, .LC4 > > movi.n a2, 0 > > addi sp, sp, 16 > > jx a14 // but A14 pointed to g@PLT in this function... > > luckily, no role is assigned from A9 to A11 in call0 ABI (A9 is already used inside of the pro/epilogue), and the "split2" stage is prior to "pro_and_epilogue"... > > === > This patch introduces support for sibling call optimization, when call0 > ABI is in effect. > > gcc/ChangeLog: > > * config/xtensa/xtensa-protos.h (xtensa_prepare_expand_call, > xtensa_emit_sibcall): New prototypes. > (xtensa_expand_epilogue): Add new argument that specifies whether > or not sibling call. > * config/xtensa/xtensa.cc (TARGET_FUNCTION_OK_FOR_SIBCALL): > New macro definition. > (xtensa_prepare_expand_call): New function in order to share > the common code. > (xtensa_emit_sibcall, xtensa_function_ok_for_sibcall): > New functions. > (xtensa_expand_epilogue): Add new argument sibcall_p and use it > for sibling call handling. > * config/xtensa/xtensa.md (call, call_value): > Use xtensa_prepare_expand_call. > (call_internal, call_value_internal): > Add the condition in order to be disabled if sibling call. > (sibcall, sibcall_value, sibcall_epilogue): New expansions. > (sibcall_internal, sibcall_value_internal): New insn patterns, > and split ones in order to take care of the indirect sibcalls. > > gcc/testsuite/ChangeLog: > > * gcc.target/xtensa/sibcalls.c: New. > --- > gcc/config/xtensa/xtensa-protos.h | 4 +- > gcc/config/xtensa/xtensa.cc | 58 +++++++++++++- > gcc/config/xtensa/xtensa.md | 93 ++++++++++++++++++---- > gcc/testsuite/gcc.target/xtensa/sibcalls.c | 20 +++++ > 4 files changed, 155 insertions(+), 20 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/xtensa/sibcalls.c Regtested for target=xtensa-linux-uclibc, no new regressions. Committed to master. -- Thanks. -- Max