From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5800D3858C24; Sat, 16 Mar 2024 11:26:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5800D3858C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710588404; bh=blnRB4NKEDI+Dt2xwI9QEloCPzzmCI5/OOvAjWZ8j28=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AoHyIXqdsSIf07ZySUCbfBt5vApaOvjSPYOgsCtKq+vRTaex6fHRqlbIbGyap4Weh l2vmzJnKUlh7i9+W3hs0QuTEQ7SILsWADH9N4iCcDKcidKIBMFvCJ2MpLNvsuysPWY E4C8GhV9sAz48kciuw3MLSsDzjzRYTWliYiph7/A= From: "xry111 at gcc dot gnu.org" 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 11:26:43 +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: xry111 at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: resolution cc bug_status 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 Xi Ruoyao changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID CC| |xry111 at gcc dot gnu.org Status|UNCONFIRMED |RESOLVED --- Comment #2 from Xi Ruoyao --- (In reply to Harald van Dijk from comment #1) > 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. >=20 > If the result of pow(x,2) is immediately converted to float, then it is a > valid 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 the result. Thus invalid. > You can call std::powf instead of std::pow to avoid the promotion to doub= le. Or add -std=3Dc++98.=