From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2062.outbound.protection.outlook.com [40.107.22.62]) by sourceware.org (Postfix) with ESMTPS id 3217F3858409 for ; Fri, 21 Jul 2023 15:24:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3217F3858409 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iG+qR0Z94bhxjGJt0WrCUg3+VU5X5taQpoCKfzBELkw=; b=HTs4tM2zGPgTlNuMkuPiKtWyACNgXHd/kE4sO+FLQEYXqUztBOz7iOvkjyEmSolvbr1+pA6zEKK3GPSXwrxKwU0fElpnTwG2eEU7m1pr7gZOODdFozoxeKFKMVKnnobBKRMTVdr2QZRZx//8eQIE0dz2uZyTMVPEPBNGRllCSWY= Received: from DU2PR04CA0258.eurprd04.prod.outlook.com (2603:10a6:10:28e::23) by PAVPR08MB8821.eurprd08.prod.outlook.com (2603:10a6:102:2fc::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.25; Fri, 21 Jul 2023 15:24:40 +0000 Received: from DBAEUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28e:cafe::98) by DU2PR04CA0258.outlook.office365.com (2603:10a6:10:28e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28 via Frontend Transport; Fri, 21 Jul 2023 15:24:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT009.mail.protection.outlook.com (100.127.143.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.24 via Frontend Transport; Fri, 21 Jul 2023 15:24:40 +0000 Received: ("Tessian outbound f9124736ff4f:v145"); Fri, 21 Jul 2023 15:24:40 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 9d61855923ee3ab4 X-CR-MTA-TID: 64aa7808 Received: from 8beb5ead0cd7.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C0E8BC9C-CDB4-49DE-9825-3E78BC16AEAE.1; Fri, 21 Jul 2023 15:24:28 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8beb5ead0cd7.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 21 Jul 2023 15:24:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WCWEFirr4a92a2gReUr/r+L+ATTgqniAkYZiJyUTPnzKs3nxCnD8nDralNC+UxJaU0f5JqAguDNUSIEtE/MyjyCB44cGLnaihEvr0n9AMU0PBFCbLt8spJN0HGtiUDJqje99PdlXMHPte/hFgCGw/a+pDSwKX/JaAVNxf3lYWOI0n7auBHH4gEVz5SJTBA4NiX5fmDXD6i5mbHKAkjV5XCMBFSRfLzvi2ggbkkviB1/qw7+5fetY1aAH7gFHDJYi0iub1+hPTNnV2JhLE94bKbeaDmaBis1lSaeZuv1rEPE679ToPND7KB129H+gXoP3AFhuAlhuS9jtuk//uE+ROg== 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=iG+qR0Z94bhxjGJt0WrCUg3+VU5X5taQpoCKfzBELkw=; b=RzBmdQ4aGyO2G8ci9Fmn081vl30P5YrjchDv+dIy/HHVttiGdWiTQi8NCiuppoilkIlSnKJCAeUZoiaDTxCL2O0YysV3KTjj/09w6+ic3yRRhR6MFFGt/t6TWBvOk4GH24sUayn7r/0/tUFIwlY1w1pcuSnH9xs6QOyAkfZ1aiC8s7tc0GaVZX9Tm0JNf7ZP42YXIczI3K8Piqjx2Pwe+uKD6L3cYi0Vi9hu4mmLjjufOhvDRC/zq9daFLzMka48nDKiCfOWvwSFOTS4yUwb9VWf7YWXiNKpGrwblWiOoqKtVHKXSYQ//l/bYIQd5VnXPEManmEmKHhDjVYXU51vvg== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iG+qR0Z94bhxjGJt0WrCUg3+VU5X5taQpoCKfzBELkw=; b=HTs4tM2zGPgTlNuMkuPiKtWyACNgXHd/kE4sO+FLQEYXqUztBOz7iOvkjyEmSolvbr1+pA6zEKK3GPSXwrxKwU0fElpnTwG2eEU7m1pr7gZOODdFozoxeKFKMVKnnobBKRMTVdr2QZRZx//8eQIE0dz2uZyTMVPEPBNGRllCSWY= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB9611.eurprd08.prod.outlook.com (2603:10a6:10:461::12) by AS2PR08MB10252.eurprd08.prod.outlook.com (2603:10a6:20b:648::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.25; Fri, 21 Jul 2023 15:24:26 +0000 Received: from DB9PR08MB9611.eurprd08.prod.outlook.com ([fe80::465a:bdfa:eee2:77b7]) by DB9PR08MB9611.eurprd08.prod.outlook.com ([fe80::465a:bdfa:eee2:77b7%4]) with mapi id 15.20.6609.026; Fri, 21 Jul 2023 15:24:25 +0000 Message-ID: <2e3a0788-bc10-4dac-dbd2-3652da81fdb5@arm.com> Date: Fri, 21 Jul 2023 16:24:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] Reduce floating-point difficulties in timevar.cc Content-Language: en-US To: Xi Ruoyao , Richard Biener Cc: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com References: <62d34c82-b883-8497-1b6b-cc662d26b4c9@arm.com> <8c74d12dd1e152ffc2f06fe9bf95aa67bd1407c5.camel@xry111.site> From: Matthew Malcomson In-Reply-To: <8c74d12dd1e152ffc2f06fe9bf95aa67bd1407c5.camel@xry111.site> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0443.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::23) To DB9PR08MB9611.eurprd08.prod.outlook.com (2603:10a6:10:461::12) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DB9PR08MB9611:EE_|AS2PR08MB10252:EE_|DBAEUR03FT009:EE_|PAVPR08MB8821:EE_ X-MS-Office365-Filtering-Correlation-Id: d24f1a40-d43c-408d-3ab0-08db89fe9a15 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ZvnsRrZGROZy+SjuPoxk9bLcEEHDPLQoLXEQn5WZoghorDfH4rklAtQqWrUU/T02wznflYe/gHfNOWEng8mKq9UryJVk59TNxKz42juuM9SAMAKZsMRQRAZuDeHt+KYjk79Q947K5LC6viIFw5+wQRLnGq/6i7/IZ7FLTpk5lGfn/i5481N8EKra6gvQMkWm9krgiicKgySqrwzjcy9EmwYKpIuX8T0423xXDBix7K7i+iSKa9E3dzY1dRHgaIQRxhkiFbPr55wkasTgNjrnpOFdutvjpwA9y/KNnz2mc0w/5pMRKMRPfJWkxfJl9uQKvMiloTO9vfL+7appUS/cnHcv1ooDAXI+puNlH9fmDmxRhxpAJAVvGxytAGt2hk4jXAifyWRaO4zp1JSZ4MPmnPmbdJoPtVhPf1p4DwVZYSLHf5QqVdUIioRJePwtYsYeaVFS49dZzTwO41fW6xho0/iozKgWpuOe7cBEWtkSDaCXOpSGiUUzNegHkM6YMfkgu5Wa9EIt+e/F7E3lQ5osYKcacvgDNwDk8BoHxJX4gAR1G05opwG0f1hNfpR5Cgf/Xi24de7rGsneRX3qYrzmJy/Z+OnK6PwCtH+lrXmsHCjipxZ9ssXPEuD7YwUzOi27gBArL6yD+uFQ4SdOpUuIgkSb95qE8+qPMoS7ZP0qxuU= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR08MB9611.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(396003)(346002)(39860400002)(366004)(451199021)(66476007)(26005)(186003)(6512007)(6666004)(4326008)(66946007)(316002)(66556008)(6486002)(41300700001)(53546011)(6506007)(5660300002)(110136005)(31686004)(44832011)(8936002)(8676002)(478600001)(2616005)(83380400001)(2906002)(38100700002)(36756003)(31696002)(86362001)(45980500001)(43740500002)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10252 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 95b190c4-44ef-41e7-1bc1-08db89fe910b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9qAGY5nqXi/xrzFN0xXR+26OyakwN9Q3iEucnARqoDVRB0+elOHkSLWFw68ZHLUFECh+7w4Dqh+psJxLmBVjswCiDck7xSC7Eyj1ZiE99cfh0VAqVPsmTFGPtBWtJIegBgvVYFkPEpGTjY4KTNbPSjpot50MG2rRhHVkNs5sttzBKHpzVq0ej4I7JUvvp8L+FvBV0RvoyGRsAVJLgNT30qUqN671weSRsHoZrIWAyGaiiaXbw3b1acd2axrWNZz5wl3A6OJTkYLXBGoxwZihujzz/OlSqT49Syowwew0s12USKER6OIMuMY58usasBTSTBZPSoRjxiU9uMJApSCCO7PjnJ/RGH5xbvC9y5ibJBcvLhvbDa7dLiHjDMPb6ad2ct6P/hQJZiom9met5D1lDQRdtCB8oV0+jGGi3Byn+Ns/i/5jpqD/vqLK8WPS2MaKJjsqbaxSC6Q4XDK5pboSqYVGZVqiHt+2CRQfz3Uyq/cR7aieYnjT8C+7UNIcYOZx15i+3itrNYKjI1nZRpaIYGyRa52EOxFfXOZQvGFwZCR9oEVRDf0t9W3UDgk02j2TH4clN19EKssgud1Gc0jgawEEyKo6I/065N/a967TaRX6AfltkLfErQ3cruc+oANi4A3U6KVUXdESZGJabqq7N0gBiuLPr0A+nIqSM9apC5h/wD5JQaaampemRRbSdh6WO/AOmmwFu31xZ2a1zJts5tIBbNp1WI+kCGnoyDJWPg/2bbi8zwlwZAxpIpNz/zzIbO1nTkc4LVZ5m9C1JNAeC13nX39cl2+3oUOua00bOeo= 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:(13230028)(4636009)(346002)(39860400002)(396003)(376002)(136003)(451199021)(82310400008)(40470700004)(36840700001)(46966006)(40460700003)(31686004)(6486002)(4326008)(6506007)(53546011)(26005)(31696002)(70206006)(86362001)(478600001)(70586007)(110136005)(6666004)(36756003)(36860700001)(336012)(83380400001)(47076005)(2616005)(186003)(8936002)(8676002)(44832011)(5660300002)(6512007)(40480700001)(41300700001)(2906002)(82740400003)(316002)(356005)(81166007)(43740500002)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2023 15:24:40.2838 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d24f1a40-d43c-408d-3ab0-08db89fe9a15 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: DBAEUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB8821 X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,KAM_DMARC_NONE,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 7/21/23 14:45, Xi Ruoyao wrote: > On Fri, 2023-07-21 at 14:11 +0100, Matthew Malcomson wrote: >> My understanding is that this is not a hardware bug and that it's >> specified that rounding does not happen on the multiply "sub-part" in >> `FNMSUB`, but rounding happens on the `FMUL` that generates some input >> to it. > > AFAIK the C standard does only say "A floating *expression* may be > contracted". I.e: > > double r = a * b + c; > > may be compiled to use FMA because "a * b + c" is a floating point > expression. But > > double t = a * b; > double r = t + c; > > is not, because "a * b" and "t + c" are two separate floating point > expressions. > > So a contraction across two functions is not allowed. We now have -ffp- > contract=on (https://gcc.gnu.org/r14-2023) to only allow C-standard > contractions. > > Perhaps -ffp-contract=on (not off) is enough to fix the issue (if you > are building GCC 14 snapshot). The default is "fast" (if no -std= > option is used), which allows some contractions disallowed by the > standard. > > But GCC is in C++ and I'm not sure if the C++ standard has the same > definition for allowed contractions as C. > Thanks -- I'll look into whether `-ffp-contract=on` works. > > It's possible that the test itself is flaky. Can you provide some > detail about how it fails? > Sure -- The outline is that `timer::validate_phases` sees the sum of sub-part timers as greater than the timer for the "overall" time (outside of a tolerance of 1.000001). It then complains and hits `gcc_unreachable()`. While I found it difficult to get enough information out of the test that is run in the testsuite, I found that if passing an invalid argument to `cc1plus` all sub-parts would be zero, and sometimes the "total" would be negative. This was due to the `times` syscall returning the same clock tick for start and end of the "total" timer and the difference in rounding between FNMSUB and FMUL means that depending on what that clock tick is the "elapsed time" can end up calculated as negative. I didn't proove it 100% but I believe the same fundamental difference (but opposite rounding error) could trigger the testsuite failure -- if the "end" of one sub-phase timer is greater than the "start" of another sub-phase timer then sum of parts could be greater than total. There is a "tolerance" in this test that I considered increasing, but since that would not affect the "invalid arguments" thing (where the total is negative and hence the tolerance multiplication of 1.000001 would have to be supplemented by a positive offset) I suggested avoiding the inline. W.r.t. the x86 bug that Alexander Monakov has pointed to, it's a very similar thing but in this case the problem is not bit-precision of values after the inlining, but rather a difference between fused and not fused operations after the inlining. Agreed that using integral arithmetic is the more robust solution.