From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A79EF385E45D; Sat, 16 Mar 2024 10:37:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A79EF385E45D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710585445; bh=Aq4Nrz+BJJyNm49DiB58bajOeTXGDIx8lPFhENB56sM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AfnsRjqkUTG01rn4DAjUjimBsW4FBXwJRBwdDGEFYpPZwMil0SktcGGT0dGF0uTSP ZpDDjtRhEUdz5SNakgq/FHdHxQ///U6XihVxDv7QMLOcXV1dvNeD90ijvOG7p4hUeS IiLu8BdpNdchzHwTZbbEZ8np4Q3D4hxSytl4hhv0= From: "harald at gigawatt dot nl" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114363] inconsistent optimization of pow(x,2)+pow(y,2) Date: Sat, 16 Mar 2024 10:37:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: harald at gigawatt dot nl X-Bugzilla-Status: UNCONFIRMED 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=3D114363 Harald van Dijk changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |harald at gigawatt dot nl --- Comment #1 from Harald van Dijk --- This is, I believe, correct. Before C++11, calling std::pow with float and = int arguments, it returned a float. As of C++11, it returns a double. If the result of pow(x,2) is immediately converted to float, then it is a v= alid optimisation to convert it to x*x: that is guaranteed to produce the exact = same result. But if it isn't, then converting to x*x loses accuracy and alters t= he result. You can call std::powf instead of std::pow to avoid the promotion to double= .=