From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id B36083858D32 for ; Mon, 18 Sep 2023 07:50:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B36083858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id 666E940F1DEB; Mon, 18 Sep 2023 07:50:17 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 666E940F1DEB Date: Mon, 18 Sep 2023 10:50:17 +0300 (MSK) From: Alexander Monakov To: Florian Weimer cc: gcc@gcc.gnu.org Subject: Re: Concerns regarding the -ffp-contract=fast default In-Reply-To: <21e46cef-1fbf-df87-608d-52b7f894dea7@ispras.ru> Message-ID: References: <87r0n01z18.fsf@oldenburg3.str.redhat.com> <21e46cef-1fbf-df87-608d-52b7f894dea7@ispras.ru> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-1041873163-1695023417=:30724" X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_SHORT,SPAM_BODY,SPF_HELO_NONE,SPF_PASS,TXREP 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: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1041873163-1695023417=:30724 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Hi Florian, On Thu, 14 Sep 2023, Alexander Monakov wrote: > > On Thu, 14 Sep 2023, Florian Weimer via Gcc wrote: > > > While rebuilding CentOS Stream with -march=x86-64-v3, I rediscovered > > several packages had test suite failures because x86-64 suddenly gained > > FMA support. I say “rediscovered” because these issues were already > > visible on other architectures with FMA. > > > > So far, our package/architecture maintainers had just disabled test > > suites or had built the package with -fp-contract=off because the > > failures did not reproduce on x86-64. I'm not sure if this is the right > > course of action. > > > > GCC contraction behavior is rather inconsistent. It does not contract x > > + x - x without -ffast-math, for example, although I believe it would be > > permissible under the rules that enable FMA contraction. This whole > > thing looks suspiciously like a quick hack to get a performance > > improvement from FMA instructions (sorry). > > > > I know that GCC 14 has -fp-contract=standard. Would it make sense to > > switch the default to that? If it fixes those package test suites, it > > probably has an observable performance impact. 8-/ > > Note that with =standard FMA contraction is still allowed within an > expression: the compiler will transform 'x * y + z' to 'fma(x, y, z)'. > The difference between =fast and =standard is contraction across > statement boundaries. So I'd expect some test suite failures you speak of > to remain with =standard as opposed to =off. > > I think it's better to switch both C and C++ defaults to =standard, > matching Clang, but it needs a bit of leg work to avoid regressing > our own testsuite for targets that have FMA in the base ISA. > > (personally I'd be on board with switching to =off even) > > See https://gcc.gnu.org/PR106902 for a worked example where -ffp-contract=fast > caused a correctness issue in a widely used FOSS image processing application > that was quite hard to debug. > > Obviously -Ofast and -ffast-math will still imply -ffp-contract=fast if we > make the change, so SPEC scores won't be affected. Is this the sort of information you were looking for? If you're joining the Cauldron and could poll people about changing the default, I feel that could be helpful. One of the tricky aspects is what to do under -std=cNN, which implies -ffp-contract=off; "upgrading" it to =standard would introduce FMAs. Also, I'm a bit unsure what you were implying here: > I know that GCC 14 has -fp-contract=standard. Would it make sense to > switch the default to that? If it fixes those package test suites, it > probably has an observable performance impact. 8-/ The "correctness trumps performance" principle still applies, and -ffp-contract=fast (the current default outside of -std=cNN) is known to cause correctness issues and violates the C language standard. And -ffast[-and-loose]-math for is not going away. Thanks. Alexander --8323328-1041873163-1695023417=:30724--