From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by sourceware.org (Postfix) with ESMTPS id 5FA8E3858D3C for ; Thu, 5 May 2022 08:10:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5FA8E3858D3C Received: by mail-vs1-xe2e.google.com with SMTP id z144so3475730vsz.13 for ; Thu, 05 May 2022 01:10:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=noTYSVRSOUG17zPsoGidiu+GNutM64lhlRselcD3OE8=; b=ShZCiI1S4Q/xHTxUfFYVgnxPwU5zTPAdL40F3Wk2nA23zXyeV+kZFeGmCXzNXF9RP+ DBTlTiKiA6QbO8M174sEDh+l7CMNe11KQY0wVIHpjW8q8G6LTV561eDIUKHefvMn9qCm 3823kW9sYui/UiO73S6XARfVJ+Mve9sFcrTD0JuTXiNgqpiDssVCYChyGcLC/Wwu3cTD 6ZIvZrr+lAJagO+LQOOOT7CGbFRyZrbzlRWy4TCPTZa94a8EmJLGnjnlNaIEPVOWOq1E FQOWL7bzKTnWwICG/4YRb9mO5rEhf9Nyl69SLfKk++0xmGMzp1RdI6LBTbT2Rn1MKSs/ uztQ== X-Gm-Message-State: AOAM5316yfLjg3gsizijNoZvGDDolkEft0sTd2rI2mi3XW/NTFmmQFW4 cT+DWvujuuFXcyO4R8C2oVNEo7XiQLZ0d93mHpw= X-Google-Smtp-Source: ABdhPJzdCHku6hgIOjyZjJXf3mqA5S4HTganwv84HwDktGXEcmBnUtgkhwhnL9TPTtImxWSYrhNwod92eZNEpBpyxKw= X-Received: by 2002:a67:6bc4:0:b0:32c:c06a:16a1 with SMTP id g187-20020a676bc4000000b0032cc06a16a1mr8121168vsc.86.1651738209635; Thu, 05 May 2022 01:10:09 -0700 (PDT) MIME-Version: 1.0 References: <4df302c6-5bc7-f6fb-916a-6dd9c0460268@linux.ibm.com> In-Reply-To: <4df302c6-5bc7-f6fb-916a-6dd9c0460268@linux.ibm.com> From: Richard Biener Date: Thu, 5 May 2022 10:09:57 +0200 Message-ID: Subject: Re: [PATCH] Skip constant folding for fmin/max when either argument is sNaN [PR105414] To: HAO CHEN GUI Cc: gcc-patches , Peter Bergner , David , Segher Boessenkool Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Thu, 05 May 2022 08:10:12 -0000 On Thu, May 5, 2022 at 10:07 AM HAO CHEN GUI via Gcc-patches wrote: > > Hi, > This patch skips constant folding for fmin/max when either argument > is sNaN. According to C standard, > fmin(sNaN, sNaN=EF=BC=89=3D qNaN, fmin(sNaN, NaN) =3D 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. > Is this okay for trunk? Any recommendations? Thanks a lot. OK. Thanks, Richard. > ChangeLog > > 2022-05-05 Haochen Gui > > gcc/ > PR target/105414 > * match.pd (minmax): Skip constant folding for fmin/fmax when bot= h > arguments are sNaN or one is sNaN and another is NaN. > > gcc/testsuite/ > PR target/105414 > * gcc.dg/pr105414.c: New. > > patch.diff > > diff --git a/gcc/match.pd b/gcc/match.pd > index cad61848daa..f256bcbb483 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3093,7 +3093,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (for minmax (min max FMIN_ALL FMAX_ALL) > (simplify > (minmax @0 @0) > - @0)) > + /* if both are sNaN, it should return qNaN. */ > + (if (!tree_expr_maybe_signaling_nan_p (@0)) > + @0))) > /* min(max(x,y),y) -> y. */ > (simplify > (min:c (max:c @0 @1) @1) > @@ -3193,12 +3195,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (minmax @1 (convert @2))))) > > (for minmax (FMIN_ALL FMAX_ALL) > - /* If either argument is NaN, return the other one. Avoid the > - transformation if we get (and honor) a signalling NaN. */ > + /* If either argument is NaN and other one is not sNaN, return the othe= r > + one. Avoid the transformation if we get (and honor) a signalling Na= N. */ > (simplify > (minmax:c @0 REAL_CST@1) > - (if (real_isnan (TREE_REAL_CST_PTR (@1)) > - && (!HONOR_SNANS (@1) || !TREE_REAL_CST (@1).signalling)) > + (if (real_isnan (TREE_REAL_CST_PTR (@1)) > + && (!HONOR_SNANS (@1) || !TREE_REAL_CST (@1).signalling) > + && !tree_expr_maybe_signaling_nan_p (@0)) > @0))) > /* Convert fmin/fmax to MIN_EXPR/MAX_EXPR. C99 requires these > functions to return the numeric arg if the other one is NaN. > diff --git a/gcc/testsuite/gcc.dg/pr105414.c b/gcc/testsuite/gcc.dg/pr105= 414.c > new file mode 100644 > index 00000000000..78772700acf > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr105414.c > @@ -0,0 +1,30 @@ > +/* { dg-do run { target { *-*-linux* *-*-gnu* } } } */ > +/* { dg-options "-O1 -fsignaling-nans -lm" } */ > +/* { dg-add-options ieee } */ > +/* { dg-require-effective-target issignaling } */ > + > + > +#define _GNU_SOURCE > +#include > +#include > + > +int main() > +{ > + double a =3D __builtin_nans (""); > + > + if (issignaling (fmin (a, a))) > + __builtin_abort (); > + > + if (issignaling (fmax (a, a))) > + __builtin_abort (); > + > + double b =3D __builtin_nan (""); > + > + if (issignaling (fmin (a, b))) > + __builtin_abort (); > + > + if (issignaling (fmax (a, b))) > + __builtin_abort (); > + > + return 0; > +}