From patchwork Fri Aug 4 17:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bradley Lucier X-Patchwork-Id: 131284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:1a9a:b0:139:fa0d:b2d with SMTP id gm26csp105173rwb; Fri, 4 Aug 2023 10:58:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNMQa8klWzXPCkSquzx/OqrCJ63QWnYHuDXmtAtFSA6SzKQmH5x8YQhQbvt92yVkzYGDBa X-Received: by 2002:a2e:b0d5:0:b0:2b7:a64:6c3c with SMTP id g21-20020a2eb0d5000000b002b70a646c3cmr1751470ljl.37.1691171900651; Fri, 04 Aug 2023 10:58:20 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t22-20020a17090605d600b00992c3b85acbsi2110073ejt.128.2023.08.04.10.58.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 10:58:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tgjPhHTj; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B61A385B528 for ; Fri, 4 Aug 2023 17:58:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B61A385B528 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691171887; bh=BrmSqU/hP8GDZ68puj+FtqQwQPNxXoYiSEiyBnoYCjE=; h=Date:Cc:To:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tgjPhHTj1/gI4UF50Q0118NYx4wpkQgwqtOryIDmn61Bp3bAwCCUDL1zhBnSqLj9V SCx0kg2r+fIkTwZOvPVbE6ozu/s4WDc6bFgiRQ2ngRR3l6FbOv8OMfzqSWUq43ow8o zUHHjq/3bwJOylPuTlf6zEhyGBmgWb9SPC4AQ4hg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2100.outbound.protection.outlook.com [40.107.236.100]) by sourceware.org (Postfix) with ESMTPS id 3D98C3858C5F for ; Fri, 4 Aug 2023 17:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D98C3858C5F ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JYZAC/eDDU119n4UKwDjAgIPgKuZxfxI66NuXBojqgy7HIx1RXhzz+ZisFkoWmOJnNIqHlgvsWwGk/G7Z4EsuUP7HdNk/c9GILCrYKjZOZfZE1uSUJ+CrOkqsgp4sJ7lWYaccnTWMmUZdpr/2A6cxJq9Q7S7YYEJ5GUXujzEYtbjnNprHVgBKp4IYWzpMabapFvgN4X1/GnHyTdN+vaUFpXe28yNVhmd3r4z83H2hKOuU7oJ8LFGuKovFE+40L/tjzjgl6s6tAakhzCI5VONXRouz+tkWN9W8QDG4YpRg9Krm1C4g+enINe5pQ0MfTmre/callEMQugIabBsIoQDzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BrmSqU/hP8GDZ68puj+FtqQwQPNxXoYiSEiyBnoYCjE=; b=m8VIx2nHz/1SKFZj/7mWaJmXrTSUklOOl9K6MKPui9r+sy4Dn/ZUaTcOkoe/C0LLWO/Wcixgj/la4wf+Fa3WY7zeUJxi/Im66ioUwvnHsDPdK9q8pD3AKhqXgV4JAMrCrMLE8/BgROv0QKXVEz3/krb3GDQW8BIof0k8wuaDXgQxFrcuqhwhbn4h3TCHyCbO+1o3q2UKEmLurmGHkchmBSC2f3rrzz8EnfYbBKvRfHXWZOnIUdGe5M5GZ9APhBWQMFyQPnNZZLAtMVccXuvR19m1+8WWtgza3Rf/0TqgQi+qDAMk1++JiRlCDMKFRH1b9djgB1SnzrVQxTPzu4bJVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=purdue.edu; dmarc=pass action=none header.from=purdue.edu; dkim=pass header.d=purdue.edu; arc=none Received: from BL1PR22MB3634.namprd22.prod.outlook.com (2603:10b6:208:392::13) by DM4PR22MB3399.namprd22.prod.outlook.com (2603:10b6:8:46::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.45; Fri, 4 Aug 2023 17:57:18 +0000 Received: from BL1PR22MB3634.namprd22.prod.outlook.com ([fe80::3b52:56d9:49c2:e187]) by BL1PR22MB3634.namprd22.prod.outlook.com ([fe80::3b52:56d9:49c2:e187%5]) with mapi id 15.20.6631.046; Fri, 4 Aug 2023 17:57:18 +0000 Message-ID: <07d4723b-d449-ccd1-d3cb-c7ee80bb97a0@purdue.edu> Date: Fri, 4 Aug 2023 13:57:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: lucier@purdue.edu Content-Language: en-US To: gcc-patches@gcc.gnu.org Subject: [PATCH] Add -Wdisabled-optimization warning for not optimizing sibling calls X-ClientProxiedBy: CH2PR12CA0027.namprd12.prod.outlook.com (2603:10b6:610:57::37) To BL1PR22MB3634.namprd22.prod.outlook.com (2603:10b6:208:392::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL1PR22MB3634:EE_|DM4PR22MB3399:EE_ X-MS-Office365-Filtering-Correlation-Id: 72bccb44-ce2d-466a-da57-08db95143e7b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MIFzvaArR7a9GNp115b89SoP9xbx1OJB2EfeFCqwvTHoIqgz5QQ3q+8P4AYUY1ejZKBpyhFWsfEGdLyr/tLtRcUtZMWxnOXCgNIyoItgoWkX8LVNmE4ljMPh6+SA1cp7qZa5B3YvsHfa/JT0FiPewA1wzTb4TJFK0i7UkWjz8Oy4035U6xD2FzyEjFjH6c6Ean1i/sHK4NnILw19m26FdqkIU/8qSu8XcsoXlSJC9vPmcSWejOFoyBxUTUbnS+hb78ne3qwV190f7+a16kIDIIIXTJFd4v/viivdVXQpcw8UxmCkRqK+aqguVjOppJNzJ0rTY4tJC++/QmBr0LL2gDDt8pnL7Zyd1xd1A+h5rDkmSuRN7tr+S1Rju8krideN0OHfHc+vW/9romJBHMNAcCHYY3SZcpZi/cqGRDR25UU2n1b88eeoNuTUA1wn1KKMuhka51QD67scpt9Y4y3ia3qgPP/UZqQAYIwGOeMs176FAyVGjMM5IwQCNya2xHxhZImSSyRDnKQhvYlrQqp4OS9u13AlfVjYbRCEYi/xPAqjeg74gsqAo4BDSLmAGA3Zp5Cuv7w9op/FT8I6rq9MjaID+P0pSiptko0Tx6KOWOQPevxTeB1NHqGSKtY1BzNj0q6FuU66L9dkzlIhAlgSZw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL1PR22MB3634.namprd22.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(376002)(366004)(39860400002)(136003)(396003)(346002)(451199021)(1800799003)(186006)(2616005)(75432002)(6512007)(316002)(478600001)(38100700002)(66476007)(66556008)(786003)(6486002)(31696002)(4326008)(6916009)(66946007)(41300700001)(36756003)(6506007)(26005)(107886003)(8936002)(8676002)(2906002)(5660300002)(31686004)(83380400001)(43740500002)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yPTI/S1DR8xcWoXg3WxRTOn82R6d?= =?utf-8?q?v8Cg1IQ1QVrNNAR6Xzscl644DdQq47Los9xdnhsmLQjL84rydynpTMsPZWsIF0PBw?= =?utf-8?q?T19p+HVT7Wk3SWwWMkdvf8pnR3v6W4aUy3EgBXksx01fcO4Ut38NieUCeBEhnGOR0?= =?utf-8?q?cBODo6jEeehbN0Gh04c2BNVZ+Xl51eTh+k3zeawaHOiEt+qs+w9/MY7fruKpK+bMD?= =?utf-8?q?n1KBTsx5ZGJ1dqsgFUBqjLKHsblXb/h3iLEQUtlSWfmvezfGTzy2zM4YrwBc0vUVV?= =?utf-8?q?Nm8Sm2QYKCu2yrOzrryhf2dyoEBLS8O6nrQ9fCFJE9sxCg02IvUtZyUHhLdoUSIUG?= =?utf-8?q?v+jN+Dyrox5AhqTIvEIKvKIVCVpq+jd5XKtfUsH8Gra5NLrCixNpweLdaplI/wSJI?= =?utf-8?q?0UZOsG751S+1fEcgoo65JzgUQ5mN/W+gDPZPMd7MWaKULKRcEygAr0henl1xfezh7?= =?utf-8?q?/SmFF7OL2k75LYE8BN3KuMTUuM1+eAOu6bRsp6/zoUIlP50JdjAPIQaeScpdGbk1J?= =?utf-8?q?ca3s3i19rt6eGz1UIP4YSy7VtfKPlDYYPbDJdnRJQPivgwMkygPdV+BO8vSvak8cy?= =?utf-8?q?JcbkGY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T2LS986hJROf4yyWAMmcQA1MUXrLUT8mLmxF3A7PMTZME?= =?utf-8?q?nKCwwIVngBiH?= X-OriginatorOrg: purdue.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 72bccb44-ce2d-466a-da57-08db95143e7b X-MS-Exchange-CrossTenant-AuthSource: BL1PR22MB3634.namprd22.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 17:57:18.6082 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4130bd39-7c53-419c-b1e5-8758d6d63f21 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XlcwJeCLeqPq/LsPh51b+tiRQ8owpciEMo6l9qvHL5CgfikkkSa2YbRNzs87Kmc83ZaQqwFHkT5Eu1NlEuwwgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR22MB3399 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP 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-Patchwork-Original-From: Bradley Lucier via Gcc-patches From: Bradley Lucier Reply-To: Bradley Lucier Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773322267065913973 X-GMAIL-MSGID: 1773322267065913973 The patch at the end adds a warning when a tail/sibling call cannot be optimized for various reasons. I built and tested GCC with and without the patch with configuration Configured with: ../../gcc-mainline/configure --enable-languages=c --disable-multilib --prefix=/pkgs/gcc-mainline --disable-werror There were some changes in the test results, but I can't say that they look substantive: diff -C 2 summary.log ../gcc-mainline *** summary.log Thu Aug 3 22:56:13 2023 --- ../gcc-mainline/summary.log Thu Aug 3 19:42:33 2023 *************** *** 14,22 **** === g++ Summary === ! # of expected passes 239234 # of unexpected failures 5 # of expected failures 2087 ! # of unsupported tests 10566 ! /home/lucier/programs/gcc/objdirs/gcc-mainline-new/gcc/xg++ version 14.0.0 20230802 (experimental) (GCC) === gcc tests === --- 14,22 ---- === g++ Summary === ! # of expected passes 239262 # of unexpected failures 5 # of expected failures 2087 ! # of unsupported tests 10562 ! /home/lucier/programs/gcc/objdirs/gcc-mainline/gcc/xg++ version 14.0.0 20230802 (experimental) (GCC) === gcc tests === *************** *** 155,164 **** === gcc Summary === ! # of expected passes 192553 # of unexpected failures 109 # of unexpected successes 19 # of expected failures 1506 ! # of unsupported tests 2623 ! /home/lucier/programs/gcc/objdirs/gcc-mainline-new/gcc/xgcc version 14.0.0 20230802 (experimental) (GCC) === libatomic tests === --- 155,164 ---- === gcc Summary === ! # of expected passes 192563 # of unexpected failures 109 # of unexpected successes 19 # of expected failures 1506 ! # of unsupported tests 2619 ! /home/lucier/programs/gcc/objdirs/gcc-mainline/gcc/xgcc version 14.0.0 20230802 (experimental) (GCC) === libatomic tests === I then configured and built GCC with ../../gcc-mainline/configure CXX="/pkgs/gcc-mainline-new/bin/g++ -Wdisabled-optimization" --enable-languages=c --disable-multilib --prefix=/pkgs/gcc-mainline-test --disable-werror --disable-bootstrap to test the new warning. The warnings are of the form, e.g., ../../../gcc-mainline/gcc/tree-vect-stmts.cc:11990:44: warning: cannot apply sibling-call optimization: callee required more stack slots than the caller [-Wdisabled-optimization] These are the number of times this warning was triggered building stage1: grep warning: build.log | grep sibling | sed 's/^.*://' | sort | uniq -c 259 callee required more stack slots than the caller [-Wdisabled-optimization] 43 callee returns a structure [-Wdisabled-optimization] If this patch is OK, someone else will need to commit it for me. Brad gcc/Changelog * calls.cc (maybe_complain_about_tail_call) Add warning when tail or sibling call cannot be optimized. diff --git a/gcc/calls.cc b/gcc/calls.cc index 1f3a6d5c450..b95c876fda8 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -1242,10 +1242,12 @@ void maybe_complain_about_tail_call (tree call_expr, const char *reason) { gcc_assert (TREE_CODE (call_expr) == CALL_EXPR); - if (!CALL_EXPR_MUST_TAIL_CALL (call_expr)) - return; - - error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); + if (CALL_EXPR_MUST_TAIL_CALL (call_expr)) + error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); + else if (flag_optimize_sibling_calls) + warning (OPT_Wdisabled_optimization, + "cannot apply sibling-call optimization: %s", reason); + return; } /* Fill in ARGS_SIZE and ARGS array based on the parameters found in