From patchwork Tue Jun 15 03:24:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1491968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=cyKx3HYb; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G3tx83QyJz9sRK for ; Tue, 15 Jun 2021 13:25:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E04E3983809 for ; Tue, 15 Jun 2021 03:25:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E04E3983809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623727512; bh=pI2YI8clwVry9sKV6kWStagOenwzBkQil7aP8ExjSpo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cyKx3HYbo01Umr8TRzEiTQzBhVBzS4WNk0JOPrGSsPu9uzh6QrSbaDJefcw1Foyh0 UGtICnZ+I5jb0vSeiuonMStMbkT65Cs5CXLW1kf4TEsK1iEcfQQgmXtSCw82eOcZis ysX+zASa3XfsMMQNCeAbFZY6JgAoTvb6j1oHjkdk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id ED00B389247F for ; Tue, 15 Jun 2021 03:24:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED00B389247F Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-aVnquSZzMPCCkRplpbctXw-1; Mon, 14 Jun 2021 23:24:26 -0400 X-MC-Unique: aVnquSZzMPCCkRplpbctXw-1 Received: by mail-qv1-f71.google.com with SMTP id a2-20020ad441c20000b0290251bb08ce61so3745519qvq.19 for ; Mon, 14 Jun 2021 20:24:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pI2YI8clwVry9sKV6kWStagOenwzBkQil7aP8ExjSpo=; b=jhN9KjJbdjlSoDnq8rF4hQmErgc1fKXJoWHcnfTUps7642hEeXkhWCoD5qCbjm3xdg HKPQ84n1WkbwAehWbryhQYd8BeXuoJ3t2V0hVcLINvhII3BfQCeK8g44/3OUaHHrbjUx qsaUUqTcDhTx8+M76L6axX39FZxf1n4RI5RpeBrWcO555TwngBvzJGBs/FcqaGgeGCmU d4moV4+Vktv/zcSYZjdQ46xyrSmtD7v1URQQKKzbGYPOcIcrkngC6y17ewZcv+vJcD32 Wdv5p0W2XvazJdsBzJNtdzhOhqhNCLTt5oiWArA2/pZDAXAaIGOc0cq2hsHZqn0TLxbB qf5w== X-Gm-Message-State: AOAM5314axf0dZ7OijTVl2CKkS8FoMgXm5Bn3fkioQndlqUecQA8eqj+ 7jJRfFaMV59j6REQxqbBsblfqmD/I0lGVrmAcpwhPjPfltya7ElJBK8oph7DM8zRTSEBY7To7iA 0THaT3I2+gB6J7FsnThYWhh1PuCOItpvB7cKJ3/ZKfWq8IxDRA6DmROlgNYdU1DCqOA== X-Received: by 2002:ac8:7f42:: with SMTP id g2mr19352812qtk.280.1623727465321; Mon, 14 Jun 2021 20:24:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwq/UCp0tIPCsBYNWx0cI6fbJ+OodBTI1IZP9a83QjfqzYLtJyk2LQ+N1+ZFU1SOnlAMzmkjA== X-Received: by 2002:ac8:7f42:: with SMTP id g2mr19352792qtk.280.1623727464923; Mon, 14 Jun 2021 20:24:24 -0700 (PDT) Received: from barrymore.redhat.com ([130.44.159.43]) by smtp.gmail.com with ESMTPSA id o13sm11377854qkg.33.2021.06.14.20.24.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 20:24:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH RFA] expand: empty class return optimization [PR88529] Date: Mon, 14 Jun 2021 23:24:22 -0400 Message-Id: <20210615032422.1910808-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The x86_64 psABI says that an empty class isn't passed or returned in memory or registers, so we shouldn't set %eax in this function. Is this a reasonable place to implement that? Another possibility would be to remove the hack to prevent i386.c:function_value_64 from returning NULL in this case and fix the callers to deal, but that seems like more work. The df-scan hunk catches the case where we look at a 0-length reg and build a range the length of unsigned int, which happened before I changed assign_parms to match expand_function_end. Tested x86_64-pc-linux-gnu. OK for trunk? PR target/88529 gcc/ChangeLog: * df-scan.c (df_ref_record): Check that regno < endregno. * function.c (assign_parms, expand_function_end): Do nothing with a TYPE_EMPTY_P result. gcc/testsuite/ChangeLog: * g++.target/i386/empty-class1.C: New test. --- gcc/df-scan.c | 2 ++ gcc/function.c | 16 ++++++++++------ gcc/testsuite/g++.target/i386/empty-class1.C | 9 +++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.target/i386/empty-class1.C base-commit: 08ce1f4c5091b80b680d15c53a17237544a3cca8 prerequisite-patch-id: 320d08bee3615919d0cf6a9d33bc2247aece51c7 diff --git a/gcc/df-scan.c b/gcc/df-scan.c index 1268536b3f0..e9da64ff3df 100644 --- a/gcc/df-scan.c +++ b/gcc/df-scan.c @@ -2595,6 +2595,8 @@ df_ref_record (enum df_ref_class cl, ref_flags |= DF_REF_PARTIAL; ref_flags |= DF_REF_MW_HARDREG; + gcc_assert (regno < endregno); + hardreg = problem_data->mw_reg_pool->allocate (); hardreg->type = ref_type; hardreg->flags = ref_flags; diff --git a/gcc/function.c b/gcc/function.c index 67576950983..6abaf3d116f 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -3821,9 +3821,11 @@ assign_parms (tree fndecl) tree decl_result = DECL_RESULT (fndecl); rtx decl_rtl = DECL_RTL (decl_result); - if (REG_P (decl_rtl) - ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER - : DECL_REGISTER (decl_result)) + if ((REG_P (decl_rtl) + ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER + : DECL_REGISTER (decl_result)) + /* Unless the psABI says not to. */ + && !TYPE_EMPTY_P (TREE_TYPE (decl_result))) { rtx real_decl_rtl; @@ -5410,9 +5412,11 @@ expand_function_end (void) tree decl_result = DECL_RESULT (current_function_decl); rtx decl_rtl = DECL_RTL (decl_result); - if (REG_P (decl_rtl) - ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER - : DECL_REGISTER (decl_result)) + if ((REG_P (decl_rtl) + ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER + : DECL_REGISTER (decl_result)) + /* Unless the psABI says not to. */ + && !TYPE_EMPTY_P (TREE_TYPE (decl_result))) { rtx real_decl_rtl = crtl->return_rtx; complex_mode cmode; diff --git a/gcc/testsuite/g++.target/i386/empty-class1.C b/gcc/testsuite/g++.target/i386/empty-class1.C new file mode 100644 index 00000000000..c1992772d26 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/empty-class1.C @@ -0,0 +1,9 @@ +// PR target/88529 +// { dg-do compile { target { c++11 && x86_64-*-* } } } +// { dg-additional-options -fdump-rtl-expand } +// { dg-final { scan-rtl-dump-not "set" "expand" } } +// The x86_64 psABI says that f() doesn't put the return value anywhere. + +class A{}; + +A f() { return {}; }