From patchwork Thu Dec 22 17:16:45 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: 35884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp67053wrn; Thu, 22 Dec 2022 09:13:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXsaHx3r0otSnN3iw4z6xBe8AiOlWRr7lpKfPdV8H5s0n4SL9RJMMbIDm/HN9ehZ1LCG+LnL X-Received: by 2002:a17:907:6d0c:b0:7c1:652:d109 with SMTP id sa12-20020a1709076d0c00b007c10652d109mr6146964ejc.35.1671729210600; Thu, 22 Dec 2022 09:13:30 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 7-20020a170906328700b007c16344082dsi607346ejw.799.2022.12.22.09.13.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 09:13:30 -0800 (PST) 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=kFm2wxzt; 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 69C1B3857C44 for ; Thu, 22 Dec 2022 17:13:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69C1B3857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671729209; bh=slrdtT4IP1fuvoxSND21hcV6zEs7ZqdcgWiQz44yTbQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=kFm2wxzti0xlBj19M/JzO5XnV6gI5N3AUlSU/jo71Spt12dCCmt7K4YebQhSjfuYf rgICRO+btUBQV4YqJvhZzr3SMBeCmAqHA5Js8l1BnzZHHZzl4aNdXnPAvdhuyFyJVk CmQ3ggf3wPFIm30Fg7aTbGN2a4xjanNHGZV45jno= 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 4AD3F3858D1E for ; Thu, 22 Dec 2022 17:12:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AD3F3858D1E Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BMFiG2T004854 for ; Thu, 22 Dec 2022 17:12:45 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mh6tr47y3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Dec 2022 17:12:45 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BMFggXP015684 for ; Thu, 22 Dec 2022 17:12:43 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2048.outbound.protection.outlook.com [104.47.56.48]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mh47f9d54-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Dec 2022 17:12:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kdUyUt0w2epDgSJX9ow7EXPbF+aYXWhF5ePXWaDI5NCKak9AmFpuSiZ8MQDHepRHsl646pzVch0qZ+uxNPLfh2INcdtFg/Qm1zkxMN5zzpvYdHnAPp8nDXL3t89g9YvHKNqUjmC0R/cl7tNY7RxB9s+CMldYpMbwT50rCvWkjAzl2sjYiZvabtHaBJHqJsO7aIx2nEucQLHgvmhR5Hv+m3koszAGA+nAyl5ofeBFtB7sjrw2/g9AAYsKB9lfIXF3wX/pwZbpSBZHjL5xxYAMO9BQXITQP0P/5HXws/HUap56Ax090MPtPuY0khkovbaVmOHswhbqa+Ch2jk9yHQspw== 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=slrdtT4IP1fuvoxSND21hcV6zEs7ZqdcgWiQz44yTbQ=; b=ThSGOK2G9R22s0p+pS0QsVKNhVMT6bz5jlMM1hXRZYMYt/oEANOfVGpSO3NPP+ML1Vn1KJGn70pYIjKaXj7HRHvH0DJyv0CMlnIiaeJapk/aA6Pb1MFeke1635gzUtzlOcvUtU2SZY0B5oWHqvtRFaU+BsSnJxuyZzbdPZ9hKxr6bA2nd99csRdTVmx7NMkTmPQklq+VlCmJSBsKjVzsySbHJY4Q5hAH4HKs7cS+SLl+xBC/2n1WfBAtwd4qoz+skt3FEawfyhKnLRV9rKUGGw6ctWKlT+jB9/zxiS1fmoJbIKrRPFPsjMkUiJg9mHKuIbUTtE85RDy6st33Im8zvg== 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 SJ0PR10MB4478.namprd10.prod.outlook.com (2603:10b6:a03:2d4::19) 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:12:42 +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:12:42 +0000 To: gcc-patches@gcc.gnu.org Cc: qing.zhao@oracle.com Subject: [PATCH] Disable sched1 in functions that call setjmp Date: Thu, 22 Dec 2022 18:16:45 +0100 Message-Id: <20221222171645.12064-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: SGXP274CA0012.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::24) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|SJ0PR10MB4478:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c7a30ec-1988-4bd2-26a3-08dae43fbc29 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sA7HD5RRDKnyxWiAB+4ew5z76MEGqlmd0/cl9BN7Bx8yKK2u7QwsQAE0bxFh6ZvzpYXoVTWCQedvY1Btu+9jDRSBIDXupogtNnMl5Z1F5l+bZ7f1wzy77YP4dst3Xa6RT75a8lcG+8GP42PBSH66FYnJ2nMzff+1E0JGGGqGz0ySQpK6gJYKlAFm8Ji+E7HE96ZYzuUJce6ysFWXS1kJMm07hYdX9EiP654HGvD0gXGroRR/s8LhT7WA7aRoI0Q1g5H3yA6vxQgdci3XLYUoBd/RZUxbVQOxctF7Ye6uzPDKGw9AxvcboHYLUxCws4tKX+Ii0LFThHm3zHs4coTV+RqWLKkcLz9e8F7hwrpFbDnvu4C6QFDVGe7Eb55w0rMtbZrzDk5i+w37CjSsCSWcHd0PI5/N1MSjDh8yL7wWFTGokDV+VGQXR2DnCCV+J5WhCmic0QoBR2lxCP9XNVjmYUe43y5vAHo8qNzOtx2EhmdZaVoiETdGFBcOAjtc6+frttoihWePIiG/VD75VejfyPZDXLfm9Ph3UZdZQr8yOnkHwmuInz9dbv9LupAdpo1VJtp2WmTwMYvcKiHulcI0NUHhqusrOoztE3MWFErybv115b957CrfdLJNy3ny6CXdxJ8eEbxYVrE8tv+gUoTS1A== 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)(366004)(39860400002)(346002)(396003)(136003)(376002)(451199015)(66946007)(1076003)(66556008)(66476007)(4326008)(8676002)(107886003)(38100700002)(6512007)(8936002)(26005)(5660300002)(186003)(2616005)(2906002)(83380400001)(6916009)(6486002)(316002)(478600001)(41300700001)(36756003)(6506007)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PACs1CFAiQBLQYCco0DzYaeephQVvPMKwPL/9C3TWVl5uxqBNSg3SfuzHFF8Zb4W5Sw9H2qa9/2Y7EVcUWJgVmHqyMTkhC92X43W6S3PNPLVwlSwYrsvED24GiuV6oLC2tdvNGZ3+yrwf7IWcLFl6AaMSYRir2Gz6X72pIWN4FQ+2CFu6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MJELlBT1xDN3X4J2k8obALgwlnBrXXJHXJ2QHQ2sdx8X20fS33pITipJWuLISMye9/b4W5VB0hS67dqx32P3IUg5xSLQXq1+PPUAgG8XCbPG3HSm/WB5U2R1sr0tfSkNLbZB9wOaCIcgvAkROzb/NNEzzg0em9ZpQFe33IYQwTfGCcyKW8CWyuGc56kcJlYjr8PYUTPf2ehbZXt3SunyQdv0gSUge8emoTyofJrqjUK0neCC3j9xje48QjMwLCP4MHH9XxJQ+BCThAuHHg8a/O/tqKGhsq9QM9d4W3AzFDovX45nkMIV0TSCNS9f/Gsp7DVx+7gh4+hq64CMDZKgicQxIUXUDNIgdVFfPzKIxA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c7a30ec-1988-4bd2-26a3-08dae43fbc29 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:12:42.0201 (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: XTpeYPuTY0M37WKTbX2UNtt6K5cmbt2i0w8v9uzd7dNikCM0/olpycPHM+Cbvvm04Ue2ueVKa0yxjrceJ7OtFXU2jDST7qmtCZ4o4rDXf8E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4478 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 adultscore=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 mlxlogscore=743 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212220146 X-Proofpoint-GUID: dwQ13AGpeUz2ZaKTGDkucbDGwlsOmAOz X-Proofpoint-ORIG-GUID: dwQ13AGpeUz2ZaKTGDkucbDGwlsOmAOz X-Spam-Status: No, score=-12.0 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?1752935129025154431?= When the following testcase is built with -fschedule-insns in either x86_64 or aarch64: ---- jmp_buf ex_buf__; 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