[PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64
Message ID | VE1PR08MB48965E8D838E5A66176719708AA49@VE1PR08MB4896.eurprd08.prod.outlook.com |
---|---|
State | New |
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 97545385842F for <patchwork@sourceware.org>; Fri, 24 Sep 2021 12:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97545385842F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632488355; bh=4Mz8FGHGBT1qUpUlpvuzTfG3k4x4+j5FT75ErajXeWc=; h=To:Subject:Date:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=l4xG/ck2Z2FFe/mo1ChdEsXEHHl1Fv6ykjn7YvWGP543lBI3TjWR5eK7lm7AfaXZs JIlzAPWuFZSaTrwKTO6W0veq7I8TdddTiay7QLwU0hbNt5RwbbQ8hEtI/PxFofXlj1 UlMehvBYwCif8wYy9/GBgrwAxNiglCdCafr8dCzs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80057.outbound.protection.outlook.com [40.107.8.57]) by sourceware.org (Postfix) with ESMTPS id 577623858402 for <gcc-patches@gcc.gnu.org>; Fri, 24 Sep 2021 12:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 577623858402 Received: from AM6PR0202CA0070.eurprd02.prod.outlook.com (2603:10a6:20b:3a::47) by AM9PR08MB6788.eurprd08.prod.outlook.com (2603:10a6:20b:30d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Fri, 24 Sep 2021 12:58:41 +0000 Received: from AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:3a:cafe::42) by AM6PR0202CA0070.outlook.office365.com (2603:10a6:20b:3a::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15 via Frontend Transport; Fri, 24 Sep 2021 12:58:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT039.mail.protection.outlook.com (10.152.17.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13 via Frontend Transport; Fri, 24 Sep 2021 12:58:40 +0000 Received: ("Tessian outbound c21c48fbc857:v103"); Fri, 24 Sep 2021 12:58:40 +0000 X-CR-MTA-TID: 64aa7808 Received: from d79300148095.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 175CD2F4-F021-418A-8930-45F953449390.1; Fri, 24 Sep 2021 12:58:30 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d79300148095.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 24 Sep 2021 12:58:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F53t6Lw7DHq8GWVgTSMcABa2kxt8NP965i/YVYu9QSi2sXz3ZaWgb3DFXPmWTKflsaKEs4tTteTuNxsjwBULJ1SfG1WFoQt1Fwnr3lNBLBoo7wOiUGKi+c/okELwB6MKw5DxoPoeZI7GHx02QDpH4omtJWMMAvf6mahA4TnkvQIcyytzaaWgCZjp7ihC0CJGZMVOsdJkx9fX0oQgsOlGi1GjA+L/1imnQJPUjFYunTT4/XlXa1q01BOK6WRsiBOI/uMd+8VfmJM/hQfwqHRSA8S1NgwPmeMYkUOKwqO2+Mmymwjrmga1IBlQfotdL+h9Haurf3RoWPE42Tp3CdNpTA== 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; bh=4Mz8FGHGBT1qUpUlpvuzTfG3k4x4+j5FT75ErajXeWc=; b=SRUIvWf56U9NUgQJmtvuHDX4IXS0oqPfHG8ZokoaJhdWTv0dsCTa6f7bxEIhXONt4JY5QMY6rlJDjuYvSH1SG/JkKm3xc18FDvm2Hn7HzWyBPawH+OSi0ufnsHcRaB5L5117K3fRvc+c4lCJbidudHYO8kVOCvEv1fkgDxVGXc5oKPrHDTlbABuFi0qX+kJ6P9LncNZphAIzVThqPTaFOjk+/8SMUy5RTYerdamqiRJeic3IaaOAPMwwLGS8NfZ+WhDJsIalC/+TAPRfZjgQiDQAZriqCbg7KdCv3SXlZ5vlQSO9Z9sOEYkb5xbcqCgy/B+1kSO8bo2cQeU4wbb3yA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from VE1PR08MB4896.eurprd08.prod.outlook.com (2603:10a6:802:b1::18) by VI1PR08MB5534.eurprd08.prod.outlook.com (2603:10a6:803:135::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Fri, 24 Sep 2021 12:58:22 +0000 Received: from VE1PR08MB4896.eurprd08.prod.outlook.com ([fe80::940f:a21:5d48:99ce]) by VE1PR08MB4896.eurprd08.prod.outlook.com ([fe80::940f:a21:5d48:99ce%7]) with mapi id 15.20.4544.015; Fri, 24 Sep 2021 12:58:21 +0000 To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org> Subject: FW: [PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 Thread-Topic: [PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 Thread-Index: AdemJAzq/Su9tMKwSxq0T4DuKjThAQFpqaXw Date: Fri, 24 Sep 2021 12:58:21 +0000 Message-ID: <VE1PR08MB48965E8D838E5A66176719708AA49@VE1PR08MB4896.eurprd08.prod.outlook.com> References: <VE1PR08MB48965978A668ADAD7C7F13E58AD69@VE1PR08MB4896.eurprd08.prod.outlook.com> In-Reply-To: <VE1PR08MB48965978A668ADAD7C7F13E58AD69@VE1PR08MB4896.eurprd08.prod.outlook.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-ts-tracking-id: 053DCACCB7A7C14592F8E611B2BC4C92.0 x-checkrecipientchecked: true Authentication-Results-Original: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: da33bb0d-66e4-4924-b795-08d97f5b0871 x-ms-traffictypediagnostic: VI1PR08MB5534:|AM9PR08MB6788: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: <AM9PR08MB6788D24506B2C29C03BECC2C8AA49@AM9PR08MB6788.eurprd08.prod.outlook.com> x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:6430;OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: gWSMjaQXH4SGFrR32BJZfxDrjXjbNQuMuslWHDTUr1dZ0MEQHM93ajZID20+IstHVxWrX2ftypcukcmluDouv4ubZ/KgAvg2/+8wW+HJv1THwROIrgSrSMMGDWmJ8F/kzS8Ri4KmYzyMXfQ6+VhKCjpo0OmCb3Kz7IjA9aretpqNmGI/c1oeEcQ40kffOFtEm2/XTvyLRWbl8POtBUIiamFG0O+q3nLrD3YGuVD2hYArqr4iLrFxQoDaN5SozKfkLj8bV13uQf4EjGDPTEujxAxiAXAWDCJzbJ9XFqoMm/uicJhdNFX9REsxZ45YpUsqeb9VVhtqS/1XWNw/7HkuCnbvoDFEw1SeTQMp4jxpPXUIxj7j2Id1TRsI16ps9HqxZCeFwY4SU0s9TYqtMpWiVw7sAf06o1mfYIHbtEcUGG+GQFCes/el27TEz6Hy1qjJf1aChs88+TpiTYV7tIK3sPq3WoF5V2RNda6kdcj28ip6M9mHRF0F3Pdp1ZodBEzcHQ1dtHrvvWaJfkNG2SUtmhGVMrSteUYqAF5SgO0qUNYY9Hu53eaP3fLt+bkrz9RUJNYh7k96OBclp+1Gz6H1xgzwtlQ5qXGiSKa4p8OeMUKSvYxxaZVmtLic2cpXbeyl3ak+OjxSQkbHDCm+et6VdYq4uuWPibfkXr69ZlTANeHSQrSwT3nm6I0GUhlw8bIQ0Ly3nSXm6uQzQebqMk5SzCNJaTD4gAKDguSbMxTW9G4a2ddZPLUFWzGkOr9t5CXbOy56o97s0uhTbshUCUw+bbF2GyLhley62vfIcVOoRiO1WL7x7z4H70BdziS7drrQQDjGlhTtGLntjEvYoFENLQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR08MB4896.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(4326008)(53546011)(71200400001)(966005)(33656002)(122000001)(508600001)(8936002)(38100700002)(26005)(8676002)(52536014)(186003)(99936003)(6916009)(76116006)(64756008)(66616009)(5660300002)(66446008)(66556008)(54906003)(66476007)(38070700005)(2906002)(55236004)(83380400001)(66946007)(55016002)(7696005)(316002)(9686003)(6506007)(66574015)(86362001); DIR:OUT; SFP:1101; Content-Type: multipart/mixed; boundary="_002_VE1PR08MB48965E8D838E5A66176719708AA49VE1PR08MB4896eurp_" MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5534 Original-Authentication-Results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 067939f5-fc37-46a3-ad63-08d97f5afd15 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CcK2bm61JlDacG8ZsiM+vwVLl1mXaqXb4AnD3oU9eE5WutUmHgC24LHu0Gi/NM034utQW8n3/1GCRx+G6uiu8HONp/JL33uL6a8nQufORQ5xm9EbEGF+myiOMTeaZcBUnlE728v1XNXRiggklReNfhRqUUhD3l0zWV4Mt4c2k9QZMz6izI8feX6ky0wJsYOG1yCAZMLhDYN4Y8byQP87w690oyQ3i+833/HUvJNwf7tMoNNOusUPvuvSDQSQ9Ph0H4a79stTXrxqH6cHDk8mx8OWmB0KMbVUw3qTzqYTIU+yo6QVaYnDi0KFQDIEaInVVKrXzXBjuzaaRy34BkSxpZUJFxe+ZzQXChZtqhrM+zWSMkj3o20lnGS+Qqy3XTxSEQBO/gMAx4+qN/MaZZ45aOG5QTQQwHmfCA7vI5MBeIU5sy17puAbEJoq2P0J7FUAmBAIGwT3lLrKcrahT31mt2JU0TZBw9FJ11+ZaK1q19t1CZ1UhW5rdBMaKpQ/GOM7GSS+W3yQp1T4dUnGNqbno5ZOKGxr1Ygg8UcjjkASFHnwAxqYfet7R0V14ymYlIdEaMrJvbBmR1AwKaX4kO4yUbcRJmFfsMcXWIgyioW26QBVhMNWDjpeAw7UVd1Fazd0MXOHMD74nseQvGx+k9GdVI8mxZwydg5nEKoTCC543qayWqSQ+b+GpdFGtIxwcTUTODeoBu/0ywRelMRPFtpExL1TIwGVNGRJ45a72xCpkGdLIpE6xRzl1DrNBhMASkacTvXseVXwrHxaP053fzioLG/XL0RXNGBwK+PUoNdU8h4zatpDY5KiSNy3KPerkzDQNRlZGWApYF3fcESbZ3nFyg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(33964004)(186003)(356005)(66574015)(36860700001)(86362001)(8936002)(99936003)(26005)(336012)(33656002)(8676002)(4326008)(81166007)(508600001)(21480400003)(70206006)(70586007)(82310400003)(966005)(55016002)(47076005)(6916009)(66616009)(83380400001)(54906003)(316002)(235185007)(7696005)(5660300002)(6506007)(2906002)(53546011)(52536014)(9686003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2021 12:58:40.8418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da33bb0d-66e4-4924-b795-08d97f5b0871 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6788 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY 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: Jirui Wu via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jirui Wu <Jirui.Wu@arm.com> Cc: Richard Sandiford <Richard.Sandiford@arm.com>, "ian@airs.com" <ian@airs.com>, 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 |
[PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64
|
|
Commit Message
Jirui Wu
Sept. 24, 2021, 12:58 p.m. UTC
Hi, Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html The patch is attached as text for ease of use. Is there anything that needs to change? Ok for master? If OK, can it be committed for me, I have no commit rights. Jirui Wu -----Original Message----- From: Jirui Wu Sent: Friday, September 10, 2021 10:14 AM To: Richard Biener <rguenther@suse.de> Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers <joseph@codesourcery.com> Subject: [PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 Hi, Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html Ok for master? If OK, can it be committed for me, I have no commit rights. Jirui Wu -----Original Message----- From: Jirui Wu Sent: Friday, September 3, 2021 12:39 PM To: 'Richard Biener' <rguenther@suse.de> Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers <joseph@codesourcery.com> Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 Ping -----Original Message----- From: Jirui Wu Sent: Friday, August 20, 2021 4:28 PM To: Richard Biener <rguenther@suse.de> Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers <joseph@codesourcery.com> Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 > -----Original Message----- > From: Richard Biener <rguenther@suse.de> > Sent: Friday, August 20, 2021 8:15 AM > To: Jirui Wu <Jirui.Wu@arm.com> > Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski > <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; > ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers > <joseph@codesourcery.com> > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for > (double)(int) under -ffast-math on aarch64 > > On Thu, 19 Aug 2021, Jirui Wu wrote: > > > Hi all, > > > > This patch generates FRINTZ instruction to optimize type casts. > > > > The changes in this patch covers: > > * Generate FRINTZ for (double)(int) casts. > > * Add new test cases. > > > > The intermediate type is not checked according to the C99 spec. > > Overflow of the integral part when casting floats to integers causes > undefined behavior. > > As a result, optimization to trunc() is not invalid. > > I've confirmed that Boolean type does not match the matching condition. > > > > Regtested on aarch64-none-linux-gnu and no issues. > > > > Ok for master? If OK can it be committed for me, I have no commit rights. > > +/* Detected a fix_trunc cast inside a float type cast, > + use IFN_TRUNC to optimize. */ > +#if GIMPLE > +(simplify > + (float (fix_trunc @0)) > + (if (direct_internal_fn_supported_p (IFN_TRUNC, type, > + OPTIMIZE_FOR_BOTH) > + && flag_unsafe_math_optimizations > + && type == TREE_TYPE (@0)) > > types_match (type, TREE_TYPE (@0)) > > please. Please perform cheap tests first (the flag test). > > + (IFN_TRUNC @0))) > +#endif > > why only for GIMPLE? I'm not sure flag_unsafe_math_optimizations is a > good test here. If you say we can use undefined behavior of any > overflow of the fix_trunc operation what do we guard here? > If it's Inf/NaN input then flag_finite_math_only would be more > appropriate, if it's behavior for -0. (I suppose trunc (-0.0) == -0.0 > and thus "wrong") then a && !HONOR_SIGNED_ZEROS (type) is missing > instead. If it's setting of FENV state and possibly trapping on > overflow (but it's undefined?!) then flag_trapping_math covers the > latter but we don't have any flag for eliding FENV state affecting > transforms, so there the kitchen-sink flag_unsafe_math_optimizations might apply. > > So - which is it? > This change is only for GIMPLE because we can't test for the optab support without being in GIMPLE. direct_internal_fn_supported_p is defined only for GIMPLE. IFN_TRUNC's documentation mentions nothing for zero, NaNs/inf inputs. So I think the correct guard is just flag_fp_int_builtin_inexact. !flag_trapping_math because the operation can only still raise inexacts. The new pattern is moved next to the place you mentioned. Ok for master? If OK can it be committed for me, I have no commit rights. Thanks, Jirui > Note there's also the pattern > > /* Handle cases of two conversions in a row. */ (for ocvt (convert > float > fix_trunc) (for icvt (convert float) > (simplify > (ocvt (icvt@1 @0)) > (with > { > ... > > which is related so please put the new pattern next to that (the set > of conversions handled there does not include (float (fix_trunc @0))) > > Thanks, > Richard. > > > Thanks, > > Jirui > > > > gcc/ChangeLog: > > > > * match.pd: Generate IFN_TRUNC. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/aarch64/merge_trunc1.c: New test. > > > > > -----Original Message----- > > > From: Richard Biener <richard.guenther@gmail.com> > > > Sent: Tuesday, August 17, 2021 9:13 AM > > > To: Andrew Pinski <pinskia@gmail.com> > > > Cc: Jirui Wu <Jirui.Wu@arm.com>; Richard Sandiford > > > <Richard.Sandiford@arm.com>; ian@airs.com; > > > gcc-patches@gcc.gnu.org; rguenther@suse.de > > > Subject: Re: [Patch][GCC][middle-end] - Generate FRINTZ for > > > (double)(int) under -ffast-math on aarch64 > > > > > > On Mon, Aug 16, 2021 at 8:48 PM Andrew Pinski via Gcc-patches > > > <gcc- patches@gcc.gnu.org> wrote: > > > > > > > > On Mon, Aug 16, 2021 at 9:15 AM Jirui Wu via Gcc-patches > > > > <gcc-patches@gcc.gnu.org> wrote: > > > > > > > > > > Hi all, > > > > > > > > > > This patch generates FRINTZ instruction to optimize type casts. > > > > > > > > > > The changes in this patch covers: > > > > > * Opimization of a FIX_TRUNC_EXPR cast inside a FLOAT_EXPR > > > > > using > > > IFN_TRUNC. > > > > > * Change of corresponding test cases. > > > > > > > > > > Regtested on aarch64-none-linux-gnu and no issues. > > > > > > > > > > Ok for master? If OK can it be committed for me, I have no > > > > > commit > rights. > > > > > > > > Is there a reason why you are doing the transformation manually > > > > inside forwprop rather than handling it inside match.pd? > > > > Also can't this only be done for -ffast-math case? > > > > > > You definitely have to look at the intermediate type - that could > > > be a uint8_t or even a boolean type. So unless the intermediate > > > type can represent all float values optimizing to trunc() is invalid. > > > Also if you emit IFN_TRUNC you have to make sure there's target > > > support - we don't emit calls to a library > > > trunc() from an internal function call (and we wouldn't want to > > > optimize it that way). > > > > > > Richard. > > > > > > > > > > > Thanks, > > > > Andrew Pinski > > > > > > > > > > > > > > Thanks, > > > > > Jirui > > > > > > > > > > gcc/ChangeLog: > > > > > > > > > > * tree-ssa-forwprop.c (pass_forwprop::execute): > > > > > Optimize with > frintz. > > > > > > > > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > > > * gcc.target/aarch64/fix_trunc1.c: Update to new expectation. > > > > -- > Richard Biener <rguenther@suse.de> > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 > Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
Comments
On Fri, Sep 24, 2021 at 2:59 PM Jirui Wu via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, > > Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html > > The patch is attached as text for ease of use. Is there anything that needs to change? > > Ok for master? If OK, can it be committed for me, I have no commit rights. I'm still not sure about the correctness. I suppose the flag_fp_int_builtin_inexact && !flag_trapping_math is supposed to guard against spurious inexact exceptions, shouldn't that be !flag_fp_int_builtin_inexact || !flag_trapping_math instead? The comment looks a bit redundant and we prefer sth like /* (double)(int)x -> trunc (x) if the type of x matches the expressions FP type. */ Thanks, Richard. > Jirui Wu > > -----Original Message----- > From: Jirui Wu > Sent: Friday, September 10, 2021 10:14 AM > To: Richard Biener <rguenther@suse.de> > Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers <joseph@codesourcery.com> > Subject: [PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 > > Hi, > > Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html > > Ok for master? If OK, can it be committed for me, I have no commit rights. > > Jirui Wu > -----Original Message----- > From: Jirui Wu > Sent: Friday, September 3, 2021 12:39 PM > To: 'Richard Biener' <rguenther@suse.de> > Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers <joseph@codesourcery.com> > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 > > Ping > > -----Original Message----- > From: Jirui Wu > Sent: Friday, August 20, 2021 4:28 PM > To: Richard Biener <rguenther@suse.de> > Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers <joseph@codesourcery.com> > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 > > > -----Original Message----- > > From: Richard Biener <rguenther@suse.de> > > Sent: Friday, August 20, 2021 8:15 AM > > To: Jirui Wu <Jirui.Wu@arm.com> > > Cc: Richard Biener <richard.guenther@gmail.com>; Andrew Pinski > > <pinskia@gmail.com>; Richard Sandiford <Richard.Sandiford@arm.com>; > > ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers > > <joseph@codesourcery.com> > > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for > > (double)(int) under -ffast-math on aarch64 > > > > On Thu, 19 Aug 2021, Jirui Wu wrote: > > > > > Hi all, > > > > > > This patch generates FRINTZ instruction to optimize type casts. > > > > > > The changes in this patch covers: > > > * Generate FRINTZ for (double)(int) casts. > > > * Add new test cases. > > > > > > The intermediate type is not checked according to the C99 spec. > > > Overflow of the integral part when casting floats to integers causes > > undefined behavior. > > > As a result, optimization to trunc() is not invalid. > > > I've confirmed that Boolean type does not match the matching condition. > > > > > > Regtested on aarch64-none-linux-gnu and no issues. > > > > > > Ok for master? If OK can it be committed for me, I have no commit rights. > > > > +/* Detected a fix_trunc cast inside a float type cast, > > + use IFN_TRUNC to optimize. */ > > +#if GIMPLE > > +(simplify > > + (float (fix_trunc @0)) > > + (if (direct_internal_fn_supported_p (IFN_TRUNC, type, > > + OPTIMIZE_FOR_BOTH) > > + && flag_unsafe_math_optimizations > > + && type == TREE_TYPE (@0)) > > > > types_match (type, TREE_TYPE (@0)) > > > > please. Please perform cheap tests first (the flag test). > > > > + (IFN_TRUNC @0))) > > +#endif > > > > why only for GIMPLE? I'm not sure flag_unsafe_math_optimizations is a > > good test here. If you say we can use undefined behavior of any > > overflow of the fix_trunc operation what do we guard here? > > If it's Inf/NaN input then flag_finite_math_only would be more > > appropriate, if it's behavior for -0. (I suppose trunc (-0.0) == -0.0 > > and thus "wrong") then a && !HONOR_SIGNED_ZEROS (type) is missing > > instead. If it's setting of FENV state and possibly trapping on > > overflow (but it's undefined?!) then flag_trapping_math covers the > > latter but we don't have any flag for eliding FENV state affecting > > transforms, so there the kitchen-sink flag_unsafe_math_optimizations might apply. > > > > So - which is it? > > > This change is only for GIMPLE because we can't test for the optab support without being in GIMPLE. direct_internal_fn_supported_p is defined only for GIMPLE. > > IFN_TRUNC's documentation mentions nothing for zero, NaNs/inf inputs. > So I think the correct guard is just flag_fp_int_builtin_inexact. > !flag_trapping_math because the operation can only still raise inexacts. > > The new pattern is moved next to the place you mentioned. > > Ok for master? If OK can it be committed for me, I have no commit rights. > > Thanks, > Jirui > > Note there's also the pattern > > > > /* Handle cases of two conversions in a row. */ (for ocvt (convert > > float > > fix_trunc) (for icvt (convert float) > > (simplify > > (ocvt (icvt@1 @0)) > > (with > > { > > ... > > > > which is related so please put the new pattern next to that (the set > > of conversions handled there does not include (float (fix_trunc @0))) > > > > Thanks, > > Richard. > > > > > Thanks, > > > Jirui > > > > > > gcc/ChangeLog: > > > > > > * match.pd: Generate IFN_TRUNC. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * gcc.target/aarch64/merge_trunc1.c: New test. > > > > > > > -----Original Message----- > > > > From: Richard Biener <richard.guenther@gmail.com> > > > > Sent: Tuesday, August 17, 2021 9:13 AM > > > > To: Andrew Pinski <pinskia@gmail.com> > > > > Cc: Jirui Wu <Jirui.Wu@arm.com>; Richard Sandiford > > > > <Richard.Sandiford@arm.com>; ian@airs.com; > > > > gcc-patches@gcc.gnu.org; rguenther@suse.de > > > > Subject: Re: [Patch][GCC][middle-end] - Generate FRINTZ for > > > > (double)(int) under -ffast-math on aarch64 > > > > > > > > On Mon, Aug 16, 2021 at 8:48 PM Andrew Pinski via Gcc-patches > > > > <gcc- patches@gcc.gnu.org> wrote: > > > > > > > > > > On Mon, Aug 16, 2021 at 9:15 AM Jirui Wu via Gcc-patches > > > > > <gcc-patches@gcc.gnu.org> wrote: > > > > > > > > > > > > Hi all, > > > > > > > > > > > > This patch generates FRINTZ instruction to optimize type casts. > > > > > > > > > > > > The changes in this patch covers: > > > > > > * Opimization of a FIX_TRUNC_EXPR cast inside a FLOAT_EXPR > > > > > > using > > > > IFN_TRUNC. > > > > > > * Change of corresponding test cases. > > > > > > > > > > > > Regtested on aarch64-none-linux-gnu and no issues. > > > > > > > > > > > > Ok for master? If OK can it be committed for me, I have no > > > > > > commit > > rights. > > > > > > > > > > Is there a reason why you are doing the transformation manually > > > > > inside forwprop rather than handling it inside match.pd? > > > > > Also can't this only be done for -ffast-math case? > > > > > > > > You definitely have to look at the intermediate type - that could > > > > be a uint8_t or even a boolean type. So unless the intermediate > > > > type can represent all float values optimizing to trunc() is invalid. > > > > Also if you emit IFN_TRUNC you have to make sure there's target > > > > support - we don't emit calls to a library > > > > trunc() from an internal function call (and we wouldn't want to > > > > optimize it that way). > > > > > > > > Richard. > > > > > > > > > > > > > > Thanks, > > > > > Andrew Pinski > > > > > > > > > > > > > > > > > Thanks, > > > > > > Jirui > > > > > > > > > > > > gcc/ChangeLog: > > > > > > > > > > > > * tree-ssa-forwprop.c (pass_forwprop::execute): > > > > > > Optimize with > > frintz. > > > > > > > > > > > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > > > > > * gcc.target/aarch64/fix_trunc1.c: Update to new expectation. > > > > > > > -- > > 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, 15 Oct 2021, Richard Biener via Gcc-patches wrote: > On Fri, Sep 24, 2021 at 2:59 PM Jirui Wu via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > Hi, > > > > Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html > > > > The patch is attached as text for ease of use. Is there anything that needs to change? > > > > Ok for master? If OK, can it be committed for me, I have no commit rights. > > I'm still not sure about the correctness. I suppose the > flag_fp_int_builtin_inexact && !flag_trapping_math is supposed to guard > against spurious inexact exceptions, shouldn't that be > !flag_fp_int_builtin_inexact || !flag_trapping_math instead? The following remarks may be relevant here, but are not intended as an assertion of what is correct in this case. 1. flag_fp_int_builtin_inexact is the more permissive case ("inexact" may or may not be raised). All existing uses in back ends are "flag_fp_int_builtin_inexact || !flag_trapping_math" or equivalent. 2. flag_fp_int_builtin_inexact only applies to certain built-in functions (as listed in invoke.texi). It's always unspecified, even in C2X, whether casts of non-integer values from floating-point to integer types raise "inexact". So flag_fp_int_builtin_inexact should not be checked in insn patterns corresponding to simple casts from floating-point to integer, only in insn patterns corresponding to the built-in functions listed for -fno-fp-int-builtin-inexact in invoke.texi (or for operations that combine such a built-in function with a cast of the *result* to integer type).
On 19/10/2021 00:22, Joseph Myers wrote: > On Fri, 15 Oct 2021, Richard Biener via Gcc-patches wrote: > >> On Fri, Sep 24, 2021 at 2:59 PM Jirui Wu via Gcc-patches >> <gcc-patches@gcc.gnu.org> wrote: >>> Hi, >>> >>> Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html >>> >>> The patch is attached as text for ease of use. Is there anything that needs to change? >>> >>> Ok for master? If OK, can it be committed for me, I have no commit rights. >> I'm still not sure about the correctness. I suppose the >> flag_fp_int_builtin_inexact && !flag_trapping_math is supposed to guard >> against spurious inexact exceptions, shouldn't that be >> !flag_fp_int_builtin_inexact || !flag_trapping_math instead? > The following remarks may be relevant here, but are not intended as an > assertion of what is correct in this case. > > 1. flag_fp_int_builtin_inexact is the more permissive case ("inexact" may > or may not be raised). All existing uses in back ends are > "flag_fp_int_builtin_inexact || !flag_trapping_math" or equivalent. > > 2. flag_fp_int_builtin_inexact only applies to certain built-in functions > (as listed in invoke.texi). It's always unspecified, even in C2X, whether > casts of non-integer values from floating-point to integer types raise > "inexact". So flag_fp_int_builtin_inexact should not be checked in insn > patterns corresponding to simple casts from floating-point to integer, > only in insn patterns corresponding to the built-in functions listed for > -fno-fp-int-builtin-inexact in invoke.texi (or for operations that combine > such a built-in function with a cast of the *result* to integer type). Hi, I agree with Joseph, I don't think we should be checking flag_fp_int_builtin_inexact here because we aren't transforming the math function 'trunc', but rather a piece of C-code that has trunc-like semantics. As for flag_trapping_math, it's definition says 'Assume floating point operations can trap'. I assume IFN_TRUNC would not trap, since I don't think IFN_TRUNC will preserve the overflow behaviour, in the cases where the FP value is bigger than the intermediate integer type range. So I think we should prevent the transformation if we are assuming the FP instructions can trap. If we don't assume the FP instructions can trap, then I think it's fine to ignore the overflow as this behavior is undefined in C. Also changed the comment. Slightly different to your suggestion Richard, in an attempt to be more generic. Do you still have concerns regarding the checks? Kind regards, Andre diff --git a/gcc/match.pd b/gcc/match.pd index 3ff15bc0de5aba45ade94ca6e47e01fad9a2a314..5bed2e12715ea213813ef8b84fd420475b04d201 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3606,6 +3606,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >= inside_prec - !inside_unsignedp) (convert @0))))))) +/* (float_type)(integer_type) x -> trunc (x) if the type of x matches + float_type. Only do the transformation if we do not need to preserve + trapping behaviour, so require !flag_trapping_math. */ +#if GIMPLE +(simplify + (float (fix_trunc @0)) + (if (!flag_trapping_math + && types_match (type, TREE_TYPE (@0)) + && direct_internal_fn_supported_p (IFN_TRUNC, type, + OPTIMIZE_FOR_BOTH)) + (IFN_TRUNC @0))) +#endif + /* If we have a narrowing conversion to an integral type that is fed by a BIT_AND_EXPR, we might be able to remove the BIT_AND_EXPR if it merely masks off bits outside the final type (and nothing else). */ diff --git a/gcc/testsuite/gcc.target/aarch64/merge_trunc1.c b/gcc/testsuite/gcc.target/aarch64/merge_trunc1.c new file mode 100644 index 0000000000000000000000000000000000000000..07217064e2ba54fcf4f5edc440e6ec19ddae66e1 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/merge_trunc1.c @@ -0,0 +1,41 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math" } */ + +float +f1 (float x) +{ + int y = x; + + return (float) y; +} + +double +f2 (double x) +{ + long y = x; + + return (double) y; +} + +float +f3 (double x) +{ + int y = x; + + return (float) y; +} + +double +f4 (float x) +{ + int y = x; + + return (double) y; +} + +/* { dg-final { scan-assembler "frintz\\ts\[0-9\]+, s\[0-9\]+" } } */ +/* { dg-final { scan-assembler "frintz\\td\[0-9\]+, d\[0-9\]+" } } */ +/* { dg-final { scan-assembler "fcvtzs\\tw\[0-9\]+, d\[0-9\]+" } } */ +/* { dg-final { scan-assembler "scvtf\\ts\[0-9\]+, w\[0-9\]+" } } */ +/* { dg-final { scan-assembler "fcvtzs\\tw\[0-9\]+, s\[0-9\]+" } } */ +/* { dg-final { scan-assembler "scvtf\\td\[0-9\]+, w\[0-9\]+" } } */
On Wed, 20 Oct 2021, Andre Vieira (lists) wrote: > > On 19/10/2021 00:22, Joseph Myers wrote: > > On Fri, 15 Oct 2021, Richard Biener via Gcc-patches wrote: > > > >> On Fri, Sep 24, 2021 at 2:59 PM Jirui Wu via Gcc-patches > >> <gcc-patches@gcc.gnu.org> wrote: > >>> Hi, > >>> > >>> Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html > >>> > >>> The patch is attached as text for ease of use. Is there anything that > >>> needs to change? > >>> > >>> Ok for master? If OK, can it be committed for me, I have no commit rights. > >> I'm still not sure about the correctness. I suppose the > >> flag_fp_int_builtin_inexact && !flag_trapping_math is supposed to guard > >> against spurious inexact exceptions, shouldn't that be > >> !flag_fp_int_builtin_inexact || !flag_trapping_math instead? > > The following remarks may be relevant here, but are not intended as an > > assertion of what is correct in this case. > > > > 1. flag_fp_int_builtin_inexact is the more permissive case ("inexact" may > > or may not be raised). All existing uses in back ends are > > "flag_fp_int_builtin_inexact || !flag_trapping_math" or equivalent. > > > > 2. flag_fp_int_builtin_inexact only applies to certain built-in functions > > (as listed in invoke.texi). It's always unspecified, even in C2X, whether > > casts of non-integer values from floating-point to integer types raise > > "inexact". So flag_fp_int_builtin_inexact should not be checked in insn > > patterns corresponding to simple casts from floating-point to integer, > > only in insn patterns corresponding to the built-in functions listed for > > -fno-fp-int-builtin-inexact in invoke.texi (or for operations that combine > > such a built-in function with a cast of the *result* to integer type). > Hi, > > I agree with Joseph, I don't think we should be checking > flag_fp_int_builtin_inexact here because we aren't transforming the math > function 'trunc', but rather a piece of C-code that has trunc-like semantics. But we are generating 'trunc' which may now raise a spurious exception. OTOH flag_fp_int_builtin_inexact wouldn't help here because "may or may not" stil may raise spurious exception flags. > As for flag_trapping_math, it's definition says 'Assume floating point > operations can trap'. I assume IFN_TRUNC would not trap, since I don't think > IFN_TRUNC will preserve the overflow behaviour, in the cases where the FP > value is bigger than the intermediate integer type range. So I think we should > prevent the transformation if we are assuming the FP instructions can trap. Note trap == set exception flags, not only raise a trap. > If we don't assume the FP instructions can trap, then I think it's fine to > ignore the overflow as this behavior is undefined in C. > > Also changed the comment. Slightly different to your suggestion Richard, in an > attempt to be more generic. Do you still have concerns regarding the checks? I think your updated patch is OK. Thanks, Richard.
diff --git a/gcc/match.pd b/gcc/match.pd index 19cbad7..72e8e91 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3487,6 +3487,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >= inside_prec - !inside_unsignedp) (convert @0))))))) +/* Detected a fix_trunc cast inside a float type cast, + use IFN_TRUNC to optimize. */ +#if GIMPLE +(simplify + (float (fix_trunc @0)) + (if (flag_fp_int_builtin_inexact + && !flag_trapping_math + && types_match (type, TREE_TYPE (@0)) + && direct_internal_fn_supported_p (IFN_TRUNC, type, + OPTIMIZE_FOR_BOTH)) + (IFN_TRUNC @0))) +#endif + /* If we have a narrowing conversion to an integral type that is fed by a BIT_AND_EXPR, we might be able to remove the BIT_AND_EXPR if it merely masks off bits outside the final type (and nothing else). */ diff --git a/gcc/testsuite/gcc.target/aarch64/merge_trunc1.c b/gcc/testsuite/gcc.target/aarch64/merge_trunc1.c new file mode 100644 index 0000000..0721706 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/merge_trunc1.c @@ -0,0 +1,41 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math" } */ + +float +f1 (float x) +{ + int y = x; + + return (float) y; +} + +double +f2 (double x) +{ + long y = x; + + return (double) y; +} + +float +f3 (double x) +{ + int y = x; + + return (float) y; +} + +double +f4 (float x) +{ + int y = x; + + return (double) y; +} + +/* { dg-final { scan-assembler "frintz\\ts\[0-9\]+, s\[0-9\]+" } } */ +/* { dg-final { scan-assembler "frintz\\td\[0-9\]+, d\[0-9\]+" } } */ +/* { dg-final { scan-assembler "fcvtzs\\tw\[0-9\]+, d\[0-9\]+" } } */ +/* { dg-final { scan-assembler "scvtf\\ts\[0-9\]+, w\[0-9\]+" } } */ +/* { dg-final { scan-assembler "fcvtzs\\tw\[0-9\]+, s\[0-9\]+" } } */ +/* { dg-final { scan-assembler "scvtf\\td\[0-9\]+, w\[0-9\]+" } } */