From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 4C5A43856974 for ; Fri, 21 Oct 2022 14:26:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C5A43856974 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29LD4JEE018883; Fri, 21 Oct 2022 14:26:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=corp-2022-7-12; bh=zX5FRYY6PRZd6NCDMKCO4hYI1vdLb6uh1RZWTU2fw8s=; b=I7ICCUA/Kdm78hSW/KRNenTB39MLlgp5GRB8QPQ8kXJMemj7p/CLT7DUjpi3wyBESXwQ uhhUwwXg8MtlJIUJNMtquVH3SR7pdp5XuVA66IHidtHo2o5Cl6i0ZPZQ/YFYrVyO6F0u txiBu8epJcy38vHQdBOihyrxjrfOh7hejm1r256QcMU1EUBlhAVk9IEbTncROmQa9cGf R43Ws2x8yLgFNMdVA93gxPhZ9yPhvzP5+vb2GB+ZtTtdOJEWKiSI58iiAhX6R0cosPDt 6kFPmHpgkRn4UHFIGsShVqzCzgnZViKfCGgU0xZEYeN7VDa7+E1V8mmJmUUqaannG9vX VA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k7mw3rd62-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Oct 2022 14:26:17 +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 29LCKeP4027378; Fri, 21 Oct 2022 14:26:16 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2102.outbound.protection.outlook.com [104.47.70.102]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3k8htkmrgk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Oct 2022 14:26:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffRCIrGGLyDk7CaiGMif6DMPk4p9tBqfWtcbwab8R+pFeyLofgEna+YSXy6l0rV3feph97GbMcBat0wWxSiSSoWoraIqOqVpn9+BBcTP7noGq4ASOFldlw8nTP3UyP1+5ysVEtVGe2BCM8xQEXEBGGke2nqp/JuwLN0ZvkOuLlOjkcXtTv1Ijb0tJ0MRRjovu+aWG1O+AjEQsQk2wMa4/3YEQrbeOWG3P5/wnsfGL9D75qRg+ZJRsZGvQIYg1u1r9gRUkg4erfWgdgIsl1a9c9cm0fekQ23ae6Bhu2gT7MR7GlI6EuMdJc6rnTY5OOn4RFTvozMQEJf8JZcrERsPGQ== 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=zX5FRYY6PRZd6NCDMKCO4hYI1vdLb6uh1RZWTU2fw8s=; b=Sr6uzFzX2CnqpSQMsOuTrh9V9kTNdMsUVsJrZ/x1DBHYoOxpo+zN+kqND20OoRjLzJ0jSscYJu+GOCshgSIbqXkOrY8EMj+gVnp44i/38BlveJqSOehfJt0FbRha3VMTH2ws60T+zbynQMSaG+uPFTnwKdc7tkBYejKNXYn0+vl+d0ui9bZ+sxkKbhuzafx5OO7/sHwMqDqcM+rxZhMW+MrugWoFuGo79ssh78f/XV9pg1r/ocyX4bZQ6yilIXylj/YGDcuCx0aQPhLcMMmCmzQWwA+Q9DzI7r1V/ZuwHOg4T4Jik4SfemZmgWAShSolqBbQz91lx9yRHxX8qZYF/w== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zX5FRYY6PRZd6NCDMKCO4hYI1vdLb6uh1RZWTU2fw8s=; b=S9EI4oQzAclZZBmwLqYMSk9Fw7Y7vzyOh9J/77fEcE+PqvhCe3K0fu9se4a4lawKK1Nz95mXutyb6m5uG65F4iOxQeuhYKvYq3M2J31S8ge7nDekfFrR4SwCoEypLCoBAD+uUCKuA0ZuiaRJSuF67rtmUudUda71Lqz82OtnrTw= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by PH7PR10MB6626.namprd10.prod.outlook.com (2603:10b6:510:209::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.34; Fri, 21 Oct 2022 14:26:14 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::cbf8:6682:721e:835c]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::cbf8:6682:721e:835c%7]) with mapi id 15.20.5746.021; Fri, 21 Oct 2022 14:26:13 +0000 From: Qing Zhao To: Alexandre Oliva CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH zero-call-used-regs] Add leafy mode for zero-call-used-regs Thread-Topic: [PATCH zero-call-used-regs] Add leafy mode for zero-call-used-regs Thread-Index: AQHY5R8glGL+nttrvkurYI0QgXksV64Y5+UA Date: Fri, 21 Oct 2022 14:26:13 +0000 Message-ID: <66ECAC37-E763-4469-B31A-7A2B031026F4@oracle.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3696.120.41.1.1) x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH2PR10MB4344:EE_|PH7PR10MB6626:EE_ x-ms-office365-filtering-correlation-id: 6df68547-9b1e-41f6-9f06-08dab37034f1 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YU86wax+TTi5X39TGOu8Z9C3FnX1XX7+yHMS7qXk2dS22dfOy6rAAtZO2JYaQnjkNSJD0gajlrPYp5ElXh2P5SjFGm843/vXo0RIvRZf/npE+FTNiXBXCUZdWZCpnc5GrYgAxQmLr0j8bFSF/7ba+ujPp1zh344JwYM0PT0EEeGbpn3XNpGScJsD3iCfSz+nVo0M0PtfYRfrJNDlUWLgeaJxSR772ZBncLcprrBuGU+t150QUzTr5m1yxjx3NWkhmGAdLNQLrcQxxIAEPbUWVOh5euNrx1rUC+BCmEjPidMrTcsFbsNAyxqgbki45WNJLiGLX7tfdhLf/NymNipcetRTE/gIR9iYO+PmTL6w8cUA9rOcpfQ7kcnXUfBh+RaBvXa94oPRNWUWbCGzyCQa3ZUXohE8y9lqvG4EVoI0SK4dq8+ZRonUAjTDYDKNG0jdYcYZ7a2iUGf3tihxdH3fMHIsmN9a/MOH4RPtges75EvefuSCQV3a7uuI3OSe1edDhcHNt8aVGNWN8z32mzwSdMCsgOnX6LsbxkXWUvFsU/LCF0Lyjb7g40/a3uqw7I4g7TN4heLFO8OClTEHnk2ZEcgrcEnnXKCJ+64g+rWjiS21jUtrVfnWO225xJKwPvosAvFD3MOS68Ri0pcYi82z7NTr1iqOLFtpLuBwTC0L+Qd3PWW7HJy697Afco571k4GtV8zbHUdKRIxklOn4RkU8cKZy13PuTdaLaJfPEJ9S0UUIth2RvpSag3t+k7jMzCSgPv+35ESYMFeiEzXWoOQ0TPyLzm5Ww8O9NEC3x48nEGlNcboZLiFHV/BD3R4/hWV2EssmHmYOPVRYquyAA4czg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4344.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(39860400002)(136003)(396003)(376002)(346002)(366004)(451199015)(84970400001)(6486002)(38070700005)(478600001)(8936002)(5660300002)(38100700002)(966005)(122000001)(71200400001)(8676002)(4326008)(6916009)(316002)(91956017)(76116006)(66946007)(64756008)(66446008)(66476007)(66556008)(6506007)(53546011)(86362001)(2906002)(83380400001)(41300700001)(33656002)(26005)(6512007)(186003)(36756003)(44832011)(2616005)(2004002)(45980500001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?USn2xMd3ZBqXt5lbzJ4tN4J2VGV7Z16Wnbq7tZ6NZpHxmj8C5pyFEFEcBaP1?= =?us-ascii?Q?DFv4hZII5as3EU1Kj4HfC41WZ67ihpPYZpZ4J44Bdm04dN03C74sz2wWI4/C?= =?us-ascii?Q?AZL8w11eGZFYBQzL49bs1NUNUjuEAzq3WJl5jkMWB8aBtVrWf50R1AEJGb++?= =?us-ascii?Q?MZxNUFwNR54VD2bEsRcCd4x7ddDr9KHx+1g/YNkrsiyXXjASaRgyxbZS5M2e?= =?us-ascii?Q?ycJOGzZyGtaDocPWkqHXOvr0M2zpekGvjCJN9ixQ0ZI8u+z11pdp7QkCuofZ?= =?us-ascii?Q?59LRZ5YK0e43UNZxwksQ2nWnUHlypWPF+JGDvUPlhW28lB5wqfSP/3aWty5D?= =?us-ascii?Q?b4tDljqmXZR3OR1PfMNir4+7Se8epPUgw0K+OL5eRTC3uSr07zbHCoSCeeaK?= =?us-ascii?Q?VEz1O9Ny5ptzFHJ5o9W5yt/n+fjJ5xHJrefcyyFzL5D19yA16HC97RgZ6QrY?= =?us-ascii?Q?nvHh6p8KdA+wTlB+y9yB6qoXR7D0YU6Me51f+kNTudwdcwPN0i3tgThhJkSb?= =?us-ascii?Q?0oSMflbxF4YxiI6vcsBkyV6d4hYgydf5Sqk1cdC0CqzddEmdVktNqjCGYZkQ?= =?us-ascii?Q?F42av9KgTdRp/CbPRPp9A5lH3NE5xudhKfFn9e9xQ0oboHdEO6Ihriy787ng?= =?us-ascii?Q?wTRQY7K7Isj0UpYMBubAWHbS8G4LDaucVQ3IBxlppFKyH5qo9IYBy4Sh/WsU?= =?us-ascii?Q?tYv1PDoKt1V0LvAgANMFrCtSyyt++Qa8iqqvFGDw7EXnmyjhDsjac2sb79HD?= =?us-ascii?Q?uQDTbV4bLXrQGQV3ulny5fQbkZ20zbQSykEJ1fGr9eNgZ6GyH3JIhGVGcNgT?= =?us-ascii?Q?q3XKTipfLY1LroLIv24VoTBRnXC5mxgVEx/C+swNU2R1rWX5/aQgZuQ0Vwkk?= =?us-ascii?Q?pUSfrmJXsiAdkPZxcKZjcRSEf+qnRLGQ08kbca1V7XVYS+8jQLmlTHiQAeBr?= =?us-ascii?Q?shSo/faU9zSp6D3QUM3cOHqI1wGhm3n7QzUwPdt2MmCD/OJBOyEw71oBuoY5?= =?us-ascii?Q?3QEJqp10A+dCRvpgRXZdFWKBLWOyP5aG5beVf04A5TuXdWJfaWJyc+44G5H5?= =?us-ascii?Q?JyJZuyUwVt8ZUpI28Y2lx6ob+ftih3l4qU4o1G9rY9O7eWzDuvi2rDo1hkX6?= =?us-ascii?Q?5v9KFPoUxFcZ9Zv1FBJDcn3nOWM9OofW4VqNnkmIZo5RblAbPACb+0cIkOFL?= =?us-ascii?Q?o5Fn/NVjjQ0RlwtdutvwUpJQyGGcn1OpQ+Di6eJvlh5tlrnw5gMulRly93m8?= =?us-ascii?Q?n12SeKdAMM+RCD32W20A34iV9GX3H6TGAKWAbuJoD7z1N5hmscmHWACCZ9ra?= =?us-ascii?Q?e912Dz+ltQK8fkNu+8ZeuopbO/MOp1SgsaX/w0SM5YWqYFgv3XUF2CYSuZSd?= =?us-ascii?Q?cJGSnnMSOrRSMLqvCmBPSNdQ5wQ4msfyN+oapzsCcu9rNXn4V3v6VkN/JNXn?= =?us-ascii?Q?9/5UtbwG7ocb8oMDY/8JYfcthK+WiUIj9ygJ6nBmMnAwsZIS5EoVsA1baw0N?= =?us-ascii?Q?dVdBRc0abKIjzpeHK3wbTcQX9rh05QSdc2jQWy1/c9X5BgZscF1xzjmi6+nN?= =?us-ascii?Q?tcgtAEdVeEtPCKk8pdcBtgyPUxArhGLWMTAQxIXx?= Content-Type: text/plain; charset="us-ascii" Content-ID: <9B29C47707D6A14684ED9C9FB6EEF366@namprd10.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6df68547-9b1e-41f6-9f06-08dab37034f1 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Oct 2022 14:26:13.1680 (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: GIo1ohq/7QIL314g3d7po3QOJEHGzl46pQM2Y02MwjHlDZIwrCjjdArN4VBPIjOSLFgWeiB2hHpaxmcjlJFWag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6626 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-21_04,2022-10-21_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210210087 X-Proofpoint-ORIG-GUID: oYNE1VryQ400RxjUXMzxoViUPazbhXoY X-Proofpoint-GUID: oYNE1VryQ400RxjUXMzxoViUPazbhXoY X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: Hi, Alexandre, Could you please explain a little bit on the motivation of this patch first= ? thanks. Qing > On Oct 21, 2022, at 3:31 AM, Alexandre Oliva wrote: >=20 > Introduce 'leafy' to auto-select between 'used' and 'all' for leaf and > nonleaf functions, respectively. >=20 > Regstrapped on x86_64-linux-gnu. Ok to install? >=20 >=20 > for gcc/ChangeLog >=20 > * doc/extend.texi (zero-call-used-regs): Document leafy and > variants thereof. > * flag-types.h (zero_regs_flags): Add LEAFY_MODE, as well as > LEAFY and variants. > * function.cc (gen_call_ued_regs_seq): Set only_used for leaf > functions in leafy mode. > * opts.cc (zero_call_used_regs_opts): Add leafy and variants. >=20 > for gcc/testsuite/ChangeLog >=20 > * c-c++-common/zero-scratch-regs-leafy-1.c: New. > * c-c++-common/zero-scratch-regs-leafy-2.c: New. > * gcc.target/i386/zero-scratch-regs-leafy-1.c: New. > * gcc.target/i386/zero-scratch-regs-leafy-2.c: New. > --- > gcc/doc/extend.texi | 22 +++++++++++++++= +++-- > gcc/flag-types.h | 5 +++++ > gcc/function.cc | 3 +++ > gcc/opts.cc | 4 ++++ > .../c-c++-common/zero-scratch-regs-leafy-1.c | 15 ++++++++++++++ > .../c-c++-common/zero-scratch-regs-leafy-2.c | 21 +++++++++++++++= ++++ > .../gcc.target/i386/zero-scratch-regs-leafy-1.c | 12 +++++++++++ > .../gcc.target/i386/zero-scratch-regs-leafy-2.c | 16 +++++++++++++++ > 8 files changed, 96 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/zero-scratch-regs-leafy-1.c > create mode 100644 gcc/testsuite/c-c++-common/zero-scratch-regs-leafy-2.c > create mode 100644 gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-= 1.c > create mode 100644 gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-= 2.c >=20 > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index 04af0584d82cc..bf11956c467fb 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -4391,10 +4391,28 @@ zeros all call-used registers that pass arguments= . > @item all-gpr-arg > zeros all call-used general purpose registers that pass > arguments. > + > +@item leafy > +Same as @samp{used} in a leaf function, and same as @samp{all} in a > +nonleaf function. > + > +@item leafy-gpr > +Same as @samp{used-gpr} in a leaf function, and same as @samp{all-gpr} > +in a nonleaf function. > + > +@item leafy-arg > +Same as @samp{used-arg} in a leaf function, and same as @samp{all-arg} > +in a nonleaf function. > + > +@item leafy-gpr-arg > +Same as @samp{used-gpr-arg} in a leaf function, and same as > +@samp{all-gpr-arg} in a nonleaf function. > + > @end table >=20 > -Of this list, @samp{used-arg}, @samp{used-gpr-arg}, @samp{all-arg}, > -and @samp{all-gpr-arg} are mainly used for ROP mitigation. > +Of this list, @samp{used-arg}, @samp{used-gpr-arg}, @samp{leafy-arg}, > +@samp{leafy-gpr-arg}, @samp{all-arg}, and @samp{all-gpr-arg} are mainly > +used for ROP mitigation. >=20 > The default for the attribute is controlled by @option{-fzero-call-used-r= egs}. > @end table > diff --git a/gcc/flag-types.h b/gcc/flag-types.h > index d2e751060ffce..b90c85167dcd4 100644 > --- a/gcc/flag-types.h > +++ b/gcc/flag-types.h > @@ -338,6 +338,7 @@ namespace zero_regs_flags { > const unsigned int ONLY_GPR =3D 1UL << 2; > const unsigned int ONLY_ARG =3D 1UL << 3; > const unsigned int ENABLED =3D 1UL << 4; > + const unsigned int LEAFY_MODE =3D 1UL << 5; > const unsigned int USED_GPR_ARG =3D ENABLED | ONLY_USED | ONLY_GPR | ON= LY_ARG; > const unsigned int USED_GPR =3D ENABLED | ONLY_USED | ONLY_GPR; > const unsigned int USED_ARG =3D ENABLED | ONLY_USED | ONLY_ARG; > @@ -346,6 +347,10 @@ namespace zero_regs_flags { > const unsigned int ALL_GPR =3D ENABLED | ONLY_GPR; > const unsigned int ALL_ARG =3D ENABLED | ONLY_ARG; > const unsigned int ALL =3D ENABLED; > + const unsigned int LEAFY_GPR_ARG =3D ENABLED | LEAFY_MODE | ONLY_GPR |= ONLY_ARG; > + const unsigned int LEAFY_GPR =3D ENABLED | LEAFY_MODE | ONLY_GPR; > + const unsigned int LEAFY_ARG =3D ENABLED | LEAFY_MODE | ONLY_ARG; > + const unsigned int LEAFY =3D ENABLED | LEAFY_MODE; > } >=20 > /* Settings of flag_incremental_link. */ > diff --git a/gcc/function.cc b/gcc/function.cc > index 6474a663b30b8..16582e698041a 100644 > --- a/gcc/function.cc > +++ b/gcc/function.cc > @@ -5879,6 +5879,9 @@ gen_call_used_regs_seq (rtx_insn *ret, unsigned int= zero_regs_type) > only_used =3D zero_regs_type & ONLY_USED; > only_arg =3D zero_regs_type & ONLY_ARG; >=20 > + if ((zero_regs_type & LEAFY_MODE) && leaf_function_p ()) > + only_used =3D true; > + > /* For each of the hard registers, we should zero it if: > 1. it is a call-used register; > and 2. it is not a fixed register; > diff --git a/gcc/opts.cc b/gcc/opts.cc > index ae079fcd20eea..39f6a1b278dc6 100644 > --- a/gcc/opts.cc > +++ b/gcc/opts.cc > @@ -2099,6 +2099,10 @@ const struct zero_call_used_regs_opts_s zero_call_= used_regs_opts[] =3D > ZERO_CALL_USED_REGS_OPT (all-gpr, zero_regs_flags::ALL_GPR), > ZERO_CALL_USED_REGS_OPT (all-arg, zero_regs_flags::ALL_ARG), > ZERO_CALL_USED_REGS_OPT (all, zero_regs_flags::ALL), > + ZERO_CALL_USED_REGS_OPT (leafy-gpr-arg, zero_regs_flags::LEAFY_GPR_ARG= ), > + ZERO_CALL_USED_REGS_OPT (leafy-gpr, zero_regs_flags::LEAFY_GPR), > + ZERO_CALL_USED_REGS_OPT (leafy-arg, zero_regs_flags::LEAFY_ARG), > + ZERO_CALL_USED_REGS_OPT (leafy, zero_regs_flags::LEAFY), > #undef ZERO_CALL_USED_REGS_OPT > {NULL, 0U} > }; > diff --git a/gcc/testsuite/c-c++-common/zero-scratch-regs-leafy-1.c b/gcc= /testsuite/c-c++-common/zero-scratch-regs-leafy-1.c > new file mode 100644 > index 0000000000000..c1a0c31ba1c37 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/zero-scratch-regs-leafy-1.c > @@ -0,0 +1,15 @@ > +/* { dg-do run } */ > +/* { dg-options "-O2 -fzero-call-used-regs=3Dleafy" } */ > + > +volatile int result =3D 0; > +int=20 > +__attribute__((noipa)) > +foo (int x) > +{ > + return x; > +} > +int main() > +{ > + result =3D foo (2); > + return 0; > +} > diff --git a/gcc/testsuite/c-c++-common/zero-scratch-regs-leafy-2.c b/gcc= /testsuite/c-c++-common/zero-scratch-regs-leafy-2.c > new file mode 100644 > index 0000000000000..d450620c1fcfe > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/zero-scratch-regs-leafy-2.c > @@ -0,0 +1,21 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > + > +#include > +int result =3D 0; > + > +int=20 > +__attribute__((noipa)) > +__attribute__ ((zero_call_used_regs("leafy"))) > +foo1 (int x) > +{ > + return (x + 1); > +} > + > +int=20 > +__attribute__((noipa)) > +__attribute__ ((zero_call_used_regs("leafy"))) > +foo2 (int x) > +{ > + return foo1 (x + 2); > +} > diff --git a/gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-1.c b/= gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-1.c > new file mode 100644 > index 0000000000000..2277710c771b7 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-1.c > @@ -0,0 +1,12 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fzero-call-used-regs=3Dleafy -fno-stack-protector = -fno-PIC" } */ > + > +void > +foo (void) > +{ > +} > + > +/* { dg-final { scan-assembler-not "vzeroall" } } */ > +/* { dg-final { scan-assembler-not "%xmm" } } */ > +/* { dg-final { scan-assembler-not "xorl\[ \t\]+%" } } */ > +/* { dg-final { scan-assembler-not "movl\[ \t\]+%" } } */ > diff --git a/gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-2.c b/= gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-2.c > new file mode 100644 > index 0000000000000..24b85c3dbb766 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/zero-scratch-regs-leafy-2.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fzero-call-used-regs=3Dleafy-gpr -fno-stack-protec= tor -fno-PIC" } */ > + > +extern int bar (int); > + > +void > +foo (void) > +{ > + int x =3D bar (0); > + if (x) > + bar (1); > +} > + > +/* { dg-final { scan-assembler "xorl\[ \t\]+%eax, %eax" } } */ > +/* { dg-final { scan-assembler "xorl\[ \t\]+%edx, %edx" } } */ > +/* { dg-final { scan-assembler "xorl\[ \t\]+%ecx, %ecx" } } */ >=20 > --=20 > Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ > Free Software Activist GNU Toolchain Engineer > Disinformation flourishes because many people care deeply about injustice > but very few check the facts. Ask me about