[Version,2,PR102281] do not add BUILTIN_CLEAR_PADDING for variables that are gimple registers
Message ID | 4B97F196-DE1A-4E67-96A6-5A0E4AC3859A@oracle.com |
---|---|
State | Committed |
Commit | 429e3b7d8bf6609ddf7c7b1e49244997e9ac76b8 |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 956F23858426 for <patchwork@sourceware.org>; Mon, 18 Oct 2021 19:26:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 956F23858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634585205; bh=43Ye77AgUffpOnEO2/rB+r8EP5SCnycOmtxyl8pQkg0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=cya89sLk65dahSVUqRZniDrICrpZmg9jDK+MLfHHSXw2ncJ3BKHzl0BBnyAaSM7RM G4IeVgn+EKflfqngWdmG6e3q0MEZArJNbE4PsBrhqeMSQibL3LNMeOOs7nfI335blz D4TGlcOMDTIcowPTP4O/apE0WcH2tmDxnwc4ylG4= 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 8405F3858C60 for <gcc-patches@gcc.gnu.org>; Mon, 18 Oct 2021 19:26:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8405F3858C60 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19IIH5ZK025779; Mon, 18 Oct 2021 19:26:13 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3brmkyec9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Oct 2021 19:26:12 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19IJLTUa139839; Mon, 18 Oct 2021 19:26:09 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by userp3030.oracle.com with ESMTP id 3bqkuw1564-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Oct 2021 19:26:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IIy6uw/hgnIwmGmFrJgwV45FEhYc+pPzJn8Rg0PiDg1nafKDOR7e2cnLiHzSlSuUy/0gbYAmUUDn5kjSYjmjCeWW+8Cq9kSlw/SCyRORI97SOi8oQ7B7V/de0jNuNGBL0G6lyOxe1h6inEJFnOsJvheENqAB3jOXbiBMgPniMelH0TGpvbzDkDWi1YwTM4mV63bqA+//m8hzMrapeVLTR/KTkrrAIE7aegu8NJTS63kfoNGffcJN3D7grmikLhowQxtQu738ThJPwoZCOpjXMiq0Ii0M6xitm2X9MWLIyAqbU6yNA/mXoGj333mkXyb5WMBJ4PvoabskmaYUFK0T8A== 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=43Ye77AgUffpOnEO2/rB+r8EP5SCnycOmtxyl8pQkg0=; b=j7WUTnN9xvr+AyCdi44aMMJJh/jcPsRGDOt8h9OQAy5zKxsKgn1vtvVDfbCwgHU/aqqv0XPDwEvPDTggqy8v6XtENJrvItx1sPMg8xLd0LDS0G2+afVMhvdZYIr+pDPoQXFnL+POl+WCgLv7dhOMyenmfFDzukGB3r6IqPp5+Ua0+cQW8lE/ysx7xcQXd+NskoaGuJrXl4o4Fga5QEX6YvoWvUjD6GY9n8yhDYkCDBobhuosRnQ/+dl5kR6c8MRWDVH6nyi7Q60rn4pPGAdKtJ18sGZ11LmFCYHEdZRzh30WmDjIq5wtOA5x3ppD4XAJaP3QxaqnPcRXzsgrXiIw+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 Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by CH0PR10MB5180.namprd10.prod.outlook.com (2603:10b6:610:db::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Mon, 18 Oct 2021 19:26:07 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::8dd2:f5a2:23e8:1a7c]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::8dd2:f5a2:23e8:1a7c%8]) with mapi id 15.20.4608.018; Mon, 18 Oct 2021 19:26:07 +0000 To: Jakub Jelinek <jakub@redhat.com> Subject: [Version 2][Patch][PR102281]do not add BUILTIN_CLEAR_PADDING for variables that are gimple registers Thread-Topic: [Version 2][Patch][PR102281]do not add BUILTIN_CLEAR_PADDING for variables that are gimple registers Thread-Index: AQHXxFX/EwE9DOF+tEeltuiQvRTEuA== Date: Mon, 18 Oct 2021 19:26:07 +0000 Message-ID: <4B97F196-DE1A-4E67-96A6-5A0E4AC3859A@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3608.120.23.2.7) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 08034e2b-844e-487a-5ef4-08d9926d223d x-ms-traffictypediagnostic: CH0PR10MB5180: x-microsoft-antispam-prvs: <CH0PR10MB5180F8DCCE6A42C723A7A7F280BC9@CH0PR10MB5180.namprd10.prod.outlook.com> x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xd9tBKox5UomIDJwXWpls5fvGIHN6B/a0oGF2Y4JvPq5onQrIC2g+FE/cWIeDwEYy6l9cXqMhqIEH3vToKOpWALz73VwpVBxtMizok7tGI+Zyghjmo09jIxnvA74QxjQhhbscRzGMKheUviqme1MRgJUNntQtXMREHEJXGr5dL5Cd+Dz+Q+CliTq5bnzuPMQycac2/0EBnZPP5jdxzQ92/RVlfcHUU6WmTypZECMui0ynEZp51Zbr/U9n7waMBcCPae6BTxz4Gd5uZvv6eY0L3iys0WSZ9oYG3GkSM1jp5tqKOQ77f5zzrVNDWgh5ocNjLd1jwiwU++W7LVYXqXV93SluVj+gZXyGb48rx3ZU43lpKQHMikRxWZFZgJU/CQrSkaAUfA2121kFr171NpsY+G4XQVzrLlOsY8fCgZJHI+GP45WwIT9dlbNpdL3pJNyVt8luNr+Kzn8eipbBmHBsb9UvsbV3tVZPzg93VlTLuGiXzdS1DjgvD8SgAEurF4TcJ8OFefRxkETFIOkDNLsp/V7pnMarZ87loq6ziOfTIMJsvXLg4+64tXaErI0fnJjCU2OakCENPOjnH3h8Lcrrav2xKcMz3l+dIw5tN5AChYxNpXRO81l9V0gQdn6AGuKQQ1KWdNMAY/pby9xK21KaxMsVOFEQlBexpt7e8u/otlSHN5gS6m5BTQOSgFlk4h0wjDpfsJO1l1T7C6P/WYigR7LVx2WQts5ssShxt+7SGm+PfInobX+BmNZDRQhQqSOnG/U0NZoqhrGkUrfkRJ37lZkA+FZ5ztqDR+D8y0CjFjyV8WM7krJaseHaj2jJjUlZ+pYytWQTfyQpAcGUbkaC/bE530XF9K5XiWNsZsbXuZ3DeJtLyBaaZI3ARv+y6tH 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:(366004)(38070700005)(36756003)(6486002)(8936002)(508600001)(86362001)(186003)(71200400001)(6506007)(53546011)(316002)(8676002)(6512007)(122000001)(4326008)(91956017)(6916009)(76116006)(66946007)(54906003)(44832011)(66446008)(83380400001)(4001150100001)(66476007)(33656002)(64756008)(5660300002)(2616005)(66556008)(38100700002)(2906002)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: cOCa9Pi3nbbxB6EWSpfp7khDg4xNmQlztb+5dZ4lqyIm4gcbwwHydjranwcrBQeCol1aL9BcpzbQkH+ve+rScAZFDaQZArEYKTeASupwA7cZ0lum1qA+vy4XuaKzeiLm1dtyeRKqGQyrBmKpVVjCxNp5GPTx0SR5U0bDwI/Jw0IenSHA49Eez3rsdr+vSrXOxDUZsWT1OFX8f3mmcclKHs0Wj7C6LXbBXIU8cEeLER7wSr6KGv1qMKap8/TX6A7/FbtsZJs+bNJ1sTEHGfGj150DV0tB06Vc9pnNb1c6mSCJvNSbv7sA28kz/3SyDOXr4fUKQZtRCFqHcdXM7EQbeJrLlGEr+ANYcLEMuA1Hm2pR5f+Eks4GY2SW9srWSCueBygwEfAhN/+/yO6bdimwQrToJHzqG6GUfx3QbEvw6/2iBlPrn9FwtmwfbNIgjFcasb+yQMT2CmdREwCi5C8FVUq0Uiz6OGnwadK5M7oWDd+iwjR9Cyao3Vx6rOLHtRvdXzhwpju4v5+tVImz339HYF1bOFsL5LM5GGXzP3AwIDpWmtn3NklvfaGbwgpGGVMreBRo0tplzCyhdo2enFpVzcBgkGBcwsxVAqQIynWvhZKOWBiaIs+REcX868iRHnnyKTBY/y9afYaJaBZtvDe1jTqDaQyv53WxXde6depTpGKShdbsNv0UnR0eppN/1JFtgOuHSUzm3a2S7y0VLfojqx7r8kB4ru9yb+lyVSYJ7213u9uwiNFZN4Q/CsY7BKY/1KHVrKPJ8brhEhoIcnTt8SgfcXtluUlnoBS9d6rSNpDHukO3IpZD6Yw59FIlXXnv09mh5n+NeInFUCQJodYxDu6ijgdBwIP/54w3R97DR31PY8JQN41cYfJg+45XdmVItcH2Dw0XW3YdhqnnQ2F1DvzrQRjIHweHij15dYXRqzfZX0Iy+/thMt3PQGsOPYU6gob7zs6Qkho+2ug0a0pd3sYFy27eH3Zua5NCDs/g02FdIvLTHPUpHgeKZLHbf+g2BdZC3wez9exvgh8jljKg/eT0PSFMlll/p/OODyR4VC3zwI2O2QPaKm+4/i1U3ffjhSKV4dMK90o/ioVuROfF9LYyf9Pvlh3BwBvemA70o2ZT1nudg4MjdJ+1G2wzSSX9K8JAscpF0fDmbgVUacwgKCFUheYXF3Ig+uT2Ew31NamDEZfURut1iHMCJ7SJEYR2iK+iV5mCXZBCjQjGx+BbUgFcRLKNZz06B/OkDG7a9fRddrXyQFPwSmYymPbFynuMLyMDfKfxaiaxn2mKlZKM86c1HpB+kg6TLahd0MzmFc0UCcINOLgOK6kK4qPUp/w7xZKdg0wQcY35jQ0MphIlp8v5OTL4VZ0KvVfS1+KR1Ec= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-ID: <BCB2354E6D38EB46BF27087037C04165@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: 08034e2b-844e-487a-5ef4-08d9926d223d X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Oct 2021 19:26:07.2048 (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: AoNBfSX6L2zffLAtd8/M5Ixb8EwTquPuvlcGueIC31+YdWxFseKujYCvyY7G45VlGDOn518wQYvIJeTj1KzR6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5180 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10141 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 bulkscore=0 phishscore=0 adultscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110180108 X-Proofpoint-GUID: Zx8bxP-3jkUJ0D2vL4PJZqc961kX-v-k X-Proofpoint-ORIG-GUID: Zx8bxP-3jkUJ0D2vL4PJZqc961kX-v-k X-Spam-Status: No, score=-11.3 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Qing Zhao <qing.zhao@oracle.com> Cc: gcc-patches Nick Alcock via <gcc-patches@gcc.gnu.org>, richard Biener <rguenther@suse.de> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[Version,2,PR102281] do not add BUILTIN_CLEAR_PADDING for variables that are gimple registers
|
|
Commit Message
Qing Zhao
Oct. 18, 2021, 7:26 p.m. UTC
Hi, Jakub,
This is the 2nd version of the patch based on your comment.
Bootstrapped on both x86 and aarch64. Regression testings are ongoing.
Please let me know if this is ready for committing?
Thanks a lot.
Qing.
======================
From d6f60370dee69b5deb3d7ef51873a5e986490782 Mon Sep 17 00:00:00 2001
From: Qing Zhao <qing.zhao@oracle.com>
Date: Mon, 18 Oct 2021 19:04:39 +0000
Subject: [PATCH] PR 102281 (-ftrivial-auto-var-init=zero causes ice)
Do not add call to __builtin_clear_padding when a variable is a gimple
register or it might not have padding.
gcc/ChangeLog:
2021-10-18 qing zhao <qing.zhao@oracle.com>
* gimplify.c (gimplify_decl_expr): Do not add call to
__builtin_clear_padding when a variable is a gimple register
or it might not have padding.
(gimplify_init_constructor): Likewise.
gcc/testsuite/ChangeLog:
2021-10-18 qing zhao <qing.zhao@oracle.com>
* c-c++-common/pr102281.c: New test.
* gcc.target/i386/auto-init-2.c: Adjust testing case.
* gcc.target/i386/auto-init-4.c: Likewise.
* gcc.target/i386/auto-init-6.c: Likewise.
* gcc.target/aarch64/auto-init-6.c: Likewise.
---
gcc/gimplify.c | 25 ++++++++++++++-----
gcc/testsuite/c-c++-common/pr102281.c | 17 +++++++++++++
.../gcc.target/aarch64/auto-init-6.c | 4 +--
gcc/testsuite/gcc.target/i386/auto-init-2.c | 2 +-
gcc/testsuite/gcc.target/i386/auto-init-4.c | 10 +++-----
gcc/testsuite/gcc.target/i386/auto-init-6.c | 7 +++---
6 files changed, 47 insertions(+), 18 deletions(-)
create mode 100644 gcc/testsuite/c-c++-common/pr102281.c
Comments
> On Oct 18, 2021, at 2:26 PM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, Jakub, > > This is the 2nd version of the patch based on your comment. > > Bootstrapped on both x86 and aarch64. Regression testings are ongoing. The regression testing was done. Looks good. Okay for committing? Thanks. Qing > > Please let me know if this is ready for committing? > > Thanks a lot. > > Qing. > > ====================== > > From d6f60370dee69b5deb3d7ef51873a5e986490782 Mon Sep 17 00:00:00 2001 > From: Qing Zhao <qing.zhao@oracle.com> > Date: Mon, 18 Oct 2021 19:04:39 +0000 > Subject: [PATCH] PR 102281 (-ftrivial-auto-var-init=zero causes ice) > > Do not add call to __builtin_clear_padding when a variable is a gimple > register or it might not have padding. > > gcc/ChangeLog: > > 2021-10-18 qing zhao <qing.zhao@oracle.com> > > * gimplify.c (gimplify_decl_expr): Do not add call to > __builtin_clear_padding when a variable is a gimple register > or it might not have padding. > (gimplify_init_constructor): Likewise. > > gcc/testsuite/ChangeLog: > > 2021-10-18 qing zhao <qing.zhao@oracle.com> > > * c-c++-common/pr102281.c: New test. > * gcc.target/i386/auto-init-2.c: Adjust testing case. > * gcc.target/i386/auto-init-4.c: Likewise. > * gcc.target/i386/auto-init-6.c: Likewise. > * gcc.target/aarch64/auto-init-6.c: Likewise. > --- > gcc/gimplify.c | 25 ++++++++++++++----- > gcc/testsuite/c-c++-common/pr102281.c | 17 +++++++++++++ > .../gcc.target/aarch64/auto-init-6.c | 4 +-- > gcc/testsuite/gcc.target/i386/auto-init-2.c | 2 +- > gcc/testsuite/gcc.target/i386/auto-init-4.c | 10 +++----- > gcc/testsuite/gcc.target/i386/auto-init-6.c | 7 +++--- > 6 files changed, 47 insertions(+), 18 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/pr102281.c > > diff --git a/gcc/gimplify.c b/gcc/gimplify.c > index d8e4b139349..b27dc0ed308 100644 > --- a/gcc/gimplify.c > +++ b/gcc/gimplify.c > @@ -1784,8 +1784,8 @@ gimple_add_init_for_auto_var (tree decl, > that padding is initialized to zero. So, we always initialize paddings > to zeroes regardless INIT_TYPE. > To do the padding initialization, we insert a call to > - __BUILTIN_CLEAR_PADDING (&decl, 0, for_auto_init = true). > - Note, we add an additional dummy argument for __BUILTIN_CLEAR_PADDING, > + __builtin_clear_padding (&decl, 0, for_auto_init = true). > + Note, we add an additional dummy argument for __builtin_clear_padding, > 'for_auto_init' to distinguish whether this call is for automatic > variable initialization or not. > */ > @@ -1954,8 +1954,14 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) > pattern initialization. > In order to make the paddings as zeroes for pattern init, We > should add a call to __builtin_clear_padding to clear the > - paddings to zero in compatiple with CLANG. */ > - if (flag_auto_var_init == AUTO_INIT_PATTERN) > + paddings to zero in compatiple with CLANG. > + We cannot insert this call if the variable is a gimple register > + since __builtin_clear_padding will take the address of the > + variable. As a result, if a long double/_Complex long double > + variable will spilled into stack later, its padding is 0XFE. */ > + if (flag_auto_var_init == AUTO_INIT_PATTERN > + && !is_gimple_reg (decl) > + && clear_padding_type_may_have_padding_p (TREE_TYPE (decl))) > gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p); > } > } > @@ -5384,12 +5390,19 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, > > /* If the user requests to initialize automatic variables, we > should initialize paddings inside the variable. Add a call to > - __BUILTIN_CLEAR_PADDING (&object, 0, for_auto_init = true) to > + __builtin_clear_pading (&object, 0, for_auto_init = true) to > initialize paddings of object always to zero regardless of > INIT_TYPE. Note, we will not insert this call if the aggregate > variable has be completely cleared already or it's initialized > - with an empty constructor. */ > + with an empty constructor. We cannot insert this call if the > + variable is a gimple register since __builtin_clear_padding will take > + the address of the variable. As a result, if a long double/_Complex long > + double variable will be spilled into stack later, its padding cannot > + be cleared with __builtin_clear_padding. We should clear its padding > + when it is spilled into memory. */ > if (is_init_expr > + && !is_gimple_reg (object) > + && clear_padding_type_may_have_padding_p (type) > && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor) > || !AGGREGATE_TYPE_P (type)) > && is_var_need_auto_init (object)) > diff --git a/gcc/testsuite/c-c++-common/pr102281.c b/gcc/testsuite/c-c++-common/pr102281.c > new file mode 100644 > index 00000000000..a961451b5a7 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/pr102281.c > @@ -0,0 +1,17 @@ > +/* PR102281 */ > +/* { dg-do compile } */ > +/* { dg-options "-ftrivial-auto-var-init=zero -Wno-psabi" } */ > +long long var1; > +float var2; > +typedef long long V __attribute__((__vector_size__(2 * sizeof(long long)))); > +typedef float W __attribute__((__vector_size__(4 * sizeof(float)))); > + > +V foo (void) > +{ > + return (V) {var1}; > +} > + > +W bar (void) > +{ > + return (W) {var2}; > +} > diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > index 27c16b33678..0456c66f496 100644 > --- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > +++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > @@ -1,6 +1,6 @@ > /* Verify pattern initialization for complex type automatic variables. */ > /* { dg-do compile } */ > -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ > +/* { dg-options "-ftrivial-auto-var-init=pattern" } */ > > > _Complex long double result; > @@ -15,4 +15,4 @@ _Complex long double foo() > return result; > } > > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 3 "expand" } } */ > +/* { dg-final { scan-assembler-times "word\t-16843010" 14 } } */ > diff --git a/gcc/testsuite/gcc.target/i386/auto-init-2.c b/gcc/testsuite/gcc.target/i386/auto-init-2.c > index e22930ae89b..0c59c62dacf 100644 > --- a/gcc/testsuite/gcc.target/i386/auto-init-2.c > +++ b/gcc/testsuite/gcc.target/i386/auto-init-2.c > @@ -29,7 +29,7 @@ void foo() > return; > } > > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 2 "expand" } } */ > +/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 1 "expand" } } */ > /* { dg-final { scan-rtl-dump-times "0xfffffffffffffefe" 1 "expand" } } */ > /* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target lp64 } } } */ > /* { dg-final { scan-rtl-dump-times "0xfefefefefefefefe" 3 "expand" { target lp64 } } } */ > diff --git a/gcc/testsuite/gcc.target/i386/auto-init-4.c b/gcc/testsuite/gcc.target/i386/auto-init-4.c > index 7b46c74a073..1803dd45842 100644 > --- a/gcc/testsuite/gcc.target/i386/auto-init-4.c > +++ b/gcc/testsuite/gcc.target/i386/auto-init-4.c > @@ -1,6 +1,6 @@ > /* Verify pattern initialization for floating point type automatic variables. */ > /* { dg-do compile } */ > -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ > +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ > > long double result; > > @@ -14,8 +14,6 @@ long double foo() > return result; > } > > -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 1 "expand" { target { ! ia32 } } } } */ > -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" { target { ! ia32 } } } } */ > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 1 "expand" { target { ! ia32 } } } } */ > -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target ia32 } } } */ > -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 2 "expand" { target ia32 } } } */ > + > +/* { dg-final { scan-assembler-times "long\t-16843010" 5 { target { ! ia32 } } } } */ > +/* { dg-final { scan-assembler-times "long\t-16843010" 3 { target { ia32 } } } } */ > diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c > index f75081edce4..339f8bc2966 100644 > --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c > +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c > @@ -1,6 +1,6 @@ > /* Verify pattern initialization for complex type automatic variables. */ > /* { dg-do compile } */ > -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ > +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ > > > _Complex long double result; > @@ -15,5 +15,6 @@ _Complex long double foo() > return result; > } > > -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" } } */ > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 2 "expand" } } */ > +/* { dg-final { scan-assembler-times "long\t-16843010" 10 { target { ! ia32 } } } } */ > +/* { dg-final { scan-assembler-times "long\t-16843010" 6 { target { ia32 } } } } */ > + > -- > 2.27.0 > >
Ping…. Is this Okay for trunk? > On Oct 18, 2021, at 2:26 PM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, Jakub, > > This is the 2nd version of the patch based on your comment. > > Bootstrapped on both x86 and aarch64. Regression testings are ongoing. The regression testing looks good. Thanks. Qing > > Please let me know if this is ready for committing? > > Thanks a lot. > > Qing. > > ====================== > > From d6f60370dee69b5deb3d7ef51873a5e986490782 Mon Sep 17 00:00:00 2001 > From: Qing Zhao <qing.zhao@oracle.com> > Date: Mon, 18 Oct 2021 19:04:39 +0000 > Subject: [PATCH] PR 102281 (-ftrivial-auto-var-init=zero causes ice) > > Do not add call to __builtin_clear_padding when a variable is a gimple > register or it might not have padding. > > gcc/ChangeLog: > > 2021-10-18 qing zhao <qing.zhao@oracle.com> > > * gimplify.c (gimplify_decl_expr): Do not add call to > __builtin_clear_padding when a variable is a gimple register > or it might not have padding. > (gimplify_init_constructor): Likewise. > > gcc/testsuite/ChangeLog: > > 2021-10-18 qing zhao <qing.zhao@oracle.com> > > * c-c++-common/pr102281.c: New test. > * gcc.target/i386/auto-init-2.c: Adjust testing case. > * gcc.target/i386/auto-init-4.c: Likewise. > * gcc.target/i386/auto-init-6.c: Likewise. > * gcc.target/aarch64/auto-init-6.c: Likewise. > --- > gcc/gimplify.c | 25 ++++++++++++++----- > gcc/testsuite/c-c++-common/pr102281.c | 17 +++++++++++++ > .../gcc.target/aarch64/auto-init-6.c | 4 +-- > gcc/testsuite/gcc.target/i386/auto-init-2.c | 2 +- > gcc/testsuite/gcc.target/i386/auto-init-4.c | 10 +++----- > gcc/testsuite/gcc.target/i386/auto-init-6.c | 7 +++--- > 6 files changed, 47 insertions(+), 18 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/pr102281.c > > diff --git a/gcc/gimplify.c b/gcc/gimplify.c > index d8e4b139349..b27dc0ed308 100644 > --- a/gcc/gimplify.c > +++ b/gcc/gimplify.c > @@ -1784,8 +1784,8 @@ gimple_add_init_for_auto_var (tree decl, > that padding is initialized to zero. So, we always initialize paddings > to zeroes regardless INIT_TYPE. > To do the padding initialization, we insert a call to > - __BUILTIN_CLEAR_PADDING (&decl, 0, for_auto_init = true). > - Note, we add an additional dummy argument for __BUILTIN_CLEAR_PADDING, > + __builtin_clear_padding (&decl, 0, for_auto_init = true). > + Note, we add an additional dummy argument for __builtin_clear_padding, > 'for_auto_init' to distinguish whether this call is for automatic > variable initialization or not. > */ > @@ -1954,8 +1954,14 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) > pattern initialization. > In order to make the paddings as zeroes for pattern init, We > should add a call to __builtin_clear_padding to clear the > - paddings to zero in compatiple with CLANG. */ > - if (flag_auto_var_init == AUTO_INIT_PATTERN) > + paddings to zero in compatiple with CLANG. > + We cannot insert this call if the variable is a gimple register > + since __builtin_clear_padding will take the address of the > + variable. As a result, if a long double/_Complex long double > + variable will spilled into stack later, its padding is 0XFE. */ > + if (flag_auto_var_init == AUTO_INIT_PATTERN > + && !is_gimple_reg (decl) > + && clear_padding_type_may_have_padding_p (TREE_TYPE (decl))) > gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p); > } > } > @@ -5384,12 +5390,19 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, > > /* If the user requests to initialize automatic variables, we > should initialize paddings inside the variable. Add a call to > - __BUILTIN_CLEAR_PADDING (&object, 0, for_auto_init = true) to > + __builtin_clear_pading (&object, 0, for_auto_init = true) to > initialize paddings of object always to zero regardless of > INIT_TYPE. Note, we will not insert this call if the aggregate > variable has be completely cleared already or it's initialized > - with an empty constructor. */ > + with an empty constructor. We cannot insert this call if the > + variable is a gimple register since __builtin_clear_padding will take > + the address of the variable. As a result, if a long double/_Complex long > + double variable will be spilled into stack later, its padding cannot > + be cleared with __builtin_clear_padding. We should clear its padding > + when it is spilled into memory. */ > if (is_init_expr > + && !is_gimple_reg (object) > + && clear_padding_type_may_have_padding_p (type) > && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor) > || !AGGREGATE_TYPE_P (type)) > && is_var_need_auto_init (object)) > diff --git a/gcc/testsuite/c-c++-common/pr102281.c b/gcc/testsuite/c-c++-common/pr102281.c > new file mode 100644 > index 00000000000..a961451b5a7 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/pr102281.c > @@ -0,0 +1,17 @@ > +/* PR102281 */ > +/* { dg-do compile } */ > +/* { dg-options "-ftrivial-auto-var-init=zero -Wno-psabi" } */ > +long long var1; > +float var2; > +typedef long long V __attribute__((__vector_size__(2 * sizeof(long long)))); > +typedef float W __attribute__((__vector_size__(4 * sizeof(float)))); > + > +V foo (void) > +{ > + return (V) {var1}; > +} > + > +W bar (void) > +{ > + return (W) {var2}; > +} > diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > index 27c16b33678..0456c66f496 100644 > --- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > +++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > @@ -1,6 +1,6 @@ > /* Verify pattern initialization for complex type automatic variables. */ > /* { dg-do compile } */ > -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ > +/* { dg-options "-ftrivial-auto-var-init=pattern" } */ > > > _Complex long double result; > @@ -15,4 +15,4 @@ _Complex long double foo() > return result; > } > > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 3 "expand" } } */ > +/* { dg-final { scan-assembler-times "word\t-16843010" 14 } } */ > diff --git a/gcc/testsuite/gcc.target/i386/auto-init-2.c b/gcc/testsuite/gcc.target/i386/auto-init-2.c > index e22930ae89b..0c59c62dacf 100644 > --- a/gcc/testsuite/gcc.target/i386/auto-init-2.c > +++ b/gcc/testsuite/gcc.target/i386/auto-init-2.c > @@ -29,7 +29,7 @@ void foo() > return; > } > > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 2 "expand" } } */ > +/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 1 "expand" } } */ > /* { dg-final { scan-rtl-dump-times "0xfffffffffffffefe" 1 "expand" } } */ > /* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target lp64 } } } */ > /* { dg-final { scan-rtl-dump-times "0xfefefefefefefefe" 3 "expand" { target lp64 } } } */ > diff --git a/gcc/testsuite/gcc.target/i386/auto-init-4.c b/gcc/testsuite/gcc.target/i386/auto-init-4.c > index 7b46c74a073..1803dd45842 100644 > --- a/gcc/testsuite/gcc.target/i386/auto-init-4.c > +++ b/gcc/testsuite/gcc.target/i386/auto-init-4.c > @@ -1,6 +1,6 @@ > /* Verify pattern initialization for floating point type automatic variables. */ > /* { dg-do compile } */ > -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ > +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ > > long double result; > > @@ -14,8 +14,6 @@ long double foo() > return result; > } > > -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 1 "expand" { target { ! ia32 } } } } */ > -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" { target { ! ia32 } } } } */ > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 1 "expand" { target { ! ia32 } } } } */ > -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target ia32 } } } */ > -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 2 "expand" { target ia32 } } } */ > + > +/* { dg-final { scan-assembler-times "long\t-16843010" 5 { target { ! ia32 } } } } */ > +/* { dg-final { scan-assembler-times "long\t-16843010" 3 { target { ia32 } } } } */ > diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c > index f75081edce4..339f8bc2966 100644 > --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c > +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c > @@ -1,6 +1,6 @@ > /* Verify pattern initialization for complex type automatic variables. */ > /* { dg-do compile } */ > -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ > +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ > > > _Complex long double result; > @@ -15,5 +15,6 @@ _Complex long double foo() > return result; > } > > -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" } } */ > -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 2 "expand" } } */ > +/* { dg-final { scan-assembler-times "long\t-16843010" 10 { target { ! ia32 } } } } */ > +/* { dg-final { scan-assembler-times "long\t-16843010" 6 { target { ia32 } } } } */ > + > -- > 2.27.0 > >
Ping…. Hi, Based on the previous discussion, I thought that we have agreed that the proposed patch for this current bug is the correct fix. And This bug is an important bug that need to be fixed. I have created another new PR for the other potential issue with padding initialization for long double/_Complex long double variables with explicit initializer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102781, and will be fixed separately later if needed. Please take a look of the new patch and let me know whether there is any more issue with this version? Or it’s okay for commit now? Thanks. Qing > On Oct 25, 2021, at 9:16 AM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Ping…. > > Is this Okay for trunk? > >> On Oct 18, 2021, at 2:26 PM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: >> >> Hi, Jakub, >> >> This is the 2nd version of the patch based on your comment. >> >> Bootstrapped on both x86 and aarch64. Regression testings are ongoing. > > The regression testing looks good. > > Thanks. > > Qing >> >> Please let me know if this is ready for committing? >> >> Thanks a lot. >> >> Qing. >> >> ====================== >> >> From d6f60370dee69b5deb3d7ef51873a5e986490782 Mon Sep 17 00:00:00 2001 >> From: Qing Zhao <qing.zhao@oracle.com> >> Date: Mon, 18 Oct 2021 19:04:39 +0000 >> Subject: [PATCH] PR 102281 (-ftrivial-auto-var-init=zero causes ice) >> >> Do not add call to __builtin_clear_padding when a variable is a gimple >> register or it might not have padding. >> >> gcc/ChangeLog: >> >> 2021-10-18 qing zhao <qing.zhao@oracle.com> >> >> * gimplify.c (gimplify_decl_expr): Do not add call to >> __builtin_clear_padding when a variable is a gimple register >> or it might not have padding. >> (gimplify_init_constructor): Likewise. >> >> gcc/testsuite/ChangeLog: >> >> 2021-10-18 qing zhao <qing.zhao@oracle.com> >> >> * c-c++-common/pr102281.c: New test. >> * gcc.target/i386/auto-init-2.c: Adjust testing case. >> * gcc.target/i386/auto-init-4.c: Likewise. >> * gcc.target/i386/auto-init-6.c: Likewise. >> * gcc.target/aarch64/auto-init-6.c: Likewise. >> --- >> gcc/gimplify.c | 25 ++++++++++++++----- >> gcc/testsuite/c-c++-common/pr102281.c | 17 +++++++++++++ >> .../gcc.target/aarch64/auto-init-6.c | 4 +-- >> gcc/testsuite/gcc.target/i386/auto-init-2.c | 2 +- >> gcc/testsuite/gcc.target/i386/auto-init-4.c | 10 +++----- >> gcc/testsuite/gcc.target/i386/auto-init-6.c | 7 +++--- >> 6 files changed, 47 insertions(+), 18 deletions(-) >> create mode 100644 gcc/testsuite/c-c++-common/pr102281.c >> >> diff --git a/gcc/gimplify.c b/gcc/gimplify.c >> index d8e4b139349..b27dc0ed308 100644 >> --- a/gcc/gimplify.c >> +++ b/gcc/gimplify.c >> @@ -1784,8 +1784,8 @@ gimple_add_init_for_auto_var (tree decl, >> that padding is initialized to zero. So, we always initialize paddings >> to zeroes regardless INIT_TYPE. >> To do the padding initialization, we insert a call to >> - __BUILTIN_CLEAR_PADDING (&decl, 0, for_auto_init = true). >> - Note, we add an additional dummy argument for __BUILTIN_CLEAR_PADDING, >> + __builtin_clear_padding (&decl, 0, for_auto_init = true). >> + Note, we add an additional dummy argument for __builtin_clear_padding, >> 'for_auto_init' to distinguish whether this call is for automatic >> variable initialization or not. >> */ >> @@ -1954,8 +1954,14 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) >> pattern initialization. >> In order to make the paddings as zeroes for pattern init, We >> should add a call to __builtin_clear_padding to clear the >> - paddings to zero in compatiple with CLANG. */ >> - if (flag_auto_var_init == AUTO_INIT_PATTERN) >> + paddings to zero in compatiple with CLANG. >> + We cannot insert this call if the variable is a gimple register >> + since __builtin_clear_padding will take the address of the >> + variable. As a result, if a long double/_Complex long double >> + variable will spilled into stack later, its padding is 0XFE. */ >> + if (flag_auto_var_init == AUTO_INIT_PATTERN >> + && !is_gimple_reg (decl) >> + && clear_padding_type_may_have_padding_p (TREE_TYPE (decl))) >> gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p); >> } >> } >> @@ -5384,12 +5390,19 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, >> >> /* If the user requests to initialize automatic variables, we >> should initialize paddings inside the variable. Add a call to >> - __BUILTIN_CLEAR_PADDING (&object, 0, for_auto_init = true) to >> + __builtin_clear_pading (&object, 0, for_auto_init = true) to >> initialize paddings of object always to zero regardless of >> INIT_TYPE. Note, we will not insert this call if the aggregate >> variable has be completely cleared already or it's initialized >> - with an empty constructor. */ >> + with an empty constructor. We cannot insert this call if the >> + variable is a gimple register since __builtin_clear_padding will take >> + the address of the variable. As a result, if a long double/_Complex long >> + double variable will be spilled into stack later, its padding cannot >> + be cleared with __builtin_clear_padding. We should clear its padding >> + when it is spilled into memory. */ >> if (is_init_expr >> + && !is_gimple_reg (object) >> + && clear_padding_type_may_have_padding_p (type) >> && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor) >> || !AGGREGATE_TYPE_P (type)) >> && is_var_need_auto_init (object)) >> diff --git a/gcc/testsuite/c-c++-common/pr102281.c b/gcc/testsuite/c-c++-common/pr102281.c >> new file mode 100644 >> index 00000000000..a961451b5a7 >> --- /dev/null >> +++ b/gcc/testsuite/c-c++-common/pr102281.c >> @@ -0,0 +1,17 @@ >> +/* PR102281 */ >> +/* { dg-do compile } */ >> +/* { dg-options "-ftrivial-auto-var-init=zero -Wno-psabi" } */ >> +long long var1; >> +float var2; >> +typedef long long V __attribute__((__vector_size__(2 * sizeof(long long)))); >> +typedef float W __attribute__((__vector_size__(4 * sizeof(float)))); >> + >> +V foo (void) >> +{ >> + return (V) {var1}; >> +} >> + >> +W bar (void) >> +{ >> + return (W) {var2}; >> +} >> diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c >> index 27c16b33678..0456c66f496 100644 >> --- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c >> +++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c >> @@ -1,6 +1,6 @@ >> /* Verify pattern initialization for complex type automatic variables. */ >> /* { dg-do compile } */ >> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ >> +/* { dg-options "-ftrivial-auto-var-init=pattern" } */ >> >> >> _Complex long double result; >> @@ -15,4 +15,4 @@ _Complex long double foo() >> return result; >> } >> >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 3 "expand" } } */ >> +/* { dg-final { scan-assembler-times "word\t-16843010" 14 } } */ >> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-2.c b/gcc/testsuite/gcc.target/i386/auto-init-2.c >> index e22930ae89b..0c59c62dacf 100644 >> --- a/gcc/testsuite/gcc.target/i386/auto-init-2.c >> +++ b/gcc/testsuite/gcc.target/i386/auto-init-2.c >> @@ -29,7 +29,7 @@ void foo() >> return; >> } >> >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 2 "expand" } } */ >> +/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 1 "expand" } } */ >> /* { dg-final { scan-rtl-dump-times "0xfffffffffffffefe" 1 "expand" } } */ >> /* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target lp64 } } } */ >> /* { dg-final { scan-rtl-dump-times "0xfefefefefefefefe" 3 "expand" { target lp64 } } } */ >> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-4.c b/gcc/testsuite/gcc.target/i386/auto-init-4.c >> index 7b46c74a073..1803dd45842 100644 >> --- a/gcc/testsuite/gcc.target/i386/auto-init-4.c >> +++ b/gcc/testsuite/gcc.target/i386/auto-init-4.c >> @@ -1,6 +1,6 @@ >> /* Verify pattern initialization for floating point type automatic variables. */ >> /* { dg-do compile } */ >> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ >> +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ >> >> long double result; >> >> @@ -14,8 +14,6 @@ long double foo() >> return result; >> } >> >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 1 "expand" { target { ! ia32 } } } } */ >> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" { target { ! ia32 } } } } */ >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 1 "expand" { target { ! ia32 } } } } */ >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target ia32 } } } */ >> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 2 "expand" { target ia32 } } } */ >> + >> +/* { dg-final { scan-assembler-times "long\t-16843010" 5 { target { ! ia32 } } } } */ >> +/* { dg-final { scan-assembler-times "long\t-16843010" 3 { target { ia32 } } } } */ >> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c >> index f75081edce4..339f8bc2966 100644 >> --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c >> +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c >> @@ -1,6 +1,6 @@ >> /* Verify pattern initialization for complex type automatic variables. */ >> /* { dg-do compile } */ >> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ >> +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ >> >> >> _Complex long double result; >> @@ -15,5 +15,6 @@ _Complex long double foo() >> return result; >> } >> >> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" } } */ >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 2 "expand" } } */ >> +/* { dg-final { scan-assembler-times "long\t-16843010" 10 { target { ! ia32 } } } } */ >> +/* { dg-final { scan-assembler-times "long\t-16843010" 6 { target { ia32 } } } } */ >> + >> -- >> 2.27.0 >> >> >
On Thu, 28 Oct 2021, Qing Zhao wrote: > Ping…. > > Hi, > > Based on the previous discussion, I thought that we have agreed that the proposed patch for this current bug is the correct fix. > And This bug is an important bug that need to be fixed. > > I have created another new PR for the other potential issue with padding initialization for long double/_Complex long double variables with explicit initializer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102781, and will be fixed separately later if needed. > > Please take a look of the new patch and let me know whether there is any > more issue with this version? Or it’s okay for commit now? I think it's reasonable. Thus OK unless Jakub has comments. Thanks, Richard. > Thanks. > > Qing > > > > > On Oct 25, 2021, at 9:16 AM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > Ping…. > > > > Is this Okay for trunk? > > > >> On Oct 18, 2021, at 2:26 PM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > >> > >> Hi, Jakub, > >> > >> This is the 2nd version of the patch based on your comment. > >> > >> Bootstrapped on both x86 and aarch64. Regression testings are ongoing. > > > > The regression testing looks good. > > > > Thanks. > > > > Qing > >> > >> Please let me know if this is ready for committing? > >> > >> Thanks a lot. > >> > >> Qing. > >> > >> ====================== > >> > >> From d6f60370dee69b5deb3d7ef51873a5e986490782 Mon Sep 17 00:00:00 2001 > >> From: Qing Zhao <qing.zhao@oracle.com> > >> Date: Mon, 18 Oct 2021 19:04:39 +0000 > >> Subject: [PATCH] PR 102281 (-ftrivial-auto-var-init=zero causes ice) > >> > >> Do not add call to __builtin_clear_padding when a variable is a gimple > >> register or it might not have padding. > >> > >> gcc/ChangeLog: > >> > >> 2021-10-18 qing zhao <qing.zhao@oracle.com> > >> > >> * gimplify.c (gimplify_decl_expr): Do not add call to > >> __builtin_clear_padding when a variable is a gimple register > >> or it might not have padding. > >> (gimplify_init_constructor): Likewise. > >> > >> gcc/testsuite/ChangeLog: > >> > >> 2021-10-18 qing zhao <qing.zhao@oracle.com> > >> > >> * c-c++-common/pr102281.c: New test. > >> * gcc.target/i386/auto-init-2.c: Adjust testing case. > >> * gcc.target/i386/auto-init-4.c: Likewise. > >> * gcc.target/i386/auto-init-6.c: Likewise. > >> * gcc.target/aarch64/auto-init-6.c: Likewise. > >> --- > >> gcc/gimplify.c | 25 ++++++++++++++----- > >> gcc/testsuite/c-c++-common/pr102281.c | 17 +++++++++++++ > >> .../gcc.target/aarch64/auto-init-6.c | 4 +-- > >> gcc/testsuite/gcc.target/i386/auto-init-2.c | 2 +- > >> gcc/testsuite/gcc.target/i386/auto-init-4.c | 10 +++----- > >> gcc/testsuite/gcc.target/i386/auto-init-6.c | 7 +++--- > >> 6 files changed, 47 insertions(+), 18 deletions(-) > >> create mode 100644 gcc/testsuite/c-c++-common/pr102281.c > >> > >> diff --git a/gcc/gimplify.c b/gcc/gimplify.c > >> index d8e4b139349..b27dc0ed308 100644 > >> --- a/gcc/gimplify.c > >> +++ b/gcc/gimplify.c > >> @@ -1784,8 +1784,8 @@ gimple_add_init_for_auto_var (tree decl, > >> that padding is initialized to zero. So, we always initialize paddings > >> to zeroes regardless INIT_TYPE. > >> To do the padding initialization, we insert a call to > >> - __BUILTIN_CLEAR_PADDING (&decl, 0, for_auto_init = true). > >> - Note, we add an additional dummy argument for __BUILTIN_CLEAR_PADDING, > >> + __builtin_clear_padding (&decl, 0, for_auto_init = true). > >> + Note, we add an additional dummy argument for __builtin_clear_padding, > >> 'for_auto_init' to distinguish whether this call is for automatic > >> variable initialization or not. > >> */ > >> @@ -1954,8 +1954,14 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) > >> pattern initialization. > >> In order to make the paddings as zeroes for pattern init, We > >> should add a call to __builtin_clear_padding to clear the > >> - paddings to zero in compatiple with CLANG. */ > >> - if (flag_auto_var_init == AUTO_INIT_PATTERN) > >> + paddings to zero in compatiple with CLANG. > >> + We cannot insert this call if the variable is a gimple register > >> + since __builtin_clear_padding will take the address of the > >> + variable. As a result, if a long double/_Complex long double > >> + variable will spilled into stack later, its padding is 0XFE. */ > >> + if (flag_auto_var_init == AUTO_INIT_PATTERN > >> + && !is_gimple_reg (decl) > >> + && clear_padding_type_may_have_padding_p (TREE_TYPE (decl))) > >> gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p); > >> } > >> } > >> @@ -5384,12 +5390,19 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, > >> > >> /* If the user requests to initialize automatic variables, we > >> should initialize paddings inside the variable. Add a call to > >> - __BUILTIN_CLEAR_PADDING (&object, 0, for_auto_init = true) to > >> + __builtin_clear_pading (&object, 0, for_auto_init = true) to > >> initialize paddings of object always to zero regardless of > >> INIT_TYPE. Note, we will not insert this call if the aggregate > >> variable has be completely cleared already or it's initialized > >> - with an empty constructor. */ > >> + with an empty constructor. We cannot insert this call if the > >> + variable is a gimple register since __builtin_clear_padding will take > >> + the address of the variable. As a result, if a long double/_Complex long > >> + double variable will be spilled into stack later, its padding cannot > >> + be cleared with __builtin_clear_padding. We should clear its padding > >> + when it is spilled into memory. */ > >> if (is_init_expr > >> + && !is_gimple_reg (object) > >> + && clear_padding_type_may_have_padding_p (type) > >> && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor) > >> || !AGGREGATE_TYPE_P (type)) > >> && is_var_need_auto_init (object)) > >> diff --git a/gcc/testsuite/c-c++-common/pr102281.c b/gcc/testsuite/c-c++-common/pr102281.c > >> new file mode 100644 > >> index 00000000000..a961451b5a7 > >> --- /dev/null > >> +++ b/gcc/testsuite/c-c++-common/pr102281.c > >> @@ -0,0 +1,17 @@ > >> +/* PR102281 */ > >> +/* { dg-do compile } */ > >> +/* { dg-options "-ftrivial-auto-var-init=zero -Wno-psabi" } */ > >> +long long var1; > >> +float var2; > >> +typedef long long V __attribute__((__vector_size__(2 * sizeof(long long)))); > >> +typedef float W __attribute__((__vector_size__(4 * sizeof(float)))); > >> + > >> +V foo (void) > >> +{ > >> + return (V) {var1}; > >> +} > >> + > >> +W bar (void) > >> +{ > >> + return (W) {var2}; > >> +} > >> diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > >> index 27c16b33678..0456c66f496 100644 > >> --- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > >> +++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c > >> @@ -1,6 +1,6 @@ > >> /* Verify pattern initialization for complex type automatic variables. */ > >> /* { dg-do compile } */ > >> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ > >> +/* { dg-options "-ftrivial-auto-var-init=pattern" } */ > >> > >> > >> _Complex long double result; > >> @@ -15,4 +15,4 @@ _Complex long double foo() > >> return result; > >> } > >> > >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 3 "expand" } } */ > >> +/* { dg-final { scan-assembler-times "word\t-16843010" 14 } } */ > >> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-2.c b/gcc/testsuite/gcc.target/i386/auto-init-2.c > >> index e22930ae89b..0c59c62dacf 100644 > >> --- a/gcc/testsuite/gcc.target/i386/auto-init-2.c > >> +++ b/gcc/testsuite/gcc.target/i386/auto-init-2.c > >> @@ -29,7 +29,7 @@ void foo() > >> return; > >> } > >> > >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 2 "expand" } } */ > >> +/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 1 "expand" } } */ > >> /* { dg-final { scan-rtl-dump-times "0xfffffffffffffefe" 1 "expand" } } */ > >> /* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target lp64 } } } */ > >> /* { dg-final { scan-rtl-dump-times "0xfefefefefefefefe" 3 "expand" { target lp64 } } } */ > >> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-4.c b/gcc/testsuite/gcc.target/i386/auto-init-4.c > >> index 7b46c74a073..1803dd45842 100644 > >> --- a/gcc/testsuite/gcc.target/i386/auto-init-4.c > >> +++ b/gcc/testsuite/gcc.target/i386/auto-init-4.c > >> @@ -1,6 +1,6 @@ > >> /* Verify pattern initialization for floating point type automatic variables. */ > >> /* { dg-do compile } */ > >> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ > >> +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ > >> > >> long double result; > >> > >> @@ -14,8 +14,6 @@ long double foo() > >> return result; > >> } > >> > >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 1 "expand" { target { ! ia32 } } } } */ > >> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" { target { ! ia32 } } } } */ > >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 1 "expand" { target { ! ia32 } } } } */ > >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target ia32 } } } */ > >> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 2 "expand" { target ia32 } } } */ > >> + > >> +/* { dg-final { scan-assembler-times "long\t-16843010" 5 { target { ! ia32 } } } } */ > >> +/* { dg-final { scan-assembler-times "long\t-16843010" 3 { target { ia32 } } } } */ > >> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c > >> index f75081edce4..339f8bc2966 100644 > >> --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c > >> +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c > >> @@ -1,6 +1,6 @@ > >> /* Verify pattern initialization for complex type automatic variables. */ > >> /* { dg-do compile } */ > >> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ > >> +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ > >> > >> > >> _Complex long double result; > >> @@ -15,5 +15,6 @@ _Complex long double foo() > >> return result; > >> } > >> > >> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" } } */ > >> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 2 "expand" } } */ > >> +/* { dg-final { scan-assembler-times "long\t-16843010" 10 { target { ! ia32 } } } } */ > >> +/* { dg-final { scan-assembler-times "long\t-16843010" 6 { target { ia32 } } } } */ > >> + > >> -- > >> 2.27.0 > >> > >> > > > >
Thank you. I will commit this patch the beginning of next week. Jakub, let me know if you have any objection on this. Qing > On Oct 29, 2021, at 2:21 AM, Richard Biener <rguenther@suse.de> wrote: > > On Thu, 28 Oct 2021, Qing Zhao wrote: > >> Ping…. >> >> Hi, >> >> Based on the previous discussion, I thought that we have agreed that the proposed patch for this current bug is the correct fix. >> And This bug is an important bug that need to be fixed. >> >> I have created another new PR for the other potential issue with padding initialization for long double/_Complex long double variables with explicit initializer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102781, and will be fixed separately later if needed. >> >> Please take a look of the new patch and let me know whether there is any >> more issue with this version? Or it’s okay for commit now? > > I think it's reasonable. > > Thus OK unless Jakub has comments. > > Thanks, > Richard. > >> Thanks. >> >> Qing >> >> >> >>> On Oct 25, 2021, at 9:16 AM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: >>> >>> Ping…. >>> >>> Is this Okay for trunk? >>> >>>> On Oct 18, 2021, at 2:26 PM, Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: >>>> >>>> Hi, Jakub, >>>> >>>> This is the 2nd version of the patch based on your comment. >>>> >>>> Bootstrapped on both x86 and aarch64. Regression testings are ongoing. >>> >>> The regression testing looks good. >>> >>> Thanks. >>> >>> Qing >>>> >>>> Please let me know if this is ready for committing? >>>> >>>> Thanks a lot. >>>> >>>> Qing. >>>> >>>> ====================== >>>> >>>> From d6f60370dee69b5deb3d7ef51873a5e986490782 Mon Sep 17 00:00:00 2001 >>>> From: Qing Zhao <qing.zhao@oracle.com> >>>> Date: Mon, 18 Oct 2021 19:04:39 +0000 >>>> Subject: [PATCH] PR 102281 (-ftrivial-auto-var-init=zero causes ice) >>>> >>>> Do not add call to __builtin_clear_padding when a variable is a gimple >>>> register or it might not have padding. >>>> >>>> gcc/ChangeLog: >>>> >>>> 2021-10-18 qing zhao <qing.zhao@oracle.com> >>>> >>>> * gimplify.c (gimplify_decl_expr): Do not add call to >>>> __builtin_clear_padding when a variable is a gimple register >>>> or it might not have padding. >>>> (gimplify_init_constructor): Likewise. >>>> >>>> gcc/testsuite/ChangeLog: >>>> >>>> 2021-10-18 qing zhao <qing.zhao@oracle.com> >>>> >>>> * c-c++-common/pr102281.c: New test. >>>> * gcc.target/i386/auto-init-2.c: Adjust testing case. >>>> * gcc.target/i386/auto-init-4.c: Likewise. >>>> * gcc.target/i386/auto-init-6.c: Likewise. >>>> * gcc.target/aarch64/auto-init-6.c: Likewise. >>>> --- >>>> gcc/gimplify.c | 25 ++++++++++++++----- >>>> gcc/testsuite/c-c++-common/pr102281.c | 17 +++++++++++++ >>>> .../gcc.target/aarch64/auto-init-6.c | 4 +-- >>>> gcc/testsuite/gcc.target/i386/auto-init-2.c | 2 +- >>>> gcc/testsuite/gcc.target/i386/auto-init-4.c | 10 +++----- >>>> gcc/testsuite/gcc.target/i386/auto-init-6.c | 7 +++--- >>>> 6 files changed, 47 insertions(+), 18 deletions(-) >>>> create mode 100644 gcc/testsuite/c-c++-common/pr102281.c >>>> >>>> diff --git a/gcc/gimplify.c b/gcc/gimplify.c >>>> index d8e4b139349..b27dc0ed308 100644 >>>> --- a/gcc/gimplify.c >>>> +++ b/gcc/gimplify.c >>>> @@ -1784,8 +1784,8 @@ gimple_add_init_for_auto_var (tree decl, >>>> that padding is initialized to zero. So, we always initialize paddings >>>> to zeroes regardless INIT_TYPE. >>>> To do the padding initialization, we insert a call to >>>> - __BUILTIN_CLEAR_PADDING (&decl, 0, for_auto_init = true). >>>> - Note, we add an additional dummy argument for __BUILTIN_CLEAR_PADDING, >>>> + __builtin_clear_padding (&decl, 0, for_auto_init = true). >>>> + Note, we add an additional dummy argument for __builtin_clear_padding, >>>> 'for_auto_init' to distinguish whether this call is for automatic >>>> variable initialization or not. >>>> */ >>>> @@ -1954,8 +1954,14 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) >>>> pattern initialization. >>>> In order to make the paddings as zeroes for pattern init, We >>>> should add a call to __builtin_clear_padding to clear the >>>> - paddings to zero in compatiple with CLANG. */ >>>> - if (flag_auto_var_init == AUTO_INIT_PATTERN) >>>> + paddings to zero in compatiple with CLANG. >>>> + We cannot insert this call if the variable is a gimple register >>>> + since __builtin_clear_padding will take the address of the >>>> + variable. As a result, if a long double/_Complex long double >>>> + variable will spilled into stack later, its padding is 0XFE. */ >>>> + if (flag_auto_var_init == AUTO_INIT_PATTERN >>>> + && !is_gimple_reg (decl) >>>> + && clear_padding_type_may_have_padding_p (TREE_TYPE (decl))) >>>> gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p); >>>> } >>>> } >>>> @@ -5384,12 +5390,19 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, >>>> >>>> /* If the user requests to initialize automatic variables, we >>>> should initialize paddings inside the variable. Add a call to >>>> - __BUILTIN_CLEAR_PADDING (&object, 0, for_auto_init = true) to >>>> + __builtin_clear_pading (&object, 0, for_auto_init = true) to >>>> initialize paddings of object always to zero regardless of >>>> INIT_TYPE. Note, we will not insert this call if the aggregate >>>> variable has be completely cleared already or it's initialized >>>> - with an empty constructor. */ >>>> + with an empty constructor. We cannot insert this call if the >>>> + variable is a gimple register since __builtin_clear_padding will take >>>> + the address of the variable. As a result, if a long double/_Complex long >>>> + double variable will be spilled into stack later, its padding cannot >>>> + be cleared with __builtin_clear_padding. We should clear its padding >>>> + when it is spilled into memory. */ >>>> if (is_init_expr >>>> + && !is_gimple_reg (object) >>>> + && clear_padding_type_may_have_padding_p (type) >>>> && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor) >>>> || !AGGREGATE_TYPE_P (type)) >>>> && is_var_need_auto_init (object)) >>>> diff --git a/gcc/testsuite/c-c++-common/pr102281.c b/gcc/testsuite/c-c++-common/pr102281.c >>>> new file mode 100644 >>>> index 00000000000..a961451b5a7 >>>> --- /dev/null >>>> +++ b/gcc/testsuite/c-c++-common/pr102281.c >>>> @@ -0,0 +1,17 @@ >>>> +/* PR102281 */ >>>> +/* { dg-do compile } */ >>>> +/* { dg-options "-ftrivial-auto-var-init=zero -Wno-psabi" } */ >>>> +long long var1; >>>> +float var2; >>>> +typedef long long V __attribute__((__vector_size__(2 * sizeof(long long)))); >>>> +typedef float W __attribute__((__vector_size__(4 * sizeof(float)))); >>>> + >>>> +V foo (void) >>>> +{ >>>> + return (V) {var1}; >>>> +} >>>> + >>>> +W bar (void) >>>> +{ >>>> + return (W) {var2}; >>>> +} >>>> diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c >>>> index 27c16b33678..0456c66f496 100644 >>>> --- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c >>>> +++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c >>>> @@ -1,6 +1,6 @@ >>>> /* Verify pattern initialization for complex type automatic variables. */ >>>> /* { dg-do compile } */ >>>> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ >>>> +/* { dg-options "-ftrivial-auto-var-init=pattern" } */ >>>> >>>> >>>> _Complex long double result; >>>> @@ -15,4 +15,4 @@ _Complex long double foo() >>>> return result; >>>> } >>>> >>>> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 3 "expand" } } */ >>>> +/* { dg-final { scan-assembler-times "word\t-16843010" 14 } } */ >>>> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-2.c b/gcc/testsuite/gcc.target/i386/auto-init-2.c >>>> index e22930ae89b..0c59c62dacf 100644 >>>> --- a/gcc/testsuite/gcc.target/i386/auto-init-2.c >>>> +++ b/gcc/testsuite/gcc.target/i386/auto-init-2.c >>>> @@ -29,7 +29,7 @@ void foo() >>>> return; >>>> } >>>> >>>> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 2 "expand" } } */ >>>> +/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 1 "expand" } } */ >>>> /* { dg-final { scan-rtl-dump-times "0xfffffffffffffefe" 1 "expand" } } */ >>>> /* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target lp64 } } } */ >>>> /* { dg-final { scan-rtl-dump-times "0xfefefefefefefefe" 3 "expand" { target lp64 } } } */ >>>> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-4.c b/gcc/testsuite/gcc.target/i386/auto-init-4.c >>>> index 7b46c74a073..1803dd45842 100644 >>>> --- a/gcc/testsuite/gcc.target/i386/auto-init-4.c >>>> +++ b/gcc/testsuite/gcc.target/i386/auto-init-4.c >>>> @@ -1,6 +1,6 @@ >>>> /* Verify pattern initialization for floating point type automatic variables. */ >>>> /* { dg-do compile } */ >>>> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ >>>> +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ >>>> >>>> long double result; >>>> >>>> @@ -14,8 +14,6 @@ long double foo() >>>> return result; >>>> } >>>> >>>> -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 1 "expand" { target { ! ia32 } } } } */ >>>> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" { target { ! ia32 } } } } */ >>>> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 1 "expand" { target { ! ia32 } } } } */ >>>> -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target ia32 } } } */ >>>> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 2 "expand" { target ia32 } } } */ >>>> + >>>> +/* { dg-final { scan-assembler-times "long\t-16843010" 5 { target { ! ia32 } } } } */ >>>> +/* { dg-final { scan-assembler-times "long\t-16843010" 3 { target { ia32 } } } } */ >>>> diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c >>>> index f75081edce4..339f8bc2966 100644 >>>> --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c >>>> +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c >>>> @@ -1,6 +1,6 @@ >>>> /* Verify pattern initialization for complex type automatic variables. */ >>>> /* { dg-do compile } */ >>>> -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ >>>> +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ >>>> >>>> >>>> _Complex long double result; >>>> @@ -15,5 +15,6 @@ _Complex long double foo() >>>> return result; >>>> } >>>> >>>> -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" } } */ >>>> -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 2 "expand" } } */ >>>> +/* { dg-final { scan-assembler-times "long\t-16843010" 10 { target { ! ia32 } } } } */ >>>> +/* { dg-final { scan-assembler-times "long\t-16843010" 6 { target { ia32 } } } } */ >>>> + >>>> -- >>>> 2.27.0 >>>> >>>> >>> >> >> > > -- > Richard Biener <rguenther@suse.de> > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, > Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
On Fri, Oct 29, 2021 at 04:55:07PM +0000, Qing Zhao wrote: > I will commit this patch the beginning of next week. > Jakub, let me know if you have any objection on this. No objections, sorry for the delay. Jakub
diff --git a/gcc/gimplify.c b/gcc/gimplify.c index d8e4b139349..b27dc0ed308 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1784,8 +1784,8 @@ gimple_add_init_for_auto_var (tree decl, that padding is initialized to zero. So, we always initialize paddings to zeroes regardless INIT_TYPE. To do the padding initialization, we insert a call to - __BUILTIN_CLEAR_PADDING (&decl, 0, for_auto_init = true). - Note, we add an additional dummy argument for __BUILTIN_CLEAR_PADDING, + __builtin_clear_padding (&decl, 0, for_auto_init = true). + Note, we add an additional dummy argument for __builtin_clear_padding, 'for_auto_init' to distinguish whether this call is for automatic variable initialization or not. */ @@ -1954,8 +1954,14 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) pattern initialization. In order to make the paddings as zeroes for pattern init, We should add a call to __builtin_clear_padding to clear the - paddings to zero in compatiple with CLANG. */ - if (flag_auto_var_init == AUTO_INIT_PATTERN) + paddings to zero in compatiple with CLANG. + We cannot insert this call if the variable is a gimple register + since __builtin_clear_padding will take the address of the + variable. As a result, if a long double/_Complex long double + variable will spilled into stack later, its padding is 0XFE. */ + if (flag_auto_var_init == AUTO_INIT_PATTERN + && !is_gimple_reg (decl) + && clear_padding_type_may_have_padding_p (TREE_TYPE (decl))) gimple_add_padding_init_for_auto_var (decl, is_vla, seq_p); } } @@ -5384,12 +5390,19 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, /* If the user requests to initialize automatic variables, we should initialize paddings inside the variable. Add a call to - __BUILTIN_CLEAR_PADDING (&object, 0, for_auto_init = true) to + __builtin_clear_pading (&object, 0, for_auto_init = true) to initialize paddings of object always to zero regardless of INIT_TYPE. Note, we will not insert this call if the aggregate variable has be completely cleared already or it's initialized - with an empty constructor. */ + with an empty constructor. We cannot insert this call if the + variable is a gimple register since __builtin_clear_padding will take + the address of the variable. As a result, if a long double/_Complex long + double variable will be spilled into stack later, its padding cannot + be cleared with __builtin_clear_padding. We should clear its padding + when it is spilled into memory. */ if (is_init_expr + && !is_gimple_reg (object) + && clear_padding_type_may_have_padding_p (type) && ((AGGREGATE_TYPE_P (type) && !cleared && !is_empty_ctor) || !AGGREGATE_TYPE_P (type)) && is_var_need_auto_init (object)) diff --git a/gcc/testsuite/c-c++-common/pr102281.c b/gcc/testsuite/c-c++-common/pr102281.c new file mode 100644 index 00000000000..a961451b5a7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr102281.c @@ -0,0 +1,17 @@ +/* PR102281 */ +/* { dg-do compile } */ +/* { dg-options "-ftrivial-auto-var-init=zero -Wno-psabi" } */ +long long var1; +float var2; +typedef long long V __attribute__((__vector_size__(2 * sizeof(long long)))); +typedef float W __attribute__((__vector_size__(4 * sizeof(float)))); + +V foo (void) +{ + return (V) {var1}; +} + +W bar (void) +{ + return (W) {var2}; +} diff --git a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c index 27c16b33678..0456c66f496 100644 --- a/gcc/testsuite/gcc.target/aarch64/auto-init-6.c +++ b/gcc/testsuite/gcc.target/aarch64/auto-init-6.c @@ -1,6 +1,6 @@ /* Verify pattern initialization for complex type automatic variables. */ /* { dg-do compile } */ -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand" } */ +/* { dg-options "-ftrivial-auto-var-init=pattern" } */ _Complex long double result; @@ -15,4 +15,4 @@ _Complex long double foo() return result; } -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 3 "expand" } } */ +/* { dg-final { scan-assembler-times "word\t-16843010" 14 } } */ diff --git a/gcc/testsuite/gcc.target/i386/auto-init-2.c b/gcc/testsuite/gcc.target/i386/auto-init-2.c index e22930ae89b..0c59c62dacf 100644 --- a/gcc/testsuite/gcc.target/i386/auto-init-2.c +++ b/gcc/testsuite/gcc.target/i386/auto-init-2.c @@ -29,7 +29,7 @@ void foo() return; } -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 2 "expand" } } */ +/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe" 1 "expand" } } */ /* { dg-final { scan-rtl-dump-times "0xfffffffffffffefe" 1 "expand" } } */ /* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target lp64 } } } */ /* { dg-final { scan-rtl-dump-times "0xfefefefefefefefe" 3 "expand" { target lp64 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/auto-init-4.c b/gcc/testsuite/gcc.target/i386/auto-init-4.c index 7b46c74a073..1803dd45842 100644 --- a/gcc/testsuite/gcc.target/i386/auto-init-4.c +++ b/gcc/testsuite/gcc.target/i386/auto-init-4.c @@ -1,6 +1,6 @@ /* Verify pattern initialization for floating point type automatic variables. */ /* { dg-do compile } */ -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ long double result; @@ -14,8 +14,6 @@ long double foo() return result; } -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 1 "expand" { target { ! ia32 } } } } */ -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" { target { ! ia32 } } } } */ -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 1 "expand" { target { ! ia32 } } } } */ -/* { dg-final { scan-rtl-dump-times "0xfffffffffefefefe" 2 "expand" { target ia32 } } } */ -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 2 "expand" { target ia32 } } } */ + +/* { dg-final { scan-assembler-times "long\t-16843010" 5 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "long\t-16843010" 3 { target { ia32 } } } } */ diff --git a/gcc/testsuite/gcc.target/i386/auto-init-6.c b/gcc/testsuite/gcc.target/i386/auto-init-6.c index f75081edce4..339f8bc2966 100644 --- a/gcc/testsuite/gcc.target/i386/auto-init-6.c +++ b/gcc/testsuite/gcc.target/i386/auto-init-6.c @@ -1,6 +1,6 @@ /* Verify pattern initialization for complex type automatic variables. */ /* { dg-do compile } */ -/* { dg-options "-ftrivial-auto-var-init=pattern -fdump-rtl-expand -march=x86-64 -mtune=generic -msse" } */ +/* { dg-options "-ftrivial-auto-var-init=pattern -march=x86-64 -mtune=generic -msse" } */ _Complex long double result; @@ -15,5 +15,6 @@ _Complex long double foo() return result; } -/* { dg-final { scan-rtl-dump-times "\\\[0xfefefefefefefefe\\\]" 1 "expand" } } */ -/* { dg-final { scan-rtl-dump-times "0xfffffffffffffffe\\\]\\\) repeated x16" 2 "expand" } } */ +/* { dg-final { scan-assembler-times "long\t-16843010" 10 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "long\t-16843010" 6 { target { ia32 } } } } */ +