From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by sourceware.org (Postfix) with ESMTPS id 747AE3858C2C for ; Tue, 28 Sep 2021 10:03:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 747AE3858C2C Received: by mail-qk1-x735.google.com with SMTP id c7so40183011qka.2 for ; Tue, 28 Sep 2021 03:03:27 -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; bh=Xamxk4PrTKbXHiilvahzXs0MD2fWsquvwEKHO20HqJc=; b=UROZbqK92DeQP1m2vo5RAw0cWahizzJ/djzVvvn2KAjQZ1aJOuYsqg0jea29tXU8os 9ixDiKLzYFwkw9JTtvy0DVEMKAtmEjQDXPEqsThau1dDDzkdBmX6w26rjKtXjznZA2Ky nVLIT3JUPdAzSf8u6DNP/PukVFaWhOgeLn4hZoHvNs69/8VH+RBJDx2mTdQgC5fl92Ky JhCQl1Hvdq7AO/8DrIVOPFmk6rOW6bc1vRDrCuai1ZHwSytVJRDcTd7YS7HvnTd68R8x vJF/YsOoydCgDA8FAuZM2GtJLtYrLAUZ9ZZiVds63x7rAmrUEF89VtMn6G6jQrzSFZQm 4jdw== X-Gm-Message-State: AOAM5324NArsMxWlBk3iVz6KKd4Q5XWk/E9dKOovcriq3tb14/8dBsVe 2mB9sjxx+4/TqdKNie9eMv4SzT+CTD/omqTtK6GLUpfpd70= X-Google-Smtp-Source: ABdhPJwo0KapBsA7AWu7udKDUaM+vQCKgbKC68yQEgfbKGWbvUxNkqIbiBWYC5r+E3J8Ex+5fTsriILh27U6HeULd8k= X-Received: by 2002:a37:68c8:: with SMTP id d191mr4338780qkc.446.1632823406959; Tue, 28 Sep 2021 03:03:26 -0700 (PDT) MIME-Version: 1.0 References: <20210928093312.GV304296@tucnak> In-Reply-To: <20210928093312.GV304296@tucnak> From: Uros Bizjak Date: Tue, 28 Sep 2021 12:03:15 +0200 Message-ID: Subject: Re: [PATCH] i386: Don't emit fldpi etc. if -frounding-math [PR102498] To: Jakub Jelinek Cc: "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: Tue, 28 Sep 2021 10:03:28 -0000 On Tue, Sep 28, 2021 at 11:33 AM Jakub Jelinek wrote: > > Hi! > > i387 has instructions to store some transcedental numbers into the top of > stack. The problem is that what exact bit in the last place one gets for > those depends on the current rounding mode, the CPU knows the number with > slightly higher precision. The compiler assumes rounding to nearest when > comparing them against constants in the IL, but at runtime the rounding > can be different and so some of these depending on rounding mode and the > constant could be 1 ulp higher or smaller than expected. > We only support changing the rounding mode at runtime if the non-default > -frounding-mode option is used, so the following patch just disables > using those constants if that flag is on. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2021-09-28 Jakub Jelinek > > PR target/102498 > * config/i386/i386.c (standard_80387_constant_p): Don't recognize > special 80387 instruction XFmode constants if flag_rounding_math. > > * gcc.target/i386/pr102498.c: New test. OK. Thanks, Uros. > > --- gcc/config/i386/i386.c.jj 2021-09-18 09:44:31.720743823 +0200 > +++ gcc/config/i386/i386.c 2021-09-27 16:55:37.928072249 +0200 > @@ -5035,7 +5035,8 @@ standard_80387_constant_p (rtx x) > /* For XFmode constants, try to find a special 80387 instruction when > optimizing for size or on those CPUs that benefit from them. */ > if (mode == XFmode > - && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS)) > + && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS) > + && !flag_rounding_math) > { > int i; > > --- gcc/testsuite/gcc.target/i386/pr102498.c.jj 2021-09-27 17:09:30.387509264 +0200 > +++ gcc/testsuite/gcc.target/i386/pr102498.c 2021-09-27 17:09:22.548618148 +0200 > @@ -0,0 +1,59 @@ > +/* PR target/102498 */ > +/* { dg-do run { target fenv } } */ > +/* { dg-options "-frounding-math" } */ > + > +#include > +#include > + > +__attribute__((noipa)) long double > +fldlg2 (void) > +{ > + return 0.3010299956639811952256464283594894482L; > +} > + > +__attribute__((noipa)) long double > +fldln2 (void) > +{ > + return 0.6931471805599453094286904741849753009L; > +} > + > +__attribute__((noipa)) long double > +fldl2e (void) > +{ > + return 1.4426950408889634073876517827983434472L; > +} > + > +__attribute__((noipa)) long double > +fldl2t (void) > +{ > + return 3.3219280948873623478083405569094566090L; > +} > + > +__attribute__((noipa)) long double > +fldpi (void) > +{ > + return 3.1415926535897932385128089594061862044L; > +} > + > +int > +main () > +{ > + long double a = fldlg2 (); > + long double b = fldln2 (); > + long double c = fldl2e (); > + long double d = fldl2t (); > + long double e = fldpi (); > + static int f[] = { FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD }; > + int i; > + for (i = 0; i < 4; i++) > + { > + fesetround (f[i]); > + if (a != fldlg2 () > + || b != fldln2 () > + || c != fldl2e () > + || d != fldl2t () > + || e != fldpi ()) > + abort (); > + } > + return 0; > +} > > Jakub >