From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 429C73858D34 for ; Thu, 2 May 2024 09:19:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 429C73858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 429C73858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714641569; cv=none; b=oFmTu2jwffOZK6lzRfxW2TLXBovmtoYuctaFKHm/bGU8ZZ6TS1B1dMXBHjJL2GjMIzOeUKXiDRWNd5vrdj9Wbv4wPVzS7pcGeySR0FfmdH/PdKfXl1W3lyH/b2Jac7P2TIMSYX8qVvUUarRL/QasQIEPe38oDOT52IPZYX+icjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714641569; c=relaxed/simple; bh=yuCIHcC31VswNZugyFHISyhm6ixdEARPcklEEBYGOJk=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ob+nnybsnfU178jnNbqgz8h7x2hmLhHp2TvR8YI3643W4ABdQu5xfw9XIoD2fJSOVVG3C8iGBU6XHIypv+AFgzrYtg5arMfzDZ4qyc30NZprkmW48coLAl5kEnvctxhshjo+CvW9QLJXeYTiqDPzdV6ZpRigSUrde9AF5mS6bKQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-51f45104ef0so237737e87.3 for ; Thu, 02 May 2024 02:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714641565; x=1715246365; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Y9aoLb+xQQ6PjbBC6fQ5I/163MUfq87yNYaO6bds+Cs=; b=NPwqnOBHLYXOs96Z0t7BNklNXZlxJ9ArVftYmBecwIfeU46aS/s62PxShulUXzbQll 7E1hUJLOzkHRY2s+XWyYIoZI6N17Y0bxZuLtFWnJJXd+fnRPH3RGpsg3fcCdFjIyMF7E wO6ASHxU1qU4Gin1ekm4HDQZQ2AIhLDNpFtPhR8gf10hQuHtnNC2SMO8O6vlfvW7Qi6r y/Lz4UxoAo2O4L68BC/sLO1fCwVfcnVgGC2s+xBdVYOkRG2pQ8OVsw7JCjdBMJXKWD1t cfAylsNNKlUbljtMSZmr28iYcgTmoXzgpxY4MHvB+qCcexUL/gyiIJ7RTfe8vIyZNjDW NHfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714641565; x=1715246365; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y9aoLb+xQQ6PjbBC6fQ5I/163MUfq87yNYaO6bds+Cs=; b=wZsP4seMJMl0WMyKcbYTA+q2I6JXQDGvucEhipHjRpSFWA3oRUD9ucqQXClXpSjLda fbycSKJewQYdBHBNRYT1KIyzMtijN9qDGhdXdXK1kVKyo5jYOFtL+n4Tot7e1kgCSyFo 3Sa1g87HjYNq2CgQqUtS/ikxcsejlSxKbDRFXhfm9WhBAzqOqIEoUpl8lV4SxsS3p+LG 4W1cV9bKqukwCcZmnMeRodXX4StzocbPpnZCYf7lU2PieyqzXqdTpgQNssleizbyHm8Q vAxUWH/90PZgGg2860Bah+QpRagpRC71sE0cKaLrT21RYKdr5YN4O6MuOjuCpCUtRtvl TRpQ== X-Gm-Message-State: AOJu0YyVvP9eL/tKhEaCUdzqVu3PhwSme/TrAR6F/3+qPQ5C0gw6jLAi oTfab8/o+IT2RSKo/ItvPAUgK5TzjRbb6jTVKOLxMDQz6dDlesWNF2nSYgQ28sdJx3najz1EcoG nZskoh0BXKK9m/XW59UO9KTwt5Vs= X-Google-Smtp-Source: AGHT+IG2M8xCYw53mzAhctIPaEk5WLNfT40tMfVRpbBcT/KHqZ94fB6DrPXpyXmq+toFXeZZjFAxxI7opfcm5IOdtI8= X-Received: by 2002:ac2:5484:0:b0:513:e63c:cfe7 with SMTP id t4-20020ac25484000000b00513e63ccfe7mr2969706lfk.66.1714641565326; Thu, 02 May 2024 02:19:25 -0700 (PDT) MIME-Version: 1.0 References: <009201da97b2$325fc140$971f43c0$@nextmovesoftware.com> In-Reply-To: <009201da97b2$325fc140$971f43c0$@nextmovesoftware.com> From: Richard Biener Date: Thu, 2 May 2024 11:19:13 +0200 Message-ID: Subject: Re: [PATCH] PR middle-end/111701: signbit(x*x) vs -fsignaling-nans To: Roger Sayle , Joseph Myers Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham 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 Fri, Apr 26, 2024 at 10:19=E2=80=AFAM Roger Sayle wrote: > > > This patch addresses PR middle-end/111701 where optimization of signbit(x= *x) > using tree_nonnegative_p incorrectly eliminates a floating point > multiplication when the operands may potentially be signaling NaNs. > > The above bug fix also provides a solution or work-around to the tricky > issue in PR middle-end/111701, that the results of IEEE operations on NaN= s > are specified to return a NaN result, but fail to (precisely) specify > the exact NaN representation of this result. Hence for the operation > "-NaN*-NaN" different hardware implementations (targets) return different > results. Ultimately knowing what the resulting NaN "payload" of an > operation is can only be known by executing that operation at run-time, > and I'd suggest that GCC's -fsignaling-nans provides a mechanism for > handling code that uses NaN representations for communication/signaling > (which is a different but related concept to IEEE's sNaN). > > One nice thing about this patch, which may or may not be a P2 regression > fix, is that it only affects (improves) code compiled with -fsignaling-na= ns > so should be extremely safe even for this point in stage 3. > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=3Dunix{-m32} > with no new failures. Ok for mainline? Hmm, but the bugreports are not about sNaN but about the fact that the sign of the NaN produced by 0/0 or by -NaN*-NaN is not well-defined. So I don't think this is the correct approach to fix this. We'd instead have to use tree_expr_maybe_nan_p () - and if NaN*NaN cannot be -NaN (is that at least specified?) then the RECURSE path should still work as well. Richard. > > 2024-04-26 Roger Sayle > > gcc/ChangeLog > PR middle-end/111701 > * fold-const.cc (tree_binary_nonnegative_warnv_p) : > Split handling of floating point and integer types. For equal > floating point operands, avoid optimization if the operand may be > a signaling NaN. > > gcc/testsuite/ChangeLog > PR middle-end/111701 > * gcc.dg/pr111701-1.c: New test case. > * gcc.dg/pr111701-2.c: Likewise. > > > Thanks in advance, > Roger > -- >