From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A435438582B2; Mon, 24 Oct 2022 19:27:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A435438582B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666639646; bh=LYso8KYVngOekDZs7r0piSxyhJIxoVWWWA13kRh24HU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qw0Xpf28VR90im3aYNE/XNTEr/53Tsw/mmL4SHrfPL+x36Hi9RgYEBXTOSZucvgCy ztcPTPb7FfPmtZzWDpsxyNOfE2qV4FYaTokUODkE+ltcV9p2FgzLMCCx5Goc+qGp91 oaswUwgbDMlkCwkIrJ6tfaEZUY9Qr2a0m54SWPjM= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/107370] long double sqrtl constant folding is wrong Date: Mon, 24 Oct 2022 19:27:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107370 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #5 from Jakub Jelinek --- On powerpc64le-linux with -O2 -nostdinc -mlong-double-128 -mabi=3Dieeelongd= ouble int main() { __builtin_printf("%.20Lg \n",__builtin_sqrtl(2.0L)); } we also emit on the trunk: .long 325511829 .long -922176773 .long -429395012 .long 1073703433 And similarly for: long double foo (long double x) { return __builtin_hypotl (x, x); } with -O2 -nostdinc -mlong-double-128 -mabi=3Dieeelongdouble -ffast-math whe= re we optimize the hypotl to fabs(x) * M_PI2l (dconst_sqrt2) it is the same const= ant. const REAL_VALUE_TYPE * dconst_sqrt2_ptr (void) { static REAL_VALUE_TYPE value; /* Initialize mathematical constants for constant folding builtins. These constants need to be given to at least 160 bits precision. */ if (value.cl =3D=3D rvc_zero) { mpfr_t m; mpfr_init2 (m, SIGNIFICAND_BITS); mpfr_sqrt_ui (m, 2, MPFR_RNDN); real_from_mpfr (&value, m, NULL_TREE, MPFR_RNDN); mpfr_clear (m); } return &value; }=