From patchwork Thu Dec 22 17:32:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 35887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp74267wrn; Thu, 22 Dec 2022 09:28:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXtI8oCkRPkAnBXTqePjEKZKpoFQqeZ4eSTNKootkUDnsJ/n6f1Ccoq36QeuJR2ZOaTHdfi3 X-Received: by 2002:aa7:d60e:0:b0:46c:edb5:afdf with SMTP id c14-20020aa7d60e000000b0046cedb5afdfmr5452733edr.41.1671730131176; Thu, 22 Dec 2022 09:28:51 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dk19-20020a0564021d9300b0046aee4c4ebfsi1053032edb.105.2022.12.22.09.28.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 09:28:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fmmnZVhI; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 2C0593858298 for ; Thu, 22 Dec 2022 17:28:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C0593858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671730130; bh=Tz45n0Q6jZgM6SMBjkKuDALIoZ7wqIzJpFFRGZ1dTc8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fmmnZVhIQTlkhfj6AiePCZdAqqdYS4ZdurpMtkJVIG4qCbnfTivksfU9MAeRr8n6n lnOA3BS8+aTCXbNouKzpa1L2lz6BdMag6CZmF2YsfDZoAFtP7K+jwXJ70HsWHIurCC oQy2golrVZ1kdCNBhaYJmf11TbxBvXhVck9nShbs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id DE1E03858425 for ; Thu, 22 Dec 2022 17:28:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE1E03858425 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BMFfOif004987 for ; Thu, 22 Dec 2022 17:28:05 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mh6tpv7bt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Dec 2022 17:28:05 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BMFdiQ2003115 for ; Thu, 22 Dec 2022 17:28:04 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2106.outbound.protection.outlook.com [104.47.58.106]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3mh47875v6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Dec 2022 17:28:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TwtNhhGgAJYzfQWkohL3k7+z7e9r2CiVmrgRocW3jioWdzbdpAbzjMaOuskuSaxJaWo9VpQ++SCn1y5GTuYvpVcyUgEadp0i3y3EYz0RC5v575ASv+KGz+PO3oSg8c66PtbibLybICafnusdBVAEXeQv0lJABZoBsu0Iftbqsq+TRl5UkMU3MYjptOoVpHrzpOU3iIr57b1miOBtK0WXDZf9CspirsBY3/qbCsQOqqEbqztP7tw+NE0R9Q6eGp9aKs6PDbnkpq5mIcRl3ciYRrQjZhZRFhSdnCeE0xmk1zy5P3WoeGL5vAecHDDMRoRsxb0p1N1iIcloyRR0hgldcA== 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=Tz45n0Q6jZgM6SMBjkKuDALIoZ7wqIzJpFFRGZ1dTc8=; b=fg66/9DWURl0hI8KYJv04lCKo5JNod9WIVD3bXAsZfwNhmN5WkI1ntY7QetoNHsW/qMCsrAhpiv/07uTdCprv/L2sB/1htTyGRHOmtw1Sc0DdpkKdKZPdxkaHvv28xdlxyOxZx0XqfetL4LEskvlXgaCkcFckxK9LbR/V2PEBcrZ0QFgQzmdd/l+YZ0g/5ROqkcaWX8dN9zE6T0xvC4apZJ9Ip32T+tbaQOKIsfzXgmnrwf9p3AeOWTvRcpY5m5N0L3lzpB/803KIET5tBmBjliXgVGHXejMz+RweK9uQVKCKAVkpKCWwywQZzRUom0iz3gMr/yjfLWpERP9hMPsbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by SN7PR10MB6285.namprd10.prod.outlook.com (2603:10b6:806:26f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Thu, 22 Dec 2022 17:28:03 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::ebe9:b7c9:82ae:d256]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::ebe9:b7c9:82ae:d256%7]) with mapi id 15.20.5924.016; Thu, 22 Dec 2022 17:28:03 +0000 To: gcc-patches@gcc.gnu.org Cc: qing.zhao@oracle.com Subject: [PATCH V2] Disable sched1 in functions that call setjmp Date: Thu, 22 Dec 2022 18:32:08 +0100 Message-Id: <20221222173208.13317-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: LO4P265CA0013.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ad::9) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|SN7PR10MB6285:EE_ X-MS-Office365-Filtering-Correlation-Id: 7434c99e-21cc-4409-9962-08dae441e11d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wz7qgN9tDvSdrggAhxW1j/QCEVCe3bLG13agim4lFHQaFsHnD++1leFj4+cfL0wjRH+LuUr7NHr5yprvYckposOP22RXbSpxpUMm3ohhlakacK/0qwnFBmU3SMAhNC3gCgwMnE5LQ4D8GZS1h00ABOqcsgaQjxA6Uzc24KpT9FHJA6DRfpuaP7rIaSLRNpXKgI5u+APjnHwUr1B/MYo9rnNrq3+BvClERIonKooLjysqQCNitGPGCASqH7Dlm/SQCPQzIbO8Nj7/yIfdFj/r/FvtB9TOtcIuGFiurckTqaOG92BFiymCAA3BrrCrePMz83X0L0px7QRugy7L0LaTQ79Z/otY3MVKiz0g7lKJq8bFfArqTWjKMQoovYkp1NUqGptRG2vv0GheUM7o0f0rGtShcGZDiRZPX5QKnxttoD8AxV10vb0WHo7QEQzJI5H7Q/aQ+Uu0nZvbzSjea/DRAcePRukHMd7jetwZ5BvZHlCYzOGHlobeKCjAOOprMGL1TO7zpWbz5690Annuq5+IOf/kDb4ySaIi7OWIeSiyWV+vExzudVSVSuHZLkQBtdbvlNKEQ3rI5lA2VnsSZBD4XY2MgtUEJff8r96Rvo7tNxd+FmCuoH4YYtvTfZ8B6+WG0DVrMAPnAdnjn4MozaT0Uw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(396003)(376002)(39860400002)(136003)(366004)(346002)(451199015)(36756003)(2906002)(6916009)(316002)(6486002)(83380400001)(478600001)(6506007)(86362001)(107886003)(1076003)(2616005)(186003)(26005)(6512007)(8936002)(38100700002)(41300700001)(66476007)(66946007)(5660300002)(8676002)(66556008)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7hYB35tjzbsEW9rdnYf7XXkG5PTjNMKXFcoEbtrMzuEqY9ZS2kyB/kAT10yC/gR5vYhvVh0eQSgiBiKNkf78WvbgArmJQpVNf9yB+sK6sVFeNxI0rjS0bafRFX7u5sloSBzvP4nH0Y6vML9tsbSOtGTKkUVwfFrE6jteTWOEfeDzUsxUb8GmRDMDWLJLR0KJipyUcNeiCijvg2EKuPztfcpyVNZEyDK0dmC6YdRjK8tk3daUlM0Y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/PwYr0Nn/hnOkvnK43QnHgwJVDdtbG4JetozHldNCT9mH+0fGPY01umE2d7RAcM3nFlPHVM6y1Mb3yxZ1bZrD9HUq3Z48+86I1MMfvLp40JPQcVsqX5TExJ6H5iq39V2DMaClV79qRgMF7HMLlWmboWeH7TGJdEU8t6Lqmaiev9BhMrwFRe56KAWungKa/Hj8Wgdh3JKpxtGvPhqoiPwK+IE5Z4dT8CQ2Vd1mA72gs625xHe2KJ/Ikd9MC+vhSoReadYZeImflY7M1Kzoq1pEqBW2abEoPVgVgIYQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7434c99e-21cc-4409-9962-08dae441e11d X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2022 17:28:02.9510 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SOJf6YinRxyipxhAp08Uijg2Ofygtco5eZCtW1XT8q+mSXldvtQwV3dbUfutprVoeKGRJqKdiD/hVxaCkB+3ux89E6dlixOd7JsvYCfPVtQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6285 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-22_09,2022-12-22_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=733 spamscore=0 phishscore=0 adultscore=0 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212220149 X-Proofpoint-ORIG-GUID: gsSWF5aJ52ZMIOM6G41AFcqVbTwlx_mi X-Proofpoint-GUID: gsSWF5aJ52ZMIOM6G41AFcqVbTwlx_mi X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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: "Jose E. Marchesi via Gcc-patches" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752935129025154431?= X-GMAIL-MSGID: =?utf-8?q?1752936093819444491?= When the following testcase is built with -fschedule-insns in either x86_64 or aarch64: #include #include #include jmp_buf ex_buf__; #define TRY do{ if( !setjmp(ex_buf__) ){ #define CATCH } else { #define ETRY } }while(0) #define THROW longjmp(ex_buf__, 1) int f(int x) { int arr[] = {1,2,6,8,9,10}; int lo=0; int hi=5; while(lo<=hi) { int mid=(lo+hi)/2; if(arr[mid]==x) { THROW; } else if(arr[mid]x) { hi=mid-1; } } return -1; } int main(int argc, char** argv) { int a=2; bool b=false; TRY { a=f(a); b=true; } CATCH { printf("a : %d\n",a); printf("Got Exception!\n"); } ETRY; if(b) { printf("b is true!\n"); } return 0; } The first instruction scheduler pass reorders instructions in the TRY block in a way `b=true' gets executed before the call to the function `f'. This optimization is wrong, because `main' calls setjmp and `f' is known to call longjmp. As discussed in BZ 57067, the root cause for this is the fact that setjmp is not properly modeled in RTL, and therefore the backend passes have no normalized way to handle this situation. As Alexander Monakov noted in the BZ, many RTL passes refuse to touch functions that call setjmp. This includes for example gcse, store_motion and cprop. This patch adds the sched1 pass to that list. Note that the other instruction scheduling passes are still allowed to run on these functions, since they reorder instructions within basic blocks, and therefore they cannot cross function calls. This doesn't fix the fundamental issue, but at least assures that sched1 wont perform invalid transformation in correct C programs. regtested in aarch64-linux-gnu. gcc/ChangeLog: PR rtl-optimization/57067 * sched-rgn.cc (pass_sched::gate): Disable pass if current function calls setjmp. --- gcc/sched-rgn.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc index 420c45dffb4..c536d0b8dea 100644 --- a/gcc/sched-rgn.cc +++ b/gcc/sched-rgn.cc @@ -3847,7 +3847,8 @@ bool pass_sched::gate (function *) { #ifdef INSN_SCHEDULING - return optimize > 0 && flag_schedule_insns && dbg_cnt (sched_func); + return optimize > 0 && flag_schedule_insns + && !cfun->calls_setjmp && dbg_cnt (sched_func); #else return 0; #endif