From patchwork Fri Sep 24 12:58:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jirui Wu X-Patchwork-Id: 45415 Return-Path: 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 ; 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 ; 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" 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: References: In-Reply-To: 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: 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; 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jirui Wu via Gcc-patches From: Jirui Wu Reply-To: Jirui Wu Cc: Richard Sandiford , "ian@airs.com" , Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 Cc: Richard Biener ; Andrew Pinski ; Richard Sandiford ; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers 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' Cc: Richard Biener ; Andrew Pinski ; Richard Sandiford ; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers 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 Cc: Richard Biener ; Andrew Pinski ; Richard Sandiford ; ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 > -----Original Message----- > From: Richard Biener > Sent: Friday, August 20, 2021 8:15 AM > To: Jirui Wu > Cc: Richard Biener ; Andrew Pinski > ; Richard Sandiford ; > ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers > > 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 > > > Sent: Tuesday, August 17, 2021 9:13 AM > > > To: Andrew Pinski > > > Cc: Jirui Wu ; Richard Sandiford > > > ; 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 > > > wrote: > > > > > > > > On Mon, Aug 16, 2021 at 9:15 AM Jirui Wu via Gcc-patches > > > > 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 > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 > Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg) 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\]+" } } */