From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa2d.google.com (mail-vk1-xa2d.google.com [IPv6:2607:f8b0:4864:20::a2d]) by sourceware.org (Postfix) with ESMTPS id BB09A3858428 for ; Wed, 7 Sep 2022 14:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB09A3858428 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-vk1-xa2d.google.com with SMTP id s11so3027992vkb.5 for ; Wed, 07 Sep 2022 07:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=GnVszwtqlbeB7fN2uojVYRmpxoZDkng15PqMZnt933A=; b=EJoxLfqB695iHgwrpu6T+HLq9Eo6/pJQSz5sAK8zhmKSbEg/oL7+80RorKBkPceqgk AdJ8NNLQqHiO8hc3twpt+qKzUCicazKafGiZa/58AYNf4bQdI0qx+VdQoGa27+RiYqyL vYH6Q2IWTGX7L0+aZHUckldKfE0Wvan4bS82ZvWSnGTjCaDdXqhm3Q/jiQjSW/aFPN7s OMmH3PH5vGboJj/97Za8d2MktkbuiBV73sZmZJe83WxPiT2KByG7XKNmqIfSPy+k2stL u2zScBxr0sQnK53P1l39LLAtiyuiCEzu5+8Fu8bIipL1TpA9bffaez4Yu/WQDW4n1WLP 73tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=GnVszwtqlbeB7fN2uojVYRmpxoZDkng15PqMZnt933A=; b=aYbT2pybH2PVRXP2P0pOlSZLaUwGmHQ4jYDLfujy7G9S0cSUry24XRHZzV54hoe/I5 Uttcgk89o7IMPL7076LFc8AYqcAJ62E/y0p1JgOXKxL6+wcLEPyPeWe6v+f/wtl+iUDr 31gsKs/159k3g16e+tAYyydOO9UZVRlK8ZHLOlZZM3ApLw21FvKkb+WaYmcjyLcQtEhq 5xtt5g/cMRWT/Tth5BkWK8eSWtzhklC3tkzXMK7JOZN92j++PigCfebC+XoYuK4HkoSE xir+C4qmiXAG02UlOab+PJSuJUB8YyAEDJgb07lxKtyQ/jOaXf5REs1gDJsP8Cr8yUVg u69w== X-Gm-Message-State: ACgBeo36OxWWvMrHpv5z64MRv6GAnk6wbHF7l2n5a2/1/r68XngP2pIz 8aUENy/zuYH70PeZyMFWvBUj3xNy7R22m9NFv1R+To0Y5gtm8g== X-Google-Smtp-Source: AA6agR4h7U/NpCwjTuqWNli8L0fOjFLanzhIBYIrIaEcA/ZcoRysulv2n5x/oOxFn+VXNBISLzWJJAoZNxe+5T/OIDc= X-Received: by 2002:a1f:2f43:0:b0:381:9296:91d4 with SMTP id v64-20020a1f2f43000000b00381929691d4mr1225005vkv.33.1662562570053; Wed, 07 Sep 2022 07:56:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Max Filippov Date: Wed, 7 Sep 2022 07:55:58 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] xtensa: Eliminate unused stack frame allocation/freeing To: "Takayuki 'January June' Suwa" Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.8 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 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 Wed, Sep 7, 2022 at 2:08 AM Takayuki 'January June' Suwa wrote: > > Changes from v2: > (xtensa_expand_prologue): Changed to check conditions for suppressing emit insns in advance, instead of tracking emitted and later replacing them with NOPs if they are found to be unnecessary. > > --- > > 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 = { 0, 1 }; > return bar(x); > } > > Thanks to the dead store elimination, the initialization of 'x' turns into > 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 boolean member as > a flag that controls whether to emit 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 emit insns if not inhibited. > (xtensa_expand_epilogue): Change to use the function mentioned > above when using the CALL0 ABI. > (xtensa_expand_prologue): Ditto. > And also change to set the inhibit flag used by > xtensa_emit_adjust_stack_ptr() to true if the stack pointer is only > used for its own adjustment. > --- > gcc/config/xtensa/xtensa.cc | 162 +++++++++++++++++------------------- > 1 file changed, 78 insertions(+), 84 deletions(-) There's still a minor issue here: this change introduces a new regression in the following test: g++.dg/opt/pr100469.C AFAICS it generates different code with and without the '-g' option: no stack modification without -g, but adjustment in prologue and epilogue with -g. -- Thanks. -- Max