From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 4BB81385735C for ; Thu, 5 May 2022 13:24:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4BB81385735C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 245DNCuj022069; Thu, 5 May 2022 08:23:12 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 245DNCsv022068; Thu, 5 May 2022 08:23:12 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Thu, 5 May 2022 08:23:11 -0500 From: Segher Boessenkool To: HAO CHEN GUI Cc: "Kewen.Lin" , Richard Biener , Peter Bergner , gcc-patches , David Subject: Re: [PATCH] Skip constant folding for fmin/max when either argument is sNaN [PR105414] Message-ID: <20220505132311.GA25951@gate.crashing.org> References: <4df302c6-5bc7-f6fb-916a-6dd9c0460268@linux.ibm.com> <0aa8c058-5dd3-c7bf-935a-8df4947ebab0@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0aa8c058-5dd3-c7bf-935a-8df4947ebab0@linux.ibm.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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-List-Received-Date: Thu, 05 May 2022 13:24:15 -0000 Hi! On Thu, May 05, 2022 at 05:30:58PM +0800, HAO CHEN GUI wrote: > On 5/5/2022 下午 4:30, Kewen.Lin wrote: > > on 2022/5/5 16:09, Richard Biener via Gcc-patches wrote: > >> On Thu, May 5, 2022 at 10:07 AM HAO CHEN GUI via Gcc-patches > >> wrote: > >>> This patch skips constant folding for fmin/max when either argument > >>> is sNaN. According to C standard, > >>> fmin(sNaN, sNaN)= qNaN, fmin(sNaN, NaN) = qNaN > >>> So signaling NaN should be tested and skipped for fmin/max in match.pd. > >>> > >>> Bootstrapped and tested on ppc64 Linux BE and LE with no regressions. The C standard does not talk about sNaNs *at all*, in any released version of the standard. And the C2x drafts do not talk about signaling arguments for fmin/fmax specifically, so it should just raise an error like any other floating operation with an sNaN arg will. This means we have to make sure to not optimise away all operations if there may be an sNaN (and we have HONOR_SNANS for the mode in use). You never have to convert to a qNaN manually. Instead, any normal operation on the sNaN will raise the exception, and convert to the qNaN. There is no sane way you can raise the exception manually, so you should make sure we end up with a real operation in the RTL, and then generate proper machine code for it as well. See rs6000 extendsfdf2 for example, for that last part. And of course both the gimple min_expr and the RTL smin are not defined for NaN inputs at all anyway :-P Segher